audioc: Use lsu_merge_config_file_options().
authorAndre Noll <maan@tuebingen.mpg.de>
Wed, 14 Mar 2018 23:59:56 +0000 (00:59 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 22 Apr 2018 18:30:37 +0000 (20:30 +0200)
This gets rid of the pointless configfile_exists() and the equally
pointless cmd variable.

audioc.c
configure.ac

index e1a225d..af67063 100644 (file)
--- a/audioc.c
+++ b/audioc.c
@@ -17,6 +17,7 @@
 
 #include "para.h"
 #include "error.h"
+#include "lsu.h"
 #include "net.h"
 #include "string.h"
 #include "fd.h"
@@ -290,19 +291,6 @@ __noreturn static void print_completions(void)
 
 #endif /* HAVE_READLINE */
 
-static char *configfile_exists(void)
-{
-       char *config_file;
-       char *home = para_homedir();
-
-       config_file = make_message("%s/.paraslash/audioc.conf", home);
-       free(home);
-       if (file_exists(config_file))
-               return config_file;
-       free(config_file);
-       return NULL;
-}
-
 static void handle_help_flag(void)
 {
        char *help;
@@ -336,54 +324,21 @@ static void handle_help_flag(void)
  */
 int main(int argc, char *argv[])
 {
-       const struct lls_command *cmd = CMD_PTR;
        int ret, fd;
-       char *cf = NULL, *buf, *args, *errctx = NULL;
+       char *buf, *args, *errctx = NULL;
        size_t bufsize;
-       struct lls_parse_result *lpr1, *lpr2, *lpr3;
        unsigned num_inputs;
 
-       ret = lls(lls_parse(argc, argv, cmd, &lpr1, &errctx));
+       ret = lls(lls_parse(argc, argv, CMD_PTR, &lpr, &errctx));
        if (ret < 0)
                goto fail;
-       lpr = lpr1;
-       loglevel = OPT_UINT32_VAL(LOGLEVEL);
        version_handle_flag("audioc", OPT_GIVEN(VERSION));
        handle_help_flag();
-       cf = configfile_exists();
-       if (cf) {
-               void *map;
-               size_t sz;
-               int cf_argc;
-               char **cf_argv;
-               ret = mmap_full_file(cf, O_RDONLY, &map, &sz, NULL);
-               if (ret != -E_EMPTY) {
-                       if (ret < 0)
-                               goto out;
-                       ret = lls(lls_convert_config(map, sz, NULL, &cf_argv,
-                               &errctx));
-                       para_munmap(map, sz);
-                       if (ret < 0) {
-                               PARA_ERROR_LOG("syntax error in %s\n", cf);
-                               goto out;
-                       }
-                       cf_argc = ret;
-                       ret = lls(lls_parse(cf_argc, cf_argv, cmd, &lpr2,
-                               &errctx));
-                       lls_free_argv(cf_argv);
-                       if (ret < 0) {
-                               PARA_ERROR_LOG("parse error in %s\n", cf);
-                               goto out;
-                       }
-                       ret = lls(lls_merge(lpr1, lpr2, cmd, &lpr3, &errctx));
-                       lls_free_parse_result(lpr2, cmd);
-                       if (ret < 0)
-                               goto out;
-                       lls_free_parse_result(lpr1, cmd);
-                       lpr = lpr3;
-                       loglevel = OPT_UINT32_VAL(LOGLEVEL);
-               }
-       }
+       ret = lsu_merge_config_file_options(NULL, "audioc.conf",
+               &lpr, CMD_PTR, audioc_suite, 0 /* default flags */);
+       if (ret < 0)
+               goto fail;
+       loglevel = OPT_UINT32_VAL(LOGLEVEL);
        if (OPT_GIVEN(COMPLETE))
                print_completions();
        if (OPT_GIVEN(SOCKET))
@@ -418,8 +373,7 @@ int main(int argc, char *argv[])
        } while (ret >= 0);
        free(buf);
 out:
-       lls_free_parse_result(lpr, cmd);
-       free(cf);
+       lls_free_parse_result(lpr, CMD_PTR);
 fail:
        if (errctx)
                PARA_ERROR_LOG("%s\n", errctx);
index 110e0c3..3fa6853 100644 (file)
@@ -797,6 +797,7 @@ AC_SUBST(write_objs, add_dot_o($write_objs))
 audioc_errlist_objs="
        audioc
        string
+       lsu
        net
        fd
        version