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