diff options
author | Martin Mares <mj@ucw.cz> | 1998-11-27 22:07:02 +0100 |
---|---|---|
committer | Martin Mares <mj@ucw.cz> | 1998-11-27 22:07:02 +0100 |
commit | 8450be97d6ffb052fce95292d39c3f67afbcdc1c (patch) | |
tree | 36073a991abcc9a33582f976a7bf2cab4314352f | |
parent | 906b0170a41cc0d8ea11c7bae0a9fea3d18fe6d1 (diff) | |
download | bird-8450be97d6ffb052fce95292d39c3f67afbcdc1c.tar bird-8450be97d6ffb052fce95292d39c3f67afbcdc1c.zip |
Added generator of default names.
-rw-r--r-- | conf/cf-lex.l | 18 | ||||
-rw-r--r-- | conf/conf.h | 2 |
2 files changed, 20 insertions, 0 deletions
diff --git a/conf/cf-lex.l b/conf/cf-lex.l index 5509fae..f653bca 100644 --- a/conf/cf-lex.l +++ b/conf/cf-lex.l @@ -32,6 +32,7 @@ static struct keyword *kw_hash[KW_HASH_SIZE]; static struct symbol **sym_hash; static int allow_new_symbols; static int cf_lino; +static int default_counter; static int cf_hash(byte *c); static struct symbol *cf_find_sym(byte *c, unsigned int h0); @@ -180,12 +181,29 @@ cf_find_sym(byte *c, unsigned int h0) return s; } +struct symbol * +cf_default_name(char *prefix) +{ + char buf[32]; + struct symbol *s; + + do + { + sprintf(buf, "%s%d", prefix, default_counter++); + s = cf_find_sym(buf, cf_hash(buf)); + if (!s) cf_error("Unable to generate default name"); + } + while (s->class != SYM_VOID); + return s; +} + void cf_lex_init(int flag) { if (allow_new_symbols = flag) sym_hash = mp_allocz(cfg_mem, SYM_HASH_SIZE * sizeof(struct keyword *)); cf_lino = 1; + default_counter = 1; } void diff --git a/conf/conf.h b/conf/conf.h index d49ee5d..0853ae8 100644 --- a/conf/conf.h +++ b/conf/conf.h @@ -26,12 +26,14 @@ struct symbol { }; #define SYM_VOID 0 +#define SYM_PROTO 1 void cf_lex_init_tables(void); int cf_lex(void); void cf_lex_init(int flag); void cf_error(char *msg) NORET; void cf_allocate(void); +struct symbol *cf_default_name(char *prefix); /* Parser */ |