X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=select.c;h=943b8fde59d8810a108c3a4026d17ef6c225ffac;hb=0a8f1be6ca96c7050f02129bb275c926671007f4;hp=05302570ff5ba740731c3ba815c62b5f8da2e1fc;hpb=bab4b8635b3e048e1d7c9a914ddace3433f02164;p=adu.git 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);