1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
/*
* hgspy.c
* Copyright (C) 2006 Akira TAGOH
*
* Authors:
* Akira TAGOH <at@gclab.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <libretto/vm.h>
#include "visualizer.h"
typedef struct _HieroGlyphSpy HgSpy;
struct _HieroGlyphSpy {
GtkWidget *window;
GtkWidget *visualizer;
GThread *vm_thread;
};
static gpointer __hg_spy_helper_get_widget = NULL;
/*
* Private Functions
*/
static gpointer
_hgspy_vm_thread(gpointer data)
{
LibrettoVM *vm;
libretto_vm_init();
vm = libretto_vm_new(LB_EMULATION_LEVEL_1);
libretto_vm_startjob(vm, (gchar *)data, TRUE);
return NULL;
}
static void
_hgspy_run_vm(HgSpy *spy,
const gchar *file)
{
if (spy->vm_thread != NULL) {
}
g_thread_create(_hgspy_vm_thread, NULL, FALSE, NULL);
}
static void
_hgspy_about_email_cb(GtkAboutDialog *about,
const gchar *link,
gpointer data)
{
}
static void
_hgspy_about_url_cb(GtkAboutDialog *about,
const gchar *link,
gpointer data)
{
}
static void
_hgspy_action_menubar_run_cb(GtkAction *action,
HgSpy *spy)
{
_hgspy_run_vm(spy, NULL);
}
static void
_hgspy_action_menubar_open_cb(GtkAction *action,
HgSpy *spy)
{
GtkWidget *dialog;
gint result;
GtkFileFilter *filter;
filter = gtk_file_filter_new();
gtk_file_filter_add_mime_type(filter, "application/postscript");
dialog = gtk_file_chooser_dialog_new(_("Open a PostScript file"),
GTK_WINDOW (spy->window),
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN,
GTK_RESPONSE_OK,
NULL);
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
result = gtk_dialog_run(GTK_DIALOG (dialog));
switch (result) {
case GTK_RESPONSE_OK:
_hgspy_run_vm(spy,
gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (dialog)));
break;
case GTK_RESPONSE_CANCEL:
default:
break;
}
gtk_widget_destroy(dialog);
}
static void
_hgspy_action_menubar_quit_cb(GtkAction *action,
HgSpy *spy)
{
gtk_main_quit();
}
static void
_hgspy_action_menubar_about_cb(GtkAction *action,
HgSpy *spy)
{
const gchar *authors[] = {
"Akira TAGOH",
NULL
};
const gchar *license =
"This library is free software; you can redistribute it and/or\n"
"modify it under the terms of the GNU Lesser General Public\n"
"License as published by the Free Software Foundation; either\n"
"version 2 of the License, or (at your option) any later version.\n"
"\n"
"This library is distributed in the hope that it will be useful,\n"
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
"Lesser General Public License for more details.\n"
"\n"
"You should have received a copy of the GNU Lesser General Public\n"
"License along with this library; if not, write to the\n"
"Free Software Foundation, Inc., 59 Temple Place - Suite 330,\n"
"Boston, MA 02111-1307, USA.\n";
gtk_about_dialog_set_email_hook(_hgspy_about_email_cb, NULL, NULL);
gtk_about_dialog_set_url_hook(_hgspy_about_url_cb, NULL, NULL);
gtk_show_about_dialog(GTK_WINDOW (spy->window),
"name", "Memory visualizer",
"version", PACKAGE_VERSION,
"copyright", "(C) 2006 Akira TAGOH",
"license", license,
"website", "http://hieroglyph.freedesktop.org/",
"comments", "for Hieroglyph memory management system",
"authors", authors,
NULL);
}
/*
* Public Functions
*/
int
main(int argc,
char **argv)
{
GModule *module;
HgSpy *spy;
GtkWidget *menubar, *vbox;
GtkUIManager *uiman;
GtkActionGroup *actions;
GtkActionEntry action_entries[] = {
/* toplevel menu */
{
.name = "VMMenu",
.stock_id = NULL,
.label = _("_VM"),
.accelerator = NULL,
.tooltip = NULL,
.callback = NULL
},
{
.name = "HelpMenu",
.stock_id = NULL,
.label = _("_Help"),
.accelerator = NULL,
.tooltip = NULL,
.callback = NULL
},
/* submenu - VM */
{
.name = "Run",
.stock_id = GTK_STOCK_EXECUTE,
.label = NULL,
.accelerator = NULL,
.tooltip = _("Run VM interactively"),
.callback = G_CALLBACK (_hgspy_action_menubar_run_cb)
},
{
.name = "Open",
.stock_id = GTK_STOCK_OPEN,
.label = NULL,
.accelerator = "<control>O",
.tooltip = _("Run a PostScript file on VM"),
.callback = G_CALLBACK (_hgspy_action_menubar_open_cb)
},
{
.name = "Quit",
.stock_id = GTK_STOCK_QUIT,
.label = NULL,
.accelerator = "<control>Q",
.tooltip = _("Quit"),
.callback = G_CALLBACK (_hgspy_action_menubar_quit_cb)
},
/* submenu - Help */
{
.name = "About",
.stock_id = GTK_STOCK_ABOUT,
.label = NULL,
.accelerator = NULL,
.tooltip = _("About"),
.callback = G_CALLBACK (_hgspy_action_menubar_about_cb)
}
};
gchar *uixml =
"<ui>"
" <menubar name='MenuBar'>"
" <menu action='VMMenu'>"
" <menuitem action='Run'/>"
" <menuitem action='Open'/>"
" <separator/>"
" <menuitem action='Quit'/>"
" </menu>"
" <menu action='HelpMenu'>"
" <menuitem action='About'/>"
" </menu>"
" </menubar>"
"</ui>";
if ((module = g_module_open("libhgspy-helper.so", 0)) == NULL) {
g_warning("Failed g_module_open: %s", g_module_error());
return 1;
}
if (!g_module_symbol(module, "hg_spy_helper_get_widget", &__hg_spy_helper_get_widget)) {
g_warning("Failed g_module_symbol: %s", g_module_error());
g_module_close(module);
return 1;
}
#ifdef ENABLE_NLS
bindtextdomain (GETTEXT_PACKAGE, HGSPY_LOCALEDIR);
#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
#endif /* HAVE_BIND_TEXTDOMAIN_CODESET */
textdomain (GETTEXT_PACKAGE);
#endif /* ENABLE_NLS */
g_thread_init(NULL);
gtk_init(&argc, &argv);
spy = g_new(HgSpy, 1);
spy->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
spy->vm_thread = NULL;
actions = gtk_action_group_new("MenuBar");
uiman = gtk_ui_manager_new();
vbox = gtk_vbox_new(FALSE, 0);
spy->visualizer = ((GtkWidget * (*) (void))__hg_spy_helper_get_widget) ();
if (spy->visualizer == NULL) {
g_warning("Failed to initialize a helper module.");
return 1;
}
/* setup action groups */
gtk_action_group_add_actions(actions,
action_entries,
sizeof (action_entries) / sizeof (GtkActionEntry),
spy);
/* setup UI */
gtk_ui_manager_add_ui_from_string(uiman, uixml, strlen(uixml), NULL);
gtk_ui_manager_insert_action_group(uiman, actions, 0);
/* setup accelerators */
gtk_window_add_accel_group(GTK_WINDOW (spy->window), gtk_ui_manager_get_accel_group(uiman));
/* widget connections */
menubar = gtk_ui_manager_get_widget(uiman, "/MenuBar");
gtk_box_pack_start(GTK_BOX (vbox), menubar, FALSE, TRUE, 0);
gtk_box_pack_start(GTK_BOX (vbox), spy->visualizer, TRUE, TRUE, 0);
gtk_container_add(GTK_CONTAINER (spy->window), vbox);
/* setup signals */
g_signal_connect(spy->window, "delete-event",
G_CALLBACK (gtk_main_quit), NULL);
gtk_widget_show_all(spy->window);
gtk_main();
/* finalize */
g_module_close(module);
return 0;
}
|