Commit 295204ed authored by Maria Matejka's avatar Maria Matejka
Browse files

Simplifying the CLI parser trick

parent 94808893
Loading
Loading
Loading
Loading
+12 −10
Original line number Diff line number Diff line
@@ -92,6 +92,7 @@ struct sym_scope *conf_this_scope;

linpool *cfg_mem;

_Thread_local int cli_rh_trick_flag;
int (*cf_read_hook)(byte *buf, unsigned int max, int fd);
struct include_file_stack *ifs;
static struct include_file_stack *ifs_head;
@@ -124,7 +125,7 @@ static enum yytokentype cf_lex_symbol(const char *data);
%option nounput
%option noreject

%x COMMENT CCOMM CLI QUOTED APOSTROPHED INCLUDE
%x COMMENT CCOMM QUOTED APOSTROPHED INCLUDE

ALPHA [a-zA-Z_]
DIGIT [0-9]
@@ -133,6 +134,15 @@ ALNUM [a-zA-Z_0-9]
WHITE [ \t]

%%

%{
  if (cli_rh_trick_flag)
  {
    cli_rh_trick_flag = 0;
    return CLI_MARKER;
  }
%}

^{WHITE}*include{WHITE}*\" {
  if (!ifs->depth)
    cf_error("Include not allowed in CLI");
@@ -307,11 +317,6 @@ else: {
  return cf_lex_symbol(yytext);
}

<CLI>(.|\n) {
  BEGIN(INITIAL);
  return CLI_MARKER;
}

\.\. {
  return DDOT;
}
@@ -714,9 +719,6 @@ cf_lex_init(int is_cli, struct config *c)
  yyrestart(NULL);
  ifs->buffer = YY_CURRENT_BUFFER;

  if (is_cli)
    BEGIN(CLI);
  else
  BEGIN(INITIAL);

  c->root_scope = cfg_allocz(sizeof(struct sym_scope));
+2 −8
Original line number Diff line number Diff line
@@ -170,7 +170,7 @@ cli_hello(cli *c)

_Thread_local static byte *cli_rh_pos;
_Thread_local static uint cli_rh_len;
_Thread_local static int cli_rh_trick_flag;
_Thread_local extern int cli_rh_trick_flag;
_Thread_local struct cli *this_cli;

/* Hack for scheduled undo notification */
@@ -190,12 +190,6 @@ cli_free(cli *c)
static int
cli_cmd_read_hook(byte *buf, uint max, UNUSED int fd)
{
  if (!cli_rh_trick_flag)
    {
      cli_rh_trick_flag = 1;
      buf[0] = '!';
      return 1;
    }
  if (max > cli_rh_len)
    max = cli_rh_len;
  memcpy(buf, cli_rh_pos, max);
@@ -219,7 +213,7 @@ cli_command(struct cli *c, byte *buf, uint len)
  cf_read_hook = cli_cmd_read_hook;
  cli_rh_pos = buf;
  cli_rh_len = len;
  cli_rh_trick_flag = 0;
  cli_rh_trick_flag = 1;
  this_cli = c;
  lp_flush(c->parser_pool);
  res = cli_parse(&f);