filter: Use lsu_merge_config_file_options().
authorAndre Noll <maan@tuebingen.mpg.de>
Thu, 15 Mar 2018 00:18:12 +0000 (01:18 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 22 Apr 2018 18:30:37 +0000 (20:30 +0200)
Straight forward conversion. We now set the loglevel only once,
after the config file options have been merged.

configure.ac
filter.c

index 3fa6853..94b3abb 100644 (file)
@@ -596,6 +596,7 @@ filter_errlist_objs="
        amp_filter
        fecdec_filter
        fec
+       lsu
        version
        prebuffer_filter
        time
index dfdadab..d4a2423 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -9,6 +9,7 @@
 #include "filter_cmd.lsg.h"
 #include "para.h"
 #include "list.h"
+#include "lsu.h"
 #include "sched.h"
 #include "buffer_tree.h"
 #include "filter.h"
@@ -71,50 +72,15 @@ static void handle_help_flag(void)
 
 static int parse_config(void)
 {
-       char *home, *cf; /* config file */
-       struct stat statbuf;
        int ret;
 
        version_handle_flag("filter", OPT_GIVEN(VERSION));
        handle_help_flag();
-       home = para_homedir();
-       cf = make_message("%s/.paraslash/filter.conf", home);
-       free(home);
-       if (!stat(cf, &statbuf)) {
-               void *map;
-               size_t sz;
-               int cf_argc;
-               char **cf_argv, *errctx;
-               struct lls_parse_result *cf_lpr, *merged_lpr;
-
-               ret = mmap_full_file(cf, O_RDONLY, &map, &sz, NULL);
-               if (ret != -E_EMPTY) {
-                       if (ret < 0)
-                               return ret;
-                       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);
-                               return ret;
-                       }
-                       cf_argc = ret;
-                       ret = lls(lls_parse(cf_argc, cf_argv, CMD_PTR, &cf_lpr,
-                               &errctx));
-                       lls_free_argv(cf_argv);
-                       if (ret < 0) {
-                               PARA_ERROR_LOG("parse error in %s\n", cf);
-                               return ret;
-                       }
-                       ret = lls(lls_merge(lpr, cf_lpr, CMD_PTR, &merged_lpr, &errctx));
-                       lls_free_parse_result(cf_lpr, CMD_PTR);
-                       if (ret < 0)
-                               return ret;
-                       lls_free_parse_result(lpr, CMD_PTR);
-                       lpr = merged_lpr;
-                       loglevel = OPT_UINT32_VAL(LOGLEVEL);
-               }
-       }
+       ret = lsu_merge_config_file_options(NULL, "filter.conf",
+               &lpr, CMD_PTR, filter_suite, 0 /* default flags */);
+       if (ret < 0)
+               return ret;
+       loglevel = OPT_UINT32_VAL(LOGLEVEL);
        if (!OPT_GIVEN(FILTER)) {
                print_filter_list();
                exit(EXIT_SUCCESS);
@@ -147,7 +113,6 @@ int main(int argc, char *argv[])
        ret = lls(lls_parse(argc, argv, CMD_PTR, &lpr, &errctx));
        if (ret < 0)
                goto out;
-       loglevel = OPT_UINT32_VAL(LOGLEVEL);
        ret = parse_config();
        if (ret < 0)
                goto free_lpr;