/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* browser.cxx
*
* A web-base parse tree browser using SWILL. This is an optional
* feature that's normally disabled.
* ----------------------------------------------------------------------------- */
char cvsroot_browser_cxx[] = "$Id: browser.cxx 10003 2007-10-17 21:42:11Z wsfulton $";
#include "swigmod.h"
#ifdef SWIG_SWILL
extern "C" {
#include "swill.h"
} static FILE *out = 0;
static Node *view_top = 0;
class Browser:public Dispatcher {
void show_checkbox(Node *t, Node *n) {
int v = 0;
if (Getmeta(n, "visible")) {
v = 1;
}
if (v) {
Printf(out, "[-] ", n, t, n, n);
} else {
Printf(out, "[+] ", n, t, n, n);
}
}
void show_attributes(Node *obj) {
if (!Getmeta(obj, "visible"))
return;
String *os = NewString("");
String *k;
Iterator ki;
ki = First(obj);
while (ki.key) {
k = ki.key;
if ((Cmp(k, "nodeType") == 0) || (Cmp(k, "firstChild") == 0) || (Cmp(k, "lastChild") == 0) ||
(Cmp(k, "parentNode") == 0) || (Cmp(k, "nextSibling") == 0) || (Cmp(k, "previousSibling") == 0) || (*(Char(k)) == '$')) {
/* Do nothing */
} else if (Cmp(k, "parms") == 0) {
String *o = NewString("");
Printf(o, "%s", ParmList_protostr(Getattr(obj, k)));
Replaceall(o, "&", "&");
Replaceall(o, "<", "<");
Replaceall(o, ">", ">");
Printf(os, "? %-12s - %s\n", Getattr(obj, k), k, o);
Delete(o);
} else {
DOH *o;
char *trunc = "";
if (DohIsString(Getattr(obj, k))) {
o = Str(Getattr(obj, k));
if (Len(o) > 70) {
trunc = "...";
}
Replaceall(o, "&", "&");
Replaceall(o, "<", "<");
Printf(os, "? %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc);
Delete(o);
} else {
Printf(os, "? %-12s - 0x%x\n", Getattr(obj, k), k, Getattr(obj, k));
}
}
ki = Next(ki);
}
Printf(out, "\n%s
\n", Char(os));
Delete(os);
}
public:
virtual int emit_one(Node *n) {
char *tag = Char(nodeType(n));
char *file = Char(Getfile(n));
int line = Getline(n);
char *name = GetChar(n, "name");
show_checkbox(view_top, n);
Printf(out, "%s", n, tag);
if (name) {
Printf(out, " (%s)", name);
}
Printf(out, ". %s:%d\n", file, line);
Printf(out, "
");
Dispatcher::emit_one(n);
return SWIG_OK;
}
virtual int emit_children(Node *n) {
if (Getmeta(n, "visible")) {
Printf(out, "
\n"); Dispatcher::emit_children(n); Printf(out, "\n"); } return SWIG_OK; } virtual int defaultHandler(Node *n) { show_attributes(n); return SWIG_OK; } virtual int top(Node *n) { show_attributes(n); emit_children(n); return SWIG_OK; } virtual int includeDirective(Node *n) { show_attributes(n); emit_children(n); return SWIG_OK; } virtual int importDirective(Node *n) { show_attributes(n); emit_children(n); return SWIG_OK; } virtual int extendDirective(Node *n) { show_attributes(n); emit_children(n); return SWIG_OK; } virtual int classDeclaration(Node *n) { show_attributes(n); emit_children(n); return SWIG_OK; } virtual int templateDeclaration(Node *n) { show_attributes(n); emit_children(n); return SWIG_OK; } virtual int enumDeclaration(Node *n) { show_attributes(n); emit_children(n); return SWIG_OK; } virtual int typemapDirective(Node *n) { show_attributes(n); emit_children(n); return SWIG_OK; } virtual int namespaceDeclaration(Node *n) { show_attributes(n); emit_children(n); return SWIG_OK; } virtual int usingDeclaration(Node *n) { show_attributes(n); emit_children(n); return SWIG_OK; } }; static int browser_exit = 0; static Node *tree_top = 0; static Browser *browse = 0; /* ---------------------------------------------------------------------- * exit_handler() - Force the browser to exit * ---------------------------------------------------------------------- */ void exit_handler(FILE *f) { browser_exit = 1; Printf(f, "Terminated.\n"); } /* ---------------------------------------------------------------------- * node_handler() - Generate information about a specific node * ---------------------------------------------------------------------- */ static void display(FILE *f, Node *n) { /* Print standard HTML header */ Printf(f, "
\n");
out = f;
browse->emit_one(n);
/* Print standard footer */
Printf(f, "
\n%s\n", Char(os)); Delete(os); } else if (DohIsString(obj)) { String *o = Str(obj); Replaceall(o, "<", "<"); Printf(out, "
\n%s\n", Char(o)); Delete(o); } else if (DohIsSequence(obj)) { int i; String *os = NewString(""); Printf(os, "List [\n"); for (i = 0; i < Len(obj); i++) { DOH *o = Getitem(obj, i); const char *trunc = ""; if (DohIsString(o)) { String *s = Str(o); if (Len(s) > 70) { trunc = "..."; } Replaceall(o, "<", "<"); Printf(os, " ? [%d] - \"%(escape)-0.70s%s\"\n", o, i, s, trunc); Delete(s); } else { Printf(os, " ? [%d] - 0x%x\n", o, i, o); } } Printf(os, "\n]\n"); Printf(out, "
\n%s\n", Char(os)); Delete(os); } } void data_handler(FILE *f) { DOH *n = 0; if (!swill_getargs("p(n)", &n)) { n = 0; } Printf(f, "
\n");
if (n) {
raw_data(f, n);
}
/* Print standard footer */
Printf(f, "
\n");
if (!swill_getargs("p(sym)|s(name)", &sym, &name)) {
sym = Swig_symbol_getscope("");
name = 0;
}
if (!sym) {
Printf(f, "No symbol table specified!\n");
return;
}
{
String *q = Swig_symbol_qualifiedscopename(sym);
if (!Len(q)) {
Printf(f, "Symbol table: :: (global)
\n");
} else {
Printf(f, "Symbol table: %s
\n", q);
}
Delete(q);
}
fprintf(f, "
\n"); if (!n) { Printf(f, "Not defined!\n"); } else { raw_data(f, n); } Printf(f, "\n"); } Printf(f, "
Nested scopes
\n");
Printf(f, "
\n"); Printf(f, "\n"); { Hash *h; h = firstChild(sym); while (h) { Printf(f, "%s\n", h, Getattr(h, "name")); h = nextSibling(h); } } Printf(f, "
Symbol table contents\n");
raw_data(f, Getattr(sym, "symtab"));
Printf(f, "