diff options
| author | Quentin Young <qlyoung@cumulusnetworks.com> | 2016-07-22 19:04:16 +0000 |
|---|---|---|
| committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2016-07-22 19:04:16 +0000 |
| commit | 880e24a1e4cc78cb23ebdd72f2e5cea861cf8be2 (patch) | |
| tree | fefe79765d2c5932a4083e428843657b9d673edd /lib/grammar_sandbox.c | |
| parent | 18be0e599d1ba666e59a3d027e973eb41798f46f (diff) | |
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 <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/grammar_sandbox.c')
| -rw-r--r-- | lib/grammar_sandbox.c | 21 |
1 files changed, 11 insertions, 10 deletions
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, "<cr>\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, "<cr>"); + else + fprintf(stderr, "%s\n", describe_node(cnode, desc, 50)); + } + free(desc); } + list_free(result); return CMD_SUCCESS; } |
