]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: Refactor CLI interface function names
authorQuentin Young <qlyoung@cumulusnetworks.com>
Thu, 11 Aug 2016 17:50:58 +0000 (17:50 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Thu, 11 Aug 2016 17:50:58 +0000 (17:50 +0000)
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
lib/command_graph.c
lib/command_graph.h
lib/command_match.c
lib/command_match.h
lib/command_parse.y
lib/grammar_sandbox.c

index f249935771d619c02b233f68a42ee66fda5a2f4f..323bd3e95358c09107fab687fe32d25a8e2c13ff 100644 (file)
@@ -26,7 +26,7 @@
 #include "memory.h"
 
 struct graph_node *
-add_node (struct graph_node *parent, struct graph_node *child)
+graphnode_add_child (struct graph_node *parent, struct graph_node *child)
 {
   vector_set (parent->children, child);
   child->refs++;
@@ -34,7 +34,7 @@ add_node (struct graph_node *parent, struct graph_node *child)
 }
 
 struct graph_node *
-new_node (enum graph_node_type type)
+graphnode_new (enum graph_node_type type)
 {
   struct graph_node *node =
      XCALLOC(MTYPE_CMD_TOKENS, sizeof(struct graph_node));
@@ -46,7 +46,7 @@ new_node (enum graph_node_type type)
 }
 
 void
-delete_node (struct graph_node *node)
+graphnode_delete (struct graph_node *node)
 {
   if (!node) return;
   if (node->children) vector_free (node->children);
@@ -57,17 +57,17 @@ delete_node (struct graph_node *node)
 }
 
 void
-delete_graph (struct graph_node *start)
+graphnode_delete_graph (struct graph_node *start)
 {
   if (start && start->children && vector_active (start->children) > 0)
     {
       for (unsigned int i = 0; i < vector_active (start->children); i++)
         {
-          delete_graph (vector_slot(start->children, i));
+          graphnode_delete (vector_slot(start->children, i));
           vector_unset (start->children, i);
         }
     }
 
   if (--(start->refs) == 0)
-    delete_node (start);
+    graphnode_delete (start);
 }
index e42b8336e5bc6d90f142acf0b58ec966d2c43e8d..a2f84e3a0fe179f0071399c2ed7018d1231afc4c 100644 (file)
@@ -83,7 +83,7 @@ struct graph_node
  * @return child node
  */
 struct graph_node *
-add_node (struct graph_node *parent, struct graph_node *child);
+graphnode_add_child (struct graph_node *parent, struct graph_node *child);
 
 /**
  * Creates a new node, initializes all fields to default values and sets the
@@ -93,7 +93,7 @@ add_node (struct graph_node *parent, struct graph_node *child);
  * @return pointer to the created node
  */
 struct graph_node *
-new_node (enum graph_node_type type);
+graphnode_new (enum graph_node_type type);
 
 /**
  * Deletes a graph node without deleting its children.
@@ -101,7 +101,7 @@ new_node (enum graph_node_type type);
  * @param[out] node pointer to node to delete
  */
 void
-delete_node (struct graph_node *node);
+graphnode_delete (struct graph_node *node);
 
 /**
  * Deletes a graph node and recursively deletes all its direct and indirect
@@ -110,6 +110,6 @@ delete_node (struct graph_node *node);
  * @param[out] node start node of graph to free
  */
 void
-delete_graph (struct graph_node *node);
+graphnode_delete_graph (struct graph_node *node);
 
 #endif /* _ZEBRA_COMMAND_GRAPH_H */
index d5efa3968619f8fa704aba7a079c25fc24b21946..95891dd82313394db165339920a1b9fb5b8f0af6 100644 (file)
@@ -32,7 +32,7 @@ static int
 add_nexthops (struct list *, struct graph_node *);
 
 static struct list *
-match_command_r (struct graph_node *, vector, unsigned int);
+command_match_r (struct graph_node *, vector, unsigned int);
 
 static int
 score_precedence (enum graph_node_type);
@@ -87,7 +87,7 @@ match_variable (struct graph_node *node, const char *word);
 static enum matcher_rv matcher_rv;
 
 enum matcher_rv
-match_command (struct graph_node *start,
+command_match (struct graph_node *start,
                vector vline,
                struct list **argv,
                struct cmd_element **el)
@@ -100,7 +100,7 @@ match_command (struct graph_node *start,
   memcpy (vvline->index + 1, vline->index, sizeof (void *) * vline->alloced);
   vvline->active = vline->active + 1;
 
-  if ((*argv = match_command_r (start, vvline, 0))) // successful match
+  if ((*argv = command_match_r (start, vvline, 0))) // successful match
     {
       list_delete_node (*argv, listhead (*argv));
       struct graph_node *end = listgetdata (listtail (*argv));
@@ -160,7 +160,7 @@ match_command (struct graph_node *start,
  * @param[in] n the index of the first input token.
  */
 static struct list *
-match_command_r (struct graph_node *start, vector vline, unsigned int n)
+command_match_r (struct graph_node *start, vector vline, unsigned int n)
 {
   assert (n < vector_active (vline));
 
@@ -201,7 +201,7 @@ match_command_r (struct graph_node *start, vector vline, unsigned int n)
         }
 
       // else recurse on candidate child node
-      struct list *result = match_command_r (gn, vline, n+1);
+      struct list *result = command_match_r (gn, vline, n+1);
 
       // save the best match
       if (result && currbest)
@@ -242,7 +242,9 @@ match_command_r (struct graph_node *start, vector vline, unsigned int n)
 }
 
 enum matcher_rv
-match_command_complete (struct graph_node *start, vector vline, struct list **completions)
+command_complete (struct graph_node *start,
+                  vector vline,
+                  struct list **completions)
 {
   // pointer to next input token to match
   char *token;
@@ -320,12 +322,12 @@ compare_completions (const void *fst, const void *snd)
 }
 
 enum matcher_rv
-match_command_complete_str (struct graph_node *start,
-                            vector vline,
-                            vector completions)
+command_complete_str (struct graph_node *start,
+                      vector vline,
+                      vector completions)
 {
   struct list *comps;
-  enum matcher_rv rv = match_command_complete (start, vline, &comps);
+  enum matcher_rv rv = command_complete (start, vline, &comps);
 
   // quick n' dirty deduplication fn here, prolly like O(n^n)
   struct listnode *ln;
@@ -522,7 +524,7 @@ disambiguate (struct list *first,
 static struct graph_node *
 copy_node (struct graph_node *node)
 {
-  struct graph_node *new = new_node(node->type);
+  struct graph_node *new = graphnode_new(node->type);
   new->children = NULL;
   new->text     = node->text ? XSTRDUP(MTYPE_CMD_TOKENS, node->text) : NULL;
   new->value    = node->value;
@@ -540,7 +542,7 @@ copy_node (struct graph_node *node)
 static void
 delete_nodelist (void *node)
 {
-  delete_node ((struct graph_node *) node);
+  graphnode_delete ((struct graph_node *) node);
 }
 
 
index e8a408495ef57c6c95fe7f16f70fbeb4761760e3..765b189496844226a842167d87de1555bef74f19 100644 (file)
@@ -75,7 +75,7 @@ enum match_type
  * @return matcher status
  */
 enum matcher_rv
-match_command (struct graph_node *start,
+command_match (struct graph_node *start,
                vector vline,
                struct list **argv,
                struct cmd_element **element);
@@ -89,9 +89,9 @@ match_command (struct graph_node *start,
  * @return matcher status
  */
 enum matcher_rv
-match_command_complete (struct graph_node *start,
-                        vector vline,
-                        struct list **completions);
+command_complete (struct graph_node *start,
+                  vector vline,
+                  struct list **completions);
 
 
 /**
@@ -103,8 +103,8 @@ match_command_complete (struct graph_node *start,
  * @return matcher status
  */
 enum matcher_rv
-match_command_complete_str (struct graph_node *start,
-                            vector vline,
-                            vector completions);
+command_complete_str (struct graph_node *start,
+                      vector vline,
+                      vector completions);
 
 #endif /* _ZEBRA_COMMAND_MATCH_H */
index df90f64edb0d91f5e9f9d7c47d5606f65ee07b92..da1a117b5d91a473ab29ba33e7555b78f5506bc4 100644 (file)
@@ -50,7 +50,7 @@
 /* functionality this unit exports */
 %code provides {
   struct graph_node *
-  parse_command_format (struct graph_node *, struct cmd_element *);
+  command_parse_format (struct graph_node *, struct cmd_element *);
 
   /* maximum length of a number, lexer will not match anything longer */
   #define DECIMAL_STRLEN_MAX 20
@@ -156,7 +156,7 @@ start:
 | sentence_root cmd_token_seq '.' placeholder_token
 {
   if ((currnode = node_replace (currnode, $4)) != $4)
-    delete_node ($4);
+    graphnode_delete ($4);
 
   // adding a node as a child of itself accepts any number
   // of the same token, which is what we want for varags
@@ -168,7 +168,7 @@ start:
 
 sentence_root: WORD
 {
-  struct graph_node *root = new_node (WORD_GN);
+  struct graph_node *root = graphnode_new (WORD_GN);
   root->text = XSTRDUP(MTYPE_CMD_TOKENS, $1);
   root->doc = doc_next();
 
@@ -183,23 +183,23 @@ cmd_token:
   placeholder_token
 {
   if ((currnode = node_replace (currnode, $1)) != $1)
-    delete_node ($1);
+    graphnode_delete ($1);
 }
 | literal_token
 {
   if ((currnode = node_replace (currnode, $1)) != $1)
-    delete_node ($1);
+    graphnode_delete ($1);
 }
 /* selectors and options are subgraphs with start and end nodes */
 | selector
 {
-  add_node (currnode, $1);
+  graphnode_add_child (currnode, $1);
   currnode = selnode_end;
   selnode_start = selnode_end = NULL;
 }
 | option
 {
-  add_node (currnode, $1);
+  graphnode_add_child (currnode, $1);
   currnode = optnode_end;
   optnode_start = optnode_end = NULL;
 }
@@ -213,42 +213,42 @@ cmd_token_seq:
 placeholder_token:
   IPV4
 {
-  $$ = new_node (IPV4_GN);
+  $$ = graphnode_new (IPV4_GN);
   $$->text = XSTRDUP(MTYPE_CMD_TOKENS, $1);
   $$->doc = doc_next();
   free ($1);
 }
 | IPV4_PREFIX
 {
-  $$ = new_node (IPV4_PREFIX_GN);
+  $$ = graphnode_new (IPV4_PREFIX_GN);
   $$->text = XSTRDUP(MTYPE_CMD_TOKENS, $1);
   $$->doc = doc_next();
   free ($1);
 }
 | IPV6
 {
-  $$ = new_node (IPV6_GN);
+  $$ = graphnode_new (IPV6_GN);
   $$->text = XSTRDUP(MTYPE_CMD_TOKENS, $1);
   $$->doc = doc_next();
   free ($1);
 }
 | IPV6_PREFIX
 {
-  $$ = new_node (IPV6_PREFIX_GN);
+  $$ = graphnode_new (IPV6_PREFIX_GN);
   $$->text = XSTRDUP(MTYPE_CMD_TOKENS, $1);
   $$->doc = doc_next();
   free ($1);
 }
 | VARIABLE
 {
-  $$ = new_node (VARIABLE_GN);
+  $$ = graphnode_new (VARIABLE_GN);
   $$->text = XSTRDUP(MTYPE_CMD_TOKENS, $1);
   $$->doc = doc_next();
   free ($1);
 }
 | RANGE
 {
-  $$ = new_node (RANGE_GN);
+  $$ = graphnode_new (RANGE_GN);
   $$->text = XSTRDUP(MTYPE_CMD_TOKENS, $1);
   $$->doc = doc_next();
 
@@ -268,14 +268,14 @@ placeholder_token:
 literal_token:
   WORD
 {
-  $$ = new_node (WORD_GN);
+  $$ = graphnode_new (WORD_GN);
   $$->text = XSTRDUP(MTYPE_CMD_TOKENS, $1);
   $$->doc = doc_next();
   free ($1);
 }
 | NUMBER
 {
-  $$ = new_node (NUMBER_GN);
+  $$ = graphnode_new (NUMBER_GN);
   $$->value = yylval.number;
   $$->text = XCALLOC(MTYPE_CMD_TOKENS, DECIMAL_STRLEN_MAX+1);
   snprintf($$->text, DECIMAL_STRLEN_MAX, "%lld", $$->value);
@@ -301,25 +301,25 @@ selector_element: selector_element_root selector_token_seq
   // if the selector start and end do not exist, create them
   if (!selnode_start || !selnode_end) {     // if one is null
     assert(!selnode_start && !selnode_end); // both should be null
-    selnode_start = new_node (SELECTOR_GN);  // diverging node
-    selnode_end = new_node (NUL_GN);         // converging node
+    selnode_start = graphnode_new (SELECTOR_GN);  // diverging node
+    selnode_end = graphnode_new (NUL_GN);         // converging node
   }
 
   // add element head as a child of the selector
-  add_node (selnode_start, $1);
+  graphnode_add_child (selnode_start, $1);
 
   if ($2->type != NUL_GN) {
-    add_node ($1, seqhead);
-    add_node ($2, selnode_end);
+    graphnode_add_child ($1, seqhead);
+    graphnode_add_child ($2, selnode_end);
   }
   else
-    add_node ($1, selnode_end);
+    graphnode_add_child ($1, selnode_end);
 
   seqhead = NULL;
 }
 
 selector_token_seq:
-  %empty { $$ = new_node (NUL_GN); }
+  %empty { $$ = graphnode_new (NUL_GN); }
 | selector_token_seq selector_token
 {
   // if the sequence component is NUL_GN, this is a sequence start
@@ -328,7 +328,7 @@ selector_token_seq:
     seqhead = $2;
   }
   else // chain on new node
-    add_node ($1, $2);
+    graphnode_add_child ($1, $2);
 
   $$ = $2;
 }
@@ -347,7 +347,7 @@ selector_token:
 option: '[' option_part ']'
 {
   // add null path
-  add_node (optnode_start, optnode_end);
+  graphnode_add_child (optnode_start, optnode_end);
   $$ = optnode_start;
 };
 
@@ -361,12 +361,12 @@ option_element:
 {
   if (!optnode_start || !optnode_end) {
     assert(!optnode_start && !optnode_end);
-    optnode_start = new_node (OPTION_GN);
-    optnode_end = new_node (NUL_GN);
+    optnode_start = graphnode_new (OPTION_GN);
+    optnode_end = graphnode_new (NUL_GN);
   }
 
-  add_node (optnode_start, seqhead);
-  add_node ($1, optnode_end);
+  graphnode_add_child (optnode_start, seqhead);
+  graphnode_add_child ($1, optnode_end);
   seqhead = NULL;
 }
 
@@ -374,7 +374,7 @@ option_token_seq:
   option_token
 { $$ = seqhead = $1; }
 | option_token_seq option_token
-{ $$ = add_node ($1, $2); }
+{ $$ = graphnode_add_child ($1, $2); }
 ;
 
 option_token:
@@ -385,7 +385,7 @@ option_token:
 %%
 
 struct graph_node *
-parse_command_format(struct graph_node *start, struct cmd_element *cmd)
+command_parse_format (struct graph_node *start, struct cmd_element *cmd)
 {
   // set to 1 to enable parser traces
   yydebug = 0;
@@ -431,13 +431,13 @@ terminate_graph (struct graph_node *startnode,
                  struct graph_node *finalnode,
                  struct cmd_element *element)
 {
-  struct graph_node *end = new_node (END_GN);
+  struct graph_node *end = graphnode_new (END_GN);
   end->element = element;
   end->text = XSTRDUP(MTYPE_CMD_TOKENS, "<cr>");
   if (node_exists (finalnode, end))
     yyerror (element, startnode, "Duplicate command.");
   else
-    add_node (finalnode, end);
+    graphnode_add_child (finalnode, end);
 }
 
 static char *
@@ -466,7 +466,7 @@ static struct graph_node *
 node_replace (struct graph_node *parent, struct graph_node *child)
 {
   struct graph_node *existing = node_exists (parent, child);
-  return existing ? existing : add_node (parent, child);
+  return existing ? existing : graphnode_add_child (parent, child);
 }
 
 static int
@@ -492,10 +492,11 @@ cmp_node (struct graph_node *first, struct graph_node *second)
     case NUMBER_GN:
       if (first->value != second->value) return 0;
       break;
-    /* selectors and options should be equal if their subgraphs are equal, but
-     * the graph isomorphism problem is not known to be solvable in polynomial time
-     * so we consider selectors and options inequal in all cases; ultimately this
-     * forks the graph, but the matcher can handle this regardless
+    /* selectors and options should be equal if their subgraphs are equal,
+     * but the graph isomorphism problem is not known to be solvable in
+     * polynomial time so we consider selectors and options inequal in all
+     * cases; ultimately this forks the graph, but the matcher can handle
+     * this regardless
      */
     case SELECTOR_GN:
     case OPTION_GN:
index 899d0469ab9863edcba9868f923dc1e90cbea7db..92a0ae304e1be2c6ff26507ee34e6a5182f16e84 100644 (file)
@@ -69,7 +69,7 @@ DEFUN (grammar_test,
   cmd->tokens = vector_init(VECTOR_MIN_SIZE);
 
   // parse the command and install it into the command graph
-  parse_command_format (nodegraph, cmd);
+  command_parse_format (nodegraph, cmd);
 
   // free resources
   free (command);
@@ -93,7 +93,7 @@ DEFUN (grammar_test_complete,
 
   vector completions = vector_init (VECTOR_MIN_SIZE);
   enum matcher_rv result =
-     match_command_complete_str (nodegraph, command, completions);
+     command_complete_str (nodegraph, command, completions);
 
   // print completions or relevant error message
   if (!MATCHER_ERROR(result))
@@ -130,7 +130,7 @@ DEFUN (grammar_test_match,
 
   struct list *argvv = NULL;
   struct cmd_element *element = NULL;
-  enum matcher_rv result = match_command (nodegraph, command, &argvv, &element);
+  enum matcher_rv result = command_match (nodegraph, command, &argvv, &element);
 
   // print completions or relevant error message
   if (element)
@@ -200,7 +200,7 @@ DEFUN (grammar_test_doc,
   cmd->tokens = vector_init (VECTOR_MIN_SIZE);
 
   // parse element
-  parse_command_format (nodegraph, cmd);
+  command_parse_format (nodegraph, cmd);
 
   return CMD_SUCCESS;
 }
@@ -224,7 +224,7 @@ DEFUN (grammar_test_show,
 /* this is called in vtysh.c to set up the testing shim */
 void grammar_sandbox_init() {
   zlog_info ("Initializing grammar testing shim");
-  nodegraph = new_node(START_GN);
+  nodegraph = graphnode_new (START_GN);
   install_element (ENABLE_NODE, &grammar_test_cmd);
   install_element (ENABLE_NODE, &grammar_test_show_cmd);
   install_element (ENABLE_NODE, &grammar_test_match_cmd);