From dfe536f475a79e899cf2915a3ba602c92aee2263 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Thu, 4 May 2017 22:46:46 +0000 Subject: lib: fix 'list permutations' Cyclic graphs ftw Also remove graph pretty printer from permutations.c 'cause it's not really needed anymore Signed-off-by: Quentin Young --- lib/command.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'lib/command.c') diff --git a/lib/command.c b/lib/command.c index 993d6f9055..43b2c478a0 100644 --- a/lib/command.c +++ b/lib/command.c @@ -1584,6 +1584,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++) @@ -1595,8 +1599,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)) { @@ -1609,7 +1611,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)); } -- cgit v1.2.3