X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=cli%2Fcli_retrace.cpp;h=d22f719bd65d6a584c416db6010d558a6a55ac9a;hb=48c661ea6c0f2bd9b76a3385cd946b7d07bc9b5f;hp=cf9ffdf5786f0d46f313e016c8e19ac58316c387;hpb=d7a4487ca3354de7603dee23eb0892b8467a6464;p=apitrace diff --git a/cli/cli_retrace.cpp b/cli/cli_retrace.cpp index cf9ffdf..d22f719 100644 --- a/cli/cli_retrace.cpp +++ b/cli/cli_retrace.cpp @@ -35,39 +35,18 @@ #include "os_process.hpp" #include "trace_parser.hpp" -#include "trace_resource.hpp" +#include "cli_resources.hpp" #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) { trace::Parser p; if (!p.open(filename)) { + exit(1); return trace::API_UNKNOWN; } trace::Call *call; @@ -98,10 +77,8 @@ executeRetrace(const std::vector & opts, case trace::API_D3D7: case trace::API_D3D8: case trace::API_D3D9: - case trace::API_D3D10: - case trace::API_D3D10_1: - case trace::API_D3D11: - // Can be used with WINE + case trace::API_DXGI: + // Use prefix so that it can be used with WINE retraceName = "d3dretrace.exe"; break; default: @@ -111,7 +88,7 @@ executeRetrace(const std::vector & opts, } std::vector command; - os::String retracePath = trace::findProgram(retraceName); + os::String retracePath = findProgram(retraceName); if (retracePath.length()) { command.push_back(retracePath); } else { @@ -120,7 +97,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 +112,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 = {