#include "os_process.hpp"
#include "trace_parser.hpp"
-#include "trace_resource.hpp"
+#include "cli_resources.hpp"
#include "cli.hpp"
#include "cli_retrace.hpp"
-static const char *synopsis = "Replay a trace.";
-
-static void
-usage(void)
-{
- std::cout << "usage: apitrace retrace [OPTIONS] TRACE_FILE\n"
- << synopsis << "\n"
- "\n"
- " -h, --help Show this help message and exit\n"
- " -w, --wait Wait for user termination after the last frame\n"
- "\n";
-}
-
-const static char *
-shortOptions = "hw";
-
-const static struct option
-longOptions[] = {
- {"help", no_argument, 0, 'h'},
- {"wait", required_argument, 0, 'w'},
- {0, 0, 0, 0}
-};
static trace::API
guessApi(const char *filename)
{
trace::Parser p;
if (!p.open(filename)) {
+ exit(1);
return trace::API_UNKNOWN;
}
trace::Call *call;
case trace::API_D3D7:
case trace::API_D3D8:
case trace::API_D3D9:
- case trace::API_D3D10:
- case trace::API_D3D10_1:
- case trace::API_D3D11:
- // Can be used with WINE
+ case trace::API_DXGI:
+ // Use prefix so that it can be used with WINE
retraceName = "d3dretrace.exe";
break;
default:
}
std::vector<const char *> command;
- os::String retracePath = trace::findProgram(retraceName);
+ os::String retracePath = findProgram(retraceName);
if (retracePath.length()) {
command.push_back(retracePath);
} else {
command.insert(command.end(), opts.begin(), opts.end());
- command.push_back(traceName);
+ if (traceName) {
+ command.push_back(traceName);
+ }
command.push_back(NULL);
return os::execute((char * const *)&command[0]);
return executeRetrace(opts, traceName, api);
}
+
+static const char *synopsis = "Replay a trace.";
+
+static void
+usage(void)
+{
+ std::vector<const char *>opts;
+ opts.push_back("--help");
+ trace::API api = trace::API_GL;
+ executeRetrace(opts, NULL, api);
+}
+
static int
command(int argc, char *argv[])
{
std::vector<const char *> opts;
-
- const char *traceName;
-
- int opt;
- while ((opt = getopt_long(argc, argv, shortOptions, longOptions, NULL)) != -1) {
- switch (opt) {
- case 'h':
- usage();
- return 0;
- case 'w':
- opts.push_back("--wait");
- break;
- default:
- std::cerr << "error: unexpected option `" << opt << "`\n";
- usage();
- return 1;
- }
- }
-
- if (optind >= argc) {
- std::cerr << "error: apitrace retrace requires a trace file as an argument.\n";
- usage();
- return 1;
+ for (int i = 1; i < argc; ++i) {
+ opts.push_back(argv[i]);
}
- if (optind < argc - 1) {
- std::cerr << "error: apitrace retrace can accept only a single trace file argument.\n";
- usage();
- return 1;
+ trace::API api = trace::API_GL;
+ if (argc >= 1) {
+ const char *lastArg = argv[argc -1];
+ if (lastArg[0] != '-') {
+ api = guessApi(lastArg);
+ }
}
- traceName = argv[optind];
-
- return executeRetrace(opts, traceName);
+ return executeRetrace(opts, NULL, api);
}
const Command retrace_command = {
- "retrace",
+ "replay",
synopsis,
usage,
command