blob: a782e17f2ef51bfacc3bbe0e785751ae4889a24e [file] [log] [blame]
Dave Barach52642c32016-02-11 19:28:19 -05001/*
2 *------------------------------------------------------------------
3 * Copyright (c) 2005-2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "g2.h"
18#include "props.h"
19#include <pwd.h>
20#include <strings.h>
21#include <stdlib.h>
22#include <unistd.h>
23#include <string.h>
24
25/*
26 * globals
27 */
28
29GtkWidget *g_mainwindow; /* The main window */
30
31/* Graphical object heirarchy
32 *
33 * [main window]
34 * [main vbox]
35 * [main (e.g. file) menubar]
36 * [view hbox]
37 * [view bottom menu]
38 */
39
40GtkWidget *g_mainvbox;
41GtkWidget *g_mainhbox;
42
43gint delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
44{
45 /* Allow window to be destroyed */
46 return(FALSE);
47}
48
49void destroy(GtkWidget *widget, gpointer data)
50{
51 gtk_main_quit();
52}
53
54int main (int argc, char **argv)
55{
56 char tmpbuf [128];
57 struct passwd *pw;
58 char *event_file = 0;
59 char *cpel_file = 0;
60 char *clib_file =0;
61 char *title = "none";
62 int curarg=1;
63 char *homedir;
64
65 gtk_init(&argc, &argv);
66
67 homedir = getenv ("HOME");
68 tmpbuf[0] = 0;
69
70 if (homedir) {
71 sprintf(tmpbuf, "%s/.g2", homedir);
72 } else {
73 pw = getpwuid(geteuid());
74 if (pw) {
75 sprintf(tmpbuf, "%s/.g2", pw->pw_dir);
76 }
77 }
78 if (tmpbuf[0])
79 readprops(tmpbuf);
80
81 g_mainwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
82
83 gtk_signal_connect (GTK_OBJECT(g_mainwindow), "delete_event",
84 GTK_SIGNAL_FUNC (delete_event), NULL);
85
86 gtk_signal_connect (GTK_OBJECT(g_mainwindow), "destroy",
87 GTK_SIGNAL_FUNC (destroy), NULL);
88
89 gtk_container_set_border_width(GTK_CONTAINER(g_mainwindow), 5);
90
91 g_mainvbox = gtk_vbox_new(FALSE, 0);
92 g_mainhbox = gtk_hbox_new(FALSE, 0);
93
94 /*
95 * init routines
96 */
97
98 menu1_init();
99 point_selector_init();
100 view1_init();
101 event_init();
102
103 /*
104 * Now that we're ready to rock 'n roll, see if we've been asked to
105 * press a few buttons...
106 */
107
108 while (curarg < argc) {
109 if (!strncmp(argv[curarg], "--cpel-input", 4)) {
110 curarg++;
111 if (curarg < argc) {
112 cpel_file = argv[curarg];
113 curarg++;
114 break;
115 }
116 g_error("Missing filename after --cpel-input");
117 }
118 if (!strncmp(argv[curarg], "--clib-input", 4)) {
119 curarg++;
120 if (curarg < argc) {
121 clib_file = argv[curarg];
122 curarg++;
123 break;
124 }
125 g_error("Missing filename after --cpel-input");
126 }
127
128 if (!strncmp(argv[curarg], "--pointdefs", 3)) {
129 curarg++;
130 if (curarg < argc) {
131 read_event_definitions(argv[curarg]);
132 curarg++;
133 continue;
134 }
135 g_error ("Missing filename after --pointdefs\n");
136 }
137 if (!strncmp(argv[curarg], "--event-log", 3)) {
138 curarg++;
139 if (curarg < argc) {
140 event_file = argv[curarg];
141 curarg++;
142 continue;
143 }
144 g_error ("Missing filename after --event-log\n");
145 }
146
147 if (!strncmp(argv[curarg], "--ticks-per-us", 3)) {
148 curarg++;
149 if (curarg < argc) {
150 ticks_per_ns = 0.0;
151 ticks_per_ns = atof(argv[curarg]);
152 if (ticks_per_ns == 0.0) {
153 g_error("ticks-per-ns (%s) didn't convert properly\n",
154 argv[curarg]);
155 }
156 ticks_per_ns_set = TRUE;
157 curarg++;
158 continue;
159 }
160 g_error ("Missing filename after --event-log\n");
161 }
162
163 fprintf(stderr,
164 "g2 [--pointdefs <filename>] [--event-log <filename>]\n");
165 fprintf(stderr, " [--ticks-per-us <value>]\n");
166 fprintf(stderr,
167 " [--cpel-input <filename>] [--clib-input <filename]>\n");
168 fprintf(stderr,
169 "%s\n%s\n", version_string, minor_v_string);
170 exit(0);
171 }
172
173 if (clib_file) {
174 read_clib_file (clib_file);
175 title = clib_file;
176 } else if (cpel_file) {
177 read_cpel_file(cpel_file);
178 title = cpel_file;
179 } else if (event_file) {
180 read_events(event_file);
181 title = event_file;
182 }
183
184 set_window_title(title);
185
186 gtk_signal_connect (GTK_OBJECT (g_mainwindow), "key_press_event",
187 (GtkSignalFunc) view1_handle_key_press_event, NULL);
188 gtk_container_add(GTK_CONTAINER(g_mainvbox), g_mainhbox);
189 gtk_widget_show(g_mainhbox);
190 gtk_container_add(GTK_CONTAINER(g_mainwindow), g_mainvbox);
191 gtk_widget_show(g_mainvbox);
192 gtk_widget_show(g_mainwindow);
193
194 gtk_main();
195 return(0);
196}