]>
git.proxmox.com Git - mirror_frr.git/blob - tools/permutations.c
2 * Generates all possible matching inputs for a command string.
4 * Copyright (C) 2016 Cumulus Networks, Inc.
6 * This file is part of GNU Zebra.
8 * GNU Zebra is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * GNU Zebra is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with GNU Zebra; see the file COPYING. If not, write to the Free
20 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 #define USAGE "usage: permutations <cmdstr>"
31 permute (struct graph_node
*);
33 pretty_print_graph (struct graph_node
*start
, int level
);
35 int main (int argc
, char *argv
[])
39 fprintf(stdout
, USAGE
"\n");
42 struct cmd_element
*cmd
= calloc (1, sizeof (struct cmd_element
));
43 cmd
->string
= strdup(argv
[1]);
45 struct graph
*graph
= graph_new();
46 struct cmd_token
*token
= new_cmd_token (START_TKN
, cmd
->attr
, NULL
, NULL
);
47 graph_new_node (graph
, token
, NULL
);
48 command_parse_format (graph
, cmd
);
50 permute (vector_slot (graph
->nodes
, 0));
54 permute (struct graph_node
*start
)
56 static struct list
*position
= NULL
;
57 if (!position
) position
= list_new ();
59 struct cmd_token
*stok
= start
->data
;
60 struct graph_node
*gnn
;
64 listnode_add (position
, start
);
65 for (unsigned int i
= 0; i
< vector_active (start
->to
); i
++)
67 struct graph_node
*gn
= vector_slot (start
->to
, i
);
68 struct cmd_token
*tok
= gn
->data
;
69 if (tok
->attr
== CMD_ATTR_HIDDEN
||
70 tok
->attr
== CMD_ATTR_DEPRECATED
)
72 else if (tok
->type
== END_TKN
|| gn
== start
)
74 fprintf (stdout
, " ");
75 for (ALL_LIST_ELEMENTS_RO (position
,ln
,gnn
))
77 struct cmd_token
*tt
= gnn
->data
;
78 if (tt
->type
< SPECIAL_TKN
)
79 fprintf (stdout
, " %s", tt
->text
);
82 fprintf (stdout
, "...");
83 fprintf (stdout
, "\n");
88 if (stok
->type
== FORK_TKN
&& tok
->type
!= FORK_TKN
)
89 for (ALL_LIST_ELEMENTS_RO (position
, ln
, gnn
))
90 if (gnn
== gn
&& (skip
= true))
96 list_delete_node (position
, listtail(position
));