]> git.cworth.org Git - apitrace/commitdiff
cli_retrace: Forward all options to retrace program.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 21 Nov 2012 09:13:32 +0000 (09:13 +0000)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 21 Nov 2012 09:13:32 +0000 (09:13 +0000)
cli/cli_retrace.cpp

index cf9ffdf5786f0d46f313e016c8e19ac58316c387..a2dbd09986b86ffc5d31ab5318b02849699f8d4e 100644 (file)
 #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<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 +113,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 = {