#include <assert.h>
#include <osl.h>
#include "gcc-compat.h"
+#include "select.cmdline.h"
/** debug loglevel, gets really noisy */
#define DEBUG 1
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);
#include "string.h"
#include "error.h"
#include "cmdline.h"
-#include "select.cmdline.h"
struct interactive_command {
const char *name;
.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)
#include "string.h"
#include "error.h"
#include "portable_io.h"
-#include "select.cmdline.h"
/** Global dir count. */
static uint64_t num_dirs;
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,
.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);