diff --git a/lib/command_lex.l b/lib/command_lex.l index 920c03db8e..b3276894f5 100644 --- a/lib/command_lex.l +++ b/lib/command_lex.l @@ -25,7 +25,9 @@ %{ #include "command_parse.h" -extern void set_buffer_string(const char *); +extern void set_lexer_string (const char *); +extern void cleanup_lexer (void); +YY_BUFFER_STATE buffer; %} WORD (\-|\+)?[a-z\*][-+_a-zA-Z0-9\*]* @@ -62,7 +64,13 @@ RANGE \({NUMBER}[ ]?\-[ ]?{NUMBER}\) %% void -set_buffer_string(const char *string) +set_lexer_string (const char *string) { - yy_scan_string(string); + buffer = yy_scan_string (XSTRDUP(MTYPE_TMP, string)); +} + +void +cleanup_lexer () +{ + yy_delete_buffer (buffer); } diff --git a/lib/command_match.c b/lib/command_match.c index 011ac698cb..9b9f8a0ec5 100644 --- a/lib/command_match.c +++ b/lib/command_match.c @@ -158,6 +158,8 @@ match_command (struct graph_node *start, static struct list * match_command_r (struct graph_node *start, vector vline, unsigned int n) { + assert (n < vector_active (vline)); + // get the minimum match level that can count as a full match enum match_type minmatch = min_match_level (start->type); diff --git a/lib/command_parse.y b/lib/command_parse.y index 6b972afe90..51c2331dc7 100644 --- a/lib/command_parse.y +++ b/lib/command_parse.y @@ -41,7 +41,10 @@ yylex (void); extern void - set_buffer_string (const char *); + set_lexer_string (const char *); + + extern void + cleanup_lexer (void); } /* functionality this unit exports */ @@ -135,7 +138,7 @@ optnode_start = optnode_end = NULL; /* set string to parse */ - set_buffer_string (element->string); + set_lexer_string (element->string); /* copy docstring and keep a pointer to the copy */ docstr = element->doc ? XSTRDUP(MTYPE_TMP, element->doc) : NULL; @@ -341,7 +344,6 @@ selector_element_root: selector_token: selector_element_root -| option ; /* [option|set] productions */ @@ -368,6 +370,7 @@ option_element: add_node (optnode_start, seqhead); add_node ($1, optnode_end); + seqhead = NULL; } option_token_seq: @@ -412,6 +415,9 @@ cleanup() /* free resources */ free (docstr_start); + /* cleanup lexer */ + cleanup_lexer(); + /* clear state pointers */ seqhead = NULL; currnode = NULL; diff --git a/lib/grammar_sandbox.c b/lib/grammar_sandbox.c index 39d4d6b7cd..cf9ce2bb58 100644 --- a/lib/grammar_sandbox.c +++ b/lib/grammar_sandbox.c @@ -63,7 +63,7 @@ DEFUN (grammar_test, // initialize a pretend cmd_element struct cmd_element *cmd = XCALLOC(MTYPE_CMD_TOKENS, sizeof(struct cmd_element)); - cmd->string = command; + cmd->string = XSTRDUP(MTYPE_TMP, command); cmd->doc = NULL; cmd->func = NULL; cmd->tokens = vector_init(VECTOR_MIN_SIZE); @@ -132,6 +132,9 @@ DEFUN (grammar_test_match, "command to match") { char *cmdstr = argv_concat(argv, argc, 0); + if (cmdstr[0] == '#') + return CMD_SUCCESS; + vector command = cmd_make_strvec (cmdstr); struct list *argvv = NULL; @@ -145,7 +148,7 @@ DEFUN (grammar_test_match, struct listnode *ln; struct graph_node *gn; for (ALL_LIST_ELEMENTS_RO(argvv,ln,gn)) - if (gn->type != END_GN) + if (gn->type == END_GN) zlog_info ("func: %p", gn->element->func); else zlog_info ("%s -- %s", gn->text, gn->arg);