]> git.cworth.org Git - apitrace/commitdiff
apitrace: Replace tracedump program with new "apitrace dump" command
authorCarl Worth <cworth@cworth.org>
Sat, 22 Oct 2011 03:40:56 +0000 (20:40 -0700)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 30 Oct 2011 13:27:59 +0000 (13:27 +0000)
The code just copies right over so should work exactly as before, but
with our nice, new, unified command-line syntax.

CMakeLists.txt
cli/CMakeLists.txt
cli/apitrace.cpp
cli/apitrace_cli.hpp [new file with mode: 0644]
cli/apitrace_dump.cpp [new file with mode: 0644]
tracedump.cpp [deleted file]

index 82cad7ef7399b725c014f70d2d95eb3e1b2ba199..0b4ab84f20c1c6e7aa59ba65b42ff97d3a530bdd 100755 (executable)
@@ -230,10 +230,6 @@ set_target_properties (common PROPERTIES
 
 link_libraries (common)
 
-add_executable (tracedump tracedump.cpp)
-
-install (TARGETS tracedump RUNTIME DESTINATION bin)
-
 ##############################################################################
 # API tracers
 
index 8772179867fdd473f9e7d79cc14b89723e886868..c25b4ce793f44c7ecc2e25ceed33853362c5d9e3 100644 (file)
@@ -1,3 +1,5 @@
-add_executable (apitrace apitrace.cpp)
+add_executable (apitrace
+  apitrace.cpp
+  apitrace_dump.cpp)
 
 install (TARGETS apitrace RUNTIME DESTINATION bin)
index b36064a43d69d515d6104440860ded09ae347c64..107952cf5529165ce8211df11d2fffaa55ff50c8 100644 (file)
  * functionality.
  */
 
-#include <iostream>
-#include <iomanip>
-
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#include "config.h"
+#include "apitrace_cli.hpp"
 
 #define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0]))
 
+typedef void (*command_usage_t) (const char *argv0);
 typedef int (*command_function_t) (int argc, char *argv[], int first_command_arg);
 
 typedef struct {
     const char *name;
+    const char *synopsis;
+    command_usage_t usage;
     command_function_t function;
-    const char *arguments;
-    const char *summary;
-    const char *documentation;
 } Command;
 
+#define APITRACE_HELP_SYNOPSIS "Print detailed help for the given command."
+
+static void
+apitrace_help_usage(const char *argv0)
+{
+    std::cout << argv0 << " [<command>]"
+        "\n\n\t"
+        APITRACE_HELP_SYNOPSIS
+        "\n\n\t"
+        "Except in this case, where this is all the help you will get."
+        "\n\n";
+}
+
 static int
 apitrace_help_command(int argc, char *argv[], int first_command_arg);
 
 static Command commands[] = {
-    { "help", apitrace_help_command,
-      "[<command>]",
-      "Print detailed help for the given command.",
-      "\tExcept in this case, where this is all the help you will get." }
+    { "dump",
+      APITRACE_DUMP_SYNOPSIS,
+      apitrace_dump_usage,
+      apitrace_dump_command },
+    { "help",
+      APITRACE_HELP_SYNOPSIS,
+      apitrace_help_usage,
+      apitrace_help_command }
 };
 
-static void
+void
 usage(void)
 {
     Command *command;
@@ -85,7 +94,7 @@ usage(void)
         command = &commands[i];
 
         std::cout << " " << std::setw(max_width+2) << command->name
-                  << " " << command->summary << "\n";
+                  << " " << command->synopsis << "\n";
     }
 
     std::cout << "\n"
@@ -110,13 +119,7 @@ apitrace_help_command(int argc, char *argv[], int first_arg_command)
 
         if (strcmp(command_name, command->name) == 0) {
             std::cout << "Help for \"apitrace " << command_name << "\":\n\n";
-            std::cout << command->name;
-            if (command->arguments)
-                std::cout << " " << command->arguments
-                          << "\n\n\t" << command->summary;
-            else
-                std::cout << "\t" << command->summary;
-            std::cout << "\n\n" << command->documentation << "\n\n";
+            (command->usage) ("apitrace");
 
             return 0;
         }
diff --git a/cli/apitrace_cli.hpp b/cli/apitrace_cli.hpp
new file mode 100644 (file)
index 0000000..7394bb9
--- /dev/null
@@ -0,0 +1,50 @@
+/*********************************************************************
+ *
+ * Copyright 2011 Intel Corporation
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ *********************************************************************/
+
+#ifndef _APITRACE_CLI_HPP_
+#define _APITRACE_CLI_HPP_
+
+#include <iostream>
+#include <iomanip>
+
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#define APITRACE_DUMP_SYNOPSIS "Dump given trace(s) to standard output."
+
+void
+apitrace_dump_usage(const char *argv0);
+
+int
+apitrace_dump_command(int argc, char *argv[], int first_command_arg);
+
+void
+usage(void);
+
+#endif /* _APITRACE_CLI_HPP_ */
diff --git a/cli/apitrace_dump.cpp b/cli/apitrace_dump.cpp
new file mode 100644 (file)
index 0000000..41900cf
--- /dev/null
@@ -0,0 +1,109 @@
+/**************************************************************************
+ *
+ * Copyright 2010 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#include "apitrace_cli.hpp"
+
+#include "trace_parser.hpp"
+
+enum ColorOption {
+    COLOR_OPTION_NEVER = 0,
+    COLOR_OPTION_ALWAYS = 1,
+    COLOR_OPTION_AUTO = -1
+};
+
+static ColorOption color = COLOR_OPTION_AUTO;
+
+void
+apitrace_dump_usage(const char *argv0)
+{
+    std::cout << argv0 << " [OPTIONS] <trace-file>..."
+        "\n\n\t"
+        APITRACE_DUMP_SYNOPSIS
+        "\n\n\t"
+        "Supports the following options:\n\t"
+       "\t--color=<WHEN>\n\t"
+       "\t--colour=<WHEN>     Colored syntax highlighting\n\t"
+       "\t                    WHEN is 'auto', 'always', or 'never'\n";
+}
+
+int
+apitrace_dump_command(int argc, char *argv[], int first_arg_command)
+{
+    int i;
+
+    for (i = first_arg_command; i < argc; ++i) {
+        const char *arg = argv[i];
+
+        if (arg[0] != '-') {
+            break;
+        }
+
+        if (!strcmp(arg, "--")) {
+            break;
+        } else if (!strcmp(arg, "--color=auto") ||
+                   !strcmp(arg, "--colour=auto")) {
+            color = COLOR_OPTION_AUTO;
+        } else if (!strcmp(arg, "--color") ||
+                   !strcmp(arg, "--colour") ||
+                   !strcmp(arg, "--color=always") ||
+                   !strcmp(arg, "--colour=always")) {
+            color = COLOR_OPTION_ALWAYS;
+        } else if (!strcmp(arg, "--color=never") ||
+                   !strcmp(arg, "--colour=never") ||
+                   !strcmp(arg, "--no-color") ||
+                   !strcmp(arg, "--no-colour")) {
+            color = COLOR_OPTION_NEVER;
+        } else {
+            std::cerr << "error: unknown option " << arg << "\n";
+            usage();
+            return 1;
+        }
+    }
+
+    if (color == COLOR_OPTION_AUTO) {
+#ifdef _WIN32
+        color = COLOR_OPTION_ALWAYS;
+#else
+        color = isatty(1) ? COLOR_OPTION_ALWAYS : COLOR_OPTION_NEVER;
+#endif
+    }
+
+    for (; i < argc; ++i) {
+        trace::Parser p;
+
+        if (!p.open(argv[i])) {
+            std::cerr << "error: failed to open " << argv[i] << "\n";
+            return 1;
+        }
+
+        trace::Call *call;
+        while ((call = p.parse_call())) {
+            call->dump(std::cout, color);
+            delete call;
+        }
+    }
+
+    return 0;
+}
diff --git a/tracedump.cpp b/tracedump.cpp
deleted file mode 100644 (file)
index 44ca609..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2010 VMware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- **************************************************************************/
-
-
-/*
- * Simple utility to dump a trace to standard output.
- */
-
-
-#include <string.h>
-
-#include "trace_parser.hpp"
-
-
-enum ColorOption {
-    COLOR_OPTION_NEVER = 0,
-    COLOR_OPTION_ALWAYS = 1,
-    COLOR_OPTION_AUTO = -1
-};
-
-static ColorOption color = COLOR_OPTION_AUTO;
-
-
-static void usage(void) {
-    std::cout <<
-        "Usage: tracedump [OPTION] [TRACE]...\n"
-        "Dump TRACE to standard output.\n"
-        "\n"
-        "  --help               display this help and exit\n"
-        "  --color[=WHEN]\n"
-        "  --colour[=WHEN]      colored syntax highlighting;\n"
-        "                       WHEN is 'always', 'never', or 'auto'\n"
-    ;
-}
-
-
-int main(int argc, char **argv)
-{
-    int i;
-
-    for (i = 1; i < argc; ++i) {
-        const char *arg = argv[i];
-
-        if (arg[0] != '-') {
-            break;
-        }
-
-        if (!strcmp(arg, "--")) {
-            break;
-        } else if (!strcmp(arg, "--help")) {
-            usage();
-            return 0;
-        } else if (!strcmp(arg, "--color=auto") ||
-                   !strcmp(arg, "--colour=auto")) {
-            color = COLOR_OPTION_AUTO;
-        } else if (!strcmp(arg, "--color") ||
-                   !strcmp(arg, "--colour") ||
-                   !strcmp(arg, "--color=always") ||
-                   !strcmp(arg, "--colour=always")) {
-            color = COLOR_OPTION_ALWAYS;
-        } else if (!strcmp(arg, "--color=never") ||
-                   !strcmp(arg, "--colour=never") ||
-                   !strcmp(arg, "--no-color") ||
-                   !strcmp(arg, "--no-colour")) {
-            color = COLOR_OPTION_NEVER;
-        } else {
-            std::cerr << "error: unknown option " << arg << "\n";
-            usage();
-            return 1;
-        }
-    }
-
-    if (color == COLOR_OPTION_AUTO) {
-#ifdef _WIN32
-        color = COLOR_OPTION_ALWAYS;
-#else
-        color = isatty(1) ? COLOR_OPTION_ALWAYS : COLOR_OPTION_NEVER;
-#endif
-    }
-
-    for (; i < argc; ++i) {
-        trace::Parser p;
-
-        if (!p.open(argv[i])) {
-            std::cerr << "error: failed to open " << argv[i] << "\n";
-            return 1;
-        }
-
-        trace::Call *call;
-        while ((call = p.parse_call())) {
-            call->dump(std::cout, color);
-            delete call;
-        }
-    }
-
-    return 0;
-}