mixer.c: Fix doxygen \file description.
[paraslash.git] / mixer.c
diff --git a/mixer.c b/mixer.c
index 00af08a..27fa7d1 100644 (file)
--- a/mixer.c
+++ b/mixer.c
@@ -1,6 +1,6 @@
 /* Copyright (C) 1998 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
 
-/** \file mixer.c A volume fader and alarm clock for OSS. */
+/** \file mixer.c A volume fader and alarm clock. */
 
 #include <regex.h>
 #include <lopsub.h>
@@ -8,6 +8,7 @@
 
 #include "mixer.lsg.h"
 #include "para.h"
+#include "lsu.h"
 #include "fd.h"
 #include "string.h"
 #include "mix.h"
@@ -192,9 +193,6 @@ static void change_afs_mode(const char *afs_mode)
 {
        char *cmd;
 
-       client_cmd("stop");
-       if (!afs_mode)
-               return;
        cmd = make_message("select %s", afs_mode);
        client_cmd(cmd);
        free(cmd);
@@ -290,7 +288,7 @@ static int com_sleep(const struct mixer *m, struct mixer_handle *h)
        PARA_INFO_LOG("waketime: %d:%02d\n", tm->tm_hour, tm->tm_min);
        client_cmd("stop");
        sleep(1);
-       if (fot) {
+       if (fot && fo_mood) {
                ret = set_initial_volume(m, h);
                if (ret < 0)
                        return ret;
@@ -307,12 +305,13 @@ static int com_sleep(const struct mixer *m, struct mixer_handle *h)
                if (ret < 0)
                        return ret;
        }
-       if (OPT_GIVEN(SLEEP, SLEEP_MOOD)) {
+       if (sleep_mood) {
                change_afs_mode(sleep_mood);
-               client_cmd("play");
-       } else
+               if (!fot || !fo_mood) /* currently stopped */
+                       client_cmd("play");
+       } else if (fot && fo_mood) /* currently playing */
                client_cmd("stop");
-       if (!fit)
+       if (!fit || !fi_mood) /* nothing to do */
                return 1;
        change_afs_mode(fi_mood);
        for (;;) {
@@ -455,60 +454,16 @@ static void handle_help_flags(void)
 static int parse_and_merge_config_file(const struct lls_command *cmd)
 {
        int ret;
-       int cf_argc;
-       char **cf_argv;
-       char *cf, *errctx = NULL;
-       struct lls_parse_result **lprp, *cf_lpr, *merged_lpr;
-       void *map;
-       size_t sz;
-       const char *subcmd_name;
-
-       if (cmd == lls_cmd(0, mixer_suite)) {
-               lprp = &lpr;
-               subcmd_name = NULL;
-       } else {
-               lprp = &sub_lpr;
-               subcmd_name = lls_command_name(cmd);
-       }
-       if (OPT_GIVEN(PARA_MIXER, CONFIG_FILE))
-               cf = para_strdup(OPT_STRING_VAL(PARA_MIXER, CONFIG_FILE));
-       else {
-               char *home = para_homedir();
-               cf = make_message("%s/.paraslash/mixer.conf", home);
-               free(home);
-       }
-       ret = mmap_full_file(cf, O_RDONLY, &map, &sz, NULL);
-       if (ret < 0) {
-               if (ret != -E_EMPTY && ret != -ERRNO_TO_PARA_ERROR(ENOENT))
-                       goto free_cf;
-               if (ret == -ERRNO_TO_PARA_ERROR(ENOENT) &&
-                               OPT_GIVEN(PARA_MIXER, CONFIG_FILE))
-                       goto free_cf;
-       } else {
-               ret = lls(lls_convert_config(map, sz, subcmd_name, &cf_argv, &errctx));
-               para_munmap(map, sz);
-               if (ret < 0)
-                       goto free_cf;
-               cf_argc = ret;
-               ret = lls(lls_parse(cf_argc, cf_argv, cmd, &cf_lpr, &errctx));
-               lls_free_argv(cf_argv);
-               if (ret < 0)
-                       goto free_cf;
-               ret = lls(lls_merge(*lprp, cf_lpr, cmd, &merged_lpr, &errctx));
-               lls_free_parse_result(cf_lpr, cmd);
-               if (ret < 0)
-                       goto free_cf;
-               lls_free_parse_result(*lprp, cmd);
-               *lprp = merged_lpr;
-               loglevel = OPT_UINT32_VAL(PARA_MIXER, LOGLEVEL);
-       }
-       ret = 1;
-free_cf:
-       free(cf);
-       if (errctx)
-               PARA_ERROR_LOG("%s\n", errctx);
-       free(errctx);
-       return ret;
+       struct lls_parse_result **lprp = (cmd == lls_cmd(0, mixer_suite))?
+               &lpr : &sub_lpr;
+
+       ret = lsu_merge_config_file_options(OPT_STRING_VAL(PARA_MIXER,
+               CONFIG_FILE), "mixer.conf", lprp, cmd, mixer_suite,
+               0 /* flags */);
+       if (ret < 0)
+               return ret;
+       loglevel = OPT_UINT32_VAL(PARA_MIXER, LOGLEVEL);
+       return 1;
 }
 
 /**