From: José Fonseca Date: Wed, 21 Nov 2012 09:13:32 +0000 (+0000) Subject: cli_retrace: Forward all options to retrace program. X-Git-Url: https://git.cworth.org/git?p=apitrace;a=commitdiff_plain;h=ec8277753112a8f6ac2495cb7fcf09f5c50687bc cli_retrace: Forward all options to retrace program. --- diff --git a/cli/cli_retrace.cpp b/cli/cli_retrace.cpp index cf9ffdf..a2dbd09 100644 --- a/cli/cli_retrace.cpp +++ b/cli/cli_retrace.cpp @@ -40,28 +40,6 @@ #include "cli.hpp" #include "cli_retrace.hpp" -static const char *synopsis = "Replay a trace."; - -static void -usage(void) -{ - std::cout << "usage: apitrace retrace [OPTIONS] TRACE_FILE\n" - << synopsis << "\n" - "\n" - " -h, --help Show this help message and exit\n" - " -w, --wait Wait for user termination after the last frame\n" - "\n"; -} - -const static char * -shortOptions = "hw"; - -const static struct option -longOptions[] = { - {"help", no_argument, 0, 'h'}, - {"wait", required_argument, 0, 'w'}, - {0, 0, 0, 0} -}; static trace::API guessApi(const char *filename) @@ -120,7 +98,9 @@ executeRetrace(const std::vector & opts, command.insert(command.end(), opts.begin(), opts.end()); - command.push_back(traceName); + if (traceName) { + command.push_back(traceName); + } command.push_back(NULL); return os::execute((char * const *)&command[0]); @@ -133,44 +113,35 @@ executeRetrace(const std::vector & opts, return executeRetrace(opts, traceName, api); } + +static const char *synopsis = "Replay a trace."; + +static void +usage(void) +{ + std::vectoropts; + opts.push_back("--help"); + trace::API api = trace::API_GL; + executeRetrace(opts, NULL, api); +} + static int command(int argc, char *argv[]) { std::vector opts; - - const char *traceName; - - int opt; - while ((opt = getopt_long(argc, argv, shortOptions, longOptions, NULL)) != -1) { - switch (opt) { - case 'h': - usage(); - return 0; - case 'w': - opts.push_back("--wait"); - break; - default: - std::cerr << "error: unexpected option `" << opt << "`\n"; - usage(); - return 1; - } - } - - if (optind >= argc) { - std::cerr << "error: apitrace retrace requires a trace file as an argument.\n"; - usage(); - return 1; + for (int i = 1; i < argc; ++i) { + opts.push_back(argv[i]); } - if (optind < argc - 1) { - std::cerr << "error: apitrace retrace can accept only a single trace file argument.\n"; - usage(); - return 1; + trace::API api = trace::API_GL; + if (argc >= 1) { + const char *lastArg = argv[argc -1]; + if (lastArg[0] != '-') { + api = guessApi(lastArg); + } } - traceName = argv[optind]; - - return executeRetrace(opts, traceName); + return executeRetrace(opts, NULL, api); } const Command retrace_command = {