summaryrefslogtreecommitdiffstats
path: root/lib/grammar_sandbox.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2016-07-21 23:38:03 +0200
committerQuentin Young <qlyoung@cumulusnetworks.com>2016-07-21 23:38:03 +0200
commit18be0e599d1ba666e59a3d027e973eb41798f46f (patch)
tree2d813d4a693a8af73e405aaec147e225c72b61ec /lib/grammar_sandbox.c
parentlib: Break up functions, begin matcher (diff)
downloadfrr-18be0e599d1ba666e59a3d027e973eb41798f46f.tar.xz
frr-18be0e599d1ba666e59a3d027e973eb41798f46f.zip
lib: Mostly complete matcher
Input matching and completions works. Still some rough edges. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/grammar_sandbox.c')
-rw-r--r--lib/grammar_sandbox.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/lib/grammar_sandbox.c b/lib/grammar_sandbox.c
index 1e6a76c69..fab78f3e2 100644
--- a/lib/grammar_sandbox.c
+++ b/lib/grammar_sandbox.c
@@ -2,29 +2,12 @@
#include "command_graph.h"
#include "command_parse.h"
#include "command_match.h"
+#include "linklist.h"
#define GRAMMAR_STR "CLI grammar sandbox\n"
struct graph_node * nodegraph;
-/*
-char* combine_vararg(char* argv, int argc) {
- size_t linesize = 0;
- for (int i = 0; i < argc; i++)
- linesize += strlen(argv[i]) + 1;
-
- char* cat = malloc(linesize);
- cat[0] = '\0';
- for (int i = 0; i < argc; i++) {
- strcat(cat, argv[i]);
- if (i != argc)
- strcat(cat, " ");
- }
-
- return cat;
-}
-*/
-
DEFUN (grammar_test,
grammar_test_cmd,
"grammar parse .COMMAND",
@@ -57,7 +40,26 @@ DEFUN (grammar_test_match,
"command to match")
{
const char* command = argv_concat(argv, argc, 0);
- match_command(nodegraph, FILTER_STRICT, command);
+ struct list **result = match_command(nodegraph, FILTER_STRICT, command);
+ struct list *matched = result[0];
+ struct list *next = result[1];
+
+ if (matched->count == 0) // the last token tried yielded no matches
+ fprintf(stderr, "%% Unknown command\n");
+ else
+ {
+ fprintf(stderr, "%% Matched full input, possible completions:\n");
+ 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));
+ }
+
return CMD_SUCCESS;
}