From 9bbc3203ea6079d4222167e6b01cec9d041d08d9 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Mon, 19 Nov 2012 19:40:12 -0800 Subject: [PATCH] main: remove "pass-by-reference" editing in parse_options() parse_options() can simply pass the argc/argv variables through the model_checker_params struct now. Also, document a few things. --- main.cc | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/main.cc b/main.cc index 6456401..53bf7c5 100644 --- a/main.cc +++ b/main.cc @@ -54,11 +54,11 @@ params->maxreads, params->maxfuturevalues, params->maxfuturedelay, params->expir exit(EXIT_SUCCESS); } -static void parse_options(struct model_params *params, int *argc, char ***argv) { +static void parse_options(struct model_params *params, int argc, char **argv) { const char *shortopts = "hm:M:s:S:f:e:b:v"; int opt; bool error = false; - while (!error && (opt = getopt(*argc, *argv, shortopts)) != -1) { + while (!error && (opt = getopt(argc, argv, shortopts)) != -1) { switch (opt) { case 'h': print_usage(params); @@ -92,9 +92,15 @@ static void parse_options(struct model_params *params, int *argc, char ***argv) break; } } - (*argv)[optind - 1] = (*argv)[0]; - (*argc) -= (optind - 1); - (*argv) += (optind - 1); + + /* Pass remaining arguments to user program */ + params->argc = argc - (optind - 1); + params->argv = argv + (optind - 1); + + /* Reset program name */ + params->argv[0] = argv[0]; + + /* Reset (global) optind for potential use by user program */ optind = 1; if (error) @@ -110,11 +116,7 @@ static void model_main() { param_defaults(¶ms); - parse_options(¶ms, &main_argc, &main_argv); - - /* Pass remaining arguments to user program */ - params.argc = main_argc; - params.argv = main_argv; + parse_options(¶ms, main_argc, main_argv); //Initialize race detector initRaceDetector(); -- 2.34.1