static void match_opt(const char *arg) { const char *eq = strchr(arg + 2, '='); const tw_optdef **group = all_groups; for (; *group; group++) { const tw_optdef *def = *group; for (; def->type; def++) { if (!def->name || def->type == TWOPTTYPE_GROUP) continue; if (!eq && !strcmp(def->name, arg + 2)) { apply_opt(def, NULL); return; } else if (eq && !strncmp(def->name, arg + 2, eq - arg - 2)) { apply_opt(def, eq + 1); return; } } } if (tw_ismaster()) fprintf(stderr, "%s: option '%s' not recognized; see --help for details\n", program, arg); tw_net_stop(); exit(1); }
void tw_end(void) { if(tw_ismaster()) { fprintf(g_tw_csv, "\n"); fclose(g_tw_csv); } tw_net_stop(); }
static void need_argument(const tw_optdef *def) { if (tw_ismaster()) fprintf(stderr, "%s: option --%s requires a valid argument\n", program, def->name); tw_net_stop(); exit(1); }
void tw_end(void) { if(tw_ismaster()) { fprintf(g_tw_csv, "\n"); fclose(g_tw_csv); } tw_net_stop(); // print end event array marker and end json file marker fputs("]\n}\n", desTraceFile); fclose(desTraceFile); }
static void apply_opt(const tw_optdef *def, const char *value) { switch (def->type) { case TWOPTTYPE_ULONG: case TWOPTTYPE_UINT: { unsigned long v; char *end; if (!value) need_argument(def); v = strtoul(value, &end, 10); if (*end) need_argument(def); switch (def->type) { case TWOPTTYPE_ULONG: *((unsigned long*)def->value) = v; break; case TWOPTTYPE_UINT: *((unsigned int*)def->value) = (unsigned int)v; break; default: tw_error(TW_LOC, "Option type not supported here."); } break; } case TWOPTTYPE_STIME: { tw_stime v; char *end; if (!value) need_argument(def); v = strtod(value, &end); if (*end) need_argument(def); *((tw_stime*)def->value) = v; break; } case TWOPTTYPE_CHAR: { if (!value) need_argument(def); //*((char **)def->value) = tw_calloc(TW_LOC, "string arg", strlen(value) + 1, 1); strcpy(def->value, value); break; } case TWOPTTYPE_SHOWHELP: if (tw_ismaster()) show_help(); tw_net_stop(); exit(0); break; default: tw_error(TW_LOC, "Option type not supported here."); } }