printdocvisitor.h 18.3 KB
Newer Older
1 2
/******************************************************************************
 *
3
 * 
4 5
 *
 *
Dimitri van Heesch's avatar
Dimitri van Heesch committed
6
 * Copyright (C) 1997-2014 by Dimitri van Heesch.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * 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.
 *
 * Documents produced by Doxygen are derivative works derived from the
 * input used in their production; they are not affected by this license.
 *
 */

#ifndef _PRINTDOCVISITOR_H
#define _PRINTDOCVISITOR_H

22
#include <qglobal.h>
23
#include "docvisitor.h"
24
#include "htmlentity.h"
25 26 27 28 29

/*! Concrete visitor implementation for pretty printing */
class PrintDocVisitor : public DocVisitor
{
  public:
Dimitri van Heesch's avatar
Dimitri van Heesch committed
30 31
    PrintDocVisitor() : DocVisitor(DocVisitor_Other), m_indent(0), 
                        m_needsEnter(FALSE), m_insidePre(FALSE) {}
32 33 34 35 36 37 38 39
    
    //--------------------------------------
    
    void visit(DocWord *w)
    {
      indent_leaf();
      printf("%s",w->word().data());
    }
40 41 42 43 44
    void visit(DocLinkedWord *w)
    {
      indent_leaf();
      printf("%s",w->word().data());
    }
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    void visit(DocWhiteSpace *w)
    {
      indent_leaf();
      if (m_insidePre)
      {
        printf("%s",w->chars().data());
      }
      else
      {
        printf(" ");
      }
    }
    void visit(DocSymbol *s)
    {
      indent_leaf();
60
      const char *res = HtmlEntityMapper::instance()->utf8(s->symbol(),TRUE);
61
      if (res)
62
      {
63
        printf("%s",res);
64 65 66
      }
      else
      {
67
        printf("print: non supported HTML-entity found: %s\n",HtmlEntityMapper::instance()->html(s->symbol(),TRUE));
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
      }
    }
    void visit(DocURL *u)
    {
      indent_leaf();
      printf("%s",u->url().data());
    }
    void visit(DocLineBreak *)
    {
      indent_leaf();
      printf("<br/>");
    }
    void visit(DocHorRuler *)
    {
      indent_leaf();
      printf("<hr>");
    }
    void visit(DocStyleChange *s)
    {
      indent_leaf();
      switch (s->style())
      {
        case DocStyleChange::Bold:
91 92
          if (s->enable()) printf("<bold>"); else printf("</bold>");
          break;
93
        case DocStyleChange::Italic:
94 95
          if (s->enable()) printf("<italic>"); else printf("</italic>");
          break;
96
        case DocStyleChange::Code:
97 98
          if (s->enable()) printf("<code>"); else printf("</code>");
          break;
99
        case DocStyleChange::Subscript:
100 101
          if (s->enable()) printf("<sub>"); else printf("</sub>");
          break;
102
        case DocStyleChange::Superscript:
103 104
          if (s->enable()) printf("<sup>"); else printf("</sup>");
          break;
105
        case DocStyleChange::Center:
106 107
          if (s->enable()) printf("<center>"); else printf("</center>");
          break;
108
        case DocStyleChange::Small:
109 110
          if (s->enable()) printf("<small>"); else printf("</small>");
          break;
111
        case DocStyleChange::Preformatted:
112 113
          if (s->enable()) printf("<pre>"); else printf("</pre>");
          break;
114
        case DocStyleChange::Div:
115 116
          if (s->enable()) printf("<div>"); else printf("</div>");
          break;
117
        case DocStyleChange::Span:
118 119
          if (s->enable()) printf("<span>"); else printf("</span>");
          break;
120 121 122 123 124 125 126 127 128 129
      }
    }
    void visit(DocVerbatim *s)
    {
      indent_leaf();
      switch(s->type())
      {
        case DocVerbatim::Code: printf("<code>"); break;
        case DocVerbatim::Verbatim: printf("<verbatim>"); break;
        case DocVerbatim::HtmlOnly: printf("<htmlonly>"); break;
130
        case DocVerbatim::RtfOnly: printf("<rtfonly>"); break;
131
        case DocVerbatim::ManOnly: printf("<manonly>"); break;
132
        case DocVerbatim::LatexOnly: printf("<latexonly>"); break;
133
        case DocVerbatim::XmlOnly: printf("<xmlonly>"); break;
134
        case DocVerbatim::DocbookOnly: printf("<docbookonly>"); break;
135
        case DocVerbatim::Dot: printf("<dot>"); break;
136
        case DocVerbatim::Msc: printf("<msc>"); break;
137
        case DocVerbatim::PlantUML: printf("<plantuml>"); break;
138 139 140 141 142 143 144
      }
      printf("%s",s->text().data());
      switch(s->type())
      {
        case DocVerbatim::Code: printf("</code>"); break;
        case DocVerbatim::Verbatim: printf("</verbatim>"); break;
        case DocVerbatim::HtmlOnly: printf("</htmlonly>"); break;
145
        case DocVerbatim::RtfOnly: printf("</rtfonly>"); break;
146
        case DocVerbatim::ManOnly: printf("</manonly>"); break;
147
        case DocVerbatim::LatexOnly: printf("</latexonly>"); break;
148
        case DocVerbatim::XmlOnly: printf("</xmlonly>"); break;
149
        case DocVerbatim::DocbookOnly: printf("</docbookonly>"); break;
150
        case DocVerbatim::Dot: printf("</dot>"); break;
151
        case DocVerbatim::Msc: printf("</msc>"); break;
152
        case DocVerbatim::PlantUML: printf("</plantuml>"); break;
153 154 155 156 157 158 159 160 161 162 163 164 165 166
      }
    }
    void visit(DocAnchor *a)
    {
      indent_leaf();
      printf("<anchor name=\"%s\"/>",a->anchor().data());
    }
    void visit(DocInclude *inc)
    {
      indent_leaf();
      printf("<include file=\"%s\" type=\"",inc->file().data());
      switch(inc->type())
      {
        case DocInclude::Include: printf("include"); break;
167
        case DocInclude::IncWithLines: printf("incwithlines"); break;
168 169
        case DocInclude::DontInclude: printf("dontinclude"); break;
        case DocInclude::HtmlInclude: printf("htmlinclude"); break;
170
        case DocInclude::LatexInclude: printf("latexinclude"); break;
171
        case DocInclude::VerbInclude: printf("verbinclude"); break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
172
        case DocInclude::Snippet: printf("snippet"); break;
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
      }
      printf("\"/>");
    }
    void visit(DocIncOperator *op)
    {
      indent_leaf();
      printf("<incoperator pattern=\"%s\" type=\"",op->pattern().data());
      switch(op->type())
      {
        case DocIncOperator::Line:     printf("line");     break;
        case DocIncOperator::Skip:     printf("skip");     break;
        case DocIncOperator::SkipLine: printf("skipline"); break;
        case DocIncOperator::Until:    printf("until");    break;
      }
      printf("\"/>");
    }
    void visit(DocFormula *f)
    {
      indent_leaf();
192
      printf("<formula name=%s test=%s/>",f->name().data(),f->text().data());
193
    }
194 195 196 197 198
    void visit(DocIndexEntry *i)
    {
      indent_leaf();
      printf("<indexentry>%s</indexentry\n",i->entry().data());
    }
199 200 201 202 203
    void visit(DocSimpleSectSep *)
    {
      indent_leaf();
      printf("<simplesectsep/>");
    }
204 205 206 207 208 209 210 211 212
    void visit(DocCite *cite)
    {
      indent_leaf();
      printf("<cite ref=\"%s\" file=\"%s\" "
             "anchor=\"%s\" text=\"%s\""
             "/>\n",
             cite->ref().data(),cite->file().data(),cite->anchor().data(),
             cite->text().data());
    }
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

    //--------------------------------------
    
    void visitPre(DocAutoList *l)
    {
      indent_pre();
      if (l->isEnumList())
      {
        printf("<ol>\n");
      }
      else
      {
        printf("<ul>\n");
      }
    }
    void visitPost(DocAutoList *l)
    {
      indent_post();
      if (l->isEnumList())
      {
        printf("</ol>\n");
      }
      else
      {
        printf("</ul>\n");
      }
    }
    void visitPre(DocAutoListItem *)
    {
      indent_pre();
      printf("<li>\n");
    }
    void visitPost(DocAutoListItem *) 
    {
      indent_post();
      printf("</li>\n");
    }
    void visitPre(DocPara *) 
    {
      indent_pre();
      printf("<para>\n");
    }
    void visitPost(DocPara *)
    {
      indent_post();
      printf("</para>\n");
    }
    void visitPre(DocRoot *)
    {
      indent_pre();
      printf("<root>\n");
    }
    void visitPost(DocRoot *)
    {
      indent_post();
      printf("</root>\n");
    }
    void visitPre(DocSimpleSect *s)
    {
      indent_pre();
      printf("<simplesect type=");
274
      switch(s->type())
275 276 277 278
      {
	case DocSimpleSect::See: printf("see"); break;
	case DocSimpleSect::Return: printf("return"); break;
	case DocSimpleSect::Author: printf("author"); break;
279
	case DocSimpleSect::Authors: printf("authors"); break;
280 281 282 283 284 285 286
	case DocSimpleSect::Version: printf("version"); break;
	case DocSimpleSect::Since: printf("since"); break;
	case DocSimpleSect::Date: printf("date"); break;
	case DocSimpleSect::Note: printf("note"); break;
	case DocSimpleSect::Warning: printf("warning"); break;
	case DocSimpleSect::Pre: printf("pre"); break;
	case DocSimpleSect::Post: printf("post"); break;
287
	case DocSimpleSect::Copyright: printf("copyright"); break;
288 289 290 291
	case DocSimpleSect::Invar: printf("invar"); break;
	case DocSimpleSect::Remark: printf("remark"); break;
	case DocSimpleSect::Attention: printf("attention"); break;
	case DocSimpleSect::User: printf("user"); break;
292
	case DocSimpleSect::Rcs: printf("rcs"); break;
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
	case DocSimpleSect::Unknown: printf("unknown"); break;
      }
      printf(">\n");
    }
    void visitPost(DocSimpleSect *)
    {
      indent_post();
      printf("</simplesect>\n");
    }
    void visitPre(DocTitle *)
    {
      indent_pre();
      printf("<title>\n");
    }
    void visitPost(DocTitle *)
    {
      indent_post();
      printf("</title>\n");
    }
    void visitPre(DocSimpleList *)
    {
      indent_pre();
      printf("<ul>\n");
    }
    void visitPost(DocSimpleList *)
    {
      indent_post();
      printf("</ul>\n");
    }
    void visitPre(DocSimpleListItem *)
    {
      indent_pre();
      printf("<li>\n");
    }
    void visitPost(DocSimpleListItem *) 
    {
      indent_post();
      printf("</li>\n");
    }
    void visitPre(DocSection *s)
    {
      indent_pre();
      printf("<sect%d>\n",s->level());
    }
    void visitPost(DocSection *s) 
    {
      indent_post();
      printf("</sect%d>\n",s->level());
    }
    void visitPre(DocHtmlList *s)
    {
      indent_pre();
      if (s->type()==DocHtmlList::Ordered) printf("<ol>\n"); else printf("<ul>\n");
    }
    void visitPost(DocHtmlList *s) 
    {
      indent_post();
      if (s->type()==DocHtmlList::Ordered) printf("</ol>\n"); else printf("</ul>\n");
    }
    void visitPre(DocHtmlListItem *)
    {
      indent_pre();
      printf("<li>\n");
    }
    void visitPost(DocHtmlListItem *) 
    {
      indent_post();
      printf("</li>\n");
    }
362 363 364 365 366 367 368 369 370 371 372 373
    //void visitPre(DocHtmlPre *)
    //{
    //  indent_pre();
    //  printf("<pre>\n");
    //  m_insidePre=TRUE;
    //}
    //void visitPost(DocHtmlPre *) 
    //{
    //  m_insidePre=FALSE;
    //  indent_post();
    //  printf("</pre>\n");
    //}
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
    void visitPre(DocHtmlDescList *)
    {
      indent_pre();
      printf("<dl>\n");
    }
    void visitPost(DocHtmlDescList *) 
    {
      indent_post();
      printf("</dl>\n");
    }
    void visitPre(DocHtmlDescTitle *)
    {
      indent_pre();
      printf("<dt>\n");
    }
    void visitPost(DocHtmlDescTitle *) 
    {
      indent_post();
      printf("</dt>\n");
    }
    void visitPre(DocHtmlDescData *)
    {
      indent_pre();
      printf("<dd>\n");
    }
    void visitPost(DocHtmlDescData *) 
    {
      indent_post();
      printf("</dd>\n");
    }
    void visitPre(DocHtmlTable *t)
    {
      indent_pre();
      printf("<table rows=\"%d\" cols=\"%d\">\n",
Dimitri van Heesch's avatar
Dimitri van Heesch committed
408
          t->numRows(),t->numColumns());
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
    }
    void visitPost(DocHtmlTable *) 
    {
      indent_post();
      printf("</table>\n");
    }
    void visitPre(DocHtmlRow *)
    {
      indent_pre();
      printf("<tr>\n");
    }
    void visitPost(DocHtmlRow *) 
    {
      indent_post();
      printf("</tr>\n");
    }
    void visitPre(DocHtmlCell *c)
    {
      indent_pre();
      printf("<t%c>\n",c->isHeading()?'h':'d');
    }
    void visitPost(DocHtmlCell *c) 
    {
      indent_post();
      printf("</t%c>\n",c->isHeading()?'h':'d');
    }
    void visitPre(DocHtmlCaption *)
    {
      indent_pre();
      printf("<caption>\n");
    }
    void visitPost(DocHtmlCaption *) 
    {
      indent_post();
      printf("</caption>\n");
    }
    void visitPre(DocInternal *)
    {
      indent_pre();
      printf("<internal>\n");
    }
    void visitPost(DocInternal *) 
    {
      indent_post();
      printf("</internal>\n");
    }
    void visitPre(DocHRef *href)
    {
      indent_pre();
      printf("<a url=\"%s\">\n",href->url().data());
    }
    void visitPost(DocHRef *) 
    {
      indent_post();
      printf("</a>\n");
    }
    void visitPre(DocHtmlHeader *header)
    {
      indent_pre();
      printf("<h%d>\n",header->level());
    }
    void visitPost(DocHtmlHeader *header) 
    {
      indent_post();
      printf("</h%d>\n",header->level());
    }
    void visitPre(DocImage *img)
    {
      indent_pre();
478 479 480
      printf("<image src=\"%s\" type=\"",img->name().data());
      switch(img->type())
      {
481 482 483 484
        case DocImage::Html:    printf("html"); break;
        case DocImage::Latex:   printf("latex"); break;
        case DocImage::Rtf:     printf("rtf"); break;
        case DocImage::DocBook: printf("docbook"); break;
485 486
      }
      printf("\" width=%s height=%s>\n",img->width().data(),img->height().data());
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
    }
    void visitPost(DocImage *) 
    {
      indent_post();
      printf("</image>\n");
    }
    void visitPre(DocDotFile *df)
    {
      indent_pre();
      printf("<dotfile src=\"%s\">\n",df->name().data());
    }
    void visitPost(DocDotFile *) 
    {
      indent_post();
      printf("</dotfile>\n");
    }
503 504 505 506 507 508 509 510 511 512
    void visitPre(DocMscFile *df)
    {
      indent_pre();
      printf("<mscfile src=\"%s\">\n",df->name().data());
    }
    void visitPost(DocMscFile *) 
    {
      indent_post();
      printf("</mscfile>\n");
    }
513 514 515 516 517 518 519 520 521 522
    void visitPre(DocDiaFile *df)
    {
      indent_pre();
      printf("<diafile src=\"%s\">\n",df->name().data());
    }
    void visitPost(DocDiaFile *)
    {
      indent_post();
      printf("</diafile>\n");
    }
523 524 525
    void visitPre(DocLink *lnk)
    {
      indent_pre();
526 527
      printf("<link ref=\"%s\" file=\"%s\" anchor=\"%s\">\n",
          lnk->ref().data(),lnk->file().data(),lnk->anchor().data());
528 529 530 531 532 533 534 535 536
    }
    void visitPost(DocLink *) 
    {
      indent_post();
      printf("</link>\n");
    }
    void visitPre(DocRef *ref)
    {
      indent_pre();
537 538 539 540 541 542
      printf("<ref ref=\"%s\" file=\"%s\" "
             "anchor=\"%s\" targetTitle=\"%s\""
             " hasLinkText=\"%s\" refToAnchor=\"%s\" refToSection=\"%s\">\n",
             ref->ref().data(),ref->file().data(),ref->anchor().data(),
             ref->targetTitle().data(),ref->hasLinkText()?"yes":"no",
             ref->refToAnchor()?"yes":"no", ref->refToSection()?"yes":"no");
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568
    }
    void visitPost(DocRef *) 
    {
      indent_post();
      printf("</ref>\n");
    }
    void visitPre(DocSecRefItem *ref)
    {
      indent_pre();
      printf("<secrefitem target=\"%s\">\n",ref->target().data());
    }
    void visitPost(DocSecRefItem *) 
    {
      indent_post();
      printf("</secrefitem>\n");
    }
    void visitPre(DocSecRefList *)
    {
      indent_pre();
      printf("<secreflist>\n");
    }
    void visitPost(DocSecRefList *) 
    {
      indent_post();
      printf("</secreflist>\n");
    }
569 570 571 572 573 574 575 576 577 578
    //void visitPre(DocLanguage *l)
    //{
    //  indent_pre();
    //  printf("<language id=%s>\n",l->id().data());
    //}
    //void visitPost(DocLanguage *) 
    //{
    //  indent_post();
    //  printf("</language>\n");
    //}
579 580 581
    void visitPre(DocParamList *pl)
    {
      indent_pre();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
582 583 584 585
      //QStrListIterator sli(pl->parameters());
      QListIterator<DocNode> sli(pl->parameters());
      //const char *s;
      DocNode *param;
586
      printf("<parameters>");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
587
      for (sli.toFirst();(param=sli.current());++sli)
588
      {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
589 590 591 592 593 594 595 596 597 598
        printf("<param>");
        if (param->kind()==DocNode::Kind_Word)
        {
          visit((DocWord*)param); 
        }
        else if (param->kind()==DocNode::Kind_LinkedWord)
        {
          visit((DocLinkedWord*)param); 
        }
        printf("</param>");
599
      }
600
      printf("\n");
601 602 603 604
    }
    void visitPost(DocParamList *)
    {
      indent_post();
605
      printf("</parameters>\n");
606 607 608 609 610 611 612 613 614 615
    }
    void visitPre(DocParamSect *ps)
    {
      indent_pre();
      printf("<paramsect type=");
      switch (ps->type())
      {
	case DocParamSect::Param: printf("param"); break;
	case DocParamSect::RetVal: printf("retval"); break;
	case DocParamSect::Exception: printf("exception"); break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
616
	case DocParamSect::TemplateParam: printf("templateparam"); break;
617 618
	case DocParamSect::Unknown: printf("unknown"); break;
      }
619
      printf(">\n");
620 621 622 623
    }
    void visitPost(DocParamSect *)
    {
      indent_post();
624
      printf("</paramsect>\n");
625 626 627 628
    }
    void visitPre(DocXRefItem *x)
    {
      indent_pre();
629
      printf("<xrefitem file=\"%s\" anchor=\"%s\" title=\"%s\"/>\n",
630 631 632 633 634
          x->file().data(),x->anchor().data(),x->title().data());
    }
    void visitPost(DocXRefItem *)
    {
      indent_post();
635
      printf("<xrefitem/>\n");
636 637 638 639 640 641 642 643 644 645 646
    }
    void visitPre(DocInternalRef *r)
    {
      indent_pre();
      printf("<internalref file=%s anchor=%s>\n",r->file().data(),r->anchor().data());
    }
    void visitPost(DocInternalRef *)
    {
      indent_post();
      printf("</internalref>\n");
    }
647 648 649 650 651 652 653 654 655 656
    void visitPre(DocCopy *c)
    {
      indent_pre();
      printf("<copy link=\"%s\">\n",c->link().data());
    }
    void visitPost(DocCopy *)
    {
      indent_post();
      printf("</copy>\n");
    }
657 658 659 660 661 662 663 664 665 666
    void visitPre(DocText *)
    {
      indent_pre();
      printf("<text>\n");
    }
    void visitPost(DocText *)
    {
      indent_post();
      printf("</text>\n");
    }
667 668 669 670 671 672 673 674 675 676
    void visitPre(DocHtmlBlockQuote *)
    {
      indent_pre();
      printf("<blockquote>\n");
    }
    void visitPost(DocHtmlBlockQuote *)
    {
      indent_post();
      printf("</blockquote>\n");
    }
677 678 679 680 681 682 683 684 685 686
    void visitPre(DocVhdlFlow *)
    {
      indent_pre();
      printf("<vhdlflow>\n");
    }
    void visitPost(DocVhdlFlow *)
    {
      indent_post();
      printf("</vhdlflow>\n");
    }
687 688 689 690 691 692 693 694 695 696
    void visitPre(DocParBlock *)
    {
      indent_pre();
      printf("<parblock>\n");
    }
    void visitPost(DocParBlock *)
    {
      indent_post();
      printf("</parblock>\n");
    }
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728

  private:
    // helper functions
    void indent() 
    { 
      if (m_needsEnter) printf("\n");
      for (int i=0;i<m_indent;i++) printf("."); 
      m_needsEnter=FALSE;
    } 
    void indent_leaf()
    {
      if (!m_needsEnter) indent();
      m_needsEnter=TRUE;
    }
    void indent_pre()
    {
      indent();
      m_indent++;
    }
    void indent_post()
    {
      m_indent--;
      indent();
    }
    
    // member variables
    int m_indent;
    bool m_needsEnter;
    bool m_insidePre;
};

#endif