]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - fade.c
fade.c: Fix some signed issues
[paraslash.git] / fade.c
diff --git a/fade.c b/fade.c
index 8dfbcc2f767f251649cddca00084d1a080b0adae..8893ca606e0d7e85ddf69513b0790214cb7452c7 100644 (file)
--- a/fade.c
+++ b/fade.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1998-2005 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 1998-2007 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
@@ -127,16 +127,17 @@ out:
  * Open mixer, get volume, fade to new_vol in secs seconds and
  * close mixer
  */
-static int fade(int new_vol, unsigned int secs)
+static void fade(int new_vol, int fade_time)
 {
-       int vol, mixer_fd = -1, diff, incr, ret;
+       int vol, mixer_fd = -1, diff, incr;
+       unsigned secs;
        struct timespec ts;
        unsigned long long tmp, tmp2; /* Careful with that axe, Eugene! */
 
-       PARA_NOTICE_LOG("fading to %d in %d seconds\n", new_vol, secs);
-       ret = 0;
-       if (!secs)
+       if (fade_time <= 0)
                goto out;
+       secs = fade_time;
+       PARA_NOTICE_LOG("fading to %d in %d seconds\n", new_vol, secs);
        mixer_fd = open_mixer();
        if (mixer_fd < 0)
                goto out;
@@ -146,7 +147,6 @@ static int fade(int new_vol, unsigned int secs)
        diff = new_vol - vol;
        if (!diff) {
                sleep(secs);
-               ret = 1;
                goto out;
        }
        incr = diff > 0? 1: -1;
@@ -166,7 +166,6 @@ static int fade(int new_vol, unsigned int secs)
 out:
        if (mixer_fd >= 0)
                close(mixer_fd);
-       return 1;
 }
 
 static int client_cmd(const char *cmd,...)
@@ -174,7 +173,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;
@@ -254,30 +253,35 @@ static void sweet_dreams(void)
 
 static void snooze(void)
 {
+       unsigned sleep_time;
+
+       if (args_info.snooze_time_arg <= 0)
+               return;
+       sleep_time = args_info.snooze_time_arg;
        if (get_vol() < args_info.snooze_out_vol_arg)
                set_vol(args_info.snooze_out_vol_arg);
        else
                fade(args_info.snooze_out_vol_arg, args_info.snooze_out_fade_arg);
        client_cmd("pause");
        PARA_NOTICE_LOG("%d seconds snooze time...\n", args_info.snooze_time_arg);
-       sleep(args_info.snooze_time_arg);
+       sleep(sleep_time);
        client_cmd("play");
        fade(args_info.snooze_in_vol_arg, args_info.snooze_in_fade_arg);
 }
 
 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);
 }
 
 
@@ -287,6 +291,7 @@ int main(int argc, char *argv[])
 
        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",