Fix documentation of select command.
[paraslash.git] / fade.c
diff --git a/fade.c b/fade.c
index d21ff4036778767a8801da9fac0d36517b3dfdae..3e8479a0eb7783db1af51edef03693e0c369b8a8 100644 (file)
--- a/fade.c
+++ b/fade.c
@@ -1,30 +1,20 @@
 /*
 /*
- * Copyright (C) 1998-2007 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 1998-2008 Andre Noll <maan@systemlinux.org>
  *
  *
- *     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
- *     the Free Software Foundation; either version 2 of the License, or
- *     (at your option) any later version.
- *
- *     This program is distributed in the hope that it will be useful,
- *     but WITHOUT ANY WARRANTY; without even the implied warranty of
- *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *     GNU General Public License for more details.
- *
- *     You should have received a copy of the GNU General Public License
- *     along with this program; if not, write to the Free Software
- *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Licensed under the GPL v2. For licencing details see COPYING.
  */
 
 /** \file fade.c a volume fader and alarm clock */
 
  */
 
 /** \file fade.c a volume fader and alarm clock */
 
+#include <sys/types.h>
+#include <dirent.h>
+
 #include "fade.cmdline.h"
 #include "para.h"
 #include "fd.h"
 
 #include <stropts.h>
 #include <ctype.h>
 #include "fade.cmdline.h"
 #include "para.h"
 #include "fd.h"
 
 #include <stropts.h>
 #include <ctype.h>
-#include <curses.h>
 #include <stdlib.h> /* EXIT_SUCCESS */
 #include <unistd.h>
 #include <signal.h>
 #include <stdlib.h> /* EXIT_SUCCESS */
 #include <unistd.h>
 #include <signal.h>
@@ -158,7 +148,7 @@ out:
        close(mixer_fd);
 }
 
        close(mixer_fd);
 }
 
-static int client_cmd(const char *cmd,...)
+static void client_cmd(const char *cmd)
 {
        int ret, fds[3] = {0, 0, 0};
        pid_t pid;
 {
        int ret, fds[3] = {0, 0, 0};
        pid_t pid;
@@ -167,7 +157,24 @@ static int client_cmd(const char *cmd,...)
        PARA_INFO_LOG("%s\n", cmdline);
        ret = para_exec_cmdline_pid(&pid, cmdline, fds);
        free(cmdline);
        PARA_INFO_LOG("%s\n", cmdline);
        ret = para_exec_cmdline_pid(&pid, cmdline, fds);
        free(cmdline);
-       return ret;
+       if (ret < 0)
+               exit(EXIT_FAILURE);
+       do
+               ret = wait(NULL);
+       while (ret != -1 && errno != ECHILD);
+}
+
+static void change_afs_mode_and_play(char *afs_mode)
+{
+       char *cmd;
+
+       client_cmd("stop");
+       if (!afs_mode)
+               return;
+       cmd = make_message("select %s\n", afs_mode);
+       client_cmd(cmd);
+       free(cmd);
+       client_cmd("play");
 }
 
 /*
 }
 
 /*
@@ -179,16 +186,14 @@ static void sweet_dreams(void)
        unsigned int delay;
        struct tm *tm;
        int min = conf.wake_min_arg;
        unsigned int delay;
        struct tm *tm;
        int min = conf.wake_min_arg;
-       char *fa_stream = conf.fa_stream_arg;
-       char *wake_stream = conf.wake_stream_arg;
-       //char *current_stream = stat_items[STREAM].content;
+       char *fa_mode = conf.fa_mode_arg;
+       char *wake_mode = conf.wake_mode_arg;
+       char *sleep_mode = conf.sleep_mode_arg;
        int wf = conf.wake_fade_arg;
        int sf = conf.fa_fade_arg;
        int wv = conf.wake_vol_arg;
        int sv = conf.fa_vol_arg;
        int iv = conf.sleep_ivol_arg;
        int wf = conf.wake_fade_arg;
        int sf = conf.fa_fade_arg;
        int wv = conf.wake_vol_arg;
        int sv = conf.fa_vol_arg;
        int iv = conf.sleep_ivol_arg;
-       char *cmd, *sleep_stream = conf.sleep_stream_given?
-               conf.sleep_stream_arg : NULL;
 
        /* calculate wake time */
        time(&t1);
 
        /* calculate wake time */
        time(&t1);
@@ -203,26 +208,22 @@ static void sweet_dreams(void)
                tm->tm_min = min;
                tm->tm_sec = 0;
        } else {
                tm->tm_min = min;
                tm->tm_sec = 0;
        } else {
-               t1 += 8 * 60 * 60;
+               t1 += 9 * 60 * 60; /* nine hours from now */
                PARA_INFO_LOG("default wake time: %lu\n", t1);
                tm = localtime(&t1);
        }
        wake_time_epoch = mktime(tm);
        PARA_INFO_LOG("waketime: %s", asctime(tm));
                PARA_INFO_LOG("default wake time: %lu\n", t1);
                tm = localtime(&t1);
        }
        wake_time_epoch = mktime(tm);
        PARA_INFO_LOG("waketime: %s", asctime(tm));
+       client_cmd("stop");
+       sleep(1);
        if (sf) {
                PARA_INFO_LOG("initial volume: %d\n", iv);
                set_vol(iv);
        if (sf) {
                PARA_INFO_LOG("initial volume: %d\n", iv);
                set_vol(iv);
-               cmd = make_message("csp %s\n", fa_stream);
-               client_cmd(cmd);
-               free(cmd);
+               change_afs_mode_and_play(fa_mode);
                fade(sv, sf);
                fade(sv, sf);
-       }
-       if (sleep_stream) {
-               cmd = make_message("csp %s\n", sleep_stream);
-               client_cmd(cmd);
-               free(cmd);
        } else
        } else
-               client_cmd("stop");
+               set_vol(sf);
+       change_afs_mode_and_play(sleep_mode);
        if (!wf)
                return;
        for (;;) {
        if (!wf)
                return;
        for (;;) {
@@ -231,15 +232,13 @@ static void sweet_dreams(void)
                        break;
                delay = wake_time_epoch - t1 - wf;
                PARA_INFO_LOG("sleeping %u seconds (%u:%02u)\n",
                        break;
                delay = wake_time_epoch - t1 - wf;
                PARA_INFO_LOG("sleeping %u seconds (%u:%02u)\n",
-                       delay, delay / 3600, 
+                       delay, delay / 3600,
                        (delay % 3600) / 60);
                sleep(delay);
        }
                        (delay % 3600) / 60);
                sleep(delay);
        }
-       cmd = make_message("csp %s\n", wake_stream);
-       client_cmd(cmd);
-       free(cmd);
+       change_afs_mode_and_play(wake_mode);
        fade(wv, wf);
        fade(wv, wf);
-       PARA_INFO_LOG("%s", "fade complete, returning\n");
+       PARA_INFO_LOG("fade complete, returning\n");
 }
 
 static void snooze(void)
 }
 
 static void snooze(void)
@@ -288,9 +287,16 @@ int main(int argc, char *argv[])
                        conf.config_file_arg);
                exit(EXIT_FAILURE);
        }
                        conf.config_file_arg);
                exit(EXIT_FAILURE);
        }
-       if (ret)
-               fade_cmdline_parser_configfile(conf.config_file_arg,
-                       &conf, 0, 0, 0);
+       if (ret) {
+               struct fade_cmdline_parser_params params = {
+                       .override = 0,
+                       .initialize = 0,
+                       .check_required = 0,
+                       .check_ambiguity = 0
+               };
+               fade_cmdline_parser_config_file(conf.config_file_arg,
+                       &conf, &params);
+       }
        ret = open_mixer();
        if (ret < 0) {
                PARA_EMERG_LOG("can not open mixer device %s.",
        ret = open_mixer();
        if (ret < 0) {
                PARA_EMERG_LOG("can not open mixer device %s.",