docparser.cpp 183 KB
Newer Older
1 2
/******************************************************************************
 *
3
 * 
4 5
 *
 *
6
 * Copyright (C) 1997-2008 by Dimitri van Heesch.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * 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.
 *
 */

#include <stdio.h>
#include <stdlib.h>

#include <qfile.h>
#include <qfileinfo.h>
#include <qcstring.h>
#include <qstack.h>
#include <qdict.h>
27
#include <qregexp.h>
28
#include <ctype.h>
29 30 31

#include "doxygen.h"
#include "debug.h"
32
#include "util.h"
33
#include "pagedef.h"
34 35 36 37 38

#include "docparser.h"
#include "doctokenizer.h"
#include "cmdmapper.h"
#include "printdocvisitor.h"
39
#include "message.h"
40
#include "section.h"
41 42
#include "searchindex.h"
#include "language.h"
43
#include "portable.h"
44

Dimitri van Heesch's avatar
Dimitri van Heesch committed
45
// debug off
46
#define DBG(x) do {} while(0)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
47 48

// debug to stdout
49 50
//#define DBG(x) printf x

Dimitri van Heesch's avatar
Dimitri van Heesch committed
51 52 53 54
// debug to stderr
//#define myprintf(x...) fprintf(stderr,x)
//#define DBG(x) myprintf x

55 56 57
#define INTERNAL_ASSERT(x) do {} while(0)
//#define INTERNAL_ASSERT(x) if (!(x)) DBG(("INTERNAL_ASSERT(%s) failed retval=0x%x: file=%s line=%d\n",#x,retval,__FILE__,__LINE__)); 

58 59
//---------------------------------------------------------------------------

60 61 62 63 64 65 66 67 68
static const char *sectionLevelToName[] = 
{
  "page",
  "section",
  "subsection",
  "subsubsection",
  "paragraph"
};

69 70
//---------------------------------------------------------------------------

Dimitri van Heesch's avatar
Dimitri van Heesch committed
71
// Parser state: global variables during a call to validatingParseDoc
72
static QString                g_context;
73 74 75
static bool                   g_inSeeBlock;
static bool                   g_insideHtmlLink;
static QStack<DocNode>        g_nodeStack;
76
static QStack<DocStyleChange> g_styleStack;
77
static QStack<DocStyleChange> g_initialStyleStack;
78
static QList<Definition>      g_copyStack;
79
static QString                g_fileName;
80
static QString                g_relPath;
81

Dimitri van Heesch's avatar
Dimitri van Heesch committed
82 83 84
static bool                   g_hasParamCommand;
static bool                   g_hasReturnCommand;
static QDict<void>            g_paramsFound;
85
static MemberDef *            g_memberDef;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
86 87 88 89 90 91 92 93 94 95
static bool                   g_isExample;
static QCString               g_exampleName;
static SectionDict *          g_sectionDict;
static QCString               g_searchUrl;

static QString                g_includeFileText;
static uint                   g_includeFileOffset;
static uint                   g_includeFileLength;

// parser's context to store all global variables
96 97
struct DocParserContext
{
98
  QString context;
99 100 101 102
  bool inSeeBlock;
  bool insideHtmlLink;
  QStack<DocNode> nodeStack;
  QStack<DocStyleChange> styleStack;
103
  QStack<DocStyleChange> initialStyleStack;
104
  QList<Definition> copyStack;
105
  QString fileName;
106
  QString relPath;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121

  bool         hasParamCommand;
  bool         hasReturnCommand;
  MemberDef *  memberDef;
  QDict<void>  paramsFound;
  bool         isExample;
  QCString     exampleName;
  SectionDict *sectionDict;
  QCString     searchUrl;

  QString  includeFileText;
  uint     includeFileOffset;
  uint     includeFileLength;

  TokenInfo *token;
122 123 124 125 126 127
};

static QStack<DocParserContext> g_parserStack;

//---------------------------------------------------------------------------

128
static void docParserPushContext(bool saveParamInfo=TRUE)
129
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
130 131 132 133
  //QCString indent;
  //indent.fill(' ',g_parserStack.count()*2+2);
  //printf("%sdocParserPushContext() count=%d\n",indent.data(),g_nodeStack.count());

134
  doctokenizerYYpushContext();
135 136 137 138 139 140 141 142 143
  DocParserContext *ctx   = new DocParserContext;
  ctx->context            = g_context;
  ctx->inSeeBlock         = g_inSeeBlock;
  ctx->insideHtmlLink     = g_insideHtmlLink;
  ctx->nodeStack          = g_nodeStack;
  ctx->styleStack         = g_styleStack;
  ctx->initialStyleStack  = g_initialStyleStack;
  ctx->copyStack          = g_copyStack;
  ctx->fileName           = g_fileName;
144
  ctx->relPath            = g_relPath;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
145

146 147 148 149 150 151 152
  if (saveParamInfo)
  {
    ctx->hasParamCommand    = g_hasParamCommand;
    ctx->hasReturnCommand   = g_hasReturnCommand;
    ctx->paramsFound        = g_paramsFound;
  }

Dimitri van Heesch's avatar
Dimitri van Heesch committed
153 154 155 156 157 158 159 160 161 162 163 164 165
  ctx->memberDef          = g_memberDef;
  ctx->isExample          = g_isExample;
  ctx->exampleName        = g_exampleName;
  ctx->sectionDict        = g_sectionDict;
  ctx->searchUrl          = g_searchUrl;

  ctx->includeFileText    = g_includeFileText;
  ctx->includeFileOffset  = g_includeFileOffset;
  ctx->includeFileLength  = g_includeFileLength;
  
  ctx->token              = g_token;
  g_token = new TokenInfo;

166 167 168
  g_parserStack.push(ctx);
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
169
static void docParserPopContext(bool keepParamInfo=FALSE)
170 171
{
  DocParserContext *ctx = g_parserStack.pop();
172 173 174 175 176 177 178 179
  g_context             = ctx->context;
  g_inSeeBlock          = ctx->inSeeBlock;
  g_insideHtmlLink      = ctx->insideHtmlLink;
  g_nodeStack           = ctx->nodeStack;
  g_styleStack          = ctx->styleStack;
  g_initialStyleStack   = ctx->initialStyleStack;
  g_copyStack           = ctx->copyStack;
  g_fileName            = ctx->fileName;
180
  g_relPath             = ctx->relPath;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
181

Dimitri van Heesch's avatar
Dimitri van Heesch committed
182 183 184 185 186 187
  if (!keepParamInfo)
  {
    g_hasParamCommand     = ctx->hasParamCommand;
    g_hasReturnCommand    = ctx->hasReturnCommand;
    g_paramsFound         = ctx->paramsFound;
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
188 189 190 191 192 193 194 195 196 197 198 199 200
  g_memberDef           = ctx->memberDef;
  g_isExample           = ctx->isExample;
  g_exampleName         = ctx->exampleName;
  g_sectionDict         = ctx->sectionDict;
  g_searchUrl           = ctx->searchUrl;

  g_includeFileText     = ctx->includeFileText;
  g_includeFileOffset   = ctx->includeFileOffset;
  g_includeFileLength   = ctx->includeFileLength;

  delete g_token;
  g_token               = ctx->token;

201 202
  delete ctx;
  doctokenizerYYpopContext();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
203 204 205 206

  //QCString indent;
  //indent.fill(' ',g_parserStack.count()*2+2);
  //printf("%sdocParserPopContext() count=%d\n",indent.data(),g_nodeStack.count());
207 208 209 210
}

//---------------------------------------------------------------------------

211
/*! search for an image in the imageNameDict and if found
212 213
 * copies the image to the output directory (which depends on the \a type
 * parameter).
214 215 216 217 218 219 220 221 222
 */
static QCString findAndCopyImage(const char *fileName,DocImage::Type type)
{
  QCString result;
  bool ambig;
  FileDef *fd;
  //printf("Search for %s\n",fileName);
  if ((fd=findFileDef(Doxygen::imageNameDict,fileName,ambig)))
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
223 224
    QCString inputFile = fd->absFilePath();
    QFile inImage(inputFile);
225 226 227 228 229 230
    if (inImage.open(IO_ReadOnly))
    {
      result = fileName;
      int i;
      if ((i=result.findRev('/'))!=-1 || (i=result.findRev('\\'))!=-1)
      {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
231
	result = result.right(result.length()-i-1);
232
      }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
233
      //printf("fileName=%s result=%s\n",fileName,result.data());
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
      QCString outputDir;
      switch(type)
      {
        case DocImage::Html: 
	  if (!Config_getBool("GENERATE_HTML")) return result;
	  outputDir = Config_getString("HTML_OUTPUT");
	  break;
        case DocImage::Latex: 
	  if (!Config_getBool("GENERATE_LATEX")) return result;
	  outputDir = Config_getString("LATEX_OUTPUT");
	  break;
        case DocImage::Rtf:
	  if (!Config_getBool("GENERATE_RTF")) return result;
	  outputDir = Config_getString("RTF_OUTPUT");
	  break;
      }
      QCString outputFile = outputDir+"/"+result;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
251
      if (outputFile!=inputFile) // prevent copying to ourself
252
      {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
253 254 255 256 257 258 259 260
        QFile outImage(outputFile.data());
        if (outImage.open(IO_WriteOnly)) // copy the image
        {
          char *buffer = new char[inImage.size()];
          inImage.readBlock(buffer,inImage.size());
          outImage.writeBlock(buffer,inImage.size());
          outImage.flush();
          delete buffer;
261
          if (type==DocImage::Html) Doxygen::indexList.addImageFile(result);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
262 263 264 265 266 267
        }
        else
        {
          warn_doc_error(g_fileName,doctokenizerYYlineno,
              "Warning: could not write output image %s",outputFile.data());
        }
268 269 270 271
      }
    }
    else
    {
272
      warn_doc_error(g_fileName,doctokenizerYYlineno,
273 274 275 276 277 278 279 280 281 282 283 284 285
	  "Warning: could not open image %s",fileName);
    }

    if (type==DocImage::Latex && Config_getBool("USE_PDFLATEX") && 
	fd->name().right(4)==".eps"
       )
    { // we have an .eps image in pdflatex mode => convert it to a pdf.
      QCString outputDir = Config_getString("LATEX_OUTPUT");
      QCString baseName  = fd->name().left(fd->name().length()-4);
      QCString epstopdfArgs(4096);
      epstopdfArgs.sprintf("\"%s/%s.eps\" --outfile=\"%s/%s.pdf\"",
                           outputDir.data(), baseName.data(),
			   outputDir.data(), baseName.data());
286
      if (portable_system("epstopdf",epstopdfArgs)!=0)
287 288 289 290 291 292 293 294 295 296 297 298
      {
	err("Error: Problems running epstopdf. Check your TeX installation!\n");
      }
      return baseName;
    }
  }
  else if (ambig)
  {
    QCString text;
    text.sprintf("Warning: image file name %s is ambigious.\n",fileName);
    text+="Possible candidates:\n";
    text+=showFileDefMatches(Doxygen::imageNameDict,fileName);
299
    warn_doc_error(g_fileName,doctokenizerYYlineno,text);
300 301 302 303 304 305
  }
  else
  {
    result=fileName;
    if (result.left(5)!="http:" && result.left(6)!="https:")
    {
306
      warn_doc_error(g_fileName,doctokenizerYYlineno,
307 308 309 310 311 312 313 314
           "Warning: image file %s is not found in IMAGE_PATH: "  
	   "assuming external image.",fileName
          );
    }
  }
  return result;
}

315
/*! Collects the parameters found with \@param or \@retval commands
316 317
 *  in a global list g_paramsFound. If \a isParam is set to TRUE
 *  and the parameter is not an actual parameter of the current
318
 *  member g_memberDef, then a warning is raised (unless warnings
319 320
 *  are disabled altogether).
 */
321
static void checkArgumentName(const QString &name,bool isParam)
322
{                
323
  if (!Config_getBool("WARN_IF_DOC_ERROR")) return;
324
  if (g_memberDef==0) return; // not a member
325
  LockingPtr<ArgumentList> al=g_memberDef->isDocsForDefinition() ? 
326 327
		   g_memberDef->argumentList() :
                   g_memberDef->declArgumentList();
328
  //printf("isDocsForDefinition()=%d\n",g_memberDef->isDocsForDefinition());
329 330
  if (al==0) return; // no argument list

331
  static QRegExp re("[a-zA-Z0-9_\\x80-\\xFF]+\\.*");
332
  int p=0,i=0,l;
333
  while ((i=re.match(name,p,&l))!=-1) // to handle @param x,y
334
  {
335
    QString aName=name.mid(i,l);
336
    //printf("aName=`%s'\n",aName.data());
337 338 339 340 341
    ArgumentListIterator ali(*al);
    Argument *a;
    bool found=FALSE;
    for (ali.toFirst();(a=ali.current());++ali)
    {
342
      QString argName = g_memberDef->isDefine() ? a->type : a->name;
343
      argName=argName.stripWhiteSpace();
344
      //printf("argName=`%s'\n",argName.data());
345 346 347 348 349 350 351 352 353 354 355 356
      if (argName.right(3)=="...") argName=argName.left(argName.length()-3);
      if (aName==argName) 
      {
	//printf("adding `%s'\n",aName.data());
	g_paramsFound.insert(aName,(void *)(0x8));
	found=TRUE;
	break;
      }
    }
    if (!found && isParam)
    {
      //printf("member type=%d\n",memberDef->memberType());
357
      QString scope=g_memberDef->getScopeString();
358
      if (!scope.isEmpty()) scope+="::"; else scope="";
359 360 361 362 363 364 365 366 367 368 369 370 371 372
      QString inheritedFrom = "";
      QString docFile = g_memberDef->docFile();
      int docLine = g_memberDef->docLine();
      MemberDef *inheritedMd = g_memberDef->inheritsDocsFrom();
      if (inheritedMd) // documentation was inherited
      {
        inheritedFrom.sprintf(" inherited from member %s at line "
            "%d in file %s",inheritedMd->name().data(),
            inheritedMd->docLine(),inheritedMd->docFile().data());
        docFile = g_memberDef->getDefFileName();
        docLine = g_memberDef->getDefLine();
        
      }
      warn_doc_error(docFile,docLine,
373
	  "Warning: argument '%s' of command @param "
374
	  "is not found in the argument list of %s%s%s%s",
375
	  aName.data(),scope.data(),g_memberDef->name().data(),
376
	  argListToString(al.pointer()).data(),inheritedFrom.data());
377 378 379 380 381
    }
    p=i+l;
  }
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
382
/*! Checks if the parameters that have been specified using \@param are
383 384 385 386
 *  indeed all paramters.
 *  Must be called after checkArgumentName() has been called for each
 *  argument.
 */
387 388
static void checkUndocumentedParams()
{
389
  if (g_memberDef && g_hasParamCommand && Config_getBool("WARN_IF_DOC_ERROR"))
390
  {
391
    LockingPtr<ArgumentList> al=g_memberDef->isDocsForDefinition() ? 
392 393
      g_memberDef->argumentList() :
      g_memberDef->declArgumentList();
394
    if (al!=0)
395 396 397 398 399 400
    {
      ArgumentListIterator ali(*al);
      Argument *a;
      bool found=FALSE;
      for (ali.toFirst();(a=ali.current());++ali)
      {
401
        QString argName = g_memberDef->isDefine() ? a->type : a->name;
402
        argName=argName.stripWhiteSpace();
403
        if (argName.right(3)=="...") argName=argName.left(argName.length()-3);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
404 405 406 407 408
        if (getLanguageFromFileName(g_memberDef->getDefFileName())==SrcLangExt_Python && argName=="self")
        { 
          // allow undocumented self parameter for Python
        }
        else if (!argName.isEmpty() && g_paramsFound.find(argName)==0 && a->docs.isEmpty()) 
409 410 411 412 413 414 415
        {
          found = TRUE;
          break;
        }
      }
      if (found)
      {
416
        bool first=TRUE;
417
        QString errMsg=
418
            "Warning: The following parameters of "+
419
            QString(g_memberDef->qualifiedName()) + 
420
            QString(argListToString(al.pointer())) +
421
            " are not documented:\n";
422 423
        for (ali.toFirst();(a=ali.current());++ali)
        {
424
          QString argName = g_memberDef->isDefine() ? a->type : a->name;
425
          argName=argName.stripWhiteSpace();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
426 427 428 429 430
          if (getLanguageFromFileName(g_memberDef->getDefFileName())==SrcLangExt_Python && argName=="self")
          { 
            // allow undocumented self parameter for Python
          }
          else if (!argName.isEmpty() && g_paramsFound.find(argName)==0) 
431
          {
432 433 434 435 436 437 438 439
            if (!first)
            {
              errMsg+="\n";
            }
            else
            {
              first=FALSE;
            }
440
            errMsg+="  parameter '"+argName+"'";
441 442
          }
        }
443 444
        if (g_memberDef->inheritsDocsFrom())
        {
445 446 447
           warn_doc_error(g_memberDef->getDefFileName(),
                          g_memberDef->getDefLine(),
                          substitute(errMsg,"%","%%"));
448 449 450
        }
        else
        {
451 452 453
           warn_doc_error(g_memberDef->docFile(),
                          g_memberDef->docLine(),
                          substitute(errMsg,"%","%%"));
454
        }
455 456 457 458 459
      }
    }
  }
}

460
/*! Check if a member has documentation for its parameter and or return
461 462 463
 *  type, if applicable. If found this will be stored in the member, this
 *  is needed as a member can have brief and detailed documentation, while
 *  only one of these needs to document the parameters.
464
 */
465
static void detectNoDocumentedParams()
466 467 468
{
  if (g_memberDef && Config_getBool("WARN_NO_PARAMDOC"))
  {
469 470
    LockingPtr<ArgumentList> al     = g_memberDef->argumentList();
    LockingPtr<ArgumentList> declAl = g_memberDef->declArgumentList();
471
    QString returnType   = g_memberDef->typeString();
472
    bool isPython = getLanguageFromFileName(g_memberDef->getDefFileName())==SrcLangExt_Python;
473

474 475 476
    if (!g_memberDef->hasDocumentedParams() &&
        g_hasParamCommand)
    {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
477
      //printf("%s->setHasDocumentedParams(TRUE);\n",g_memberDef->name().data());
478 479 480
      g_memberDef->setHasDocumentedParams(TRUE);
    }
    else if (!g_memberDef->hasDocumentedParams())
481
    {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
482
      bool allDoc=TRUE; // no paramater => all parameters are documented
483
      if ( // member has parameters
484
             al!=0 &&       // but the member has a parameter list
485 486
             al->count()>0  // with at least one parameter (that is not void)
         )
487
      {
488 489 490 491 492 493
        ArgumentListIterator ali(*al);
        Argument *a;

        // see if all parameters have documentation
        for (ali.toFirst();(a=ali.current()) && allDoc;++ali)
        {
494 495 496
          if (!a->name.isEmpty() && a->type!="void" &&
              !(isPython && a->name=="self")
             )
Dimitri van Heesch's avatar
Dimitri van Heesch committed
497 498 499 500 501
          {
            allDoc = !a->docs.isEmpty();
          }
          //printf("a->type=%s a->name=%s doc=%s\n",
          //        a->type.data(),a->name.data(),a->docs.data());
502
        }
503
        if (!allDoc && declAl!=0) // try declaration arguments as well
504 505 506 507 508 509
        {
          allDoc=TRUE;
          ArgumentListIterator ali(*declAl);
          Argument *a;
          for (ali.toFirst();(a=ali.current()) && allDoc;++ali)
          {
510 511 512
            if (!a->name.isEmpty() && a->type!="void" &&
                !(isPython && a->name=="self")
               )
Dimitri van Heesch's avatar
Dimitri van Heesch committed
513 514 515
            {
              allDoc = !a->docs.isEmpty();
            }
516
            //printf("a->name=%s doc=%s\n",a->name.data(),a->docs.data());
517 518 519
          }
        }
      }
520 521
      if (allDoc) 
      {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
522
        //printf("%s->setHasDocumentedParams(TRUE);\n",g_memberDef->name().data());
523 524
        g_memberDef->setHasDocumentedParams(TRUE);
      }
525
    }
526 527 528 529 530 531 532 533 534 535 536 537
    //printf("Member %s hasReturnCommand=%d\n",g_memberDef->name().data(),g_hasReturnCommand);
    if (!g_memberDef->hasDocumentedReturnType() && // docs not yet found
        g_hasReturnCommand)
    {
      g_memberDef->setHasDocumentedReturnType(TRUE);
    }
    else if ( // see if return needs to documented 
        g_memberDef->hasDocumentedReturnType() ||
        returnType.isEmpty() ||          // empty return type
        returnType.find("void")!=-1  ||  // void return type
        !g_memberDef->isConstructor() || // a constructor
        !g_memberDef->isDestructor()     // or destructor
538 539
       )
    {
540
      g_memberDef->setHasDocumentedReturnType(TRUE);
541
    }
542
       
543 544 545 546
  }
}


547 548
//---------------------------------------------------------------------------

549
/*! Strips known html and tex extensions from \a text. */
550
static QString stripKnownExtensions(const char *text)
551
{
552
  QString result=text;
553 554 555 556 557
  if (result.right(4)==".tex")
  {
    result=result.left(result.length()-4);
  }
  else if (result.right(Doxygen::htmlFileExtension.length())==
558
         QString(Doxygen::htmlFileExtension)) 
559 560 561 562 563 564 565
  {
    result=result.left(result.length()-Doxygen::htmlFileExtension.length());
  }
  return result;
}


566 567 568 569 570 571 572
//---------------------------------------------------------------------------

/*! Returns TRUE iff node n is a child of a preformatted node */
static bool insidePRE(DocNode *n)
{
  while (n)
  {
573
    if (n->isPreformatted()) return TRUE;
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
    n=n->parent();
  }
  return FALSE;
}

//---------------------------------------------------------------------------

/*! Returns TRUE iff node n is a child of a html list item node */
static bool insideLI(DocNode *n)
{
  while (n)
  {
    if (n->kind()==DocNode::Kind_HtmlListItem) return TRUE;
    n=n->parent();
  }
  return FALSE;
}

//---------------------------------------------------------------------------

/*! Returns TRUE iff node n is a child of a unordered html list node */
static bool insideUL(DocNode *n)
{
  while (n)
  {
    if (n->kind()==DocNode::Kind_HtmlList && 
        ((DocHtmlList *)n)->type()==DocHtmlList::Unordered) return TRUE;
    n=n->parent();
  }
  return FALSE;
}

//---------------------------------------------------------------------------

/*! Returns TRUE iff node n is a child of a ordered html list node */
static bool insideOL(DocNode *n)
{
  while (n)
  {
    if (n->kind()==DocNode::Kind_HtmlList && 
        ((DocHtmlList *)n)->type()==DocHtmlList::Ordered) return TRUE;
    n=n->parent();
  }
  return FALSE;
}

//---------------------------------------------------------------------------

622 623 624 625 626 627 628 629 630 631 632 633
static bool insideTable(DocNode *n)
{
  while (n)
  {
    if (n->kind()==DocNode::Kind_HtmlTable) return TRUE;
    n=n->parent();
  }
  return FALSE;
}

//---------------------------------------------------------------------------

634 635 636 637 638 639 640 641 642 643
///*! Returns TRUE iff node n is a child of a language node */
//static bool insideLang(DocNode *n)
//{
//  while (n)
//  {
//    if (n->kind()==DocNode::Kind_Language) return TRUE;
//    n=n->parent();
//  }
//  return FALSE;
//}
644 645 646 647


//---------------------------------------------------------------------------

648 649 650 651 652 653 654 655
/*! Looks for a documentation block with name commandName in the current
 *  context (g_context). The resulting documentation string is
 *  put in pDoc, the definition in which the documentation was found is
 *  put in pDef.
 *  @retval TRUE if name was found.
 *  @retval FALSE if name was not found.
 */
static bool findDocsForMemberOrCompound(const char *commandName,
656
                                 QString *pDoc,
657
                                 QString *pBrief,
658 659
                                 Definition **pDef)
{
660
  //printf("findDocsForMemberOrCompound(%s)\n",commandName);
661
  *pDoc="";
662
  *pBrief="";
663
  *pDef=0;
664
  QString cmdArg=substitute(commandName,"#","::");
665 666 667 668 669
  int l=cmdArg.length();
  if (l==0) return FALSE;

  int funcStart=cmdArg.find('(');
  if (funcStart==-1) funcStart=l;
670

671
  QString name=removeRedundantWhiteSpace(cmdArg.left(funcStart).latin1());
672
  QString args=cmdArg.right(l-funcStart);
673 674 675 676 677 678 679

  // try if the link is to a member
  MemberDef    *md=0;
  ClassDef     *cd=0;
  FileDef      *fd=0;
  NamespaceDef *nd=0;
  GroupDef     *gd=0;
680
  PageDef      *pd=0;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
681 682 683 684 685
  bool found = getDefs(
      g_context.find('.')==-1?g_context.latin1():"", // `find('.') is a hack to detect files
      name.latin1(),
      args.isEmpty()?0:args.latin1(),
      md,cd,fd,nd,gd,FALSE,0,TRUE);
686
  //printf("found=%d context=%s name=%s\n",found,g_context.data(),name.data());
687 688 689
  if (found && md)
  {
    *pDoc=md->documentation();
690
    *pBrief=md->briefDescription();
691 692 693 694 695 696 697 698
    *pDef=md;
    return TRUE;
  }


  int scopeOffset=g_context.length();
  do // for each scope
  {
699
    QString fullName=cmdArg;
700 701 702 703 704 705 706
    if (scopeOffset>0)
    {
      fullName.prepend(g_context.left(scopeOffset)+"::");
    }
    //printf("Trying fullName=`%s'\n",fullName.data());

    // try class, namespace, group, page, file reference
707
    cd = Doxygen::classSDict->find(fullName);
708 709 710
    if (cd) // class 
    {
      *pDoc=cd->documentation();
711
      *pBrief=cd->briefDescription();
712 713 714
      *pDef=cd;
      return TRUE;
    }
715
    nd = Doxygen::namespaceSDict->find(fullName);
716 717 718
    if (nd) // namespace
    {
      *pDoc=nd->documentation();
719
      *pBrief=nd->briefDescription();
720 721 722
      *pDef=nd;
      return TRUE;
    }
723
    gd = Doxygen::groupSDict->find(cmdArg);
724 725 726
    if (gd) // group
    {
      *pDoc=gd->documentation();
727
      *pBrief=gd->briefDescription();
728 729 730
      *pDef=gd;
      return TRUE;
    }
731 732
    pd = Doxygen::pageSDict->find(cmdArg);
    if (pd) // page
733
    {
734
      *pDoc=pd->documentation();
735
      *pBrief=pd->briefDescription();
736
      *pDef=pd;
737 738 739 740 741 742 743
      return TRUE;
    }
    bool ambig;
    fd = findFileDef(Doxygen::inputNameDict,cmdArg,ambig);
    if (fd && !ambig) // file
    {
      *pDoc=fd->documentation();
744
      *pBrief=fd->briefDescription();
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764
      *pDef=fd;
      return TRUE;
    }

    if (scopeOffset==0)
    {
      scopeOffset=-1;
    }
    else
    {
      scopeOffset = g_context.findRev("::",scopeOffset-1);
      if (scopeOffset==-1) scopeOffset=0;
    }
  } while (scopeOffset>=0);

  
  return FALSE;
}
//---------------------------------------------------------------------------

765 766 767 768 769 770 771
// forward declaration
static bool defaultHandleToken(DocNode *parent,int tok, 
                               QList<DocNode> &children,bool
                               handleWord=TRUE);


static int handleStyleArgument(DocNode *parent,QList<DocNode> &children,
772
                               const QString &cmdName)
773
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
774
  DBG(("handleStyleArgument(%s)\n",cmdName.data()));
775
  QString tokenName = g_token->name;
776 777 778
  int tok=doctokenizerYYlex();
  if (tok!=TK_WHITESPACE)
  {
779
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected whitespace after %s command",
780
	cmdName.data());
781 782
    return tok;
  }
783
  while ((tok=doctokenizerYYlex()) && 
784 785 786 787
          tok!=TK_WHITESPACE && 
          tok!=TK_NEWPARA &&
          tok!=TK_LISTITEM && 
          tok!=TK_ENDLIST
788
        )
789
  {
790 791 792 793 794 795 796
    static QRegExp specialChar("[.,|()\\[\\]:;\\?]");
    if (tok==TK_WORD && g_token->name.length()==1 && 
        g_token->name.find(specialChar)!=-1)
    {
      // special character that ends the markup command
      return tok;
    }
797 798 799 800 801
    if (!defaultHandleToken(parent,tok,children))
    {
      switch (tok)
      {
        case TK_COMMAND: 
802
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Illegal command \\%s as the argument of a \\%s command",
803
	       g_token->name.data(),cmdName.data());
804 805
          break;
        case TK_SYMBOL: 
806 807 808 809
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unsupported symbol %s found while handling command %s",
               g_token->name.data(),cmdName.data());
          break;
        case TK_HTMLTAG:
810
          if (insideLI(parent) && Mappers::htmlTagMapper->map(g_token->name) && g_token->endTag)
811 812 813
          { // ignore </li> as the end of a style command
            continue; 
          }
814
          return tok;
815 816
          break;
        default:
817 818
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected token %s while handling command %s",
	       tokToString(tok),cmdName.data());
819 820
          break;
      }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
821
      break;
822 823
    }
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
824 825 826
  DBG(("handleStyleArgument(%s) end tok=%x\n",cmdName.data(),tok));
  return (tok==TK_NEWPARA || tok==TK_LISTITEM || tok==TK_ENDLIST
         ) ? tok : RetVal_OK; 
827 828
}

829 830 831
/*! Called when a style change starts. For instance a \<b\> command is
 *  encountered.
 */
832 833
static void handleStyleEnter(DocNode *parent,QList<DocNode> &children,
          DocStyleChange::Style s,const HtmlAttribList *attribs)
834 835
{
  DBG(("HandleStyleEnter\n"));
836
  DocStyleChange *sc= new DocStyleChange(parent,g_nodeStack.count(),s,TRUE,attribs);
837 838 839 840
  children.append(sc);
  g_styleStack.push(sc);
}

841 842 843
/*! Called when a style change ends. For instance a \</b\> command is
 *  encountered.
 */
844 845
static void handleStyleLeave(DocNode *parent,QList<DocNode> &children,
         DocStyleChange::Style s,const char *tagName)
846 847 848 849 850 851 852
{
  DBG(("HandleStyleLeave\n"));
  if (g_styleStack.isEmpty() ||                           // no style change
      g_styleStack.top()->style()!=s ||                   // wrong style change
      g_styleStack.top()->position()!=g_nodeStack.count() // wrong position
     )
  {
853 854 855 856 857 858 859 860 861 862
    if (g_styleStack.isEmpty())
    {
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: found </%s> tag without matching <%s>",
          tagName,tagName);
    }
    else
    {
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: found </%s> tag while expecting </%s>",
          tagName,g_styleStack.top()->styleString());
    }
863 864 865 866 867 868 869 870 871
  }
  else // end the section
  {
    DocStyleChange *sc= new DocStyleChange(parent,g_nodeStack.count(),s,FALSE);
    children.append(sc);
    g_styleStack.pop();
  }
}

872 873 874 875
/*! Called at the end of a paragraph to close all open style changes
 *  (e.g. a <b> without a </b>). The closed styles are pushed onto a stack
 *  and entered again at the start of a new paragraph.
 */
876 877 878 879 880 881 882 883
static void handlePendingStyleCommands(DocNode *parent,QList<DocNode> &children)
{
  if (!g_styleStack.isEmpty())
  {
    DocStyleChange *sc = g_styleStack.top();
    while (sc && sc->position()>=g_nodeStack.count()) 
    { // there are unclosed style modifiers in the paragraph
      children.append(new DocStyleChange(parent,g_nodeStack.count(),sc->style(),FALSE));
884
      g_initialStyleStack.push(sc);
885 886 887 888 889 890
      g_styleStack.pop();
      sc = g_styleStack.top();
    }
  }
}

891 892 893 894 895 896 897 898 899
static void handleInitialStyleCommands(DocPara *parent,QList<DocNode> &children)
{
  DocStyleChange *sc;
  while ((sc=g_initialStyleStack.pop()))
  {
    handleStyleEnter(parent,children,sc->style(),&sc->attribs());
  }
}

900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941
static int handleAHref(DocNode *parent,QList<DocNode> &children,const HtmlAttribList &tagHtmlAttribs)
{
  HtmlAttribListIterator li(tagHtmlAttribs);
  HtmlAttrib *opt;
  int index=0;
  int retval = RetVal_OK;
  for (li.toFirst();(opt=li.current());++li,++index)
  {
    if (opt->name=="name") // <a name=label> tag
    {
      if (!opt->value.isEmpty())
      {
        DocAnchor *anc = new DocAnchor(parent,opt->value,TRUE);
        children.append(anc);
        break; // stop looking for other tag attribs
      }
      else
      {
        warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: found <a> tag with name option but without value!");
      }
    }
    else if (opt->name=="href") // <a href=url>..</a> tag
    {
      // copy attributes
      HtmlAttribList attrList = tagHtmlAttribs;
      // and remove the href attribute
      bool result = attrList.remove(index);
      ASSERT(result);
      DocHRef *href = new DocHRef(parent,attrList,opt->value);
      children.append(href);
      g_insideHtmlLink=TRUE;
      retval = href->parse();
      g_insideHtmlLink=FALSE;
      break;
    }
    else // unsupported option for tag a
    {
    }
  }
  return retval;
}

942 943 944 945 946 947 948 949 950 951 952 953
const char *DocStyleChange::styleString() const
{
  switch (m_style)
  {
    case DocStyleChange::Bold:         return "b"; 
    case DocStyleChange::Italic:       return "em"; 
    case DocStyleChange::Code:         return "code"; 
    case DocStyleChange::Center:       return "center"; 
    case DocStyleChange::Small:        return "small"; 
    case DocStyleChange::Subscript:    return "subscript"; 
    case DocStyleChange::Superscript:  return "superscript"; 
    case DocStyleChange::Preformatted: return "pre"; 
954 955
    case DocStyleChange::Div:          return "div";
    case DocStyleChange::Span:         return "span";
956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973
  }
  return "<invalid>";
}

static void handleUnclosedStyleCommands()
{
  if (!g_initialStyleStack.isEmpty())
  {
    DocStyleChange *sc = g_initialStyleStack.top();
    g_initialStyleStack.pop();
    handleUnclosedStyleCommands();
    warn_doc_error(g_fileName,doctokenizerYYlineno,
             "Warning: end of comment block while expecting "
             "command </%s>",sc->styleString());
  }
}


974 975 976 977
static void handleLinkedWord(DocNode *parent,QList<DocNode> &children)
{
  Definition *compound=0;
  MemberDef  *member=0;
978
  QString name = linkToText(g_token->name,TRUE);
979
  int len = g_token->name.length();
980
  ClassDef *cd=0;
981
  //printf("handleLinkedWord(%s) g_context=%s\n",name.data(),g_context.data());
982
  if (!g_insideHtmlLink && 
983 984 985 986 987
      (resolveRef(g_context,g_token->name,g_inSeeBlock,&compound,&member)
       || (!g_context.isEmpty() &&  // also try with global scope
           resolveRef("",g_token->name,g_inSeeBlock,&compound,&member))
      )
     )
988
  {
989
    //printf("resolveRef %s = %p (linkable?=%d)\n",g_token->name.data(),member,member ? member->isLinkable() : FALSE);
990
    if (member && member->isLinkable()) // member link
991
    {
992 993 994 995 996
      if (member->isObjCMethod()) 
      {
        bool localLink = g_memberDef ? member->getClassDef()==g_memberDef->getClassDef() : FALSE;
        name = member->objCMethodName(localLink,g_inSeeBlock);
      }
997
      children.append(new 
998
          DocLinkedWord(parent,name,
999 1000
            member->getReference(),
            member->getOutputFileBase(),
1001 1002
            member->anchor(),
            member->briefDescriptionAsTooltip()
1003 1004 1005
                       )
                     );
    }
1006
    else if (compound->isLinkable()) // compound link
1007
    {
1008 1009 1010 1011
      if (compound->definitionType()==Definition::TypeFile)
      {
        name=g_token->name;
      }
1012 1013 1014 1015
      else if (compound->definitionType()==Definition::TypeGroup)
      {
        name=((GroupDef*)compound)->groupTitle();
      }
1016
      children.append(new 
1017
          DocLinkedWord(parent,name,
1018 1019
                        compound->getReference(),
                        compound->getOutputFileBase(),
1020 1021
                        "",
                        compound->briefDescriptionAsTooltip()
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032
                       )
                     );
    }
    else if (compound->definitionType()==Definition::TypeFile &&
             ((FileDef*)compound)->generateSourceFile()
            ) // undocumented file that has source code we can link to
    {
      children.append(new 
          DocLinkedWord(parent,g_token->name,
                         compound->getReference(),
                         compound->getSourceFileBase(),
1033 1034
                         "",
                         compound->briefDescriptionAsTooltip()
1035 1036 1037
                       )
                     );
    }
1038 1039 1040 1041
    else // not linkable
    {
      children.append(new DocWord(parent,name));
    }
1042
  }
1043
  else if (!g_insideHtmlLink && len>1 && g_token->name.at(len-1)==':')
1044 1045 1046 1047 1048 1049 1050
  {
    // special case, where matching Foo: fails to be an Obj-C reference, 
    // but Foo itself might be linkable.
    g_token->name=g_token->name.left(len-1);
    handleLinkedWord(parent,children);
    children.append(new DocWord(parent,":"));
  }
1051 1052 1053 1054 1055 1056 1057 1058
  else if (!g_insideHtmlLink && (cd=getClass(g_token->name+"-p")))
  {
    // special case 2, where the token name is not a class, but could
    // be a Obj-C protocol
    children.append(new 
        DocLinkedWord(parent,name,
          cd->getReference(),
          cd->getOutputFileBase(),
1059 1060 1061
          "",
          cd->briefDescriptionAsTooltip()
          ));
1062
  }
1063
  else // normal non-linkable word
1064
  {
1065 1066 1067 1068 1069
    if (g_token->name.at(0)=='#')
    {
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: explicit link request to '%s' could not be resolved",name.data());
    }
    children.append(new DocWord(parent,name));
1070 1071 1072
  }
}

1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084
/* Helper function that deals with the most common tokens allowed in
 * title like sections. 
 * @param parent     Parent node, owner of the children list passed as 
 *                   the third argument. 
 * @param tok        The token to process.
 * @param children   The list of child nodes to which the node representing
 *                   the token can be added.
 * @param handleWord Indicates if word token should be processed
 * @retval TRUE      The token was handled.
 * @retval FALSE     The token was not handled.
 */
static bool defaultHandleToken(DocNode *parent,int tok, QList<DocNode> &children,bool
1085
    handleWord)
1086 1087
{
  DBG(("token %s at %d",tokToString(tok),doctokenizerYYlineno));
1088
  if (tok==TK_WORD || tok==TK_LNKWORD || tok==TK_SYMBOL || tok==TK_URL || 
1089 1090 1091 1092 1093 1094
      tok==TK_COMMAND || tok==TK_HTMLTAG
     )
  {
    DBG((" name=%s",g_token->name.data()));
  }
  DBG(("\n"));
1095
reparsetoken:
1096
  QString tokenName = g_token->name;
1097 1098 1099
  switch (tok)
  {
    case TK_COMMAND: 
1100
      switch (Mappers::cmdMapper->map(tokenName))
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128
      {
        case CMD_BSLASH:
          children.append(new DocSymbol(parent,DocSymbol::BSlash));
          break;
        case CMD_AT:
          children.append(new DocSymbol(parent,DocSymbol::At));
          break;
        case CMD_LESS:
          children.append(new DocSymbol(parent,DocSymbol::Less));
          break;
        case CMD_GREATER:
          children.append(new DocSymbol(parent,DocSymbol::Greater));
          break;
        case CMD_AMP:
          children.append(new DocSymbol(parent,DocSymbol::Amp));
          break;
        case CMD_DOLLAR:
          children.append(new DocSymbol(parent,DocSymbol::Dollar));
          break;
        case CMD_HASH:
          children.append(new DocSymbol(parent,DocSymbol::Hash));
          break;
        case CMD_PERCENT:
          children.append(new DocSymbol(parent,DocSymbol::Percent));
          break;
        case CMD_EMPHASIS:
          {
            children.append(new DocStyleChange(parent,g_nodeStack.count(),DocStyleChange::Italic,TRUE));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1129
            tok=handleStyleArgument(parent,children,tokenName);
1130
            children.append(new DocStyleChange(parent,g_nodeStack.count(),DocStyleChange::Italic,FALSE));
1131
            if (tok!=TK_WORD) children.append(new DocWhiteSpace(parent," "));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1132
            if (tok==TK_NEWPARA) goto handlepara;
1133 1134 1135 1136 1137
            else if (tok==TK_WORD || tok==TK_HTMLTAG) 
            {
	      DBG(("CMD_EMPHASIS: reparsing command %s\n",g_token->name.data()));
              goto reparsetoken;
            }
1138 1139 1140 1141 1142
          }
          break;
        case CMD_BOLD:
          {
            children.append(new DocStyleChange(parent,g_nodeStack.count(),DocStyleChange::Bold,TRUE));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1143
            tok=handleStyleArgument(parent,children,tokenName);
1144
            children.append(new DocStyleChange(parent,g_nodeStack.count(),DocStyleChange::Bold,FALSE));
1145
            if (tok!=TK_WORD) children.append(new DocWhiteSpace(parent," "));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1146
            if (tok==TK_NEWPARA) goto handlepara;
1147 1148 1149 1150 1151
            else if (tok==TK_WORD || tok==TK_HTMLTAG) 
            {
	      DBG(("CMD_BOLD: reparsing command %s\n",g_token->name.data()));
              goto reparsetoken;
            }
1152 1153 1154 1155 1156
          }
          break;
        case CMD_CODE:
          {
            children.append(new DocStyleChange(parent,g_nodeStack.count(),DocStyleChange::Code,TRUE));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1157
            tok=handleStyleArgument(parent,children,tokenName);
1158
            children.append(new DocStyleChange(parent,g_nodeStack.count(),DocStyleChange::Code,FALSE));
1159
            if (tok!=TK_WORD) children.append(new DocWhiteSpace(parent," "));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1160
            if (tok==TK_NEWPARA) goto handlepara;
1161 1162 1163 1164 1165
            else if (tok==TK_WORD || tok==TK_HTMLTAG) 
            {
	      DBG(("CMD_CODE: reparsing command %s\n",g_token->name.data()));
              goto reparsetoken;
            }
1166 1167 1168 1169 1170
          }
          break;
        case CMD_HTMLONLY:
          {
            doctokenizerYYsetStateHtmlOnly();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1171
            tok = doctokenizerYYlex();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1172
            children.append(new DocVerbatim(parent,g_context,g_token->verb,DocVerbatim::HtmlOnly,g_isExample,g_exampleName));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1173
            if (tok==0) warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: htmlonly section ended without end marker");
1174 1175 1176
            doctokenizerYYsetStatePara();
          }
          break;
1177 1178 1179 1180 1181 1182 1183 1184 1185
        case CMD_MANONLY:
          {
            doctokenizerYYsetStateManOnly();
            tok = doctokenizerYYlex();
            children.append(new DocVerbatim(parent,g_context,g_token->verb,DocVerbatim::ManOnly,g_isExample,g_exampleName));
            if (tok==0) warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: manonly section ended without end marker");
            doctokenizerYYsetStatePara();
          }
          break;
1186 1187 1188
        case CMD_LATEXONLY:
          {
            doctokenizerYYsetStateLatexOnly();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1189
            tok = doctokenizerYYlex();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1190
            children.append(new DocVerbatim(parent,g_context,g_token->verb,DocVerbatim::LatexOnly,g_isExample,g_exampleName));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1191
            if (tok==0) warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: latexonly section ended without end marker",doctokenizerYYlineno);
1192 1193 1194
            doctokenizerYYsetStatePara();
          }
          break;
1195 1196 1197 1198 1199 1200 1201 1202 1203
        case CMD_XMLONLY:
          {
            doctokenizerYYsetStateXmlOnly();
            tok = doctokenizerYYlex();
            children.append(new DocVerbatim(parent,g_context,g_token->verb,DocVerbatim::XmlOnly,g_isExample,g_exampleName));
            if (tok==0) warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: xmlonly section ended without end marker",doctokenizerYYlineno);
            doctokenizerYYsetStatePara();
          }
          break;
1204 1205 1206 1207 1208 1209
        case CMD_FORMULA:
          {
            DocFormula *form=new DocFormula(parent,g_token->id);
            children.append(form);
          }
          break;
1210 1211
        case CMD_ANCHOR:
          {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1212
            tok=doctokenizerYYlex();
1213 1214
            if (tok!=TK_WHITESPACE)
            {
1215
              warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected whitespace after %s command",
1216
                  tokenName.data());
1217 1218 1219 1220 1221
              break;
            }
            tok=doctokenizerYYlex();
            if (tok==0)
            {
1222
              warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected end of comment block while parsing the "
1223
                  "argument of command %s",tokenName.data());
1224 1225 1226 1227
              break;
            }
            else if (tok!=TK_WORD && tok!=TK_LNKWORD)
            {
1228
              warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected token %s as the argument of %s",
1229
                  tokToString(tok),tokenName.data());
1230 1231
              break;
            }
1232
            DocAnchor *anchor = new DocAnchor(parent,g_token->name,FALSE);
1233 1234 1235 1236 1237
            children.append(anchor);
          }
          break;
        case CMD_INTERNALREF:
          {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1238
            tok=doctokenizerYYlex();
1239 1240
            if (tok!=TK_WHITESPACE)
            {
1241
              warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected whitespace after %s command",
1242
                  tokenName.data());
1243 1244 1245 1246 1247 1248 1249
              break;
            }
            doctokenizerYYsetStateInternalRef();
            tok=doctokenizerYYlex(); // get the reference id
            DocInternalRef *ref=0;
            if (tok!=TK_WORD && tok!=TK_LNKWORD)
            {
1250
              warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected token %s as the argument of %s",
1251
                  tokToString(tok),tokenName.data());
1252 1253 1254 1255 1256 1257 1258 1259 1260
              doctokenizerYYsetStatePara();
              break;
            }
            ref = new DocInternalRef(parent,g_token->name);
            children.append(ref);
            ref->parse();
            doctokenizerYYsetStatePara();
          }
          break;
1261 1262 1263 1264 1265 1266
        default:
          return FALSE;
      }
      break;
    case TK_HTMLTAG:
      {
1267
        switch (Mappers::htmlTagMapper->map(tokenName))
1268
        {
1269 1270 1271 1272 1273 1274
          case HTML_DIV:
            warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: found <div> tag in heading\n");
            break;
          case HTML_PRE:
            warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: found <pre> tag in heading\n");
            break;
1275 1276 1277
          case HTML_BOLD:
            if (!g_token->endTag)
            {
1278
              handleStyleEnter(parent,children,DocStyleChange::Bold,&g_token->attribs);
1279 1280 1281 1282 1283 1284 1285
            }
            else
            {
              handleStyleLeave(parent,children,DocStyleChange::Bold,tokenName);
            }
            break;
          case HTML_CODE:
1286
          case XML_C:
1287 1288
            if (!g_token->endTag)
            {
1289
              handleStyleEnter(parent,children,DocStyleChange::Code,&g_token->attribs);
1290 1291 1292 1293 1294 1295 1296 1297 1298
            }
            else
            {
              handleStyleLeave(parent,children,DocStyleChange::Code,tokenName);
            }
            break;
          case HTML_EMPHASIS:
            if (!g_token->endTag)
            {
1299
              handleStyleEnter(parent,children,DocStyleChange::Italic,&g_token->attribs);
1300 1301 1302 1303 1304 1305 1306 1307 1308
            }
            else
            {
              handleStyleLeave(parent,children,DocStyleChange::Italic,tokenName);
            }
            break;
          case HTML_SUB:
            if (!g_token->endTag)
            {
1309
              handleStyleEnter(parent,children,DocStyleChange::Subscript,&g_token->attribs);
1310 1311 1312 1313 1314 1315 1316 1317 1318
            }
            else
            {
              handleStyleLeave(parent,children,DocStyleChange::Subscript,tokenName);
            }
            break;
          case HTML_SUP:
            if (!g_token->endTag)
            {
1319
              handleStyleEnter(parent,children,DocStyleChange::Superscript,&g_token->attribs);
1320 1321 1322 1323 1324 1325 1326 1327 1328
            }
            else
            {
              handleStyleLeave(parent,children,DocStyleChange::Superscript,tokenName);
            }
            break;
          case HTML_CENTER:
            if (!g_token->endTag)
            {
1329
              handleStyleEnter(parent,children,DocStyleChange::Center,&g_token->attribs);
1330 1331 1332 1333 1334 1335 1336 1337 1338
            }
            else
            {
              handleStyleLeave(parent,children,DocStyleChange::Center,tokenName);
            }
            break;
          case HTML_SMALL:
            if (!g_token->endTag)
            {
1339
              handleStyleEnter(parent,children,DocStyleChange::Small,&g_token->attribs);
1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373
            }
            else
            {
              handleStyleLeave(parent,children,DocStyleChange::Small,tokenName);
            }
            break;
          default:
            return FALSE;
            break;
        }
      }
      break;
    case TK_SYMBOL: 
      {
        char letter='\0';
        DocSymbol::SymType s = DocSymbol::decodeSymbol(tokenName,&letter);
        if (s!=DocSymbol::Unknown)
        {
          children.append(new DocSymbol(parent,s,letter));
        }
        else
        {
          return FALSE;
        }
      }
      break;
    case TK_WHITESPACE: 
    case TK_NEWPARA: 
handlepara:
      if (insidePRE(parent) || !children.isEmpty())
      {
        children.append(new DocWhiteSpace(parent,g_token->chars));
      }
      break;
1374 1375 1376 1377 1378 1379 1380 1381
    case TK_LNKWORD: 
      if (handleWord)
      {
        handleLinkedWord(parent,children);
      }
      else
        return FALSE;
      break;
1382 1383
    case TK_WORD: 
      if (handleWord)
1384
      {
1385
        children.append(new DocWord(parent,g_token->name));
1386
      }
1387 1388 1389 1390
      else
        return FALSE;
      break;
    case TK_URL:
1391 1392 1393 1394 1395 1396 1397 1398
      if (g_insideHtmlLink)
      {
        children.append(new DocWord(parent,g_token->name));
      }
      else
      {
        children.append(new DocURL(parent,g_token->name,g_token->isEMailAddr));
      }
1399 1400 1401 1402 1403 1404 1405 1406 1407 1408
      break;
    default:
      return FALSE;
  }
  return TRUE;
}


//---------------------------------------------------------------------------

1409
DocSymbol::SymType DocSymbol::decodeSymbol(const QString &symName,char *letter)
1410 1411 1412 1413
{
  int l=symName.length();
  DBG(("decodeSymbol(%s) l=%d\n",symName.data(),l));
  if      (symName=="&copy;")  return DocSymbol::Copy;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1414
  else if (symName=="&trade;") return DocSymbol::Tm;
1415
  else if (symName=="&tm;")    return DocSymbol::Tm; // alias for &trace;
1416
  else if (symName=="&reg;")   return DocSymbol::Reg;
1417 1418 1419 1420 1421
  else if (symName=="&lt;")    return DocSymbol::Less;
  else if (symName=="&gt;")    return DocSymbol::Greater;
  else if (symName=="&amp;")   return DocSymbol::Amp;
  else if (symName=="&apos;")  return DocSymbol::Apos;
  else if (symName=="&quot;")  return DocSymbol::Quot;
1422 1423 1424 1425 1426 1427
  else if (symName=="&lsquo;") return DocSymbol::Lsquo;
  else if (symName=="&rsquo;") return DocSymbol::Rsquo;
  else if (symName=="&ldquo;") return DocSymbol::Ldquo;
  else if (symName=="&rdquo;") return DocSymbol::Rdquo;
  else if (symName=="&ndash;") return DocSymbol::Ndash;
  else if (symName=="&mdash;") return DocSymbol::Mdash;
1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464
  else if (symName=="&szlig;") return DocSymbol::Szlig;
  else if (symName=="&nbsp;")  return DocSymbol::Nbsp;
  else if (l==6 && symName.right(4)=="uml;")  
  {
    *letter=symName.at(1);
    return DocSymbol::Uml;
  }
  else if (l==8 && symName.right(6)=="acute;")  
  {
    *letter=symName.at(1);
    return DocSymbol::Acute;
  }
  else if (l==8 && symName.right(6)=="grave;")
  {
    *letter=symName.at(1);
    return DocSymbol::Grave;
  }
  else if (l==7 && symName.right(5)=="circ;")
  {
    *letter=symName.at(1);
    return DocSymbol::Circ;
  }
  else if (l==8 && symName.right(6)=="tilde;")
  {
    *letter=symName.at(1);
    return DocSymbol::Tilde;
  }
  else if (l==8 && symName.right(6)=="cedil;")
  {
    *letter=symName.at(1);
    return DocSymbol::Cedil;
  }
  else if (l==7 && symName.right(5)=="ring;")
  {
    *letter=symName.at(1);
    return DocSymbol::Ring;
  }
1465 1466 1467 1468 1469
  else if (l==8 && symName.right(6)=="slash;")
  {
    *letter=symName.at(1);
    return DocSymbol::Slash;
  }
1470 1471 1472 1473 1474
  return DocSymbol::Unknown;
}

//---------------------------------------------------------------------------

1475
static int internalValidatingParseDoc(DocNode *parent,QList<DocNode> &children,
1476
                                    const QString &doc)
1477 1478 1479
{
  int retval = RetVal_OK;

Dimitri van Heesch's avatar
Dimitri van Heesch committed
1480 1481
  if (doc.isEmpty()) return retval;

Dimitri van Heesch's avatar
Dimitri van Heesch committed
1482
  doctokenizerYYinit(doc,g_fileName);
1483 1484

  // first parse any number of paragraphs
1485
  bool isFirst=TRUE;
1486
  DocPara *lastPar=0;
1487 1488 1489 1490 1491
  if (!children.isEmpty() && children.last()->kind()==DocNode::Kind_Para)
  { // last child item was a paragraph
    lastPar = (DocPara*)children.last();
    isFirst=FALSE;
  }
1492 1493 1494 1495 1496 1497 1498 1499
  do
  {
    DocPara *par = new DocPara(parent);
    if (isFirst) { par->markFirst(); isFirst=FALSE; }
    retval=par->parse();
    if (!par->isEmpty()) 
    {
      children.append(par);
1500
      if (lastPar) lastPar->markLast(FALSE);
1501 1502
      lastPar=par;
    }
1503 1504 1505 1506
    else
    {
      delete par;
    }
1507 1508 1509 1510 1511 1512 1513 1514
  } while (retval==TK_NEWPARA);
  if (lastPar) lastPar->markLast();

  return retval;
}

//---------------------------------------------------------------------------

1515
static void readTextFileByName(const QString &file,QString &text)
1516 1517 1518 1519 1520
{
  bool ambig;
  FileDef *fd;
  if ((fd=findFileDef(Doxygen::exampleNameDict,file,ambig)))
  {
1521
    text = fileToString(fd->absFilePath(),Config_getBool("FILTER_SOURCE_FILES"));
1522 1523 1524
  }
  else if (ambig)
  {
1525
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: included file name %s is ambigious"
1526
           "Possible candidates:\n%s",file.data(),
1527 1528 1529 1530 1531
           showFileDefMatches(Doxygen::exampleNameDict,file).data()
          );
  }
  else
  {
1532 1533
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: included file %s is not found. "
           "Check your EXAMPLE_PATH",file.data());
1534 1535 1536 1537 1538
  }
}

//---------------------------------------------------------------------------

1539 1540 1541 1542 1543 1544
DocWord::DocWord(DocNode *parent,const QString &word) : 
      m_parent(parent), m_word(word) 
{
  //printf("new word %s url=%s\n",word.data(),g_searchUrl.data());
  if (!g_searchUrl.isEmpty())
  {
1545
    Doxygen::searchIndex->addWord(word,FALSE);
1546 1547 1548 1549 1550 1551 1552
  }
}

//---------------------------------------------------------------------------

DocLinkedWord::DocLinkedWord(DocNode *parent,const QString &word,
                  const QString &ref,const QString &file,
1553
                  const QString &anchor,const QString &tooltip) : 
1554
      m_parent(parent), m_word(word), m_ref(ref), 
1555 1556
      m_file(file), m_relPath(g_relPath), m_anchor(anchor),
      m_tooltip(tooltip)
1557 1558 1559 1560
{
  //printf("new word %s url=%s\n",word.data(),g_searchUrl.data());
  if (!g_searchUrl.isEmpty())
  {
1561
    Doxygen::searchIndex->addWord(word,FALSE);
1562 1563 1564 1565 1566
  }
}

//---------------------------------------------------------------------------

1567
DocAnchor::DocAnchor(DocNode *parent,const QString &id,bool newAnchor) 
1568 1569 1570 1571
  : m_parent(parent)
{
  if (id.isEmpty())
  {
1572
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Empty anchor label");
1573 1574 1575 1576 1577 1578 1579 1580 1581 1582
  }
  if (newAnchor) // found <a name="label">
  {
    m_anchor = id;
  }
  else // found \anchor label
  {
    SectionInfo *sec = Doxygen::sectionDict[id];
    if (sec)
    {
1583
      //printf("Found anchor %s\n",id.data());
1584 1585
      m_file   = sec->fileName;
      m_anchor = sec->label;
1586 1587
      if (g_sectionDict && g_sectionDict->find(id)==0)
      {
1588
        //printf("Inserting in dictionary!\n");
1589 1590
        g_sectionDict->insert(id,sec);
      }
1591 1592 1593
    }
    else
    {
1594
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Invalid anchor id `%s'",id.data());
1595 1596
      m_anchor = "invalid";
      m_file = "invalid";
1597 1598 1599 1600
    }
  }
}

1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611
//---------------------------------------------------------------------------

DocVerbatim::DocVerbatim(DocNode *parent,const QString &context,
    const QString &text, Type t,bool isExample,
    const QString &exampleFile) 
  : m_parent(parent), m_context(context), m_text(text), m_type(t),
    m_isExample(isExample), m_exampleFile(exampleFile), m_relPath(g_relPath) 
{
}


1612 1613 1614 1615
//---------------------------------------------------------------------------

void DocInclude::parse()
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1616
  DBG(("DocInclude::parse(file=%s,text=%s)\n",m_file.data(),m_text.data()));
1617 1618
  switch(m_type)
  {
1619 1620
    case IncWithLines:
      // fall through
1621 1622 1623 1624 1625 1626 1627
    case Include:
      // fall through
    case DontInclude:
      readTextFileByName(m_file,m_text);
      g_includeFileText   = m_text;
      g_includeFileOffset = 0;
      g_includeFileLength = m_text.length();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1628
      //printf("g_includeFile=<<%s>>\n",g_includeFileText.data());
1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644
      break;
    case VerbInclude: 
      // fall through
    case HtmlInclude:
      readTextFileByName(m_file,m_text);
      break;
  }
}

//---------------------------------------------------------------------------

void DocIncOperator::parse()
{
  const char *p = g_includeFileText;
  uint l = g_includeFileLength;
  uint o = g_includeFileOffset;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1645
  DBG(("DocIncOperator::parse() text=%s off=%d len=%d\n",p,o,l));
1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658
  uint so = o,bo;
  bool nonEmpty = FALSE;
  switch(type())
  {
    case Line:
      while (o<l)
      {
        char c = p[o];
        if (c=='\n') 
        {
          if (nonEmpty) break; // we have a pattern to match
          so=o+1; // no pattern, skip empty line
        }
1659
        else if (!isspace((uchar)c)) // no white space char
1660 1661 1662 1663 1664 1665 1666 1667
        {
          nonEmpty=TRUE;
        }
        o++;
      }
      if (g_includeFileText.mid(so,o-so).find(m_pattern)!=-1)
      {
        m_text = g_includeFileText.mid(so,o-so);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1668
        DBG(("DocIncOperator::parse() Line: %s\n",m_text.data()));
1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683
      }
      g_includeFileOffset = QMIN(l,o+1); // set pointer to start of new line
      break;
    case SkipLine:
      while (o<l)
      {
        so=o;
        while (o<l)
        {
          char c = p[o];
          if (c=='\n')
          {
            if (nonEmpty) break; // we have a pattern to match
            so=o+1; // no pattern, skip empty line
          }
1684
          else if (!isspace((uchar)c)) // no white space char
1685 1686 1687 1688 1689 1690 1691 1692
          {
            nonEmpty=TRUE;
          }
          o++;
        }
        if (g_includeFileText.mid(so,o-so).find(m_pattern)!=-1)
        {
          m_text = g_includeFileText.mid(so,o-so);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1693
          DBG(("DocIncOperator::parse() SkipLine: %s\n",m_text.data()));
1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711
          break;
        }
        o++; // skip new line
      }
      g_includeFileOffset = QMIN(l,o+1); // set pointer to start of new line
      break;
    case Skip:
      while (o<l)
      {
        so=o;
        while (o<l)
        {
          char c = p[o];
          if (c=='\n')
          {
            if (nonEmpty) break; // we have a pattern to match
            so=o+1; // no pattern, skip empty line
          }
1712
          else if (!isspace((uchar)c)) // no white space char
1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738
          {
            nonEmpty=TRUE;
          }
          o++;
        }
        if (g_includeFileText.mid(so,o-so).find(m_pattern)!=-1)
        {
          break;
        }
        o++; // skip new line
      }
      g_includeFileOffset = so; // set pointer to start of new line
      break;
    case Until:
      bo=o;
      while (o<l)
      {
        so=o;
        while (o<l)
        {
          char c = p[o];
          if (c=='\n')
          {
            if (nonEmpty) break; // we have a pattern to match
            so=o+1; // no pattern, skip empty line
          }
1739
          else if (!isspace((uchar)c)) // no white space char
1740 1741 1742 1743 1744 1745 1746 1747
          {
            nonEmpty=TRUE;
          }
          o++;
        }
        if (g_includeFileText.mid(so,o-so).find(m_pattern)!=-1)
        {
          m_text = g_includeFileText.mid(bo,o-bo);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1748
          DBG(("DocIncOperator::parse() Until: %s\n",m_text.data()));
1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761
          break;
        }
        o++; // skip new line
      }
      g_includeFileOffset = QMIN(l,o+1); // set pointer to start of new line
      break;
  }
}

//---------------------------------------------------------------------------

void DocCopy::parse()
{
1762
  QString doc,brief;
1763
  Definition *def;
1764
  if (findDocsForMemberOrCompound(m_link,&doc,&brief,&def))
1765 1766 1767
  {
    if (g_copyStack.findRef(def)==-1) // definition not parsed earlier
    {
1768 1769 1770 1771 1772 1773 1774
      bool         hasParamCommand  = g_hasParamCommand;
      bool         hasReturnCommand = g_hasReturnCommand;
      QDict<void>  paramsFound      = g_paramsFound;
      //printf("..1 hasParamCommand=%d hasReturnCommand=%d paramsFound=%d\n",
      //      g_hasParamCommand,g_hasReturnCommand,g_paramsFound.count());

      docParserPushContext(FALSE);
1775 1776 1777 1778 1779 1780 1781 1782
      if (def->definitionType()==Definition::TypeMember && def->getOuterScope())
      {
        g_context=def->getOuterScope()->name();
      }
      else
      {
        g_context=def->name();
      }
1783 1784 1785
      g_styleStack.clear();
      g_nodeStack.clear();
      g_copyStack.append(def);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1786 1787
      // make sure the descriptions end with a newline, so the parser will correctly
      // handle them in all cases.
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1788 1789
      //printf("doc='%s'\n",doc.data());
      //printf("brief='%s'\n",brief.data());
1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821
      if (m_copyBrief)
      {
        brief+='\n';
        internalValidatingParseDoc(this,m_children,brief);

        //printf("..2 hasParamCommand=%d hasReturnCommand=%d paramsFound=%d\n",
        //    g_hasParamCommand,g_hasReturnCommand,g_paramsFound.count());
        hasParamCommand  = hasParamCommand  || g_hasParamCommand;
        hasReturnCommand = hasReturnCommand || g_hasReturnCommand;
        QDictIterator<void> it(g_paramsFound);
        void *item;
        for (;(item=it.current());++it)
        {
          paramsFound.insert(it.currentKey(),it.current());
        }
      }
      if (m_copyDetails)
      {
        doc+='\n';
        internalValidatingParseDoc(this,m_children,doc);

        //printf("..3 hasParamCommand=%d hasReturnCommand=%d paramsFound=%d\n",
        //    g_hasParamCommand,g_hasReturnCommand,g_paramsFound.count());
        hasParamCommand  = hasParamCommand  || g_hasParamCommand;
        hasReturnCommand = hasReturnCommand || g_hasReturnCommand;
        QDictIterator<void> it(g_paramsFound);
        void *item;
        for (;(item=it.current());++it)
        {
          paramsFound.insert(it.currentKey(),it.current());
        }
      }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1822
      g_copyStack.remove(def);
1823 1824
      ASSERT(g_styleStack.isEmpty());
      ASSERT(g_nodeStack.isEmpty());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1825
      docParserPopContext(TRUE);
1826 1827 1828 1829 1830 1831 1832

      g_hasParamCommand  = hasParamCommand;
      g_hasReturnCommand = hasReturnCommand;
      g_paramsFound      = paramsFound;

      //printf("..4 hasParamCommand=%d hasReturnCommand=%d paramsFound=%d\n",
      //      g_hasParamCommand,g_hasReturnCommand,g_paramsFound.count());
1833 1834 1835
    }
    else // oops, recursion
    {
1836
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: recursive call chain of \\copydoc commands detected at %d\n",
1837 1838 1839 1840 1841
          doctokenizerYYlineno);
    }
  }
  else
  {
1842
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: target %s of \\copydoc command not found",
1843
        m_link.data());
1844 1845 1846 1847 1848
  }
}

//---------------------------------------------------------------------------

1849 1850 1851 1852 1853 1854
DocXRefItem::DocXRefItem(DocNode *parent,int id,const char *key) : 
   m_parent(parent), m_id(id), m_key(key), m_relPath(g_relPath)
{
}

bool DocXRefItem::parse()
1855
{
1856
  QString listName;
1857 1858 1859 1860 1861 1862 1863 1864 1865 1866
  RefList *refList = Doxygen::xrefLists->find(m_key); 
  if (refList && 
      (
       // either not a built-in list or the list is enabled
       (m_key!="todo"       || Config_getBool("GENERATE_TODOLIST")) && 
       (m_key!="test"       || Config_getBool("GENERATE_TESTLIST")) && 
       (m_key!="bug"        || Config_getBool("GENERATE_BUGLIST"))  && 
       (m_key!="deprecated" || Config_getBool("GENERATE_DEPRECATEDLIST"))
      ) 
     )
1867 1868 1869
  {
    RefItem *item = refList->getRefItem(m_id);
    ASSERT(item!=0);
1870
    if (item)
1871
    {
1872 1873 1874 1875 1876 1877 1878 1879 1880 1881
      if (g_memberDef && g_memberDef->name().at(0)=='@')
      {
        m_file   = "@";  // can't cross reference anonymous enum
        m_anchor = "@";
      }
      else
      {
        m_file   = refList->listName();
        m_anchor = item->listAnchor;
      }
1882
      m_title  = refList->sectionTitle();
1883 1884
      //printf("DocXRefItem: file=%s anchor=%s title=%s\n",
      //    m_file.data(),m_anchor.data(),m_title.data());
1885 1886 1887 1888 1889 1890 1891

      if (!item->text.isEmpty())
      {
        docParserPushContext();
        internalValidatingParseDoc(this,m_children,item->text);
        docParserPopContext();
      }
1892
    }
1893
    return TRUE;
1894
  }
1895
  return FALSE;
1896 1897 1898 1899 1900
}

//---------------------------------------------------------------------------

DocFormula::DocFormula(DocNode *parent,int id) :
1901
      m_parent(parent), m_relPath(g_relPath)
1902
{
1903
  QString formCmd;
1904 1905 1906 1907
  formCmd.sprintf("\\form#%d",id);
  Formula *formula=Doxygen::formulaNameDict[formCmd];
  if (formula)
  {
1908 1909
    m_id = formula->getId();
    m_name.sprintf("form_%d",m_id);
1910 1911 1912 1913 1914 1915
    m_text = formula->getFormulaText();
  }
}

//---------------------------------------------------------------------------

1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939
//int DocLanguage::parse()
//{
//  int retval;
//  DBG(("DocLanguage::parse() start\n"));
//  g_nodeStack.push(this);
//
//  // parse one or more paragraphs
//  bool isFirst=TRUE;
//  DocPara *par=0;
//  do
//  {
//    par = new DocPara(this);
//    if (isFirst) { par->markFirst(); isFirst=FALSE; }
//    m_children.append(par);
//    retval=par->parse();
//  }
//  while (retval==TK_NEWPARA);
//  if (par) par->markLast();
//
//  DBG(("DocLanguage::parse() end\n"));
//  DocNode *n = g_nodeStack.pop();
//  ASSERT(n==this);
//  return retval;
//}
1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956

//---------------------------------------------------------------------------

void DocSecRefItem::parse()
{
  DBG(("DocSecRefItem::parse() start\n"));
  g_nodeStack.push(this);

  doctokenizerYYsetStateTitle();
  int tok;
  while ((tok=doctokenizerYYlex()))
  {
    if (!defaultHandleToken(this,tok,m_children))
    {
      switch (tok)
      {
        case TK_COMMAND: 
1957
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Illegal command %s as part of a \\refitem",
1958
	       g_token->name.data());
1959 1960
          break;
        case TK_SYMBOL: 
1961
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unsupported symbol %s found",
1962
               g_token->name.data());
1963 1964
          break;
        default:
1965
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected token %s",
1966
	       tokToString(tok));
1967 1968 1969 1970 1971 1972
          break;
      }
    }
  }
  doctokenizerYYsetStatePara();
  handlePendingStyleCommands(this,m_children);
1973 1974 1975 1976 1977 1978 1979 1980 1981

  SectionInfo *sec=0;
  if (!m_target.isEmpty())
  {
    sec=Doxygen::sectionDict[m_target];
    if (sec)
    {
      m_file   = sec->fileName;
      m_anchor = sec->label;
1982 1983 1984 1985
      if (g_sectionDict && g_sectionDict->find(m_target)==0)
      {
        g_sectionDict->insert(m_target,sec);
      }
1986 1987 1988
    }
    else
    {
1989
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning reference to unknown section %s",
1990
          m_target.data());
1991 1992 1993 1994
    }
  } 
  else
  {
1995
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning reference to empty target");
1996 1997
  }
  
1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011
  DBG(("DocSecRefItem::parse() end\n"));
  DocNode *n = g_nodeStack.pop();
  ASSERT(n==this);
}

//---------------------------------------------------------------------------

void DocSecRefList::parse()
{
  DBG(("DocSecRefList::parse() start\n"));
  g_nodeStack.push(this);

  int tok=doctokenizerYYlex();
  // skip white space
2012
  while (tok==TK_WHITESPACE || tok==TK_NEWPARA) tok=doctokenizerYYlex();
2013 2014 2015 2016 2017
  // handle items
  while (tok)
  {
    if (tok==TK_COMMAND)
    {
2018
      switch (Mappers::cmdMapper->map(g_token->name))
2019 2020 2021 2022 2023 2024
      {
        case CMD_SECREFITEM:
          {
            int tok=doctokenizerYYlex();
            if (tok!=TK_WHITESPACE)
            {
2025
              warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected whitespace after \\refitem command");
2026 2027 2028
              break;
            }
            tok=doctokenizerYYlex();
2029
            if (tok!=TK_WORD && tok!=TK_LNKWORD)
2030
            {
2031
              warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected token %s as the argument of \\refitem",
2032
                  tokToString(tok));
2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043
              break;
            }

            DocSecRefItem *item = new DocSecRefItem(this,g_token->name);
            m_children.append(item);
            item->parse();
          }
          break;
        case CMD_ENDSECREFLIST:
          goto endsecreflist;
        default:
2044
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Illegal command %s as part of a \\secreflist",
2045
              g_token->name.data());
2046 2047 2048
          goto endsecreflist;
      }
    }
2049 2050 2051 2052
    else if (tok==TK_WHITESPACE)
    {
      // ignore whitespace
    }
2053 2054
    else
    {
2055
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected token %s inside section reference list",
2056
          tokToString(tok));
2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067
      goto endsecreflist;
    }
    tok=doctokenizerYYlex();
  }

endsecreflist:
  DBG(("DocSecRefList::parse() end\n"));
  DocNode *n = g_nodeStack.pop();
  ASSERT(n==this);
}

2068 2069
//---------------------------------------------------------------------------

2070
DocInternalRef::DocInternalRef(DocNode *parent,const QString &ref) 
2071
  : m_parent(parent), m_relPath(g_relPath)
2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083
{
  int i=ref.find('#');
  if (i!=-1)
  {
    m_anchor = ref.right(ref.length()-i-1);
    m_file   = ref.left(i);
  }
  else
  {
    m_file = ref;
  }
}
2084

2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097
void DocInternalRef::parse()
{
  g_nodeStack.push(this);
  DBG(("DocInternalRef::parse() start\n"));

  int tok;
  while ((tok=doctokenizerYYlex()))
  {
    if (!defaultHandleToken(this,tok,m_children))
    {
      switch (tok)
      {
        case TK_COMMAND: 
2098
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Illegal command %s as part of a \\ref",
2099
	       g_token->name.data());
2100 2101
          break;
        case TK_SYMBOL: 
2102
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unsupported symbol %s found",
2103
               g_token->name.data());
2104 2105
          break;
        default:
2106
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected token %s",
2107
		tokToString(tok));
2108 2109 2110 2111 2112 2113 2114 2115 2116 2117
          break;
      }
    }
  }

  handlePendingStyleCommands(this,m_children);
  DBG(("DocInternalRef::parse() end\n"));
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
}
2118 2119 2120

//---------------------------------------------------------------------------

2121
DocRef::DocRef(DocNode *parent,const QString &target,const QString &context) : 
2122 2123 2124
   m_parent(parent), m_refToSection(FALSE), m_refToAnchor(FALSE)
{
  Definition  *compound = 0;
2125
  QCString     anchor;
2126
  //printf("DocRef::DocRef(target=%s,context=%s\n",target.data(),context.data());
2127
  ASSERT(!target.isEmpty());
2128
  m_relPath = g_relPath;
2129 2130 2131 2132 2133 2134 2135 2136
  SectionInfo *sec = Doxygen::sectionDict[target];
  if (sec) // ref to section or anchor
  {
    m_text         = sec->title;
    if (m_text.isEmpty()) m_text = sec->label;

    m_ref          = sec->ref;
    m_file         = stripKnownExtensions(sec->fileName);
2137
    if (sec->type!=SectionInfo::Page) m_anchor = sec->label;
2138 2139
    m_refToAnchor  = sec->type==SectionInfo::Anchor;
    m_refToSection = sec->type!=SectionInfo::Anchor;
2140 2141
    //printf("m_text=%s,m_ref=%s,m_file=%s,m_refToAnchor=%d type=%d\n",
    //    m_text.data(),m_ref.data(),m_file.data(),m_refToAnchor,sec->type);
2142
    return;
2143
  }
2144
  else if (resolveLink(context,target,TRUE,&compound,anchor))
2145
  {
2146 2147 2148 2149
    bool isFile = compound ? 
                 (compound->definitionType()==Definition::TypeFile ? TRUE : FALSE) : 
                 FALSE;
    m_text = linkToText(target,isFile);
2150
    m_anchor = anchor;
2151
    if (compound && compound->isLinkable()) // ref to compound
2152
    {
2153 2154 2155 2156 2157
      if (anchor.isEmpty() &&                                  /* compound link */
          compound->definitionType()==Definition::TypeGroup && /* is group */
          ((GroupDef *)compound)->groupTitle()                 /* with title */
         )
      {
2158 2159 2160 2161 2162 2163 2164 2165 2166
        m_text=((GroupDef *)compound)->groupTitle(); // use group's title as link
      }
      else if (compound->definitionType()==Definition::TypeMember &&
          ((MemberDef*)compound)->isObjCMethod())
      {
        // Objective C Method
        MemberDef *member = (MemberDef*)compound;
        bool localLink = g_memberDef ? member->getClassDef()==g_memberDef->getClassDef() : FALSE;
        m_text = member->objCMethodName(localLink,g_inSeeBlock);
2167 2168
      }

2169 2170
      m_file = compound->getOutputFileBase();
      m_ref  = compound->getReference();
2171
      return;
2172
    }
2173 2174 2175
    else if (compound->definitionType()==Definition::TypeFile && 
             ((FileDef*)compound)->generateSourceFile()
            ) // undocumented file that has source code we can link to
2176
    {
2177 2178 2179
      m_file = compound->getSourceFileBase();
      m_ref  = compound->getReference();
      return;
2180
    }
2181
  }
2182 2183
  m_text = linkToText(target,FALSE);
  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unable to resolve reference to `%s' for \\ref command",
2184
           target.data()); 
2185 2186
}

2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214
static void flattenParagraphs(QList<DocNode> &children)
{
  QListIterator<DocNode> li(children);
  QList<DocNode> newChildren;
  DocNode *dn;
  for (li.toFirst();(dn=li.current());++li)
  {
    if (dn->kind()==DocNode::Kind_Para)
    {
      DocPara *para = (DocPara*)dn;
      QList<DocNode> &paraChildren = para->children();
      paraChildren.setAutoDelete(FALSE); // unlink children from paragraph node
      QListIterator<DocNode> li2(paraChildren);
      DocNode *dn2;
      for (li2.toFirst();(dn2=li2.current());++li2)
      {
        newChildren.append(dn2); // add them to new node
      }
    }
  }
  children.clear();
  QListIterator<DocNode> li3(newChildren);
  for (li3.toFirst();(dn=li3.current());++li3)
  {
    children.append(dn);
  }
}

2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227
void DocRef::parse()
{
  g_nodeStack.push(this);
  DBG(("DocRef::parse() start\n"));

  int tok;
  while ((tok=doctokenizerYYlex()))
  {
    if (!defaultHandleToken(this,tok,m_children))
    {
      switch (tok)
      {
        case TK_COMMAND: 
2228
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Illegal command %s as part of a \\ref",
2229
	       g_token->name.data());
2230 2231
          break;
        case TK_SYMBOL: 
2232
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unsupported symbol %s found",
2233
               g_token->name.data());
2234
          break;
2235 2236
        case TK_HTMLTAG:
          break;
2237
        default:
2238
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected token %s",
2239
		tokToString(tok));
2240 2241 2242 2243 2244
          break;
      }
    }
  }

2245 2246 2247 2248 2249 2250 2251
  if (m_children.isEmpty() && !m_text.isEmpty())
  {
    g_insideHtmlLink=TRUE;
    docParserPushContext();
    internalValidatingParseDoc(this,m_children,m_text);
    docParserPopContext();
    g_insideHtmlLink=FALSE;
2252
    flattenParagraphs(m_children);
2253 2254
  }

2255
  handlePendingStyleCommands(this,m_children);
2256
  
2257 2258 2259 2260 2261 2262
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
}

//---------------------------------------------------------------------------

2263
DocLink::DocLink(DocNode *parent,const QString &target) : 
2264 2265 2266
      m_parent(parent)
{
  Definition *compound;
2267
  //PageInfo *page;
2268
  QCString anchor;
2269
  m_refText = target;
2270
  m_relPath = g_relPath;
2271 2272 2273 2274
  if (!m_refText.isEmpty() && m_refText.at(0)=='#')
  {
    m_refText = m_refText.right(m_refText.length()-1);
  }
2275
  if (resolveLink(g_context,stripKnownExtensions(target),g_inSeeBlock,
2276
                  &compound,anchor))
2277
  {
2278
    m_anchor = anchor;
2279
    if (compound && compound->isLinkable())
2280 2281 2282 2283
    {
      m_file = compound->getOutputFileBase();
      m_ref  = compound->getReference();
    }
2284 2285 2286 2287 2288 2289 2290 2291
    else if (compound->definitionType()==Definition::TypeFile && 
             ((FileDef*)compound)->generateSourceFile()
            ) // undocumented file that has source code we can link to
    {
      m_file = compound->getSourceFileBase();
      m_ref  = compound->getReference();
    }
    return;
2292
  }
2293 2294 2295 2296

  // bogus link target
  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unable to resolve link to `%s' for \\link command",
         target.data()); 
2297 2298 2299
}


2300
QString DocLink::parse(bool isJavaLink,bool isXmlLink)
2301
{
2302
  QString result;
2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313
  g_nodeStack.push(this);
  DBG(("DocLink::parse() start\n"));

  int tok;
  while ((tok=doctokenizerYYlex()))
  {
    if (!defaultHandleToken(this,tok,m_children,FALSE))
    {
      switch (tok)
      {
        case TK_COMMAND: 
2314
          switch (Mappers::cmdMapper->map(g_token->name))
2315 2316 2317 2318
          {
            case CMD_ENDLINK:
              if (isJavaLink)
              {
2319
                warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: {@link.. ended with @endlink command");
2320 2321 2322
              }
              goto endlink;
            default:
2323
              warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Illegal command %s as part of a \\link",
2324
                  g_token->name.data());
2325 2326 2327 2328
              break;
          }
          break;
        case TK_SYMBOL: 
2329
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unsupported symbol %s found",
2330
              g_token->name.data());
2331
          break;
2332 2333 2334 2335 2336 2337 2338
        case TK_HTMLTAG:
          if (g_token->name!="see" || !isXmlLink)
          {
            warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected xml/html command %s found",
                g_token->name.data());
          }
          goto endlink;
2339
        case TK_LNKWORD: 
2340 2341 2342
        case TK_WORD: 
          if (isJavaLink) // special case to detect closing }
          {
2343
            QString w = g_token->name;
2344 2345 2346 2347 2348 2349 2350
            int p;
            if (w=="}")
            {
              goto endlink;
            }
            else if ((p=w.find('}'))!=-1)
            {
2351
              uint l=w.length();
2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362
              m_children.append(new DocWord(this,w.left(p)));
              if ((uint)p<l-1) // something left after the } (for instance a .)
              {
                result=w.right(l-p-1);
              }
              goto endlink;
            }
          }
          m_children.append(new DocWord(this,g_token->name));
          break;
        default:
2363
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected token %s",
2364
             tokToString(tok));
2365 2366 2367 2368 2369 2370
        break;
      }
    }
  }
  if (tok==0)
  {
2371
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected end of comment while inside"
2372
           " link command\n"); 
2373 2374 2375
  }
endlink:

2376
  if (m_children.isEmpty()) // no link text
2377
  {
2378
    m_children.append(new DocWord(this,m_refText));
2379 2380
  }

2381 2382 2383 2384 2385 2386 2387 2388 2389 2390
  handlePendingStyleCommands(this,m_children);
  DBG(("DocLink::parse() end\n"));
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return result;
}


//---------------------------------------------------------------------------

2391 2392
DocDotFile::DocDotFile(DocNode *parent,const QString &name,const QString &context) : 
      m_parent(parent), m_name(name), m_relPath(g_relPath), m_context(context)
2393 2394 2395
{
}

2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409
void DocDotFile::parse()
{
  g_nodeStack.push(this);
  DBG(("DocDotFile::parse() start\n"));

  doctokenizerYYsetStateTitle();
  int tok;
  while ((tok=doctokenizerYYlex()))
  {
    if (!defaultHandleToken(this,tok,m_children))
    {
      switch (tok)
      {
        case TK_COMMAND: 
2410
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Illegal command %s as part of a \\dotfile",
2411
	       g_token->name.data());
2412 2413
          break;
        case TK_SYMBOL: 
2414
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unsupported symbol %s found",
2415
               g_token->name.data());
2416 2417
          break;
        default:
2418
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected token %s",
2419
		tokToString(tok));
2420 2421 2422 2423
          break;
      }
    }
  }
2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436
  tok=doctokenizerYYlex();
  while (tok==TK_WORD) // there are values following the title
  {
    if (g_token->name=="width") 
    {
      m_width=g_token->chars;
    }
    else if (g_token->name=="height") 
    {
      m_height=g_token->chars;
    }
    else 
    {
2437
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unknown option %s after image title",
2438
            g_token->name.data());
2439 2440 2441 2442
    }
    tok=doctokenizerYYlex();
  }
  ASSERT(tok==0);
2443 2444
  doctokenizerYYsetStatePara();
  handlePendingStyleCommands(this,m_children);
2445 2446 2447 2448 2449 2450 2451 2452 2453

  bool ambig;
  FileDef *fd = findFileDef(Doxygen::dotFileNameDict,m_name,ambig);
  if (fd)
  {
    m_file = fd->absFilePath();
  }
  else if (ambig)
  {
2454
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: included dot file name %s is ambigious.\n"
2455
           "Possible candidates:\n%s",m_name.data(),
2456 2457 2458 2459 2460
           showFileDefMatches(Doxygen::exampleNameDict,m_name).data()
          );
  }
  else
  {
2461
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: included dot file %s is not found "
2462
           "in any of the paths specified via DOTFILE_DIRS!",m_name.data());
2463 2464
  }

2465 2466 2467 2468 2469 2470 2471 2472
  DBG(("DocDotFile::parse() end\n"));
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
}


//---------------------------------------------------------------------------

2473 2474 2475 2476 2477 2478
DocImage::DocImage(DocNode *parent,const HtmlAttribList &attribs,const QString &name,Type t) : 
      m_parent(parent), m_attribs(attribs), m_name(name), 
      m_type(t), m_relPath(g_relPath)
{
}

2479 2480 2481 2482 2483
void DocImage::parse()
{
  g_nodeStack.push(this);
  DBG(("DocImage::parse() start\n"));

2484
  // parse title
2485 2486 2487 2488
  doctokenizerYYsetStateTitle();
  int tok;
  while ((tok=doctokenizerYYlex()))
  {
2489 2490 2491 2492 2493 2494 2495 2496
    if (tok==TK_WORD && (g_token->name=="width=" || g_token->name=="height="))
    {
      // special case: no title, but we do have a size indicator
      doctokenizerYYsetStateTitleAttrValue();
      // strip =
      g_token->name=g_token->name.left(g_token->name.length()-1);
      break;
    } 
2497 2498 2499 2500 2501
    if (!defaultHandleToken(this,tok,m_children))
    {
      switch (tok)
      {
        case TK_COMMAND: 
2502
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Illegal command %s as part of a \\image",
2503
              g_token->name.data());
2504 2505
          break;
        case TK_SYMBOL: 
2506 2507
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unsupported symbol %s found",
              g_token->name.data());
2508 2509
          break;
        default:
2510 2511
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected token %s",
              tokToString(tok));
2512 2513 2514 2515
          break;
      }
    }
  }
2516 2517 2518
  // parse size attributes
  tok=doctokenizerYYlex();
  while (tok==TK_WORD) // there are values following the title
2519
  {
2520
    if (g_token->name=="width") 
2521
    {
2522 2523 2524 2525 2526
      m_width=g_token->chars;
    }
    else if (g_token->name=="height") 
    {
      m_height=g_token->chars;
2527
    }
2528 2529 2530 2531 2532 2533
    else 
    {
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unknown option %s after image title",
          g_token->name.data());
    }
    tok=doctokenizerYYlex();
2534
  }
2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559
  doctokenizerYYsetStatePara();

  handlePendingStyleCommands(this,m_children);
  DBG(("DocImage::parse() end\n"));
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
}


//---------------------------------------------------------------------------

int DocHtmlHeader::parse()
{
  int retval=RetVal_OK;
  g_nodeStack.push(this);
  DBG(("DocHtmlHeader::parse() start\n"));

  int tok;
  while ((tok=doctokenizerYYlex()))
  {
    if (!defaultHandleToken(this,tok,m_children))
    {
      switch (tok)
      {
        case TK_COMMAND: 
2560
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Illegal command %s as part of a <h%d> tag",
2561
	       g_token->name.data(),m_level);
2562 2563 2564
          break;
        case TK_HTMLTAG:
          {
2565
            int tagId=Mappers::htmlTagMapper->map(g_token->name);
2566 2567 2568 2569
            if (tagId==HTML_H1 && g_token->endTag) // found </h1> tag
            {
              if (m_level!=1)
              {
2570
                warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: <h%d> ended with </h1>",
2571
                    m_level); 
2572 2573 2574 2575 2576 2577 2578
              }
              goto endheader;
            }
            else if (tagId==HTML_H2 && g_token->endTag) // found </h2> tag
            {
              if (m_level!=2)
              {
2579
                warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: <h%d> ended with </h2>",
2580
                    m_level); 
2581 2582 2583 2584 2585 2586 2587
              }
              goto endheader;
            }
            else if (tagId==HTML_H3 && g_token->endTag) // found </h3> tag
            {
              if (m_level!=3)
              {
2588
                warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: <h%d> ended with </h3>",
2589
                    m_level); 
2590 2591 2592
              }
              goto endheader;
            }
2593 2594 2595 2596
            else if (tagId==HTML_H4 && g_token->endTag) // found </h4> tag
            {
              if (m_level!=4)
              {
2597
                warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: <h%d> ended with </h4>",
2598 2599 2600 2601 2602 2603 2604 2605
                    m_level); 
              }
              goto endheader;
            }
            else if (tagId==HTML_H5 && g_token->endTag) // found </h5> tag
            {
              if (m_level!=5)
              {
2606
                warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: <h%d> ended with </h5>",
2607 2608 2609 2610 2611 2612 2613 2614
                    m_level); 
              }
              goto endheader;
            }
            else if (tagId==HTML_H6 && g_token->endTag) // found </h6> tag
            {
              if (m_level!=6)
              {
2615
                warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: <h%d> ended with </h6>",
2616 2617 2618 2619
                    m_level); 
              }
              goto endheader;
            }
2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631
            else if (tagId==HTML_A)
            {
              if (!g_token->endTag)
              {
                handleAHref(this,m_children,g_token->attribs);
              }
            }
            else if (tagId==HTML_BR)
            {
              DocLineBreak *lb = new DocLineBreak(this);
              m_children.append(lb);
            }
2632 2633
            else
            {
2634
              warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected html tag <%s%s> found within <h%d> context",
2635
                  g_token->endTag?"/":"",g_token->name.data(),m_level);
2636
            }
2637
            
2638 2639 2640
          }
          break;
        case TK_SYMBOL: 
2641
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unsupported symbol %s found",
2642
               g_token->name.data());
2643 2644
          break;
        default:
2645
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected token %s",
2646
		tokToString(tok));
2647 2648 2649 2650 2651 2652
          break;
      }
    }
  }
  if (tok==0)
  {
2653
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected end of comment while inside"
2654
           " <h%d> tag\n",m_level); 
2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679
  }
endheader:
  handlePendingStyleCommands(this,m_children);
  DBG(("DocHtmlHeader::parse() end\n"));
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return retval;
}

//---------------------------------------------------------------------------

int DocHRef::parse()
{
  int retval=RetVal_OK;
  g_nodeStack.push(this);
  DBG(("DocHRef::parse() start\n"));

  int tok;
  while ((tok=doctokenizerYYlex()))
  {
    if (!defaultHandleToken(this,tok,m_children))
    {
      switch (tok)
      {
        case TK_COMMAND: 
2680
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Illegal command %s as part of a <a>..</a> block",
2681
	       g_token->name.data());
2682 2683
          break;
        case TK_SYMBOL: 
2684
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unsupported symbol %s found",
2685
               g_token->name.data());
2686 2687 2688
          break;
        case TK_HTMLTAG:
          {
2689
            int tagId=Mappers::htmlTagMapper->map(g_token->name);
2690 2691 2692 2693 2694 2695
            if (tagId==HTML_A && g_token->endTag) // found </a> tag
            {
              goto endhref;
            }
            else
            {
2696
              warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected html tag <%s%s> found within <a href=...> context",
2697 2698 2699 2700 2701
                  g_token->endTag?"/":"",g_token->name.data(),doctokenizerYYlineno);
            }
          }
          break;
        default:
2702
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected token %s",
2703
		tokToString(tok),doctokenizerYYlineno);
2704 2705 2706 2707 2708 2709
          break;
      }
    }
  }
  if (tok==0)
  {
2710
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected end of comment while inside"
2711
           " <a href=...> tag",doctokenizerYYlineno); 
2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722
  }
endhref:
  handlePendingStyleCommands(this,m_children);
  DBG(("DocHRef::parse() end\n"));
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return retval;
}

//---------------------------------------------------------------------------

Dimitri van Heesch's avatar
Dimitri van Heesch committed
2723
int DocInternal::parse(int level)
2724 2725 2726 2727 2728 2729
{
  int retval=RetVal_OK;
  g_nodeStack.push(this);
  DBG(("DocInternal::parse() start\n"));

  // first parse any number of paragraphs
2730
  bool isFirst=TRUE;
2731
  DocPara *lastPar=0;
2732 2733 2734
  do
  {
    DocPara *par = new DocPara(this);
2735
    if (isFirst) { par->markFirst(); isFirst=FALSE; }
2736
    retval=par->parse();
2737 2738 2739 2740 2741
    if (!par->isEmpty()) 
    {
      m_children.append(par);
      lastPar=par;
    }
2742 2743 2744 2745
    else
    {
      delete par;
    }
2746 2747
    if (retval==TK_LISTITEM)
    {
2748
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Invalid list item found",doctokenizerYYlineno);
2749
    }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
2750 2751 2752 2753 2754 2755
  } while (retval!=0 && 
           retval!=RetVal_Section &&
           retval!=RetVal_Subsection &&
           retval!=RetVal_Subsubsection &&
           retval!=RetVal_Paragraph
          );
2756
  if (lastPar) lastPar->markLast();
2757

Dimitri van Heesch's avatar
Dimitri van Heesch committed
2758 2759 2760 2761 2762 2763
  // then parse any number of level-n sections
  while ((level==1 && retval==RetVal_Section) || 
         (level==2 && retval==RetVal_Subsection) ||
         (level==3 && retval==RetVal_Subsubsection) ||
         (level==4 && retval==RetVal_Paragraph)
        )
2764
  {
2765
    DocSection *s=new DocSection(this,
2766
        QMIN(level+Doxygen::subpageNestingLevel,5),g_token->sectionId);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
2767 2768
    m_children.append(s);
    retval = s->parse();
2769 2770 2771 2772
  }

  if (retval==RetVal_Internal)
  {
2773
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: \\internal command found inside internal section");
2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791
  }

  DBG(("DocInternal::parse() end\n"));
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return retval;
}

//---------------------------------------------------------------------------

int DocIndexEntry::parse()
{
  int retval=RetVal_OK;
  g_nodeStack.push(this);
  DBG(("DocIndexEntry::parse() start\n"));
  int tok=doctokenizerYYlex();
  if (tok!=TK_WHITESPACE)
  {
2792
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected whitespace after \\addindex command");
2793 2794
    goto endindexentry;
  }
2795
  doctokenizerYYsetStateTitle();
2796
  m_entry="";
2797
  while ((tok=doctokenizerYYlex()))
2798
  {
2799
    switch (tok)
2800
    {
2801 2802 2803
      case TK_WHITESPACE:
        m_entry+=" ";
        break;
2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823
      case TK_WORD: 
      case TK_LNKWORD: 
        m_entry+=g_token->name;
        break;
      case TK_SYMBOL:
        {
          char letter='\0';
          DocSymbol::SymType s = DocSymbol::decodeSymbol(g_token->name,&letter);
          switch (s)
          {
            case DocSymbol::BSlash:  m_entry+='\\'; break;
            case DocSymbol::At:      m_entry+='@';  break;
            case DocSymbol::Less:    m_entry+='<';  break;
            case DocSymbol::Greater: m_entry+='>';  break;
            case DocSymbol::Amp:     m_entry+='&';  break;
            case DocSymbol::Dollar:  m_entry+='$';  break;
            case DocSymbol::Hash:    m_entry+='#';  break;
            case DocSymbol::Percent: m_entry+='%';  break;
            case DocSymbol::Apos:    m_entry+='\''; break;
            case DocSymbol::Quot:    m_entry+='"';  break;
2824 2825 2826 2827 2828 2829
            case DocSymbol::Lsquo:   m_entry+='`';  break;
            case DocSymbol::Rsquo:   m_entry+='\'';  break;
            case DocSymbol::Ldquo:   m_entry+="``";  break;
            case DocSymbol::Rdquo:   m_entry+="''";  break;
            case DocSymbol::Ndash:   m_entry+="--";  break;
            case DocSymbol::Mdash:   m_entry+="---";  break;
2830
            default:
2831
              warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected symbol found as argument of \\addindex");
2832 2833 2834 2835 2836
              break;
          }
        }
        break;
    case TK_COMMAND: 
2837
      switch (Mappers::cmdMapper->map(g_token->name))
2838
      {
2839 2840 2841 2842 2843 2844 2845 2846
        case CMD_BSLASH:  m_entry+='\\'; break;
        case CMD_AT:      m_entry+='@';  break;
        case CMD_LESS:    m_entry+='<';  break;
        case CMD_GREATER: m_entry+='>';  break;
        case CMD_AMP:     m_entry+='&';  break;
        case CMD_DOLLAR:  m_entry+='$';  break;
        case CMD_HASH:    m_entry+='#';  break;
        case CMD_PERCENT: m_entry+='%';  break;
2847
        default:
2848
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected command %s found as argument of \\addindex",
2849
                    g_token->name.data());
2850 2851
          break;
      }
2852 2853
      break;
      default:
2854
        warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected token %s",
2855
            tokToString(tok));
2856
        break;
2857 2858
    }
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
2859
  if (tok!=0) retval=tok;
2860
  doctokenizerYYsetStatePara();
2861
endindexentry:
2862
  DBG(("DocIndexEntry::parse() end retval=%x\n",retval));
2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return retval;
}

//---------------------------------------------------------------------------

int DocHtmlCaption::parse()
{
  int retval=0;
  g_nodeStack.push(this);
  DBG(("DocHtmlCaption::parse() start\n"));
  int tok;
  while ((tok=doctokenizerYYlex()))
  {
    if (!defaultHandleToken(this,tok,m_children))
    {
      switch (tok)
      {
        case TK_COMMAND: 
2883
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Illegal command %s as part of a <caption> tag",
2884
              g_token->name.data());
2885 2886
          break;
        case TK_SYMBOL: 
2887
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unsupported symbol %s found",
2888
              g_token->name.data());
2889 2890 2891
          break;
        case TK_HTMLTAG:
          {
2892
            int tagId=Mappers::htmlTagMapper->map(g_token->name);
2893 2894 2895 2896 2897 2898 2899
            if (tagId==HTML_CAPTION && g_token->endTag) // found </caption> tag
            {
              retval = RetVal_OK;
              goto endcaption;
            }
            else
            {
2900
              warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected html tag <%s%s> found within <caption> context",
2901
                  g_token->endTag?"/":"",g_token->name.data());
2902 2903 2904 2905
            }
          }
          break;
        default:
2906
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected token %s",
2907
              tokToString(tok));
2908 2909 2910 2911 2912 2913
          break;
      }
    }
  }
  if (tok==0)
  {
2914
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected end of comment while inside"
2915
           " <caption> tag",doctokenizerYYlineno); 
2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933
  }
endcaption:
  handlePendingStyleCommands(this,m_children);
  DBG(("DocHtmlCaption::parse() end\n"));
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return retval;
}

//---------------------------------------------------------------------------

int DocHtmlCell::parse()
{
  int retval=RetVal_OK;
  g_nodeStack.push(this);
  DBG(("DocHtmlCell::parse() start\n"));

  // parse one or more paragraphs
2934
  bool isFirst=TRUE;
2935
  DocPara *par=0;
2936 2937
  do
  {
2938 2939
    par = new DocPara(this);
    if (isFirst) { par->markFirst(); isFirst=FALSE; }
2940 2941
    m_children.append(par);
    retval=par->parse();
2942 2943
    if (retval==TK_HTMLTAG)
    {
2944
      int tagId=Mappers::htmlTagMapper->map(g_token->name);
2945 2946 2947 2948 2949 2950 2951 2952 2953
      if (tagId==HTML_TD && g_token->endTag) // found </dt> tag
      {
        retval=TK_NEWPARA; // ignore the tag
      }
      else if (tagId==HTML_TH && g_token->endTag) // found </th> tag
      {
        retval=TK_NEWPARA; // ignore the tag
      }
    }
2954 2955
  }
  while (retval==TK_NEWPARA);
2956
  if (par) par->markLast();
2957 2958 2959 2960 2961 2962 2963

  DBG(("DocHtmlCell::parse() end\n"));
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return retval;
}

2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000
int DocHtmlCell::parseXml()
{
  int retval=RetVal_OK;
  g_nodeStack.push(this);
  DBG(("DocHtmlCell::parseXml() start\n"));

  // parse one or more paragraphs
  bool isFirst=TRUE;
  DocPara *par=0;
  do
  {
    par = new DocPara(this);
    if (isFirst) { par->markFirst(); isFirst=FALSE; }
    m_children.append(par);
    retval=par->parse();
    if (retval==TK_HTMLTAG)
    {
      int tagId=Mappers::htmlTagMapper->map(g_token->name);
      if (tagId==XML_ITEM && g_token->endTag) // found </item> tag
      {
        retval=TK_NEWPARA; // ignore the tag
      }
      else if (tagId==XML_DESCRIPTION && g_token->endTag) // found </description> tag
      {
        retval=TK_NEWPARA; // ignore the tag
      }
    }
  }
  while (retval==TK_NEWPARA);
  if (par) par->markLast();

  DBG(("DocHtmlCell::parseXml() end\n"));
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return retval;
}

3001 3002 3003 3004 3005 3006 3007 3008 3009
//---------------------------------------------------------------------------

int DocHtmlRow::parse()
{
  int retval=RetVal_OK;
  g_nodeStack.push(this);
  DBG(("DocHtmlRow::parse() start\n"));

  bool isHeading=FALSE;
3010 3011 3012
  bool isFirst=TRUE;
  DocHtmlCell *cell=0;

3013 3014 3015
  // get next token
  int tok=doctokenizerYYlex();
  // skip whitespace
3016
  while (tok==TK_WHITESPACE || tok==TK_NEWPARA) tok=doctokenizerYYlex();
3017 3018 3019
  // should find a html tag now
  if (tok==TK_HTMLTAG)
  {
3020
    int tagId=Mappers::htmlTagMapper->map(g_token->name);
3021 3022 3023 3024 3025 3026 3027 3028 3029
    if (tagId==HTML_TD && !g_token->endTag) // found <td> tag
    {
    }
    else if (tagId==HTML_TH && !g_token->endTag) // found <th> tag
    {
      isHeading=TRUE;
    }
    else // found some other tag
    {
3030
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected <td> or <th> tag but "
3031
          "found <%s> instead!",g_token->name.data());
3032
      doctokenizerYYpushBackHtmlTag(g_token->name);
3033 3034 3035 3036 3037
      goto endrow;
    }
  }
  else if (tok==0) // premature end of comment
  {
3038
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected end of comment while looking"
3039
        " for a html description title");
3040 3041 3042 3043
    goto endrow;
  }
  else // token other than html token
  {
3044
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected <td> or <th> tag but found %s token instead!",
3045
        tokToString(tok));
3046 3047 3048 3049 3050 3051
    goto endrow;
  }

  // parse one or more cells
  do
  {
3052
    cell=new DocHtmlCell(this,g_token->attribs,isHeading);
3053 3054 3055 3056
    cell->markFirst(isFirst);
    isFirst=FALSE;
    m_children.append(cell);
    retval=cell->parse();
3057 3058 3059
    isHeading = retval==RetVal_TableHCell;
  }
  while (retval==RetVal_TableCell || retval==RetVal_TableHCell);
3060
  if (cell) cell->markLast(TRUE);
3061 3062 3063 3064 3065 3066 3067 3068

endrow:
  DBG(("DocHtmlRow::parse() end\n"));
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return retval;
}

3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130
int DocHtmlRow::parseXml(bool isHeading)
{
  int retval=RetVal_OK;
  g_nodeStack.push(this);
  DBG(("DocHtmlRow::parseXml() start\n"));

  bool isFirst=TRUE;
  DocHtmlCell *cell=0;

  // get next token
  int tok=doctokenizerYYlex();
  // skip whitespace
  while (tok==TK_WHITESPACE || tok==TK_NEWPARA) tok=doctokenizerYYlex();
  // should find a html tag now
  if (tok==TK_HTMLTAG)
  {
    int tagId=Mappers::htmlTagMapper->map(g_token->name);
    if (tagId==XML_TERM && !g_token->endTag) // found <term> tag
    {
    }
    else if (tagId==XML_DESCRIPTION && !g_token->endTag) // found <description> tag
    {
    }
    else // found some other tag
    {
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected <term> or <description> tag but "
          "found <%s> instead!",g_token->name.data());
      doctokenizerYYpushBackHtmlTag(g_token->name);
      goto endrow;
    }
  }
  else if (tok==0) // premature end of comment
  {
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected end of comment while looking"
        " for a html description title");
    goto endrow;
  }
  else // token other than html token
  {
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected <td> or <th> tag but found %s token instead!",
        tokToString(tok));
    goto endrow;
  }

  do
  {
    cell=new DocHtmlCell(this,g_token->attribs,isHeading);
    cell->markFirst(isFirst);
    isFirst=FALSE;
    m_children.append(cell);
    retval=cell->parseXml();
  }
  while (retval==RetVal_TableCell || retval==RetVal_TableHCell);
  if (cell) cell->markLast(TRUE);

endrow:
  DBG(("DocHtmlRow::parseXml() end\n"));
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return retval;
}

3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142
//---------------------------------------------------------------------------

int DocHtmlTable::parse()
{
  int retval=RetVal_OK;
  g_nodeStack.push(this);
  DBG(("DocHtmlTable::parse() start\n"));
  
getrow:
  // get next token
  int tok=doctokenizerYYlex();
  // skip whitespace
3143
  while (tok==TK_WHITESPACE || tok==TK_NEWPARA) tok=doctokenizerYYlex();
3144 3145 3146
  // should find a html tag now
  if (tok==TK_HTMLTAG)
  {
3147
    int tagId=Mappers::htmlTagMapper->map(g_token->name);
3148 3149 3150 3151 3152 3153 3154 3155 3156
    if (tagId==HTML_TR && !g_token->endTag) // found <tr> tag
    {
      // no caption, just rows
      retval=RetVal_TableRow;
    }
    else if (tagId==HTML_CAPTION && !g_token->endTag) // found <caption> tag
    {
      if (m_caption)
      {
3157
        warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: table already has a caption, found another one");
3158 3159 3160
      }
      else
      {
3161
        m_caption = new DocHtmlCaption(this,g_token->attribs);
3162 3163 3164 3165 3166 3167 3168 3169 3170 3171
        retval=m_caption->parse();

        if (retval==RetVal_OK) // caption was parsed ok
        {
          goto getrow;
        }
      }
    }
    else // found wrong token
    {
3172
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected <tr> or <caption> tag but "
3173
          "found <%s%s> instead!", g_token->endTag ? "/" : "", g_token->name.data());
3174 3175 3176 3177
    }
  }
  else if (tok==0) // premature end of comment
  {
3178
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected end of comment while looking"
3179
          " for a <tr> or <caption> tag");
3180 3181 3182
  }
  else // token other than html token
  {
3183
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected <tr> tag but found %s token instead!",
3184
        tokToString(tok));
3185 3186 3187 3188 3189
  }
       
  // parse one or more rows
  while (retval==RetVal_TableRow)
  {
3190
    DocHtmlRow *tr=new DocHtmlRow(this,g_token->attribs);
3191 3192 3193 3194 3195 3196 3197 3198 3199 3200
    m_children.append(tr);
    retval=tr->parse();
  } 

  DBG(("DocHtmlTable::parse() end\n"));
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return retval==RetVal_EndTable ? RetVal_OK : retval;
}

3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242
int DocHtmlTable::parseXml()
{
  int retval=RetVal_OK;
  g_nodeStack.push(this);
  DBG(("DocHtmlTable::parseXml() start\n"));
  
  // get next token
  int tok=doctokenizerYYlex();
  // skip whitespace
  while (tok==TK_WHITESPACE || tok==TK_NEWPARA) tok=doctokenizerYYlex();
  // should find a html tag now
  int tagId=0;
  bool isHeader=FALSE;
  if (tok==TK_HTMLTAG)
  {
    tagId=Mappers::htmlTagMapper->map(g_token->name);
    if (tagId==XML_ITEM && !g_token->endTag) // found <item> tag
    {
      retval=RetVal_TableRow;
    }
    if (tagId==XML_LISTHEADER && !g_token->endTag) // found <listheader> tag
    {
      retval=RetVal_TableRow;
      isHeader=TRUE;
    }
  }

  // parse one or more rows
  while (retval==RetVal_TableRow)
  {
    DocHtmlRow *tr=new DocHtmlRow(this,g_token->attribs);
    m_children.append(tr);
    retval=tr->parseXml(isHeader);
    isHeader=FALSE;
  } 

  DBG(("DocHtmlTable::parseXml() end\n"));
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return retval==RetVal_EndTable ? RetVal_OK : retval;
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268
uint DocHtmlTable::numCols() const
{
  uint cols=0;
  QListIterator<DocNode> cli(m_children);
  DocNode *n;
  for (cli.toFirst();(n=cli.current());++cli)
  {
    ASSERT(n->kind()==DocNode::Kind_HtmlRow);
    cols=QMAX(cols,((DocHtmlRow *)n)->numCells());
  }
  return cols;
}

void DocHtmlTable::accept(DocVisitor *v) 
{ 
  v->visitPre(this); 
  // for HTML output we put the caption first
  if (m_caption && v->id()==DocVisitor_Html) m_caption->accept(v);
  QListIterator<DocNode> cli(m_children);
  DocNode *n;
  for (cli.toFirst();(n=cli.current());++cli) n->accept(v);
  // for other output formats we put the caption last
  if (m_caption && v->id()!=DocVisitor_Html) m_caption->accept(v);
  v->visitPost(this); 
}

3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284
//---------------------------------------------------------------------------

int DocHtmlDescTitle::parse()
{
  int retval=0;
  g_nodeStack.push(this);
  DBG(("DocHtmlDescTitle::parse() start\n"));

  int tok;
  while ((tok=doctokenizerYYlex()))
  {
    if (!defaultHandleToken(this,tok,m_children))
    {
      switch (tok)
      {
        case TK_COMMAND: 
3285 3286 3287
          {
            QString cmdName=g_token->name;
            bool isJavaLink=FALSE;
3288
            switch (Mappers::cmdMapper->map(cmdName))
3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308
            {
              case CMD_REF:
                {
                  int tok=doctokenizerYYlex();
                  if (tok!=TK_WHITESPACE)
                  {
                    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected whitespace after %s command",
                        g_token->name.data());
                  }
                  else
                  {
                    doctokenizerYYsetStateRef();
                    tok=doctokenizerYYlex(); // get the reference id
                    if (tok!=TK_WORD)
                    {
                      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected token %s as the argument of %s",
                          tokToString(tok),cmdName.data());
                    }
                    else
                    {
3309
                      DocRef *ref = new DocRef(this,g_token->name,g_context);
3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356
                      m_children.append(ref);
                      ref->parse();
                    }
                    doctokenizerYYsetStatePara();
                  }
                }
                break;
              case CMD_JAVALINK:
                isJavaLink=TRUE;
                // fall through
              case CMD_LINK:
                {
                  int tok=doctokenizerYYlex();
                  if (tok!=TK_WHITESPACE)
                  {
                    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected whitespace after %s command",
                        cmdName.data());
                  }
                  else
                  {
                    doctokenizerYYsetStateLink();
                    tok=doctokenizerYYlex();
                    if (tok!=TK_WORD)
                    {
                      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected token %s as the argument of %s",
                          tokToString(tok),cmdName.data());
                    }
                    else
                    {
                      doctokenizerYYsetStatePara();
                      DocLink *lnk = new DocLink(this,g_token->name);
                      m_children.append(lnk);
                      QString leftOver = lnk->parse(isJavaLink);
                      if (!leftOver.isEmpty())
                      {
                        m_children.append(new DocWord(this,leftOver));
                      }
                    }
                  }
                }

                break;
              default:
                warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Illegal command %s as part of a <dt> tag",
                               g_token->name.data());
            }
          }
3357 3358
          break;
        case TK_SYMBOL: 
3359
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unsupported symbol %s found",
3360
              g_token->name.data());
3361 3362 3363
          break;
        case TK_HTMLTAG:
          {
3364
            int tagId=Mappers::htmlTagMapper->map(g_token->name);
3365 3366 3367 3368 3369 3370 3371 3372 3373
            if (tagId==HTML_DD && !g_token->endTag) // found <dd> tag
            {
              retval = RetVal_DescData;
              goto endtitle;
            }
            else if (tagId==HTML_DT && g_token->endTag)
            {
              // ignore </dt> tag.
            }
3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384
            else if (tagId==HTML_DT)
            {
              // missing <dt> tag.
              retval = RetVal_DescTitle;
              goto endtitle;
            }
            else if (tagId==HTML_DL && g_token->endTag)
            {
              retval=RetVal_EndDesc;
              goto endtitle;
            }
3385 3386
            else
            {
3387
              warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected html tag <%s%s> found within <dt> context",
3388
                  g_token->endTag?"/":"",g_token->name.data());
3389 3390 3391 3392
            }
          }
          break;
        default:
3393
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected token %s",
3394
              tokToString(tok));
3395 3396 3397 3398 3399 3400
          break;
      }
    }
  }
  if (tok==0)
  {
3401
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected end of comment while inside"
3402
        " <dt> tag"); 
3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415
  }
endtitle:
  handlePendingStyleCommands(this,m_children);
  DBG(("DocHtmlDescTitle::parse() end\n"));
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return retval;
}

//---------------------------------------------------------------------------

int DocHtmlDescData::parse()
{
3416
  m_attribs = g_token->attribs;
3417 3418 3419 3420
  int retval=0;
  g_nodeStack.push(this);
  DBG(("DocHtmlDescData::parse() start\n"));

3421
  bool isFirst=TRUE;
3422
  DocPara *par=0;
3423 3424
  do
  {
3425 3426
    par = new DocPara(this);
    if (isFirst) { par->markFirst(); isFirst=FALSE; }
3427 3428 3429 3430
    m_children.append(par);
    retval=par->parse();
  }
  while (retval==TK_NEWPARA);
3431
  if (par) par->markLast();
3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453
  
  DBG(("DocHtmlDescData::parse() end\n"));
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return retval;
}

//---------------------------------------------------------------------------

int DocHtmlDescList::parse()
{
  int retval=RetVal_OK;
  g_nodeStack.push(this);
  DBG(("DocHtmlDescList::parse() start\n"));

  // get next token
  int tok=doctokenizerYYlex();
  // skip whitespace
  while (tok==TK_WHITESPACE || tok==TK_NEWPARA) tok=doctokenizerYYlex();
  // should find a html tag now
  if (tok==TK_HTMLTAG)
  {
3454
    int tagId=Mappers::htmlTagMapper->map(g_token->name);
3455 3456 3457 3458 3459 3460
    if (tagId==HTML_DT && !g_token->endTag) // found <dt> tag
    {
      // continue
    }
    else // found some other tag
    {
3461
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected <dt> tag but "
3462
          "found <%s> instead!",g_token->name.data());
3463
      doctokenizerYYpushBackHtmlTag(g_token->name);
3464 3465 3466 3467 3468
      goto enddesclist;
    }
  }
  else if (tok==0) // premature end of comment
  {
3469
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected end of comment while looking"
3470
        " for a html description title");
3471 3472 3473 3474
    goto enddesclist;
  }
  else // token other than html token
  {
3475
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected <dt> tag but found %s token instead!",
3476
        tokToString(tok));
3477 3478 3479 3480 3481
    goto enddesclist;
  }

  do
  {
3482
    DocHtmlDescTitle *dt=new DocHtmlDescTitle(this,g_token->attribs);
3483 3484 3485 3486 3487 3488 3489 3490
    m_children.append(dt);
    DocHtmlDescData *dd=new DocHtmlDescData(this);
    m_children.append(dd);
    retval=dt->parse();
    if (retval==RetVal_DescData)
    {
      retval=dd->parse();
    }
3491
    else if (retval!=RetVal_DescTitle)
3492 3493 3494 3495 3496 3497 3498 3499
    {
      // error
      break;
    }
  } while (retval==RetVal_DescTitle);

  if (retval==0)
  {
3500
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected end of comment while inside <dl> block");
3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519
  }

enddesclist:

  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  DBG(("DocHtmlDescList::parse() end\n"));
  return retval==RetVal_EndDesc ? RetVal_OK : retval;
}

//---------------------------------------------------------------------------

int DocHtmlListItem::parse()
{
  DBG(("DocHtmlListItem::parse() start\n"));
  int retval=0;
  g_nodeStack.push(this);

  // parse one or more paragraphs
3520
  bool isFirst=TRUE;
3521
  DocPara *par=0;
3522 3523
  do
  {
3524 3525
    par = new DocPara(this);
    if (isFirst) { par->markFirst(); isFirst=FALSE; }
3526 3527 3528 3529
    m_children.append(par);
    retval=par->parse();
  }
  while (retval==TK_NEWPARA);
3530
  if (par) par->markLast();
3531 3532 3533 3534 3535 3536 3537

  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  DBG(("DocHtmlListItem::parse() end retval=%x\n",retval));
  return retval;
}

3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571
int DocHtmlListItem::parseXml()
{
  DBG(("DocHtmlListItem::parseXml() start\n"));
  int retval=0;
  g_nodeStack.push(this);

  // parse one or more paragraphs
  bool isFirst=TRUE;
  DocPara *par=0;
  do
  {
    par = new DocPara(this);
    if (isFirst) { par->markFirst(); isFirst=FALSE; }
    m_children.append(par);
    retval=par->parse();
    if (retval==0) break;

    //printf("new item: retval=%x g_token->name=%s g_token->endTag=%d\n",
    //    retval,g_token->name.data(),g_token->endTag);
    if (retval==RetVal_ListItem)
    {
      break;
    }
  }
  while (retval!=RetVal_CloseXml);

  if (par) par->markLast();

  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  DBG(("DocHtmlListItem::parseXml() end retval=%x\n",retval));
  return retval;
}

3572 3573 3574 3575 3576 3577
//---------------------------------------------------------------------------

int DocHtmlList::parse()
{
  DBG(("DocHtmlList::parse() start\n"));
  int retval=RetVal_OK;
3578
  int num=1;
3579 3580 3581 3582
  g_nodeStack.push(this);

  // get next token
  int tok=doctokenizerYYlex();
3583 3584
  // skip whitespace and paragraph breaks
  while (tok==TK_WHITESPACE || tok==TK_NEWPARA) tok=doctokenizerYYlex();
3585 3586 3587
  // should find a html tag now
  if (tok==TK_HTMLTAG)
  {
3588
    int tagId=Mappers::htmlTagMapper->map(g_token->name);
3589 3590 3591 3592 3593 3594
    if (tagId==HTML_LI && !g_token->endTag) // found <li> tag
    {
      // ok, we can go on.
    }
    else // found some other tag
    {
3595
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected <li> tag but "
3596
          "found <%s> instead!",g_token->name.data());
3597
      doctokenizerYYpushBackHtmlTag(g_token->name);
3598 3599 3600 3601 3602
      goto endlist;
    }
  }
  else if (tok==0) // premature end of comment
  {
3603
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected end of comment while looking"
3604
        " for a html list item");
3605 3606 3607 3608
    goto endlist;
  }
  else // token other than html token
  {
3609
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected <li> tag but found %s token instead!",
3610
        tokToString(tok));
3611 3612 3613 3614 3615
    goto endlist;
  }

  do
  {
3616
    DocHtmlListItem *li=new DocHtmlListItem(this,g_token->attribs,num++);
3617 3618 3619 3620 3621 3622
    m_children.append(li);
    retval=li->parse();
  } while (retval==RetVal_ListItem);
  
  if (retval==0)
  {
3623
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected end of comment while inside <%cl> block",
3624
        m_type==Unordered ? 'u' : 'o');
3625 3626 3627 3628 3629 3630 3631 3632 3633
  }

endlist:
  DBG(("DocHtmlList::parse() end retval=%x\n",retval));
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return retval==RetVal_EndList ? RetVal_OK : retval;
}

3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657
int DocHtmlList::parseXml()
{
  DBG(("DocHtmlList::parseXml() start\n"));
  int retval=RetVal_OK;
  int num=1;
  g_nodeStack.push(this);

  // get next token
  int tok=doctokenizerYYlex();
  // skip whitespace and paragraph breaks
  while (tok==TK_WHITESPACE || tok==TK_NEWPARA) tok=doctokenizerYYlex();
  // should find a html tag now
  if (tok==TK_HTMLTAG)
  {
    int tagId=Mappers::htmlTagMapper->map(g_token->name);
    //printf("g_token->name=%s g_token->endTag=%d\n",g_token->name.data(),g_token->endTag);
    if (tagId==XML_ITEM && !g_token->endTag) // found <item> tag
    {
      // ok, we can go on.
    }
    else // found some other tag
    {
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected <item> tag but "
          "found <%s> instead!",g_token->name.data());
3658
      doctokenizerYYpushBackHtmlTag(g_token->name);
3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693
      goto endlist;
    }
  }
  else if (tok==0) // premature end of comment
  {
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected end of comment while looking"
        " for a html list item");
    goto endlist;
  }
  else // token other than html token
  {
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected <item> tag but found %s token instead!",
        tokToString(tok));
    goto endlist;
  }

  do
  {
    DocHtmlListItem *li=new DocHtmlListItem(this,g_token->attribs,num++);
    m_children.append(li);
    retval=li->parseXml();
    if (retval==0) break;
    //printf("retval=%x g_token->name=%s\n",retval,g_token->name.data());
  } while (retval==RetVal_ListItem);
  
  if (retval==0)
  {
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected end of comment while inside <list type=\"%s\"> block",
        m_type==Unordered ? "bullet" : "number");
  }

endlist:
  DBG(("DocHtmlList::parseXml() end retval=%x\n",retval));
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
3694 3695 3696
  return retval==RetVal_EndList || 
         (retval==RetVal_CloseXml || g_token->name=="list") ? 
         RetVal_OK : retval;
3697 3698
}

3699 3700 3701 3702 3703 3704
//---------------------------------------------------------------------------

int DocSimpleListItem::parse()
{
  g_nodeStack.push(this);
  int rv=m_paragraph->parse();
3705 3706
  m_paragraph->markFirst();
  m_paragraph->markLast();
3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return rv;
}

//--------------------------------------------------------------------------

int DocSimpleList::parse()
{
  g_nodeStack.push(this);
  int rv;
  do
  {
    DocSimpleListItem *li=new DocSimpleListItem(this);
    m_children.append(li);
    rv=li->parse();
  } while (rv==RetVal_ListItem);
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return (rv!=TK_NEWPARA) ? rv : RetVal_OK;
}

//--------------------------------------------------------------------------

int DocAutoListItem::parse()
{
  int retval = RetVal_OK;
  g_nodeStack.push(this);
  retval=m_paragraph->parse();
3736 3737
  m_paragraph->markFirst();
  m_paragraph->markLast();
3738 3739 3740 3741 3742 3743 3744 3745 3746 3747
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return retval;
}

//--------------------------------------------------------------------------

int DocAutoList::parse()
{
  int retval = RetVal_OK;
3748
  int num=1;
3749 3750 3751 3752
  g_nodeStack.push(this);
	  // first item or sub list => create new list
  do
  {
3753
    DocAutoListItem *li = new DocAutoListItem(this,num++);
3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781
    m_children.append(li);
    retval=li->parse();
  } 
  while (retval==TK_LISTITEM &&              // new list item
         m_indent==g_token->indent &&        // at same indent level
	 m_isEnumList==g_token->isEnumList   // of the same kind
        );

  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return retval;
}

//--------------------------------------------------------------------------

void DocTitle::parse()
{
  DBG(("DocTitle::parse() start\n"));
  g_nodeStack.push(this);
  doctokenizerYYsetStateTitle();
  int tok;
  while ((tok=doctokenizerYYlex()))
  {
    if (!defaultHandleToken(this,tok,m_children))
    {
      switch (tok)
      {
        case TK_COMMAND: 
3782
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Illegal command %s as part of a title section",
3783
	       g_token->name.data());
3784 3785
          break;
        case TK_SYMBOL: 
3786
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unsupported symbol %s found",
3787
               g_token->name.data());
3788 3789
          break;
        default:
3790
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected token %s",
3791
		tokToString(tok));
3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802
          break;
      }
    }
  }
  doctokenizerYYsetStatePara();
  handlePendingStyleCommands(this,m_children);
  DBG(("DocTitle::parse() end\n"));
  DocNode *n = g_nodeStack.pop();
  ASSERT(n==this);
}

3803 3804 3805 3806 3807
void DocTitle::parseFromString(const QString &text)
{
  m_children.append(new DocWord(this,text));
}

3808 3809 3810
//--------------------------------------------------------------------------

DocSimpleSect::DocSimpleSect(DocNode *parent,Type t) : 
3811
     m_parent(parent), m_type(t)
3812
{ 
3813
  m_title=0; 
3814 3815
}

3816
DocSimpleSect::~DocSimpleSect()
3817
{ 
3818
  delete m_title; 
3819 3820 3821 3822 3823 3824
}

void DocSimpleSect::accept(DocVisitor *v)
{
  v->visitPre(this);
  if (m_title) m_title->accept(v);
3825 3826 3827
  QListIterator<DocNode> cli(m_children);
  DocNode *n;
  for (cli.toFirst();(n=cli.current());++cli) n->accept(v);
3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842
  v->visitPost(this);
}

int DocSimpleSect::parse(bool userTitle)
{
  DBG(("DocSimpleSect::parse() start\n"));
  g_nodeStack.push(this);

  // handle case for user defined title
  if (userTitle)
  {
    m_title = new DocTitle(this);
    m_title->parse();
  }
  
3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858
  // add new paragraph as child
  DocPara *par = new DocPara(this);
  if (m_children.isEmpty()) 
  {
    par->markFirst();
  }
  else
  {
    ASSERT(m_children.last()->kind()==DocNode::Kind_Para);
    ((DocPara *)m_children.last())->markLast(FALSE);
  }
  par->markLast();
  m_children.append(par);
  
  // parse the contents of the paragraph
  int retval = par->parse();
3859 3860

  DBG(("DocSimpleSect::parse() end retval=%d\n",retval));
3861
  DocNode *n=g_nodeStack.pop();
3862 3863 3864 3865
  ASSERT(n==this);
  return retval; // 0==EOF, TK_NEWPARA, TK_LISTITEM, TK_ENDLIST, RetVal_SimpleSec
}

3866 3867 3868 3869 3870 3871 3872 3873
int DocSimpleSect::parseRcs()
{
  DBG(("DocSimpleSect::parseRcs() start\n"));
  g_nodeStack.push(this);

  m_title = new DocTitle(this);
  m_title->parseFromString(g_token->name);

3874 3875 3876 3877
  QString text = g_token->text;
  docParserPushContext(); // this will create a new g_token
  internalValidatingParseDoc(this,m_children,text);
  docParserPopContext(); // this will restore the old g_token
3878

Dimitri van Heesch's avatar
Dimitri van Heesch committed
3879
  DBG(("DocSimpleSect::parseRcs()\n"));
3880 3881 3882 3883 3884
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return RetVal_OK; 
}

3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944
int DocSimpleSect::parseXml()
{
  DBG(("DocSimpleSect::parse() start\n"));
  g_nodeStack.push(this);

  int retval = RetVal_OK;
  for (;;) 
  {
    // add new paragraph as child
    DocPara *par = new DocPara(this);
    if (m_children.isEmpty()) 
    {
      par->markFirst();
    }
    else
    {
      ASSERT(m_children.last()->kind()==DocNode::Kind_Para);
      ((DocPara *)m_children.last())->markLast(FALSE);
    }
    par->markLast();
    m_children.append(par);

    // parse the contents of the paragraph
    retval = par->parse();
    if (retval == 0) break;
    if (retval == RetVal_CloseXml) 
    {
      retval = RetVal_OK;
      break;
    }
  }
  
  DBG(("DocSimpleSect::parseXml() end retval=%d\n",retval));
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return retval; 
}

void DocSimpleSect::appendLinkWord(const QString &word)
{
  DocPara *p;
  if (m_children.isEmpty() || m_children.last()->kind()!=DocNode::Kind_Para)
  {
    p = new DocPara(this);
    m_children.append(p);
  }
  else
  {
    p = (DocPara *)m_children.last();
    
    // Comma-seperate <seealso> links.
    p->injectToken(TK_WORD,",");
    p->injectToken(TK_WHITESPACE," ");
  }
  
  g_inSeeBlock=TRUE;
  p->injectToken(TK_LNKWORD,word);
  g_inSeeBlock=FALSE;
}

3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969
QCString DocSimpleSect::typeString() const
{
  switch (m_type)
  {
    case Unknown:    break;
    case See:        return "see";
    case Return:     return "return";
    case Author:     // fall through
    case Authors:    return "author";
    case Version:    return "version";
    case Since:      return "since";
    case Date:       return "date";
    case Note:       return "note";
    case Warning:    return "warning";
    case Pre:        return "pre";
    case Post:       return "post";
    case Invar:      return "invariant";
    case Remark:     return "remark";
    case Attention:  return "attention";
    case User:       return "user";
    case Rcs:        return "rcs";
  }
  return "unknown";
}

3970 3971
//--------------------------------------------------------------------------

3972
int DocParamList::parse(const QString &cmdName)
3973
{
3974 3975 3976
  int retval=RetVal_OK;
  DBG(("DocParamList::parse() start\n"));
  g_nodeStack.push(this);
3977
  DocPara *par=0;
3978 3979 3980 3981

  int tok=doctokenizerYYlex();
  if (tok!=TK_WHITESPACE)
  {
3982
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected whitespace after %s command",
3983
        cmdName.data());
3984 3985 3986 3987 3988
  }
  doctokenizerYYsetStateParam();
  tok=doctokenizerYYlex();
  while (tok==TK_WORD) /* there is a parameter name */
  {
3989 3990 3991 3992 3993 3994 3995
    if (m_type==DocParamSect::Param)
    {
      g_hasParamCommand=TRUE;
      checkArgumentName(g_token->name,TRUE);
    }
    else if (m_type==DocParamSect::RetVal)
    {
3996
      g_hasReturnCommand=TRUE;
3997 3998
      checkArgumentName(g_token->name,FALSE);
    }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
3999 4000
    //m_params.append(g_token->name);
    handleLinkedWord(this,m_params);
4001 4002
    tok=doctokenizerYYlex();
  }
4003
  doctokenizerYYsetStatePara();
4004 4005
  if (tok==0) /* premature end of comment block */
  {
4006
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected end of comment block while parsing the "
4007
        "argument of command %s",cmdName.data());
4008 4009
    retval=0;
    goto endparamlist;
4010 4011
  }
  ASSERT(tok==TK_WHITESPACE);
4012

4013 4014 4015 4016 4017
  par = new DocPara(this);
  m_paragraphs.append(par);
  retval = par->parse();
  par->markFirst();
  par->markLast();
4018

4019
endparamlist:
4020 4021 4022 4023
  DBG(("DocParamList::parse() end retval=%d\n",retval));
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return retval;
4024 4025
}

4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073
int DocParamList::parseXml(const QString &paramName)
{
  int retval=RetVal_OK;
  DBG(("DocParamList::parseXml() start\n"));
  g_nodeStack.push(this);

  g_token->name = paramName;
  if (m_type==DocParamSect::Param)
  {
    g_hasParamCommand=TRUE;
    checkArgumentName(g_token->name,TRUE);
  }
  else if (m_type==DocParamSect::RetVal)
  {
    g_hasReturnCommand=TRUE;
    checkArgumentName(g_token->name,FALSE);
  }
  
  handleLinkedWord(this,m_params);

  do
  {
    DocPara *par = new DocPara(this);
    retval = par->parse();
    if (par->isEmpty()) // avoid adding an empty paragraph for the whitespace
                        // after </para> and before </param>
    {
      delete par;
      break;
    }
    else // append the paragraph to the list
    {
      if (m_paragraphs.isEmpty())
      {
        par->markFirst();
      }
      else
      {
        m_paragraphs.last()->markLast(FALSE);
      }
      par->markLast();
      m_paragraphs.append(par);
    }

    if (retval == 0) break;

  } while (retval==RetVal_CloseXml && 
           Mappers::htmlTagMapper->map(g_token->name)!=XML_PARAM &&
Dimitri van Heesch's avatar
Dimitri van Heesch committed
4074
           Mappers::htmlTagMapper->map(g_token->name)!=XML_TYPEPARAM &&
4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093
           Mappers::htmlTagMapper->map(g_token->name)!=XML_EXCEPTION);
  

  if (retval==0) /* premature end of comment block */
  {
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unterminated param or exception tag");
  }
  else
  {
    retval=RetVal_OK;
  }


  DBG(("DocParamList::parse() end retval=%d\n",retval));
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return retval;
}

4094 4095
//--------------------------------------------------------------------------

4096
int DocParamSect::parse(const QString &cmdName,bool xmlContext, Direction d)
4097
{
4098 4099 4100 4101
  int retval=RetVal_OK;
  DBG(("DocParamSect::parse() start\n"));
  g_nodeStack.push(this);

4102
  DocParamList *pl = new DocParamList(this,m_type,d);
4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113
  if (m_children.isEmpty())
  {
    pl->markFirst();
    pl->markLast();
  }
  else
  {
    ASSERT(m_children.last()->kind()==DocNode::Kind_ParamList);
    ((DocParamList *)m_children.last())->markLast(FALSE);
    pl->markLast();
  }
4114
  m_children.append(pl);
4115 4116 4117 4118 4119 4120 4121 4122
  if (xmlContext)
  {
    retval = pl->parseXml(cmdName);
  }
  else
  {
    retval = pl->parse(cmdName);
  }
4123 4124 4125 4126 4127 4128 4129 4130 4131
  
  DBG(("DocParamSect::parse() end retval=%d\n",retval));
  DocNode *n=g_nodeStack.pop();
  ASSERT(n==this);
  return retval;
}

//--------------------------------------------------------------------------

4132
int DocPara::handleSimpleSection(DocSimpleSect::Type t, bool xmlContext)
4133 4134
{
  DocSimpleSect *ss=0;
4135 4136 4137 4138
  if (!m_children.isEmpty() &&                           // previous element
      m_children.last()->kind()==Kind_SimpleSect &&      // was a simple sect
      ((DocSimpleSect *)m_children.last())->type()==t && // of same type
      t!=DocSimpleSect::User)                            // but not user defined
4139
  {
4140 4141
    // append to previous section
    ss=(DocSimpleSect *)m_children.last();
4142
  }
4143
  else // start new section
4144
  {
4145 4146
    ss=new DocSimpleSect(this,t);
    m_children.append(ss);
4147
  }
4148 4149 4150 4151 4152 4153 4154 4155 4156
  int rv = RetVal_OK;
  if (xmlContext)
  {
    return ss->parseXml();
  }
  else
  {
    rv = ss->parse(t==DocSimpleSect::User);
  }
4157
  return (rv!=TK_NEWPARA) ? rv : RetVal_OK;
4158 4159
}

4160 4161
int DocPara::handleParamSection(const QString &cmdName,
                                DocParamSect::Type t,
4162
                                bool xmlContext=FALSE,
4163
                                int direction=DocParamSect::Unspecified)
4164
{
4165 4166 4167 4168
  DocParamSect *ps=0;
  if (!m_children.isEmpty() &&                        // previous element
      m_children.last()->kind()==Kind_ParamSect &&    // was a param sect
      ((DocParamSect *)m_children.last())->type()==t) // of same type
4169
  {
4170 4171
    // append to previous section
    ps=(DocParamSect *)m_children.last();
4172
  }
4173
  else // start new section
4174
  {
4175 4176
    ps=new DocParamSect(this,t);
    m_children.append(ps);
4177
  }
4178
  int rv=ps->parse(cmdName,xmlContext,(DocParamSect::Direction)direction);
4179
  return (rv!=TK_NEWPARA) ? rv : RetVal_OK;
4180 4181
}

4182
int DocPara::handleXRefItem()
4183 4184 4185 4186 4187
{
  int retval=doctokenizerYYlex();
  ASSERT(retval==TK_WHITESPACE);
  doctokenizerYYsetStateXRefItem();
  retval=doctokenizerYYlex();
4188
  if (retval==RetVal_OK)
4189
  {
4190
    DocXRefItem *ref = new DocXRefItem(this,g_token->id,g_token->name);
4191 4192 4193 4194
    if (ref->parse())
    {
      m_children.append(ref);
    }
4195
    else 
4196 4197 4198
    {
      delete ref;
    }
4199 4200 4201 4202 4203
  }
  doctokenizerYYsetStatePara();
  return retval;
}

4204
void DocPara::handleIncludeOperator(const QString &cmdName,DocIncOperator::Type t)
4205
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
4206
  DBG(("handleIncludeOperator(%s)\n",cmdName.data()));
4207 4208 4209
  int tok=doctokenizerYYlex();
  if (tok!=TK_WHITESPACE)
  {
4210
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected whitespace after %s command",
4211
        cmdName.data());
4212 4213 4214 4215 4216 4217 4218
    return;
  }
  doctokenizerYYsetStatePattern();
  tok=doctokenizerYYlex();
  doctokenizerYYsetStatePara();
  if (tok==0)
  {
4219
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected end of comment block while parsing the "
4220
        "argument of command %s", cmdName.data());
4221 4222 4223 4224
    return;
  }
  else if (tok!=TK_WORD)
  {
4225
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected token %s as the argument of %s",
4226
        tokToString(tok),cmdName.data());
4227 4228
    return;
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
4229
  DocIncOperator *op = new DocIncOperator(this,t,g_token->name,g_context,g_isExample,g_exampleName);
4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250
  DocNode *n1 = m_children.last();
  DocNode *n2 = n1!=0 ? m_children.prev() : 0;
  bool isFirst = n1==0 || // no last node
                 (n1->kind()!=DocNode::Kind_IncOperator && 
                  n1->kind()!=DocNode::Kind_WhiteSpace
                 ) || // last node is not operator or whitespace
                 (n1->kind()==DocNode::Kind_WhiteSpace && 
                  n2!=0 && n2->kind()!=DocNode::Kind_IncOperator
                 ); // previous not is not operator
  op->markFirst(isFirst);
  op->markLast(TRUE);
  if (n1!=0 && n1->kind()==DocNode::Kind_IncOperator)
  {
    ((DocIncOperator *)n1)->markLast(FALSE);
  }
  else if (n1!=0 && n1->kind()==DocNode::Kind_WhiteSpace &&
           n2!=0 && n2->kind()==DocNode::Kind_IncOperator
          )
  {
    ((DocIncOperator *)n2)->markLast(FALSE);
  }
4251
  m_children.append(op);
4252
  op->parse();
4253 4254
}

4255
void DocPara::handleImage(const QString &cmdName)
4256 4257 4258 4259
{
  int tok=doctokenizerYYlex();
  if (tok!=TK_WHITESPACE)
  {
4260
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected whitespace after %s command",
4261
        cmdName.data());
4262 4263 4264
    return;
  }
  tok=doctokenizerYYlex();
4265
  if (tok!=TK_WORD && tok!=TK_LNKWORD)
4266
  {
4267
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected token %s as the argument of %s",
4268
        tokToString(tok),cmdName.data());
4269 4270 4271 4272 4273
    return;
  }
  tok=doctokenizerYYlex();
  if (tok!=TK_WHITESPACE)
  {
4274
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected whitespace after %s command",
4275
        cmdName.data());
4276 4277 4278
    return;
  }
  DocImage::Type t;
4279
  QString imgType = g_token->name.lower();
4280 4281 4282 4283 4284
  if      (imgType=="html")  t=DocImage::Html;
  else if (imgType=="latex") t=DocImage::Latex;
  else if (imgType=="rtf")   t=DocImage::Rtf;
  else
  {
4285
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: image type %s specified as the first argument of "
4286 4287
        "%s is not valid",
        imgType.data(),cmdName.data());
4288 4289 4290 4291
    return;
  } 
  doctokenizerYYsetStateFile();
  tok=doctokenizerYYlex();
4292
  doctokenizerYYsetStatePara();
4293 4294
  if (tok!=TK_WORD)
  {
4295
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected token %s as the argument of %s",
4296
        tokToString(tok),cmdName.data());
4297 4298
    return;
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
4299 4300
  HtmlAttribList attrList;
  DocImage *img = new DocImage(this,attrList,findAndCopyImage(g_token->name,t),t);
4301 4302 4303 4304
  m_children.append(img);
  img->parse();
}

4305
void DocPara::handleDotFile(const QString &cmdName)
4306 4307 4308 4309
{
  int tok=doctokenizerYYlex();
  if (tok!=TK_WHITESPACE)
  {
4310
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected whitespace after %s command",
4311
        cmdName.data());
4312 4313 4314 4315
    return;
  }
  doctokenizerYYsetStateFile();
  tok=doctokenizerYYlex();
4316
  doctokenizerYYsetStatePara();
4317 4318
  if (tok!=TK_WORD)
  {
4319
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected token %s as the argument of %s",
4320
        tokToString(tok),cmdName.data());
4321 4322
    return;
  }
4323
  QString name = g_token->name;
4324
  DocDotFile *df = new DocDotFile(this,name,g_context);
4325 4326 4327 4328
  m_children.append(df);
  df->parse();
}

4329
void DocPara::handleLink(const QString &cmdName,bool isJavaLink)
4330 4331 4332 4333
{
  int tok=doctokenizerYYlex();
  if (tok!=TK_WHITESPACE)
  {
4334
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected whitespace after %s command",
4335
        cmdName.data());
4336 4337 4338 4339 4340 4341
    return;
  }
  doctokenizerYYsetStateLink();
  tok=doctokenizerYYlex();
  if (tok!=TK_WORD)
  {
4342
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected token %s as the argument of %s",
4343
        tokToString(tok),cmdName.data());
4344 4345 4346 4347 4348
    return;
  }
  doctokenizerYYsetStatePara();
  DocLink *lnk = new DocLink(this,g_token->name);
  m_children.append(lnk);
4349
  QString leftOver = lnk->parse(isJavaLink);
4350 4351 4352 4353 4354 4355
  if (!leftOver.isEmpty())
  {
    m_children.append(new DocWord(this,leftOver));
  }
}

4356
void DocPara::handleRef(const QString &cmdName)
4357
{
4358
  DBG(("handleRef(%s)\n",cmdName.data()));
4359 4360 4361
  int tok=doctokenizerYYlex();
  if (tok!=TK_WHITESPACE)
  {
4362
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected whitespace after %s command",
4363
        cmdName.data());
4364 4365 4366 4367 4368 4369 4370
    return;
  }
  doctokenizerYYsetStateRef();
  tok=doctokenizerYYlex(); // get the reference id
  DocRef *ref=0;
  if (tok!=TK_WORD)
  {
4371
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected token %s as the argument of %s",
4372
        tokToString(tok),cmdName.data());
4373 4374
    goto endref;
  }
4375
  ref = new DocRef(this,g_token->name,g_context);
4376 4377 4378 4379 4380 4381 4382
  m_children.append(ref);
  ref->parse();
endref:
  doctokenizerYYsetStatePara();
}


4383
void DocPara::handleInclude(const QString &cmdName,DocInclude::Type t)
4384
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
4385
  DBG(("handleInclude(%s)\n",cmdName.data()));
4386 4387 4388
  int tok=doctokenizerYYlex();
  if (tok!=TK_WHITESPACE)
  {
4389
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected whitespace after %s command",
4390
        cmdName.data());
4391 4392 4393 4394 4395 4396 4397
    return;
  }
  doctokenizerYYsetStateFile();
  tok=doctokenizerYYlex();
  doctokenizerYYsetStatePara();
  if (tok==0)
  {
4398
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected end of comment block while parsing the "
4399
        "argument of command %s",cmdName.data());
4400 4401 4402 4403
    return;
  }
  else if (tok!=TK_WORD)
  {
4404
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected token %s as the argument of %s",
4405
        tokToString(tok),cmdName.data());
4406 4407
    return;
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
4408
  DocInclude *inc = new DocInclude(this,g_token->name,g_context,t,g_isExample,g_exampleName);
4409
  m_children.append(inc);
4410
  inc->parse();
4411 4412
}

4413 4414 4415 4416 4417 4418
void DocPara::handleSection(const QString &cmdName)
{
  // get the argument of the section command.
  int tok=doctokenizerYYlex();
  if (tok!=TK_WHITESPACE)
  {
4419
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected whitespace after %s command",
4420 4421 4422 4423 4424 4425
        cmdName.data());
    return;
  }
  tok=doctokenizerYYlex();
  if (tok==0)
  {
4426
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected end of comment block while parsing the "
4427 4428 4429 4430 4431
        "argument of command %s\n", cmdName.data());
    return;
  }
  else if (tok!=TK_WORD && tok!=TK_LNKWORD)
  {
4432
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected token %s as the argument of %s",
4433 4434 4435 4436 4437 4438 4439 4440 4441
        tokToString(tok),cmdName.data());
    return;
  }
  g_token->sectionId = g_token->name;
  doctokenizerYYsetStateSkipTitle();
  doctokenizerYYlex();
  doctokenizerYYsetStatePara();
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
4442 4443 4444 4445 4446 4447 4448
int DocPara::handleHtmlHeader(const HtmlAttribList &tagHtmlAttribs,int level)
{
  DocHtmlHeader *header = new DocHtmlHeader(this,tagHtmlAttribs,level);
  m_children.append(header);
  int retval = header->parse();
  return (retval==RetVal_OK) ? TK_NEWPARA : retval;
}
4449

4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474
// For XML tags whose content is stored in attributes rather than
// contained within the element, we need a way to inject the attribute
// text into the current paragraph.
bool DocPara::injectToken(int tok,const QString &tokText) 
{
  g_token->name = tokText;
  return defaultHandleToken(this,tok,m_children);
}

int DocPara::handleStartCode()
{
  int retval = doctokenizerYYlex();
  // search for the first non-whitespace line, index is stored in li
  int i=0,li=0,l=g_token->verb.length();
  while (i<l && g_token->verb.at(i)==' ' || g_token->verb.at(i)=='\n')
  {
    if (g_token->verb.at(i)=='\n') li=i+1;
    i++;
  }
  m_children.append(new DocVerbatim(this,g_context,g_token->verb.mid(li),DocVerbatim::Code,g_isExample,g_exampleName));
  if (retval==0) warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: code section ended without end marker");
  doctokenizerYYsetStatePara();
  return retval;
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492
void DocPara::handleInheritDoc()
{
  if (g_memberDef) // inheriting docs from a member
  {
    MemberDef *reMd = g_memberDef->reimplements();
    if (reMd) // member from which was inherited.
    {
      MemberDef *thisMd = g_memberDef;
      //printf("{InheritDocs:%s=>%s}\n",g_memberDef->qualifiedName().data(),reMd->qualifiedName().data());
      docParserPushContext();
      g_context=reMd->getOuterScope()->name();
      g_memberDef=reMd;
      g_styleStack.clear();
      g_nodeStack.clear();
      g_copyStack.append(reMd);
      internalValidatingParseDoc(this,m_children,reMd->briefDescription());
      internalValidatingParseDoc(this,m_children,reMd->documentation());
      g_copyStack.remove(reMd);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
4493
      docParserPopContext(TRUE);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
4494 4495 4496 4497 4498 4499
      g_memberDef = thisMd;
    }
  }
}


4500
int DocPara::handleCommand(const QString &cmdName)
4501
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
4502
  DBG(("handleCommand(%s)\n",cmdName.data()));
4503
  int retval = RetVal_OK;
4504 4505
  int cmdId = Mappers::cmdMapper->map(cmdName);
  switch (cmdId)
4506 4507
  {
    case CMD_UNKNOWN:
4508
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Found unknown command `\\%s'",cmdName.data());
4509 4510 4511 4512 4513
      break;
    case CMD_EMPHASIS:
      m_children.append(new DocStyleChange(this,g_nodeStack.count(),DocStyleChange::Italic,TRUE));
      retval=handleStyleArgument(this,m_children,cmdName); 
      m_children.append(new DocStyleChange(this,g_nodeStack.count(),DocStyleChange::Italic,FALSE));
4514
      if (retval!=TK_WORD) m_children.append(new DocWhiteSpace(this," "));
4515 4516 4517 4518 4519
      break;
    case CMD_BOLD:
      m_children.append(new DocStyleChange(this,g_nodeStack.count(),DocStyleChange::Bold,TRUE));
      retval=handleStyleArgument(this,m_children,cmdName); 
      m_children.append(new DocStyleChange(this,g_nodeStack.count(),DocStyleChange::Bold,FALSE));
4520
      if (retval!=TK_WORD) m_children.append(new DocWhiteSpace(this," "));
4521 4522 4523 4524 4525
      break;
    case CMD_CODE:
      m_children.append(new DocStyleChange(this,g_nodeStack.count(),DocStyleChange::Code,TRUE));
      retval=handleStyleArgument(this,m_children,cmdName); 
      m_children.append(new DocStyleChange(this,g_nodeStack.count(),DocStyleChange::Code,FALSE));
4526
      if (retval!=TK_WORD) m_children.append(new DocWhiteSpace(this," "));
4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552
      break;
    case CMD_BSLASH:
      m_children.append(new DocSymbol(this,DocSymbol::BSlash));
      break;
    case CMD_AT:
      m_children.append(new DocSymbol(this,DocSymbol::At));
      break;
    case CMD_LESS:
      m_children.append(new DocSymbol(this,DocSymbol::Less));
      break;
    case CMD_GREATER:
      m_children.append(new DocSymbol(this,DocSymbol::Greater));
      break;
    case CMD_AMP:
      m_children.append(new DocSymbol(this,DocSymbol::Amp));
      break;
    case CMD_DOLLAR:
      m_children.append(new DocSymbol(this,DocSymbol::Dollar));
      break;
    case CMD_HASH:
      m_children.append(new DocSymbol(this,DocSymbol::Hash));
      break;
    case CMD_PERCENT:
      m_children.append(new DocSymbol(this,DocSymbol::Percent));
      break;
    case CMD_SA:
4553
      g_inSeeBlock=TRUE;
4554
      retval = handleSimpleSection(DocSimpleSect::See);
4555
      g_inSeeBlock=FALSE;
4556 4557 4558
      break;
    case CMD_RETURN:
      retval = handleSimpleSection(DocSimpleSect::Return);
4559
      g_hasReturnCommand=TRUE;
4560 4561 4562 4563
      break;
    case CMD_AUTHOR:
      retval = handleSimpleSection(DocSimpleSect::Author);
      break;
4564 4565 4566
    case CMD_AUTHORS:
      retval = handleSimpleSection(DocSimpleSect::Authors);
      break;
4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608
    case CMD_VERSION:
      retval = handleSimpleSection(DocSimpleSect::Version);
      break;
    case CMD_SINCE:
      retval = handleSimpleSection(DocSimpleSect::Since);
      break;
    case CMD_DATE:
      retval = handleSimpleSection(DocSimpleSect::Date);
      break;
    case CMD_NOTE:
      retval = handleSimpleSection(DocSimpleSect::Note);
      break;
    case CMD_WARNING:
      retval = handleSimpleSection(DocSimpleSect::Warning);
      break;
    case CMD_PRE:
      retval = handleSimpleSection(DocSimpleSect::Pre);
      break;
    case CMD_POST:
      retval = handleSimpleSection(DocSimpleSect::Post);
      break;
    case CMD_INVARIANT:
      retval = handleSimpleSection(DocSimpleSect::Invar);
      break;
    case CMD_REMARK:
      retval = handleSimpleSection(DocSimpleSect::Remark);
      break;
    case CMD_ATTENTION:
      retval = handleSimpleSection(DocSimpleSect::Attention);
      break;
    case CMD_PAR:
      retval = handleSimpleSection(DocSimpleSect::User);
      break;
    case CMD_LI:
      {
	DocSimpleList *sl=new DocSimpleList(this);
	m_children.append(sl);
        retval = sl->parse();
      }
      break;
    case CMD_SECTION:
      {
4609
        handleSection(cmdName);
4610 4611 4612
	retval = RetVal_Section;
      }
      break;
4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630
    case CMD_SUBSECTION:
      {
        handleSection(cmdName);
	retval = RetVal_Subsection;
      }
      break;
    case CMD_SUBSUBSECTION:
      {
        handleSection(cmdName);
	retval = RetVal_Subsubsection;
      }
      break;
    case CMD_PARAGRAPH:
      {
        handleSection(cmdName);
	retval = RetVal_Paragraph;
      }
      break;
4631 4632 4633
    case CMD_STARTCODE:
      {
        doctokenizerYYsetStateCode();
4634
        retval = handleStartCode();
4635 4636 4637 4638 4639 4640
      }
      break;
    case CMD_HTMLONLY:
      {
        doctokenizerYYsetStateHtmlOnly();
        retval = doctokenizerYYlex();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
4641
        m_children.append(new DocVerbatim(this,g_context,g_token->verb,DocVerbatim::HtmlOnly,g_isExample,g_exampleName));
4642
        if (retval==0) warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: htmlonly section ended without end marker");
4643 4644 4645
        doctokenizerYYsetStatePara();
      }
      break;
4646 4647 4648 4649 4650 4651 4652 4653 4654
    case CMD_MANONLY:
      {
        doctokenizerYYsetStateManOnly();
        retval = doctokenizerYYlex();
        m_children.append(new DocVerbatim(this,g_context,g_token->verb,DocVerbatim::ManOnly,g_isExample,g_exampleName));
        if (retval==0) warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: manonly section ended without end marker");
        doctokenizerYYsetStatePara();
      }
      break;
4655 4656 4657 4658
    case CMD_LATEXONLY:
      {
        doctokenizerYYsetStateLatexOnly();
        retval = doctokenizerYYlex();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
4659
        m_children.append(new DocVerbatim(this,g_context,g_token->verb,DocVerbatim::LatexOnly,g_isExample,g_exampleName));
4660
        if (retval==0) warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: latexonly section ended without end marker");
4661 4662 4663
        doctokenizerYYsetStatePara();
      }
      break;
4664 4665 4666 4667 4668 4669 4670 4671 4672
    case CMD_XMLONLY:
      {
        doctokenizerYYsetStateXmlOnly();
        retval = doctokenizerYYlex();
        m_children.append(new DocVerbatim(this,g_context,g_token->verb,DocVerbatim::XmlOnly,g_isExample,g_exampleName));
        if (retval==0) warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: xmlonly section ended without end marker");
        doctokenizerYYsetStatePara();
      }
      break;
4673 4674 4675 4676
    case CMD_VERBATIM:
      {
        doctokenizerYYsetStateVerbatim();
        retval = doctokenizerYYlex();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
4677
        m_children.append(new DocVerbatim(this,g_context,g_token->verb,DocVerbatim::Verbatim,g_isExample,g_exampleName));
4678
        if (retval==0) warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: verbatim section ended without end marker");
4679 4680 4681
        doctokenizerYYsetStatePara();
      }
      break;
4682 4683 4684 4685 4686 4687 4688 4689 4690
    case CMD_DOT:
      {
        doctokenizerYYsetStateDot();
        retval = doctokenizerYYlex();
        m_children.append(new DocVerbatim(this,g_context,g_token->verb,DocVerbatim::Dot,g_isExample,g_exampleName));
        if (retval==0) warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: dot section ended without end marker");
        doctokenizerYYsetStatePara();
      }
      break;
4691 4692 4693 4694 4695 4696 4697 4698 4699
    case CMD_MSC:
      {
        doctokenizerYYsetStateMsc();
        retval = doctokenizerYYlex();
        m_children.append(new DocVerbatim(this,g_context,g_token->verb,DocVerbatim::Msc,g_isExample,g_exampleName));
        if (retval==0) warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: msc section ended without end marker");
        doctokenizerYYsetStatePara();
      }
      break;
4700 4701
    case CMD_ENDCODE:
    case CMD_ENDHTMLONLY:
4702
    case CMD_ENDMANONLY:
4703
    case CMD_ENDLATEXONLY:
4704
    case CMD_ENDXMLONLY:
4705 4706
    case CMD_ENDLINK:
    case CMD_ENDVERBATIM:
4707
    case CMD_ENDDOT:
4708
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected command %s",g_token->name.data());
4709
      break; 
4710 4711 4712
    case CMD_ENDMSC:
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected command %s",g_token->name.data());
      break; 
4713
    case CMD_PARAM:
4714
      retval = handleParamSection(cmdName,DocParamSect::Param,FALSE,g_token->paramDir);
4715
      break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
4716 4717 4718
    case CMD_TPARAM:
      retval = handleParamSection(cmdName,DocParamSect::TemplateParam,FALSE,g_token->paramDir);
      break;
4719
    case CMD_RETVAL:
4720
      retval = handleParamSection(cmdName,DocParamSect::RetVal);
4721 4722
      break;
    case CMD_EXCEPTION:
4723
      retval = handleParamSection(cmdName,DocParamSect::Exception);
4724
      break;
4725 4726
    case CMD_XREFITEM:
      retval = handleXRefItem();
4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738
      break;
    case CMD_LINEBREAK:
      {
        DocLineBreak *lb = new DocLineBreak(this);
        m_children.append(lb);
      }
      break;
    case CMD_ANCHOR:
      {
	int tok=doctokenizerYYlex();
	if (tok!=TK_WHITESPACE)
	{
4739
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected whitespace after %s command",
4740
	      cmdName.data());
4741 4742 4743 4744 4745
	  break;
	}
	tok=doctokenizerYYlex();
	if (tok==0)
	{
4746
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected end of comment block while parsing the "
4747
	      "argument of command %s",cmdName.data());
4748 4749
	  break;
	}
4750
	else if (tok!=TK_WORD && tok!=TK_LNKWORD)
4751
	{
4752
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected token %s as the argument of %s",
4753
	      tokToString(tok),cmdName.data());
4754 4755
	  break;
	}
4756
        DocAnchor *anchor = new DocAnchor(this,g_token->name,FALSE);
4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769
        m_children.append(anchor);
      }
      break;
    case CMD_ADDINDEX:
      {
        DocIndexEntry *ie = new DocIndexEntry(this);
        m_children.append(ie);
        retval = ie->parse();
      }
      break;
    case CMD_INTERNAL:
      retval = RetVal_Internal;
      break;
4770 4771 4772
    case CMD_COPYDOC:   // fall through
    case CMD_COPYBRIEF: // fall through
    case CMD_COPYDETAILS:
4773 4774 4775 4776
      {
	int tok=doctokenizerYYlex();
	if (tok!=TK_WHITESPACE)
	{
4777
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: expected whitespace after %s command",
4778
	      cmdName.data());
4779 4780 4781 4782 4783
	  break;
	}
	tok=doctokenizerYYlex();
	if (tok==0)
	{
4784
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected end of comment block while parsing the "
4785
	      "argument of command %s\n", cmdName.data());
4786 4787
	  break;
	}
4788
	else if (tok!=TK_WORD && tok!=TK_LNKWORD)
4789
	{
4790
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected token %s as the argument of %s",
4791
	      tokToString(tok),cmdName.data());
4792 4793
	  break;
	}
4794 4795 4796
        DocCopy *cpy = new DocCopy(this,g_token->name,
            cmdId==CMD_COPYDOC || cmdId==CMD_COPYBRIEF,
            cmdId==CMD_COPYDOC || cmdId==CMD_COPYDETAILS);
4797
        m_children.append(cpy);
4798
        cpy->parse();
4799 4800 4801 4802 4803
      }
      break;
    case CMD_INCLUDE:
      handleInclude(cmdName,DocInclude::Include);
      break;
4804 4805 4806
    case CMD_INCWITHLINES:
      handleInclude(cmdName,DocInclude::IncWithLines);
      break;
4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839
    case CMD_DONTINCLUDE:
      handleInclude(cmdName,DocInclude::DontInclude);
      break;
    case CMD_HTMLINCLUDE:
      handleInclude(cmdName,DocInclude::HtmlInclude);
      break;
    case CMD_VERBINCLUDE:
      handleInclude(cmdName,DocInclude::VerbInclude);
      break;
    case CMD_SKIP:
      handleIncludeOperator(cmdName,DocIncOperator::Skip);
      break;
    case CMD_UNTIL:
      handleIncludeOperator(cmdName,DocIncOperator::Until);
      break;
    case CMD_SKIPLINE:
      handleIncludeOperator(cmdName,DocIncOperator::SkipLine);
      break;
    case CMD_LINE:
      handleIncludeOperator(cmdName,DocIncOperator::Line);
      break;
    case CMD_IMAGE:
      handleImage(cmdName);
      break;
    case CMD_DOTFILE:
      handleDotFile(cmdName);
      break;
    case CMD_LINK:
      handleLink(cmdName,FALSE);
      break;
    case CMD_JAVALINK:
      handleLink(cmdName,TRUE);
      break;
4840 4841
    case CMD_REF: // fall through
    case CMD_SUBPAGE:
4842 4843 4844 4845 4846 4847 4848 4849 4850 4851
      handleRef(cmdName);
      break;
    case CMD_SECREFLIST:
      {
        DocSecRefList *list = new DocSecRefList(this);
        m_children.append(list);
        list->parse();
      }
      break;
    case CMD_SECREFITEM:
4852
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected command %s",g_token->name.data());
4853 4854
      break;
    case CMD_ENDSECREFLIST:
4855
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected command %s",g_token->name.data());
4856 4857 4858 4859 4860 4861 4862
      break;
    case CMD_FORMULA:
      {
        DocFormula *form=new DocFormula(this,g_token->id);
        m_children.append(form);
      }
      break;
4863 4864 4865
    //case CMD_LANGSWITCH:
    //  retval = handleLanguageSwitch();
    //  break;
4866
    case CMD_INTERNALREF:
4867
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: unexpected command %s",g_token->name.data());
4868
      break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
4869 4870 4871
    case CMD_INHERITDOC:
      handleInheritDoc();
      break;
4872 4873 4874 4875 4876
    default:
      // we should not get here!
      ASSERT(0);
      break;
  }
4877
  INTERNAL_ASSERT(retval==0 || retval==RetVal_OK || retval==RetVal_SimpleSec || 
4878 4879 4880 4881
         retval==TK_LISTITEM || retval==TK_ENDLIST || retval==TK_NEWPARA ||
         retval==RetVal_Section || retval==RetVal_EndList || 
         retval==RetVal_Internal || retval==RetVal_SwitchLang
        );
Dimitri van Heesch's avatar
Dimitri van Heesch committed
4882
  DBG(("handleCommand(%s) end retval=%x\n",cmdName.data(),retval));
4883 4884 4885
  return retval;
}

4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902
static bool findAttribute(const HtmlAttribList &tagHtmlAttribs, 
                          const char *attrName, 
                          QString *result) 
{

  HtmlAttribListIterator li(tagHtmlAttribs);
  HtmlAttrib *opt;
  for (li.toFirst();(opt=li.current());++li)
  {
    if (opt->name==attrName) 
    {
      *result = opt->value;
      return TRUE;
    }
  }
  return FALSE;
}
4903

4904
int DocPara::handleHtmlStartTag(const QString &tagName,const HtmlAttribList &tagHtmlAttribs)
4905
{
4906
  DBG(("handleHtmlStartTag(%s,%d)\n",tagName.data(),tagHtmlAttribs.count()));
4907
  int retval=RetVal_OK;
4908 4909 4910
  int tagId = Mappers::htmlTagMapper->map(tagName);
  if (g_token->emptyTag && !(tagId&XML_CmdMask) && tagId!=HTML_UNKNOWN)
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: HTML tags may not use the 'empty tag' XHTML syntax.");
4911 4912 4913 4914
  switch (tagId)
  {
    case HTML_UL: 
      {
4915
        DocHtmlList *list = new DocHtmlList(this,tagHtmlAttribs,DocHtmlList::Unordered);
4916 4917 4918 4919 4920 4921
        m_children.append(list);
        retval=list->parse();
      }
      break;
    case HTML_OL: 
      {
4922
        DocHtmlList *list = new DocHtmlList(this,tagHtmlAttribs,DocHtmlList::Ordered);
4923 4924 4925 4926 4927 4928 4929
        m_children.append(list);
        retval=list->parse();
      }
      break;
    case HTML_LI:
      if (!insideUL(this) && !insideOL(this))
      {
4930
        warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: lonely <li> tag found");
4931 4932 4933 4934 4935 4936 4937
      }
      else
      {
        retval=RetVal_ListItem;
      }
      break;
    case HTML_BOLD:
4938
      handleStyleEnter(this,m_children,DocStyleChange::Bold,&g_token->attribs);
4939 4940
      break;
    case HTML_CODE:
4941 4942 4943 4944 4945 4946 4947 4948 4949 4950
      if (g_fileName.right(3)==".cs") 
        // for C# code we treat <code> as an XML tag
      {
        doctokenizerYYsetStateXmlCode();
        retval = handleStartCode();
      }
      else // normal HTML markup
      {
        handleStyleEnter(this,m_children,DocStyleChange::Code,&g_token->attribs);
      }
4951 4952
      break;
    case HTML_EMPHASIS:
4953
      handleStyleEnter(this,m_children,DocStyleChange::Italic,&g_token->attribs);
4954
      break;
4955 4956 4957 4958 4959 4960
    case HTML_DIV:
      handleStyleEnter(this,m_children,DocStyleChange::Div,&g_token->attribs);
      break;
    case HTML_SPAN:
      handleStyleEnter(this,m_children,DocStyleChange::Span,&g_token->attribs);
      break;
4961
    case HTML_SUB:
4962
      handleStyleEnter(this,m_children,DocStyleChange::Subscript,&g_token->attribs);
4963 4964
      break;
    case HTML_SUP:
4965
      handleStyleEnter(this,m_children,DocStyleChange::Superscript,&g_token->attribs);
4966 4967
      break;
    case HTML_CENTER:
4968
      handleStyleEnter(this,m_children,DocStyleChange::Center,&g_token->attribs);
4969 4970
      break;
    case HTML_SMALL:
4971 4972 4973 4974 4975
      handleStyleEnter(this,m_children,DocStyleChange::Small,&g_token->attribs);
      break;
    case HTML_PRE:
      handleStyleEnter(this,m_children,DocStyleChange::Preformatted,&g_token->attribs);
      setInsidePreformatted(TRUE);
4976
      //doctokenizerYYsetInsidePre(TRUE);
4977 4978 4979 4980 4981 4982
      break;
    case HTML_P:
      retval=TK_NEWPARA;
      break;
    case HTML_DL:
      {
4983
        DocHtmlDescList *list = new DocHtmlDescList(this,tagHtmlAttribs);
4984 4985 4986 4987 4988 4989 4990 4991
        m_children.append(list);
        retval=list->parse();
      }
      break;
    case HTML_DT:
      retval = RetVal_DescTitle;
      break;
    case HTML_DD:
4992
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected tag <dd> found");
4993 4994 4995
      break;
    case HTML_TABLE:
      {
4996
        DocHtmlTable *table = new DocHtmlTable(this,tagHtmlAttribs);
4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010
        m_children.append(table);
        retval=table->parse();
      }
      break;
    case HTML_TR:
      retval = RetVal_TableRow;
      break;
    case HTML_TD:
      retval = RetVal_TableCell;
      break;
    case HTML_TH:
      retval = RetVal_TableHCell;
      break;
    case HTML_CAPTION:
5011
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected tag <caption> found");
5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025
      break;
    case HTML_BR:
      {
        DocLineBreak *lb = new DocLineBreak(this);
        m_children.append(lb);
      }
      break;
    case HTML_HR:
      {
        DocHorRuler *hr = new DocHorRuler(this);
        m_children.append(hr);
      }
      break;
    case HTML_A:
5026
      retval=handleAHref(this,m_children,tagHtmlAttribs);
5027 5028
      break;
    case HTML_H1:
Dimitri van Heesch's avatar
Dimitri van Heesch committed
5029
      retval=handleHtmlHeader(tagHtmlAttribs,1);
5030 5031
      break;
    case HTML_H2:
Dimitri van Heesch's avatar
Dimitri van Heesch committed
5032
      retval=handleHtmlHeader(tagHtmlAttribs,2);
5033 5034
      break;
    case HTML_H3:
Dimitri van Heesch's avatar
Dimitri van Heesch committed
5035
      retval=handleHtmlHeader(tagHtmlAttribs,3);
5036
      break;
5037
    case HTML_H4:
Dimitri van Heesch's avatar
Dimitri van Heesch committed
5038
      retval=handleHtmlHeader(tagHtmlAttribs,4);
5039 5040
      break;
    case HTML_H5:
Dimitri van Heesch's avatar
Dimitri van Heesch committed
5041
      retval=handleHtmlHeader(tagHtmlAttribs,5);
5042 5043
      break;
    case HTML_H6:
Dimitri van Heesch's avatar
Dimitri van Heesch committed
5044
      retval=handleHtmlHeader(tagHtmlAttribs,6);
5045
      break;
5046 5047
    case HTML_IMG:
      {
5048 5049
        HtmlAttribListIterator li(tagHtmlAttribs);
        HtmlAttrib *opt;
5050
        bool found=FALSE;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
5051 5052
        int index=0;
        for (li.toFirst();(opt=li.current());++li,++index)
5053
        {
5054
          //printf("option name=%s value=%s\n",opt->name.data(),opt->value.data());
5055 5056
          if (opt->name=="src" && !opt->value.isEmpty())
          {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
5057 5058 5059 5060 5061 5062
            // copy attributes
            HtmlAttribList attrList = tagHtmlAttribs;
            // and remove the href attribute
            bool result = attrList.remove(index);
            ASSERT(result);
            DocImage *img = new DocImage(this,attrList,opt->value,DocImage::Html);
5063
            m_children.append(img);
5064
            found = TRUE;
5065 5066
          }
        }
5067 5068 5069 5070
        if (!found)
        {
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: IMG tag does not have a SRC attribute!\n");
        }
5071 5072
      }
      break;
5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084

    case XML_SUMMARY:
    case XML_REMARKS:
    case XML_VALUE:
    case XML_PARA:
      if (!m_children.isEmpty())
      {
        retval = TK_NEWPARA;
      }
      break;
    case XML_EXAMPLE:
    case XML_DESCRIPTION:
5085 5086 5087 5088
      if (insideTable(this))
      {
        retval=RetVal_TableCell;
      }
5089 5090 5091 5092 5093
      break;
    case XML_C:
      handleStyleEnter(this,m_children,DocStyleChange::Code,&g_token->attribs);
      break;
    case XML_PARAM:
Dimitri van Heesch's avatar
Dimitri van Heesch committed
5094
    case XML_TYPEPARAM:
5095 5096 5097 5098
      {
        QString paramName;
        if (findAttribute(tagHtmlAttribs,"name",&paramName))
	{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
5099 5100 5101
          retval = handleParamSection(paramName,
              tagId==XML_PARAM ? DocParamSect::Param : DocParamSect::TemplateParam,
              TRUE);
5102 5103 5104 5105 5106 5107 5108 5109
        }
        else
        {
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Missing 'name' attribute from <param> tag.");
        }
      }
      break;
    case XML_PARAMREF:
Dimitri van Heesch's avatar
Dimitri van Heesch committed
5110
    case XML_TYPEPARAMREF:
5111 5112 5113 5114
      {
        QString paramName;
        if (findAttribute(tagHtmlAttribs,"name",&paramName))
        {
5115
          //printf("paramName=%s\n",paramName.data());
5116
          m_children.append(new DocStyleChange(this,g_nodeStack.count(),DocStyleChange::Italic,TRUE));
5117
          m_children.append(new DocWord(this,paramName)); 
5118 5119 5120 5121 5122
          m_children.append(new DocStyleChange(this,g_nodeStack.count(),DocStyleChange::Italic,FALSE));
          if (retval!=TK_WORD) m_children.append(new DocWhiteSpace(this," "));
        }
        else
        {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
5123
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Missing 'name' attribute from <param%sref> tag.",tagId==XML_PARAMREF?"":"type");
5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140
        }
      }
      break;
    case XML_EXCEPTION:
      {
        QString exceptName;
        if (findAttribute(tagHtmlAttribs,"cref",&exceptName))
	{
          retval = handleParamSection(exceptName,DocParamSect::Exception,TRUE);
        }
        else
        {
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Missing 'name' attribute from <exception> tag.");
        }
      }
      break;
    case XML_ITEM:
5141 5142
    case XML_LISTHEADER:
      if (insideTable(this))
5143
      {
5144
        retval=RetVal_TableRow;
5145
      }
5146
      else if (insideUL(this) || insideOL(this))
5147 5148 5149
      {
        retval=RetVal_ListItem;
      }
5150 5151 5152 5153
      else
      {
        warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: lonely <item> tag found");
      }
5154 5155 5156 5157 5158
      break;
    case XML_RETURNS:
      retval = handleSimpleSection(DocSimpleSect::Return,TRUE);
      g_hasReturnCommand=TRUE;
      break;
5159 5160 5161 5162 5163 5164 5165
    case XML_TERM:
      m_children.append(new DocStyleChange(this,g_nodeStack.count(),DocStyleChange::Bold,TRUE));
      if (insideTable(this))
      {
        retval=RetVal_TableCell;
      }
      break;
5166 5167 5168 5169 5170 5171 5172
    case XML_SEE:
      // I'm not sure if <see> is the same as <seealso> or if it
      // should you link a member without producing a section. The
      // C# specification is extremely vague about this (but what else 
      // can we expect from Microsoft...)
      {
        QString cref;
5173
        //printf("XML_SEE: empty tag=%d\n",g_token->emptyTag);
5174 5175
        if (findAttribute(tagHtmlAttribs,"cref",&cref))
        {
5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197
          if (g_token->emptyTag) // <see cref="..."/> style
          {
            bool inSeeBlock = g_inSeeBlock;
            g_token->name = cref;
            g_inSeeBlock = TRUE;
            handleLinkedWord(this,m_children);
            g_inSeeBlock = inSeeBlock;
          }
          else // <see cref="...">...</see> style
          {
            //DocRef *ref = new DocRef(this,cref);
            //m_children.append(ref);
            //ref->parse();
            doctokenizerYYsetStatePara();
            DocLink *lnk = new DocLink(this,cref);
            m_children.append(lnk);
            QString leftOver = lnk->parse(FALSE,TRUE);
            if (!leftOver.isEmpty())
            {
              m_children.append(new DocWord(this,leftOver));
            }
          }
5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239
        }
        else
        {
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Missing 'cref' attribute from <see> tag.");
        }
      }
      break;
    case XML_SEEALSO:
      {
        QString cref;
        if (findAttribute(tagHtmlAttribs,"cref",&cref))
	{
	  // Look for an existing "see" section
          DocSimpleSect *ss=0;
          QListIterator<DocNode> cli(m_children);
          DocNode *n;
          for (cli.toFirst();(n=cli.current());++cli)
          {
            if (n->kind()==Kind_SimpleSect && ((DocSimpleSect *)n)->type()==DocSimpleSect::See)
            {
              ss = (DocSimpleSect *)n;
            }
          }
  
          if (!ss)  // start new section
          {
            ss=new DocSimpleSect(this,DocSimpleSect::See);
            m_children.append(ss);
          }
          
          ss->appendLinkWord(cref);
	  retval = RetVal_OK;
        }
        else
        {
          warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Missing 'cref' attribute from <seealso> tag.");
        }
      }
      break;
    case XML_LIST:
      {
        QString type;
5240
        findAttribute(tagHtmlAttribs,"type",&type);
5241
        DocHtmlList::Type listType = DocHtmlList::Unordered;
5242
        if (type=="number")
5243 5244 5245
        {
          listType=DocHtmlList::Ordered;
        }
5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258
        if (type=="table")
        {
          DocHtmlTable *table = new DocHtmlTable(this,tagHtmlAttribs);
          m_children.append(table);
          retval=table->parseXml();
        }
        else
        {
          HtmlAttribList emptyList;
          DocHtmlList *list = new DocHtmlList(this,emptyList,listType);
          m_children.append(list);
          retval=list->parseXml();
        }
5259 5260 5261 5262 5263 5264
      }
      break;
    case XML_INCLUDE:
    case XML_PERMISSION:
      // These tags are defined in .Net but are currently unsupported
      break;
5265
    case HTML_UNKNOWN:
5266
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unsupported xml/html tag <%s> found", tagName.data());
5267
      m_children.append(new DocWord(this, "<"+tagName+tagHtmlAttribs.toString()+">"));
5268
      break;
5269 5270 5271 5272 5273 5274 5275 5276
    default:
      // we should not get here!
      ASSERT(0);
      break;
  }
  return retval;
}

5277
int DocPara::handleHtmlEndTag(const QString &tagName)
5278 5279
{
  DBG(("handleHtmlEndTag(%s)\n",tagName.data()));
5280
  int tagId = Mappers::htmlTagMapper->map(tagName);
5281 5282 5283 5284 5285 5286
  int retval=RetVal_OK;
  switch (tagId)
  {
    case HTML_UL: 
      if (!insideUL(this))
      {
5287
        warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: found </ul> tag without matching <ul>");
5288 5289 5290 5291 5292 5293 5294 5295 5296
      }
      else
      {
        retval=RetVal_EndList;
      }
      break;
    case HTML_OL: 
      if (!insideOL(this))
      {
5297
        warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: found </ol> tag without matching <ol>");
5298 5299 5300 5301 5302 5303 5304 5305 5306
      }
      else
      {
        retval=RetVal_EndList;
      }
      break;
    case HTML_LI:
      if (!insideLI(this))
      {
5307
        warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: found </li> tag without matching <li>");
5308 5309 5310 5311 5312 5313
      }
      else
      {
        // ignore </li> tags
      }
      break;
5314 5315 5316
    //case HTML_PRE:
    //  if (!insidePRE(this))
    //  {
5317
    //    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: found </pre> tag without matching <pre>");
5318 5319 5320 5321 5322 5323
    //  }
    //  else
    //  {
    //    retval=RetVal_EndPre;
    //  }
    //  break;
5324 5325 5326 5327 5328 5329 5330 5331 5332
    case HTML_BOLD:
      handleStyleLeave(this,m_children,DocStyleChange::Bold,"b");
      break;
    case HTML_CODE:
      handleStyleLeave(this,m_children,DocStyleChange::Code,"code");
      break;
    case HTML_EMPHASIS:
      handleStyleLeave(this,m_children,DocStyleChange::Italic,"em");
      break;
5333 5334 5335 5336 5337 5338
    case HTML_DIV:
      handleStyleLeave(this,m_children,DocStyleChange::Div,"div");
      break;
    case HTML_SPAN:
      handleStyleLeave(this,m_children,DocStyleChange::Span,"span");
      break;
5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350
    case HTML_SUB:
      handleStyleLeave(this,m_children,DocStyleChange::Subscript,"sub");
      break;
    case HTML_SUP:
      handleStyleLeave(this,m_children,DocStyleChange::Superscript,"sup");
      break;
    case HTML_CENTER:
      handleStyleLeave(this,m_children,DocStyleChange::Center,"center");
      break;
    case HTML_SMALL:
      handleStyleLeave(this,m_children,DocStyleChange::Small,"small");
      break;
5351
    case HTML_PRE:
5352
      handleStyleLeave(this,m_children,DocStyleChange::Preformatted,"pre");
5353
      setInsidePreformatted(FALSE);
5354
      //doctokenizerYYsetInsidePre(FALSE);
5355
      break;
5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380
    case HTML_P:
      // ignore </p> tag
      break;
    case HTML_DL:
      retval=RetVal_EndDesc;
      break;
    case HTML_DT:
      // ignore </dt> tag
      break;
    case HTML_DD:
      // ignore </dd> tag
      break;
    case HTML_TABLE:
      retval=RetVal_EndTable;
      break;
    case HTML_TR:
      // ignore </tr> tag
      break;
    case HTML_TD:
      // ignore </td> tag
      break;
    case HTML_TH:
      // ignore </th> tag
      break;
    case HTML_CAPTION:
5381
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected tag </caption> found");
5382 5383
      break;
    case HTML_BR:
5384
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Illegal </br> tag found\n");
5385 5386
      break;
    case HTML_H1:
5387
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected tag </h1> found");
5388 5389
      break;
    case HTML_H2:
5390
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected tag </h2> found");
5391 5392
      break;
    case HTML_H3:
5393
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected tag </h3> found");
5394 5395
      break;
    case HTML_IMG:
5396
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected tag </img> found");
5397 5398
      break;
    case HTML_HR:
5399
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected tag </hr> found");
5400 5401
      break;
    case HTML_A:
5402
      //warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected tag </a> found");
5403 5404
      // ignore </a> tag (can be part of <a name=...></a>
      break;
5405

5406 5407 5408
    case XML_TERM:
      m_children.append(new DocStyleChange(this,g_nodeStack.count(),DocStyleChange::Bold,FALSE));
      break;
5409 5410 5411 5412 5413 5414 5415
    case XML_SUMMARY:
    case XML_REMARKS:
    case XML_PARA:
    case XML_VALUE:
    case XML_LIST:
    case XML_EXAMPLE:
    case XML_PARAM:
Dimitri van Heesch's avatar
Dimitri van Heesch committed
5416
    case XML_TYPEPARAM:
5417 5418 5419 5420 5421 5422 5423 5424 5425
    case XML_RETURNS:
    case XML_SEEALSO:
    case XML_EXCEPTION:
      retval = RetVal_CloseXml;
      break;
    case XML_C:
      handleStyleLeave(this,m_children,DocStyleChange::Code,"c");
      break;
    case XML_ITEM:
5426
    case XML_LISTHEADER:
5427 5428 5429 5430
    case XML_INCLUDE:
    case XML_PERMISSION:
    case XML_DESCRIPTION:
    case XML_PARAMREF:
Dimitri van Heesch's avatar
Dimitri van Heesch committed
5431
    case XML_TYPEPARAMREF:
5432 5433
      // These tags are defined in .Net but are currently unsupported
      break;
5434
    case HTML_UNKNOWN:
5435
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unsupported xml/html tag </%s> found", tagName.data());
5436
      m_children.append(new DocWord(this,"</"+tagName+">"));
5437 5438 5439
      break;
    default:
      // we should not get here!
5440
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Unexpected end tag %s\n",tagName.data());
5441 5442 5443 5444 5445 5446 5447 5448 5449 5450
      ASSERT(0);
      break;
  }
  return retval;
}

int DocPara::parse()
{
  DBG(("DocPara::parse() start\n"));
  g_nodeStack.push(this);
5451
  // handle style commands "inherited" from the previous paragraph
5452
  handleInitialStyleCommands(this,m_children);
5453 5454 5455 5456 5457 5458
  int tok;
  int retval=0;
  while ((tok=doctokenizerYYlex())) // get the next token
  {
reparsetoken:
    DBG(("token %s at %d",tokToString(tok),doctokenizerYYlineno));
5459
    if (tok==TK_WORD || tok==TK_LNKWORD || tok==TK_SYMBOL || tok==TK_URL || 
5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470
        tok==TK_COMMAND || tok==TK_HTMLTAG
       )
    {
      DBG((" name=%s",g_token->name.data()));
    }
    DBG(("\n"));
    switch(tok)
    {
      case TK_WORD:        
	m_children.append(new DocWord(this,g_token->name));
	break;
5471 5472 5473
      case TK_LNKWORD:        
        handleLinkedWord(this,m_children);
	break;
5474
      case TK_URL:
5475
        m_children.append(new DocURL(this,g_token->name,g_token->isEMailAddr));
5476 5477
        break;
      case TK_WHITESPACE:  
5478 5479 5480
        {
          // prevent leading whitespace and collapse multiple whitespace areas
          DocNode::Kind k; 
5481
          if (insidePRE(this) || // all whitespace is relevant
5482 5483 5484 5485 5486 5487 5488 5489 5490 5491
              (                
               // remove leading whitespace 
               !m_children.isEmpty()  && 
               // and whitespace after certain constructs
               (k=m_children.last()->kind())!=DocNode::Kind_HtmlDescList &&
               k!=DocNode::Kind_HtmlTable &&
               k!=DocNode::Kind_HtmlList &&
               k!=DocNode::Kind_SimpleSect &&
               k!=DocNode::Kind_AutoList &&
               k!=DocNode::Kind_SimpleList &&
5492
               /*k!=DocNode::Kind_Verbatim &&*/
5493 5494 5495 5496 5497 5498 5499 5500 5501
               k!=DocNode::Kind_HtmlHeader &&
               k!=DocNode::Kind_ParamSect &&
               k!=DocNode::Kind_XRefItem
              )
             )
          {
            m_children.append(new DocWhiteSpace(this,g_token->chars));
          }
        }
5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518
	break;
      case TK_LISTITEM:    
	{
	  DBG(("found list item at %d parent=%d\n",g_token->indent,parent()->kind()));
	  DocNode *n=parent();
	  while (n && n->kind()!=DocNode::Kind_AutoList) n=n->parent();
	  if (n) // we found an auto list up in the hierarchy
	  {
	    DocAutoList *al = (DocAutoList *)n;
	    DBG(("previous list item at %d\n",al->indent()));
	    if (al->indent()>=g_token->indent) 
	      // new item at the same or lower indent level
	    {
	      retval=TK_LISTITEM;
	      goto endparagraph;
	    }
	  }
5519 5520 5521 5522 5523 5524 5525 5526 5527

          // determine list depth
          int depth = 0;
          n=parent();
          while(n) {
            if(n->kind() == DocNode::Kind_AutoList) ++depth;
            n=n->parent();
          }

5528 5529 5530 5531
	  // first item or sub list => create new list
	  DocAutoList *al=0;
	  do
	  {
5532 5533
	    al = new DocAutoList(this,g_token->indent,g_token->isEnumList,
                                 depth);
5534 5535 5536
	    m_children.append(al);
	    retval = al->parse();
	  } while (retval==TK_LISTITEM &&         // new list
5537
	           al->indent()==g_token->indent  // at same indent level
5538 5539 5540 5541 5542 5543 5544 5545 5546
		  );
	      
	  // check the return value
	  if (retval==RetVal_SimpleSec) // auto list ended due to simple section command
	  {
	    // Reparse the token that ended the section at this level,
	    // so a new simple section will be started at this level.
	    // This is the same as unputting the last read token and continuing.
	    g_token->name = g_token->simpleSectName;
5547 5548 5549 5550 5551 5552 5553 5554 5555 5556
            if (g_token->name.left(4)=="rcs:") // RCS section
            {
              g_token->name = g_token->name.mid(4);
              g_token->text = g_token->simpleSectText;
              tok = TK_RCSTAG;
            }
            else // other section
            {
	      tok = TK_COMMAND;
            }
5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589
	    DBG(("reparsing command %s\n",g_token->name.data()));
	    goto reparsetoken;
	  }
	  else if (retval==TK_ENDLIST)
	  {
	    if (al->indent()>g_token->indent) // end list
	    {
	      goto endparagraph;
	    }
	    else // continue with current paragraph
	    {
	    }
	  }
	  else // paragraph ended due to TK_NEWPARA, TK_LISTITEM, or EOF
	  {
	    goto endparagraph;
	  }
	}
	break;
      case TK_ENDLIST:     
	DBG(("Found end of list inside of paragraph at line %d\n",doctokenizerYYlineno));
	if (parent()->kind()==DocNode::Kind_AutoListItem)
	{
	  ASSERT(parent()->parent()->kind()==DocNode::Kind_AutoList);
	  DocAutoList *al = (DocAutoList *)parent()->parent();
	  if (al->indent()>=g_token->indent)
	  {
	    // end of list marker ends this paragraph
	    retval=TK_ENDLIST;
	    goto endparagraph;
	  }
	  else
	  {
5590
	    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: End of list marker found "
5591
		   "has invalid indent level");
5592 5593 5594 5595
	  }
	}
	else
	{
5596
	  warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: End of list marker found without any preceding "
5597
	         "list items");
5598 5599 5600 5601 5602
	}
	break;
      case TK_COMMAND:    
	{
	  // see if we have to start a simple section
5603
	  int cmd = Mappers::cmdMapper->map(g_token->name);
5604
	  DocNode *n=parent();
5605 5606 5607 5608 5609 5610 5611
	  while (n && 
                 n->kind()!=DocNode::Kind_SimpleSect && 
                 n->kind()!=DocNode::Kind_ParamSect
                ) 
          {
            n=n->parent();
          }
5612 5613
	  if (cmd&SIMPLESECT_BIT)
	  {
5614
	    if (n)  // already in a simple section
5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636
	    {
	      // simple section cannot start in this paragraph, need
	      // to unwind the stack and remember the command.
	      g_token->simpleSectName = g_token->name.copy();
	      retval=RetVal_SimpleSec;
	      goto endparagraph;
	    }
	  }
	  // see if we are in a simple list
	  n=parent();
	  while (n && n->kind()!=DocNode::Kind_SimpleListItem) n=n->parent();
	  if (n)
	  {
	    if (cmd==CMD_LI)
	    {
	      retval=RetVal_ListItem;
	      goto endparagraph;
	    }
	  }
	  
	  // handle the command
	  retval=handleCommand(g_token->name.copy());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
5637
          DBG(("handleCommand returns %x\n",retval));
5638 5639 5640 5641 5642 5643 5644 5645

	  // check the return value
	  if (retval==RetVal_SimpleSec)
	  {
	    // Reparse the token that ended the section at this level,
	    // so a new simple section will be started at this level.
	    // This is the same as unputting the last read token and continuing.
	    g_token->name = g_token->simpleSectName;
5646 5647 5648 5649 5650 5651 5652 5653 5654 5655
            if (g_token->name.left(4)=="rcs:") // RCS section
            {
              g_token->name = g_token->name.mid(4);
              g_token->text = g_token->simpleSectText;
              tok = TK_RCSTAG;
            }
            else // other section
            {
	      tok = TK_COMMAND;
            }
5656 5657 5658 5659 5660
	    DBG(("reparsing command %s\n",g_token->name.data()));
	    goto reparsetoken;
	  }
	  else if (retval==RetVal_OK) 
	  {
5661
	    // the command ended normally, keep scanning for new tokens.
5662 5663
	    retval = 0;
	  }
5664 5665 5666
          else if (retval>0 && retval<RetVal_OK)
          { 
            // the command ended with a new command, reparse this token
Dimitri van Heesch's avatar
Dimitri van Heesch committed
5667 5668 5669
            tok = retval;
            goto reparsetoken;
          }
5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680
	  else // end of file, end of paragraph, start or end of section 
	       // or some auto list marker
	  {
	    goto endparagraph;
	  }
	}
	break;
      case TK_HTMLTAG:    
        {
          if (!g_token->endTag) // found a start tag
          {
5681
            retval = handleHtmlStartTag(g_token->name,g_token->attribs);
5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698
          }
          else // found an end tag
          {
            retval = handleHtmlEndTag(g_token->name);
          }
          if (retval==RetVal_OK) 
          {
	    // the command ended normally, keep scanner for new tokens.
            retval = 0;
          }
          else
          {
            goto endparagraph;
          }
        }
	break;
      case TK_SYMBOL:     
5699 5700 5701 5702 5703 5704 5705 5706 5707
        {
          char letter='\0';
          DocSymbol::SymType s = DocSymbol::decodeSymbol(g_token->name,&letter);
          if (s!=DocSymbol::Unknown)
          {
            m_children.append(new DocSymbol(this,s,letter));
          }
          else
          {
5708
            warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unsupported symbol %s found",
5709
                g_token->name.data());
5710 5711 5712
          }
          break;
        }
5713 5714 5715
      case TK_NEWPARA:     
	retval=TK_NEWPARA;
	goto endparagraph;
5716 5717
      case TK_RCSTAG:
        {
5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736
	  DocNode *n=parent();
	  while (n && 
                 n->kind()!=DocNode::Kind_SimpleSect && 
                 n->kind()!=DocNode::Kind_ParamSect
                ) 
          {
            n=n->parent();
          }
	  if (n)  // already in a simple section
	  {
	    // simple section cannot start in this paragraph, need
	    // to unwind the stack and remember the command.
	    g_token->simpleSectName = "rcs:"+g_token->name;
            g_token->simpleSectText = g_token->text;
	    retval=RetVal_SimpleSec;
	    goto endparagraph;
	  }

	  // see if we are in a simple list
5737 5738 5739 5740 5741 5742 5743 5744 5745
          DocSimpleSect *ss=new DocSimpleSect(this,DocSimpleSect::Rcs);
          m_children.append(ss);
          ss->parseRcs();
        }
        break;
      default:
        warn_doc_error(g_fileName,doctokenizerYYlineno,
            "Warning: Found unexpected token (id=%x)\n",tok);
        break;
5746 5747
    }
  }
5748
  retval=0;
5749 5750 5751 5752 5753
endparagraph:
  handlePendingStyleCommands(this,m_children);
  DocNode *n = g_nodeStack.pop();
  ASSERT(n==this);
  DBG(("DocPara::parse() end retval=%x\n",retval));
5754
  INTERNAL_ASSERT(retval==0 || retval==TK_NEWPARA || retval==TK_LISTITEM || 
5755 5756 5757 5758 5759 5760 5761 5762 5763 5764
         retval==TK_ENDLIST || retval>RetVal_OK 
	);

  return retval; 
}

//--------------------------------------------------------------------------

int DocSection::parse()
{
5765
  DBG(("DocSection::parse() start %s level=%d\n",g_token->sectionId.data(),m_level));
5766 5767 5768
  int retval=RetVal_OK;
  g_nodeStack.push(this);

5769 5770 5771 5772 5773 5774 5775 5776 5777 5778
  SectionInfo *sec;
  if (!m_id.isEmpty())
  {
    sec=Doxygen::sectionDict[m_id];
    if (sec)
    {
      m_file   = sec->fileName;
      m_anchor = sec->label;
      m_title  = sec->title;
      if (m_title.isEmpty()) m_title = sec->label;
5779 5780 5781 5782
      if (g_sectionDict && g_sectionDict->find(m_id)==0)
      {
        g_sectionDict->insert(m_id,sec);
      }
5783 5784 5785
    }
  }

5786
  // first parse any number of paragraphs
5787
  bool isFirst=TRUE;
5788
  DocPara *lastPar=0;
5789 5790 5791
  do
  {
    DocPara *par = new DocPara(this);
5792
    if (isFirst) { par->markFirst(); isFirst=FALSE; }
5793
    retval=par->parse();
5794 5795 5796
    if (!par->isEmpty()) 
    {
      m_children.append(par);
5797 5798 5799 5800 5801
      lastPar=par;
    }
    else
    {
      delete par;
5802
    }
5803 5804
    if (retval==TK_LISTITEM)
    {
5805
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Invalid list item found");
5806
    }
5807 5808 5809 5810 5811 5812 5813 5814
  } while (retval!=0 && 
           retval!=RetVal_Internal      &&
           retval!=RetVal_Section       &&
           retval!=RetVal_Subsection    &&
           retval!=RetVal_Subsubsection &&
           retval!=RetVal_Paragraph    
          );

5815
  if (lastPar) lastPar->markLast();
5816

5817 5818 5819
  //printf("m_level=%d <-> %d\n",m_level,Doxygen::subpageNestingLevel);

  if (retval==RetVal_Subsection && m_level==Doxygen::subpageNestingLevel+1)
5820
  {
5821 5822
    // then parse any number of nested sections
    while (retval==RetVal_Subsection) // more sections follow
5823
    {
5824
      //SectionInfo *sec=Doxygen::sectionDict[g_token->sectionId];
5825
      DocSection *s=new DocSection(this,
5826
          QMIN(2+Doxygen::subpageNestingLevel,5),g_token->sectionId);
5827 5828
      m_children.append(s);
      retval = s->parse();
5829
    }
5830
  }
5831
  else if (retval==RetVal_Subsubsection && m_level==Doxygen::subpageNestingLevel+2)
5832 5833 5834
  {
    // then parse any number of nested sections
    while (retval==RetVal_Subsubsection) // more sections follow
5835
    {
5836
      //SectionInfo *sec=Doxygen::sectionDict[g_token->sectionId];
5837
      DocSection *s=new DocSection(this,
5838
          QMIN(3+Doxygen::subpageNestingLevel,5),g_token->sectionId);
5839 5840
      m_children.append(s);
      retval = s->parse();
5841
    }
5842
  }
5843
  else if (retval==RetVal_Paragraph && m_level==QMIN(5,Doxygen::subpageNestingLevel+3))
5844 5845 5846
  {
    // then parse any number of nested sections
    while (retval==RetVal_Paragraph) // more sections follow
5847
    {
5848
      //SectionInfo *sec=Doxygen::sectionDict[g_token->sectionId];
5849 5850
      DocSection *s=new DocSection(this,
          QMIN(4+Doxygen::subpageNestingLevel,5),g_token->sectionId);
5851 5852 5853 5854
      m_children.append(s);
      retval = s->parse();
    }
  }
5855 5856
  else if ((m_level<=1+Doxygen::subpageNestingLevel && retval==RetVal_Subsubsection) ||
           (m_level<=2+Doxygen::subpageNestingLevel && retval==RetVal_Paragraph)
5857 5858 5859 5860 5861 5862
          ) 
  {
    int level; 
    if (retval==RetVal_Subsection) level=2; 
    else if (retval==RetVal_Subsubsection) level=3;
    else level=4;
5863
    warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected %s "
5864 5865 5866 5867 5868
            "command found inside %s!",
            sectionLevelToName[level],sectionLevelToName[m_level]);
    retval=0; // stop parsing
            
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
5869 5870 5871 5872 5873 5874
  else if (retval==RetVal_Internal)
  {
    DocInternal *in = new DocInternal(this);
    m_children.append(in);
    retval = in->parse(m_level+1);
  }
5875 5876 5877
  else
  {
  }
5878 5879 5880 5881 5882 5883 5884 5885

  INTERNAL_ASSERT(retval==0 || 
                  retval==RetVal_Section || 
                  retval==RetVal_Subsection || 
                  retval==RetVal_Subsubsection || 
                  retval==RetVal_Paragraph || 
                  retval==RetVal_Internal
                 );
5886 5887 5888 5889 5890 5891 5892

  DBG(("DocSection::parse() end\n"));
  DocNode *n = g_nodeStack.pop();
  ASSERT(n==this);
  return retval;
}

5893 5894 5895 5896
//--------------------------------------------------------------------------

void DocText::parse()
{
5897
  DBG(("DocText::parse() start\n"));
5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921
  g_nodeStack.push(this);
  doctokenizerYYsetStateText();
  
  int tok;
  while ((tok=doctokenizerYYlex())) // get the next token
  {
    switch(tok)
    {
      case TK_WORD:        
	m_children.append(new DocWord(this,g_token->name));
	break;
      case TK_WHITESPACE:  
        m_children.append(new DocWhiteSpace(this,g_token->chars));
	break;
      case TK_SYMBOL:     
        {
          char letter='\0';
          DocSymbol::SymType s = DocSymbol::decodeSymbol(g_token->name,&letter);
          if (s!=DocSymbol::Unknown)
          {
            m_children.append(new DocSymbol(this,s,letter));
          }
          else
          {
5922
            warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unsupported symbol %s found",
5923 5924 5925 5926 5927
                g_token->name.data());
          }
        }
        break;
      case TK_COMMAND: 
5928
        switch (Mappers::cmdMapper->map(g_token->name))
5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954
        {
          case CMD_BSLASH:
            m_children.append(new DocSymbol(this,DocSymbol::BSlash));
            break;
          case CMD_AT:
            m_children.append(new DocSymbol(this,DocSymbol::At));
            break;
          case CMD_LESS:
            m_children.append(new DocSymbol(this,DocSymbol::Less));
            break;
          case CMD_GREATER:
            m_children.append(new DocSymbol(this,DocSymbol::Greater));
            break;
          case CMD_AMP:
            m_children.append(new DocSymbol(this,DocSymbol::Amp));
            break;
          case CMD_DOLLAR:
            m_children.append(new DocSymbol(this,DocSymbol::Dollar));
            break;
          case CMD_HASH:
            m_children.append(new DocSymbol(this,DocSymbol::Hash));
            break;
          case CMD_PERCENT:
            m_children.append(new DocSymbol(this,DocSymbol::Percent));
            break;
          default:
5955
            warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected command `%s' found",
5956 5957 5958 5959 5960
                      g_token->name.data());
            break;
        }
        break;
      default:
5961
        warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Unexpected token %s",
5962 5963 5964 5965 5966
            tokToString(tok));
        break;
    }
  }

5967 5968
  handleUnclosedStyleCommands();

5969 5970
  DocNode *n = g_nodeStack.pop();
  ASSERT(n==this);
5971
  DBG(("DocText::parse() end\n"));
5972 5973 5974
}


5975 5976 5977 5978
//--------------------------------------------------------------------------

void DocRoot::parse()
{
5979
  DBG(("DocRoot::parse() start\n"));
5980 5981 5982 5983 5984
  g_nodeStack.push(this);
  doctokenizerYYsetStatePara();
  int retval=0;

  // first parse any number of paragraphs
5985
  bool isFirst=TRUE;
5986
  DocPara *lastPar=0;
5987 5988
  do
  {
5989 5990
    DocPara *par = new DocPara(this);
    if (isFirst) { par->markFirst(); isFirst=FALSE; }
5991
    retval=par->parse();
5992 5993 5994
    if (!par->isEmpty()) 
    {
      m_children.append(par);
5995 5996 5997 5998 5999
      lastPar=par;
    }
    else
    {
      delete par;
6000
    }
6001 6002
    if (retval==TK_LISTITEM)
    {
6003
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Invalid list item found");
6004
    }
6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016
    else if (retval==RetVal_Subsection)
    {
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: found subsection command outside of section context!");
    }
    else if (retval==RetVal_Subsubsection)
    {
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: found subsubsection command outside of subsection context!");
    }
    else if (retval==RetVal_Paragraph)
    {
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: found paragraph command outside of subsubsection context!");
    }
6017
  } while (retval!=0 && retval!=RetVal_Section && retval!=RetVal_Internal);
6018
  if (lastPar) lastPar->markLast();
6019

6020
  //printf("DocRoot::parse() retval=%d %d\n",retval,RetVal_Section);
6021 6022 6023 6024
  // then parse any number of level1 sections
  while (retval==RetVal_Section)
  {
    SectionInfo *sec=Doxygen::sectionDict[g_token->sectionId];
Dimitri van Heesch's avatar
Dimitri van Heesch committed
6025 6026
    if (sec)
    {
6027
      DocSection *s=new DocSection(this,
6028
          QMIN(1+Doxygen::subpageNestingLevel,5),g_token->sectionId);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
6029 6030 6031 6032 6033
      m_children.append(s);
      retval = s->parse();
    }
    else
    {
6034
      warn_doc_error(g_fileName,doctokenizerYYlineno,"Warning: Invalid section id `%s'; ignoring section",g_token->sectionId.data());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
6035 6036
      retval = 0;
    }
6037 6038 6039 6040 6041 6042
  }

  if (retval==RetVal_Internal)
  {
    DocInternal *in = new DocInternal(this);
    m_children.append(in);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
6043
    retval = in->parse(1);
6044 6045
  }

6046

6047 6048
  handleUnclosedStyleCommands();

6049 6050
  DocNode *n = g_nodeStack.pop();
  ASSERT(n==this);
6051
  DBG(("DocRoot::parse() end\n"));
6052 6053 6054 6055
}

//--------------------------------------------------------------------------

6056
DocNode *validatingParseDoc(const char *fileName,int startLine,
6057 6058
                            Definition *ctx,MemberDef *md,
                            const char *input,bool indexWords,
6059
                            bool isExample, const char *exampleName,
6060
                            bool singleLine, bool linkFromIndex)
6061
{
6062 6063 6064
  //printf("validatingParseDoc(%s,%s)=[%s]\n",ctx?ctx->name().data():"<none>",
  //                                     md?md->name().data():"<none>",
  //                                     input);
6065 6066
  //printf("========== validating %s at line %d\n",fileName,startLine);
  //printf("---------------- input --------------------\n%s\n----------- end input -------------------\n",input);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
6067 6068 6069
  //g_token = new TokenInfo;

  // store parser state so we can re-enter this function if needed
6070
  bool fortranOpt = Config_getBool("OPTIMIZE_FOR_FORTRAN");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
6071
  docParserPushContext();
6072

6073 6074 6075 6076 6077 6078 6079 6080
  if (ctx &&
      (ctx->definitionType()==Definition::TypeClass || 
       ctx->definitionType()==Definition::TypeNamespace
      )
     ) 
  {
    g_context = ctx->name();
  }
6081 6082
  else if (ctx && ctx->definitionType()==Definition::TypePage)
  {
6083 6084 6085 6086 6087 6088 6089
    Definition *scope = ((PageDef*)ctx)->getPageScope();
    if (scope) g_context = scope->name();
  }
  else if (ctx && ctx->definitionType()==Definition::TypeGroup)
  {
    Definition *scope = ((GroupDef*)ctx)->getGroupScope();
    if (scope) g_context = scope->name();
6090
  }
6091 6092 6093 6094
  else
  {
    g_context = "";
  }
6095
  //printf("g_context=%s\n",g_context.data());
6096 6097 6098

  if (indexWords && md && Config_getBool("SEARCHENGINE"))
  {
6099
      
6100
    g_searchUrl=md->getOutputFileBase();
6101
    Doxygen::searchIndex->setCurrentDoc(
6102
        (fortranOpt?theTranslator->trSubprogram(TRUE,TRUE):theTranslator->trMember(TRUE,TRUE))+" "+md->qualifiedName(),
6103 6104
        g_searchUrl,
        md->anchor());
6105 6106 6107
  }
  else if (indexWords && ctx && Config_getBool("SEARCHENGINE"))
  {
6108
    g_searchUrl=ctx->getOutputFileBase();
6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140
    QCString name = ctx->qualifiedName();
    if (Config_getBool("OPTIMIZE_OUTPUT_JAVA"))
    {
      name = substitute(name,"::",".");
    }
    switch (ctx->definitionType())
    {
      case Definition::TypePage:
        {
          PageDef *pd = (PageDef *)ctx;
          if (!pd->title().isEmpty())
          {
            name = theTranslator->trPage(TRUE,TRUE)+" "+pd->title();
          }
          else
          {
            name = theTranslator->trPage(TRUE,TRUE)+" "+pd->name();
          }
        }
        break;
      case Definition::TypeClass:
        {
          ClassDef *cd = (ClassDef *)ctx;
          name.prepend(cd->compoundTypeString()+" ");
        }
        break;
      case Definition::TypeNamespace:
        {
          if (Config_getBool("OPTIMIZE_OUTPUT_JAVA"))
          {
            name = theTranslator->trPackage(name);
          }
6141 6142 6143 6144 6145
          else if(fortranOpt)
          {
            name.prepend(theTranslator->trModule(TRUE,TRUE)+" ");
          }
            else
6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173
          {
            name.prepend(theTranslator->trNamespace(TRUE,TRUE)+" ");
          }
        }
        break;
      case Definition::TypeGroup:
        {
          GroupDef *gd = (GroupDef *)ctx;
          if (gd->groupTitle())
          {
            name = theTranslator->trGroup(TRUE,TRUE)+" "+gd->groupTitle();
          }
          else
          {
            name.prepend(theTranslator->trGroup(TRUE,TRUE)+" ");
          }
        }
        break;
      default:
        break;
    }
    Doxygen::searchIndex->setCurrentDoc(name,g_searchUrl);
  }
  else
  {
    g_searchUrl="";
  }

6174
  g_fileName = fileName;
6175
  g_relPath = (!linkFromIndex && ctx) ? 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
6176 6177
               QString(relativePathToRoot(ctx->getOutputFileBase())) : 
               QString("");
6178
  //printf("ctx->name=%s relPath=%s\n",ctx->name().data(),g_relPath.data());
6179
  g_memberDef = md;
6180 6181
  g_nodeStack.clear();
  g_styleStack.clear();
6182
  g_initialStyleStack.clear();
6183 6184
  g_inSeeBlock = FALSE;
  g_insideHtmlLink = FALSE;
6185
  g_includeFileText = "";
6186 6187
  g_includeFileOffset = 0;
  g_includeFileLength = 0;
6188
  g_isExample = isExample;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
6189
  g_exampleName = exampleName;
6190
  g_hasParamCommand = FALSE;
6191
  g_hasReturnCommand = FALSE;
6192 6193
  g_paramsFound.setAutoDelete(FALSE);
  g_paramsFound.clear();
6194
  g_sectionDict = 0; //sections;
6195
  
6196
  //printf("Starting comment block at %s:%d\n",g_fileName.data(),startLine);
6197
  doctokenizerYYlineno=startLine;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
6198
  doctokenizerYYinit(input,g_fileName);
6199

Dimitri van Heesch's avatar
Dimitri van Heesch committed
6200

6201
  // build abstract syntax tree
6202
  DocRoot *root = new DocRoot(md!=0,singleLine);
6203 6204
  root->parse();

Dimitri van Heesch's avatar
Dimitri van Heesch committed
6205

6206 6207 6208 6209 6210
  if (Debug::isFlagSet(Debug::PrintTree))
  {
    // pretty print the result
    PrintDocVisitor *v = new PrintDocVisitor;
    root->accept(v);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
6211
    delete v;
6212 6213
  }

Dimitri van Heesch's avatar
Dimitri van Heesch committed
6214

6215 6216
  checkUndocumentedParams();
  detectNoDocumentedParams();
6217

6218 6219
  // TODO: These should be called at the end of the program.
  //doctokenizerYYcleanup();
6220 6221
  //Mappers::cmdMapper->freeInstance();
  //Mappers::htmlTagMapper->freeInstance();
6222

Dimitri van Heesch's avatar
Dimitri van Heesch committed
6223 6224 6225
  // restore original parser state
  docParserPopContext();

6226
  //printf(">>>>>> end validatingParseDoc(%s,%s)\n",ctx?ctx->name().data():"<none>",
6227 6228
  //                                     md?md->name().data():"<none>");
  
6229
  return root;
6230 6231
}

6232 6233
DocNode *validatingParseText(const char *input)
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
6234 6235 6236
  // store parser state so we can re-enter this function if needed
  docParserPushContext();

6237 6238
  //printf("------------ input ---------\n%s\n"
  //       "------------ end input -----\n",input);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
6239
  //g_token = new TokenInfo;
6240 6241
  g_context = "";
  g_fileName = "<parseText>";
6242
  g_relPath = "";
6243 6244 6245
  g_memberDef = 0;
  g_nodeStack.clear();
  g_styleStack.clear();
6246
  g_initialStyleStack.clear();
6247 6248 6249 6250 6251 6252
  g_inSeeBlock = FALSE;
  g_insideHtmlLink = FALSE;
  g_includeFileText = "";
  g_includeFileOffset = 0;
  g_includeFileLength = 0;
  g_isExample = FALSE;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
6253
  g_exampleName = "";
6254
  g_hasParamCommand = FALSE;
6255
  g_hasReturnCommand = FALSE;
6256 6257
  g_paramsFound.setAutoDelete(FALSE);
  g_paramsFound.clear();
6258
  g_searchUrl="";
6259 6260 6261

  DocText *txt = new DocText;

6262
  if (input)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
6263
  {
6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276
    doctokenizerYYlineno=1;
    doctokenizerYYinit(input,g_fileName);

    // build abstract syntax tree
    txt->parse();

    if (Debug::isFlagSet(Debug::PrintTree))
    {
      // pretty print the result
      PrintDocVisitor *v = new PrintDocVisitor;
      txt->accept(v);
      delete v;
    }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
6277 6278
  }

Dimitri van Heesch's avatar
Dimitri van Heesch committed
6279 6280
  // restore original parser state
  docParserPopContext();
6281 6282 6283
  return txt;
}

6284 6285 6286 6287
void docFindSections(const char *input,
                     Definition *d,
                     MemberGroup *mg,
                     const char *fileName)
6288
{
6289
  doctokenizerYYFindSections(input,d,mg,fileName);
6290 6291
}

6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302
void initDocParser()
{
  if (Config_getBool("SEARCHENGINE"))
  {
    Doxygen::searchIndex = new SearchIndex;
  }
  else
  {
    Doxygen::searchIndex = 0;
  }
}
6303 6304 6305 6306 6307 6308

void finializeDocParser()
{
  delete Doxygen::searchIndex;
}