[PATCH] trace-cmd: add getopt support to gui tools for input

From: Darren Hart
Date: Tue Dec 29 2009 - 14:19:15 EST


From b3acaddbe845dd3296374a32951b29616519da86 Mon Sep 17 00:00:00 2001
From: Darren Hart <dvhltc@xxxxxxxxxx>
Date: Tue, 29 Dec 2009 11:17:37 -0800
Subject: [PATCH] trace-cmd: add getopt support to gui tools for input file

Signed-off-by: Darren Hart <dvhltc@xxxxxxxxxx>
---
kernel-shark.c | 28 +++++++++++++++++++++++++++-
trace-graph-main.c | 28 +++++++++++++++++++++++++++-
trace-view-main.c | 29 ++++++++++++++++++++++++++++-
3 files changed, 82 insertions(+), 3 deletions(-)

diff --git a/kernel-shark.c b/kernel-shark.c
index 158b9ac..0d72459 100644
--- a/kernel-shark.c
+++ b/kernel-shark.c
@@ -18,12 +18,15 @@
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
+#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <fcntl.h>
#include <unistd.h>
#include <gtk/gtk.h>
+#include <getopt.h>
+#include <string.h>

#include "trace-compat.h"
#include "trace-cmd.h"
@@ -34,7 +37,15 @@
#define TRACE_WIDTH 800
#define TRACE_HEIGHT 600

-#define input_file "trace.dat"
+#define default_input_file "trace.dat"
+static char *input_file = default_input_file;
+
+void usage(char *prog)
+{
+ printf("Usage: %s\n", prog);
+ printf(" -h Display this help message\n");
+ printf(" -i input_file, default is %s\n", default_input_file);
+}

/* graph callbacks */

@@ -161,6 +172,21 @@ void kernel_shark(int argc, char **argv)
GtkWidget *draw;
GtkWidget *label;
GtkWidget *spin;
+ int c;
+
+ while ((c = getopt(argc, argv, "hi:")) != -1) {
+ switch(c) {
+ case 'h':
+ usage(basename(argv[0]));
+ return;
+ case 'i':
+ input_file = optarg;
+ break;
+ default:
+ /* assume the other options are for gtk */
+ break;
+ }
+ }

info = g_new0(typeof(*info), 1);
if (!info)
diff --git a/trace-graph-main.c b/trace-graph-main.c
index 4eb257f..54194e1 100644
--- a/trace-graph-main.c
+++ b/trace-graph-main.c
@@ -1,4 +1,7 @@
+#define _GNU_SOURCE
#include <gtk/gtk.h>
+#include <getopt.h>
+#include <string.h>

#include "trace-cmd.h"
#include "trace-graph.h"
@@ -7,10 +10,18 @@

#define TRACE_WIDTH 800
#define TRACE_HEIGHT 600
-#define input_file "trace.dat"

+#define default_input_file "trace.dat"
+static char *input_file = default_input_file;
static struct graph_info *ginfo;

+void usage(char *prog)
+{
+ printf("Usage: %s\n", prog);
+ printf(" -h Display this help message\n");
+ printf(" -i input_file, default is %s\n", default_input_file);
+}
+
/* Callback for the clicked signal of the Exit button */
static void
exit_clicked (GtkWidget *widget, gpointer data)
@@ -42,6 +53,21 @@ void trace_graph(int argc, char **argv)
GtkWidget *sub_item;
GtkWidget *scrollwin;
GtkWidget *draw;
+ int c;
+
+ while ((c = getopt(argc, argv, "hi:")) != -1) {
+ switch(c) {
+ case 'h':
+ usage(basename(argv[0]));
+ return;
+ case 'i':
+ input_file = optarg;
+ break;
+ default:
+ /* assume the other options are for gtk */
+ break;
+ }
+ }

handle = tracecmd_open(input_file);

diff --git a/trace-view-main.c b/trace-view-main.c
index c0eb716..5b6eb7b 100644
--- a/trace-view-main.c
+++ b/trace-view-main.c
@@ -1,4 +1,7 @@
+#define _GNU_SOURCE
#include <gtk/gtk.h>
+#include <getopt.h>
+#include <string.h>

#include "trace-cmd.h"
#include "trace-view.h"
@@ -7,11 +10,20 @@

#define TRACE_WIDTH 800
#define TRACE_HEIGHT 600
-#define input_file "trace.dat"
+
+#define default_input_file "trace.dat"
+static char *input_file = default_input_file;

GtkWidget *trace_tree;
static struct tracecmd_input *handle;

+void usage(char *prog)
+{
+ printf("Usage: %s\n", prog);
+ printf(" -h Display this help message\n");
+ printf(" -i input_file, default is %s\n", default_input_file);
+}
+
/* Callback for the clicked signal of the Exit button */
static void
exit_clicked (GtkWidget *widget, gpointer data)
@@ -76,6 +88,21 @@ void trace_view(int argc, char **argv)
GtkWidget *scrollwin;
GtkWidget *label;
GtkWidget *spin;
+ int c;
+
+ while ((c = getopt(argc, argv, "hi:")) != -1) {
+ switch(c) {
+ case 'h':
+ usage(basename(argv[0]));
+ return;
+ case 'i':
+ input_file = optarg;
+ break;
+ default:
+ /* assume the other options are for gtk */
+ break;
+ }
+ }

handle = tracecmd_open(input_file);

--
1.6.3.3
--
Darren Hart
IBM Linux Technology Center
Real-Time Linux Team
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/