d1dbb7424703988404d0107da41db0b53b07be49
[platform/upstream/doxygen.git] / src / printdocvisitor.h
1 /******************************************************************************
2  *
3  * 
4  *
5  *
6  * Copyright (C) 1997-2015 by Dimitri van Heesch.
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation under the terms of the GNU General Public License is hereby 
10  * granted. No representations are made about the suitability of this software 
11  * for any purpose. It is provided "as is" without express or implied warranty.
12  * See the GNU General Public License for more details.
13  *
14  * Documents produced by Doxygen are derivative works derived from the
15  * input used in their production; they are not affected by this license.
16  *
17  */
18
19 #ifndef _PRINTDOCVISITOR_H
20 #define _PRINTDOCVISITOR_H
21
22 #include <qglobal.h>
23 #include "docvisitor.h"
24 #include "htmlentity.h"
25 #include "message.h"
26
27 /*! Concrete visitor implementation for pretty printing */
28 class PrintDocVisitor : public DocVisitor
29 {
30   public:
31     PrintDocVisitor() : DocVisitor(DocVisitor_Other), m_indent(0), 
32                         m_needsEnter(FALSE), m_insidePre(FALSE) {}
33     
34     //--------------------------------------
35     
36     void visit(DocWord *w)
37     {
38       indent_leaf();
39       printf("%s",w->word().data());
40     }
41     void visit(DocLinkedWord *w)
42     {
43       indent_leaf();
44       printf("%s",w->word().data());
45     }
46     void visit(DocWhiteSpace *w)
47     {
48       indent_leaf();
49       if (m_insidePre)
50       {
51         printf("%s",w->chars().data());
52       }
53       else
54       {
55         printf(" ");
56       }
57     }
58     void visit(DocSymbol *s)
59     {
60       indent_leaf();
61       const char *res = HtmlEntityMapper::instance()->utf8(s->symbol(),TRUE);
62       if (res)
63       {
64         printf("%s",res);
65       }
66       else
67       {
68         printf("print: non supported HTML-entity found: %s\n",HtmlEntityMapper::instance()->html(s->symbol(),TRUE));
69       }
70     }
71     void visit(DocURL *u)
72     {
73       indent_leaf();
74       printf("%s",u->url().data());
75     }
76     void visit(DocLineBreak *)
77     {
78       indent_leaf();
79       printf("<br/>");
80     }
81     void visit(DocHorRuler *)
82     {
83       indent_leaf();
84       printf("<hr>");
85     }
86     void visit(DocStyleChange *s)
87     {
88       indent_leaf();
89       switch (s->style())
90       {
91         case DocStyleChange::Bold:
92           if (s->enable()) printf("<bold>"); else printf("</bold>");
93           break;
94         case DocStyleChange::Italic:
95           if (s->enable()) printf("<italic>"); else printf("</italic>");
96           break;
97         case DocStyleChange::Code:
98           if (s->enable()) printf("<code>"); else printf("</code>");
99           break;
100         case DocStyleChange::Subscript:
101           if (s->enable()) printf("<sub>"); else printf("</sub>");
102           break;
103         case DocStyleChange::Superscript:
104           if (s->enable()) printf("<sup>"); else printf("</sup>");
105           break;
106         case DocStyleChange::Center:
107           if (s->enable()) printf("<center>"); else printf("</center>");
108           break;
109         case DocStyleChange::Small:
110           if (s->enable()) printf("<small>"); else printf("</small>");
111           break;
112         case DocStyleChange::Preformatted:
113           if (s->enable()) printf("<pre>"); else printf("</pre>");
114           break;
115         case DocStyleChange::Div:
116           if (s->enable()) printf("<div>"); else printf("</div>");
117           break;
118         case DocStyleChange::Span:
119           if (s->enable()) printf("<span>"); else printf("</span>");
120           break;
121       }
122     }
123     void visit(DocVerbatim *s)
124     {
125       indent_leaf();
126       switch(s->type())
127       {
128         case DocVerbatim::Code: printf("<code>"); break;
129         case DocVerbatim::Verbatim: printf("<verbatim>"); break;
130         case DocVerbatim::HtmlOnly: printf("<htmlonly>"); break;
131         case DocVerbatim::RtfOnly: printf("<rtfonly>"); break;
132         case DocVerbatim::ManOnly: printf("<manonly>"); break;
133         case DocVerbatim::LatexOnly: printf("<latexonly>"); break;
134         case DocVerbatim::XmlOnly: printf("<xmlonly>"); break;
135         case DocVerbatim::DocbookOnly: printf("<docbookonly>"); break;
136         case DocVerbatim::Dot: printf("<dot>"); break;
137         case DocVerbatim::Msc: printf("<msc>"); break;
138         case DocVerbatim::PlantUML: printf("<plantuml>"); break;
139       }
140       printf("%s",s->text().data());
141       switch(s->type())
142       {
143         case DocVerbatim::Code: printf("</code>"); break;
144         case DocVerbatim::Verbatim: printf("</verbatim>"); break;
145         case DocVerbatim::HtmlOnly: printf("</htmlonly>"); break;
146         case DocVerbatim::RtfOnly: printf("</rtfonly>"); break;
147         case DocVerbatim::ManOnly: printf("</manonly>"); break;
148         case DocVerbatim::LatexOnly: printf("</latexonly>"); break;
149         case DocVerbatim::XmlOnly: printf("</xmlonly>"); break;
150         case DocVerbatim::DocbookOnly: printf("</docbookonly>"); break;
151         case DocVerbatim::Dot: printf("</dot>"); break;
152         case DocVerbatim::Msc: printf("</msc>"); break;
153         case DocVerbatim::PlantUML: printf("</plantuml>"); break;
154       }
155     }
156     void visit(DocAnchor *a)
157     {
158       indent_leaf();
159       printf("<anchor name=\"%s\"/>",a->anchor().data());
160     }
161     void visit(DocInclude *inc)
162     {
163       indent_leaf();
164       printf("<include file=\"%s\" type=\"",inc->file().data());
165       switch(inc->type())
166       {
167         case DocInclude::Include: printf("include"); break;
168         case DocInclude::IncWithLines: printf("incwithlines"); break;
169         case DocInclude::DontInclude: printf("dontinclude"); break;
170         case DocInclude::HtmlInclude: printf("htmlinclude"); break;
171         case DocInclude::LatexInclude: printf("latexinclude"); break;
172         case DocInclude::VerbInclude: printf("verbinclude"); break;
173         case DocInclude::Snippet: printf("snippet"); break;
174         case DocInclude::SnipWithLines: printf("snipwithlines"); break;
175         case DocInclude::SnippetDoc: 
176         case DocInclude::IncludeDoc: 
177           err("Internal inconsistency: found switch SnippetDoc / IncludeDoc in file: %s"
178               "Please create a bug report\n",__FILE__);
179           break;
180       }
181       printf("\"/>");
182     }
183     void visit(DocIncOperator *op)
184     {
185       indent_leaf();
186       printf("<incoperator pattern=\"%s\" type=\"",op->pattern().data());
187       switch(op->type())
188       {
189         case DocIncOperator::Line:     printf("line");     break;
190         case DocIncOperator::Skip:     printf("skip");     break;
191         case DocIncOperator::SkipLine: printf("skipline"); break;
192         case DocIncOperator::Until:    printf("until");    break;
193       }
194       printf("\"/>");
195     }
196     void visit(DocFormula *f)
197     {
198       indent_leaf();
199       printf("<formula name=%s text=%s/>",f->name().data(),f->text().data());
200     }
201     void visit(DocIndexEntry *i)
202     {
203       indent_leaf();
204       printf("<indexentry>%s</indexentry\n",i->entry().data());
205     }
206     void visit(DocSimpleSectSep *)
207     {
208       indent_leaf();
209       printf("<simplesectsep/>");
210     }
211     void visit(DocCite *cite)
212     {
213       indent_leaf();
214       printf("<cite ref=\"%s\" file=\"%s\" "
215              "anchor=\"%s\" text=\"%s\""
216              "/>\n",
217              cite->ref().data(),cite->file().data(),cite->anchor().data(),
218              cite->text().data());
219     }
220
221     //--------------------------------------
222     
223     void visitPre(DocAutoList *l)
224     {
225       indent_pre();
226       if (l->isEnumList())
227       {
228         printf("<ol>\n");
229       }
230       else
231       {
232         printf("<ul>\n");
233       }
234     }
235     void visitPost(DocAutoList *l)
236     {
237       indent_post();
238       if (l->isEnumList())
239       {
240         printf("</ol>\n");
241       }
242       else
243       {
244         printf("</ul>\n");
245       }
246     }
247     void visitPre(DocAutoListItem *)
248     {
249       indent_pre();
250       printf("<li>\n");
251     }
252     void visitPost(DocAutoListItem *) 
253     {
254       indent_post();
255       printf("</li>\n");
256     }
257     void visitPre(DocPara *) 
258     {
259       indent_pre();
260       printf("<para>\n");
261     }
262     void visitPost(DocPara *)
263     {
264       indent_post();
265       printf("</para>\n");
266     }
267     void visitPre(DocRoot *)
268     {
269       indent_pre();
270       printf("<root>\n");
271     }
272     void visitPost(DocRoot *)
273     {
274       indent_post();
275       printf("</root>\n");
276     }
277     void visitPre(DocSimpleSect *s)
278     {
279       indent_pre();
280       printf("<simplesect type=");
281       switch(s->type())
282       {
283         case DocSimpleSect::See: printf("see"); break;
284         case DocSimpleSect::Return: printf("return"); break;
285         case DocSimpleSect::Author: printf("author"); break;
286         case DocSimpleSect::Authors: printf("authors"); break;
287         case DocSimpleSect::Version: printf("version"); break;
288         case DocSimpleSect::Since: printf("since"); break;
289         case DocSimpleSect::Date: printf("date"); break;
290         case DocSimpleSect::Note: printf("note"); break;
291         case DocSimpleSect::Warning: printf("warning"); break;
292         case DocSimpleSect::Pre: printf("pre"); break;
293         case DocSimpleSect::Post: printf("post"); break;
294         case DocSimpleSect::Copyright: printf("copyright"); break;
295         case DocSimpleSect::Invar: printf("invar"); break;
296         case DocSimpleSect::Remark: printf("remark"); break;
297         case DocSimpleSect::Attention: printf("attention"); break;
298         case DocSimpleSect::User: printf("user"); break;
299         case DocSimpleSect::Rcs: printf("rcs"); break;
300         case DocSimpleSect::Unknown: printf("unknown"); break;
301       }
302       printf(">\n");
303     }
304     void visitPost(DocSimpleSect *)
305     {
306       indent_post();
307       printf("</simplesect>\n");
308     }
309     void visitPre(DocTitle *)
310     {
311       indent_pre();
312       printf("<title>\n");
313     }
314     void visitPost(DocTitle *)
315     {
316       indent_post();
317       printf("</title>\n");
318     }
319     void visitPre(DocSimpleList *)
320     {
321       indent_pre();
322       printf("<ul>\n");
323     }
324     void visitPost(DocSimpleList *)
325     {
326       indent_post();
327       printf("</ul>\n");
328     }
329     void visitPre(DocSimpleListItem *)
330     {
331       indent_pre();
332       printf("<li>\n");
333     }
334     void visitPost(DocSimpleListItem *) 
335     {
336       indent_post();
337       printf("</li>\n");
338     }
339     void visitPre(DocSection *s)
340     {
341       indent_pre();
342       printf("<sect%d>\n",s->level());
343     }
344     void visitPost(DocSection *s) 
345     {
346       indent_post();
347       printf("</sect%d>\n",s->level());
348     }
349     void visitPre(DocHtmlList *s)
350     {
351       indent_pre();
352       if (s->type()==DocHtmlList::Ordered) printf("<ol>\n"); else printf("<ul>\n");
353     }
354     void visitPost(DocHtmlList *s) 
355     {
356       indent_post();
357       if (s->type()==DocHtmlList::Ordered) printf("</ol>\n"); else printf("</ul>\n");
358     }
359     void visitPre(DocHtmlListItem *)
360     {
361       indent_pre();
362       printf("<li>\n");
363     }
364     void visitPost(DocHtmlListItem *) 
365     {
366       indent_post();
367       printf("</li>\n");
368     }
369     //void visitPre(DocHtmlPre *)
370     //{
371     //  indent_pre();
372     //  printf("<pre>\n");
373     //  m_insidePre=TRUE;
374     //}
375     //void visitPost(DocHtmlPre *) 
376     //{
377     //  m_insidePre=FALSE;
378     //  indent_post();
379     //  printf("</pre>\n");
380     //}
381     void visitPre(DocHtmlDescList *)
382     {
383       indent_pre();
384       printf("<dl>\n");
385     }
386     void visitPost(DocHtmlDescList *) 
387     {
388       indent_post();
389       printf("</dl>\n");
390     }
391     void visitPre(DocHtmlDescTitle *)
392     {
393       indent_pre();
394       printf("<dt>\n");
395     }
396     void visitPost(DocHtmlDescTitle *) 
397     {
398       indent_post();
399       printf("</dt>\n");
400     }
401     void visitPre(DocHtmlDescData *)
402     {
403       indent_pre();
404       printf("<dd>\n");
405     }
406     void visitPost(DocHtmlDescData *) 
407     {
408       indent_post();
409       printf("</dd>\n");
410     }
411     void visitPre(DocHtmlTable *t)
412     {
413       indent_pre();
414       printf("<table rows=\"%d\" cols=\"%d\">\n",
415           t->numRows(),t->numColumns());
416     }
417     void visitPost(DocHtmlTable *) 
418     {
419       indent_post();
420       printf("</table>\n");
421     }
422     void visitPre(DocHtmlRow *)
423     {
424       indent_pre();
425       printf("<tr>\n");
426     }
427     void visitPost(DocHtmlRow *) 
428     {
429       indent_post();
430       printf("</tr>\n");
431     }
432     void visitPre(DocHtmlCell *c)
433     {
434       indent_pre();
435       printf("<t%c>\n",c->isHeading()?'h':'d');
436     }
437     void visitPost(DocHtmlCell *c) 
438     {
439       indent_post();
440       printf("</t%c>\n",c->isHeading()?'h':'d');
441     }
442     void visitPre(DocHtmlCaption *)
443     {
444       indent_pre();
445       printf("<caption>\n");
446     }
447     void visitPost(DocHtmlCaption *) 
448     {
449       indent_post();
450       printf("</caption>\n");
451     }
452     void visitPre(DocInternal *)
453     {
454       indent_pre();
455       printf("<internal>\n");
456     }
457     void visitPost(DocInternal *) 
458     {
459       indent_post();
460       printf("</internal>\n");
461     }
462     void visitPre(DocHRef *href)
463     {
464       indent_pre();
465       printf("<a url=\"%s\">\n",href->url().data());
466     }
467     void visitPost(DocHRef *) 
468     {
469       indent_post();
470       printf("</a>\n");
471     }
472     void visitPre(DocHtmlHeader *header)
473     {
474       indent_pre();
475       printf("<h%d>\n",header->level());
476     }
477     void visitPost(DocHtmlHeader *header) 
478     {
479       indent_post();
480       printf("</h%d>\n",header->level());
481     }
482     void visitPre(DocImage *img)
483     {
484       indent_pre();
485       printf("<image src=\"%s\" type=\"",img->name().data());
486       switch(img->type())
487       {
488         case DocImage::Html:    printf("html"); break;
489         case DocImage::Latex:   printf("latex"); break;
490         case DocImage::Rtf:     printf("rtf"); break;
491         case DocImage::DocBook: printf("docbook"); break;
492       }
493       printf("\" %s %s>\n",img->width().data(),img->height().data());
494     }
495     void visitPost(DocImage *) 
496     {
497       indent_post();
498       printf("</image>\n");
499     }
500     void visitPre(DocDotFile *df)
501     {
502       indent_pre();
503       printf("<dotfile src=\"%s\">\n",df->name().data());
504     }
505     void visitPost(DocDotFile *) 
506     {
507       indent_post();
508       printf("</dotfile>\n");
509     }
510     void visitPre(DocMscFile *df)
511     {
512       indent_pre();
513       printf("<mscfile src=\"%s\">\n",df->name().data());
514     }
515     void visitPost(DocMscFile *) 
516     {
517       indent_post();
518       printf("</mscfile>\n");
519     }
520     void visitPre(DocDiaFile *df)
521     {
522       indent_pre();
523       printf("<diafile src=\"%s\">\n",df->name().data());
524     }
525     void visitPost(DocDiaFile *)
526     {
527       indent_post();
528       printf("</diafile>\n");
529     }
530     void visitPre(DocLink *lnk)
531     {
532       indent_pre();
533       printf("<link ref=\"%s\" file=\"%s\" anchor=\"%s\">\n",
534           lnk->ref().data(),lnk->file().data(),lnk->anchor().data());
535     }
536     void visitPost(DocLink *) 
537     {
538       indent_post();
539       printf("</link>\n");
540     }
541     void visitPre(DocRef *ref)
542     {
543       indent_pre();
544       printf("<ref ref=\"%s\" file=\"%s\" "
545              "anchor=\"%s\" targetTitle=\"%s\""
546              " hasLinkText=\"%s\" refToAnchor=\"%s\" refToSection=\"%s\" refToTable=\"%s\">\n",
547              ref->ref().data(),ref->file().data(),ref->anchor().data(),
548              ref->targetTitle().data(),ref->hasLinkText()?"yes":"no",
549              ref->refToAnchor()?"yes":"no", ref->refToSection()?"yes":"no",
550              ref->refToTable()?"yes":"no");
551     }
552     void visitPost(DocRef *) 
553     {
554       indent_post();
555       printf("</ref>\n");
556     }
557     void visitPre(DocSecRefItem *ref)
558     {
559       indent_pre();
560       printf("<secrefitem target=\"%s\">\n",ref->target().data());
561     }
562     void visitPost(DocSecRefItem *) 
563     {
564       indent_post();
565       printf("</secrefitem>\n");
566     }
567     void visitPre(DocSecRefList *)
568     {
569       indent_pre();
570       printf("<secreflist>\n");
571     }
572     void visitPost(DocSecRefList *) 
573     {
574       indent_post();
575       printf("</secreflist>\n");
576     }
577     //void visitPre(DocLanguage *l)
578     //{
579     //  indent_pre();
580     //  printf("<language id=%s>\n",l->id().data());
581     //}
582     //void visitPost(DocLanguage *) 
583     //{
584     //  indent_post();
585     //  printf("</language>\n");
586     //}
587     void visitPre(DocParamList *pl)
588     {
589       indent_pre();
590       //QStrListIterator sli(pl->parameters());
591       QListIterator<DocNode> sli(pl->parameters());
592       //const char *s;
593       DocNode *param;
594       printf("<parameters>");
595       for (sli.toFirst();(param=sli.current());++sli)
596       {
597         printf("<param>");
598         if (param->kind()==DocNode::Kind_Word)
599         {
600           visit((DocWord*)param); 
601         }
602         else if (param->kind()==DocNode::Kind_LinkedWord)
603         {
604           visit((DocLinkedWord*)param); 
605         }
606         printf("</param>");
607       }
608       printf("\n");
609     }
610     void visitPost(DocParamList *)
611     {
612       indent_post();
613       printf("</parameters>\n");
614     }
615     void visitPre(DocParamSect *ps)
616     {
617       indent_pre();
618       printf("<paramsect type=");
619       switch (ps->type())
620       {
621         case DocParamSect::Param: printf("param"); break;
622         case DocParamSect::RetVal: printf("retval"); break;
623         case DocParamSect::Exception: printf("exception"); break;
624         case DocParamSect::TemplateParam: printf("templateparam"); break;
625         case DocParamSect::Unknown: printf("unknown"); break;
626       }
627       printf(">\n");
628     }
629     void visitPost(DocParamSect *)
630     {
631       indent_post();
632       printf("</paramsect>\n");
633     }
634     void visitPre(DocXRefItem *x)
635     {
636       indent_pre();
637       printf("<xrefitem file=\"%s\" anchor=\"%s\" title=\"%s\"/>\n",
638           x->file().data(),x->anchor().data(),x->title().data());
639     }
640     void visitPost(DocXRefItem *)
641     {
642       indent_post();
643       printf("<xrefitem/>\n");
644     }
645     void visitPre(DocInternalRef *r)
646     {
647       indent_pre();
648       printf("<internalref file=%s anchor=%s>\n",r->file().data(),r->anchor().data());
649     }
650     void visitPost(DocInternalRef *)
651     {
652       indent_post();
653       printf("</internalref>\n");
654     }
655     void visitPre(DocCopy *c)
656     {
657       indent_pre();
658       printf("<copy link=\"%s\">\n",c->link().data());
659     }
660     void visitPost(DocCopy *)
661     {
662       indent_post();
663       printf("</copy>\n");
664     }
665     void visitPre(DocText *)
666     {
667       indent_pre();
668       printf("<text>\n");
669     }
670     void visitPost(DocText *)
671     {
672       indent_post();
673       printf("</text>\n");
674     }
675     void visitPre(DocHtmlBlockQuote *)
676     {
677       indent_pre();
678       printf("<blockquote>\n");
679     }
680     void visitPost(DocHtmlBlockQuote *)
681     {
682       indent_post();
683       printf("</blockquote>\n");
684     }
685     void visitPre(DocVhdlFlow *)
686     {
687       indent_pre();
688       printf("<vhdlflow>\n");
689     }
690     void visitPost(DocVhdlFlow *)
691     {
692       indent_post();
693       printf("</vhdlflow>\n");
694     }
695     void visitPre(DocParBlock *)
696     {
697       indent_pre();
698       printf("<parblock>\n");
699     }
700     void visitPost(DocParBlock *)
701     {
702       indent_post();
703       printf("</parblock>\n");
704     }
705
706   private:
707     // helper functions
708     void indent() 
709     { 
710       if (m_needsEnter) printf("\n");
711       for (int i=0;i<m_indent;i++) printf("."); 
712       m_needsEnter=FALSE;
713     } 
714     void indent_leaf()
715     {
716       if (!m_needsEnter) indent();
717       m_needsEnter=TRUE;
718     }
719     void indent_pre()
720     {
721       indent();
722       m_indent++;
723     }
724     void indent_post()
725     {
726       m_indent--;
727       indent();
728     }
729     
730     // member variables
731     int m_indent;
732     bool m_needsEnter;
733     bool m_insidePre;
734 };
735
736 #endif