static bool parse_cmp(ExprParseState *state) { CHECK_ERROR(parse_add(state)); BinaryOpFunc func = parse_get_cmp_func(state->token); if (func) { CHECK_ERROR(parse_next_token(state) && parse_add(state)); return parse_cmp_chain(state, func); } return true; }
// replace testName with the name of the particular test. Replace ClassName with // the name of the class being tested TEST(SOMETHING,SHOMETI) { std::stringstream ss; std::string parse_string("123this is a string to parse!"); Histogram histo; histo.add_count("alpha"); histo.add_count("digit"); histo.add_count("white space"); histo.add_count("punctuation"); parse_add(histo,parse_string); ss << histo; CHECK_EQUAL(49,ss.str().length()); }
static bool parse_cmp_chain(ExprParseState *state, BinaryOpFunc cur_func) { BinaryOpFunc next_func = parse_get_cmp_func(state->token); if (next_func) { parse_add_op(state, OPCODE_CMP_CHAIN, -1)->arg.func2 = cur_func; int jump = state->last_jmp = state->ops_count; CHECK_ERROR(parse_next_token(state) && parse_add(state)); CHECK_ERROR(parse_cmp_chain(state, next_func)); parse_set_jump(state, jump); } else { parse_add_func(state, OPCODE_FUNC2, 2, cur_func); } return true; }
int main(int ac, char **av) { const char *pidfile = NULL; const char *av0 = av[0]; char *ptr; enum cmd commandopt; int ch; int i; commandopt = CMD_NONE; while ((ch = getopt(ac, av, "fnlvp:")) != -1) { switch(ch) { case 'f': ++ForceOpt; break; case 'n': ++NumericOpt; break; case 'l': commandopt = CMD_LIST; break; case 'v': ++VerboseOpt; break; case 'p': pidfile = optarg; break; default: fprintf(stderr, "unknown option: -%c\n", optopt); usage(av0); } } ac -= optind; av += optind; /* * -l with no arguments dumps all syslink routers. This is the * only command that does not require further arguments. */ if (commandopt == CMD_LIST && ac == 0) exit(run_cmd(commandopt)); if (ac == 0) usage(av0); /* * Parse sysid[:linkid] */ ptr = strdup(av[0]); SysId = ptr; if ((ptr = strchr(ptr, ':')) != NULL) { *ptr++ = 0; LinkId = ptr; } --ac; ++av; /* * Handle options that are actually commands (-l only at the moment). * There should be no more arguments if we have a command-as-option. */ if (commandopt != CMD_NONE) { if (ac) usage(av0); exit(run_cmd(commandopt)); } /* * Parse keyword commands, set commandopt as an earmark. */ if (ac == 0) { fprintf(stderr, "Missing command directive\n"); usage(av0); } --ac; ++av; if (strcmp(av[-1], "add") == 0) { /* * add [protocol:]target[/bits] */ commandopt = CMD_ADD; if (ac == 0) usage(av0); if (parse_add(av[0])) usage(av0); --ac; ++av; } else if (strcmp(av[-1], "del") == 0) { commandopt = CMD_DEL; } else if (strcmp(av[-1], "delete") == 0) { commandopt = CMD_DEL; } else if (strcmp(av[-1], "mod") == 0) { commandopt = CMD_MOD; } else if (strcmp(av[-1], "modify") == 0) { commandopt = CMD_MOD; } else { fprintf(stderr, "Unknown command directive: %s\n", av[-1]); usage(av0); } /* * Parse supplementary info */ for (i = 0; i < ac; ++i) { if (strcmp(av[i], "label") == 0) { LabelStr = av[i+1]; ++i; } else if (strcmp(av[i], "port") == 0) { ptr = av[i+1]; TargetSin.sin_port = htons(strtol(ptr, &ptr, 0)); if (*ptr) { fprintf(stderr, "Non-numeric port specified\n"); usage(av0); } ++i; } else { fprintf(stderr, "Unknown directive: %s\n", av[i]); usage(av0); } } if (i > ac) { fprintf(stderr, "Expected argument for last directive\n"); usage(av0); } exit(run_cmd(commandopt)); }