X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=cli%2Fcli_diff_state.cpp;h=a802b12a6bdf18f573d09ca9315c8e396627eeb1;hb=4ce88b87e64c56b2638ee2b6b4785b4ed35aabd6;hp=8536e3235c16b170388ce899ce9c651d29ae5f7c;hpb=54f752c09233cdb8e6149ac1e73b989bed367179;p=apitrace diff --git a/cli/cli_diff_state.cpp b/cli/cli_diff_state.cpp index 8536e32..a802b12 100644 --- a/cli/cli_diff_state.cpp +++ b/cli/cli_diff_state.cpp @@ -26,12 +26,14 @@ *********************************************************************/ #include +#include + #include #include "cli.hpp" #include "os_string.hpp" #include "os_process.hpp" -#include "trace_resource.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 '.\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 = 1; 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 `" << (char)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,10 +80,10 @@ command(int argc, char *argv[]) char *file1, *file2; - file1 = argv[i]; - file2 = argv[i+1]; + file1 = argv[optind]; + file2 = argv[optind + 1]; - os::String command = trace::findScript("jsondiff.py"); + os::String command = findScript("jsondiff.py"); char *args[5];