29 fprintf(stderr,
"usage: %s [options] [-- [args]]\n",
program);
32 for (; *group; group++)
35 for (; def->
type; def++)
43 fprintf(stderr,
"%s:\n", def->
help);
48 pos += fprintf(stderr,
" --%s", def->
name);
54 pos += fprintf(stderr,
"=n");
58 pos += fprintf(stderr,
"=dbl");
62 pos += fprintf(stderr,
"=ts");
66 pos += fprintf(stderr,
"=str");
78 fprintf(stderr,
"%*s", col - pos,
"");
81 fprintf(stderr,
"%*s", col,
"");
84 fputs(def->
help, stderr);
92 fprintf(stderr,
" (default %lu)", *((
unsigned long*)def->
value));
96 fprintf(stderr,
" (default %llu)", *((
unsigned long long*)def->
value));
100 fprintf(stderr,
" (default %u)", *((
unsigned int*)def->
value));
104 fprintf(stderr,
" (default %.2f)", *((
double*)def->
value));
108 fprintf(stderr,
" (default %.2f)", *((
tw_stime*)def->
value));
112 fprintf(stderr,
" (default %s)", (
char *) def->
value);
116 if((*(
unsigned int*)def->
value) == 0) {
117 fprintf(stderr,
" (default off)");
119 fprintf(stderr,
" (default on)");
134 fprintf(stderr,
"ROSS CMake Configuration Options:\n");
135 fprintf(stderr,
" (See build-dir/core/config.h)\n");
142 for (; *group; group++){
144 for (; def->
type; def++){
149 fputc(
'\n', outfile);
150 fprintf(outfile,
"%s:\n", def->
help);
155 pos += fprintf(outfile,
" --%s", def->
name);
161 fprintf(outfile,
"%*s", col - pos,
"");
163 fputc(
'\n', outfile);
164 fprintf(outfile,
"%*s", col,
"");
172 fprintf(outfile,
"%lu", *((
unsigned long*)def->
value));
176 fprintf(outfile,
"%llu", *((
unsigned long long*)def->
value));
180 fprintf(outfile,
"%u", *((
unsigned int*)def->
value));
184 fprintf(outfile,
"%.2f", *((
double*)def->
value));
192 fprintf(outfile,
"%s", (
char *) def->
value);
196 if((*(
unsigned int*)def->
value) == 0) {
197 fprintf(outfile,
"off");
199 fprintf(outfile,
"on");
208 fputc(
'\n', outfile);
223 for (; *group; group++)
226 for (; def->
type; def++)
229 (def->
name && 0 == strcmp(def->
name,
"help")))
237 fprintf(f,
"%lu,", *((
unsigned long*)def->
value));
241 fprintf(f,
"%llu,", *((
unsigned long long*)def->
value));
245 fprintf(f,
"%u,", *((
unsigned int*)def->
value));
249 fprintf(f,
"%.2f,", *((
double*)def->
value));
257 fprintf(f,
"%s,", (
char *)def->
value);
261 fprintf(f,
"%s,", (
char *)def->
name);
268 fprintf(f,
"undefined,");
280 "%s: option --%s requires a valid argument\n",
300 v = strtoul(value, &end, 10);
306 *((
unsigned long*)def->
value) = v;
309 *((
unsigned long long*)def->
value) = v;
313 *((
unsigned int*)def->
value) = (
unsigned int)v;
328 v = strtod(value, &end);
331 *((
double*)def->
value) = v;
340 tw_warning(
TW_LOC,
"Option type stime (TWOPT_STIME) is deprecated. Please use double (TWOPT_DOUBLE).");
344 v = strtod(value, &end);
357 strcpy((
char *) def->
value, value);
362 *((
unsigned int*)def->
value) = 1;
380 const char *eq = strchr(arg + 2,
'=');
383 for (; *group; group++)
386 for (; def->
type; def++)
390 if (!eq && !strcmp(def->
name, arg + 2))
395 else if (eq && !strncmp(def->
name, arg + 2, eq - arg - 2))
405 "%s: option '%s' not recognized; see --help for details\n",
418 for (; def->
type; def++) {
430 char **argv = *argv_p;
433 program = strrchr(argv[0],
'/');
439 for (i = 0; opt_groups[i]; i++)
441 if (!(opt_groups[i])->type ||
is_empty(opt_groups[i]))
445 all_groups[i] = opt_groups[i];
447 all_groups[i++] =
basic;
448 all_groups[i] = NULL;
452 const char *s = argv[1];
453 if (strncmp(s,
"--", 2))
455 printf(
"Warning: found ill-formated argument: %s, stopping arg parsing here!! \n", s );
462 memmove(argv + 1, argv + 2, (argc - 1) *
sizeof(*argv));
464 if (!strcmp(s,
"--"))
static int is_empty(const tw_optdef *def)
static void need_argument(const tw_optdef *def)
static void apply_opt(const tw_optdef *def, const char *value)
void tw_net_stop(void)
Stops the network library after simulation end.
void tw_error(const char *file, int line, const char *fmt,...) NORETURN
static int tw_ismaster(void)
void tw_warning(const char *file, int line, const char *fmt,...)
static const tw_optdef * opt_groups[10]
static const tw_optdef * all_groups[10]
static const char * program
void tw_opt_add(const tw_optdef *options)
static void show_help(void)
void tw_opt_settings(FILE *outfile)
static const tw_optdef basic[]
static void match_opt(const char *arg)
static unsigned int opt_index
void tw_opt_parse(int *argc_p, char ***argv_p)