Handle select help options properly.
authorAndre Noll <maan@systemlinux.org>
Wed, 2 Jul 2008 16:19:07 +0000 (18:19 +0200)
committerAndre Noll <maan@systemlinux.org>
Wed, 2 Jul 2008 16:19:07 +0000 (18:19 +0200)
The old code never printed out the help texts.

adu.c
adu.h
interactive.c
select.c

diff --git a/adu.c b/adu.c
index 02bfa30..47eee77 100644 (file)
--- a/adu.c
+++ b/adu.c
@@ -8,7 +8,6 @@
 #include "string.h"
 #include "error.h"
 #include "portable_io.h"
-#include "select.cmdline.h"
 
 DEFINE_ERRLIST;
 int osl_errno;
diff --git a/adu.h b/adu.h
index 2a15457..8e62969 100644 (file)
--- a/adu.h
+++ b/adu.h
@@ -21,6 +21,7 @@
 #include <assert.h>
 #include <osl.h>
 #include "gcc-compat.h"
+#include "select.cmdline.h"
 
 /** debug loglevel, gets really noisy */
 #define DEBUG 1
@@ -194,6 +195,8 @@ int for_each_admissible_user(int (*func)(struct user_info *, void *),
 void sort_hash_table(int (*comp)(const void *, const void *));
 
 /* select.c */
+int parse_select_options(char *string, struct select_cmdline_parser_params *params,
+               struct uid_range **admissible_uids);
 int run_select_query(struct uid_range *admissible_uids);
 int com_select(void);
 
index 494a4f8..295be37 100644 (file)
@@ -2,7 +2,6 @@
 #include "string.h"
 #include "error.h"
 #include "cmdline.h"
-#include "select.cmdline.h"
 
 struct interactive_command {
        const char *name;
@@ -75,10 +74,7 @@ static int icom_set(char *line)
                .check_ambiguity = 0,
                .print_errors = 1
        };
-       if (select_cmdline_parser_string_ext(line, &select_conf, "select",
-               &params))
-               return -E_SYNTAX;
-       return parse_uid_arg(select_conf.uid_arg, &admissible_uids);
+       return parse_select_options(line, &params, &admissible_uids);
 }
 
 static int icom_dump(__a_unused char *line)
index 0530257..943b8fd 100644 (file)
--- a/select.c
+++ b/select.c
@@ -14,7 +14,6 @@
 #include "string.h"
 #include "error.h"
 #include "portable_io.h"
-#include "select.cmdline.h"
 
 /** Global dir count. */
 static uint64_t num_dirs;
@@ -676,12 +675,40 @@ out:
        return ret;
 }
 
-int com_select(void)
+/* return: < 0: error, >0: OK, == 0: help given */
+int parse_select_options(char *string, struct select_cmdline_parser_params *params,
+               struct uid_range **admissible_uids)
 {
        int ret;
+       const char **line;
+
+       if (select_cmdline_parser_string_ext(string, &select_conf, "select",
+                       params))
+               return -E_SYNTAX;
+       ret = parse_uid_arg(select_conf.uid_arg, admissible_uids);
+       if (ret < 0)
+               return ret;
+       if (!select_conf.help_given && !select_conf.detailed_help_given)
+               return 1;
+
+       line = select_conf.detailed_help_given?
+               select_args_info_detailed_help : select_args_info_help;
+       if (!output_file)
+               output_file = stdout;
+       for (; *line; line++) {
+               ret = output("%s\n", *line);
+               if (ret < 0)
+                       return ret;
+       }
+       return 0;
+}
+
+int com_select(void)
+{
        struct uid_range *admissible_uids = NULL;
 
        if (conf.select_options_given) {
+               int ret;
                struct select_cmdline_parser_params params = {
                        .override = 1,
                        .initialize = 1,
@@ -689,12 +716,9 @@ int com_select(void)
                        .check_ambiguity = 1,
                        .print_errors = 1
                };
-
-               if (select_cmdline_parser_string_ext(conf.select_options_arg,
-                       &select_conf, "select", &params))
-                       return -E_SYNTAX;
-               ret = parse_uid_arg(select_conf.uid_arg, &admissible_uids);
-               if (ret < 0)
+               ret = parse_select_options(conf.select_options_arg, &params,
+                       &admissible_uids);
+               if (ret <= 0) /* do not run query if help was given */
                        return ret;
        }
        return run_select_query(admissible_uids);