1 /*********************************************************************
3 * Copyright 2011 Intel Corporation
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use, copy,
10 * modify, merge, publish, distribute, sublicense, and/or sell copies
11 * of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 *********************************************************************/
30 * Top-level application for accessing almost all of apitrace
41 #define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0]))
43 static const char *help_synopsis = "Print detailed help for the given command.";
45 static void list_commands(void);
51 << "usage: apitrace help [<command>]\n"
52 << help_synopsis << "\n"
59 do_help_command(int argc, char *argv[]);
61 const Command help_command = {
68 static const Command * commands[] = {
79 "Usage: apitrace <command> [<args> ...]\n"
80 "Top-level command line frontend to apitrace.\n"
88 const Command *command;
91 std::cout << "The available commands are as follows:\n\n";
93 std::cout << std::setiosflags(std::ios::left);
95 for (i = 0; i < ARRAY_SIZE(commands); i++) {
96 command = commands[i];
97 if (strlen(command->name) > max_width) {
98 max_width = strlen(command->name);
102 for (i = 0; i < ARRAY_SIZE(commands); i++) {
103 command = commands[i];
105 std::cout << " " << std::setw(max_width + 2) << command->name
106 << " " << command->synopsis << "\n";
110 "Use \"apitrace help <command>\" for more details on each command.\n";
115 do_help_command(int argc, char *argv[])
117 const Command *command;
125 char *command_name = argv[0];
127 for (i = 0; i < ARRAY_SIZE(commands); i++) {
128 command = commands[i];
130 if (strcmp(command_name, command->name) == 0) {
136 std::cerr << "Error: Unknown command: " << command_name
137 << " (see \"apitrace help\").\n";
143 main(int argc, char **argv)
145 const char *command_name;
146 const Command *command;
149 for (i = 1; i < argc; ++i) {
150 const char *arg = argv[i];
156 if (strcmp(arg, "--help") == 0) {
157 return do_help_command(0, NULL);
159 std::cerr << "Error: unknown option " << arg << "\n";
170 command_name = argv[i++];
175 for (i = 0; i < ARRAY_SIZE(commands); i++) {
176 command = commands[i];
178 if (strcmp(command_name, command->name) == 0)
179 return (command->function) (argc, argv);
182 std::cerr << "Error: unknown command " << command_name
183 << " (see \"apitrace help\").\n";