~ubuntu-branches/ubuntu/maverick/swig1.3/maverick

« back to all changes in this revision

Viewing changes to Source/Modules/browser.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2006-12-20 14:43:24 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20061220144324-bps3kb06xp5oy9w1
Tags: 1.3.31-1ubuntu1
* Merge from debian unstable, remaining changes:
  - drop support for pike
  - use php5 instead of php4
  - clean Runtime/ as well
  - force a few environment variables

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 * feature that's normally disabled.
9
9
 * ----------------------------------------------------------------------------- */
10
10
 
11
 
char cvsroot_browser_cxx[] = "$Header: /cvsroot/swig/SWIG/Source/Modules/browser.cxx,v 1.7 2006/03/06 22:50:56 wsfulton Exp $";
 
11
char cvsroot_browser_cxx[] = "$Header: /cvsroot/swig/SWIG/Source/Modules/browser.cxx,v 1.9 2006/11/15 23:45:47 wsfulton Exp $";
12
12
 
13
13
#include "swigmod.h"
14
14
 
15
15
#ifdef SWIG_SWILL
16
16
extern "C" {
17
17
#include "swill.h"
18
 
}
19
 
 
20
 
static FILE *out = 0;
 
18
} static FILE *out = 0;
21
19
static Node *view_top = 0;
22
 
      
23
 
class Browser : public Dispatcher {
 
20
 
 
21
class Browser:public Dispatcher {
24
22
  void show_checkbox(Node *t, Node *n) {
25
23
    int v = 0;
26
 
    if (Getmeta(n,"visible")) {
 
24
    if (Getmeta(n, "visible")) {
27
25
      v = 1;
28
26
    }
29
27
    if (v) {
30
 
      Printf(out,"<a name=\"n%x\"></a>[<a href=\"hide.html?node=0x%x&hn=0x%x#n%x\">-</a>] ",  n, t, n,n);
 
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);
31
29
    } else {
32
 
      Printf(out,"<a name=\"n%x\"></a>[<a href=\"show.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
31
    }
34
32
  }
35
33
  void show_attributes(Node *obj) {
36
 
    if (!Getmeta(obj,"visible")) return;
 
34
    if (!Getmeta(obj, "visible"))
 
35
      return;
37
36
    String *os = NewString("");
38
37
    String *k;
39
38
    Iterator ki;
40
39
    ki = First(obj);
41
40
    while (ki.key) {
42
41
      k = ki.key;
43
 
      if ((Cmp(k,"nodeType") == 0) || (Cmp(k,"firstChild") == 0) || (Cmp(k,"lastChild") == 0) ||
44
 
          (Cmp(k,"parentNode") == 0) || (Cmp(k,"nextSibling") == 0) || 
45
 
          (Cmp(k,"previousSibling") == 0) || (*(Char(k)) == '$')) {
 
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)) == '$')) {
46
44
        /* Do nothing */
47
 
      } else if (Cmp(k,"parms") == 0) {
 
45
      } else if (Cmp(k, "parms") == 0) {
48
46
        String *o = NewString("");
49
 
        Printf(o,"%s", ParmList_protostr(Getattr(obj,k)));
50
 
        Replaceall(o,"&","&amp;");
51
 
        Replaceall(o,"<","&lt;");
52
 
        Replaceall(o,">","&gt;");
53
 
        Printf(os,"<a href=\"data.html?n=0x%x\">?</a> %-12s - %s\n", Getattr(obj,k), k, o);
 
47
        Printf(o, "%s", ParmList_protostr(Getattr(obj, k)));
 
48
        Replaceall(o, "&", "&amp;");
 
49
        Replaceall(o, "<", "&lt;");
 
50
        Replaceall(o, ">", "&gt;");
 
51
        Printf(os, "<a href=\"data.html?n=0x%x\">?</a> %-12s - %s\n", Getattr(obj, k), k, o);
54
52
        Delete(o);
55
53
      } else {
56
54
        DOH *o;
57
55
        char *trunc = "";
58
 
        if (DohIsString(Getattr(obj,k))) {
59
 
          o = Str(Getattr(obj,k));
 
56
        if (DohIsString(Getattr(obj, k))) {
 
57
          o = Str(Getattr(obj, k));
60
58
          if (Len(o) > 70) {
61
59
            trunc = "...";
62
60
          }
63
 
          Replaceall(o,"&","&amp;");
64
 
          Replaceall(o,"<","&lt;");
65
 
          Printf(os,"<a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj,k), k, o, trunc);
 
61
          Replaceall(o, "&", "&amp;");
 
62
          Replaceall(o, "<", "&lt;");
 
63
          Printf(os, "<a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc);
66
64
          Delete(o);
67
65
        } else {
68
 
          Printf(os,"<a href=\"data.html?n=0x%x\">?</a> %-12s - 0x%x\n", Getattr(obj,k), k, Getattr(obj,k));
 
66
          Printf(os, "<a href=\"data.html?n=0x%x\">?</a> %-12s - 0x%x\n", Getattr(obj, k), k, Getattr(obj, k));
69
67
        }
70
68
      }
71
69
      ki = Next(ki);
72
70
    }
73
 
    Printf(out,"<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
 
71
    Printf(out, "<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
74
72
    Delete(os);
75
73
  }
76
74
 
78
76
  virtual int emit_one(Node *n) {
79
77
    char *tag = Char(nodeType(n));
80
78
    char *file = Char(Getfile(n));
81
 
    int   line = Getline(n);
82
 
    char *name = GetChar(n,"name");
 
79
    int line = Getline(n);
 
80
    char *name = GetChar(n, "name");
83
81
 
84
82
    show_checkbox(view_top, n);
85
 
    Printf(out,"<b><a href=\"index.html?node=0x%x\">%s</a></b>", n, tag);
 
83
    Printf(out, "<b><a href=\"index.html?node=0x%x\">%s</a></b>", n, tag);
86
84
    if (name) {
87
 
      Printf(out," (%s)", name);
 
85
      Printf(out, " (%s)", name);
88
86
    }
89
 
    Printf(out,".  %s:%d\n", file, line);
90
 
    Printf(out,"<br>");
 
87
    Printf(out, ".  %s:%d\n", file, line);
 
88
    Printf(out, "<br>");
91
89
    Dispatcher::emit_one(n);
92
90
    return SWIG_OK;
93
91
  }
94
92
  virtual int emit_children(Node *n) {
95
 
    if (Getmeta(n,"visible")) {
96
 
      Printf(out,"<blockquote>\n");
 
93
    if (Getmeta(n, "visible")) {
 
94
      Printf(out, "<blockquote>\n");
97
95
      Dispatcher::emit_children(n);
98
 
      Printf(out,"</blockquote>\n");
 
96
      Printf(out, "</blockquote>\n");
99
97
    }
100
98
    return SWIG_OK;
101
99
  }
169
167
 
170
168
void exit_handler(FILE *f) {
171
169
  browser_exit = 1;
172
 
  Printf(f,"Terminated.\n");
 
170
  Printf(f, "Terminated.\n");
173
171
}
174
172
 
175
173
/* ----------------------------------------------------------------------
178
176
 
179
177
static void display(FILE *f, Node *n) {
180
178
  /* Print standard HTML header */
181
 
  
182
 
  Printf(f,"<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", PACKAGE_VERSION); 
183
 
  Printf(f,"<b>SWIG-%s</b><br>\n", PACKAGE_VERSION);
184
 
  Printf(f,"[ <a href=\"exit.html\">Exit</a> ]");
185
 
  Printf(f," [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
 
179
 
 
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);
186
184
  if (n != tree_top) {
187
 
    Printf(f," [ <a href=\"index.html?node=0x%x\">Up</a> ]", parentNode(n));
 
185
    Printf(f, " [ <a href=\"index.html?node=0x%x\">Up</a> ]", parentNode(n));
188
186
  }
189
 
  Printf(f," [ <a href=\"symbol.html\">Symbols</a> ]");
190
 
  Printf(f,"<br><hr><p>\n");
 
187
  Printf(f, " [ <a href=\"symbol.html\">Symbols</a> ]");
 
188
  Printf(f, "<br><hr><p>\n");
191
189
 
192
190
  out = f;
193
191
 
194
192
  browse->emit_one(n);
195
193
 
196
194
  /* Print standard footer */
197
 
  Printf(f,"<br><hr></BODY></HTML>\n");
 
195
  Printf(f, "<br><hr></BODY></HTML>\n");
198
196
 
199
197
}
200
198
 
204
202
    n = tree_top;
205
203
  }
206
204
  view_top = n;
207
 
  display(f,n);
 
205
  display(f, n);
208
206
}
209
207
 
210
208
 
218
216
    n = 0;
219
217
  }
220
218
  if (n) {
221
 
    Delmeta(n,"visible");
 
219
    Delmeta(n, "visible");
222
220
  }
223
221
  node_handler(f);
224
222
}
229
227
    n = 0;
230
228
  }
231
229
  if (n) {
232
 
    Setmeta(n,"visible","1");
 
230
    Setmeta(n, "visible", "1");
233
231
  }
234
232
  node_handler(f);
235
233
}
236
234
 
237
235
void raw_data(FILE *out, Node *obj) {
238
 
  if (!obj) return;
 
236
  if (!obj)
 
237
    return;
239
238
  if (DohIsMapping(obj)) {
240
239
    String *k;
241
240
    Iterator ki;
242
241
    String *os = NewString("");
243
 
    Printf(os,"Hash {\n");
 
242
    Printf(os, "Hash {\n");
244
243
    ki = First(obj);
245
244
    while (ki.key) {
246
245
      k = ki.key;
247
246
      DOH *o;
248
247
      const char *trunc = "";
249
 
      if (DohIsString(Getattr(obj,k))) {
250
 
        o = Str(Getattr(obj,k));
 
248
      if (DohIsString(Getattr(obj, k))) {
 
249
        o = Str(Getattr(obj, k));
251
250
        if (Len(o) > 70) {
252
251
          trunc = "...";
253
252
        }
254
 
        Replaceall(o,"<","&lt;");
255
 
        Printf(os,"    <a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj,k), k, o, trunc);
 
253
        Replaceall(o, "<", "&lt;");
 
254
        Printf(os, "    <a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc);
256
255
        Delete(o);
257
256
      } else {
258
 
        Printf(os,"    <a href=\"data.html?n=0x%x\">?</a> %-12s - 0x%x\n", Getattr(obj,k), k, Getattr(obj,k));
 
257
        Printf(os, "    <a href=\"data.html?n=0x%x\">?</a> %-12s - 0x%x\n", Getattr(obj, k), k, Getattr(obj, k));
259
258
      }
260
259
      ki = Next(ki);
261
260
    }
262
 
    Printf(os,"}\n");
263
 
    Printf(out,"<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
 
261
    Printf(os, "}\n");
 
262
    Printf(out, "<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
264
263
    Delete(os);
265
264
  } else if (DohIsString(obj)) {
266
265
    String *o = Str(obj);
267
 
    Replaceall(o,"<","&lt;");
268
 
    Printf(out,"<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(o));
 
266
    Replaceall(o, "<", "&lt;");
 
267
    Printf(out, "<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(o));
269
268
    Delete(o);
270
269
  } else if (DohIsSequence(obj)) {
271
270
    int i;
272
271
    String *os = NewString("");
273
 
    Printf(os,"List [\n");
 
272
    Printf(os, "List [\n");
274
273
    for (i = 0; i < Len(obj); i++) {
275
 
      DOH *o = Getitem(obj,i);
 
274
      DOH *o = Getitem(obj, i);
276
275
      const char *trunc = "";
277
276
      if (DohIsString(o)) {
278
277
        String *s = Str(o);
279
278
        if (Len(s) > 70) {
280
279
          trunc = "...";
281
280
        }
282
 
        Replaceall(o,"<","&lt;");
283
 
        Printf(os,"    <a href=\"data.html?n=0x%x\">?</a> [%d] - \"%(escape)-0.70s%s\"\n", o,i,s, trunc);
 
281
        Replaceall(o, "<", "&lt;");
 
282
        Printf(os, "    <a href=\"data.html?n=0x%x\">?</a> [%d] - \"%(escape)-0.70s%s\"\n", o, i, s, trunc);
284
283
        Delete(s);
285
284
      } else {
286
 
        Printf(os,"    <a href=\"data.html?n=0x%x\">?</a> [%d] - 0x%x\n", o, i, o);
 
285
        Printf(os, "    <a href=\"data.html?n=0x%x\">?</a> [%d] - 0x%x\n", o, i, o);
287
286
      }
288
287
    }
289
 
    Printf(os,"\n]\n");
290
 
    Printf(out,"<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
 
288
    Printf(os, "\n]\n");
 
289
    Printf(out, "<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
291
290
    Delete(os);
292
291
  }
293
292
}
297
296
  if (!swill_getargs("p(n)", &n)) {
298
297
    n = 0;
299
298
  }
300
 
  Printf(f,"<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", PACKAGE_VERSION); 
301
 
  Printf(f,"<b>SWIG-%s</b><br>\n", PACKAGE_VERSION);
302
 
  Printf(f,"[ <a href=\"exit.html\">Exit</a> ]");
303
 
  Printf(f," [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
304
 
  Printf(f,"<br><hr><p>\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");
305
304
  if (n) {
306
 
    raw_data(f,n);
 
305
    raw_data(f, n);
307
306
  }
308
307
  /* Print standard footer */
309
 
  Printf(f,"<br><hr></BODY></HTML>\n");
 
308
  Printf(f, "<br><hr></BODY></HTML>\n");
310
309
}
311
310
 
312
311
void symbol_handler(FILE *f) {
313
312
  Symtab *sym;
314
 
  char   *name = 0;
315
 
 
316
 
  Printf(f,"<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", PACKAGE_VERSION); 
317
 
  Printf(f,"<b>SWIG-%s</b><br>\n", PACKAGE_VERSION);
318
 
  Printf(f,"[ <a href=\"exit.html\">Exit</a> ]");
319
 
  Printf(f," [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
320
 
  Printf(f," [ <a href=\"symbol.html\">Symbols</a> ]");
321
 
  Printf(f,"<br><hr><p>\n");
322
 
  
 
313
  char *name = 0;
 
314
 
 
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");
 
321
 
323
322
  if (!swill_getargs("p(sym)|s(name)", &sym, &name)) {
324
323
    sym = Swig_symbol_getscope("");
325
324
    name = 0;
326
325
  }
327
326
  if (!sym) {
328
 
    Printf(f,"No symbol table specified!\n");
 
327
    Printf(f, "No symbol table specified!\n");
329
328
    return;
330
329
  }
331
330
  {
332
331
    String *q = Swig_symbol_qualifiedscopename(sym);
333
332
    if (!Len(q)) {
334
 
      Printf(f,"<b>Symbol table: :: (global)</b><br>\n"); 
 
333
      Printf(f, "<b>Symbol table: :: (global)</b><br>\n");
335
334
    } else {
336
 
      Printf(f,"<b>Symbol table: %s</b><br>\n", q);
 
335
      Printf(f, "<b>Symbol table: %s</b><br>\n", q);
337
336
    }
338
337
    Delete(q);
339
338
  }
340
 
  
341
 
  fprintf(f,"<p><form action=\"symbol.html\" method=GET>\n");
342
 
  fprintf(f,"Symbol lookup: <input type=text name=name size=40></input><br>\n");
343
 
  fprintf(f,"<input type=hidden name=sym value=\"0x%x\">\n", sym);
344
 
  fprintf(f,"Submit : <input type=submit></input>\n");
345
 
  fprintf(f,"</form>");
 
339
 
 
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>");
346
345
 
347
346
  if (name) {
348
 
    Node *n = Swig_symbol_clookup(name,sym);
349
 
    Printf(f,"Symbol '%s':\n", name);
350
 
    Printf(f,"<blockquote>\n");
 
347
    Node *n = Swig_symbol_clookup(name, sym);
 
348
    Printf(f, "Symbol '%s':\n", name);
 
349
    Printf(f, "<blockquote>\n");
351
350
    if (!n) {
352
 
      Printf(f,"Not defined!\n");
 
351
      Printf(f, "Not defined!\n");
353
352
    } else {
354
 
      raw_data(f,n);
 
353
      raw_data(f, n);
355
354
    }
356
 
    Printf(f,"</blockquote>\n");
 
355
    Printf(f, "</blockquote>\n");
357
356
  }
358
357
 
359
 
  Printf(f,"<p><b>Nested scopes</b><br>\n");
360
 
  Printf(f,"<blockquote><pre>\n");
 
358
  Printf(f, "<p><b>Nested scopes</b><br>\n");
 
359
  Printf(f, "<blockquote><pre>\n");
361
360
  {
362
 
    Hash   *h;
 
361
    Hash *h;
363
362
    h = firstChild(sym);
364
363
    while (h) {
365
 
      Printf(f,"<a href=\"symbol.html?sym=0x%x\">%s</a>\n", h, Getattr(h,"name"));
 
364
      Printf(f, "<a href=\"symbol.html?sym=0x%x\">%s</a>\n", h, Getattr(h, "name"));
366
365
      h = nextSibling(h);
367
366
    }
368
367
  }
369
 
  Printf(f,"</pre></blockquote>\n");
370
 
  
371
 
  Printf(f,"<p><b>Symbol table contents</b></br>\n");
372
 
  raw_data(f,Getattr(sym,"symtab"));
373
 
  Printf(f,"<br><hr></BODY></HTML>\n");
 
368
  Printf(f, "</pre></blockquote>\n");
 
369
 
 
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");
374
373
 
375
374
}
376
375
#endif
377
376
 
378
 
void
379
 
Swig_browser(Node *top, int port) {
 
377
void Swig_browser(Node *top, int port) {
380
378
#ifdef SWIG_SWILL
381
379
  int sport;
382
380
  browser_exit = 0;
384
382
  /* Initialize the server */
385
383
  sport = swill_init(port);
386
384
  if (sport < 0) {
387
 
    Printf(stderr,"Couldn't open socket on port %d. Sorry.\n", port);
 
385
    Printf(stderr, "Couldn't open socket on port %d. Sorry.\n", port);
388
386
    return;
389
387
  }
390
388
  browse = new Browser();
391
 
  Setmeta(top,"visible","1");
 
389
  Setmeta(top, "visible", "1");
392
390
  tree_top = top;
393
391
 
394
 
  Printf(stderr,"SWIG: Tree browser listening on port %d\n", sport);
 
392
  Printf(stderr, "SWIG: Tree browser listening on port %d\n", sport);
395
393
 
396
 
  swill_handle("exit.html", exit_handler,0);
 
394
  swill_handle("exit.html", exit_handler, 0);
397
395
  swill_handle("index.html", node_handler, 0);
398
 
  swill_handle("hide.html", hide_handler,0);
399
 
  swill_handle("show.html", show_handler,0);
400
 
  swill_handle("data.html", data_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);
401
399
  swill_handle("symbol.html", symbol_handler, 0);
402
400
  swill_netscape("index.html");
403
401
 
404
402
  while (!browser_exit) {
405
403
    swill_serve();
406
404
  }
407
 
  Printf(stderr,"Browser terminated.\n");
 
405
  Printf(stderr, "Browser terminated.\n");
408
406
  swill_close();
409
407
  delete browse;
410
408
  return;
411
409
#else
412
 
  (void)top;
413
 
  (void)port;
 
410
  (void) top;
 
411
  (void) port;
414
412
#endif
415
413
}
416
 
 
417
 
 
418
 
 
419
 
 
420