diff options
| author | David Lamparter <equinox@opensourcerouting.org> | 2017-07-14 13:07:30 +0200 |
|---|---|---|
| committer | David Lamparter <equinox@opensourcerouting.org> | 2017-07-14 13:07:30 +0200 |
| commit | 2d8270596a085e7a815cebaea21e17cba9e26111 (patch) | |
| tree | f9a559f654e7d704ecacc9dadedbe01868615610 /lib/grammar_sandbox.c | |
| parent | 625e016d14073dfefb69c0fa36cddb81fbe034ed (diff) | |
| parent | 905c15079393987f8cfdd55c30e7e1a3248c8c48 (diff) | |
Merge remote-tracking branch 'frr/master' into newline-redux
Lots of conflicts from CMD_WARNING_CONFIG_FAILED...
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/grammar_sandbox.c')
| -rw-r--r-- | lib/grammar_sandbox.c | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/lib/grammar_sandbox.c b/lib/grammar_sandbox.c index f6bc3e772c..81c2ca5c30 100644 --- a/lib/grammar_sandbox.c +++ b/lib/grammar_sandbox.c @@ -50,6 +50,12 @@ init_cmdgraph (struct vty *, struct graph **); /** shim interface commands **/ struct graph *nodegraph = NULL, *nodegraph_free = NULL; +#define check_nodegraph() \ + do { if (!nodegraph) { \ + vty_outln(vty, "nodegraph not initialized"); \ + return CMD_WARNING; \ + } } while (0) + DEFUN (grammar_test, grammar_test_cmd, "grammar parse LINE...", @@ -57,6 +63,8 @@ DEFUN (grammar_test, "parse a command\n" "command to pass to new parser\n") { + check_nodegraph(); + int idx_command = 2; // make a string from tokenized command line char *command = argv_concat (argv, argc, idx_command); @@ -85,6 +93,8 @@ DEFUN (grammar_test_complete, "attempt to complete input on DFA\n" "command to complete\n") { + check_nodegraph(); + int idx_command = 2; char *cmdstr = argv_concat (argv, argc, idx_command); if (!cmdstr) @@ -143,6 +153,8 @@ DEFUN (grammar_test_match, "attempt to match input on DFA\n" "command to match\n") { + check_nodegraph(); + int idx_command = 2; if (argv[2]->arg[0] == '#') return CMD_SUCCESS; @@ -209,6 +221,8 @@ DEFUN (grammar_test_doc, "Test function for docstring\n" "Command end\n") { + check_nodegraph(); + // create cmd_element with docstring struct cmd_element *cmd = XCALLOC (MTYPE_CMD_TOKENS, sizeof (struct cmd_element)); cmd->string = XSTRDUP (MTYPE_CMD_TOKENS, "test docstring <example|selector follow> (1-255) end VARIABLE [OPTION|set lol] . VARARG"); @@ -243,12 +257,10 @@ DEFUN (grammar_test_show, "print current accumulated DFA\n" "include docstrings\n") { - struct graph_node *stack[MAXDEPTH]; + check_nodegraph(); - if (!nodegraph) - vty_out(vty, "nodegraph uninitialized\r\n"); - else - pretty_print_graph (vty, vector_slot (nodegraph->nodes, 0), 0, argc >= 3, stack, 0); + struct graph_node *stack[MAXDEPTH]; + pretty_print_graph (vty, vector_slot (nodegraph->nodes, 0), 0, argc >= 3, stack, 0); return CMD_SUCCESS; } @@ -259,14 +271,12 @@ DEFUN (grammar_test_dot, "print current graph for dot\n" ".dot filename\n") { + check_nodegraph(); + struct graph_node *stack[MAXDEPTH]; struct graph_node *visited[MAXDEPTH*MAXDEPTH]; size_t vpos = 0; - if (!nodegraph) { - vty_out(vty, "nodegraph uninitialized\r\n"); - return CMD_SUCCESS; - } FILE *ofd = fopen(argv[2]->arg, "w"); if (!ofd) { vty_out(vty, "%s: %s\r\n", argv[2]->arg, strerror(errno)); @@ -389,7 +399,7 @@ DEFUN (grammar_findambig, if (!scan && !nodegraph) { vty_out(vty, "nodegraph uninitialized\r\n"); - return CMD_WARNING; + return CMD_WARNING_CONFIG_FAILED; } do { @@ -432,7 +442,7 @@ DEFUN (grammar_findambig, if (scan) nodegraph = NULL; - return ambig == 0 ? CMD_SUCCESS : CMD_WARNING; + return ambig == 0 ? CMD_SUCCESS : CMD_WARNING_CONFIG_FAILED; } DEFUN (grammar_init_graph, @@ -466,7 +476,7 @@ DEFUN (grammar_access, if (!cnode) { vty_out (vty, "%% no such node\n"); - return CMD_WARNING; + return CMD_WARNING_CONFIG_FAILED; } vty_out (vty, "node %d\n", (int)cnode->node); @@ -476,8 +486,6 @@ DEFUN (grammar_access, /* this is called in vtysh.c to set up the testing shim */ void grammar_sandbox_init(void) { - init_cmdgraph (NULL, &nodegraph); - // install all enable elements install_element (ENABLE_NODE, &grammar_test_cmd); install_element (ENABLE_NODE, &grammar_test_show_cmd); |
