fade: cosmetic cleanups
authorAndre Noll <maan@systemlinux.org>
Sat, 26 May 2007 21:02:18 +0000 (23:02 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 26 May 2007 21:02:18 +0000 (23:02 +0200)
always return negative values on errors, some other trivial changes.

fade.c

diff --git a/fade.c b/fade.c
index 3c622ef0f9ec3356169827d2959b75e2f4f7592a..d21ff4036778767a8801da9fac0d36517b3dfdae 100644 (file)
--- a/fade.c
+++ b/fade.c
@@ -92,10 +92,10 @@ static int get_vol(void)
  */
 static int do_set_vol(int mixer_fd, int volume)
 {
  */
 static int do_set_vol(int mixer_fd, int volume)
 {
-       int tmp;
-       tmp = (volume << 8) + volume;
+       int tmp = (volume << 8) + volume;
+
        if (ioctl(mixer_fd, MIXER_WRITE(SOUND_MIXER_VOLUME), &tmp) < 0)
        if (ioctl(mixer_fd, MIXER_WRITE(SOUND_MIXER_VOLUME), &tmp) < 0)
-               return 0;
+               return -1;
        return 1;
 }
 
        return 1;
 }
 
@@ -104,18 +104,13 @@ static int do_set_vol(int mixer_fd, int volume)
  */
 static int set_vol(int volume)
 {
  */
 static int set_vol(int volume)
 {
-       int mixer_fd;
-       int ret;
+       int mixer_fd, ret = open_mixer();
 
 
-       mixer_fd = open_mixer();
-       ret = 0;
-       if (mixer_fd < 0)
-               goto out;
-       if (!do_set_vol(mixer_fd, volume))
-               goto out;
-       ret = 1;
+       if (ret < 0)
+               return ret;
+       mixer_fd = ret;
+       ret = do_set_vol(mixer_fd, volume);
        close(mixer_fd);
        close(mixer_fd);
-out:
        return ret;
 }
 
        return ret;
 }
 
@@ -125,18 +120,18 @@ out:
  */
 static void fade(int new_vol, int fade_time)
 {
  */
 static void fade(int new_vol, int fade_time)
 {
-       int vol, mixer_fd = -1, diff, incr;
+       int vol, mixer_fd, diff, incr;
        unsigned secs;
        struct timespec ts;
        unsigned long long tmp, tmp2; /* Careful with that axe, Eugene! */
 
        if (fade_time <= 0)
        unsigned secs;
        struct timespec ts;
        unsigned long long tmp, tmp2; /* Careful with that axe, Eugene! */
 
        if (fade_time <= 0)
-               goto out;
+               return;
        secs = fade_time;
        PARA_NOTICE_LOG("fading to %d in %d seconds\n", new_vol, secs);
        mixer_fd = open_mixer();
        if (mixer_fd < 0)
        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;
+               return;
        vol = do_get_vol(mixer_fd);
        if (vol < 0)
                goto out;
        vol = do_get_vol(mixer_fd);
        if (vol < 0)
                goto out;
@@ -154,14 +149,13 @@ static void fade(int new_vol, int fade_time)
                ts.tv_sec = tmp / 1000; /* really nec ?*/
                //printf("ts.tv_sec: %i\n", ts.tv_nsec);
                vol += incr;
                ts.tv_sec = tmp / 1000; /* really nec ?*/
                //printf("ts.tv_sec: %i\n", ts.tv_nsec);
                vol += incr;
-               if (!do_set_vol(mixer_fd, vol))
+               if (do_set_vol(mixer_fd, vol) < 0)
                        goto out;
                //printf("vol = %i\n", vol);
                nanosleep(&ts, NULL);
        }
 out:
                        goto out;
                //printf("vol = %i\n", vol);
                nanosleep(&ts, NULL);
        }
 out:
-       if (mixer_fd >= 0)
-               close(mixer_fd);
+       close(mixer_fd);
 }
 
 static int client_cmd(const char *cmd,...)
 }
 
 static int client_cmd(const char *cmd,...)
@@ -169,6 +163,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);
        int ret, fds[3] = {0, 0, 0};
        pid_t pid;
        char *cmdline = make_message(BINDIR "/para_client %s", 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);
@@ -296,14 +291,15 @@ int main(int argc, char *argv[])
        if (ret)
                fade_cmdline_parser_configfile(conf.config_file_arg,
                        &conf, 0, 0, 0);
        if (ret)
                fade_cmdline_parser_configfile(conf.config_file_arg,
                        &conf, 0, 0, 0);
-       if ((ret = open_mixer()) < 0) {
+       ret = open_mixer();
+       if (ret < 0) {
                PARA_EMERG_LOG("can not open mixer device %s.",
                        conf.mixer_device_arg);
                exit(EXIT_FAILURE);
                PARA_EMERG_LOG("can not open mixer device %s.",
                        conf.mixer_device_arg);
                exit(EXIT_FAILURE);
-       } else
-               close(ret);
+       }
+       close(ret);
        ret = 0;
        ret = 0;
-       setlinebuf(stdout);
+//     setlinebuf(stdout);
        if (!strcmp(conf.mode_arg, "sleep")) {
                sweet_dreams();
                goto out;
        if (!strcmp(conf.mode_arg, "sleep")) {
                sweet_dreams();
                goto out;
@@ -318,5 +314,5 @@ int main(int argc, char *argv[])
        }
        ret = -1;
 out:
        }
        ret = -1;
 out:
-       return ret;
+       return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;
 }
 }