diff options
author | José Fonseca <jose.r.fonseca@gmail.com> | 2011-10-30 14:29:28 +0000 |
---|---|---|
committer | José Fonseca <jose.r.fonseca@gmail.com> | 2011-10-30 14:29:28 +0000 |
commit | ffba59728abf36a0a9b8f7c6e4f6f0a1a95575b5 (patch) | |
tree | c3c6937276398dffae5096676ee7e7494e286de9 /cli | |
parent | 3c167fe5060d5fcd49422ef47c9602f6aedd978c (diff) |
Drop first_arg_command.
Unnecessary.
Diffstat (limited to 'cli')
-rw-r--r-- | cli/cli.hpp | 2 | ||||
-rw-r--r-- | cli/cli_dump.cpp | 4 | ||||
-rw-r--r-- | cli/cli_main.cpp | 33 |
3 files changed, 19 insertions, 20 deletions
diff --git a/cli/cli.hpp b/cli/cli.hpp index bc2dcf9..0792aff 100644 --- a/cli/cli.hpp +++ b/cli/cli.hpp @@ -36,7 +36,7 @@ struct Command { typedef void (*Usage) (void); Usage usage; - typedef int (*Function) (int argc, char *argv[], int first_command_arg); + typedef int (*Function) (int argc, char *argv[]); Function function; }; diff --git a/cli/cli_dump.cpp b/cli/cli_dump.cpp index 9f7752e..2164518 100644 --- a/cli/cli_dump.cpp +++ b/cli/cli_dump.cpp @@ -52,11 +52,11 @@ usage(void) } static int -command(int argc, char *argv[], int first_arg_command) +command(int argc, char *argv[]) { int i; - for (i = first_arg_command; i < argc; ++i) { + for (i = 0; i < argc; ++i) { const char *arg = argv[i]; if (arg[0] != '-') { diff --git a/cli/cli_main.cpp b/cli/cli_main.cpp index fd4dbbb..1731640 100644 --- a/cli/cli_main.cpp +++ b/cli/cli_main.cpp @@ -56,7 +56,7 @@ help_usage() } static int -help_command(int argc, char *argv[], int first_command_arg); +help_command(int argc, char *argv[]); const Command help = { "help", @@ -110,17 +110,17 @@ list_commands(void) { static int -help_command(int argc, char *argv[], int first_arg_command) +help_command(int argc, char *argv[]) { const Command *command; int i; - if (first_arg_command == argc) { + if (argc != 1) { help_usage(); return 0; } - char *command_name = argv[first_arg_command]; + char *command_name = argv[0]; for (i = 0; i < ARRAY_SIZE(commands); i++) { command = commands[i]; @@ -140,14 +140,9 @@ help_command(int argc, char *argv[], int first_arg_command) int main(int argc, char **argv) { - const char *command_name = "trace"; + const char *command_name; const Command *command; - int i, first_command_arg; - - if (argc == 1) { - usage(); - return 1; - } + int i; for (i = 1; i < argc; ++i) { const char *arg = argv[i]; @@ -157,25 +152,29 @@ main(int argc, char **argv) } if (strcmp(arg, "--help") == 0) { - return help_command (0, NULL, 0); + return help_command(0, NULL); } else { std::cerr << "Error: unknown option " << arg << "\n"; usage(); return 1; } } - first_command_arg = i; - if (first_command_arg < argc) { - command_name = argv[first_command_arg]; - first_command_arg++; + if (i == argc) { + usage(); + return 1; } + command_name = argv[i++]; + + argc -= i; + argv = &argv[i]; + for (i = 0; i < ARRAY_SIZE(commands); i++) { command = commands[i]; if (strcmp(command_name, command->name) == 0) - return (command->function) (argc, argv, first_command_arg); + return (command->function) (argc, argv); } std::cerr << "Error: unknown command " << command_name |