summaryrefslogtreecommitdiff
path: root/lib/command_match.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2016-08-10 15:04:21 +0000
committerQuentin Young <qlyoung@cumulusnetworks.com>2016-08-10 15:04:21 +0000
commiteaf46b79b6c771877b9289959bb6280518beaad2 (patch)
tree5a9c8bc780799156322b0646399e6d3549f4f353 /lib/command_match.c
parentb84f1d850aed50dea347ab5b99888bc85448604f (diff)
lib: Fix broken disambiguation on leader tokens
Fix incorrect assumption that the set of first tokens of all commands are perfectly unambiguous Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/command_match.c')
-rw-r--r--lib/command_match.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/lib/command_match.c b/lib/command_match.c
index b323bc5809..285a776a7c 100644
--- a/lib/command_match.c
+++ b/lib/command_match.c
@@ -91,17 +91,18 @@ match_command (struct graph_node *start,
{
matcher_rv = MATCHER_NO_MATCH;
- // call recursive matcher on each starting child
- for (unsigned int i = 0; i < vector_active (start->children); i++)
+ // prepend a dummy token to match that pesky start node
+ vector vvline = vector_init (vline->alloced + 1);
+ vector_set_index (vvline, 0, (void *) "dummy");
+ memcpy (vvline->index + 1, vline->index, sizeof (void *) * vline->alloced);
+ vvline->active = vline->active + 1;
+
+ if ((*argv = match_command_r (start, vvline, 0))) // successful match
{
- *argv = match_command_r (vector_slot (start->children, i), vline, 0);
- if (*argv) // successful match
- {
- struct graph_node *end = listgetdata (listtail (*argv));
- *el = end->element;
- assert (*el);
- break;
- }
+ list_delete_node (*argv, listhead (*argv));
+ struct graph_node *end = listgetdata (listtail (*argv));
+ *el = end->element;
+ assert (*el);
}
return matcher_rv;
@@ -344,6 +345,9 @@ min_match_level (enum node_type type)
{
switch (type)
{
+ // anything matches a start node, for the sake of recursion
+ case START_GN:
+ return no_match;
// allowing words to partly match enables command abbreviation
case WORD_GN:
return partly_match;