diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/cocci.h | 54 | ||||
| -rw-r--r-- | tools/permutations.c | 114 |
2 files changed, 77 insertions, 91 deletions
diff --git a/tools/cocci.h b/tools/cocci.h index 3d877a7b4b..43b8ad6e80 100644 --- a/tools/cocci.h +++ b/tools/cocci.h @@ -1,34 +1,28 @@ /* some of this stuff doesn't seem to parse properly in coccinelle */ -#define DEFUN(funcname, cmdname, str, help) \ - static int funcname \ - (const struct cmd_element *self, \ - struct vty *vty, \ - int argc, \ - struct cmd_token *argv[]) -#define DEFUN_HIDDEN(funcname, cmdname, str, help) \ - static int funcname \ - (const struct cmd_element *self, \ - struct vty *vty, \ - int argc, \ - struct cmd_token *argv[]) +#define DEFUN(funcname, cmdname, str, help) \ + static int funcname(const struct cmd_element *self, struct vty *vty, \ + int argc, struct cmd_token *argv[]) +#define DEFUN_HIDDEN(funcname, cmdname, str, help) \ + static int funcname(const struct cmd_element *self, struct vty *vty, \ + int argc, struct cmd_token *argv[]) #define ENABLE_BGP_VNC 1 -#define ALL_LIST_ELEMENTS_RO(list,node,data) \ - (node) = listhead(list), ((data) = NULL);\ - (node) != NULL && ((data) = listgetdata(node)); \ - (node) = listnextnode(node), ((data) = NULL) -#define ALL_LIST_ELEMENTS(list,node,nextnode,data) \ - (node) = listhead(list), ((data) = NULL); \ - (node) != NULL && \ - ((data) = listgetdata(node),(nextnode) = node->next); \ - (node) = (nextnode), ((data) = NULL) -#define LIST_HEAD(name, type) \ - struct name { \ - struct type *lh_first; /* first element */ \ - } -#define LIST_ENTRY(type) \ -struct { \ - struct type *le_next; /* next element */ \ - struct type **le_prev; /* address of previous next element */ \ -} +#define ALL_LIST_ELEMENTS_RO(list, node, data) \ + (node) = listhead(list), ((data) = NULL); \ + (node) != NULL && ((data) = listgetdata(node)); \ + (node) = listnextnode(node), ((data) = NULL) +#define ALL_LIST_ELEMENTS(list, node, nextnode, data) \ + (node) = listhead(list), ((data) = NULL); \ + (node) != NULL \ + && ((data) = listgetdata(node), (nextnode) = node->next); \ + (node) = (nextnode), ((data) = NULL) +#define LIST_HEAD(name, type) \ + struct name { \ + struct type *lh_first; /* first element */ \ + } +#define LIST_ENTRY(type) \ + struct { \ + struct type *le_next; /* next element */ \ + struct type **le_prev; /* address of previous next element */ \ + } diff --git a/tools/permutations.c b/tools/permutations.c index 88d1464697..4caae1c9c0 100644 --- a/tools/permutations.c +++ b/tools/permutations.c @@ -27,74 +27,66 @@ #define USAGE "usage: permutations <cmdstr>" -void -permute (struct graph_node *); -void -pretty_print_graph (struct graph_node *start, int level); +void permute(struct graph_node *); +void pretty_print_graph(struct graph_node *start, int level); -int main (int argc, char *argv[]) +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]); + 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]); - struct graph *graph = graph_new(); - struct cmd_token *token = new_cmd_token (START_TKN, cmd->attr, NULL, NULL); - graph_new_node (graph, token, NULL); - command_parse_format (graph, cmd); + struct graph *graph = graph_new(); + struct cmd_token *token = + new_cmd_token(START_TKN, cmd->attr, NULL, NULL); + graph_new_node(graph, token, NULL); + command_parse_format(graph, cmd); - permute (vector_slot (graph->nodes, 0)); + permute(vector_slot(graph->nodes, 0)); } -void -permute (struct graph_node *start) +void permute(struct graph_node *start) { - static struct list *position = NULL; - if (!position) position = list_new (); + static struct list *position = NULL; + if (!position) + position = list_new(); - struct cmd_token *stok = start->data; - struct graph_node *gnn; - struct listnode *ln; + 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->attr == CMD_ATTR_HIDDEN || - tok->attr == CMD_ATTR_DEPRECATED) - continue; - else if (tok->type == END_TKN || gn == start) - { - 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); - } - if (gn == start) - fprintf (stdout, "..."); - fprintf (stdout, "\n"); - } - else - { - 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); - } - } - list_delete_node (position, listtail(position)); + // 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->attr == CMD_ATTR_HIDDEN + || tok->attr == CMD_ATTR_DEPRECATED) + continue; + else if (tok->type == END_TKN || gn == start) { + 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); + } + if (gn == start) + fprintf(stdout, "..."); + fprintf(stdout, "\n"); + } else { + 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); + } + } + list_delete_node(position, listtail(position)); } |
