main.cpp 21.5 KB
Newer Older
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1 2 3 4 5
/******************************************************************************
 *
 * $Id$
 *
 *
6
 * Copyright (C) 1997-2006 by Dimitri van Heesch.
Dimitri van Heesch's avatar
Dimitri van Heesch committed
7 8 9 10 11 12 13 14 15 16
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation under the terms of the GNU General Public License is hereby 
 * granted. No representations are made about the suitability of this software 
 * for any purpose. It is provided "as is" without express or implied warranty.
 * See the GNU General Public License for more details.
 *
 */

#include <stdio.h>
17
#include <stdlib.h>
Dimitri van Heesch's avatar
Dimitri van Heesch committed
18
#include <doxmlintf.h>
19
#include <qstring.h>
Dimitri van Heesch's avatar
Dimitri van Heesch committed
20

21 22 23
/*! Dumps the contents of a hyperlinked text fragment as plain text to the
 *  output.
 */
Dimitri van Heesch's avatar
Dimitri van Heesch committed
24 25 26 27 28 29 30 31
QString linkedTextToString(ILinkedTextIterator *ti)
{
  QString result;
  ILinkedText *lt=0;
  for (ti->toFirst();(lt=ti->current());ti->toNext())
  {
    switch (lt->kind())
    {
32 33 34 35
      case ILinkedText::Kind_Text: // plain text
        result+=dynamic_cast<ILT_Text*>(lt)->text()->latin1(); break;
      case ILinkedText::Kind_Ref:  // a link
        result+=dynamic_cast<ILT_Ref *>(lt)->text()->latin1(); break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
36 37 38 39 40
    }
  }
  return result;
}

41 42 43 44 45 46 47 48 49
/*! Macro for printing an indented  message. */
#define InPrint(x) printf("%s",indent.latin1()), printf x;

/*! Dumps the contents of a documentation block to stdout.
 *  @note This function will call itself recursively.
 *  @param doc The root of the documentation tree.
 *  @param level The indent level.
 */
void DumpDoc(IDoc *doc,int level)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
50
{
51
  if (doc==0) return;
52 53 54
  QString indent;
  indent.fill(' ',level);
  //printf("      doc node kind=`%d'\n",doc->kind());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
55 56 57 58
  switch (doc->kind())
  {
    case IDoc::Para: 
      {
59
        InPrint(("<para>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
60 61 62 63 64 65
        IDocPara *par = dynamic_cast<IDocPara*>(doc);
        ASSERT(par!=0);
        IDocIterator *di = par->contents();
        IDoc *pdoc;
        for (di->toFirst();(pdoc=di->current());di->toNext())
        {
66
          DumpDoc(pdoc,level+1);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
67 68
        }
        di->release();
69
        InPrint(("</para>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
70 71 72 73 74 75
      }
      break;
    case IDoc::Text:
      {
        IDocText *txt = dynamic_cast<IDocText*>(doc);
        ASSERT(txt!=0);
76 77
        InPrint(("<text value=`%s' markup=%d headingLevel=%d/>\n",
              txt->text()->latin1(),txt->markup(),txt->headingLevel()));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
78 79
      }
      break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
80 81 82 83
    case IDoc::MarkupModifier:
      {
        IDocMarkupModifier *md = dynamic_cast<IDocMarkupModifier*>(doc);
        ASSERT(md!=0);
84 85
        InPrint(("<markup modifier enabled=%d markup=%d headingLevel=%d/>\n",
              md->enabled(),md->markup(),md->headingLevel()));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
86 87 88 89
      }
      break;
    case IDoc::ItemizedList:
      {
90
        InPrint(("<itemized list>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
91 92 93 94 95 96
        IDocItemizedList *list = dynamic_cast<IDocItemizedList*>(doc);
        ASSERT(list!=0);
        IDocIterator *di = list->elements();
        IDoc *pdoc;
        for (di->toFirst();(pdoc=di->current());di->toNext())
        {
97
          DumpDoc(pdoc,level+1);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
98 99
        }
        di->release();
100
        InPrint(("</itemized list>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
101 102 103 104
      }
      break;
    case IDoc::OrderedList:
      {
105
        InPrint(("<ordered list>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
106 107 108 109 110 111
        IDocOrderedList *list = dynamic_cast<IDocOrderedList*>(doc);
        ASSERT(list!=0);
        IDocIterator *di = list->elements();
        IDoc *pdoc;
        for (di->toFirst();(pdoc=di->current());di->toNext())
        {
112
          DumpDoc(pdoc,level+1);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
113 114
        }
        di->release();
115
        InPrint(("</ordered list>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
116 117 118 119
      }
      break;
    case IDoc::ListItem:
      {
120
        InPrint(("<list item>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
121 122 123 124 125 126
        IDocListItem *li = dynamic_cast<IDocListItem*>(doc);
        ASSERT(li!=0);
        IDocIterator *di = li->contents();
        IDoc *pdoc;
        for (di->toFirst();(pdoc=di->current());di->toNext())
        {
127
          DumpDoc(pdoc,level+1);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
128 129
        }
        di->release();
130
        InPrint(("</list item>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
131 132
      }
      break;
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
    case IDoc::ParameterItem:
      {
        IDocParameterItem *item = dynamic_cast<IDocParameterItem*>(doc);
        InPrint(("<parameter item>\n"));
        IDocIterator *di = item->paramNames();
        IDoc *pdoc;
        for (di->toFirst();(pdoc=di->current());di->toNext())
        {
          DumpDoc(pdoc,level+1);
        }
        di->release();
        DumpDoc(item->description(),level+1);
        InPrint(("</parameter item>\n"));
      }
      break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
148 149 150
    case IDoc::ParameterList:
      {
        IDocParameterList *list = dynamic_cast<IDocParameterList*>(doc);
151
        InPrint(("<parameter list type=%d>\n",list->sectType()));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
152
        IDocIterator *di = list->params();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
153 154 155
        IDoc *pdoc;
        for (di->toFirst();(pdoc=di->current());di->toNext())
        {
156
          DumpDoc(pdoc,level+1);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
157 158
        }
        di->release();
159
        InPrint(("</parameter list>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
160 161 162 163 164 165 166
        ASSERT(list!=0);
      }
      break;
    case IDoc::Parameter:
      {
        IDocParameter *par = dynamic_cast<IDocParameter*>(doc);
        ASSERT(par!=0);
167
        InPrint(("<parameter name=%s/>\n",par->name()->latin1()));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
168 169 170 171
      }
      break;
    case IDoc::SimpleSect:
      {
172
        IDocSimpleSect *ss = dynamic_cast<IDocSimpleSect*>(doc);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
173
        ASSERT(ss!=0);
174 175 176 177
        InPrint(("<simplesect type=%s>\n",ss->typeString()->latin1()));
        DumpDoc(ss->title(),level+1);
        DumpDoc(ss->description(),level+1);
        InPrint(("<simplesect/>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
178 179
      }
      break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
180 181
    case IDoc::Title:
      {
182
        InPrint(("<title>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
183 184 185 186 187 188
        IDocTitle *t = dynamic_cast<IDocTitle*>(doc);
        ASSERT(t!=0);
        IDocIterator *di = t->title();
        IDoc *pdoc;
        for (di->toFirst();(pdoc=di->current());di->toNext())
        {
189
          DumpDoc(pdoc,level+1);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
190
        }
191
        InPrint(("<title/>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
192 193
      }
      break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
194 195
    case IDoc::Ref:
      {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
196
        IDocRef *ref = dynamic_cast<IDocRef*>(doc);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
197
        ASSERT(ref!=0);
198 199
        InPrint(("<ref id=%s text=%s/>\n",
            ref->refId()->latin1(),ref->text()->latin1()));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
200 201 202 203
      }
      break;
    case IDoc::VariableList:
      {
204
        InPrint(("<variablelist>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
205
        IDocVariableList *vl = dynamic_cast<IDocVariableList*>(doc);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
206
        ASSERT(vl!=0);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
207 208 209 210
        IDocIterator *di = vl->entries();
        IDoc *pdoc;
        for (di->toFirst();(pdoc=di->current());di->toNext())
        {
211
          DumpDoc(pdoc,level+1);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
212 213
        }
        di->release();
214
        InPrint(("<variablelist/>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
215 216 217 218
      }
      break;
    case IDoc::VariableListEntry:
      {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
219
        IDocVariableListEntry *vle = dynamic_cast<IDocVariableListEntry*>(doc);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
220
        ASSERT(vle!=0);
221 222 223 224
        ILinkedTextIterator *lti = vle->term();
        QString term = linkedTextToString(lti);
        lti->release();
        InPrint(("<variablelistentry term=%s>\n",term.latin1()));
225 226
        DumpDoc(vle->description(),level+1);
        InPrint(("<variablelistentry/>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
227 228 229 230
      }
      break;
    case IDoc::HRuler:
      {
231
        IDocHRuler *hr = dynamic_cast<IDocHRuler*>(doc);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
232
        ASSERT(hr!=0);
233
        InPrint(("<hruler/>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
234 235 236 237
      }
      break;
    case IDoc::LineBreak:
      {
238
        IDocLineBreak *lb = dynamic_cast<IDocLineBreak*>(doc);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
239
        ASSERT(lb!=0);
240
        InPrint(("<linebreak/>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
241 242 243 244
      }
      break;
    case IDoc::ULink:
      {
245
        IDocULink *ul = dynamic_cast<IDocULink*>(doc);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
246
        ASSERT(ul!=0);
247
        InPrint(("<ulink url=`%s' text=`%s'/>\n",ul->url()->latin1(),ul->text()->latin1()));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
248 249 250 251
      }
      break;
    case IDoc::EMail:
      {
252
        IDocEMail *em = dynamic_cast<IDocEMail*>(doc);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
253
        ASSERT(em!=0);
254
        InPrint(("<email address=`%s'/>\n",em->address()->latin1()));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
255 256 257 258
      }
      break;
    case IDoc::Link:
      {
259
        IDocLink *lk = dynamic_cast<IDocLink*>(doc);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
260
        ASSERT(lk!=0);
261
        InPrint(("<link refid=`%s' text=`%s'/>\n",lk->refId()->latin1(),lk->text()->latin1()));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
262 263 264 265
      }
      break;
    case IDoc::ProgramListing:
      {
266
        IDocProgramListing *pl = dynamic_cast<IDocProgramListing*>(doc);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
267
        ASSERT(pl!=0);
268 269 270 271 272 273 274 275
        InPrint(("<programlisting>\n"));
        IDocIterator *cli = pl->codeLines();
        IDoc *cl;
        for (cli->toFirst();(cl=cli->current());cli->toNext())
        {
          DumpDoc(cl,level+1);
        }
        cli->release();
276
        InPrint(("</programlisting>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
277 278 279 280
      }
      break;
    case IDoc::CodeLine:
      {
281
        IDocCodeLine *cl = dynamic_cast<IDocCodeLine*>(doc);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
282
        ASSERT(cl!=0);
283 284 285 286 287 288 289 290
        InPrint(("<codeline lineNumber=%d refId=`%s'>\n",cl->lineNumber(),cl->refId()->latin1()));
        IDocIterator *cei = cl->codeElements();
        IDoc *ce;
        for (cei->toFirst();(ce=cei->current());cei->toNext())
        {
          DumpDoc(ce,level+1);
        }
        cei->release();
291
        InPrint(("</codeline>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
292 293 294 295
      }
      break;
    case IDoc::Highlight:
      {
296
        IDocHighlight *hl = dynamic_cast<IDocHighlight*>(doc);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
297
        ASSERT(hl!=0);
298 299 300 301 302 303 304 305 306
        InPrint(("<highlight kind=%d>\n",hl->kind()));
        IDocIterator *cei = hl->codeElements();
        IDoc *ce;
        for (cei->toFirst();(ce=cei->current());cei->toNext())
        {
          DumpDoc(ce,level+1);
        }
        cei->release();
        InPrint(("</highlight>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
307 308 309 310
      }
      break;
    case IDoc::Formula:
      {
311
        IDocFormula *fm = dynamic_cast<IDocFormula*>(doc);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
312
        ASSERT(fm!=0);
313
        InPrint(("<formula id=`%s' text=`%s'/>\n",fm->id()->latin1(),fm->text()->latin1()));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
314 315 316 317
      }
      break;
    case IDoc::Image:
      {
318
        IDocImage *img = dynamic_cast<IDocImage*>(doc);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
319
        ASSERT(img!=0);
320
        InPrint(("<image name=`%s' caption=`%s'/>\n",img->name()->latin1(),img->caption()->latin1()));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
321 322 323 324
      }
      break;
    case IDoc::DotFile:
      {
325
        IDocDotFile *df = dynamic_cast<IDocDotFile*>(doc);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
326
        ASSERT(df!=0);
327
        InPrint(("<dotfile name=`%s' caption=`%s'/>\n",df->name()->latin1(),df->caption()->latin1()));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
328 329 330 331
      }
      break;
    case IDoc::IndexEntry:
      {
332
        IDocIndexEntry *ie = dynamic_cast<IDocIndexEntry*>(doc);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
333
        ASSERT(ie!=0);
334
        InPrint(("<indexentry primary=`%s' secondary=`%s'/>\n",ie->primary()->latin1(),ie->secondary()->latin1()));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
335 336 337 338
      }
      break;
    case IDoc::Table:
      {
339
        IDocTable *tbl = dynamic_cast<IDocTable*>(doc);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
340
        ASSERT(tbl!=0);
341 342 343 344 345 346 347 348 349
        InPrint(("<table numcols=%d caption=`%s'>\n",tbl->numColumns(),tbl->caption()->latin1()));
        IDocIterator *ri = tbl->rows();
        IDoc *row;
        for (ri->toFirst();(row=ri->current());ri->toNext())
        {
          DumpDoc(row,level+1);
        }
        ri->release();
        InPrint(("</table>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
350 351 352 353
      }
      break;
    case IDoc::Row:
      {
354
        IDocRow *row = dynamic_cast<IDocRow*>(doc);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
355
        ASSERT(row!=0);
356 357 358 359 360 361 362 363 364
        InPrint(("<row>\n"));
        IDocIterator *ei = row->entries();
        IDoc *e;
        for (ei->toFirst();(e=ei->current());ei->toNext())
        {
          DumpDoc(e,level+1);
        }
        ei->release();
        InPrint(("</row>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
365 366 367 368
      }
      break;
    case IDoc::Entry:
      {
369
        IDocEntry *ent = dynamic_cast<IDocEntry*>(doc);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
370
        ASSERT(ent!=0);
371 372 373 374 375 376 377 378 379
        InPrint(("<entry>\n"));
        IDocIterator *di = ent->contents();
        IDoc *pdoc;
        for (di->toFirst();(pdoc=di->current());di->toNext())
        {
          DumpDoc(pdoc,level+1);
        }
        di->release();
        InPrint(("</entry>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
380 381
      }
      break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
382 383 384 385
    case IDoc::Section:
      {
        IDocSection *sec = dynamic_cast<IDocSection*>(doc);
        ASSERT(sec!=0);
386 387
        InPrint(("<section id=`%s' level=%d>\n",
            sec->id()->latin1(),sec->level()));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
388 389
        DumpDoc(sec->title(),level+1);
        IDocIterator *di = sec->paragraphs();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
390 391 392
        IDoc *pdoc;
        for (di->toFirst();(pdoc=di->current());di->toNext())
        {
393
          DumpDoc(pdoc,level+1);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
394
        }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
395 396 397 398 399 400 401 402 403 404
        di=sec->subSections();
        for (di->toFirst();(pdoc=di->current());di->toNext())
        {
          DumpDoc(pdoc,level+1);
        }
        IDocInternal *intern = sec->internal();
        if (intern)
        {
          DumpDoc(intern,level+1);
        }
405
        InPrint(("</section>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
406 407
      }
      break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
    case IDoc::Internal:
      {
        IDocInternal *intern = dynamic_cast<IDocInternal*>(doc);
        ASSERT(intern!=0);
        InPrint(("<internal>\n"));
        IDocIterator *di = intern->paragraphs();
        IDoc *pdoc;
        for (di->toFirst();(pdoc=di->current());di->toNext())
        {
          DumpDoc(pdoc,level+1);
        }
        di=intern->subSections();
        for (di->toFirst();(pdoc=di->current());di->toNext())
        {
          DumpDoc(pdoc,level+1);
        }
        InPrint(("</internal>\n"));
      }
      break;
427
    case IDoc::Copy:
428
      {
429 430 431 432
        IDocCopy *cpy = dynamic_cast<IDocCopy*>(doc);
        ASSERT(cpy!=0);
        InPrint(("<copydoc>\n"));
        IDocIterator *di = cpy->contents();
433 434 435 436 437 438
        IDoc *pdoc;
        for (di->toFirst();(pdoc=di->current());di->toNext())
        {
          DumpDoc(pdoc,level+1);
        }
        di->release();
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
        InPrint(("<copydoc/>\n"));
      }
      break;
    case IDoc::TocItem:
      {
        IDocTocItem *ti = dynamic_cast<IDocTocItem*>(doc);
        ASSERT(ti!=0);
        InPrint(("<tocitem id=\"%s\" title=\"%s\"/>\n",
                 ti->id()->latin1(),ti->title()->latin1()));
      }
      break;
    case IDoc::TocList:
      {
        IDocTocList *tl = dynamic_cast<IDocTocList*>(doc);
        ASSERT(tl!=0);
        InPrint(("<toclist>\n"));
        IDocIterator *di = tl->elements();
        IDoc *pdoc;
        for (di->toFirst();(pdoc=di->current());di->toNext())
        {
          DumpDoc(pdoc,level+1);
        }
        di->release();
        InPrint(("<toclist/>\n"));
463 464
      }
      break;
465 466 467 468
    case IDoc::Verbatim:
      {
        IDocVerbatim *vt = dynamic_cast<IDocVerbatim*>(doc);
        ASSERT(vt!=0);
469 470 471 472 473 474 475 476 477 478
        const char *s=0;
        switch (vt->type())
        {
          case IDocVerbatim::Verbatim:  s="verbatim"; break;
          case IDocVerbatim::HtmlOnly:  s="htmlonly"; break;
          case IDocVerbatim::LatexOnly: s="latexonly"; break;
          default:
            printf("Invalid verbatim type!\n");
        }
        InPrint(("<verbatim %s>\n",s));
479
        InPrint(("%s",vt->text()->latin1()));
480 481 482 483 484 485 486 487
        InPrint(("</verbatim>\n"));
      }
      break;
    case IDoc::Anchor:
      {
        IDocAnchor *anc = dynamic_cast<IDocAnchor*>(doc);
        ASSERT(anc!=0);
        InPrint(("<anchor id='%s'/>\n",anc->id()->latin1()));
488 489
      }
      break;
490 491 492 493 494 495 496 497
    case IDoc::Symbol:
      {
        IDocSymbol *sym = dynamic_cast<IDocSymbol*>(doc);
        ASSERT(sym!=0);
        InPrint(("<symbol type=%s letter=%c/>\n",
              sym->typeString()->latin1(),sym->letter()));
      }
      break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
498 499
    case IDoc::Root:
      {
500
        InPrint(("<root>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
501 502 503 504 505 506
        IDocRoot *root = dynamic_cast<IDocRoot*>(doc);
        ASSERT(root!=0);
        IDocIterator *di = root->contents();
        IDoc *pdoc;
        for (di->toFirst();(pdoc=di->current());di->toNext())
        {
507
          DumpDoc(pdoc,level+1);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
508 509
        }
        di->release();
510
        InPrint(("</root>\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
511 512 513 514
      }
      break;

    default:
515
      printf("Found unsupported node type %d!\n",doc->kind());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
516 517 518 519
      break;
  }
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
520 521 522 523 524 525 526 527 528
void DumpGraph(IGraph *graph)
{
  if (graph==0) { printf(" --- no graph ---\n"); return; }
  printf(" --- graph ----\n");
  INodeIterator *ni = graph->nodes();
  INode *node;
  for (ni->toFirst();(node=ni->current());ni->toNext())
  {
    printf("   --- node id=%s label=%s linkId=%s\n",
529 530 531
           node->id()->latin1(),
           node->label()->latin1(),
           node->linkId()->latin1()
Dimitri van Heesch's avatar
Dimitri van Heesch committed
532 533 534 535 536 537
          );
    IChildNodeIterator *cni = node->children();
    IChildNode *cn;
    for (cni->toFirst();(cn=cni->current());cni->toNext())
    {
      printf("    + child id=%s label=%s relation=%s\n",
538 539 540
          cn->node()->id()->latin1(),
          cn->node()->label()->latin1(),
          cn->relationString()->latin1()
Dimitri van Heesch's avatar
Dimitri van Heesch committed
541 542 543 544 545
      );
      IEdgeLabelIterator *eli = cn->edgeLabels();
      IEdgeLabel *el;
      for (eli->toFirst();(el=eli->current());eli->toNext())
      {
546
        printf("      edgeLabel=%s\n",el->label()->latin1());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
547 548 549 550 551 552 553 554 555 556
      }
      eli->release();
    }
    cni->release();
  }
  ni->release();
  printf(" --- end graph ----\n");

}

557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
void DumpParamList(IParamIterator *pli,int indent)
{
  QString indentStr;
  indentStr.fill(' ',indent);
  IParam *par;
  for (pli->toFirst();(par=pli->current());pli->toNext())
  {
    ILinkedTextIterator *lti = par->type();
    QString parType = linkedTextToString(lti);
    lti->release();
    lti = par->defaultValue();
    QString defVal =  linkedTextToString(lti);
    lti->release();
    printf("%sParam type=%s decl_name=%s def_name=%s defvalue=%s\n",
        indentStr.data(), parType.latin1(), 
        par->declarationName()->latin1(),
        par->definitionName()->latin1(),
        defVal.latin1());
  }
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
578 579 580 581
int main(int argc,char **argv)
{
  if (argc!=2)
  {
582
    printf("Usage: %s xmldir\n",argv[0]);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
583 584 585
    exit(1);
  }

586 587
  IDoxygen *dox = createObjectModel();

588
  dox->setDebugLevel(4);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
589

590 591 592 593 594
  if (!dox->readXMLDir(argv[1]))
  {
    printf("Error reading %s/index.xml\n",argv[1]);
    exit(1);
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
595 596 597 598 599 600 601

  ICompoundIterator *cli = dox->compounds();
  ICompound *comp;
  printf("--- compound list ---------\n");
  for (cli->toFirst();(comp=cli->current());cli->toNext())
  {
    printf("Compound name=%s id=%s kind=%s\n",
602
        comp->name()->latin1(),comp->id()->latin1(),comp->kindString()->latin1());
603

Dimitri van Heesch's avatar
Dimitri van Heesch committed
604 605 606 607
    ISectionIterator *sli = comp->sections();
    ISection *sec;
    for (sli->toFirst();(sec=sli->current());sli->toNext())
    {
608
      printf("  Section kind=%s\n",sec->kindString()->latin1());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
609 610
      IMemberIterator *mli = sec->members();
      IMember *mem;
611 612 613 614 615
      if( sec->kind() == ISection::UserDefined )
      {
	IUserDefined *group = dynamic_cast<IUserDefined*>(sec);
	printf("    Title=%s\n", group->header()->latin1() );
      }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
616 617 618 619
      for (mli->toFirst();(mem=mli->current());mli->toNext())
      {
        ILinkedTextIterator *lti = mem->type();
        printf("    Member type=%s name=%s\n",
620
            linkedTextToString(lti).latin1(),mem->name()->latin1());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
621 622
        lti->release();

623 624
        IParamIterator *pli = mem->parameters();
        DumpParamList(pli,6);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
625 626 627 628 629 630 631
        pli->release();
        IMemberReferenceIterator *mri = mem->references();
        IMemberReference *mr;
        for (mri->toFirst();(mr=mri->current());mri->toNext())
        {
          IMember *memr = mr->member();
          printf("      References %s at line %d\n",
632
              mr->name()->latin1(),memr->bodyStart());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
633 634 635 636 637 638 639 640
        }

        mri->release();
        mri = mem->referencedBy();
        for (mri->toFirst();(mr=mri->current());mri->toNext())
        {
          IMember *memr = mr->member();
          printf("      ReferencedBy %s at line %d\n",
641
              mr->name()->latin1(),memr->bodyStart());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
642 643 644
        }
        mri->release();

645
        if (mem->kind()==IMember::Enum) // we have found an enum
Dimitri van Heesch's avatar
Dimitri van Heesch committed
646
        {
647 648 649 650 651 652 653 654 655 656 657 658 659
          IEnum *e = dynamic_cast<IEnum*>(mem);
          IMemberIterator *evi = e->enumValues(); // get the enum values
          IMember *mev;
          for (evi->toFirst();(mev=evi->current());evi->toNext())
          {
            IEnumValue *ev = dynamic_cast<IEnumValue*>(mev);
            ILinkedTextIterator *lti = ev->initializer();
            QString init = linkedTextToString(lti);
            lti->release();
            printf("      Enum value `%s' init=`%s'\n",
                ev->name()->latin1(),init.latin1());
          }
          evi->release();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
660 661
        }

662 663 664 665 666 667 668 669
        pli = mem->templateParameters();
        if (pli)
        {
          printf("      Template parameters\n");
          DumpParamList(pli,8);
          pli->release();
        }

Dimitri van Heesch's avatar
Dimitri van Heesch committed
670 671 672 673
        IDoc *doc = mem->briefDescription();
        if (doc)
        {
          printf("===== brief description ==== \n");
674
          DumpDoc(doc,0);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
675 676 677 678 679 680
        }

        doc = mem->detailedDescription();
        if (doc)
        {
          printf("===== detailed description ==== \n");
681
          DumpDoc(doc,0);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
682 683 684 685 686 687 688 689 690 691
        }
      }
      mli->release();
    }
    sli->release();

    IDoc *doc = comp->briefDescription();
    if (doc)
    {
      printf("===== brief description ==== \n");
692
      DumpDoc(doc,0);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
693 694 695 696 697 698
    }

    doc = comp->detailedDescription();
    if (doc)
    {
      printf("===== detailed description ==== \n");
699
      DumpDoc(doc,0);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
700
    }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
701 702 703 704 705 706 707 708 709 710 711 712 713

    if (comp->kind()==ICompound::Class)
    {
      IClass *cls = dynamic_cast<IClass*>(comp);
      ASSERT(cls!=0);

      printf("==== inheritance graph ==== \n");
      DumpGraph(cls->inheritanceGraph());

      printf("==== collabration graph ==== \n");
      DumpGraph(cls->collaborationGraph());

      printf("==== base classes ==== \n");
714
      IRelatedCompoundIterator *bcli = cls->baseCompounds();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
715 716 717 718
      IRelatedCompound *bClass;
      for (bcli->toFirst();(bClass=bcli->current());bcli->toNext())
      {
        ICompound *bc = bClass->compound();
719
        printf("    + class %s\n",bc->name()->latin1());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
720 721 722 723 724
        bc->release();
      }
      bcli->release();

      printf("==== derived classes ==== \n");
725
      IRelatedCompoundIterator *dcli = cls->derivedCompounds();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
726 727 728 729
      IRelatedCompound *dClass;
      for (dcli->toFirst();(dClass=dcli->current());dcli->toNext())
      {
        ICompound *dc = dClass->compound();
730
        printf("    + class %s\n",dc->name()->latin1());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
731 732 733 734
        dc->release();
      }
      dcli->release();
    }
735 736 737 738 739 740 741 742 743 744
    else if (comp->kind()==ICompound::File)
    {
      IFile *file = dynamic_cast<IFile*>(comp);
      ASSERT(file!=0);

      printf("==== include dependency graph ==== \n");
      DumpGraph(file->includeDependencyGraph());

      printf("==== included by dependency graph ==== \n");
      DumpGraph(file->includedByDependencyGraph());
745 746 747

      printf("==== source ====\n");
      DumpDoc(file->source(),0);
748
    }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
749
    
750
    comp->release();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
751 752 753 754 755 756 757 758 759
  }
  cli->release();
  printf("---------------------------\n");

  dox->release();

  return 0;
}