]> git.puffer.fish Git - matthieu/frr.git/commitdiff
tools: add copyright header & usage to permutations
authorQuentin Young <qlyoung@cumulusnetworks.com>
Sun, 2 Oct 2016 19:30:08 +0000 (19:30 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Sun, 2 Oct 2016 19:30:08 +0000 (19:30 +0000)
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
tools/.gitignore
tools/permutations.c

index 60c4c0650f9dc51e892314b4624743029b3c9c89..066b0887aed224570b9aef7b66448a8272361141 100644 (file)
@@ -5,3 +5,4 @@
 *.loT
 .libs
 *.o
+permutations
index 48627812966c854cd37c5e5a856b696bd24f43a1..819305e54e47376ecc58c35e81b5e3da64c38e27 100644 (file)
@@ -1,13 +1,44 @@
+/*
+ * Generates all possible matching inputs for a command string.
+ * --
+ * Copyright (C) 2016 Cumulus Networks, Inc.
+ *
+ * This file is part of GNU Zebra.
+ *
+ * GNU Zebra is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * GNU Zebra is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Zebra; see the file COPYING.  If not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
 #include "command.h"
 #include "graph.h"
 #include "command_parse.h"
 #include "vector.h"
 
+#define USAGE "usage: permutations <cmdstr>"
+
 void
-pretty_print_graph (struct graph_node *);
+permute (struct graph_node *);
 
 int main (int argc, char *argv[])
 {
+  if (argc < 2)
+  {
+    fprintf(stdout, USAGE"\n");
+    exit(EXIT_SUCCESS);
+  }
+
   struct cmd_element *cmd = calloc (1, sizeof (struct cmd_element));
   cmd->string = strdup(argv[1]);
 
@@ -16,18 +47,11 @@ int main (int argc, char *argv[])
   graph_new_node (graph, token, NULL);
   command_parse_format (graph, cmd);
 
-  pretty_print_graph (vector_slot (graph->nodes, 0));
+  permute (vector_slot (graph->nodes, 0));
 }
 
-/**
- * Pretty-prints a graph, assuming it is a tree.
- *
- * @param start the node to take as the root
- * @param level indent level for recursive calls, always pass 0
- */
-
 void
-pretty_print_graph (struct graph_node *start)
+permute (struct graph_node *start)
 {
   static struct list *position = NULL;
   if (!position) position = list_new ();
@@ -51,7 +75,7 @@ pretty_print_graph (struct graph_node *start)
       fprintf (stdout, "\n");
     }
     else
-      pretty_print_graph (gn);
+      permute (gn);
   }
   list_delete_node (position, listtail(position));
 }