diff options
| author | David Lamparter <equinox@diac24.net> | 2017-05-09 17:54:22 +0200 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-05-09 17:54:22 +0200 | 
| commit | 92fd8a7d59879743ac2393d6660dc4dd06c67365 (patch) | |
| tree | d2be5e0db385c9f7ca49a2610ee70d2629d9541b /lib | |
| parent | 54f12d6f77c4069a7c636f95e563c030a5345d5b (diff) | |
| parent | e4e63cb6ebcddfaeea04f85ad28b39ed3df3d605 (diff) | |
Merge pull request #468 from qlyoung/fix-list-perm
lib: fix 'list permutations'
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/command.c | 16 | 
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/command.c b/lib/command.c index ba1e0bcec3..11c9a0968b 100644 --- a/lib/command.c +++ b/lib/command.c @@ -1592,6 +1592,10 @@ permute (struct graph_node *start, struct vty *vty)    static struct list *position = NULL;    if (!position) position = list_new (); +  struct cmd_token *stok = start->data; +  struct graph_node *gnn; +  struct listnode *ln; +    // recursive dfs    listnode_add (position, start);    for (unsigned int i = 0; i < vector_active (start->to); i++) @@ -1603,8 +1607,6 @@ permute (struct graph_node *start, struct vty *vty)        continue;      else if (tok->type == END_TKN || gn == start)      { -      struct graph_node *gnn; -      struct listnode *ln;        vty_out (vty, " ");        for (ALL_LIST_ELEMENTS_RO (position,ln,gnn))        { @@ -1617,7 +1619,15 @@ permute (struct graph_node *start, struct vty *vty)        vty_out (vty, VTY_NEWLINE);      }      else -      permute (gn, vty); +    { +      bool skip = false; +      if (stok->type == FORK_TKN && tok->type != FORK_TKN) +        for (ALL_LIST_ELEMENTS_RO (position, ln, gnn)) +           if (gnn == gn && (skip = true)) +             break; +      if (!skip) +        permute (gn, vty); +    }    }    list_delete_node (position, listtail(position));  }  | 
