]> git.cworth.org Git - apitrace/blobdiff - cli/cli_retrace.cpp
trace: Unwrap all args before serializing them.
[apitrace] / cli / cli_retrace.cpp
index cf9ffdf5786f0d46f313e016c8e19ac58316c387..d22f719bd65d6a584c416db6010d558a6a55ac9a 100644 (file)
 #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<const char *> & 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<const char *> & opts,
     }
 
     std::vector<const char *> 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<const char *> & 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<const char *> & opts,
     return executeRetrace(opts, traceName, api);
 }
 
+
+static const char *synopsis = "Replay a trace.";
+
+static void
+usage(void)
+{
+    std::vector<const char *>opts;
+    opts.push_back("--help");
+    trace::API api = trace::API_GL;
+    executeRetrace(opts, NULL, api);
+}
+
 static int
 command(int argc, char *argv[])
 {
     std::vector<const char *> 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 = {