mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-11-14 23:28:43 +00:00
Lexer: Passing the buffer to Flex directly.
This commit is contained in:
parent
02297d3c54
commit
118c443aba
@ -355,6 +355,12 @@ cf_free_state(struct cf_context *ctx, struct conf_state *cs)
|
|||||||
/* The state structure is allocated from linpool, will be auto-freed. */
|
/* The state structure is allocated from linpool, will be auto-freed. */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cf_scan_bytes(struct cf_context *ctx, const char *buf, uint len)
|
||||||
|
{
|
||||||
|
yy_scan_bytes(buf, len, ctx->yyscanner);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cf_include(char *arg, int alen, yyscan_t yyscanner)
|
cf_include(char *arg, int alen, yyscan_t yyscanner)
|
||||||
{
|
{
|
||||||
|
@ -157,6 +157,8 @@ cli_parse(struct conf_order *order)
|
|||||||
|
|
||||||
struct cf_context *ctx = cf_new_context(1, order);
|
struct cf_context *ctx = cf_new_context(1, order);
|
||||||
|
|
||||||
|
cf_scan_bytes(ctx, order->buf, order->len);
|
||||||
|
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
if (setjmp(ctx->jmpbuf))
|
if (setjmp(ctx->jmpbuf))
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -65,6 +65,8 @@ struct conf_order {
|
|||||||
struct conf_state *state;
|
struct conf_state *state;
|
||||||
struct pool *pool; /* If set, use this resource pool */
|
struct pool *pool; /* If set, use this resource pool */
|
||||||
struct linpool *lp; /* If set, use this linpool */
|
struct linpool *lp; /* If set, use this linpool */
|
||||||
|
const char *buf;
|
||||||
|
uint len;
|
||||||
int (*cf_read_hook)(struct conf_order *order, byte *buf, uint max);
|
int (*cf_read_hook)(struct conf_order *order, byte *buf, uint max);
|
||||||
void (*cf_include)(struct conf_order *order, char *name, uint len);
|
void (*cf_include)(struct conf_order *order, char *name, uint len);
|
||||||
int (*cf_outclude)(struct conf_order *order);
|
int (*cf_outclude)(struct conf_order *order);
|
||||||
|
@ -34,6 +34,9 @@ void cf_free_context(struct cf_context *);
|
|||||||
struct conf_state *cf_new_state(struct cf_context *ctx, const char *name);
|
struct conf_state *cf_new_state(struct cf_context *ctx, const char *name);
|
||||||
void cf_free_state(struct cf_context *ctx, struct conf_state *cs);
|
void cf_free_state(struct cf_context *ctx, struct conf_state *cs);
|
||||||
|
|
||||||
|
/* Lexer input is a memory buffer */
|
||||||
|
void cf_scan_bytes(struct cf_context *, const char *, uint);
|
||||||
|
|
||||||
/* Init keyword hash is called once from global init */
|
/* Init keyword hash is called once from global init */
|
||||||
void cf_init_kh(void);
|
void cf_init_kh(void);
|
||||||
|
|
||||||
|
21
nest/cli.c
21
nest/cli.c
@ -242,24 +242,8 @@ struct cli *this_cli;
|
|||||||
struct cli_conf_order {
|
struct cli_conf_order {
|
||||||
struct conf_order co;
|
struct conf_order co;
|
||||||
struct cli *cli;
|
struct cli *cli;
|
||||||
const char *pos;
|
|
||||||
uint len;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
|
||||||
cli_cmd_read_hook(struct conf_order *co, byte *buf, uint max)
|
|
||||||
{
|
|
||||||
struct cli_conf_order *cco = (struct cli_conf_order *) co;
|
|
||||||
|
|
||||||
if (max > cco->len)
|
|
||||||
max = cco->len;
|
|
||||||
|
|
||||||
memcpy(buf, cco->pos, cco->len);
|
|
||||||
cco->pos += max;
|
|
||||||
cco->len -= max;
|
|
||||||
return max;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cli_cmd_error(struct conf_order *co, const char *msg, va_list args)
|
cli_cmd_error(struct conf_order *co, const char *msg, va_list args)
|
||||||
{
|
{
|
||||||
@ -279,15 +263,14 @@ cli_command(struct cli *c)
|
|||||||
.co = {
|
.co = {
|
||||||
.ctx = NULL,
|
.ctx = NULL,
|
||||||
.state = &state,
|
.state = &state,
|
||||||
.cf_read_hook = cli_cmd_read_hook,
|
.buf = c->rx_buf,
|
||||||
|
.len = strlen(c->rx_buf),
|
||||||
.cf_include = NULL,
|
.cf_include = NULL,
|
||||||
.cf_outclude = NULL,
|
.cf_outclude = NULL,
|
||||||
.cf_error = cli_cmd_error,
|
.cf_error = cli_cmd_error,
|
||||||
.lp = c->parser_pool,
|
.lp = c->parser_pool,
|
||||||
.pool = c->pool,
|
.pool = c->pool,
|
||||||
},
|
},
|
||||||
.pos = c->rx_buf,
|
|
||||||
.len = strlen(c->rx_buf),
|
|
||||||
.cli = c,
|
.cli = c,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user