fecdec: Use a fixed buffer pool size of 64K.
[paraslash.git] / fade.c
diff --git a/fade.c b/fade.c
index 78903e5..d9f93cc 100644 (file)
--- a/fade.c
+++ b/fade.c
@@ -1,18 +1,14 @@
 /*
- * Copyright (C) 1998-2009 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 1998-2010 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
 
-/** \file fade.c A volume fader and alarm clock for linux. */
+/** \file fade.c A volume fader and alarm clock for OSS. */
 
+#include <regex.h>
 #include <sys/types.h>
 #include <dirent.h>
-
-#include "fade.cmdline.h"
-#include "para.h"
-#include "fd.h"
-
 #include <sys/ioctl.h>
 #include <ctype.h>
 #include <stdlib.h> /* EXIT_SUCCESS */
 #include <string.h>
 #include <limits.h>
 #include <sys/soundcard.h>
+
+#include "fade.cmdline.h"
+#include "para.h"
+#include "fd.h"
 #include "string.h"
 #include "error.h"
 
-
 INIT_FADE_ERRLISTS;
-struct fade_args_info conf;
+static struct fade_args_info conf;
 
 __printf_2_3 void para_log(__a_unused int ll, const char *fmt, ...)
 {
@@ -43,10 +42,11 @@ __printf_2_3 void para_log(__a_unused int ll, const char *fmt, ...)
 }
 
 /*
- * open mixer device
+ * Open the mixer device.
  */
 static int open_mixer(void)
 {
+       PARA_INFO_LOG("opening %s\n", conf.mixer_device_arg);
        return para_open(conf.mixer_device_arg, O_RDWR, 42);
 }
 
@@ -131,7 +131,7 @@ static void fixup_mixer_channel_arg(void)
 
 /*
  * Open mixer, get volume, fade to new_vol in secs seconds and
- * close mixer
+ * close mixer.
  */
 static int fade(int new_vol, int fade_time)
 {
@@ -217,14 +217,14 @@ static int sweet_dreams(void)
        unsigned int delay;
        struct tm *tm;
        int ret, min = conf.wake_min_arg;
-       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;
+       char *fo_mood = conf.fo_mood_arg;
+       char *fi_mood = conf.fi_mood_arg;
+       char *sleep_mood = conf.sleep_mood_arg;
+       int fit = conf.fi_time_arg;
+       int fot = conf.fo_time_arg;
+       int fiv = conf.fi_vol_arg;
+       int fov = conf.fo_vol_arg;
+       int iv = conf.ivol_arg;
 
        /* calculate wake time */
        time(&t1);
@@ -247,38 +247,38 @@ static int sweet_dreams(void)
        PARA_INFO_LOG("waketime: %s", asctime(tm));
        client_cmd("stop");
        sleep(1);
-       if (sf) {
+       if (fot) {
                PARA_INFO_LOG("initial volume: %d\n", iv);
                ret = open_and_set_mixer_channel(iv);
                if (ret < 0)
                        return ret;
-               change_afs_mode_and_play(fa_mode);
-               ret = fade(sv, sf);
+               change_afs_mode_and_play(fo_mood);
+               ret = fade(fov, fot);
                if (ret < 0)
                        return ret;
        } else {
-               ret = open_and_set_mixer_channel(sf);
+               ret = open_and_set_mixer_channel(fov);
                if (ret < 0)
                        return ret;
        }
-       if (conf.sleep_mode_given)
-               change_afs_mode_and_play(sleep_mode);
+       if (conf.sleep_mood_given)
+               change_afs_mode_and_play(sleep_mood);
        else
                client_cmd("stop");
-       if (!wf)
+       if (!fit)
                return 1;
        for (;;) {
                time(&t1);
-               if (wake_time_epoch <= t1 + wf)
+               if (wake_time_epoch <= t1 + fit)
                        break;
-               delay = wake_time_epoch - t1 - wf;
+               delay = wake_time_epoch - t1 - fit;
                PARA_INFO_LOG("sleeping %u seconds (%u:%02u)\n",
                        delay, delay / 3600,
                        (delay % 3600) / 60);
                sleep(delay);
        }
-       change_afs_mode_and_play(wake_mode);
-       ret = fade(wv, wf);
+       change_afs_mode_and_play(fi_mood);
+       ret = fade(fiv, fit);
        PARA_INFO_LOG("fade complete, returning\n");
        return ret;
 }
@@ -288,20 +288,20 @@ static int snooze(void)
        int ret;
        unsigned sleep_time;
 
-       if (conf.snooze_time_arg <= 0)
+       if (conf.so_time_arg <= 0)
                return 1;
-       sleep_time = conf.snooze_time_arg;
-       if (open_and_get_mixer_channel() < conf.snooze_out_vol_arg)
-               ret = open_and_set_mixer_channel(conf.snooze_out_vol_arg);
+       sleep_time = conf.so_time_arg;
+       if (open_and_get_mixer_channel() < conf.so_vol_arg)
+               ret = open_and_set_mixer_channel(conf.so_vol_arg);
        else
-               ret = fade(conf.snooze_out_vol_arg, conf.snooze_out_fade_arg);
+               ret = fade(conf.so_vol_arg, conf.so_time_arg);
        if (ret < 0)
                return ret;
        client_cmd("pause");
        PARA_NOTICE_LOG("%d seconds snooze time...\n", conf.snooze_time_arg);
        sleep(sleep_time);
        client_cmd("play");
-       return fade(conf.snooze_in_vol_arg, conf.snooze_in_fade_arg);
+       return fade(conf.si_vol_arg, conf.si_time_arg);
 }
 
 static int configfile_exists(void)
@@ -336,26 +336,24 @@ int main(int argc, char *argv[])
                        .override = 0,
                        .initialize = 0,
                        .check_required = 0,
-                       .check_ambiguity = 0
+                       .check_ambiguity = 0,
+                       .print_errors = 1
                };
                fade_cmdline_parser_config_file(conf.config_file_arg,
                        &conf, &params);
        }
        fixup_mixer_channel_arg();
-       if (!strcmp(conf.mode_arg, "sleep")) {
+       switch (conf.mode_arg) {
+       case mode_arg_sleep:
                ret = sweet_dreams();
-               goto out;
-       }
-       if (!strcmp(conf.mode_arg, "fade")) {
+               break;
+       case mode_arg_fade:
                ret = fade(conf.fade_vol_arg, conf.fade_time_arg);
-               goto out;
-       }
-       if (!strcmp(conf.mode_arg, "snooze")) {
+               break;
+       case mode_arg_snooze:
                ret = snooze();
-               goto out;
+               break;
        }
-       ret = -E_FADE_SYNTAX;
-out:
        if (ret < 0)
                PARA_EMERG_LOG("%s\n", para_strerror(-ret));
        return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;