summaryrefslogtreecommitdiff
path: root/lib/command_match.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2016-12-05 20:04:08 +0100
committerDavid Lamparter <equinox@opensourcerouting.org>2016-12-05 20:04:08 +0100
commit7ddcfca4fb5246c5e211f7e37d98a8c9a51b4e70 (patch)
treeea8dead406e7963c4b8283477daea4d5224845ac /lib/command_match.c
parent53dc2b05c76f4f5cd6a72373fb241afdcedb2ee1 (diff)
parent54c5dce6a5e46717ad52c80f2dc99fc36a372e28 (diff)
Merge branch 'queue/osr/vtysh-generic'
WARNING: Merge contains nontrivial fixups in vrf_cmd handling. Conflicts: lib/if.c zebra/interface.c
Diffstat (limited to 'lib/command_match.c')
-rw-r--r--lib/command_match.c79
1 files changed, 39 insertions, 40 deletions
diff --git a/lib/command_match.c b/lib/command_match.c
index 06a50656b6..25309654f3 100644
--- a/lib/command_match.c
+++ b/lib/command_match.c
@@ -25,9 +25,17 @@
#include <zebra.h>
#include "command_match.h"
-#include "command_parse.h"
#include "memory.h"
+#ifdef TRACE_MATCHER
+#define TM 1
+#else
+#define TM 0
+#endif
+
+#define trace_matcher(...) \
+ do { if (TM) fprintf (stderr, __VA_ARGS__); } while (0);
+
DEFINE_MTYPE_STATIC(LIB, CMD_TOKENS, "Command Tokens")
/* matcher helper prototypes */
@@ -116,12 +124,12 @@ command_match (struct graph *cmdgraph,
assert (*el);
}
-#ifdef TRACE_MATCHER
- if (!*el)
- fprintf (stdout, "No match\n");
- else
- fprintf (stdout, "Matched command\n->string %s\n->desc %s\n", (*el)->string, (*el)->doc);
-#endif
+ if (!*el) {
+ trace_matcher ("No match");
+ }
+ else {
+ trace_matcher ("Matched command\n->string %s\n->desc %s\n", (*el)->string, (*el)->doc);
+ }
// free the leader token we alloc'd
XFREE (MTYPE_TMP, vector_slot (vvline, 0));
@@ -194,28 +202,26 @@ command_match_r (struct graph_node *start, vector vline, unsigned int n)
// get the current operating input token
char *input_token = vector_slot (vline, n);
-#ifdef TRACE_MATCHER
- fprintf (stdout, "\"%-20s\" matches \"%-30s\" ? ", input_token, token->text);
+ trace_matcher ("\"%-20s\" matches \"%-30s\" ? ", input_token, token->text);
enum match_type mt = match_token (token, input_token);
- fprintf (stdout, "min: %d - ", minmatch);
+ trace_matcher ("min: %d - ", minmatch);
switch (mt)
{
case trivial_match:
- fprintf (stdout, "trivial_match ");
+ trace_matcher ("trivial_match ");
break;
case no_match:
- fprintf (stdout, "no_match ");
+ trace_matcher ("no_match ");
break;
case partly_match:
- fprintf (stdout, "partly_match ");
+ trace_matcher ("partly_match ");
break;
case exact_match:
- fprintf (stdout, "exact_match ");
+ trace_matcher ("exact_match ");
break;
}
- if (mt >= minmatch) fprintf (stdout, " MATCH");
- fprintf (stdout, "\n");
-#endif
+ if (mt >= minmatch) { trace_matcher (" MATCH") };
+ trace_matcher ("\n");
// if we don't match this node, die
if (match_token (token, input_token) < minmatch)
@@ -345,37 +351,35 @@ command_complete (struct graph *graph,
continue;
enum match_type minmatch = min_match_level (token->type);
-#ifdef TRACE_MATCHER
- fprintf (stdout, "\"%s\" matches \"%s\" (%d) ? ", input_token, token->text, token->type);
-#endif
+ trace_matcher ("\"%s\" matches \"%s\" (%d) ? ", input_token, token->text, token->type);
switch (match_token (token, input_token))
{
case trivial_match:
-#ifdef TRACE_MATCHER
- fprintf (stdout, "trivial_match\n");
-#endif
+ trace_matcher ("trivial_match\n");
+ assert(idx == vector_active (vline) - 1);
+ listnode_add (next, gn);
+ break;
case partly_match:
-#ifdef TRACE_MATCHER
- fprintf (stdout, "partly_match\n");
-#endif
+ trace_matcher ("partly_match\n");
+ // last token on line is partial and
+ // not a space
if (idx == vector_active (vline) - 1)
{
listnode_add (next, gn);
break;
}
- if (minmatch > partly_match)
- break;
+ if (minmatch <= partly_match)
+ add_nexthops (next, gn);
+
+ break;
case exact_match:
-#ifdef TRACE_MATCHER
- fprintf (stdout, "exact_match\n");
-#endif
+ trace_matcher ("exact_match\n");
add_nexthops (next, gn);
+ listnode_add (next, gn);
break;
default:
-#ifdef TRACE_MATCHER
- fprintf (stdout, "no_match\n");
-#endif
+ trace_matcher ("no_match\n");
break;
}
}
@@ -855,14 +859,9 @@ match_word (struct cmd_token *token, const char *word)
return no_match;
}
-#define VARIABLE_ALPHABET \
-"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890:/._-"
-
static enum match_type
match_variable (struct cmd_token *token, const char *word)
{
assert (token->type == VARIABLE_TKN);
-
- return strlen (word) == strspn(word, VARIABLE_ALPHABET) ?
- exact_match : no_match;
+ return exact_match;
}