]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Slightly better generator of default protocol instance names.
authorMartin Mares <mj@ucw.cz>
Fri, 26 Mar 1999 21:37:29 +0000 (21:37 +0000)
committerMartin Mares <mj@ucw.cz>
Fri, 26 Mar 1999 21:37:29 +0000 (21:37 +0000)
conf/cf-lex.l
conf/conf.h
nest/proto.c
nest/protocol.h

index 426f5287c276445b67b9eeae4a8717af46e62124..d000f97260dc62ec3818f16f347fd2c9d4eaeee5 100644 (file)
@@ -33,7 +33,6 @@ static struct keyword {
 static struct keyword *kw_hash[KW_HASH_SIZE];
 static struct symbol **sym_hash;
 static int allow_new_symbols;
-static int default_counter;
 
 int conf_lino;
 
@@ -163,8 +162,11 @@ cf_find_sym(byte *c, unsigned int h0)
   int l;
 
   while (s)
-    if (!strcmp(s->name, c))
-      return s;
+    {
+      if (!strcmp(s->name, c))
+        return s;
+      s = s->next;
+    }
   if (!allow_new_symbols)
     return NULL;
   l = strlen(c);
@@ -181,14 +183,14 @@ cf_find_sym(byte *c, unsigned int h0)
 }
 
 struct symbol *
-cf_default_name(char *prefix)
+cf_default_name(char *prefix, int *counter)
 {
   char buf[32];
   struct symbol *s;
 
   do
     {
-      sprintf(buf, "%s%d", prefix, default_counter++);
+      sprintf(buf, "%s%d", prefix, ++(*counter));
       s = cf_find_sym(buf, cf_hash(buf));
       if (!s) cf_error("Unable to generate default name");
     }
@@ -202,7 +204,6 @@ cf_lex_init(int flag)
   if (allow_new_symbols = flag)
     sym_hash = cfg_allocz(SYM_HASH_SIZE * sizeof(struct keyword *));
   conf_lino = 1;
-  default_counter = 1;
 }
 
 void
index 69f4a02e5868bf92cf89c75a927a3dda2c1b699d..5ceb4af00fb0ecd7745d2bfa2e86f8c9712be2a9 100644 (file)
@@ -67,7 +67,7 @@ extern int conf_lino;
 void cf_lex_init_tables(void);
 int cf_lex(void);
 void cf_lex_init(int flag);
-struct symbol *cf_default_name(char *prefix);
+struct symbol *cf_default_name(char *prefix, int *counter);
 
 /* Parser */
 
index 431c47dbdbeffcde8a8244a3bbb00fe533667ea0..04ee289b58f195fa47c425ecfcd82623c3d80990 100644 (file)
@@ -127,6 +127,7 @@ protos_preconfig(struct config *c)
   WALK_LIST(p, protocol_list)
     {
       debug(" %s", p->name);
+      p->name_counter = 0;
       if (p->preconfig)
        p->preconfig(p, c);
     }
index 1e641a5f746cd5d5723401f59f768ee1b700724e..626dd994fca44cd4cc765648258e96f9b24b3a49 100644 (file)
@@ -31,6 +31,7 @@ struct protocol {
   char *name;
   unsigned debug;                      /* Default debugging flags */
   int priority;                                /* Protocol priority (usually 0) */
+  int name_counter;                    /* Counter for automatic name generation */
 
   void (*preconfig)(struct protocol *, struct config *);       /* Just before configuring */
   void (*postconfig)(struct proto_config *);                   /* After configuring each instance */