From 54f752c09233cdb8e6149ac1e73b989bed367179 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Tue, 31 Jan 2012 10:02:52 +0000 Subject: [PATCH] Avoid hacking around argc / argv. --- cli/cli_diff.cpp | 2 +- cli/cli_diff_images.cpp | 8 ++++---- cli/cli_diff_state.cpp | 2 +- cli/cli_dump.cpp | 6 +----- cli/cli_main.cpp | 6 +++--- cli/cli_pickle.cpp | 2 +- cli/cli_repack.cpp | 2 +- cli/cli_trace.cpp | 2 +- cli/cli_trim.cpp | 2 +- scripts/tracediff.sh | 2 +- 10 files changed, 15 insertions(+), 19 deletions(-) diff --git a/cli/cli_diff.cpp b/cli/cli_diff.cpp index 0bd1b31..9f6efef 100644 --- a/cli/cli_diff.cpp +++ b/cli/cli_diff.cpp @@ -50,7 +50,7 @@ command(int argc, char *argv[]) { int i; - for (i = 0; i < argc; ++i) { + for (i = 1; i < argc; ++i) { const char *arg = argv[i]; if (arg[0] != '-') { diff --git a/cli/cli_diff_images.cpp b/cli/cli_diff_images.cpp index 42aaaff..626a34f 100644 --- a/cli/cli_diff_images.cpp +++ b/cli/cli_diff_images.cpp @@ -68,12 +68,12 @@ command(int argc, char *argv[]) return 1; } - char **args = new char* [argc + 2]; + char **args = new char* [argc + 1]; args[0] = (char *) command.str(); - for (i = 0; i < argc; i++) { - args[i + 1] = argv[i]; + for (i = 1; i < argc; i++) { + args[i] = argv[i]; } - args[i + 1] = NULL; + args[argc] = NULL; ret = os::execute(args); diff --git a/cli/cli_diff_state.cpp b/cli/cli_diff_state.cpp index 8918d58..8536e32 100644 --- a/cli/cli_diff_state.cpp +++ b/cli/cli_diff_state.cpp @@ -50,7 +50,7 @@ command(int argc, char *argv[]) { int i; - for (i = 0; i < argc; ++i) { + for (i = 1; i < argc; ++i) { const char *arg = argv[i]; if (arg[0] != '-') { diff --git a/cli/cli_dump.cpp b/cli/cli_dump.cpp index 3f393ce..d6f5014 100644 --- a/cli/cli_dump.cpp +++ b/cli/cli_dump.cpp @@ -117,10 +117,6 @@ command(int argc, char *argv[]) trace::DumpFlags dumpFlags = 0; bool dumpThreadIds = false; - // FIXME: avoid hacking around argc / argv - argc += 1; - argv = &argv[-1]; - int opt; while ((opt = getopt_long(argc, argv, shortOptions, longOptions, NULL)) != -1) { switch (opt) { @@ -154,7 +150,7 @@ command(int argc, char *argv[]) } break; case THREAD_IDS_OPT: - dumpThreadIds = boolOption(optarg, true); + dumpThreadIds = boolOption(optarg); break; default: std::cerr << "error: unexpected option `" << opt << "`\n"; diff --git a/cli/cli_main.cpp b/cli/cli_main.cpp index a776107..cff6a05 100644 --- a/cli/cli_main.cpp +++ b/cli/cli_main.cpp @@ -122,12 +122,12 @@ do_help_command(int argc, char *argv[]) const Command *command; int i; - if (argc != 1) { + if (argc != 2) { help_usage(); return 0; } - char *command_name = argv[0]; + char *command_name = argv[1]; for (i = 0; i < ARRAY_SIZE(commands); i++) { command = commands[i]; @@ -172,7 +172,7 @@ main(int argc, char **argv) return 1; } - command_name = argv[i++]; + command_name = argv[i]; argc -= i; argv = &argv[i]; diff --git a/cli/cli_pickle.cpp b/cli/cli_pickle.cpp index 8535b18..6af879f 100644 --- a/cli/cli_pickle.cpp +++ b/cli/cli_pickle.cpp @@ -166,7 +166,7 @@ command(int argc, char *argv[]) { int i; - for (i = 0; i < argc;) { + for (i = 1; i < argc;) { const char *arg = argv[i]; if (arg[0] != '-') { diff --git a/cli/cli_repack.cpp b/cli/cli_repack.cpp index 918f54a..a92723d 100644 --- a/cli/cli_repack.cpp +++ b/cli/cli_repack.cpp @@ -80,7 +80,7 @@ command(int argc, char *argv[]) { int i; - for (i = 0; i < argc; ++i) { + for (i = 1; i < argc; ++i) { const char *arg = argv[i]; if (arg[0] != '-') { diff --git a/cli/cli_trace.cpp b/cli/cli_trace.cpp index 92251b4..68526cb 100644 --- a/cli/cli_trace.cpp +++ b/cli/cli_trace.cpp @@ -64,7 +64,7 @@ command(int argc, char *argv[]) const char *output = NULL; int i; - for (i = 0; i < argc; ) { + for (i = 1; i < argc; ) { const char *arg = argv[i]; if (arg[0] != '-') { diff --git a/cli/cli_trim.cpp b/cli/cli_trim.cpp index 8fdd93c..515b4b6 100644 --- a/cli/cli_trim.cpp +++ b/cli/cli_trim.cpp @@ -56,7 +56,7 @@ command(int argc, char *argv[]) trace::CallSet calls(trace::FREQUENCY_ALL); int i; - for (i = 0; i < argc;) { + for (i = 1; i < argc;) { const char *arg = argv[i]; if (arg[0] != '-') { diff --git a/scripts/tracediff.sh b/scripts/tracediff.sh index 9f9633d..819a251 100755 --- a/scripts/tracediff.sh +++ b/scripts/tracediff.sh @@ -31,7 +31,7 @@ APITRACE=${APITRACE:-apitrace} $APITRACE dump stripdump () { - $APITRACE dump --color=never --no-arg-names "$1" \ + $APITRACE dump --color=never --arg-names=no "$1" \ | sed \ -e 's/\r$//g' \ -e 's/^[0-9]\+ //' \ -- 2.7.4