]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: fix 'list permutations' 468/head
authorQuentin Young <qlyoung@cumulusnetworks.com>
Thu, 4 May 2017 22:46:46 +0000 (22:46 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Fri, 5 May 2017 00:19:00 +0000 (00:19 +0000)
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>
lib/command.c
tools/permutations.c

index af13542bc35c186ac03966029c122a88dacb042c..98ff933177efdb588d93f43c61f616735b42a8a1 100644 (file)
@@ -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));
 }
index 0ca980b2595b186c06a6f1e633b80dc3049da2a6..6e1a37981a7b4044b3bd639346609313b49c0e04 100644 (file)
@@ -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));
 }