xmldocvisitor.cpp 28.4 KB
Newer Older
1 2
/******************************************************************************
 *
3
 * 
4 5
 *
 *
Dimitri van Heesch's avatar
Dimitri van Heesch committed
6
 * Copyright (C) 1997-2013 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
#include "xmldocvisitor.h"
#include "docparser.h"
#include "language.h"
#include "doxygen.h"
#include "outputgen.h"
#include "xmlgen.h"
#include "dot.h"
#include "message.h"
29
#include "util.h"
30
#include "parserintf.h"
31 32
#include "filename.h"
#include "config.h"
33

34
XmlDocVisitor::XmlDocVisitor(FTextStream &t,CodeOutputInterface &ci) 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
35
  : DocVisitor(DocVisitor_XML), m_t(t), m_ci(ci), m_insidePre(FALSE), m_hide(FALSE) 
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
{
}

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

void XmlDocVisitor::visit(DocWord *w)
{
  if (m_hide) return;
  filter(w->word());
}

void XmlDocVisitor::visit(DocLinkedWord *w)
{
  if (m_hide) return;
  startLink(w->ref(),w->file(),w->anchor());
  filter(w->word());
  endLink();
}

void XmlDocVisitor::visit(DocWhiteSpace *w)
{
  if (m_hide) return;
  if (m_insidePre)
  {
    m_t << w->chars();
  }
  else
  {
    m_t << " ";
  }
}

void XmlDocVisitor::visit(DocSymbol *s)
{
  if (m_hide) return;
  switch(s->symbol())
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    case DocSymbol::BSlash:        m_t << "\\"; break;
    case DocSymbol::At:            m_t << "@"; break;
    case DocSymbol::Less:          m_t << "&lt;"; break;
    case DocSymbol::Greater:       m_t << "&gt;"; break;
    case DocSymbol::Amp:           m_t << "&amp;"; break;
    case DocSymbol::Dollar:        m_t << "$"; break;
    case DocSymbol::Hash:          m_t << "#"; break;
    case DocSymbol::DoubleColon:   m_t << "::"; break;
    case DocSymbol::Percent:       m_t << "%"; break;
    case DocSymbol::Pipe:          m_t << "|"; break;
    case DocSymbol::Copy:          m_t << "<copy/>"; break;
    case DocSymbol::Tm:            m_t << "<trademark/>"; break;
    case DocSymbol::Reg:           m_t << "<registered/>"; break;
    case DocSymbol::Apos:          m_t << "'"; break;
    case DocSymbol::Quot:          m_t << "\""; break;
    case DocSymbol::Lsquo:         m_t << "<lsquo/>"; break;
    case DocSymbol::Rsquo:         m_t << "<rsquo/>"; break;
    case DocSymbol::Ldquo:         m_t << "<ldquo/>"; break;
    case DocSymbol::Rdquo:         m_t << "<rdquo/>"; break;
    case DocSymbol::Ndash:         m_t << "<ndash/>"; break;
    case DocSymbol::Mdash:         m_t << "<mdash/>"; break;
    case DocSymbol::Uml:           m_t << "<umlaut char=\"" << s->letter() << "\"/>"; break;
    case DocSymbol::Acute:         m_t << "<acute char=\"" << s->letter() << "\"/>"; break;
    case DocSymbol::Grave:         m_t << "<grave char=\"" << s->letter() << "\"/>"; break;
    case DocSymbol::Circ:          m_t << "<circ char=\"" << s->letter() << "\"/>"; break;
    case DocSymbol::Tilde:         m_t << "<tilde char=\"" << s->letter() << "\"/>"; break;
    case DocSymbol::Szlig:         m_t << "<szlig/>"; break;
    case DocSymbol::Cedil:         m_t << "<cedil char=\"" << s->letter() << "\"/>"; break;
    case DocSymbol::Ring:          m_t << "<ring char=\"" << s->letter() << "\"/>"; break;
    case DocSymbol::Slash:         m_t << "<slash char=\"" << s->letter() << "\"/>"; break;
    case DocSymbol::Nbsp:          m_t << "<nonbreakablespace/>"; break;
    case DocSymbol::Aelig:         m_t << "<aelig/>"; break;
    case DocSymbol::AElig:         m_t << "<AElig/>"; break;
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
    case DocSymbol::GrkGamma:      m_t << "<Gamma/>"; break;
    case DocSymbol::GrkDelta:      m_t << "<Delta/>"; break;
    case DocSymbol::GrkTheta:      m_t << "<Theta/>"; break;
    case DocSymbol::GrkLambda:     m_t << "<Lambda/>"; break;
    case DocSymbol::GrkXi:         m_t << "<Xi/>"; break;
    case DocSymbol::GrkPi:         m_t << "<Pi/>"; break;
    case DocSymbol::GrkSigma:      m_t << "<Sigma/>"; break;
    case DocSymbol::GrkUpsilon:    m_t << "<Upsilon/>"; break;
    case DocSymbol::GrkPhi:        m_t << "<Phi/>"; break;
    case DocSymbol::GrkPsi:        m_t << "<Psi/>"; break;
    case DocSymbol::GrkOmega:      m_t << "<Omega/>"; break;
    case DocSymbol::Grkalpha:      m_t << "<alpha/>"; break;
    case DocSymbol::Grkbeta:       m_t << "<beta/>"; break;
    case DocSymbol::Grkgamma:      m_t << "<gamma/>"; break;
    case DocSymbol::Grkdelta:      m_t << "<delta/>"; break;
    case DocSymbol::Grkepsilon:    m_t << "<epsilon/>"; break;
    case DocSymbol::Grkzeta:       m_t << "<zeta/>"; break;
    case DocSymbol::Grketa:        m_t << "<eta/>"; break;
    case DocSymbol::Grktheta:      m_t << "<theta/>"; break;
    case DocSymbol::Grkiota:       m_t << "<iota/>"; break;
    case DocSymbol::Grkkappa:      m_t << "<kappa/>"; break;
    case DocSymbol::Grklambda:     m_t << "<lambda/>"; break;
    case DocSymbol::Grkmu:         m_t << "<mu/>"; break;
    case DocSymbol::Grknu:         m_t << "<nu/>"; break;
    case DocSymbol::Grkxi:         m_t << "<xi/>"; break;
    case DocSymbol::Grkpi:         m_t << "<pi/>"; break;
    case DocSymbol::Grkrho:        m_t << "<rho/>"; break;
    case DocSymbol::Grksigma:      m_t << "<sigma/>"; break;
    case DocSymbol::Grktau:        m_t << "<tau/>"; break;
    case DocSymbol::Grkupsilon:    m_t << "<upsilon/>"; break;
    case DocSymbol::Grkphi:        m_t << "<phi/>"; break;
    case DocSymbol::Grkchi:        m_t << "<chi/>"; break;
    case DocSymbol::Grkpsi:        m_t << "<psi/>"; break;
    case DocSymbol::Grkomega:      m_t << "<omega/>"; break;
    case DocSymbol::Grkvarsigma:   m_t << "<sigmaf/>"; break;
    case DocSymbol::Section:       m_t << "<sect/>"; break;
    case DocSymbol::Degree:        m_t << "<deg/>"; break;
    case DocSymbol::Prime:         m_t << "<prime/>"; break;
    case DocSymbol::DoublePrime:   m_t << "<Prime/>"; break;
    case DocSymbol::Infinity:      m_t << "<infin/>"; break;
    case DocSymbol::EmptySet:      m_t << "<empty/>"; break;
    case DocSymbol::PlusMinus:     m_t << "<plusmn/>"; break;
    case DocSymbol::Times:         m_t << "<times/>"; break;
    case DocSymbol::Minus:         m_t << "<minus/>"; break;
    case DocSymbol::CenterDot:     m_t << "<sdot/>"; break;
    case DocSymbol::Partial:       m_t << "<part/>"; break;
    case DocSymbol::Nabla:         m_t << "<nabla/>"; break;
    case DocSymbol::SquareRoot:    m_t << "<radic/>"; break;
    case DocSymbol::Perpendicular: m_t << "<perp/>"; break;
    case DocSymbol::Sum:           m_t << "<sum/>"; break;
    case DocSymbol::Integral:      m_t << "<int/>"; break;
    case DocSymbol::Product:       m_t << "<prod/>"; break;
    case DocSymbol::Similar:       m_t << "<sim/>"; break;
    case DocSymbol::Approx:        m_t << "<asymp/>"; break;
    case DocSymbol::NotEqual:      m_t << "<ne/>"; break;
    case DocSymbol::Equivalent:    m_t << "<equiv/>"; break;
    case DocSymbol::Proportional:  m_t << "<prop/>"; break;
    case DocSymbol::LessEqual:     m_t << "<le/>"; break;
    case DocSymbol::GreaterEqual:  m_t << "<ge/>"; break;
    case DocSymbol::LeftArrow:     m_t << "<larr/>"; break;
    case DocSymbol::RightArrow:    m_t << "<rarr/>"; break;
    case DocSymbol::SetIn:         m_t << "<isin/>"; break;
    case DocSymbol::SetNotIn:      m_t << "<notin/>"; break;
    case DocSymbol::LeftCeil:      m_t << "<lceil/>"; break;
    case DocSymbol::RightCeil:     m_t << "<rceil/>"; break;
    case DocSymbol::LeftFloor:     m_t << "<lfloor/>"; break;
    case DocSymbol::RightFloor:    m_t << "<rfloor/>"; break;
175
    default:
176
                             err("unknown symbol found\n");
177 178 179 180 181 182
  }
}

void XmlDocVisitor::visit(DocURL *u)
{
  if (m_hide) return;
183 184
  m_t << "<ulink url=\""; 
  if (u->isEmail()) m_t << "mailto:";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
185 186
  filter(u->url());
  m_t << "\">";
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
  filter(u->url());
  m_t << "</ulink>";
}

void XmlDocVisitor::visit(DocLineBreak *)
{
  if (m_hide) return;
  m_t << "<linebreak/>\n";
}

void XmlDocVisitor::visit(DocHorRuler *)
{
  if (m_hide) return;
  m_t << "<hruler/>\n";
}

void XmlDocVisitor::visit(DocStyleChange *s)
{
  if (m_hide) return;
  switch (s->style())
  {
    case DocStyleChange::Bold:
Dimitri van Heesch's avatar
Dimitri van Heesch committed
209
      if (s->enable()) m_t << "<bold>";      else m_t << "</bold>";
210 211
      break;
    case DocStyleChange::Italic:
Dimitri van Heesch's avatar
Dimitri van Heesch committed
212
      if (s->enable()) m_t << "<emphasis>";     else m_t << "</emphasis>";
213 214
      break;
    case DocStyleChange::Code:
Dimitri van Heesch's avatar
Dimitri van Heesch committed
215
      if (s->enable()) m_t << "<computeroutput>";   else m_t << "</computeroutput>";
216 217
      break;
    case DocStyleChange::Subscript:
Dimitri van Heesch's avatar
Dimitri van Heesch committed
218
      if (s->enable()) m_t << "<subscript>";    else m_t << "</subscript>";
219 220
      break;
    case DocStyleChange::Superscript:
Dimitri van Heesch's avatar
Dimitri van Heesch committed
221
      if (s->enable()) m_t << "<superscript>";    else m_t << "</superscript>";
222 223
      break;
    case DocStyleChange::Center:
Dimitri van Heesch's avatar
Dimitri van Heesch committed
224
      if (s->enable()) m_t << "<center>"; else m_t << "</center>";
225 226
      break;
    case DocStyleChange::Small:
Dimitri van Heesch's avatar
Dimitri van Heesch committed
227
      if (s->enable()) m_t << "<small>";  else m_t << "</small>";
228
      break;
229 230 231 232 233 234 235 236
    case DocStyleChange::Preformatted:
      if (s->enable()) 
      {
        m_t << "<preformatted>";  
        m_insidePre=TRUE;
      }
      else 
      {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
237
        m_t << "</preformatted>";
238 239 240
        m_insidePre=FALSE;
      }
      break;
241 242
    case DocStyleChange::Div:  /* HTML only */ break;
    case DocStyleChange::Span: /* HTML only */ break;
243 244 245 246 247 248
  }
}

void XmlDocVisitor::visit(DocVerbatim *s)
{
  if (m_hide) return;
249 250 251 252 253 254
  QCString lang = m_langExt;
  if (!s->language().isEmpty()) // explicit language setting
  {
    lang = s->language();
  }
  SrcLangExt langExt = getLanguageFromFileName(lang);
255 256 257 258
  switch(s->type())
  {
    case DocVerbatim::Code: // fall though
      m_t << "<programlisting>"; 
259
      Doxygen::parserManager->getParser(lang)
260
                            ->parseCode(m_ci,s->context(),s->text(),langExt,
261
                                        s->isExample(),s->exampleFile());
262 263 264
      m_t << "</programlisting>"; 
      break;
    case DocVerbatim::Verbatim: 
265
      m_t << "<verbatim>";
266
      filter(s->text());
267
      m_t << "</verbatim>"; 
268 269 270 271 272 273
      break;
    case DocVerbatim::HtmlOnly: 
      m_t << "<htmlonly>";
      filter(s->text());
      m_t << "</htmlonly>";
      break;
274 275 276 277 278
    case DocVerbatim::RtfOnly: 
      m_t << "<rtfonly>";
      filter(s->text());
      m_t << "</rtfonly>";
      break;
279 280 281 282 283
    case DocVerbatim::ManOnly: 
      m_t << "<manonly>";
      filter(s->text());
      m_t << "</manonly>";
      break;
284 285 286 287 288
    case DocVerbatim::LatexOnly: 
      m_t << "<latexonly>";
      filter(s->text());
      m_t << "</latexonly>";
      break;
289 290 291
    case DocVerbatim::XmlOnly: 
      m_t << s->text();
      break;
292 293 294 295 296
    case DocVerbatim::DocbookOnly:
      m_t << "<docbookonly>";
      filter(s->text());
      m_t << "</docbookonly>";
      break;
297 298 299 300 301
    case DocVerbatim::Dot: 
      m_t << "<dot>";
      filter(s->text());
      m_t << "</dot>";
      break;
302 303 304 305 306
    case DocVerbatim::Msc: 
      m_t << "<msc>";
      filter(s->text());
      m_t << "</msc>";
      break;
307 308 309 310 311 312 313 314 315 316 317 318
  }
}

void XmlDocVisitor::visit(DocAnchor *anc)
{
  if (m_hide) return;
  m_t << "<anchor id=\"" << anc->file() << "_1" << anc->anchor() << "\"/>";
}

void XmlDocVisitor::visit(DocInclude *inc)
{
  if (m_hide) return;
319
  SrcLangExt langExt = getLanguageFromFileName(inc->extension());
320 321
  switch(inc->type())
  {
322 323 324 325
    case DocInclude::IncWithLines:
      { 
         m_t << "<programlisting>";
         QFileInfo cfi( inc->file() );
326
         FileDef fd( cfi.dirPath().utf8(), cfi.fileName().utf8() );
327
         Doxygen::parserManager->getParser(inc->extension())
328
                               ->parseCode(m_ci,inc->context(),
329
                                           inc->text(),
330
                                           langExt,
331 332
                                           inc->isExample(),
                                           inc->exampleFile(), &fd);
333 334 335
         m_t << "</programlisting>"; 
      }
      break;    
336 337
    case DocInclude::Include: 
      m_t << "<programlisting>";
338
      Doxygen::parserManager->getParser(inc->extension())
339
                            ->parseCode(m_ci,inc->context(),
340
                                        inc->text(),
341
                                        langExt,
342 343
                                        inc->isExample(),
                                        inc->exampleFile());
344 345 346 347 348 349 350 351 352 353
      m_t << "</programlisting>"; 
      break;
    case DocInclude::DontInclude: 
      break;
    case DocInclude::HtmlInclude: 
      m_t << "<htmlonly>";
      filter(inc->text());
      m_t << "</htmlonly>";
      break;
    case DocInclude::VerbInclude: 
354
      m_t << "<verbatim>";
355
      filter(inc->text());
356
      m_t << "</verbatim>"; 
357
      break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
358 359 360 361 362 363
    case DocInclude::Snippet:
      m_t << "<programlisting>";
      Doxygen::parserManager->getParser(inc->extension())
                            ->parseCode(m_ci,
                                        inc->context(),
                                        extractBlock(inc->text(),inc->blockId()),
364
                                        langExt,
Dimitri van Heesch's avatar
Dimitri van Heesch committed
365 366 367 368 369
                                        inc->isExample(),
                                        inc->exampleFile()
                                       );
      m_t << "</programlisting>"; 
      break;
370 371 372 373 374 375 376 377 378
  }
}

void XmlDocVisitor::visit(DocIncOperator *op)
{
  //printf("DocIncOperator: type=%d first=%d, last=%d text=`%s'\n",
  //    op->type(),op->isFirst(),op->isLast(),op->text().data());
  if (op->isFirst()) 
  {
379 380 381 382 383
    if (!m_hide)
    {
      m_t << "<programlisting>";
    }
    pushEnabled();
384 385
    m_hide = TRUE;
  }
386
  SrcLangExt langExt = getLanguageFromFileName(m_langExt);
387 388
  if (op->type()!=DocIncOperator::Skip) 
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
389
    popEnabled();
390 391 392 393
    if (!m_hide) 
    {
      Doxygen::parserManager->getParser(m_langExt)
                            ->parseCode(m_ci,op->context(),
394
                                        op->text(),langExt,op->isExample(),
395 396
                                        op->exampleFile());
    }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
397 398
    pushEnabled();
    m_hide=TRUE;
399 400 401
  }
  if (op->isLast())  
  {
402 403
    popEnabled();
    if (!m_hide) m_t << "</programlisting>"; 
404 405 406
  }
  else
  {
407
    if (!m_hide) m_t << endl;
408 409 410 411 412 413 414 415 416 417 418 419 420
  }
}

void XmlDocVisitor::visit(DocFormula *f)
{
  if (m_hide) return;
  m_t << "<formula id=\"" << f->id() << "\">";
  filter(f->text());
  m_t << "</formula>";
}

void XmlDocVisitor::visit(DocIndexEntry *ie)
{
421
  if (m_hide) return;
422 423 424 425 426 427 428 429
  m_t << "<indexentry>"
           "<primaryie>";
  filter(ie->entry());
  m_t << "</primaryie>"
           "<secondaryie></secondaryie>"
         "</indexentry>";
}

430 431 432 433 434
void XmlDocVisitor::visit(DocSimpleSectSep *)
{
  m_t << "<simplesectsep/>";
}

435 436 437 438 439 440 441 442
void XmlDocVisitor::visit(DocCite *cite)
{
  if (m_hide) return;
  if (!cite->file().isEmpty()) startLink(cite->ref(),cite->file(),cite->anchor());
  filter(cite->text());
  if (!cite->file().isEmpty()) endLink();
}

443 444 445 446 447 448
//--------------------------------------
// visitor functions for compound nodes
//--------------------------------------

void XmlDocVisitor::visitPre(DocAutoList *l)
{
449
  if (m_hide) return;
450 451 452 453 454 455 456 457 458 459 460 461
  if (l->isEnumList())
  {
    m_t << "<orderedlist>\n";
  }
  else
  {
    m_t << "<itemizedlist>\n";
  }
}

void XmlDocVisitor::visitPost(DocAutoList *l)
{
462
  if (m_hide) return;
463 464 465 466 467 468 469 470 471 472 473 474
  if (l->isEnumList())
  {
    m_t << "</orderedlist>\n";
  }
  else
  {
    m_t << "</itemizedlist>\n";
  }
}

void XmlDocVisitor::visitPre(DocAutoListItem *)
{
475
  if (m_hide) return;
476 477 478 479 480
  m_t << "<listitem>";
}

void XmlDocVisitor::visitPost(DocAutoListItem *) 
{
481
  if (m_hide) return;
482 483 484 485 486
  m_t << "</listitem>";
}

void XmlDocVisitor::visitPre(DocPara *) 
{
487
  if (m_hide) return;
488 489 490 491 492
  m_t << "<para>";
}

void XmlDocVisitor::visitPost(DocPara *)
{
493
  if (m_hide) return;
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
  m_t << "</para>";
}

void XmlDocVisitor::visitPre(DocRoot *)
{
  //m_t << "<hr><h4><font color=\"red\">New parser:</font></h4>\n";
}

void XmlDocVisitor::visitPost(DocRoot *)
{
  //m_t << "<hr><h4><font color=\"red\">Old parser:</font></h4>\n";
}

void XmlDocVisitor::visitPre(DocSimpleSect *s)
{
509
  if (m_hide) return;
510
  m_t << "<simplesect kind=\"";
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
  switch(s->type())
  {
    case DocSimpleSect::See: 
      m_t << "see"; break;
    case DocSimpleSect::Return: 
      m_t << "return"; break;
    case DocSimpleSect::Author: 
      m_t << "author"; break;
    case DocSimpleSect::Authors: 
      m_t << "authors"; break;
    case DocSimpleSect::Version: 
      m_t << "version"; break;
    case DocSimpleSect::Since: 
      m_t << "since"; break;
    case DocSimpleSect::Date: 
      m_t << "date"; break;
    case DocSimpleSect::Note: 
528
      m_t << "note"; break;
529 530 531 532 533 534
    case DocSimpleSect::Warning:
      m_t << "warning"; break;
    case DocSimpleSect::Pre:
      m_t << "pre"; break;
    case DocSimpleSect::Post:
      m_t << "post"; break;
535 536
    case DocSimpleSect::Copyright:
      m_t << "copyright"; break;
537 538 539 540 541 542 543 544
    case DocSimpleSect::Invar:
      m_t << "invariant"; break;
    case DocSimpleSect::Remark:
      m_t << "remark"; break;
    case DocSimpleSect::Attention:
      m_t << "attention"; break;
    case DocSimpleSect::User: 
      m_t << "par"; break;
545 546
    case DocSimpleSect::Rcs: 
      m_t << "rcs"; break;
547 548 549 550 551 552 553
    case DocSimpleSect::Unknown:  break;
  }
  m_t << "\">";
}

void XmlDocVisitor::visitPost(DocSimpleSect *)
{
554
  if (m_hide) return;
555 556 557 558 559
  m_t << "</simplesect>\n";
}

void XmlDocVisitor::visitPre(DocTitle *)
{
560
  if (m_hide) return;
561 562 563 564 565
  m_t << "<title>";
}

void XmlDocVisitor::visitPost(DocTitle *)
{
566
  if (m_hide) return;
567 568 569 570 571
  m_t << "</title>";
}

void XmlDocVisitor::visitPre(DocSimpleList *)
{
572
  if (m_hide) return;
573 574 575 576 577
  m_t << "<itemizedlist>\n";
}

void XmlDocVisitor::visitPost(DocSimpleList *)
{
578
  if (m_hide) return;
579 580 581 582 583
  m_t << "</itemizedlist>\n";
}

void XmlDocVisitor::visitPre(DocSimpleListItem *)
{
584
  if (m_hide) return;
585 586 587 588 589
  m_t << "<listitem>";
}

void XmlDocVisitor::visitPost(DocSimpleListItem *) 
{
590
  if (m_hide) return;
591 592 593 594 595
  m_t << "</listitem>\n";
}

void XmlDocVisitor::visitPre(DocSection *s)
{
596
  if (m_hide) return;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
597 598 599
  m_t << "<sect" << s->level() << " id=\"" << s->file();
  if (!s->anchor().isEmpty()) m_t << "_1" << s->anchor();
  m_t << "\">" << endl;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
600
  m_t << "<title>";
601
  filter(convertCharEntitiesToUTF8(s->title()));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
602
  m_t << "</title>" << endl;
603 604
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
605
void XmlDocVisitor::visitPost(DocSection *s) 
606
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
607
  m_t << "</sect" << s->level() << ">\n";
608 609 610 611
}

void XmlDocVisitor::visitPre(DocHtmlList *s)
{
612
  if (m_hide) return;
613 614 615 616 617 618 619 620
  if (s->type()==DocHtmlList::Ordered) 
    m_t << "<orderedlist>\n"; 
  else 
    m_t << "<itemizedlist>\n";
}

void XmlDocVisitor::visitPost(DocHtmlList *s) 
{
621
  if (m_hide) return;
622 623 624 625 626 627 628 629
  if (s->type()==DocHtmlList::Ordered) 
    m_t << "</orderedlist>\n"; 
  else 
    m_t << "</itemizedlist>\n";
}

void XmlDocVisitor::visitPre(DocHtmlListItem *)
{
630
  if (m_hide) return;
631 632 633 634 635
  m_t << "<listitem>\n";
}

void XmlDocVisitor::visitPost(DocHtmlListItem *) 
{
636
  if (m_hide) return;
637 638 639 640 641
  m_t << "</listitem>\n";
}

void XmlDocVisitor::visitPre(DocHtmlDescList *)
{
642
  if (m_hide) return;
643 644 645 646 647
  m_t << "<variablelist>\n";
}

void XmlDocVisitor::visitPost(DocHtmlDescList *) 
{
648
  if (m_hide) return;
649 650 651 652 653
  m_t << "</variablelist>\n";
}

void XmlDocVisitor::visitPre(DocHtmlDescTitle *)
{
654
  if (m_hide) return;
655 656 657 658 659
  m_t << "<varlistentry><term>";
}

void XmlDocVisitor::visitPost(DocHtmlDescTitle *) 
{
660
  if (m_hide) return;
661 662 663 664 665
  m_t << "</term></varlistentry>\n";
}

void XmlDocVisitor::visitPre(DocHtmlDescData *)
{
666
  if (m_hide) return;
667 668 669 670 671
  m_t << "<listitem>";
}

void XmlDocVisitor::visitPost(DocHtmlDescData *) 
{
672
  if (m_hide) return;
673 674 675 676 677
  m_t << "</listitem>\n";
}

void XmlDocVisitor::visitPre(DocHtmlTable *t)
{
678
  if (m_hide) return;
679
  m_t << "<table rows=\"" << t->numRows() 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
680
      << "\" cols=\"" << t->numColumns() << "\">" ;
681 682 683 684
}

void XmlDocVisitor::visitPost(DocHtmlTable *) 
{
685
  if (m_hide) return;
686 687 688 689 690
  m_t << "</table>\n";
}

void XmlDocVisitor::visitPre(DocHtmlRow *)
{
691
  if (m_hide) return;
692 693 694 695 696
  m_t << "<row>\n";
}

void XmlDocVisitor::visitPost(DocHtmlRow *) 
{
697
  if (m_hide) return;
698 699 700 701 702
  m_t << "</row>\n";
}

void XmlDocVisitor::visitPre(DocHtmlCell *c)
{
703
  if (m_hide) return;
704 705 706 707 708
  if (c->isHeading()) m_t << "<entry thead=\"yes\">"; else m_t << "<entry thead=\"no\">";
}

void XmlDocVisitor::visitPost(DocHtmlCell *) 
{
709
  if (m_hide) return;
710 711 712 713 714
  m_t << "</entry>"; 
}

void XmlDocVisitor::visitPre(DocHtmlCaption *)
{
715
  if (m_hide) return;
716 717 718 719 720
  m_t << "<caption>";
}

void XmlDocVisitor::visitPost(DocHtmlCaption *) 
{
721
  if (m_hide) return;
722 723 724 725 726
  m_t << "</caption>\n";
}

void XmlDocVisitor::visitPre(DocInternal *)
{
727
  if (m_hide) return;
728 729 730 731 732
  m_t << "<internal>";
}

void XmlDocVisitor::visitPost(DocInternal *) 
{
733
  if (m_hide) return;
734 735 736 737 738
  m_t << "</internal>" << endl;
}

void XmlDocVisitor::visitPre(DocHRef *href)
{
739
  if (m_hide) return;
740 741 742 743 744
  m_t << "<ulink url=\"" << href->url() << "\">";
}

void XmlDocVisitor::visitPost(DocHRef *) 
{
745
  if (m_hide) return;
746 747 748 749 750
  m_t << "</ulink>";
}

void XmlDocVisitor::visitPre(DocHtmlHeader *header)
{
751
  if (m_hide) return;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
752
  m_t << "<heading level=\"" << header->level() << "\">";
753 754
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
755
void XmlDocVisitor::visitPost(DocHtmlHeader *) 
756
{
757
  if (m_hide) return;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
758
  m_t << "</heading>\n";
759 760 761 762
}

void XmlDocVisitor::visitPre(DocImage *img)
{
763
  if (m_hide) return;
764 765 766 767 768 769 770 771 772
  m_t << "<image type=\"";
  switch(img->type())
  {
    case DocImage::Html:  m_t << "html"; break;
    case DocImage::Latex: m_t << "latex"; break;
    case DocImage::Rtf:   m_t << "rtf"; break;
  }
  m_t << "\"";

773
  QCString baseName=img->name();
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792
  int i;
  if ((i=baseName.findRev('/'))!=-1 || (i=baseName.findRev('\\'))!=-1)
  {
    baseName=baseName.right(baseName.length()-i-1);
  }
  m_t << " name=\"" << baseName << "\"";
  if (!img->width().isEmpty())
  {
    m_t << " width=\"";
    filter(img->width());
    m_t << "\"";
  }
  else if (!img->height().isEmpty())
  {
    m_t << " height=\"";
    filter(img->height());
    m_t << "\"";
  }
  m_t << ">";
793 794 795

  // copy the image to the output dir
  QFile inImage(img->name());
796
  QFile outImage(Config_getString("XML_OUTPUT")+"/"+baseName.data());
797 798 799 800 801 802 803 804
  if (inImage.open(IO_ReadOnly))
  {
    if (outImage.open(IO_WriteOnly))
    {
      char *buffer = new char[inImage.size()];
      inImage.readBlock(buffer,inImage.size());
      outImage.writeBlock(buffer,inImage.size());
      outImage.flush();
805
      delete[] buffer;
806 807
    }
  }
808 809 810 811
}

void XmlDocVisitor::visitPost(DocImage *) 
{
812
  if (m_hide) return;
813 814 815 816 817
  m_t << "</image>" << endl;
}

void XmlDocVisitor::visitPre(DocDotFile *df)
{
818
  if (m_hide) return;
819 820 821 822 823
  m_t << "<dotfile name=\"" << df->file() << "\">";
}

void XmlDocVisitor::visitPost(DocDotFile *) 
{
824
  if (m_hide) return;
825 826 827
  m_t << "</dotfile>" << endl;
}

828 829 830 831 832 833 834 835 836
void XmlDocVisitor::visitPre(DocMscFile *df)
{
  if (m_hide) return;
  m_t << "<mscfile name=\"" << df->file() << "\">";
}

void XmlDocVisitor::visitPost(DocMscFile *) 
{
  if (m_hide) return;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
837
  m_t << "</mscfile>" << endl;
838
}
839 840 841 842 843 844 845 846 847 848 849 850 851

void XmlDocVisitor::visitPre(DocDiaFile *df)
{
  if (m_hide) return;
  m_t << "<diafile name=\"" << df->file() << "\">";
}

void XmlDocVisitor::visitPost(DocDiaFile *)
{
  if (m_hide) return;
  m_t << "</diafile>" << endl;
}

852 853
void XmlDocVisitor::visitPre(DocLink *lnk)
{
854
  if (m_hide) return;
855 856 857 858 859
  startLink(lnk->ref(),lnk->file(),lnk->anchor());
}

void XmlDocVisitor::visitPost(DocLink *) 
{
860
  if (m_hide) return;
861 862 863 864 865
  endLink();
}

void XmlDocVisitor::visitPre(DocRef *ref)
{
866
  if (m_hide) return;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
867 868 869 870
  if (!ref->file().isEmpty()) 
  {
    startLink(ref->ref(),ref->file(),ref->isSubPage() ? QCString() : ref->anchor());
  }
871 872 873
  if (!ref->hasLinkText()) filter(ref->targetTitle());
}

874
void XmlDocVisitor::visitPost(DocRef *ref) 
875
{
876
  if (m_hide) return;
877
  if (!ref->file().isEmpty()) endLink();
878
  //m_t << " ";
879 880 881 882
}

void XmlDocVisitor::visitPre(DocSecRefItem *ref)
{
883
  if (m_hide) return;
884 885 886 887 888
  m_t << "<tocitem id=\"" << ref->file() << "_1" << ref->anchor() << "\">";
}

void XmlDocVisitor::visitPost(DocSecRefItem *) 
{
889
  if (m_hide) return;
890 891 892 893 894
  m_t << "</tocitem>" << endl;
}

void XmlDocVisitor::visitPre(DocSecRefList *)
{
895
  if (m_hide) return;
896 897 898 899 900
  m_t << "<toclist>" << endl;
}

void XmlDocVisitor::visitPost(DocSecRefList *) 
{
901
  if (m_hide) return;
902 903 904
  m_t << "</toclist>" << endl;
}

905 906 907 908 909 910 911 912 913 914 915
//void XmlDocVisitor::visitPre(DocLanguage *l)
//{
//  if (m_hide) return;
//  m_t << "<language langid=\"" << l->id() << "\">";
//}
//
//void XmlDocVisitor::visitPost(DocLanguage *) 
//{
//  if (m_hide) return;
//  m_t << "</language>" << endl;
//}
916 917 918

void XmlDocVisitor::visitPre(DocParamSect *s)
{
919
  if (m_hide) return;
920 921 922 923 924 925 926 927 928
  m_t << "<parameterlist kind=\"";
  switch(s->type())
  {
    case DocParamSect::Param: 
      m_t << "param"; break;
    case DocParamSect::RetVal: 
      m_t << "retval"; break;
    case DocParamSect::Exception: 
      m_t << "exception"; break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
929 930
    case DocParamSect::TemplateParam: 
      m_t << "templateparam"; break;
931 932 933 934 935 936 937 938
    default:
      ASSERT(0);
  }
  m_t << "\">";
}

void XmlDocVisitor::visitPost(DocParamSect *)
{
939
  if (m_hide) return;
940 941 942 943 944
  m_t << "</parameterlist>" << endl;
}

void XmlDocVisitor::visitPre(DocParamList *pl)
{
945
  if (m_hide) return;
946 947
  m_t << "<parameteritem>" << endl;
  m_t << "<parameternamelist>" << endl;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
948 949 950 951 952
  //QStrListIterator li(pl->parameters());
  //const char *s;
  QListIterator<DocNode> li(pl->parameters());
  DocNode *param;
  for (li.toFirst();(param=li.current());++li)
953
  {
954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971
    if (pl->paramTypes().count()>0)
    {
      QListIterator<DocNode> li(pl->paramTypes());
      DocNode *type;
      for (li.toFirst();(type=li.current());++li)
      {
        m_t << "<parametertype>";
        if (type->kind()==DocNode::Kind_Word)
        {
          visit((DocWord*)type); 
        }
        else if (type->kind()==DocNode::Kind_LinkedWord)
        {
          visit((DocLinkedWord*)type); 
        }
        m_t << "</parametertype>" << endl;
      }
    }
972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990
    m_t << "<parametername";
    if (pl->direction()!=DocParamSect::Unspecified)
    {
      m_t << " direction=\"";
      if (pl->direction()==DocParamSect::In)
      {
        m_t << "in";
      }
      else if (pl->direction()==DocParamSect::Out)
      {
        m_t << "out";
      }
      else if (pl->direction()==DocParamSect::InOut)
      {
        m_t << "inout";
      }
      m_t << "\"";
    }
    m_t << ">";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
991 992 993 994 995 996 997 998
    if (param->kind()==DocNode::Kind_Word)
    {
      visit((DocWord*)param); 
    }
    else if (param->kind()==DocNode::Kind_LinkedWord)
    {
      visit((DocLinkedWord*)param); 
    }
999 1000
    m_t << "</parametername>" << endl;
  }
1001
  m_t << "</parameternamelist>" << endl;
1002 1003 1004 1005 1006
  m_t << "<parameterdescription>" << endl;
}

void XmlDocVisitor::visitPost(DocParamList *)
{
1007
  if (m_hide) return;
1008 1009
  m_t << "</parameterdescription>" << endl;
  m_t << "</parameteritem>" << endl;
1010 1011 1012 1013
}

void XmlDocVisitor::visitPre(DocXRefItem *x)
{
1014
  if (m_hide) return;
1015
  if (x->title().isEmpty()) return;
1016 1017 1018 1019 1020 1021 1022 1023 1024
  m_t << "<xrefsect id=\"";
  m_t << x->file() << "_1" << x->anchor();
  m_t << "\">";
  m_t << "<xreftitle>";
  filter(x->title());
  m_t << "</xreftitle>";
  m_t << "<xrefdescription>";
}

1025
void XmlDocVisitor::visitPost(DocXRefItem *x)
1026
{
1027
  if (m_hide) return;
1028
  if (x->title().isEmpty()) return;
1029 1030 1031 1032 1033 1034
  m_t << "</xrefdescription>";
  m_t << "</xrefsect>";
}

void XmlDocVisitor::visitPre(DocInternalRef *ref)
{
1035
  if (m_hide) return;
1036 1037 1038 1039 1040
  startLink(0,ref->file(),ref->anchor());
}

void XmlDocVisitor::visitPost(DocInternalRef *) 
{
1041
  if (m_hide) return;
1042 1043 1044 1045
  endLink();
  m_t << " ";
}

1046
void XmlDocVisitor::visitPre(DocCopy *c)
1047
{
1048
  if (m_hide) return;
1049
  m_t << "<copydoc link=\"" << convertToXML(c->link()) << "\">";
1050 1051 1052 1053
}

void XmlDocVisitor::visitPost(DocCopy *)
{
1054
  if (m_hide) return;
1055
  m_t << "</copydoc>" << endl;
1056 1057
}

1058 1059 1060 1061 1062 1063 1064 1065
void XmlDocVisitor::visitPre(DocText *)
{
}

void XmlDocVisitor::visitPost(DocText *)
{
}

1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077
void XmlDocVisitor::visitPre(DocHtmlBlockQuote *)
{
  if (m_hide) return;
  m_t << "<blockquote>";
}

void XmlDocVisitor::visitPost(DocHtmlBlockQuote *)
{
  if (m_hide) return;
  m_t << "</blockquote>";
}

1078 1079 1080 1081 1082 1083 1084
void XmlDocVisitor::visitPre(DocVhdlFlow *)
{
}

void XmlDocVisitor::visitPost(DocVhdlFlow *)
{
}
1085

1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098
void XmlDocVisitor::visitPre(DocParBlock *)
{
  if (m_hide) return;
  m_t << "<parblock>";
}

void XmlDocVisitor::visitPost(DocParBlock *)
{
  if (m_hide) return;
  m_t << "</parblock>";
}


1099 1100
void XmlDocVisitor::filter(const char *str)
{ 
1101
  m_t << convertToXML(str);
1102 1103
}

1104
void XmlDocVisitor::startLink(const QCString &ref,const QCString &file,const QCString &anchor)
1105
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1106
  //printf("XmlDocVisitor: file=%s anchor=%s\n",file.data(),anchor.data());
1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120
  m_t << "<ref refid=\"" << file;
  if (!anchor.isEmpty()) m_t << "_1" << anchor;
  m_t << "\" kindref=\"";
  if (!anchor.isEmpty()) m_t << "member"; else m_t << "compound";
  m_t << "\"";
  if (!ref.isEmpty()) m_t << " external=\"" << ref << "\"";
  m_t << ">";
}

void XmlDocVisitor::endLink()
{
  m_t << "</ref>";
}

1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
void XmlDocVisitor::pushEnabled()
{
  m_enabled.push(new bool(m_hide));
}

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