]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: Unrefactor to signed long long for ranges
authorQuentin Young <qlyoung@cumulusnetworks.com>
Thu, 4 Aug 2016 18:16:26 +0000 (18:16 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Thu, 4 Aug 2016 18:16:26 +0000 (18:16 +0000)
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
lib/command_graph.c
lib/command_graph.h
lib/command_lex.l
lib/command_match.c
lib/command_parse.y
lib/grammar_sandbox.c

index d420b1c063e52ebf44eecb6292cfc78b866cbaf1..50be35044ad3a64f9468d4a725f2db14ba7b5200 100644 (file)
@@ -125,7 +125,7 @@ describe_node(struct graph_node *node, char* buffer, unsigned int bufsize)
       snprintf(buffer, bufsize, node->text);
       break;
     case NUMBER_GN:
-      snprintf(buffer, bufsize, "%ld", node->value);
+      snprintf(buffer, bufsize, "%lld", node->value);
       break;
     case SELECTOR_GN:
       snprintf(buffer, bufsize, "<>");
@@ -182,10 +182,10 @@ dump_node (struct graph_node *node)
   describe_node(node, buf, 50);
   fprintf(stderr, "%s[%d]\n", buf, node->type);
   fprintf(stderr, "\t->text: %s\n", node->text);
-  fprintf(stderr, "\t->value: %ld\n", node->value);
+  fprintf(stderr, "\t->value: %lld\n", node->value);
   fprintf(stderr, "\t->is_start: %d\n", node->is_start);
   fprintf(stderr, "\t->element: %p\n", node->element);
-  fprintf(stderr, "\t->min: %d\n->max: %d\n", node->min, node->max);
+  fprintf(stderr, "\t->min: %lld\n->max: %lld\n", node->min, node->max);
   fprintf(stderr, "\t->arg: %s\n", node->arg);
   fprintf(stderr, "\t->refs: %d\n", node->refs);
   fprintf(stderr, "\tnum children: %d\n", vector_active(node->children));
index 925133c203b92690435b15d43b3995941da84c6e..e1feb9f77f4f15c146f7f87c3fe4de1698dd65f2 100644 (file)
@@ -23,13 +23,13 @@ enum graph_node_type
 struct graph_node
 {
   enum graph_node_type type;// data type this node matches or holds
-  int is_start;             // whether this node is a start node
+  unsigned int is_start;    // whether this node is a start node
   vector children;          // this node's children
   struct graph_node * end;  // pointer to end for SELECTOR_GN & OPTION_GN
 
   char* text;               // for WORD_GN and VARIABLE_GN
-  long value;               // for NUMBER_GN
-  int min, max;             // for RANGE_GN
+  long long value;          // for NUMBER_GN
+  long long min, max;       // for RANGE_GN
 
   /* cmd_element struct pointer, only valid for END_GN */
   struct cmd_element *element;
@@ -37,7 +37,7 @@ struct graph_node
   char *arg;
 
   /* refcount for node parents */
-  int refs;
+  unsigned int refs;
 };
 
 /*
index 47723cbf9161c36b53fff94314f2355e77be13ec..855cf9a06590c7b0b1c85702c4f4b0305f7c85f2 100644 (file)
@@ -4,13 +4,13 @@
 extern void set_buffer_string(const char *);
 %}
 
-WORD            [-|+]?[a-z\*][-+_a-zA-Z0-9\*]*
+WORD            (\-|\+)?[a-z\*][-+_a-zA-Z0-9\*]*
 IPV4            A\.B\.C\.D
 IPV4_PREFIX     A\.B\.C\.D\/M
 IPV6            X:X::X:X
 IPV6_PREFIX     X:X::X:X\/M
 VARIABLE        [A-Z][-_a-zA-Z:0-9]+
-NUMBER          [-|+]?[0-9]{1,20}
+NUMBER          (\-|\+)?[0-9]{1,20}
 RANGE           \({NUMBER}[ ]?\-[ ]?{NUMBER}\)
 
 /* yytext shall be a pointer */
index aac2edc482f77375ae7d900a7a34b140494511ba..eaacce027f2a80f34c81741904deb3340e5754f1 100644 (file)
@@ -636,12 +636,12 @@ static enum match_type
 match_range (struct graph_node *rangenode, const char *str)
 {
   char *endptr = NULL;
-  signed int val;
+  long long val;
 
   if (str == NULL)
     return 1;
 
-  val = strtoimax (str, &endptr, 10);
+  val = strtoll (str, &endptr, 10);
   if (*endptr != '\0')
     return 0;
 
@@ -674,7 +674,7 @@ match_number(struct graph_node *numnode, const char *word)
 {
   if (!strcmp("\0", word)) return no_match;
   char *endptr;
-  int num = strtoimax(word, &endptr, 10);
+  long long num = strtoll (word, &endptr, 10);
   if (endptr != '\0') return no_match;
   return num == numnode->value ? exact_match : no_match;
 }
index 0ea87443467219436ff67dcb32d626c58247d20a..ac075e67a30fc186f0b95d35e2ddb097921a7e22 100644 (file)
@@ -36,7 +36,7 @@ node_replace(struct graph_node *, struct graph_node *);
 
 /* valid types for tokens */
 %union{
-  signed int integer;
+  long long integer;
   char *string;
   struct graph_node *node;
 }
@@ -205,9 +205,10 @@ placeholder_token:
   $$->text = XSTRDUP(MTYPE_CMD_TOKENS, $1);
 
   // get the numbers out
-  $$->min = strtoimax( yylval.string+1, &yylval.string, 10 );
+  yylval.string++;
+  $$->min = strtoll( yylval.string, &yylval.string, 10 );
   strsep (&yylval.string, "-");
-  $$->max = strtoimax( yylval.string, &yylval.string, 10 );
+  $$->max = strtoll( yylval.string, &yylval.string, 10 );
 
   // validate range
   if ($$->min >= $$->max) yyerror("Invalid range.");
@@ -352,7 +353,7 @@ parse_command_format(struct graph_node *start, struct cmd_element *cmd)
   optnode_start = optnode_end = NULL;
 
   // trace parser
-  yydebug = 1;
+  yydebug = 0;
   // command string
   command = cmd;
   // make flex read from a string
index 0eb8d69cee2786663c6b602da7eaa96e520f6015..a2177c176713d9bb1ab2199f1e45c8d5061e79e0 100644 (file)
@@ -32,9 +32,8 @@ DEFUN (grammar_test_show,
 {
   if (!nodegraph)
     fprintf(stderr, "!nodegraph\n");
-  fprintf(stderr, "trying to print nodegraph->type\n");
-  fprintf(stderr, "%d\n", nodegraph->type);
-  walk_graph(nodegraph, 0);
+  else
+    walk_graph(nodegraph, 0);
   return CMD_SUCCESS;
 }