diff options
author | Quentin Young <qlyoung@cumulusnetworks.com> | 2016-10-02 21:13:59 +0200 |
---|---|---|
committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2016-10-02 21:13:59 +0200 |
commit | 96dcc565e6e590eddd124cdcf3634b68b9579a85 (patch) | |
tree | c2673a9ce5ecb4ac43728c0f5b6aafd143b9cb99 /tools | |
parent | lib: explicitly support the case of empty input for completions (diff) | |
download | frr-96dcc565e6e590eddd124cdcf3634b68b9579a85.tar.xz frr-96dcc565e6e590eddd124cdcf3634b68b9579a85.zip |
tools: add command permutations generator
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/.gitignore | 3 | ||||
-rw-r--r-- | tools/Makefile.am | 8 | ||||
-rw-r--r-- | tools/permutations.c | 57 |
3 files changed, 67 insertions, 1 deletions
diff --git a/tools/.gitignore b/tools/.gitignore index dd5bf7c67..60c4c0650 100644 --- a/tools/.gitignore +++ b/tools/.gitignore @@ -3,4 +3,5 @@ *~ *.loT - +.libs +*.o diff --git a/tools/Makefile.am b/tools/Makefile.am index 125bfee2c..c5dbba5a8 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -1,3 +1,11 @@ +AM_CPPFLAGS = -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib +DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" +AM_CFLAGS = $(WERROR) + +bin_PROGRAMS = permutations +permutations_SOURCES = permutations.c +permutations_LDADD = ../lib/libzebra.la + sbin_SCRIPTS = quagga-reload.py quagga EXTRA_DIST = quagga.service quagga-reload.py quagga diff --git a/tools/permutations.c b/tools/permutations.c new file mode 100644 index 000000000..486278129 --- /dev/null +++ b/tools/permutations.c @@ -0,0 +1,57 @@ +#include "command.h" +#include "graph.h" +#include "command_parse.h" +#include "vector.h" + +void +pretty_print_graph (struct graph_node *); + +int main (int argc, char *argv[]) +{ + struct cmd_element *cmd = calloc (1, sizeof (struct cmd_element)); + cmd->string = strdup(argv[1]); + + struct graph *graph = graph_new(); + struct cmd_token *token = new_cmd_token (START_TKN, NULL, NULL); + graph_new_node (graph, token, NULL); + command_parse_format (graph, cmd); + + pretty_print_graph (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) +{ + static struct list *position = NULL; + if (!position) position = list_new (); + + // 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) + { + struct graph_node *gnn; + struct listnode *ln; + for (ALL_LIST_ELEMENTS_RO (position,ln,gnn)) + { + struct cmd_token *tt = gnn->data; + if (tt->type < SELECTOR_TKN) + fprintf (stdout, "%s ", tt->text); + } + fprintf (stdout, "\n"); + } + else + pretty_print_graph (gn); + } + list_delete_node (position, listtail(position)); +} |