X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=cli%2Fcli_diff.cpp;h=f03e02d118c207828c45c165842224806021c9e5;hb=a65795f10ab268c2b2c4e079c715eca6f47c2239;hp=9f6efefa00eac2ac29e2b086161dd16b0c2a354c;hpb=589a579c395bd9d49e82cd94d7c20faaa550f400;p=apitrace diff --git a/cli/cli_diff.cpp b/cli/cli_diff.cpp index 9f6efef..f03e02d 100644 --- a/cli/cli_diff.cpp +++ b/cli/cli_diff.cpp @@ -35,14 +35,26 @@ static const char *synopsis = "Identify differences between two traces."; +static os::String +find_command(void) +{ + return trace::findScript("tracediff.py"); +} + static void usage(void) { - std::cout - << "usage: apitrace diff \n" - << synopsis << "\n" - "\n" - " Both input files should be the result of running 'apitrace trace'.\n"; + os::String command = find_command(); + if (!command.length()) { + exit(1); + } + + char *args[3]; + args[0] = (char *) command.str(); + args[1] = (char *) "--help"; + args[2] = NULL; + + os::execute(args); } static int @@ -50,55 +62,23 @@ 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")) { - usage(); - return 0; - } else { - std::cerr << "error: unknown option " << arg << "\n"; - usage(); - return 1; - } - } - - if (argc - i != 2) { - std::cerr << "Error: diff requires exactly two trace files as arguments.\n"; - usage(); + os::String command = find_command(); + if (!command.length()) { return 1; } - char *file1, *file2; - - file1 = argv[i]; - file2 = argv[i+1]; - - os::String command = trace::findScript("tracediff.sh"); + os::String apitracePath = os::getProcessName(); - char* args[4]; - - args[0] = (char *) command.str(); - args[1] = file1; - args[2] = file2; - args[3] = NULL; - -#ifdef _WIN32 - std::cerr << "The 'apitrace diff' command is not yet supported on this O/S.\n"; - return 1; -#else - os::String apitrace = os::getProcessName(); - setenv("APITRACE", apitrace.str(), 1); + std::vectorargs; + args.push_back(command.str()); + args.push_back("--apitrace"); + args.push_back(apitracePath.str()); + for (i = 1; i < argc; i++) { + args.push_back(argv[i]); + } + args.push_back(NULL); - return os::execute(args); -#endif + return os::execute((char * const *)&args[0]); } const Command diff_command = {