X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=fade.c;h=9ba733b3113ca0273143e95892266c236938631f;hp=94b866969358126a06d76218832a86f0a985752d;hb=809dba091f6d000ccfab130b2e9891de85ba0ba6;hpb=09e1e9039b42f00bcfa64091700d611931618bca diff --git a/fade.c b/fade.c index 94b86696..9ba733b3 100644 --- a/fade.c +++ b/fade.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1998-2005 Andre Noll + * Copyright (C) 1998-2007 Andre Noll * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,9 +34,9 @@ #include "string.h" -struct gengetopt_args_info args_info; +struct fade_args_info args_info; -void para_log(__unused int ll, const char *fmt,...) +void para_log(__a_unused int ll, const char *fmt,...) { va_list argp; time_t t1; @@ -55,11 +55,11 @@ void para_log(__unused int ll, const char *fmt,...) */ static int open_mixer(void) { - int mixer_fd; + int mixer_fd; - if ((mixer_fd = open(args_info.mixer_device_arg, O_RDWR, 0)) < 0) - return -1; - return mixer_fd; + if ((mixer_fd = open(args_info.mixer_device_arg, O_RDWR, 0)) < 0) + return -1; + return mixer_fd; } /* @@ -174,7 +174,7 @@ static int client_cmd(const char *cmd,...) int ret, fds[3] = {0, 0, 0}; pid_t pid; char *cmdline = make_message(BINDIR "/para_client %s", cmd); - PARA_INFO_LOG("%s", cmdline); + PARA_INFO_LOG("%s\n", cmdline); ret = para_exec_cmdline_pid(&pid, cmdline, fds); free(cmdline); return ret; @@ -188,7 +188,6 @@ static void sweet_dreams(void) time_t t1, wake_time_epoch; unsigned int delay; struct tm *tm; - int hour = args_info.wake_hour_arg; int min = args_info.wake_min_arg; char *fa_stream = args_info.fa_stream_arg; char *wake_stream = args_info.wake_stream_arg; @@ -201,6 +200,25 @@ static void sweet_dreams(void) char *cmd, *sleep_stream = args_info.sleep_stream_given? args_info.sleep_stream_arg : NULL; + /* calculate wake time */ + time(&t1); + if (args_info.wake_hour_given) { + int hour = args_info.wake_hour_arg; + tm = localtime(&t1); + if (tm->tm_hour > hour || (tm->tm_hour == hour && tm->tm_min> min)) { + t1 += 86400; /* wake time is tomorrow */ + tm = localtime(&t1); + } + tm->tm_hour = hour; + tm->tm_min = min; + tm->tm_sec = 0; + } else { + t1 += 8 * 60 * 60; + PARA_INFO_LOG("default wake time: %lu\n", t1); + tm = localtime(&t1); + } + wake_time_epoch = mktime(tm); + PARA_INFO_LOG("waketime: %s", asctime(tm)); if (sf) { PARA_INFO_LOG("initial volume: %d\n", iv); set_vol(iv); @@ -217,27 +235,15 @@ static void sweet_dreams(void) client_cmd("stop"); if (!wf) return; - /* calculate wake time */ - time(&t1); - tm = localtime(&t1); - if (tm->tm_hour > hour || (tm->tm_hour == hour && tm->tm_min> min)) { - /* wake time is tomorrow */ - t1 += 86400; - tm = localtime(&t1); - t1 -= 86400; - } - tm->tm_hour = hour; - tm->tm_min = min; - tm->tm_sec = 0; - wake_time_epoch = mktime(tm); - PARA_INFO_LOG("waketime: %s", asctime(tm)); - while (wake_time_epoch > t1 + wf) { + for (;;) { + time(&t1); + if (wake_time_epoch <= t1 + wf) + break; delay = wake_time_epoch - t1 - wf; PARA_INFO_LOG("sleeping %u seconds (%u:%02u)\n", delay, delay / 3600, (delay % 3600) / 60); sleep(delay); - time(&t1); } cmd = make_message("csp %s\n", wake_stream); client_cmd(cmd); @@ -261,17 +267,17 @@ static void snooze(void) static int configfile_exists(void) { - static char *config_file; + static char *config_file; - if (!args_info.config_file_given) { + if (!args_info.config_file_given) { char *home = para_homedir(); const char *conf = ".paraslash/fade.conf"; free(config_file); config_file = make_message("%s/%s", home, conf); free(home); - args_info.config_file_arg = config_file; - } - return file_exists(args_info.config_file_arg); + args_info.config_file_arg = config_file; + } + return file_exists(args_info.config_file_arg); } @@ -279,8 +285,9 @@ int main(int argc, char *argv[]) { int ret; - if (cmdline_parser(argc, argv, &args_info)) + if (fade_cmdline_parser(argc, argv, &args_info)) exit(EXIT_FAILURE); + HANDLE_VERSION_FLAG("fade", args_info); ret = configfile_exists(); if (!ret && args_info.config_file_given) { PARA_EMERG_LOG("can not read config file %s\n", @@ -288,7 +295,7 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } if (ret) - cmdline_parser_configfile(args_info.config_file_arg, + fade_cmdline_parser_configfile(args_info.config_file_arg, &args_info, 0, 0, 0); if ((ret = open_mixer()) < 0) { PARA_EMERG_LOG("can not open mixer device %s.",