summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2017-05-05 00:46:46 +0200
committerQuentin Young <qlyoung@cumulusnetworks.com>2017-05-05 02:19:00 +0200
commite4e63cb6ebcddfaeea04f85ad28b39ed3df3d605 (patch)
tree101801eb1ff2ef8cc6dd19bf0df9def17af49006 /tools
parentMerge remote-tracking branch 'origin/stable/3.0' (diff)
downloadfrr-e4e63cb6ebcddfaeea04f85ad28b39ed3df3d605.tar.xz
frr-e4e63cb6ebcddfaeea04f85ad28b39ed3df3d605.zip
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 <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/permutations.c57
1 files changed, 21 insertions, 36 deletions
diff --git a/tools/permutations.c b/tools/permutations.c
index 0ca980b25..6e1a37981 100644
--- a/tools/permutations.c
+++ b/tools/permutations.c
@@ -48,7 +48,6 @@ int main (int argc, char *argv[])
command_parse_format (graph, cmd);
permute (vector_slot (graph->nodes, 0));
- pretty_print_graph (vector_slot (graph->nodes, 0), 0);
}
void
@@ -57,56 +56,42 @@ permute (struct graph_node *start)
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++)
{
struct graph_node *gn = vector_slot (start->to, i);
struct cmd_token *tok = gn->data;
- if (tok->type == END_TKN)
+ if (tok->attr == CMD_ATTR_HIDDEN ||
+ tok->attr == CMD_ATTR_DEPRECATED)
+ continue;
+ else if (tok->type == END_TKN || gn == start)
{
- struct graph_node *gnn;
- struct listnode *ln;
+ fprintf (stdout, " ");
for (ALL_LIST_ELEMENTS_RO (position,ln,gnn))
{
struct cmd_token *tt = gnn->data;
if (tt->type < SPECIAL_TKN)
- fprintf (stdout, "%s ", tt->text);
+ fprintf (stdout, " %s", tt->text);
}
+ if (gn == start)
+ fprintf (stdout, "...");
fprintf (stdout, "\n");
}
else
- permute (gn);
- }
- list_delete_node (position, listtail(position));
-}
-
-void
-pretty_print_graph (struct graph_node *start, int level)
-{
- // print this node
- struct cmd_token *tok = start->data;
- fprintf (stdout, "%s[%d] ", tok->text, tok->type);
-
- int numto = vector_active (start->to);
- if (numto)
{
- if (numto > 1)
- fprintf (stdout, "\n");
- for (unsigned int i = 0; i < vector_active (start->to); i++)
- {
- struct graph_node *adj = vector_slot (start->to, i);
- // if we're listing multiple children, indent!
- if (numto > 1)
- for (int j = 0; j < level+1; j++)
- fprintf (stdout, " ");
- // if this node is a vararg, just print *
- if (adj == start)
- fprintf (stdout, "*");
- else
- pretty_print_graph (adj, numto > 1 ? level+1 : level);
- }
+ 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);
}
- else
- fprintf(stdout, "\n");
+ }
+ list_delete_node (position, listtail(position));
}