From 880e24a1e4cc78cb23ebdd72f2e5cea861cf8be2 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Fri, 22 Jul 2016 19:04:16 +0000 Subject: lib: Reorganize some matching stuff Introduce new node type, END_GN, and remove is_leaf flags. Reorganize command_match.c & remove internal functions from command_match.h. Start rewriting command.h in command_new.h with changes for new backend. Signed-off-by: Quentin Young --- lib/grammar_sandbox.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'lib/grammar_sandbox.c') diff --git a/lib/grammar_sandbox.c b/lib/grammar_sandbox.c index fab78f3e21..24f882c89f 100644 --- a/lib/grammar_sandbox.c +++ b/lib/grammar_sandbox.c @@ -40,25 +40,26 @@ DEFUN (grammar_test_match, "command to match") { const char* command = argv_concat(argv, argc, 0); - struct list **result = match_command(nodegraph, FILTER_STRICT, command); - struct list *matched = result[0]; - struct list *next = result[1]; + struct list *result = match_command(nodegraph, FILTER_STRICT, command); - if (matched->count == 0) // the last token tried yielded no matches + if (result->count == 0) // invalid command fprintf(stderr, "%% Unknown command\n"); else { fprintf(stderr, "%% Matched full input, possible completions:\n"); + char* desc = malloc(50); struct listnode *node; struct graph_node *cnode; - // iterate through currently matched nodes to see if any are leaves - for (ALL_LIST_ELEMENTS_RO(matched,node,cnode)) - if (cnode->is_leaf) - fprintf(stderr, "\n"); // print possible next hops, if any - for (ALL_LIST_ELEMENTS_RO(next,node,cnode)) - fprintf(stderr, "%s\n",describe_node(cnode)); + for (ALL_LIST_ELEMENTS_RO(result,node,cnode)) { + if (cnode->type == END_GN) + fprintf(stderr, ""); + else + fprintf(stderr, "%s\n", describe_node(cnode, desc, 50)); + } + free(desc); } + list_free(result); return CMD_SUCCESS; } -- cgit v1.2.3