5 #include "select.cmdline.h"
7 struct select_args_info select_conf;
9 struct interactive_command {
11 int (*handler)(char *);
14 #define INTERACTIVE_COMMANDS \
15 INTERACTIVE_COMMAND(dump) \
16 INTERACTIVE_COMMAND(set) \
17 INTERACTIVE_COMMAND(def) \
19 #define INTERACTIVE_COMMAND(name) \
20 static int icom_ ## name (char *line);
24 #undef INTERACTIVE_COMMAND
26 #define INTERACTIVE_COMMAND(_name) \
29 .handler = icom_ ## _name \
32 struct interactive_command icmds[] = {
37 static int read_input_line(char *line, size_t size)
39 return fgets(line, size, stdin)? 1 : -1;
42 static int icom_def(__a_unused char *line)
44 select_cmdline_parser_init(&select_conf);
48 static int icom_set(char *line)
50 struct select_cmdline_parser_params params = {
57 return select_cmdline_parser_string_ext(line, &select_conf, "select",
62 static int icom_dump(__a_unused char *line)
64 ERROR_LOG("dump: %s\n", select_conf.format_arg);
65 select_cmdline_parser_dump(stdout, &select_conf);
69 static int exec_interactive_command(char *line)
71 const char const *delim = "\t\n ";
73 char *cmd = adu_strdup(line + strspn(line, delim));
74 char *p = cmd + strcspn(cmd, delim);
79 for (i = 0; icmds[i].name; i++) {
80 ERROR_LOG("name: %s, cmd: %s.\n", icmds[i].name, cmd);
81 if (strcmp(icmds[i].name, cmd))
83 ERROR_LOG("exec cmd: %s, args: %s\n", cmd, p);
84 ret = icmds[i].handler(p);
91 int com_interactive(void)
96 while (read_input_line(line, sizeof(line)) >= 0) {
97 size_t len = strlen(line);
100 if (line[len - 1] == '\n')
101 line[len - 1] = '\0';
102 ret = exec_interactive_command(line);
104 printf("%s\n", adu_strerror(-ret));