// XXX: ideally, this would be const char. need to check if that works with all
// called functions.
static char *get_string(const char *identifier) {
- DLOG("Getting string %s from stack...\n", identifier);
for (int c = 0; c < 10; c++) {
if (stack[c].identifier == NULL)
break;
}
static void clear_stack(void) {
- DLOG("clearing stack.\n");
for (int c = 0; c < 10; c++) {
if (stack[c].str != NULL)
free(stack[c].str);
static void next_state(const cmdp_token *token) {
if (token->next_state == __CALL) {
- DLOG("should call stuff, yay. call_id = %d\n",
- token->extra.call_identifier);
subcommand_output.json_gen = command_output.json_gen;
subcommand_output.needs_tree_render = false;
GENERATED_call(token->extra.call_identifier, &subcommand_output);
/* TODO: Return parsing errors via JSON. */
struct CommandResult *parse_command(const char *input) {
- DLOG("new parser handling: %s\n", input);
+ DLOG("COMMAND: *%s*\n", input);
state = INITIAL;
/* A YAJL JSON generator used for formatting replies. */
*walk == '\r' || *walk == '\n') && *walk != '\0')
walk++;
- DLOG("remaining input = %s\n", walk);
-
cmdp_token_ptr *ptr = &(tokens[state]);
token_handled = false;
for (c = 0; c < ptr->n; c++) {
token = &(ptr->array[c]);
- DLOG("trying token %d = %s\n", c, token->name);
/* A literal. */
if (token->name[0] == '\'') {
- DLOG("literal\n");
if (strncasecmp(walk, token->name + 1, strlen(token->name) - 1) == 0) {
- DLOG("found literal, moving to next state\n");
if (token->identifier != NULL)
push_string(token->identifier, sstrdup(token->name + 1));
walk += strlen(token->name) - 1;
if (strcmp(token->name, "string") == 0 ||
strcmp(token->name, "word") == 0) {
- DLOG("parsing this as a string\n");
const char *beginning = walk;
/* Handle quoted strings (or words). */
if (*walk == '"') {
}
if (token->identifier)
push_string(token->identifier, str);
- DLOG("str is \"%s\"\n", str);
/* If we are at the end of a quoted string, skip the ending
* double quote. */
if (*walk == '"')
}
if (strcmp(token->name, "end") == 0) {
- DLOG("checking for the end token.\n");
if (*walk == '\0' || *walk == ',' || *walk == ';') {
- DLOG("yes, indeed. end\n");
next_state(token);
token_handled = true;
/* To make sure we start with an appropriate matching
y(array_close);
- DLOG("command_output.needs_tree_render = %d\n", command_output.needs_tree_render);
return &command_output;
}