X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=cli%2Fcli_diff_state.cpp;h=341d244ff0d5adc14d9f0e59d6e06056068ed513;hb=bd9811ff579a0482bfd7d40b1149bcef40ad3d71;hp=e58bd1d270172a14e964771f32af9a993bf1a41b;hpb=ca0c40fa6d5764b3f2ba7cafc7ba1c291e466005;p=apitrace diff --git a/cli/cli_diff_state.cpp b/cli/cli_diff_state.cpp index e58bd1d..341d244 100644 --- a/cli/cli_diff_state.cpp +++ b/cli/cli_diff_state.cpp @@ -26,11 +26,14 @@ *********************************************************************/ #include +#include + #include #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 state dumps."; @@ -44,32 +47,32 @@ usage(void) " Both input files should be the result of running 'glretrace -D XYZ '.\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; @@ -77,31 +80,20 @@ command(int argc, char *argv[]) char *file1, *file2; - file1 = argv[i]; - file2 = argv[i+1]; - -#define CLI_DIFF_STATE_COMMAND "jsondiff.py" - - os::Path command = trace::findFile("scripts/" CLI_DIFF_STATE_COMMAND, - APITRACE_SCRIPTS_INSTALL_DIR "/" CLI_DIFF_STATE_COMMAND, - true); - - char* args[4]; + file1 = argv[optind]; + file2 = argv[optind + 1]; - args[0] = (char *) command.str(); - args[1] = file1; - args[2] = file2; - args[3] = NULL; + os::String command = findScript("jsondiff.py"); -#ifdef _WIN32 - std::cerr << "The 'apitrace diff-state' command is not yet supported on this O/S.\n"; -#else - execv(command.str(), args); -#endif + char *args[5]; - std::cerr << "Error: Failed to execute " << argv[0] << "\n"; + args[0] = const_cast("python"); + args[1] = const_cast(command.str()); + args[2] = file1; + args[3] = file2; + args[4] = NULL; - return 1; + return os::execute(args); } const Command diff_state_command = {