Chameleon

Chameleon Svn Source Tree

Root/branches/xZenu/src/util/doxygen/src/mangen.cpp

Source at commit 1322 created 9 years 5 months ago.
By meklort, Add doxygen to utils folder
1/******************************************************************************
2 *
3 * $Id: htmlgen.cpp,v 1.17 1998/11/28 11:33:19 root Exp $
4 *
5 * Copyright (C) 1997-2011 by Dimitri van Heesch.
6 *
7 * Permission to use, copy, modify, and distribute this software and its
8 * documentation under the terms of the GNU General Public License is hereby
9 * granted. No representations are made about the suitability of this software
10 * for any purpose. It is provided "as is" without express or implied warranty.
11 * See the GNU General Public License for more details.
12 *
13 * Documents produced by Doxygen are derivative works derived from the
14 * input used in their production; they are not affected by this license.
15 *
16 */
17
18/* http://www.cubic.org/source/archive/fileform/txt/man/ has some
19 nice introductions to groff and man pages. */
20
21#include <stdlib.h>
22
23#include "qtbc.h"
24#include <qdir.h>
25#include "message.h"
26#include "mangen.h"
27#include "config.h"
28#include "util.h"
29#include "doxygen.h"
30#include <string.h>
31#include "docparser.h"
32#include "mandocvisitor.h"
33
34static QCString getExtension()
35{
36 QCString ext = Config_getString("MAN_EXTENSION");
37 if( ext.length() >= 2 &&
38 ext.data()[0] == '.')
39 {
40 ext = ext.mid(1, ext.length()-1);
41 }
42 else
43 {
44 ext = "3";
45 }
46 return ext;
47}
48
49ManGenerator::ManGenerator() : OutputGenerator()
50{
51 dir=Config_getString("MAN_OUTPUT")+"/man" + getExtension();
52 firstCol=TRUE;
53 paragraph=FALSE;
54 col=0;
55 upperCase=FALSE;
56 insideTabbing=FALSE;
57 inHeader=FALSE;
58}
59
60ManGenerator::~ManGenerator()
61{
62}
63
64//void ManGenerator::append(const OutputGenerator *g)
65//{
66// QCString r=g->getContents();
67// if (upperCase)
68// t << r.upper();
69// else
70// t << r;
71// if (!r.isEmpty())
72// firstCol = r.at(r.length()-1)=='\n';
73// else
74// firstCol = ((ManGenerator *)g)->firstCol;
75// col+=((ManGenerator *)g)->col;
76// inHeader=((ManGenerator *)g)->inHeader;
77// paragraph=FALSE;
78//}
79
80void ManGenerator::init()
81{
82 QCString ext = getExtension();
83 QCString &manOutput = Config_getString("MAN_OUTPUT");
84
85 QDir d(manOutput);
86 if (!d.exists() && !d.mkdir(manOutput))
87 {
88 err("Could not create output directory %s\n",manOutput.data());
89 exit(1);
90 }
91 d.setPath(manOutput+"/man"+ext);
92 if (!d.exists() && !d.mkdir(manOutput+"/man"+ext))
93 {
94 err("Could not create output directory %s/man%s\n",manOutput.data(),ext.data());
95 exit(1);
96 }
97 createSubDirs(d);
98}
99
100static QCString buildFileName(const char *name)
101{
102 QCString fileName;
103 if (name==0) return "noname";
104
105 const char *p=name;
106 char c;
107 while ((c=*p++))
108 {
109 switch (c)
110 {
111 case ':':
112 fileName+="_";
113 if (*p==':') p++;
114 break;
115 case '<':
116 case '>':
117 case '&':
118 case '*':
119 case '!':
120 case '^':
121 case '~':
122 case '%':
123 case '+':
124 case '/':
125 fileName+="_";
126 break;
127 default:
128 fileName+=c;
129 }
130 }
131
132 QCString &manExtension = Config_getString("MAN_EXTENSION");
133 if (convertToQCString(fileName.right(2))!=manExtension)
134 {
135 fileName+=manExtension;
136 }
137
138 return fileName;
139}
140
141void ManGenerator::startFile(const char *,const char *manName,const char *)
142{
143 startPlainFile( buildFileName( manName ) );
144 firstCol=TRUE;
145}
146
147void ManGenerator::endFile()
148{
149 t << endl;
150 endPlainFile();
151}
152
153void ManGenerator::endTitleHead(const char *,const char *name)
154{
155 t << ".TH \"" << name << "\" " << getExtension() << " \""
156 << dateToString(FALSE) << "\" \"";
157 if (!Config_getString("PROJECT_NUMBER").isEmpty())
158 t << "Version " << Config_getString("PROJECT_NUMBER") << "\" \"";
159 if (Config_getString("PROJECT_NAME").isEmpty())
160 t << "Doxygen";
161 else
162 t << Config_getString("PROJECT_NAME");
163 t << "\" \\\" -*- nroff -*-" << endl;
164 t << ".ad l" << endl;
165 t << ".nh" << endl;
166 t << ".SH NAME" << endl;
167 t << name << " \\- ";
168 firstCol=FALSE;
169 inHeader=TRUE;
170}
171
172void ManGenerator::newParagraph()
173{
174 if (!paragraph)
175 {
176 if (!firstCol) t << endl;
177 t << ".PP" << endl;
178 firstCol=TRUE;
179 }
180 paragraph=TRUE;
181}
182
183void ManGenerator::startParagraph()
184{
185 if (!paragraph)
186 {
187 if (!firstCol) t << endl;
188 t << ".PP" << endl;
189 firstCol=TRUE;
190 }
191 paragraph=TRUE;
192}
193
194void ManGenerator::endParagraph()
195{
196}
197
198void ManGenerator::writeString(const char *text)
199{
200 docify(text);
201}
202
203void ManGenerator::startIndexItem(const char *,const char *)
204{
205}
206
207void ManGenerator::endIndexItem(const char *,const char *)
208{
209}
210
211void ManGenerator::writeStartAnnoItem(const char *,const char *,
212 const char *,const char *)
213{
214}
215
216void ManGenerator::writeObjectLink(const char *,const char *,
217 const char *, const char *name)
218{
219 startBold(); docify(name); endBold();
220}
221
222void ManGenerator::writeCodeLink(const char *,const char *,
223 const char *, const char *name,
224 const char *)
225{
226 docify(name);
227}
228
229void ManGenerator::startHtmlLink(const char *)
230{
231}
232
233void ManGenerator::endHtmlLink()
234{
235}
236
237//void ManGenerator::writeMailLink(const char *url)
238//{
239// docify(url);
240//}
241
242void ManGenerator::startGroupHeader(int)
243{
244 if (!firstCol) t << endl;
245 t << ".SH \"";
246 upperCase=TRUE;
247 firstCol=FALSE;
248}
249
250void ManGenerator::endGroupHeader(int)
251{
252 t << "\"\n.PP " << endl;
253 firstCol=TRUE;
254 paragraph=TRUE;
255 upperCase=FALSE;
256}
257
258void ManGenerator::startMemberHeader(const char *)
259{
260 if (!firstCol) t << endl;
261 t << ".SS \"";
262}
263
264void ManGenerator::endMemberHeader()
265{
266 t << "\"\n";
267 firstCol=TRUE;
268 paragraph=FALSE;
269}
270
271void ManGenerator::docify(const char *str)
272{
273 if (str)
274 {
275 const char *p=str;
276 char c=0;
277 while ((c=*p++))
278 {
279 switch(c)
280 {
281 case '\\': t << "\\\\"; col++; break;
282 case '\n': t << "\n"; col=0; break;
283 case '\"': c = '\''; // no break!
284 default: t << c; col++; break;
285 }
286 }
287 firstCol=(c=='\n');
288 //printf("%s",str);fflush(stdout);
289 }
290 paragraph=FALSE;
291}
292
293void ManGenerator::codify(const char *str)
294{
295 //static char spaces[]=" ";
296 if (str)
297 {
298 const char *p=str;
299 char c;
300 int spacesToNextTabStop;
301 while (*p)
302 {
303 c=*p++;
304 switch(c)
305 {
306 case '\t': spacesToNextTabStop =
307 Config_getInt("TAB_SIZE") - (col%Config_getInt("TAB_SIZE"));
308 t << Doxygen::spaces.left(spacesToNextTabStop);
309 col+=spacesToNextTabStop;
310 break;
311 case '\n': t << "\n"; firstCol=TRUE; col=0; break;
312 case '\\': t << "\\"; col++; break;
313 case '\"': c = '\''; // no break!
314 default: t << c; firstCol=FALSE; col++; break;
315 }
316 }
317 //printf("%s",str);fflush(stdout);
318 }
319 paragraph=FALSE;
320}
321
322void ManGenerator::writeChar(char c)
323{
324 firstCol=(c=='\n');
325 if (firstCol) col=0; else col++;
326 switch (c)
327 {
328 case '\\': t << "\\\\"; break;
329 case '\"': c = '\''; // no break!
330 default: t << c; break;
331 }
332 //printf("%c",c);fflush(stdout);
333 paragraph=FALSE;
334}
335
336void ManGenerator::startDescList(SectionTypes)
337{
338 if (!firstCol)
339 { t << endl << ".PP" << endl;
340 firstCol=TRUE; paragraph=TRUE;
341 col=0;
342 }
343 paragraph=FALSE;
344 startBold();
345}
346
347void ManGenerator::startTitle()
348{
349 if (!firstCol) t << endl;
350 t << ".SH \"";
351 firstCol=FALSE;
352 paragraph=FALSE;
353}
354
355void ManGenerator::endTitle()
356{
357 t << "\"";
358}
359
360void ManGenerator::startItemListItem()
361{
362 if (!firstCol) t << endl;
363 t << ".TP" << endl;
364 firstCol=TRUE;
365 paragraph=FALSE;
366 col=0;
367}
368
369void ManGenerator::endItemListItem()
370{
371}
372
373void ManGenerator::startCodeFragment()
374{
375 newParagraph();
376 t << ".nf" << endl;
377 firstCol=TRUE;
378 paragraph=FALSE;
379}
380
381void ManGenerator::endCodeFragment()
382{
383 if (!firstCol) t << endl;
384 t << ".fi" << endl;
385 firstCol=TRUE;
386 paragraph=FALSE;
387 col=0;
388}
389
390void ManGenerator::startMemberDoc(const char *,const char *,const char *,const char *,bool)
391{
392 if (!firstCol) t << endl;
393 t << ".SS \"";
394 firstCol=FALSE;
395 paragraph=FALSE;
396}
397
398void ManGenerator::startDoxyAnchor(const char *,const char *manName,
399 const char *, const char *name,
400 const char *)
401{
402 // something to be done?
403 if( !Config_getBool("MAN_LINKS") )
404 {
405return; // no
406 }
407
408 // the name of the link file is derived from the name of the anchor:
409 // - truncate after an (optional) ::
410 QCString baseName = name;
411 int i=baseName.findRev("::");
412 if (i!=-1) baseName=baseName.right(baseName.length()-i-2);
413
414 //printf("Converting man link '%s'->'%s'->'%s'\n",
415 // name,baseName.data(),buildFileName(baseName).data());
416
417 // - remove dangerous characters and append suffix, then add dir prefix
418 QCString fileName=dir+"/"+buildFileName( baseName );
419 QFile linkfile( fileName );
420 // - only create file if it doesn't exist already
421 if ( !linkfile.open( IO_ReadOnly ) )
422 {
423if ( linkfile.open( IO_WriteOnly ) )
424 {
425 FTextStream linkstream;
426 linkstream.setDevice(&linkfile);
427 //linkstream.setEncoding(QTextStream::UnicodeUTF8);
428 linkstream << ".so man" << getExtension() << "/" << buildFileName( manName ) << endl;
429}
430 }
431 linkfile.close();
432}
433
434void ManGenerator::endMemberDoc(bool)
435{
436 t << "\"";
437}
438
439void ManGenerator::startSubsection()
440{
441 if (!firstCol) t << endl;
442 t << ".SS \"";
443 firstCol=FALSE;
444 paragraph=FALSE;
445}
446
447void ManGenerator::endSubsection()
448{
449 t << "\"";
450}
451
452
453void ManGenerator::startSubsubsection()
454{
455 if (!firstCol) t << endl;
456 t << "\n.SS \"";
457 firstCol=FALSE;
458 paragraph=FALSE;
459}
460
461void ManGenerator::endSubsubsection()
462{
463 t << "\"";
464}
465
466void ManGenerator::writeSynopsis()
467{
468 if (!firstCol) t << endl;
469 t << ".SH SYNOPSIS\n.br\n.PP\n";
470 firstCol=TRUE;
471 paragraph=FALSE;
472}
473
474void ManGenerator::startDescItem()
475{
476 if (!firstCol) t << endl;
477 t << ".IP \"";
478 firstCol=FALSE;
479}
480
481//void ManGenerator::endDescTitle()
482//{
483// endBold();
484// paragraph=TRUE;
485//}
486
487void ManGenerator::startDescForItem()
488{
489 if (!firstCol) t << endl;
490 if (!paragraph) t << ".in -1c" << endl;
491 t << ".in +1c" << endl;
492 firstCol=TRUE;
493 paragraph=FALSE;
494 col=0;
495}
496
497void ManGenerator::endDescForItem()
498{
499}
500
501void ManGenerator::endDescItem()
502{
503 t << "\" 1c" << endl;
504 firstCol=TRUE;
505}
506
507void ManGenerator::startAnonTypeScope(int indentLevel)
508{
509 if (indentLevel==0)
510 {
511 insideTabbing=TRUE;
512 }
513}
514
515void ManGenerator::endAnonTypeScope(int indentLevel)
516{
517 if (indentLevel==0)
518 {
519 insideTabbing=FALSE;
520 }
521}
522
523
524void ManGenerator::startMemberItem(int)
525{
526 if (firstCol && !insideTabbing) t << ".in +1c\n";
527 t << "\n.ti -1c\n.RI \"";
528 firstCol=FALSE;
529}
530
531void ManGenerator::endMemberItem()
532{
533 t << "\"\n.br";
534}
535
536void ManGenerator::startMemberList()
537{
538 if (!insideTabbing)
539 {
540 t << "\n.in +1c"; firstCol=FALSE;
541 }
542}
543
544void ManGenerator::endMemberList()
545{
546 if (!insideTabbing)
547 {
548 t << "\n.in -1c"; firstCol=FALSE;
549 }
550}
551
552void ManGenerator::startMemberGroupHeader(bool)
553{
554 t << "\n.PP\n.RI \"\\fB";
555}
556
557void ManGenerator::endMemberGroupHeader()
558{
559 t << "\\fP\"\n.br\n";
560 firstCol=TRUE;
561}
562
563void ManGenerator::startMemberGroupDocs()
564{
565}
566
567void ManGenerator::endMemberGroupDocs()
568{
569 t << "\n.PP";
570}
571
572void ManGenerator::startMemberGroup()
573{
574 t << "\n.in +1c";
575}
576
577void ManGenerator::endMemberGroup(bool)
578{
579 t << "\n.in -1c";
580 firstCol=FALSE;
581}
582
583void ManGenerator::startSection(const char *,const char *,SectionInfo::SectionType type)
584{
585 if( !inHeader )
586 {
587 switch(type)
588 {
589 case SectionInfo::Page: startGroupHeader(FALSE); break;
590 case SectionInfo::Section: startGroupHeader(FALSE); break;
591 case SectionInfo::Subsection: startMemberHeader(0); break;
592 case SectionInfo::Subsubsection: startMemberHeader(0); break;
593 case SectionInfo::Paragraph: startMemberHeader(0); break;
594 default: ASSERT(0); break;
595 }
596 }
597}
598
599void ManGenerator::endSection(const char *,SectionInfo::SectionType type)
600{
601 if( !inHeader )
602 {
603 switch(type)
604 {
605 case SectionInfo::Page: endGroupHeader(0); break;
606 case SectionInfo::Section: endGroupHeader(0); break;
607 case SectionInfo::Subsection: endMemberHeader(); break;
608 case SectionInfo::Subsubsection: endMemberHeader(); break;
609 case SectionInfo::Paragraph: endMemberHeader(); break;
610 default: ASSERT(0); break;
611 }
612 }
613 else
614 {
615 t << "\n";
616 firstCol=TRUE;
617 paragraph=FALSE;
618 inHeader=FALSE;
619 }
620}
621
622void ManGenerator::startSimpleSect(SectionTypes,const char *,
623 const char *,const char *title)
624{
625 if (!firstCol)
626 { t << endl << ".PP" << endl;
627 firstCol=TRUE; paragraph=TRUE;
628 col=0;
629 }
630 paragraph=FALSE;
631 startBold();
632 docify(title);
633 endBold();
634 paragraph=TRUE;
635}
636
637void ManGenerator::endSimpleSect()
638{
639}
640
641void ManGenerator::startParamList(ParamListTypes,const char *title)
642{
643 if (!firstCol)
644 { t << endl << ".PP" << endl;
645 firstCol=TRUE; paragraph=TRUE;
646 col=0;
647 }
648 paragraph=FALSE;
649 startBold();
650 docify(title);
651 endBold();
652 paragraph=TRUE;
653}
654
655void ManGenerator::endParamList()
656{
657}
658
659void ManGenerator::printDoc(DocNode *n,const char *langExt)
660{
661 ManDocVisitor *visitor = new ManDocVisitor(t,*this,langExt);
662 n->accept(visitor);
663 delete visitor;
664 firstCol=FALSE;
665 paragraph = FALSE;
666}
667
668void ManGenerator::startConstraintList(const char *header)
669{
670 if (!firstCol)
671 { t << endl << ".PP" << endl;
672 firstCol=TRUE; paragraph=TRUE;
673 col=0;
674 }
675 paragraph=FALSE;
676 startBold();
677 docify(header);
678 endBold();
679 paragraph=TRUE;
680}
681
682void ManGenerator::startConstraintParam()
683{
684 startItemListItem();
685 startEmphasis();
686}
687
688void ManGenerator::endConstraintParam()
689{
690 endEmphasis();
691 endItemListItem();
692 t << " : ";
693}
694
695void ManGenerator::startConstraintType()
696{
697 startEmphasis();
698}
699
700void ManGenerator::endConstraintType()
701{
702 endEmphasis();
703}
704
705void ManGenerator::startConstraintDocs()
706{
707}
708
709void ManGenerator::endConstraintDocs()
710{
711 t << endl; firstCol=TRUE;
712}
713
714void ManGenerator::endConstraintList()
715{
716}
717
718void ManGenerator::startInlineDescription()
719{
720}
721
722void ManGenerator::endInlineDescription()
723{
724}
725
726void ManGenerator::startInlineHeader()
727{
728 if (!firstCol)
729 {
730 t << endl << ".PP" << endl << ".in -1c" << endl;
731 }
732 t << ".RI \"\\fB";
733}
734
735void ManGenerator::endInlineHeader()
736{
737 t << "\\fP\"" << endl << ".in +1c" << endl;
738 firstCol = FALSE;
739}
740
741
742
743

Archive Download this file

Revision: 1322