]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Lexer: Passing the buffer to Flex directly.
authorJan Maria Matejka <mq@ucw.cz>
Thu, 23 Aug 2018 19:54:35 +0000 (21:54 +0200)
committerJan Maria Matejka <mq@ucw.cz>
Fri, 14 Sep 2018 12:44:45 +0000 (14:44 +0200)
conf/cf-lex.l
conf/conf.c
conf/conf.h
conf/parser.h
nest/cli.c

index 72acd9476dabed7edd8f6b6a307cfdcb031df60e..32dc576a62623bd395704fd23a0c115f58b1c6c6 100644 (file)
@@ -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. */
 }
 
+void
+cf_scan_bytes(struct cf_context *ctx, const char *buf, uint len)
+{
+  yy_scan_bytes(buf, len, ctx->yyscanner);
+}
+
 static void
 cf_include(char *arg, int alen, yyscan_t yyscanner)
 {
index 05b740f5e824cb30c4ad232900c3dbf2e155ae30..1048296cf239e1d08c54d519208925db69ea4dd9 100644 (file)
@@ -157,6 +157,8 @@ cli_parse(struct conf_order *order)
 
   struct cf_context *ctx = cf_new_context(1, order);
 
+  cf_scan_bytes(ctx, order->buf, order->len);
+
   int ok = 0;
   if (setjmp(ctx->jmpbuf))
     goto done;
index bbdb70ac13a15099d746627be96d8476cd06d2e8..999e09963acb0d552dec701c9d0d8f396dce33c3 100644 (file)
@@ -65,6 +65,8 @@ struct conf_order {
   struct conf_state *state;
   struct pool *pool;                   /* If set, use this resource pool */
   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);
   void (*cf_include)(struct conf_order *order, char *name, uint len);
   int (*cf_outclude)(struct conf_order *order);
index 36cd2349966ab5dcd2ee83f16e9bb95558508248..1d858cf16016d24aa336c456e499e9353b543883 100644 (file)
@@ -34,6 +34,9 @@ void cf_free_context(struct cf_context *);
 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);
 
+/* 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 */
 void cf_init_kh(void);
 
index 80946d4181c0feacf320fb6f3e3ae11a788eb72f..ac29677fe6a890c3de26067950e029b113df387d 100644 (file)
@@ -242,24 +242,8 @@ struct cli *this_cli;
 struct cli_conf_order {
   struct conf_order co;
   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
 cli_cmd_error(struct conf_order *co, const char *msg, va_list args)
 {
@@ -279,15 +263,14 @@ cli_command(struct cli *c)
     .co = {
       .ctx = NULL,
       .state = &state,
-      .cf_read_hook = cli_cmd_read_hook,
+      .buf = c->rx_buf,
+      .len = strlen(c->rx_buf),
       .cf_include = NULL,
       .cf_outclude = NULL,
       .cf_error = cli_cmd_error,
       .lp = c->parser_pool,
       .pool = c->pool,
     },
-    .pos = c->rx_buf,
-    .len = strlen(c->rx_buf),
     .cli = c,
   };