]> git.cworth.org Git - apitrace/blobdiff - cli/cli_diff_images.cpp
trace: Unwrap all args before serializing them.
[apitrace] / cli / cli_diff_images.cpp
index 390174c237bd5c05cd61e740dfa9cedbec3f5e3d..ba8df3e92a440afd5c29f3fafeb967559d281d2c 100644 (file)
 #include <iostream>
 
 #include "cli.hpp"
-#include "os_path.hpp"
-#include "trace_tools.hpp"
+#include "os_string.hpp"
+#include "os_process.hpp"
+#include "cli_resources.hpp"
 
 static const char *synopsis = "Identify differences between two image dumps.";
 
-static os::Path
+static os::String
 find_command(void)
 {
-#define CLI_DIFF_IMAGES_COMMAND "snapdiff.py"
-
-    return trace::findFile("scripts/" CLI_DIFF_IMAGES_COMMAND,
-     APITRACE_SCRIPTS_INSTALL_DIR "/" CLI_DIFF_IMAGES_COMMAND,
-                           true);
-
+    return findScript("snapdiff.py");
 }
 
 static void
 usage(void)
 {
-    char *args[3];
-
-    os::Path command = find_command();
-
-    args[0] = (char *) command.str();
-    args[1] = (char *) "--help";
-    args[2] = NULL;
+    os::String command = find_command();
+    if (!command.length()) {
+        exit(1);
+    }
 
-#ifdef _WIN32
-    std::cerr << "The 'apitrace diff-images' command is not yet supported on this O/S.\n";
-#else
-    execv(command.str(), args);
-#endif
+    char *args[4];
+    args[0] = (char *) "python";
+    args[1] = (char *) command.str();
+    args[2] = (char *) "--help";
+    args[3] = NULL;
 
-    std::cerr << "Error: Failed to execute " << args[0] << "\n";
+    os::execute(args);
 }
 
 static int
 command(int argc, char *argv[])
 {
     int i;
-    char **args = new char* [argc+2];
 
-    os::Path command = find_command();
-
-    args[0] = (char *) command.str();
-
-    for (i = 0; i < argc; i++) {
-        args[i+1] = argv[i];
+    os::String command = find_command();
+    if (!command.length()) {
+        return 1;
     }
 
-    args[i+1] = NULL;
-
-#ifdef _WIN32
-    std::cerr << "The 'apitrace diff-images' command is not yet supported on this O/S.\n";
-#else
-    execv(command.str(), args);
-#endif
-
-    std::cerr << "Error: Failed to execute " << args[0] << "\n";
+    std::vector<const char *> args;
+    args.push_back("python");
+    args.push_back(command.str());
+    for (i = 1; i < argc; i++) {
+        args.push_back(argv[i]);
+    }
+    args.push_back(NULL);
 
-    return 1;
+    return os::execute((char * const *)&args[0]);
 }
 
 const Command diff_images_command = {