2016-06-23 16:47:32 +02:00
|
|
|
#include "command.h"
|
2016-07-17 23:49:16 +02:00
|
|
|
#include "command_parse.h"
|
2016-07-18 18:16:36 +02:00
|
|
|
#include "cmdtree.h"
|
2016-06-23 16:47:32 +02:00
|
|
|
|
|
|
|
#define GRAMMAR_STR "CLI grammar sandbox\n"
|
|
|
|
|
2016-07-19 19:06:11 +02:00
|
|
|
struct graph_node * nodegraph;
|
|
|
|
|
2016-07-17 23:49:16 +02:00
|
|
|
DEFUN (grammar_test,
|
|
|
|
grammar_test_cmd,
|
2016-07-19 19:06:11 +02:00
|
|
|
"grammar parse .COMMAND",
|
2016-06-23 16:47:32 +02:00
|
|
|
GRAMMAR_STR
|
2016-07-17 23:49:16 +02:00
|
|
|
"command to pass to new parser\n")
|
2016-06-23 16:47:32 +02:00
|
|
|
{
|
2016-07-17 23:49:16 +02:00
|
|
|
size_t linesize = 0;
|
|
|
|
for (int i = 0; i < argc; i++)
|
|
|
|
linesize += strlen(argv[i]) + 1;
|
2016-06-23 16:47:32 +02:00
|
|
|
|
2016-07-17 23:49:16 +02:00
|
|
|
char* cat = malloc(linesize);
|
|
|
|
cat[0] = '\0';
|
|
|
|
for (int i = 0; i < argc; i++) {
|
|
|
|
strcat(cat, argv[i]);
|
|
|
|
if (i != argc)
|
|
|
|
strcat(cat, " ");
|
|
|
|
}
|
2016-06-23 16:47:32 +02:00
|
|
|
|
2016-07-19 19:06:11 +02:00
|
|
|
//struct graph_node *result = new_node(NUL_GN);
|
|
|
|
cmd_parse_format_new((const char*) cat, "lol", nodegraph);
|
|
|
|
walk_graph(nodegraph, 0);
|
|
|
|
|
2016-07-17 23:49:16 +02:00
|
|
|
return CMD_SUCCESS;
|
2016-06-23 16:47:32 +02:00
|
|
|
}
|
|
|
|
|
2016-07-19 19:06:11 +02:00
|
|
|
DEFUN (grammar_test_show,
|
|
|
|
grammar_test_show_cmd,
|
|
|
|
"grammar tree",
|
|
|
|
GRAMMAR_STR
|
|
|
|
"print current accumulated DFA\n")
|
|
|
|
{
|
|
|
|
walk_graph(nodegraph, 0);
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-06-23 16:47:32 +02:00
|
|
|
|
|
|
|
void grammar_sandbox_init(void);
|
|
|
|
void grammar_sandbox_init() {
|
2016-07-19 19:06:11 +02:00
|
|
|
fprintf(stderr, "reinitializing graph\n");
|
|
|
|
nodegraph = new_node(NUL_GN);
|
2016-07-17 23:49:16 +02:00
|
|
|
install_element (ENABLE_NODE, &grammar_test_cmd);
|
2016-07-19 19:06:11 +02:00
|
|
|
install_element (ENABLE_NODE, &grammar_test_show_cmd);
|
2016-06-23 16:47:32 +02:00
|
|
|
}
|