]> git.ipfire.org Git - thirdparty/bird.git/blobdiff - conf/cf-lex.l
Configuration strings are constant.
[thirdparty/bird.git] / conf / cf-lex.l
index 4f69993e1a29b222aa57fe4f7b70f0dd9cca9c66..1d6cae2cd52212a5e89e561c5cfd4da984d13323 100644 (file)
@@ -88,7 +88,7 @@ HASH_DEFINE_REHASH_FN(SYM, struct symbol)
 HASH(struct keyword) kw_hash;
 
 
-static struct sym_scope *conf_this_scope;
+struct sym_scope *conf_this_scope;
 
 linpool *cfg_mem;
 
@@ -168,7 +168,7 @@ WHITE [ \t]
   char *e;
 
   errno = 0;
-  l = bstrtoul(yytext, &e, 10);
+  l = bstrtoul10(yytext, &e);
   if (e && (*e != ':') || (errno == ERANGE) || (l >> 32))
     cf_error("ASN out of range");
 
@@ -186,7 +186,7 @@ WHITE [ \t]
   }
 
   errno = 0;
-  l = bstrtoul(e+1, &e, 10);
+  l = bstrtoul10(e+1, &e);
   if (e && *e || (errno == ERANGE) || (l >> len2))
     cf_error("Number out of range");
   cf_lval.i64 |= l;
@@ -213,13 +213,13 @@ WHITE [ \t]
   }
 
   errno = 0;
-  l = bstrtoul(yytext+2, &e, 10);
+  l = bstrtoul10(yytext+2, &e);
   if (e && (*e != ':') || (errno == ERANGE) || (l >> len1))
     cf_error("ASN out of range");
   cf_lval.i64 |= ((u64) l) << len2;
 
   errno = 0;
-  l = bstrtoul(e+1, &e, 10);
+  l = bstrtoul10(e+1, &e);
   if (e && *e || (errno == ERANGE) || (l >> len2))
     cf_error("Number out of range");
   cf_lval.i64 |= l;
@@ -241,7 +241,7 @@ WHITE [ \t]
   cf_lval.i64 |= ((u64) ip4_to_u32(ip4)) << 16;
 
   errno = 0;
-  l = bstrtoul(e, &e, 10);
+  l = bstrtoul10(e, &e);
   if (e && *e || (errno == ERANGE) || (l >> 16))
     cf_error("Number out of range");
   cf_lval.i64 |= l;
@@ -265,7 +265,7 @@ WHITE [ \t]
   char *e;
   unsigned long int l;
   errno = 0;
-  l = bstrtoul(yytext+2, &e, 16);
+  l = bstrtoul16(yytext+2, &e);
   if (e && *e || errno == ERANGE || (unsigned long int)(unsigned int) l != l)
     cf_error("Number out of range");
   cf_lval.i = l;
@@ -276,7 +276,7 @@ WHITE [ \t]
   char *e;
   unsigned long int l;
   errno = 0;
-  l = bstrtoul(yytext, &e, 10);
+  l = bstrtoul10(yytext, &e);
   if (e && *e || errno == ERANGE || (unsigned long int)(unsigned int) l != l)
     cf_error("Number out of range");
   cf_lval.i = l;
@@ -654,6 +654,14 @@ cf_default_name(char *template, int *counter)
 static enum yytokentype
 cf_lex_symbol(const char *data)
 {
+  /* Have we defined such a symbol? */
+  struct symbol *sym = cf_get_symbol(data);
+  cf_lval.s = sym;
+
+  if (sym->class != SYM_VOID)
+    return CF_SYM_KNOWN;
+
+  /* Is it a keyword? */
   struct keyword *k = HASH_FIND(kw_hash, KW, data);
   if (k)
   {
@@ -666,19 +674,9 @@ cf_lex_symbol(const char *data)
     }
   }
 
-  cf_lval.s = cf_get_symbol(data);
-  switch (cf_lval.s->class) {
-    case SYM_VOID: return CF_SYM_VOID;
-    case SYM_PROTO: return CF_SYM_PROTO;
-    case SYM_TEMPLATE: return CF_SYM_TEMPLATE;
-    case SYM_FUNCTION: return CF_SYM_FUNCTION;
-    case SYM_FILTER: return CF_SYM_FILTER;
-    case SYM_TABLE: return CF_SYM_TABLE;
-    case SYM_ATTRIBUTE: return CF_SYM_ATTRIBUTE;
-    case SYM_VARIABLE_RANGE: return CF_SYM_VARIABLE;
-    case SYM_CONSTANT_RANGE: return CF_SYM_CONSTANT;
-    default: bug("Unknown symbol class %d", cf_lval.s->class);
-  }
+  /* OK, undefined symbol */
+  cf_lval.s = sym;
+  return CF_SYM_UNDEFINED;
 }
 
 static void
@@ -721,7 +719,8 @@ cf_lex_init(int is_cli, struct config *c)
   else
     BEGIN(INITIAL);
 
-  conf_this_scope = cfg_allocz(sizeof(struct sym_scope));
+  c->root_scope = cfg_allocz(sizeof(struct sym_scope));
+  conf_this_scope = c->root_scope;
   conf_this_scope->active = 1;
 }
 
@@ -744,6 +743,7 @@ cf_push_scope(struct symbol *sym)
   conf_this_scope = s;
   s->active = 1;
   s->name = sym;
+  s->slots = 0;
 }
 
 /**
@@ -758,6 +758,7 @@ cf_pop_scope(void)
 {
   conf_this_scope->active = 0;
   conf_this_scope = conf_this_scope->next;
+
   ASSERT(conf_this_scope);
 }