String eval_sys(Mapping *m, Statement *source, Queue *repQueue) { String prepare = copy_string(m->sys->prepare); String eval = copy_string(m->sys->eval); Mapping *mapping = NULL; String* array = NULL; String* arraySource = NULL; String* arrayTarget = NULL; String prepareSource; String prepareTarget; String sourceFuncMacro; String sourceMacro; String targetFuncMacro; String targetMacro; if (!equals_string(prepare, "NIL")) { mapping = alloc_mapping(); mapping->sys = NULL; if (strcmp(m->sys->name, DEF_MACRO) == 0) { mapping->isMacro = TRUE; } else { mapping->isMacro = FALSE; } array = split_string_once(prepare, '>'); prepareSource = array[0]; prepareTarget = array[1]; arraySource = split_string_once(prepareSource, ','); sourceFuncMacro = trim_string(arraySource[0]); sourceMacro = trim_string(arraySource[1]); mapping->source = parse_macro(repQueue, sourceMacro); mapping->sourceFunc = parse_macro(repQueue, sourceFuncMacro); mapping->sourceStatement = parse(mapping->source); mapping->starter = to_dfa(mapping->sourceStatement); arrayTarget = split_string_once(prepareTarget, ','); targetFuncMacro = trim_string(arrayTarget[0]); targetMacro = trim_string(arrayTarget[1]); mapping->target = parse_macro(repQueue, targetMacro); mapping->targetFunc = parse_macro(repQueue, targetFuncMacro); mapping->targetStatement = parse(mapping->target); //enqueue(get_mappings(), mapping); add_mapping_to_trie(mapping); } if (!equals_string(eval, "NIL")) { return parse_macro(repQueue, eval); } else { return ""; } }
void test_split_string_once() { String str = copy_string("aaaaaa|bbbbbb|cccccc"); String *arr = split_string_once(str, '|'); assert(strcmp(arr[0], "aaaaaa") == 0); assert(strcmp(arr[1], "bbbbbb|cccccc") == 0); assert(arr[2] == NULL); }
int plotstuff_run_command(plot_args_t* pargs, const char* cmd) { int i; anbool matched = FALSE; if (!cmd || (strlen(cmd) == 0) || (cmd[0] == '#')) { return 0; } if (!plotstuff_plot_layer(pargs, cmd)) { return 0; } for (i=0; i<pargs->NP; i++) { if (starts_with(cmd, pargs->plotters[i].name)) { char* cmdcmd; char* cmdargs; if (!split_string_once(cmd, " ", &cmdcmd, &cmdargs)) { //ERROR("Failed to split command \"%s\" into words\n", cmd); //return -1; cmdcmd = strdup(cmd); cmdargs = NULL; } logmsg("Command \"%s\", args \"%s\"\n", cmdcmd, cmdargs); if (pargs->plotters[i].command(cmdcmd, cmdargs, pargs, pargs->plotters[i].baton)) { ERROR("Plotter \"%s\" failed on command \"%s\"", pargs->plotters[i].name, cmd); return -1; } free(cmdcmd); free(cmdargs); } else continue; matched = TRUE; break; } if (!matched) { ERROR("Did not find a plotter for command \"%s\"", cmd); return -1; } return 0; }