%{
#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\*]*
%%
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);
}
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);
yylex (void);
extern void
- set_buffer_string (const char *);
+ set_lexer_string (const char *);
+
+ extern void
+ cleanup_lexer (void);
}
/* functionality this unit exports */
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;
selector_token:
selector_element_root
-| option
;
/* [option|set] productions */
add_node (optnode_start, seqhead);
add_node ($1, optnode_end);
+ seqhead = NULL;
}
option_token_seq:
/* free resources */
free (docstr_start);
+ /* cleanup lexer */
+ cleanup_lexer();
+
/* clear state pointers */
seqhead = NULL;
currnode = NULL;
// 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);
"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;
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);