#include "adu.h"
+#include "format.h"
+#include "select.h"
#include "string.h"
#include "error.h"
#include "cmdline.h"
-#include "select.cmdline.h"
-
-struct select_args_info select_conf;
struct interactive_command {
const char *name;
int (*handler)(char *);
+ const char *desc;
};
+static struct uid_range *admissible_uids;
+static struct format_info *fi;
+
#define INTERACTIVE_COMMANDS \
- INTERACTIVE_COMMAND(dump) \
- INTERACTIVE_COMMAND(set) \
- INTERACTIVE_COMMAND(def) \
+ INTERACTIVE_COMMAND(dump, "dump the current configuration") \
+ INTERACTIVE_COMMAND(set, "change the current configuration") \
+ INTERACTIVE_COMMAND(reset, "reset configuration to defaults") \
+ INTERACTIVE_COMMAND(help, "show list of commands and one-line descriptions") \
+ INTERACTIVE_COMMAND(run, "start the query according to the current options")
+
-#define INTERACTIVE_COMMAND(name) \
+#define INTERACTIVE_COMMAND(name, desc) \
static int icom_ ## name (char *line);
INTERACTIVE_COMMANDS
#undef INTERACTIVE_COMMAND
-#define INTERACTIVE_COMMAND(_name) \
+#define INTERACTIVE_COMMAND(_name, _desc) \
{ \
.name = #_name, \
- .handler = icom_ ## _name \
+ .handler = icom_ ## _name, \
+ .desc = _desc \
},
struct interactive_command icmds[] = {
{.name = NULL}
};
+#define FOR_EACH_COMMAND(c) for (c = icmds; c->name; c++)
+
static int read_input_line(char *line, size_t size)
{
return fgets(line, size, stdin)? 1 : -1;
}
-static int icom_def(__a_unused char *line)
+static int icom_run(__a_unused char *line)
+{
+ return run_select_query(admissible_uids, fi);
+}
+
+static int icom_help(__a_unused char *line)
+{
+ struct interactive_command *c;
+
+ FOR_EACH_COMMAND(c)
+ fprintf(stdout, "%s\t%s\n", c->name, c->desc);
+ return 1;
+}
+
+void print_interactive_help(void)
+{
+ icom_help(NULL);
+}
+
+static int icom_reset(__a_unused char *line)
{
select_cmdline_parser_init(&select_conf);
return 1;
.check_ambiguity = 0,
.print_errors = 1
};
- return select_cmdline_parser_string_ext(line, &select_conf, "select",
- ¶ms)?
- -E_SYNTAX : 1;
+ return parse_select_options(line, ¶ms, &admissible_uids, &fi);
}
static int icom_dump(__a_unused char *line)
{
- ERROR_LOG("dump: %s\n", select_conf.format_arg);
select_cmdline_parser_dump(stdout, &select_conf);
return 1;
}
char *p = cmd + strcspn(cmd, delim);
int ret = -E_SYNTAX;
- *p = '\0';
- p++;
+ if (*p == '\0')
+ p = NULL;
+ else {
+ *p = '\0';
+ p++;
+ }
for (i = 0; icmds[i].name; i++) {
ERROR_LOG("name: %s, cmd: %s.\n", icmds[i].name, cmd);
if (strcmp(icmds[i].name, cmd))
char line[255];
int ret = 1;
+ select_cmdline_parser_init(&select_conf);
while (read_input_line(line, sizeof(line)) >= 0) {
size_t len = strlen(line);
if (!len)