diff options
author | José Fonseca <jfonseca@vmware.com> | 2014-06-19 19:25:27 +0100 |
---|---|---|
committer | José Fonseca <jfonseca@vmware.com> | 2014-06-24 16:30:34 +0100 |
commit | a6e716225a2a181da4b6ddb9d8c31157e33cac9d (patch) | |
tree | 3eb6a924dfa57922e2b0964b26027832646f2f14 /cli | |
parent | aa5ba9351d37d4f9055c696edfaaee8db559f851 (diff) |
cli/diff-state: Get usage from jsondiff.py script.
Diffstat (limited to 'cli')
-rw-r--r-- | cli/cli_diff_state.cpp | 74 |
1 files changed, 27 insertions, 47 deletions
diff --git a/cli/cli_diff_state.cpp b/cli/cli_diff_state.cpp index a802b12a..427d258c 100644 --- a/cli/cli_diff_state.cpp +++ b/cli/cli_diff_state.cpp @@ -26,8 +26,6 @@ *********************************************************************/ #include <string.h> -#include <getopt.h> - #include <iostream> #include "cli.hpp" @@ -37,63 +35,45 @@ static const char *synopsis = "Identify differences between two state dumps."; +static os::String +find_command(void) +{ + return findScript("jsondiff.py"); +} + static void usage(void) { - std::cout - << "usage: apitrace diff-state <state-1> <state-2>\n" - << synopsis << "\n" - "\n" - " Both input files should be the result of running 'glretrace -D XYZ <trace>'.\n"; -} + os::String command = find_command(); + if (!command.length()) { + exit(1); + } -const static char * -shortOptions = "h"; + char *args[4]; + args[0] = (char *) "python"; + args[1] = (char *) command.str(); + args[2] = (char *) "--help"; + args[3] = NULL; -const static struct option -longOptions[] = { - {"help", no_argument, 0, 'h'}, - {0, 0, 0, 0} -}; + os::execute(args); +} static int command(int argc, char *argv[]) { - int opt; - while ((opt = getopt_long(argc, argv, shortOptions, longOptions, NULL)) != -1) { - switch (opt) { - case 'h': - usage(); - return 0; - default: - std::cerr << "error: unexpected option `" << (char)opt << "`\n"; - usage(); - return 1; - } - } - - if (argc != optind + 2) { - std::cerr << "Error: diff-state requires exactly two state-dump files as arguments.\n"; - usage(); - return 1; - } - - char *file1, *file2; + int i; - file1 = argv[optind]; - file2 = argv[optind + 1]; + os::String command = find_command(); - os::String command = findScript("jsondiff.py"); - - char *args[5]; - - args[0] = const_cast<char *>("python"); - args[1] = const_cast<char *>(command.str()); - args[2] = file1; - args[3] = file2; - args[4] = NULL; + 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 os::execute(args); + return os::execute((char * const *)&args[0]); } const Command diff_state_command = { |