From 99fc209e6a465ccb6ea96ef81116e8d931e2261c Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Tue, 14 May 2013 19:49:13 +0200 Subject: cli: complete basic functionality of the interactive mode This patch adds missing code to get basic interactive mode operative via `nft -i', including parsing, evaluation, command execution via netlink and error reporting. Autocomplete is not yet implemented. Signed-off-by: Pablo Neira Ayuso --- src/cli.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/cli.c') diff --git a/src/cli.c b/src/cli.c index e302dfa8..a5a891e2 100644 --- a/src/cli.c +++ b/src/cli.c @@ -32,6 +32,7 @@ static const struct input_descriptor indesc_cli = { .type = INDESC_CLI, + .name = "", }; static struct parser_state *state; @@ -86,6 +87,7 @@ static void cli_complete(char *line) { const HIST_ENTRY *hist; const char *c; + LIST_HEAD(msgs); line = cli_append_multiline(line); if (line == NULL) @@ -102,10 +104,10 @@ static void cli_complete(char *line) if (hist == NULL || strcmp(hist->line, line)) add_history(line); + parser_init(state, &msgs); scanner_push_buffer(scanner, &indesc_cli, line); - nft_parse(scanner, state); - - erec_print_list(stdout, state->msgs); + nft_run(scanner, state, &msgs); + erec_print_list(stdout, &msgs); xfree(line); } @@ -140,7 +142,7 @@ void __fmtstring(1, 0) cli_display(const char *fmt, va_list ap) rl_forced_update_display(); } -int cli_init(void *_scanner, struct parser_state *_state) +int cli_init(struct parser_state *_state) { const char *home; @@ -159,8 +161,8 @@ int cli_init(void *_scanner, struct parser_state *_state) read_history(histfile); history_set_pos(history_length); - scanner = _scanner; state = _state; + scanner = scanner_init(state); while (!eof) rl_callback_read_char(); -- cgit v1.2.3