From: Andre Noll Date: Wed, 2 Jul 2008 16:19:07 +0000 (+0200) Subject: Handle select help options properly. X-Git-Tag: v0.0.4~38^2 X-Git-Url: http://git.tuebingen.mpg.de/?p=adu.git;a=commitdiff_plain;h=1f948aa655d9a7389477baa1489f86e548ec064e Handle select help options properly. The old code never printed out the help texts. --- diff --git a/adu.c b/adu.c index 02bfa30..47eee77 100644 --- 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 --- a/adu.h +++ b/adu.h @@ -21,6 +21,7 @@ #include #include #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); diff --git a/interactive.c b/interactive.c index 494a4f8..295be37 100644 --- a/interactive.c +++ b/interactive.c @@ -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", - ¶ms)) - return -E_SYNTAX; - return parse_uid_arg(select_conf.uid_arg, &admissible_uids); + return parse_select_options(line, ¶ms, &admissible_uids); } static int icom_dump(__a_unused char *line) diff --git a/select.c b/select.c index 0530257..943b8fd 100644 --- 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", ¶ms)) - return -E_SYNTAX; - ret = parse_uid_arg(select_conf.uid_arg, &admissible_uids); - if (ret < 0) + ret = parse_select_options(conf.select_options_arg, ¶ms, + &admissible_uids); + if (ret <= 0) /* do not run query if help was given */ return ret; } return run_select_query(admissible_uids);