summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2016-10-02 21:30:08 +0200
committerQuentin Young <qlyoung@cumulusnetworks.com>2016-10-02 21:30:08 +0200
commit73baf6a3a66d783c89ad2efac556f2e3eb48c568 (patch)
treeec7317804775423c3cb835a9e86721f1c6315e05 /tools
parentlib: allow nesting selectors (diff)
downloadfrr-73baf6a3a66d783c89ad2efac556f2e3eb48c568.tar.xz
frr-73baf6a3a66d783c89ad2efac556f2e3eb48c568.zip
tools: add copyright header & usage to permutations
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/.gitignore1
-rw-r--r--tools/permutations.c46
2 files changed, 36 insertions, 11 deletions
diff --git a/tools/.gitignore b/tools/.gitignore
index 60c4c0650..066b0887a 100644
--- a/tools/.gitignore
+++ b/tools/.gitignore
@@ -5,3 +5,4 @@
*.loT
.libs
*.o
+permutations
diff --git a/tools/permutations.c b/tools/permutations.c
index 486278129..819305e54 100644
--- a/tools/permutations.c
+++ b/tools/permutations.c
@@ -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));
}