From e4e63cb6ebcddfaeea04f85ad28b39ed3df3d605 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 af13542bc3..98ff933177 100644 --- a/lib/command.c +++ b/lib/command.c @@ -1590,6 +1590,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++) @@ -1601,8 +1605,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)) { @@ -1615,7 +1617,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