1 /* -----------------------------------------------------------------------------
2 * See the LICENSE file for information on copyright, usage and redistribution
3 * of SWIG, and the README file for authors - http://www.swig.org/release.html.
7 * A web-base parse tree browser using SWILL. This is an optional
8 * feature that's normally disabled.
9 * ----------------------------------------------------------------------------- */
11 char cvsroot_browser_cxx[] = "$Id: browser.cxx 10003 2007-10-17 21:42:11Z wsfulton $";
18 } static FILE *out = 0;
19 static Node *view_top = 0;
21 class Browser:public Dispatcher {
22 void show_checkbox(Node *t, Node *n) {
24 if (Getmeta(n, "visible")) {
28 Printf(out, "<a name=\"n%x\"></a>[<a href=\"hide.html?node=0x%x&hn=0x%x#n%x\">-</a>] ", n, t, n, n);
30 Printf(out, "<a name=\"n%x\"></a>[<a href=\"show.html?node=0x%x&hn=0x%x#n%x\">+</a>] ", n, t, n, n);
33 void show_attributes(Node *obj) {
34 if (!Getmeta(obj, "visible"))
36 String *os = NewString("");
42 if ((Cmp(k, "nodeType") == 0) || (Cmp(k, "firstChild") == 0) || (Cmp(k, "lastChild") == 0) ||
43 (Cmp(k, "parentNode") == 0) || (Cmp(k, "nextSibling") == 0) || (Cmp(k, "previousSibling") == 0) || (*(Char(k)) == '$')) {
45 } else if (Cmp(k, "parms") == 0) {
46 String *o = NewString("");
47 Printf(o, "%s", ParmList_protostr(Getattr(obj, k)));
48 Replaceall(o, "&", "&");
49 Replaceall(o, "<", "<");
50 Replaceall(o, ">", ">");
51 Printf(os, "<a href=\"data.html?n=0x%x\">?</a> %-12s - %s\n", Getattr(obj, k), k, o);
56 if (DohIsString(Getattr(obj, k))) {
57 o = Str(Getattr(obj, k));
61 Replaceall(o, "&", "&");
62 Replaceall(o, "<", "<");
63 Printf(os, "<a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc);
66 Printf(os, "<a href=\"data.html?n=0x%x\">?</a> %-12s - 0x%x\n", Getattr(obj, k), k, Getattr(obj, k));
71 Printf(out, "<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
76 virtual int emit_one(Node *n) {
77 char *tag = Char(nodeType(n));
78 char *file = Char(Getfile(n));
79 int line = Getline(n);
80 char *name = GetChar(n, "name");
82 show_checkbox(view_top, n);
83 Printf(out, "<b><a href=\"index.html?node=0x%x\">%s</a></b>", n, tag);
85 Printf(out, " (%s)", name);
87 Printf(out, ". %s:%d\n", file, line);
89 Dispatcher::emit_one(n);
92 virtual int emit_children(Node *n) {
93 if (Getmeta(n, "visible")) {
94 Printf(out, "<blockquote>\n");
95 Dispatcher::emit_children(n);
96 Printf(out, "</blockquote>\n");
100 virtual int defaultHandler(Node *n) {
104 virtual int top(Node *n) {
109 virtual int includeDirective(Node *n) {
114 virtual int importDirective(Node *n) {
120 virtual int extendDirective(Node *n) {
125 virtual int classDeclaration(Node *n) {
131 virtual int templateDeclaration(Node *n) {
137 virtual int enumDeclaration(Node *n) {
142 virtual int typemapDirective(Node *n) {
147 virtual int namespaceDeclaration(Node *n) {
152 virtual int usingDeclaration(Node *n) {
160 static int browser_exit = 0;
161 static Node *tree_top = 0;
162 static Browser *browse = 0;
164 /* ----------------------------------------------------------------------
165 * exit_handler() - Force the browser to exit
166 * ---------------------------------------------------------------------- */
168 void exit_handler(FILE *f) {
170 Printf(f, "Terminated.\n");
173 /* ----------------------------------------------------------------------
174 * node_handler() - Generate information about a specific node
175 * ---------------------------------------------------------------------- */
177 static void display(FILE *f, Node *n) {
178 /* Print standard HTML header */
180 Printf(f, "<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", Swig_package_version());
181 Printf(f, "<b>SWIG-%s</b><br>\n", Swig_package_version());
182 Printf(f, "[ <a href=\"exit.html\">Exit</a> ]");
183 Printf(f, " [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
185 Printf(f, " [ <a href=\"index.html?node=0x%x\">Up</a> ]", parentNode(n));
187 Printf(f, " [ <a href=\"symbol.html\">Symbols</a> ]");
188 Printf(f, "<br><hr><p>\n");
194 /* Print standard footer */
195 Printf(f, "<br><hr></BODY></HTML>\n");
199 void node_handler(FILE *f) {
201 if (!swill_getargs("p(node)", &n)) {
209 /* ----------------------------------------------------------------------
210 * hide_handler() - Hide a node
211 * ---------------------------------------------------------------------- */
213 void hide_handler(FILE *f) {
215 if (!swill_getargs("p(hn)", &n)) {
219 Delmeta(n, "visible");
224 void show_handler(FILE *f) {
226 if (!swill_getargs("p(hn)", &n)) {
230 Setmeta(n, "visible", "1");
235 void raw_data(FILE *out, Node *obj) {
238 if (DohIsMapping(obj)) {
241 String *os = NewString("");
242 Printf(os, "Hash {\n");
247 const char *trunc = "";
248 if (DohIsString(Getattr(obj, k))) {
249 o = Str(Getattr(obj, k));
253 Replaceall(o, "<", "<");
254 Printf(os, " <a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc);
257 Printf(os, " <a href=\"data.html?n=0x%x\">?</a> %-12s - 0x%x\n", Getattr(obj, k), k, Getattr(obj, k));
262 Printf(out, "<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
264 } else if (DohIsString(obj)) {
265 String *o = Str(obj);
266 Replaceall(o, "<", "<");
267 Printf(out, "<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(o));
269 } else if (DohIsSequence(obj)) {
271 String *os = NewString("");
272 Printf(os, "List [\n");
273 for (i = 0; i < Len(obj); i++) {
274 DOH *o = Getitem(obj, i);
275 const char *trunc = "";
276 if (DohIsString(o)) {
281 Replaceall(o, "<", "<");
282 Printf(os, " <a href=\"data.html?n=0x%x\">?</a> [%d] - \"%(escape)-0.70s%s\"\n", o, i, s, trunc);
285 Printf(os, " <a href=\"data.html?n=0x%x\">?</a> [%d] - 0x%x\n", o, i, o);
289 Printf(out, "<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
294 void data_handler(FILE *f) {
296 if (!swill_getargs("p(n)", &n)) {
299 Printf(f, "<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", Swig_package_version());
300 Printf(f, "<b>SWIG-%s</b><br>\n", Swig_package_version());
301 Printf(f, "[ <a href=\"exit.html\">Exit</a> ]");
302 Printf(f, " [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
303 Printf(f, "<br><hr><p>\n");
307 /* Print standard footer */
308 Printf(f, "<br><hr></BODY></HTML>\n");
311 void symbol_handler(FILE *f) {
315 Printf(f, "<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", Swig_package_version());
316 Printf(f, "<b>SWIG-%s</b><br>\n", Swig_package_version());
317 Printf(f, "[ <a href=\"exit.html\">Exit</a> ]");
318 Printf(f, " [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
319 Printf(f, " [ <a href=\"symbol.html\">Symbols</a> ]");
320 Printf(f, "<br><hr><p>\n");
322 if (!swill_getargs("p(sym)|s(name)", &sym, &name)) {
323 sym = Swig_symbol_getscope("");
327 Printf(f, "No symbol table specified!\n");
331 String *q = Swig_symbol_qualifiedscopename(sym);
333 Printf(f, "<b>Symbol table: :: (global)</b><br>\n");
335 Printf(f, "<b>Symbol table: %s</b><br>\n", q);
340 fprintf(f, "<p><form action=\"symbol.html\" method=GET>\n");
341 fprintf(f, "Symbol lookup: <input type=text name=name size=40></input><br>\n");
342 fprintf(f, "<input type=hidden name=sym value=\"0x%x\">\n", sym);
343 fprintf(f, "Submit : <input type=submit></input>\n");
344 fprintf(f, "</form>");
347 Node *n = Swig_symbol_clookup(name, sym);
348 Printf(f, "Symbol '%s':\n", name);
349 Printf(f, "<blockquote>\n");
351 Printf(f, "Not defined!\n");
355 Printf(f, "</blockquote>\n");
358 Printf(f, "<p><b>Nested scopes</b><br>\n");
359 Printf(f, "<blockquote><pre>\n");
364 Printf(f, "<a href=\"symbol.html?sym=0x%x\">%s</a>\n", h, Getattr(h, "name"));
368 Printf(f, "</pre></blockquote>\n");
370 Printf(f, "<p><b>Symbol table contents</b></br>\n");
371 raw_data(f, Getattr(sym, "symtab"));
372 Printf(f, "<br><hr></BODY></HTML>\n");
377 void Swig_browser(Node *top, int port) {
382 /* Initialize the server */
383 sport = swill_init(port);
385 Printf(stderr, "Couldn't open socket on port %d. Sorry.\n", port);
388 browse = new Browser();
389 Setmeta(top, "visible", "1");
392 Printf(stderr, "SWIG: Tree browser listening on port %d\n", sport);
394 swill_handle("exit.html", exit_handler, 0);
395 swill_handle("index.html", node_handler, 0);
396 swill_handle("hide.html", hide_handler, 0);
397 swill_handle("show.html", show_handler, 0);
398 swill_handle("data.html", data_handler, 0);
399 swill_handle("symbol.html", symbol_handler, 0);
400 swill_netscape("index.html");
402 while (!browser_exit) {
405 Printf(stderr, "Browser terminated.\n");