X-Git-Url: http://git.tuebingen.mpg.de/?p=adu.git;a=blobdiff_plain;f=interactive.c;h=9460877e344e8f8452b0f0d20f1d6ceef83dd39e;hp=a35a82b3867b75bff62ec44fb6da5592954b02cf;hb=e584cd6d5a3782ddeb6640f69534ab1664da2605;hpb=99eaf79ebdb45f935eb9d8b60cc0889e09d5b6df diff --git a/interactive.c b/interactive.c index a35a82b..9460877 100644 --- a/interactive.c +++ b/interactive.c @@ -2,14 +2,24 @@ #include "adu.h" #include "format.h" -#include "select.h" +#include "user.h" #include "string.h" +#include "select.cmdline.h" +#include "select.h" #include "error.h" -#include "cmdline.h" +/** + * Describes one valid command for interactive mode. + * + * When invoked in interactive mode, adu reads commands from stdin. There's a + * static array of all such commands. + */ struct interactive_command { + /** The name of the command. */ const char *name; + /** Pointer to The function that is being executed. */ int (*handler)(char *); + /** Help text. */ const char *desc; }; @@ -65,11 +75,17 @@ static int icom_help(__a_unused char *line) void print_interactive_help(void) { - icom_help(NULL); + struct interactive_command *c; + FOR_EACH_COMMAND(c) + fprintf(stdout, "\t%s\t%s\n", c->name, c->desc); } static int icom_reset(__a_unused char *line) { + free_format_info(fi); + fi = NULL; + free(admissible_uids); + admissible_uids = NULL; select_cmdline_parser_init(&select_conf); return 1; } @@ -88,6 +104,10 @@ static int icom_set(char *line) return 1; } + free_format_info(fi); + fi = NULL; + free(admissible_uids); + admissible_uids = NULL; return parse_select_options(line, ¶ms, &admissible_uids, &fi); } @@ -113,6 +133,8 @@ static int exec_interactive_command(char *line) if (!*line) return 1; /* OK, we have a non-empty line */ + if (*line == '#') + return 1; cmd = adu_strdup(line); args = cmd + strcspn(cmd, delim); if (!*args) @@ -143,6 +165,7 @@ int com_interactive(void) int ret = 1; select_cmdline_parser_init(&select_conf); + ret = parse_select_options(NULL, NULL, &admissible_uids, &fi); while (read_input_line(line, sizeof(line)) >= 0) { ret = exec_interactive_command(line); if (ret < 0)