mandocvisitor.cpp 21.6 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
 *
 * 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.
 *
 */

19 20
#include <qfileinfo.h> 

21 22 23 24 25 26 27 28 29
#include "mandocvisitor.h"
#include "docparser.h"
#include "language.h"
#include "doxygen.h"
#include "outputgen.h"
#include "code.h"
#include "dot.h"
#include "util.h"
#include "message.h"
30
#include "parserintf.h"
31
#include "filedef.h"
32
#include "htmlentity.h"
33

34
ManDocVisitor::ManDocVisitor(FTextStream &t,CodeOutputInterface &ci,
35
                             const char *langExt) 
36
  : DocVisitor(DocVisitor_Man), m_t(t), m_ci(ci), m_insidePre(FALSE), m_hide(FALSE), m_firstCol(FALSE),
37
    m_indent(0), m_langExt(langExt)
38 39 40 41 42 43 44 45 46 47 48
{
}

  //--------------------------------------
  // visitor functions for leaf nodes
  //--------------------------------------

void ManDocVisitor::visit(DocWord *w)
{
  if (m_hide) return;
  filter(w->word());
49
  m_firstCol=FALSE;
50 51 52 53 54 55 56 57
}

void ManDocVisitor::visit(DocLinkedWord *w)
{
  if (m_hide) return;
  m_t << "\\fB";
  filter(w->word());
  m_t << "\\fP";
58
  m_firstCol=FALSE;
59 60 61 62 63 64 65 66
}

void ManDocVisitor::visit(DocWhiteSpace *w)
{
  if (m_hide) return;
  if (m_insidePre)
  {
    m_t << w->chars();
67
    m_firstCol=w->chars().at(w->chars().length()-1)=='\n';
68 69 70 71
  }
  else
  {
    m_t << " ";
72
    m_firstCol=FALSE;
73 74 75 76 77 78
  }
}

void ManDocVisitor::visit(DocSymbol *s)
{
  if (m_hide) return;
79
  const char *res = HtmlEntityMapper::instance()->man(s->symbol());
80
  if (res)
81
  {
82 83 84 85 86 87
    m_t << res;
  }
  else
  {
    // no error or warning to be supplied
    // err("man: non supported HTML-entity found: &%s;\n",get_symbol_item(s->symbol()));
88
  }
89
  m_firstCol=FALSE;
90 91 92 93 94
}

void ManDocVisitor::visit(DocURL *u)
{
  if (m_hide) return;
95 96
  m_t << u->url();
  m_firstCol=FALSE;
97 98 99 100 101
}

void ManDocVisitor::visit(DocLineBreak *)
{
  if (m_hide) return;
102 103
  m_t << endl << ".br" << endl;
  m_firstCol=TRUE;
104 105 106 107 108
}

void ManDocVisitor::visit(DocHorRuler *)
{
  if (m_hide) return;
109 110 111
  if (!m_firstCol) m_t << endl;
  m_t << ".PP" << endl;
  m_firstCol=TRUE;
112 113 114 115 116 117 118 119
}

void ManDocVisitor::visit(DocStyleChange *s)
{
  if (m_hide) return;
  switch (s->style())
  {
    case DocStyleChange::Bold:
120 121
      if (s->enable()) m_t << "\\fB";      else m_t << "\\fP";
      m_firstCol=FALSE;
122 123
      break;
    case DocStyleChange::Italic:
124 125
      if (s->enable()) m_t << "\\fI";     else m_t << "\\fP";
      m_firstCol=FALSE;
126 127
      break;
    case DocStyleChange::Code:
128 129
      if (s->enable()) m_t << "\\fC";   else m_t << "\\fP";
      m_firstCol=FALSE;
130 131
      break;
    case DocStyleChange::Subscript:
132 133
      if (s->enable()) m_t << "\\*<";    else m_t << "\\*> ";
      m_firstCol=FALSE;
134 135
      break;
    case DocStyleChange::Superscript:
136 137
      if (s->enable()) m_t << "\\*{";    else m_t << "\\*} ";
      m_firstCol=FALSE;
138 139
      break;
    case DocStyleChange::Center:
140
      /* not supported */
141 142
      break;
    case DocStyleChange::Small:
143
      /* not supported */
144
      break;
145 146 147 148 149 150 151 152 153 154 155 156
    case DocStyleChange::Preformatted:
      if (s->enable())
      {
        if (!m_firstCol) m_t << endl;
        m_t << ".PP" << endl;
        m_t << ".nf" << endl;
        m_insidePre=TRUE;
      }
      else
      {
        m_insidePre=FALSE;
        if (!m_firstCol) m_t << endl;
157
        m_t << ".fi" << endl;
158 159 160
        m_t << ".PP" << endl;
        m_firstCol=TRUE;
      }
161 162 163
      break;
    case DocStyleChange::Div:  /* HTML only */ break;
    case DocStyleChange::Span: /* HTML only */ break;
164 165 166 167 168 169
  }
}

void ManDocVisitor::visit(DocVerbatim *s)
{
  if (m_hide) return;
170 171 172 173 174 175
  QCString lang = m_langExt;
  if (!s->language().isEmpty()) // explicit language setting
  {
    lang = s->language();
  }
  SrcLangExt langExt = getLanguageFromFileName(lang);
176
  switch (s->type())
177 178
  {
    case DocVerbatim::Code: // fall though
179 180 181
      if (!m_firstCol) m_t << endl;
      m_t << ".PP" << endl;
      m_t << ".nf" << endl;
182
      Doxygen::parserManager->getParser(lang)
183
                            ->parseCode(m_ci,s->context(),s->text(),
184
                                        langExt,
185
                                        s->isExample(),s->exampleFile());
186
      if (!m_firstCol) m_t << endl;
187
      m_t << ".fi" << endl;
188 189
      m_t << ".PP" << endl;
      m_firstCol=TRUE;
190 191
      break;
    case DocVerbatim::Verbatim: 
192 193 194
      if (!m_firstCol) m_t << endl;
      m_t << ".PP" << endl;
      m_t << ".nf" << endl;
195
      m_t << s->text();
196
      if (!m_firstCol) m_t << endl;
197
      m_t << ".fi" << endl;
198 199
      m_t << ".PP" << endl;
      m_firstCol=TRUE;
200
      break;
201 202 203
    case DocVerbatim::ManOnly: 
      m_t << s->text(); 
      break;
204
    case DocVerbatim::HtmlOnly: 
205
    case DocVerbatim::XmlOnly: 
206
    case DocVerbatim::LatexOnly: 
207 208
    case DocVerbatim::RtfOnly:
    case DocVerbatim::DocbookOnly:
209
    case DocVerbatim::Dot: 
210
    case DocVerbatim::Msc: 
211 212 213 214 215
      /* nothing */ 
      break;
  }
}

216
void ManDocVisitor::visit(DocAnchor *)
217
{
218
  /* no support for anchors in man pages */
219 220 221 222 223
}

void ManDocVisitor::visit(DocInclude *inc)
{
  if (m_hide) return;
224
  SrcLangExt langExt = getLanguageFromFileName(inc->extension());
225 226
  switch(inc->type())
  {
227 228 229 230 231 232
    case DocInclude::IncWithLines:
      { 
         if (!m_firstCol) m_t << endl;
         m_t << ".PP" << endl;
         m_t << ".nf" << endl;
         QFileInfo cfi( inc->file() );
233
         FileDef fd( cfi.dirPath().utf8(), cfi.fileName().utf8() );
234
         Doxygen::parserManager->getParser(inc->extension())
235
                               ->parseCode(m_ci,inc->context(),
236
                                           inc->text(),
237
                                           langExt,
238 239
                                           inc->isExample(),
                                           inc->exampleFile(), &fd);
240
         if (!m_firstCol) m_t << endl;
241
         m_t << ".fi" << endl;
242 243 244 245
         m_t << ".PP" << endl;
         m_firstCol=TRUE;
      }
      break;
246
    case DocInclude::Include: 
247 248 249
      if (!m_firstCol) m_t << endl;
      m_t << ".PP" << endl;
      m_t << ".nf" << endl;
250
      Doxygen::parserManager->getParser(inc->extension())
251
                            ->parseCode(m_ci,inc->context(),
252 253 254
                                        inc->text(),
                                        langExt,
                                        inc->isExample(),
255
                                        inc->exampleFile());
256
      if (!m_firstCol) m_t << endl;
257
      m_t << ".fi" << endl;
258 259
      m_t << ".PP" << endl;
      m_firstCol=TRUE;
260 261 262 263 264
      break;
    case DocInclude::DontInclude: 
      break;
    case DocInclude::HtmlInclude: 
      break;
265 266
    case DocInclude::LatexInclude:
      break;
267
    case DocInclude::VerbInclude: 
268 269 270
      if (!m_firstCol) m_t << endl;
      m_t << ".PP" << endl;
      m_t << ".nf" << endl;
271
      m_t << inc->text();
272
      if (!m_firstCol) m_t << endl;
273
      m_t << ".fi" << endl;
274 275
      m_t << ".PP" << endl;
      m_firstCol=TRUE;
276
      break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
277 278 279 280 281 282 283 284
    case DocInclude::Snippet:
      if (!m_firstCol) m_t << endl;
      m_t << ".PP" << endl;
      m_t << ".nf" << endl;
      Doxygen::parserManager->getParser(inc->extension())
                            ->parseCode(m_ci,
                                        inc->context(),
                                        extractBlock(inc->text(),inc->blockId()),
285
                                        langExt,
Dimitri van Heesch's avatar
Dimitri van Heesch committed
286 287 288 289 290 291 292 293
                                        inc->isExample(),
                                        inc->exampleFile()
                                       );
      if (!m_firstCol) m_t << endl;
      m_t << ".fi" << endl;
      m_t << ".PP" << endl;
      m_firstCol=TRUE;
      break;
294 295 296 297 298
  }
}

void ManDocVisitor::visit(DocIncOperator *op)
{
299
  SrcLangExt langExt = getLanguageFromFileName(m_langExt);
300 301 302 303
  //printf("DocIncOperator: type=%d first=%d, last=%d text=`%s'\n",
  //    op->type(),op->isFirst(),op->isLast(),op->text().data());
  if (op->isFirst()) 
  {
304 305 306 307 308 309 310
    if (!m_hide)
    {
      if (!m_firstCol) m_t << endl;
      m_t << ".PP" << endl;
      m_t << ".nf" << endl;
    }
    pushEnabled();
311 312 313 314
    m_hide = TRUE;
  }
  if (op->type()!=DocIncOperator::Skip) 
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
315
    popEnabled();
316 317
    if (!m_hide) 
    {
318 319
      Doxygen::parserManager->getParser(m_langExt)
                            ->parseCode(m_ci,op->context(),op->text(),langExt,
320 321
                                        op->isExample(),op->exampleFile());
    }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
322 323
    pushEnabled();
    m_hide=TRUE;
324 325 326
  }
  if (op->isLast())  
  {
327 328 329 330
    popEnabled();
    if (!m_hide)
    {
      if (!m_firstCol) m_t << endl;
331
      m_t << ".fi" << endl;
332 333 334
      m_t << ".PP" << endl;
      m_firstCol=TRUE;
    }
335 336 337
  }
  else
  {
338
    if (!m_hide) m_t << endl;
339 340 341 342 343 344 345 346 347
  }
}

void ManDocVisitor::visit(DocFormula *f)
{
  if (m_hide) return;
  m_t << f->text();
}

348
void ManDocVisitor::visit(DocIndexEntry *)
349 350 351
{
}

352 353 354 355
void ManDocVisitor::visit(DocSimpleSectSep *)
{
}

356 357 358 359 360 361 362 363 364 365 366
void ManDocVisitor::visit(DocCite *cite)
{
  if (m_hide) return;
  m_t << "\\fB";
  if (cite->file().isEmpty()) m_t << "[";
  filter(cite->text());
  if (cite->file().isEmpty()) m_t << "]";
  m_t << "\\fP";
}


367 368 369 370
//--------------------------------------
// visitor functions for compound nodes
//--------------------------------------

371
void ManDocVisitor::visitPre(DocAutoList *)
372
{
373
  if (m_hide) return;
374 375 376 377 378
  m_indent+=2;
}

void ManDocVisitor::visitPost(DocAutoList *)
{
379
  if (m_hide) return;
380 381
  m_indent-=2;
  m_t << ".PP" << endl;
382 383
}

384
void ManDocVisitor::visitPre(DocAutoListItem *li)
385
{
386
  if (m_hide) return;
387 388 389 390 391
  QCString ws;
  ws.fill(' ',m_indent-2);
  if (!m_firstCol) m_t << endl;
  m_t << ".IP \"" << ws; 
  if (((DocAutoList *)li->parent())->isEnumList())
392
  {
393
    m_t << li->itemNumber() << ".\" " << m_indent+2;
394
  }
395
  else // bullet list
396
  {
397
    m_t << "\\(bu\" " << m_indent;
398
  }
399 400
  m_t << endl;
  m_firstCol=TRUE;
401 402 403 404
}

void ManDocVisitor::visitPost(DocAutoListItem *) 
{
405
  if (m_hide) return;
406 407
  m_t << endl;
  m_firstCol=TRUE;
408 409 410 411 412 413 414 415
}

void ManDocVisitor::visitPre(DocPara *) 
{
}

void ManDocVisitor::visitPost(DocPara *p)
{
416
  if (m_hide) return;
417 418 419 420
  if (!p->isLast() &&            // omit <p> for last paragraph
      !(p->parent() &&           // and for parameter sections
        p->parent()->kind()==DocNode::Kind_ParamSect
       )
421 422 423 424 425 426
     ) 
  {
    if (!m_firstCol) m_t << endl;
    m_t << ".PP" << endl;
    m_firstCol=TRUE;
  }
427 428 429 430 431 432 433 434 435 436 437 438
}

void ManDocVisitor::visitPre(DocRoot *)
{
}

void ManDocVisitor::visitPost(DocRoot *)
{
}

void ManDocVisitor::visitPre(DocSimpleSect *s)
{
439
  if (m_hide) return;
440 441 442 443 444 445
  if (!m_firstCol)
  { 
    m_t << endl;
    m_t << ".PP" << endl;
  }
  m_t << "\\fB";
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
  switch(s->type())
  {
    case DocSimpleSect::See: 
      m_t << theTranslator->trSeeAlso(); break;
    case DocSimpleSect::Return: 
      m_t << theTranslator->trReturns(); break;
    case DocSimpleSect::Author: 
      m_t << theTranslator->trAuthor(TRUE,TRUE); break;
    case DocSimpleSect::Authors: 
      m_t << theTranslator->trAuthor(TRUE,FALSE); break;
    case DocSimpleSect::Version: 
      m_t << theTranslator->trVersion(); break;
    case DocSimpleSect::Since: 
      m_t << theTranslator->trSince(); break;
    case DocSimpleSect::Date: 
      m_t << theTranslator->trDate(); break;
    case DocSimpleSect::Note: 
      m_t << theTranslator->trNote(); break;
    case DocSimpleSect::Warning:
      m_t << theTranslator->trWarning(); break;
    case DocSimpleSect::Pre:
      m_t << theTranslator->trPrecondition(); break;
    case DocSimpleSect::Post:
      m_t << theTranslator->trPostcondition(); break;
470
    case DocSimpleSect::Copyright:
471
      m_t << theTranslator->trCopyright(); break;
472 473 474 475 476 477 478
    case DocSimpleSect::Invar:
      m_t << theTranslator->trInvariant(); break;
    case DocSimpleSect::Remark:
      m_t << theTranslator->trRemarks(); break;
    case DocSimpleSect::Attention:
      m_t << theTranslator->trAttention(); break;
    case DocSimpleSect::User: break;
479
    case DocSimpleSect::Rcs: break;
480 481 482 483
    case DocSimpleSect::Unknown:  break;
  }

  // special case 1: user defined title
484
  if (s->type()!=DocSimpleSect::User && s->type()!=DocSimpleSect::Rcs)
485
  {
486 487
    m_t << ":\\fP" << endl;
    m_t << ".RS 4" << endl;
488 489 490 491 492
  }
}

void ManDocVisitor::visitPost(DocSimpleSect *)
{
493
  if (m_hide) return;
494 495 496 497
  if (!m_firstCol) m_t << endl;
  m_t << ".RE" << endl;
  m_t << ".PP" << endl;
  m_firstCol=TRUE;
498 499 500 501 502 503 504 505
}

void ManDocVisitor::visitPre(DocTitle *)
{
}

void ManDocVisitor::visitPost(DocTitle *)
{
506
  if (m_hide) return;
507
  m_t << "\\fP" << endl;
508
  m_t << ".RS 4" << endl;
509 510 511 512
}

void ManDocVisitor::visitPre(DocSimpleList *)
{
513
  if (m_hide) return;
514
  m_indent+=2;
515
  if (!m_firstCol) m_t << endl;
516
  m_t << ".PD 0" << endl;
517 518 519 520
}

void ManDocVisitor::visitPost(DocSimpleList *)
{
521
  if (m_hide) return;
522 523
  m_indent-=2;
  m_t << ".PP" << endl;
524 525 526 527
}

void ManDocVisitor::visitPre(DocSimpleListItem *)
{
528
  if (m_hide) return;
529 530 531 532 533
  QCString ws;
  ws.fill(' ',m_indent-2);
  if (!m_firstCol) m_t << endl;
  m_t << ".IP \"" << ws << "\\(bu\" " << m_indent << endl;
  m_firstCol=TRUE;
534 535 536 537
}

void ManDocVisitor::visitPost(DocSimpleListItem *) 
{
538
  if (m_hide) return;
539 540
  m_t << endl;
  m_firstCol=TRUE;
541 542 543 544
}

void ManDocVisitor::visitPre(DocSection *s)
{
545
  if (m_hide) return;
546 547 548
  if (!m_firstCol) m_t << endl;
  if (s->level()==1) m_t << ".SH"; else m_t << ".SS";
  m_t << " \"";
549
  filter(s->title());
550 551 552
  m_t << "\"" << endl;
  if (s->level()==1) m_t << ".PP" << endl;
  m_firstCol=TRUE;
553 554 555 556 557 558
}

void ManDocVisitor::visitPost(DocSection *) 
{
}

559
void ManDocVisitor::visitPre(DocHtmlList *)
560
{
561
  if (m_hide) return;
562
  m_indent+=2;
563
  if (!m_firstCol) m_t << endl;
564
  m_t << ".PD 0" << endl;
565 566
}

567
void ManDocVisitor::visitPost(DocHtmlList *) 
568
{
569
  if (m_hide) return;
570
  m_indent-=2;
571
  if (!m_firstCol) m_t << endl;
572
  m_t << ".PP" << endl;
573 574
}

575
void ManDocVisitor::visitPre(DocHtmlListItem *li)
576
{
577
  if (m_hide) return;
578 579 580 581 582 583 584 585 586 587 588 589 590 591
  QCString ws;
  ws.fill(' ',m_indent-2);
  if (!m_firstCol) m_t << endl;
  m_t << ".IP \"" << ws; 
  if (((DocHtmlList *)li->parent())->type()==DocHtmlList::Ordered)
  {
    m_t << li->itemNumber() << ".\" " << m_indent+2;
  }
  else // bullet list
  {
    m_t << "\\(bu\" " << m_indent;
  }
  m_t << endl;
  m_firstCol=TRUE;
592 593 594 595
}

void ManDocVisitor::visitPost(DocHtmlListItem *) 
{
596
  if (m_hide) return;
597 598
  m_t << endl;
  m_firstCol=TRUE;
599 600
}

601 602 603 604 605 606 607 608 609 610 611 612
//void ManDocVisitor::visitPre(DocHtmlPre *)
//{
//  if (!m_firstCol) m_t << endl;
//  m_t << ".PP" << endl;
//  m_t << ".nf" << endl;
//  m_insidePre=TRUE;
//}
//
//void ManDocVisitor::visitPost(DocHtmlPre *) 
//{
//  m_insidePre=FALSE;
//  if (!m_firstCol) m_t << endl;
613
//  m_t << ".fi" << endl;
614 615 616
//  m_t << ".PP" << endl;
//  m_firstCol=TRUE;
//}
617 618 619 620 621 622 623

void ManDocVisitor::visitPre(DocHtmlDescList *)
{
}

void ManDocVisitor::visitPost(DocHtmlDescList *) 
{
624
  if (m_hide) return;
625 626 627
  if (!m_firstCol) m_t << endl;
  m_t << ".PP" << endl;
  m_firstCol=TRUE;
628 629 630 631
}

void ManDocVisitor::visitPre(DocHtmlDescTitle *)
{
632
  if (m_hide) return;
633 634 635
  if (!m_firstCol) m_t << endl;
  m_t << ".IP \"\\fB";
  m_firstCol=FALSE;
636 637 638 639
}

void ManDocVisitor::visitPost(DocHtmlDescTitle *) 
{
640
  if (m_hide) return;
641 642
  m_t << "\\fP\" 1c" << endl;
  m_firstCol=TRUE;
643 644 645 646 647 648 649 650 651 652
}

void ManDocVisitor::visitPre(DocHtmlDescData *)
{
}

void ManDocVisitor::visitPost(DocHtmlDescData *) 
{
}

653
void ManDocVisitor::visitPre(DocHtmlTable *)
654 655 656
{
}

657
void ManDocVisitor::visitPost(DocHtmlTable *) 
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680
{
}

void ManDocVisitor::visitPre(DocHtmlCaption *)
{
}

void ManDocVisitor::visitPost(DocHtmlCaption *) 
{
}

void ManDocVisitor::visitPre(DocHtmlRow *)
{
}

void ManDocVisitor::visitPost(DocHtmlRow *) 
{
}

void ManDocVisitor::visitPre(DocHtmlCell *)
{
}

681
void ManDocVisitor::visitPost(DocHtmlCell *) 
682 683 684 685 686
{
}

void ManDocVisitor::visitPre(DocInternal *)
{
687
  if (m_hide) return;
688 689 690 691
  //if (!m_firstCol) m_t << endl;
  //m_t << ".PP" << endl;
  //m_t << "\\fB" << theTranslator->trForInternalUseOnly() << "\\fP" << endl;
  //m_t << ".RS 4" << endl;
692 693 694 695
}

void ManDocVisitor::visitPost(DocInternal *) 
{
696
  if (m_hide) return;
697 698 699 700
  //if (!m_firstCol) m_t << endl;
  //m_t << ".RE" << endl;
  //m_t << ".PP" << endl;
  //m_firstCol=TRUE;
701 702
}

703
void ManDocVisitor::visitPre(DocHRef *)
704
{
705
  if (m_hide) return;
706
  m_t << "\\fC";
707 708 709 710
}

void ManDocVisitor::visitPost(DocHRef *) 
{
711
  if (m_hide) return;
712
  m_t << "\\fP";
713 714 715 716
}

void ManDocVisitor::visitPre(DocHtmlHeader *header)
{
717
  if (m_hide) return;
718 719 720
  if (!m_firstCol) m_t << endl;
  if (header->level()==1) m_t << ".SH"; else m_t << ".SS";
  m_t << " \"";
721 722
}

723
void ManDocVisitor::visitPost(DocHtmlHeader *header) 
724
{
725
  if (m_hide) return;
726 727 728
  m_t << "\"" << endl;
  if (header->level()==1) m_t << ".PP" << endl;
  m_firstCol=TRUE;
729 730
}

731
void ManDocVisitor::visitPre(DocImage *)
732 733 734
{
}

735
void ManDocVisitor::visitPost(DocImage *) 
736 737 738
{
}

739
void ManDocVisitor::visitPre(DocDotFile *)
740 741 742
{
}

743
void ManDocVisitor::visitPost(DocDotFile *) 
744 745
{
}
746 747 748 749 750 751 752 753
void ManDocVisitor::visitPre(DocMscFile *)
{
}

void ManDocVisitor::visitPost(DocMscFile *) 
{
}

754 755 756 757 758 759 760
void ManDocVisitor::visitPre(DocDiaFile *)
{
}

void ManDocVisitor::visitPost(DocDiaFile *)
{
}
761 762 763

void ManDocVisitor::visitPre(DocLink *)
{
764
  if (m_hide) return;
765
  m_t << "\\fB";
766 767 768 769
}

void ManDocVisitor::visitPost(DocLink *) 
{
770
  if (m_hide) return;
771
  m_t << "\\fP";
772 773 774 775
}

void ManDocVisitor::visitPre(DocRef *ref)
{
776
  if (m_hide) return;
777
  m_t << "\\fB";
778 779 780 781 782
  if (!ref->hasLinkText()) filter(ref->targetTitle());
}

void ManDocVisitor::visitPost(DocRef *) 
{
783
  if (m_hide) return;
784
  m_t << "\\fP";
785 786 787 788
}

void ManDocVisitor::visitPre(DocSecRefItem *)
{
789
  if (m_hide) return;
790 791 792 793 794
  QCString ws;
  ws.fill(' ',m_indent-2);
  if (!m_firstCol) m_t << endl;
  m_t << ".IP \"" << ws << "\\(bu\" " << m_indent << endl;
  m_firstCol=TRUE;
795 796
}

797
void ManDocVisitor::visitPost(DocSecRefItem *) 
798
{
799
  if (m_hide) return;
800 801
  m_t << endl;
  m_firstCol=TRUE;
802 803 804 805
}

void ManDocVisitor::visitPre(DocSecRefList *)
{
806
  if (m_hide) return;
807
  m_indent+=2;
808 809 810 811
}

void ManDocVisitor::visitPost(DocSecRefList *) 
{
812
  if (m_hide) return;
813
  m_indent-=2;
814
  if (!m_firstCol) m_t << endl;
815
  m_t << ".PP" << endl;
816 817
}

818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835
//void ManDocVisitor::visitPre(DocLanguage *l)
//{
//  QString langId = Config_getEnum("OUTPUT_LANGUAGE");
//  if (l->id().lower()!=langId.lower())
//  {
//    pushEnabled();
//    m_hide = TRUE;
//  }
//}
//
//void ManDocVisitor::visitPost(DocLanguage *l) 
//{
//  QString langId = Config_getEnum("OUTPUT_LANGUAGE");
//  if (l->id().lower()!=langId.lower())
//  {
//    popEnabled();
//  }
//}
836 837 838

void ManDocVisitor::visitPre(DocParamSect *s)
{
839
  if (m_hide) return;
840 841 842 843 844 845
  if (!m_firstCol)
  { 
    m_t << endl;
    m_t << ".PP" << endl;
  }
  m_t << "\\fB";
846 847 848 849 850 851 852 853
  switch(s->type())
  {
    case DocParamSect::Param: 
      m_t << theTranslator->trParameters(); break;
    case DocParamSect::RetVal: 
      m_t << theTranslator->trReturnValues(); break;
    case DocParamSect::Exception: 
      m_t << theTranslator->trExceptions(); break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
854 855 856 857 858
    case DocParamSect::TemplateParam: 
      /* TODO: add this 
      m_t << theTranslator->trTemplateParam(); break;
      */
      m_t << "Template Parameters"; break;
859 860 861
    default:
      ASSERT(0);
  }
862 863
  m_t << ":\\fP" << endl;
  m_t << ".RS 4" << endl;
864 865 866 867
}

void ManDocVisitor::visitPost(DocParamSect *)
{
868
  if (m_hide) return;
869 870 871 872
  if (!m_firstCol) m_t << endl;
  m_t << ".RE" << endl;
  m_t << ".PP" << endl;
  m_firstCol=TRUE;
873 874 875 876
}

void ManDocVisitor::visitPre(DocParamList *pl)
{
877
  if (m_hide) return;
878
  m_t << "\\fI";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
879 880 881 882
  //QStrListIterator li(pl->parameters());
  //const char *s;
  QListIterator<DocNode> li(pl->parameters());
  DocNode *param;
883
  bool first=TRUE;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
884
  for (li.toFirst();(param=li.current());++li)
885 886
  {
    if (!first) m_t << ","; else first=FALSE;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
887 888 889 890 891 892 893 894
    if (param->kind()==DocNode::Kind_Word)
    {
      visit((DocWord*)param); 
    }
    else if (param->kind()==DocNode::Kind_LinkedWord)
    {
      visit((DocLinkedWord*)param); 
    }
895
  }
896
  m_t << "\\fP ";
897 898
}

899
void ManDocVisitor::visitPost(DocParamList *pl)
900
{
901
  if (m_hide) return;
902 903 904 905 906
  if (!pl->isLast())
  {
    if (!m_firstCol) m_t << endl;
    m_t << ".br" << endl;
  }
907 908 909 910
}

void ManDocVisitor::visitPre(DocXRefItem *x)
{
911
  if (m_hide) return;
912
  if (x->title().isEmpty()) return;
913 914 915 916
  if (!m_firstCol)
  { 
    m_t << endl;
    m_t << ".PP" << endl;
917
  }
918
  m_t << "\\fB";
919
  filter(x->title());
920 921
  m_t << "\\fP" << endl;
  m_t << ".RS 4" << endl;
922 923
}

924
void ManDocVisitor::visitPost(DocXRefItem *x)
925
{
926
  if (m_hide) return;
927
  if (x->title().isEmpty()) return;
928 929 930 931
  if (!m_firstCol) m_t << endl;
  m_t << ".RE" << endl;
  m_t << ".PP" << endl;
  m_firstCol=TRUE;
932 933 934 935
}

void ManDocVisitor::visitPre(DocInternalRef *)
{
936
  if (m_hide) return;
937
  m_t << "\\fB";
938 939 940 941
}

void ManDocVisitor::visitPost(DocInternalRef *) 
{
942
  if (m_hide) return;
943
  m_t << "\\fP";
944 945 946 947 948 949 950 951 952 953
}

void ManDocVisitor::visitPre(DocCopy *)
{
}

void ManDocVisitor::visitPost(DocCopy *)
{
}

954 955 956 957 958 959 960 961
void ManDocVisitor::visitPre(DocText *)
{
}

void ManDocVisitor::visitPost(DocText *)
{
}

962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981
void ManDocVisitor::visitPre(DocHtmlBlockQuote *)
{
  if (m_hide) return;
  if (!m_firstCol)
  { 
    m_t << endl;
    m_t << ".PP" << endl;
  }
  m_t << ".RS 4" << endl; // TODO: add support for nested block quotes
}

void ManDocVisitor::visitPost(DocHtmlBlockQuote *)
{
  if (m_hide) return;
  if (!m_firstCol) m_t << endl;
  m_t << ".RE" << endl;
  m_t << ".PP" << endl;
  m_firstCol=TRUE;
}

982 983 984 985 986 987 988 989
void ManDocVisitor::visitPre(DocVhdlFlow *)
{
}

void ManDocVisitor::visitPost(DocVhdlFlow *)
{
}

990 991 992 993 994 995 996 997
void ManDocVisitor::visitPre(DocParBlock *)
{
}

void ManDocVisitor::visitPost(DocParBlock *)
{
}

998

999 1000 1001 1002 1003 1004 1005 1006 1007 1008
void ManDocVisitor::filter(const char *str)
{ 
  if (str)
  {
    const char *p=str;
    char c=0;
    while ((c=*p++)) 
    {
      switch(c)
      {
1009
        case '.':  m_t << "\\&."; break; // see  bug652277
1010 1011 1012 1013 1014 1015 1016 1017
        case '\\': m_t << "\\\\"; break;
        case '"':  c = '\''; // fall through
        default: m_t << c; break;
      }
    }
  }
}

1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
void ManDocVisitor::pushEnabled()
{
  m_enabled.push(new bool(m_hide));
}

void ManDocVisitor::popEnabled()
{
  bool *v=m_enabled.pop();
  ASSERT(v!=0);
  m_hide = *v;
  delete v;
}