]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: Add support for negative ranges
authorQuentin Young <qlyoung@cumulusnetworks.com>
Thu, 4 Aug 2016 16:18:31 +0000 (16:18 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Thu, 4 Aug 2016 16:18:31 +0000 (16:18 +0000)
And convert range delimiters to signed int

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

index 05570d5c7365833e6e7ea06fa26d974251dd270b..d420b1c063e52ebf44eecb6292cfc78b866cbaf1 100644 (file)
@@ -185,7 +185,7 @@ dump_node (struct graph_node *node)
   fprintf(stderr, "\t->value: %ld\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: %lld\n->max: %lld\n", node->min, node->max);
+  fprintf(stderr, "\t->min: %d\n->max: %d\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 35a0eee273e82b5341c356014ee69c3a0295382f..925133c203b92690435b15d43b3995941da84c6e 100644 (file)
@@ -29,7 +29,7 @@ struct graph_node
 
   char* text;               // for WORD_GN and VARIABLE_GN
   long value;               // for NUMBER_GN
-  signed long long min, max;// for RANGE_GN
+  int min, max;             // for RANGE_GN
 
   /* cmd_element struct pointer, only valid for END_GN */
   struct cmd_element *element;
index ff951149b3ae666e799b77394b2ccc2cc7b4da7d..0a997de8df11f8b6f2dbd057969cef7b8ef2a83e 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 */
@@ -30,7 +30,7 @@ RANGE           \({NUMBER}\-{NUMBER}\)
 {VARIABLE}      {yylval.string = XSTRDUP(MTYPE_TMP, yytext); return VARIABLE;}
 {NUMBER}        {
                     char *endptr;
-                    yylval.integer = strtoll(yytext, &endptr, 10);
+                    yylval.integer = strtoimax(yytext, &endptr, 10);
                     return NUMBER;
                 }
 {RANGE}         {yylval.string = XSTRDUP(MTYPE_TMP, yytext); return RANGE;}
index 305e3b1a68ed826152dbea4bae615d8b0dc9a1f0..aac2edc482f77375ae7d900a7a34b140494511ba 100644 (file)
@@ -622,7 +622,7 @@ match_ipv6_prefix (const char *str)
     return no_match;
 
   /* validate mask */
-  nmask = strtol (mask, &endptr, 10);
+  nmask = strtoimax (mask, &endptr, 10);
   if (*endptr != '\0' || nmask < 0 || nmask > 128)
     return no_match;
 
@@ -636,15 +636,14 @@ static enum match_type
 match_range (struct graph_node *rangenode, const char *str)
 {
   char *endptr = NULL;
-  signed long long val;
+  signed int val;
 
   if (str == NULL)
     return 1;
 
-  val = strtoll (str, &endptr, 10);
+  val = strtoimax (str, &endptr, 10);
   if (*endptr != '\0')
     return 0;
-  val = llabs(val);
 
   if (val < rangenode->min || val > rangenode->max)
     return no_match;
@@ -675,7 +674,7 @@ match_number(struct graph_node *numnode, const char *word)
 {
   if (!strcmp("\0", word)) return no_match;
   char *endptr;
-  long num = strtol(word, &endptr, 10);
+  int num = strtoimax(word, &endptr, 10);
   if (endptr != '\0') return no_match;
   return num == numnode->value ? exact_match : no_match;
 }
index 0c36c2a6dc92698ff11ebeff627ea13161109973..9d7432ca40de924cbc0c57f67461d2f6a4db9e98 100644 (file)
@@ -16,6 +16,8 @@ node_exists(struct graph_node *, struct graph_node *);
 struct graph_node *
 node_replace(struct graph_node *, struct graph_node *);
 
+#define DECIMAL_STRLEN_MAX 20
+
 // compile with debugging facilities
 #define YYDEBUG 1
 %}
@@ -34,7 +36,7 @@ node_replace(struct graph_node *, struct graph_node *);
 
 /* valid types for tokens */
 %union{
-  signed long long integer;
+  signed int integer;
   char *string;
   struct graph_node *node;
 }
@@ -203,10 +205,8 @@ placeholder_token:
   $$->text = XSTRDUP(MTYPE_CMD_TOKENS, $1);
 
   // get the numbers out
-  strsep(&yylval.string, "(-)");
-  char *endptr;
-  $$->min = strtoll( strsep(&yylval.string, "(-)"), &endptr, 10 );
-  $$->max = strtoll( strsep(&yylval.string, "(-)"), &endptr, 10 );
+  $$->min = strtoimax( yylval.string+1, &yylval.string, 10 );
+  $$->max = strtoimax( yylval.string+1, &yylval.string, 10 );
 
   free ($1);
 }
@@ -333,11 +333,7 @@ option_token:
 void yyerror(char const *message) {
   // fail on bad parse
   fprintf(stderr, "Grammar error: %s\n", message);
-  fprintf(stderr, "Token on error: ");
-  if (yylval.string) fprintf(stderr, "%s\n", yylval.string);
-  else if (yylval.node) fprintf(stderr, "%s\n", yylval.node->text);
-  else fprintf(stderr, "%lld\n", yylval.integer);
-
+  exit(EXIT_FAILURE);
 }
 
 struct graph_node *