blob: 5af679d44db64aa5835d6a09d7ea30a262617ae3 [file] [log] [blame]
Dave Barach3e07a4a2020-04-04 10:05:48 -04001/*
Dave Barach52642c32016-02-11 19:28:19 -05002 *------------------------------------------------------------------
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>
Dave Barachde9571f2017-03-25 08:20:22 -040024#include <vppinfra/mem.h>
Dave Barach52642c32016-02-11 19:28:19 -050025
26/*
27 * globals
28 */
29
30GtkWidget *g_mainwindow; /* The main window */
31
32/* Graphical object heirarchy
33 *
34 * [main window]
35 * [main vbox]
36 * [main (e.g. file) menubar]
Dave Barach3e07a4a2020-04-04 10:05:48 -040037 * [view hbox]
Dave Barach52642c32016-02-11 19:28:19 -050038 * [view bottom menu]
39 */
40
41GtkWidget *g_mainvbox;
42GtkWidget *g_mainhbox;
43
44gint delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
45{
46 /* Allow window to be destroyed */
47 return(FALSE);
48}
49
50void destroy(GtkWidget *widget, gpointer data)
51{
52 gtk_main_quit();
53}
54
55int main (int argc, char **argv)
56{
57 char tmpbuf [128];
58 struct passwd *pw;
59 char *event_file = 0;
60 char *cpel_file = 0;
61 char *clib_file =0;
62 char *title = "none";
63 int curarg=1;
64 char *homedir;
Dave Barach3e07a4a2020-04-04 10:05:48 -040065
Dave Barachde9571f2017-03-25 08:20:22 -040066 clib_mem_init (0, ((uword)3<<30));
67
Dave Barach52642c32016-02-11 19:28:19 -050068 gtk_init(&argc, &argv);
69
70 homedir = getenv ("HOME");
71 tmpbuf[0] = 0;
72
73 if (homedir) {
Dave Barach3e07a4a2020-04-04 10:05:48 -040074 snprintf(tmpbuf, sizeof(tmpbuf), "%s/.g2", homedir);
Dave Barach52642c32016-02-11 19:28:19 -050075 } else {
76 pw = getpwuid(geteuid());
77 if (pw) {
Dave Barach3e07a4a2020-04-04 10:05:48 -040078 snprintf(tmpbuf, sizeof(tmpbuf), "%s/.g2", pw->pw_dir);
Dave Barach52642c32016-02-11 19:28:19 -050079 }
80 }
81 if (tmpbuf[0])
82 readprops(tmpbuf);
83
84 g_mainwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
85
86 gtk_signal_connect (GTK_OBJECT(g_mainwindow), "delete_event",
87 GTK_SIGNAL_FUNC (delete_event), NULL);
88
89 gtk_signal_connect (GTK_OBJECT(g_mainwindow), "destroy",
90 GTK_SIGNAL_FUNC (destroy), NULL);
91
92 gtk_container_set_border_width(GTK_CONTAINER(g_mainwindow), 5);
93
94 g_mainvbox = gtk_vbox_new(FALSE, 0);
95 g_mainhbox = gtk_hbox_new(FALSE, 0);
96
Dave Barach3e07a4a2020-04-04 10:05:48 -040097 /*
Dave Barach52642c32016-02-11 19:28:19 -050098 * init routines
99 */
100
101 menu1_init();
102 point_selector_init();
103 view1_init();
104 event_init();
105
Dave Barach3e07a4a2020-04-04 10:05:48 -0400106 /*
Dave Barach52642c32016-02-11 19:28:19 -0500107 * Now that we're ready to rock 'n roll, see if we've been asked to
108 * press a few buttons...
109 */
Dave Barach3e07a4a2020-04-04 10:05:48 -0400110
Dave Barach52642c32016-02-11 19:28:19 -0500111 while (curarg < argc) {
112 if (!strncmp(argv[curarg], "--cpel-input", 4)) {
113 curarg++;
114 if (curarg < argc) {
115 cpel_file = argv[curarg];
116 curarg++;
117 break;
118 }
119 g_error("Missing filename after --cpel-input");
120 }
121 if (!strncmp(argv[curarg], "--clib-input", 4)) {
122 curarg++;
123 if (curarg < argc) {
124 clib_file = argv[curarg];
125 curarg++;
126 break;
127 }
128 g_error("Missing filename after --cpel-input");
129 }
130
131 if (!strncmp(argv[curarg], "--pointdefs", 3)) {
132 curarg++;
133 if (curarg < argc) {
134 read_event_definitions(argv[curarg]);
135 curarg++;
136 continue;
137 }
138 g_error ("Missing filename after --pointdefs\n");
139 }
140 if (!strncmp(argv[curarg], "--event-log", 3)) {
141 curarg++;
142 if (curarg < argc) {
143 event_file = argv[curarg];
144 curarg++;
145 continue;
146 }
147 g_error ("Missing filename after --event-log\n");
148 }
149
150 if (!strncmp(argv[curarg], "--ticks-per-us", 3)) {
151 curarg++;
152 if (curarg < argc) {
153 ticks_per_ns = 0.0;
154 ticks_per_ns = atof(argv[curarg]);
155 if (ticks_per_ns == 0.0) {
156 g_error("ticks-per-ns (%s) didn't convert properly\n",
157 argv[curarg]);
158 }
159 ticks_per_ns_set = TRUE;
160 curarg++;
161 continue;
162 }
163 g_error ("Missing filename after --event-log\n");
164 }
165
Dave Barach3e07a4a2020-04-04 10:05:48 -0400166 fprintf(stderr,
Dave Barach52642c32016-02-11 19:28:19 -0500167 "g2 [--pointdefs <filename>] [--event-log <filename>]\n");
168 fprintf(stderr, " [--ticks-per-us <value>]\n");
Dave Barach3e07a4a2020-04-04 10:05:48 -0400169 fprintf(stderr,
Dave Barach52642c32016-02-11 19:28:19 -0500170 " [--cpel-input <filename>] [--clib-input <filename]>\n");
Dave Barach3e07a4a2020-04-04 10:05:48 -0400171 fprintf(stderr,
Dave Barach52642c32016-02-11 19:28:19 -0500172 "%s\n%s\n", version_string, minor_v_string);
173 exit(0);
174 }
175
176 if (clib_file) {
177 read_clib_file (clib_file);
178 title = clib_file;
179 } else if (cpel_file) {
180 read_cpel_file(cpel_file);
181 title = cpel_file;
182 } else if (event_file) {
183 read_events(event_file);
184 title = event_file;
185 }
186
187 set_window_title(title);
188
189 gtk_signal_connect (GTK_OBJECT (g_mainwindow), "key_press_event",
190 (GtkSignalFunc) view1_handle_key_press_event, NULL);
191 gtk_container_add(GTK_CONTAINER(g_mainvbox), g_mainhbox);
192 gtk_widget_show(g_mainhbox);
193 gtk_container_add(GTK_CONTAINER(g_mainwindow), g_mainvbox);
194 gtk_widget_show(g_mainvbox);
195 gtk_widget_show(g_mainwindow);
196
197 gtk_main();
198 return(0);
199}