summaryrefslogtreecommitdiffstats
path: root/conf/cf-lex.l
diff options
context:
space:
mode:
authorMartin Mares <mj@ucw.cz>2000-01-17 12:52:50 +0100
committerMartin Mares <mj@ucw.cz>2000-01-17 12:52:50 +0100
commitd272fe22dddcb5c293d6aac18d36e3e3e66406a5 (patch)
tree20710583efb431b87ce836c068825dc12be7f0d2 /conf/cf-lex.l
parentf7fcb752520759ab3aed274ca608e8e6f96665c8 (diff)
downloadbird-d272fe22dddcb5c293d6aac18d36e3e3e66406a5.tar
bird-d272fe22dddcb5c293d6aac18d36e3e3e66406a5.zip
Separated `official protocol names' used in status dumps from name templates
used for automatic generation of instance names. protocol->name is the official name protocol->template is the name template (usually "name%d"), should be all lowercase. Updated all protocols to define the templates, checked that their configuration grammar includes proto_name which generates the name and interns it in the symbol table.
Diffstat (limited to 'conf/cf-lex.l')
-rw-r--r--conf/cf-lex.l20
1 files changed, 13 insertions, 7 deletions
diff --git a/conf/cf-lex.l b/conf/cf-lex.l
index cd6699f..df0f3c1 100644
--- a/conf/cf-lex.l
+++ b/conf/cf-lex.l
@@ -1,7 +1,7 @@
/*
* BIRD -- Configuration Lexer
*
- * (c) 1998--1999 Martin Mares <mj@ucw.cz>
+ * (c) 1998--2000 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
@@ -19,6 +19,7 @@
#include "filter/filter.h"
#include "conf/conf.h"
#include "conf/cf-parse.tab.h"
+#include "lib/string.h"
static struct keyword {
byte *name;
@@ -231,19 +232,24 @@ cf_find_symbol(byte *c)
}
struct symbol *
-cf_default_name(char *prefix, int *counter)
+cf_default_name(char *template, int *counter)
{
char buf[32];
struct symbol *s;
+ char *perc = strchr(template, '%');
- do
+ for(;;)
{
- sprintf(buf, "%s%d", prefix, ++(*counter));
+ bsprintf(buf, template, ++(*counter));
s = cf_find_sym(buf, cf_hash(buf));
- if (!s) cf_error("Unable to generate default name");
+ if (!s)
+ break;
+ if (s->class == SYM_VOID)
+ return s;
+ if (!perc)
+ break;
}
- while (s->class != SYM_VOID);
- return s;
+ cf_error("Unable to generate default name");
}
void