summaryrefslogtreecommitdiffstats
path: root/conf/cf-lex.l
diff options
context:
space:
mode:
authorMartin Mares <mj@ucw.cz>1999-10-31 18:47:47 +0100
committerMartin Mares <mj@ucw.cz>1999-10-31 18:47:47 +0100
commitbc2fb68098faaf09393437a7743285d2af71d102 (patch)
tree94b82b1648296c7a7fdb35063a524a1a7fe90228 /conf/cf-lex.l
parentb9672a845f7ff7d2441e21746566eacc51f274b7 (diff)
downloadbird-bc2fb68098faaf09393437a7743285d2af71d102.tar
bird-bc2fb68098faaf09393437a7743285d2af71d102.zip
Parse CLI commands. We use the same parser as for configuration files (because
we want to allow filter and similar complex constructs to be used in commands and we should avoid code duplication), only with CLI_MARKER token prepended before the whole input. Defined macro CF_CLI(cmd, args, help) for defining CLI commands in .Y files. The first argument specifies the command itself, the remaining two arguments are copied to the help file (er, will be copied after the help file starts to exist). This macro automatically creates a skeleton rule for the command, you only need to append arguments as in: CF_CLI(STEAL MONEY, <$>, [[Steal <$> US dollars or equivalent in any other currency]]): NUM { cli_msg(0, "%d$ stolen", $3); } ; Also don't forget to reset lexer state between inputs.
Diffstat (limited to 'conf/cf-lex.l')
-rw-r--r--conf/cf-lex.l38
1 files changed, 23 insertions, 15 deletions
diff --git a/conf/cf-lex.l b/conf/cf-lex.l
index 21727a9..258ca7e 100644
--- a/conf/cf-lex.l
+++ b/conf/cf-lex.l
@@ -34,14 +34,12 @@ static struct keyword {
static struct keyword *kw_hash[KW_HASH_SIZE];
static struct symbol **sym_hash;
-static int allow_new_symbols;
int conf_lino;
static int cf_hash(byte *c);
static struct symbol *cf_find_sym(byte *c, unsigned int h0);
-pool *cfg_pool;
linpool *cfg_mem;
int (*cf_read_hook)(byte *buf, unsigned int max);
@@ -54,7 +52,7 @@ int (*cf_read_hook)(byte *buf, unsigned int max);
%option noyywrap
-%x COMMENT CCOMM
+%x COMMENT CCOMM CLI
ALPHA [a-zA-Z_]
DIGIT [0-9]
@@ -121,6 +119,11 @@ WHITE [ \t]
return SYM;
}
+<CLI>! {
+ BEGIN(INITIAL);
+ return CLI_MARKER;
+}
+
[={}:;,()+*/%-<>~\[\]] {
return yytext[0];
}
@@ -174,17 +177,18 @@ static struct symbol *
cf_find_sym(byte *c, unsigned int h0)
{
unsigned int h = h0 & (SYM_HASH_SIZE-1);
- struct symbol *s = sym_hash[h];
+ struct symbol *s;
int l;
- while (s)
- {
- if (!strcmp(s->name, c))
- return s;
- s = s->next;
- }
- if (!allow_new_symbols)
- return NULL;
+ if (!sym_hash)
+ sym_hash = cfg_allocz(SYM_HASH_SIZE * sizeof(struct keyword *));
+ else
+ for(s = sym_hash[h]; s; s=s->next)
+ {
+ if (!strcmp(s->name, c))
+ return s;
+ s = s->next;
+ }
l = strlen(c);
if (l > SYM_MAX_LEN)
cf_error("Symbol too long");
@@ -230,11 +234,15 @@ cf_define_symbol(struct symbol *sym, int type, void *def)
}
void
-cf_lex_init(int flag)
+cf_lex_init(int is_cli)
{
- if (allow_new_symbols = flag)
- sym_hash = cfg_allocz(SYM_HASH_SIZE * sizeof(struct keyword *));
+ sym_hash = NULL;
conf_lino = 1;
+ yyrestart(NULL);
+ if (is_cli)
+ BEGIN(CLI);
+ else
+ BEGIN(INITIAL);
}
void