]> git.cworth.org Git - apitrace/blobdiff - cli/cli_diff_state.cpp
Update downloads link.
[apitrace] / cli / cli_diff_state.cpp
index 5dd0fbe4897decd52b4a5f5b31989a77d3c47ad6..341d244ff0d5adc14d9f0e59d6e06056068ed513 100644 (file)
  *********************************************************************/
 
 #include <string.h>
+#include <getopt.h>
+
 #include <iostream>
 
 #include "cli.hpp"
-#include "os_path.hpp"
+#include "os_string.hpp"
 #include "os_process.hpp"
-#include "trace_tools.hpp"
+#include "cli_resources.hpp"
 
 static const char *synopsis = "Identify differences between two state dumps.";
 
@@ -45,32 +47,32 @@ usage(void)
         "    Both input files should be the result of running 'glretrace -D XYZ <trace>'.\n";
 }
 
+const static char *
+shortOptions = "h";
+
+const static struct option
+longOptions[] = {
+    {"help", no_argument, 0, 'h'},
+    {0, 0, 0, 0}
+};
+
 static int
 command(int argc, char *argv[])
 {
-    int i;
-
-    for (i = 0; i < argc; ++i) {
-        const char *arg = argv[i];
-
-        if (arg[0] != '-') {
-            break;
-        }
-
-        if (!strcmp(arg, "--")) {
-            i++;
-            break;
-        } else if (!strcmp(arg, "--help")) {
+    int opt;
+    while ((opt = getopt_long(argc, argv, shortOptions, longOptions, NULL)) != -1) {
+        switch (opt) {
+        case 'h':
             usage();
             return 0;
-        } else {
-            std::cerr << "error: unknown option " << arg << "\n";
+        default:
+            std::cerr << "error: unexpected option `" << opt << "`\n";
             usage();
             return 1;
         }
     }
 
-    if (argc - i != 2) {
+    if (argc != optind + 2) {
         std::cerr << "Error: diff-state requires exactly two state-dump files as arguments.\n";
         usage();
         return 1;
@@ -78,14 +80,10 @@ command(int argc, char *argv[])
 
     char *file1, *file2;
 
-    file1 = argv[i];
-    file2 = argv[i+1];
-
-#define CLI_DIFF_STATE_COMMAND "jsondiff.py"
+    file1 = argv[optind];
+    file2 = argv[optind + 1];
 
-    os::Path command = trace::findFile("scripts/" CLI_DIFF_STATE_COMMAND,
-                 APITRACE_SCRIPTS_INSTALL_DIR "/" CLI_DIFF_STATE_COMMAND,
-                                       true);
+    os::String command = findScript("jsondiff.py");
 
     char *args[5];