]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Merge branch 'master' into next
authorAndre Noll <maan@systemlinux.org>
Fri, 4 Sep 2009 08:38:34 +0000 (10:38 +0200)
committerAndre Noll <maan@systemlinux.org>
Fri, 4 Sep 2009 08:38:34 +0000 (10:38 +0200)
1  2 
fade.c

diff --combined fade.c
index 44904ac54088124f695a63bb62a7e49867442f78,78903e5f6d95ba3265ffc0a5688121f54eec3bbe..f95ef4c843588fa821c0a07fc090d24b88f220b8
--- 1/fade.c
--- 2/fade.c
+++ b/fade.c
@@@ -4,11 -4,15 +4,11 @@@
   * 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, ...)
  {
@@@ -42,7 -43,7 +42,7 @@@
  }
  
  /*
 - * open mixer device
 + * Open the mixer device.
   */
  static int open_mixer(void)
  {
@@@ -107,7 -108,7 +107,7 @@@ static int open_and_set_mixer_channel(i
  
  static void fixup_mixer_channel_arg(void)
  {
-       int val;
+       int val = SOUND_MIXER_VOLUME; /* STFU, gcc */
  
        switch (conf.mixer_channel_arg) {
                case mixer_channel_arg_volume: val = SOUND_MIXER_VOLUME; break;
  
  /*
   * 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)
  {
@@@ -216,14 -217,14 +216,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);
        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;
  }
@@@ -287,20 -288,20 +287,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)
@@@ -335,24 -336,26 +335,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;