Avoid warning about sys/sysctl.h on glibc-2.30.
[paraslash.git] / filter.c
index 156e049..d4a2423 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -1,8 +1,4 @@
-/*
- * Copyright (C) 2005 Andre Noll <maan@tuebingen.mpg.de>
- *
- * Licensed under the GPL v2. For licencing details see COPYING.
- */
+/* Copyright (C) 2005 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
 
 /** \file filter.c The stand-alone filter program. */
 
@@ -13,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"
@@ -75,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);
@@ -151,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;