It's no good to spam the user with syntax errors on empty lines.
In popular shells, the set command prints the current environment
if called without arguments. So do the same and kill the dump command.
+#include <ctype.h> /* isspace() */
+
#include "adu.h"
#include "format.h"
#include "select.h"
#include "adu.h"
#include "format.h"
#include "select.h"
static struct format_info *fi;
#define INTERACTIVE_COMMANDS \
static struct format_info *fi;
#define INTERACTIVE_COMMANDS \
- 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(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")
+ INTERACTIVE_COMMAND(run, "start the query according to the current configuration")
#define INTERACTIVE_COMMAND(name, desc) \
#define INTERACTIVE_COMMAND(name, desc) \
.check_ambiguity = 0,
.print_errors = 1
};
.check_ambiguity = 0,
.print_errors = 1
};
- return parse_select_options(line, ¶ms, &admissible_uids, &fi);
-}
+ if (!line) {
+ select_cmdline_parser_dump(stdout, &select_conf);
+ return 1;
+ }
-static int icom_dump(__a_unused char *line)
-{
- select_cmdline_parser_dump(stdout, &select_conf);
- return 1;
+ return parse_select_options(line, ¶ms, &admissible_uids, &fi);
}
static int exec_interactive_command(char *line)
{
}
static int exec_interactive_command(char *line)
{
- const char const *delim = "\t\n ";
+ const char const *delim = "\t\n\f\r\v ";
- char *cmd = adu_strdup(line + strspn(line, delim));
- char *p = cmd + strcspn(cmd, delim);
+ size_t len;
+
+ if (!line || !*line)
+ return 1;
+ len = strlen(line);
- if (*p == '\0')
- p = NULL;
+ while (len && isspace(line[len - 1])) {
+ line[len - 1] = '\0';
+ len--;
+ }
+ if (!len)
+ return 1;
+ line += strspn(line, delim); /* skip initial whitespace */
+ if (!*line)
+ return 1;
+ /* OK, we have a non-empty line */
+ cmd = adu_strdup(line);
+ args = cmd + strcspn(cmd, delim);
+ if (!*args)
+ args = NULL;
+ *args = '\0';
+ args++;
+ /* let p point to the next non-whitespace char */
+ args += strspn(args, delim);
+ if (!*args)
+ args = NULL;
+ DEBUG_LOG("name: %s, args: %s.\n", cmd, args);
for (i = 0; icmds[i].name; i++) {
for (i = 0; icmds[i].name; i++) {
- ERROR_LOG("name: %s, cmd: %s.\n", icmds[i].name, cmd);
if (strcmp(icmds[i].name, cmd))
continue;
if (strcmp(icmds[i].name, cmd))
continue;
- ERROR_LOG("exec cmd: %s, args: %s\n", cmd, p);
- ret = icmds[i].handler(p);
+ INFO_LOG("exec cmd: %s, args: %s\n", cmd, args);
+ ret = icmds[i].handler(args);
select_cmdline_parser_init(&select_conf);
while (read_input_line(line, sizeof(line)) >= 0) {
select_cmdline_parser_init(&select_conf);
while (read_input_line(line, sizeof(line)) >= 0) {
- size_t len = strlen(line);
- if (!len)
- continue;
- if (line[len - 1] == '\n')
- line[len - 1] = '\0';
ret = exec_interactive_command(line);
if (ret < 0)
printf("%s\n", adu_strerror(-ret));
ret = exec_interactive_command(line);
if (ret < 0)
printf("%s\n", adu_strerror(-ret));