diff options
author | Martin Mares <mj@ucw.cz> | 1998-11-29 22:59:37 +0100 |
---|---|---|
committer | Martin Mares <mj@ucw.cz> | 1998-11-29 22:59:37 +0100 |
commit | 49e4a4d1fd64da045182f6ccd38753feb364f9c5 (patch) | |
tree | b92509e77cf0ba1bfdf87a58625591bafabd9ff5 /conf/cf-lex.l | |
parent | 5cd462f291b45a6a33168cdfbc4ba55ee068af65 (diff) | |
download | bird-49e4a4d1fd64da045182f6ccd38753feb364f9c5.tar bird-49e4a4d1fd64da045182f6ccd38753feb364f9c5.zip |
Created new functions for allocating configuration data:
o cfg_alloc(size) -- generic memory allocation
o cfg_allocu(size) -- unaligned memory allocation
o cfg_allocz(size) -- zeroed memory allocation
o cfg_strcpy(str) -- allocate a copy of a string
Also fixed a bug in lexing of string literals.
Diffstat (limited to 'conf/cf-lex.l')
-rw-r--r-- | conf/cf-lex.l | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/conf/cf-lex.l b/conf/cf-lex.l index 66f3038..eb1d330 100644 --- a/conf/cf-lex.l +++ b/conf/cf-lex.l @@ -107,7 +107,7 @@ WHITE [ \t] ["][^"\n]*["] { cf_lval.t = yytext+1; - yytext[yyleng] = 0; + yytext[yyleng-1] = 0; return TEXT; } @@ -172,7 +172,7 @@ cf_find_sym(byte *c, unsigned int h0) l = strlen(c); if (l > SYM_MAX_LEN) cf_error("Symbol too long"); - s = mp_alloc(cfg_mem, sizeof(struct symbol) + l); + s = cfg_alloc(sizeof(struct symbol) + l); s->next = sym_hash[h]; sym_hash[h] = s; s->class = SYM_VOID; @@ -202,7 +202,7 @@ void cf_lex_init(int flag) { if (allow_new_symbols = flag) - sym_hash = mp_allocz(cfg_mem, SYM_HASH_SIZE * sizeof(struct keyword *)); + sym_hash = cfg_allocz(SYM_HASH_SIZE * sizeof(struct keyword *)); cf_lino = 1; default_counter = 1; } @@ -234,3 +234,12 @@ cf_allocate(void) cfg_pool = rp_new(&root_pool, "Config"); cfg_mem = mp_new(cfg_pool, 1024); } + +char * +cfg_strcpy(char *c) +{ + int l = strlen(c) + 1; + char *z = cfg_allocu(l); + memcpy(z, c, l); + return z; +} |