diff options
Diffstat (limited to 'src/docbookvisitor.cpp')
-rw-r--r-- | src/docbookvisitor.cpp | 367 |
1 files changed, 176 insertions, 191 deletions
diff --git a/src/docbookvisitor.cpp b/src/docbookvisitor.cpp index 9de0a16..d444b7b 100644 --- a/src/docbookvisitor.cpp +++ b/src/docbookvisitor.cpp @@ -1,9 +1,6 @@ /****************************************************************************** * - * - * - * - * Copyright (C) 1997-2015 by Dimitri van Heesch. + * Copyright (C) 1997-2020 by Dimitri van Heesch. * * Permission to use, copy, modify, and distribute this software and its * documentation under the terms of the GNU General Public License is hereby @@ -16,6 +13,7 @@ * */ + #include <qfileinfo.h> #include "docbookvisitor.h" @@ -55,7 +53,7 @@ static QCString filterId(const char *s) static GrowBuf growBuf; growBuf.clear(); if (s==0) return ""; - const unsigned char *p=(const unsigned char *)s; + const char *p=s; char c; while ((c=*p++)) { @@ -69,6 +67,23 @@ static QCString filterId(const char *s) return growBuf.get(); } +static bool supportedHtmlAttribute(const QCString &name) +{ + return (name=="align" || + name=="bgcolor" || + name=="border" || + name=="cellpadding" || + name=="cellspacing" || + name=="class" || + name=="frame" || + name=="label" || + name=="style" || + name=="width" || + name=="tabstyle" || + name=="title"); +} + + void DocbookDocVisitor::visitCaption(const QList<DocNode> &children) { QListIterator<DocNode> cli(children); @@ -138,7 +153,7 @@ void DocbookDocVisitor::visitPostEnd(FTextStream &t, bool hasCaption, bool inlin } DocbookDocVisitor::DocbookDocVisitor(FTextStream &t,CodeOutputInterface &ci) - : DocVisitor(DocVisitor_Docbook), m_t(t), m_ci(ci), m_insidePre(FALSE), m_hide(FALSE) + : DocVisitor(DocVisitor_Docbook), m_t(t), m_ci(ci) { DB_VIS_C // m_t << "<section>" << endl; @@ -301,9 +316,11 @@ DB_VIS_C { case DocVerbatim::Code: // fall though m_t << "<literallayout><computeroutput>"; - Doxygen::parserManager->getCodeParser(m_langExt) - .parseCode(m_ci,s->context(),s->text(),langExt, - s->isExample(),s->exampleFile()); + getCodeParser(m_langExt).parseCode(m_ci,s->context(), + s->text(), + langExt, + s->isExample(), + s->exampleFile()); m_t << "</computeroutput></literallayout>"; break; case DocVerbatim::Verbatim: @@ -311,17 +328,17 @@ DB_VIS_C filter(s->text()); m_t << "</computeroutput></literallayout>"; break; - case DocVerbatim::HtmlOnly: + case DocVerbatim::HtmlOnly: break; - case DocVerbatim::RtfOnly: + case DocVerbatim::RtfOnly: break; - case DocVerbatim::ManOnly: + case DocVerbatim::ManOnly: break; - case DocVerbatim::LatexOnly: + case DocVerbatim::LatexOnly: break; - case DocVerbatim::XmlOnly: + case DocVerbatim::XmlOnly: break; - case DocVerbatim::DocbookOnly: + case DocVerbatim::DocbookOnly: m_t << s->text(); break; case DocVerbatim::Dot: @@ -339,12 +356,13 @@ DB_VIS_C QFile file(baseName+".dot"); if (!file.open(IO_WriteOnly)) { - err("Could not open file %s.msc for writing\n",baseName.data()); + err("Could not open file %s.dot for writing\n",baseName.data()); } file.writeBlock( stext, stext.length() ); file.close(); writeDotFile(baseName, s); m_t << "</para>" << endl; + if (Config_getBool(DOT_CLEANUP)) file.remove(); } break; case DocVerbatim::Msc: @@ -371,6 +389,7 @@ DB_VIS_C file.close(); writeMscFile(baseName,s); m_t << "</para>" << endl; + if (Config_getBool(DOT_CLEANUP)) file.remove(); } break; case DocVerbatim::PlantUML: @@ -381,7 +400,7 @@ DB_VIS_C int i; if ((i=shortName.findRev('/'))!=-1) { - shortName=shortName.right(shortName.length()-i-1); + shortName=shortName.right((int)shortName.length()-i-1); } m_t << "<para>" << endl; writePlantUMLFile(baseName,s); @@ -410,30 +429,34 @@ DB_VIS_C m_t << "<literallayout><computeroutput>"; QFileInfo cfi( inc->file() ); FileDef *fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() ); - Doxygen::parserManager->getCodeParser(inc->extension()) - .parseCode(m_ci,inc->context(), - inc->text(), - langExt, - inc->isExample(), - inc->exampleFile(), fd); + getCodeParser(inc->extension()).parseCode(m_ci,inc->context(), + inc->text(), + langExt, + inc->isExample(), + inc->exampleFile(), fd); delete fd; m_t << "</computeroutput></literallayout>"; } break; case DocInclude::Include: m_t << "<literallayout><computeroutput>"; - Doxygen::parserManager->getCodeParser(inc->extension()) - .parseCode(m_ci,inc->context(), - inc->text(), - langExt, - inc->isExample(), - inc->exampleFile()); + getCodeParser(inc->extension()).parseCode(m_ci,inc->context(), + inc->text(), + langExt, + inc->isExample(), + inc->exampleFile()); m_t << "</computeroutput></literallayout>"; break; case DocInclude::DontInclude: case DocInclude::DontIncWithLines: case DocInclude::HtmlInclude: case DocInclude::LatexInclude: + case DocInclude::RtfInclude: + case DocInclude::ManInclude: + case DocInclude::XmlInclude: + break; + case DocInclude::DocbookInclude: + m_t << inc->text(); break; case DocInclude::VerbInclude: m_t << "<literallayout>"; @@ -442,14 +465,13 @@ DB_VIS_C break; case DocInclude::Snippet: m_t << "<literallayout><computeroutput>"; - Doxygen::parserManager->getCodeParser(inc->extension()) - .parseCode(m_ci, - inc->context(), - extractBlock(inc->text(),inc->blockId()), - langExt, - inc->isExample(), - inc->exampleFile() - ); + getCodeParser(inc->extension()).parseCode(m_ci, + inc->context(), + extractBlock(inc->text(),inc->blockId()), + langExt, + inc->isExample(), + inc->exampleFile() + ); m_t << "</computeroutput></literallayout>"; break; case DocInclude::SnipWithLines: @@ -457,13 +479,12 @@ DB_VIS_C QFileInfo cfi( inc->file() ); FileDef *fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() ); m_t << "<literallayout><computeroutput>"; - Doxygen::parserManager->getCodeParser(inc->extension()) - .parseCode(m_ci, + getCodeParser(inc->extension()).parseCode(m_ci, inc->context(), extractBlock(inc->text(),inc->blockId()), langExt, inc->isExample(), - inc->exampleFile(), + inc->exampleFile(), fd, lineBlock(inc->text(),inc->blockId()), -1, // endLine @@ -475,8 +496,8 @@ DB_VIS_C m_t << "</computeroutput></literallayout>"; } break; - case DocInclude::SnippetDoc: - case DocInclude::IncludeDoc: + case DocInclude::SnippetDoc: + case DocInclude::IncludeDoc: err("Internal inconsistency: found switch SnippetDoc / IncludeDoc in file: %s" "Please create a bug report\n",__FILE__); break; @@ -510,17 +531,16 @@ DB_VIS_C fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() ); } - Doxygen::parserManager->getCodeParser(locLangExt) - .parseCode(m_ci,op->context(), - op->text(),langExt,op->isExample(), - op->exampleFile(), - fd, // fileDef - op->line(), // startLine - -1, // endLine - FALSE, // inline fragment - 0, // memberDef - op->showLineNo() // show line numbers - ); + getCodeParser(locLangExt).parseCode(m_ci,op->context(), + op->text(),langExt,op->isExample(), + op->exampleFile(), + fd, // fileDef + op->line(), // startLine + -1, // endLine + FALSE, // inline fragment + 0, // memberDef + op->showLineNo() // show line numbers + ); if (fd) delete fd; } pushEnabled(); @@ -657,152 +677,152 @@ DB_VIS_C switch(s->type()) { case DocSimpleSect::See: - if (m_insidePre) + if (m_insidePre) { m_t << "<formalpara><title>" << theTranslator->trSeeAlso() << "</title>" << endl; - } - else + } + else { m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trSeeAlso()) << "</title>" << endl; } break; case DocSimpleSect::Return: - if (m_insidePre) + if (m_insidePre) { m_t << "<formalpara><title>" << theTranslator->trReturns()<< "</title>" << endl; - } - else + } + else { m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trReturns()) << "</title>" << endl; } break; case DocSimpleSect::Author: - if (m_insidePre) + if (m_insidePre) { m_t << "<formalpara><title>" << theTranslator->trAuthor(TRUE, TRUE) << "</title>" << endl; - } - else + } + else { m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trAuthor(TRUE, TRUE)) << "</title>" << endl; } break; case DocSimpleSect::Authors: - if (m_insidePre) + if (m_insidePre) { m_t << "<formalpara><title>" << theTranslator->trAuthor(TRUE, FALSE) << "</title>" << endl; - } - else + } + else { m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trAuthor(TRUE, FALSE)) << "</title>" << endl; } break; case DocSimpleSect::Version: - if (m_insidePre) + if (m_insidePre) { m_t << "<formalpara><title>" << theTranslator->trVersion() << "</title>" << endl; - } - else + } + else { m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trVersion()) << "</title>" << endl; } break; case DocSimpleSect::Since: - if (m_insidePre) + if (m_insidePre) { m_t << "<formalpara><title>" << theTranslator->trSince() << "</title>" << endl; - } - else + } + else { m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trSince()) << "</title>" << endl; } break; case DocSimpleSect::Date: - if (m_insidePre) + if (m_insidePre) { m_t << "<formalpara><title>" << theTranslator->trDate() << "</title>" << endl; - } - else + } + else { m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trDate()) << "</title>" << endl; } break; case DocSimpleSect::Note: - if (m_insidePre) + if (m_insidePre) { m_t << "<note><title>" << theTranslator->trNote() << "</title>" << endl; - } - else + } + else { m_t << "<note><title>" << convertToDocBook(theTranslator->trNote()) << "</title>" << endl; } break; case DocSimpleSect::Warning: - if (m_insidePre) + if (m_insidePre) { m_t << "<warning><title>" << theTranslator->trWarning() << "</title>" << endl; - } - else + } + else { m_t << "<warning><title>" << convertToDocBook(theTranslator->trWarning()) << "</title>" << endl; } break; case DocSimpleSect::Pre: - if (m_insidePre) + if (m_insidePre) { m_t << "<formalpara><title>" << theTranslator->trPrecondition() << "</title>" << endl; - } - else + } + else { m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trPrecondition()) << "</title>" << endl; } break; case DocSimpleSect::Post: - if (m_insidePre) + if (m_insidePre) { m_t << "<formalpara><title>" << theTranslator->trPostcondition() << "</title>" << endl; - } - else + } + else { m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trPostcondition()) << "</title>" << endl; } break; case DocSimpleSect::Copyright: - if (m_insidePre) + if (m_insidePre) { m_t << "<formalpara><title>" << theTranslator->trCopyright() << "</title>" << endl; - } - else + } + else { m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trCopyright()) << "</title>" << endl; } break; case DocSimpleSect::Invar: - if (m_insidePre) + if (m_insidePre) { m_t << "<formalpara><title>" << theTranslator->trInvariant() << "</title>" << endl; - } - else + } + else { m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trInvariant()) << "</title>" << endl; } break; case DocSimpleSect::Remark: // <remark> is miising the <title> possibility - if (m_insidePre) + if (m_insidePre) { m_t << "<formalpara><title>" << theTranslator->trRemarks() << "</title>" << endl; - } - else + } + else { m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trRemarks()) << "</title>" << endl; } break; case DocSimpleSect::Attention: - if (m_insidePre) + if (m_insidePre) { m_t << "<caution><title>" << theTranslator->trAttention() << "</title>" << endl; - } - else + } + else { m_t << "<caution><title>" << convertToDocBook(theTranslator->trAttention()) << "</title>" << endl; } @@ -983,12 +1003,10 @@ DB_VIS_C m_t << "</listitem></varlistentry>\n"; } -static int colCnt = 0; -static bool bodySet = FALSE; // it is possible to have tables without a header void DocbookDocVisitor::visitPre(DocHtmlTable *t) { DB_VIS_C - bodySet = FALSE; + m_bodySet.push(false); if (m_hide) return; m_t << "<informaltable frame=\"all\">" << endl; m_t << " <tgroup cols=\"" << t->numColumns() << "\" align=\"left\" colsep=\"1\" rowsep=\"1\">" << endl; @@ -1003,8 +1021,8 @@ void DocbookDocVisitor::visitPost(DocHtmlTable *) { DB_VIS_C if (m_hide) return; - if (bodySet) m_t << " </tbody>" << endl; - bodySet = FALSE; + if (m_bodySet.top()) m_t << " </tbody>" << endl; + m_bodySet.pop(); m_t << " </tgroup>" << endl; m_t << "</informaltable>" << endl; } @@ -1012,13 +1030,18 @@ DB_VIS_C void DocbookDocVisitor::visitPre(DocHtmlRow *tr) { DB_VIS_C - colCnt = 0; + m_colCnt = 0; if (m_hide) return; - if (tr->isHeading()) m_t << "<thead>\n"; - else if (!bodySet) + if (tr->isHeading()) + { + if (m_bodySet.top()) m_t << "</tbody>\n"; + m_bodySet.top() = false; + m_t << "<thead>\n"; + } + else if (!m_bodySet.top()) { - bodySet = TRUE; + m_bodySet.top() = true; m_t << "<tbody>\n"; } @@ -1028,25 +1051,10 @@ DB_VIS_C HtmlAttrib *opt; for (li.toFirst();(opt=li.current());++li) { - if (opt->name=="class") + if (supportedHtmlAttribute(opt->name)) { - // just skip it - } - else if (opt->name=="style") - { - // just skip it - } - else if (opt->name=="height") - { - // just skip it - } - else if (opt->name=="filter") - { - // just skip it - } - else - { - m_t << " " << opt->name << "='" << opt->value << "'"; + // process supported attributes only + m_t << " " << opt->name << "='" << convertToDocBook(opt->value) << "'"; } } m_t << ">\n"; @@ -1059,15 +1067,15 @@ DB_VIS_C m_t << "</row>\n"; if (tr->isHeading()) { - bodySet = TRUE; m_t << "</thead><tbody>\n"; + m_bodySet.top() = true; } } void DocbookDocVisitor::visitPre(DocHtmlCell *c) { DB_VIS_C - colCnt++; + m_colCnt++; if (m_hide) return; m_t << "<entry"; @@ -1077,10 +1085,10 @@ DB_VIS_C { if (opt->name=="colspan") { - m_t << " namest='c" << colCnt << "'"; + m_t << " namest='c" << m_colCnt << "'"; int cols = opt->value.toInt(); - colCnt += (cols - 1); - m_t << " nameend='c" << colCnt << "'"; + m_colCnt += (cols - 1); + m_t << " nameend='c" << m_colCnt << "'"; } else if (opt->name=="rowspan") { @@ -1089,63 +1097,44 @@ DB_VIS_C } else if (opt->name=="class") { - if (opt->value == "markdownTableBodyRight") - { - m_t << " align='right'"; - } - else if (opt->value == "markdownTableBodyLeftt") - { - m_t << " align='left'"; - } - else if (opt->value == "markdownTableBodyCenter") - { - m_t << " align='center'"; - } - else if (opt->value == "markdownTableHeadRight") + if (opt->value.left(13)=="markdownTable") // handle markdown generated attributes { - m_t << " align='right'"; - } - else if (opt->value == "markdownTableHeadLeftt") - { - m_t << " align='left'"; + if (opt->value.right(5)=="Right") + { + m_t << " align='right'"; + } + else if (opt->value.right(4)=="Left") + { + m_t << " align='left'"; + } + else if (opt->value.right(6)=="Center") + { + m_t << " align='center'"; + } + // skip 'markdownTable*' value ending with "None" } - else if (opt->value == "markdownTableHeadCenter") + else { - m_t << " align='center'"; + m_t << " class='" << convertToDocBook(opt->value) << "'"; } } - else if (opt->name=="style") + else if (supportedHtmlAttribute(opt->name)) { - // just skip it - } - else if (opt->name=="width") - { - // just skip it - } - else if (opt->name=="height") - { - // just skip it - } - else if (opt->name=="nowrap" && opt->value.isEmpty()) - { - m_t << " " << opt->name << "='nowrap'"; - } - else - { - m_t << " " << opt->name << "='" << opt->value << "'"; + // process supported attributes only + m_t << " " << opt->name << "='" << convertToDocBook(opt->value) << "'"; } } m_t << ">"; } -void DocbookDocVisitor::visitPost(DocHtmlCell *c) +void DocbookDocVisitor::visitPost(DocHtmlCell *) { DB_VIS_C if (m_hide) return; m_t << "</entry>"; } -void DocbookDocVisitor::visitPre(DocHtmlCaption *c) +void DocbookDocVisitor::visitPre(DocHtmlCaption *) { DB_VIS_C if (m_hide) return; @@ -1212,7 +1201,7 @@ DB_VIS_C int i; if ((i=baseName.findRev('/'))!=-1 || (i=baseName.findRev('\\'))!=-1) { - baseName=baseName.right(baseName.length()-i-1); + baseName=baseName.right((int)baseName.length()-i-1); } visitPreStart(m_t, img->children(), img->hasCaption(), img->relPath() + baseName, img->width(), img->height(), img->isInlineImage()); } @@ -1235,12 +1224,12 @@ DB_VIS_C int i; if ((i=baseName.findRev('/'))!=-1 || (i=baseName.findRev('\\'))!=-1) { - baseName=baseName.right(baseName.length()-i-1); + baseName=baseName.right((int)baseName.length()-i-1); } QCString m_file; bool ambig; - FileDef *fd=findFileDef(Doxygen::imageNameDict, baseName, ambig); - if (fd) + FileDef *fd=findFileDef(Doxygen::imageNameLinkedMap, baseName, ambig); + if (fd) { m_file=fd->absFilePath(); } @@ -1257,8 +1246,8 @@ DB_VIS_C delete[] buffer; } } - } - else + } + else { popEnabled(); } @@ -1342,7 +1331,7 @@ DB_VIS_C if (!ref->file().isEmpty()) endLink(); } -void DocbookDocVisitor::visitPre(DocSecRefItem *ref) +void DocbookDocVisitor::visitPre(DocSecRefItem *) { DB_VIS_C if (m_hide) return; @@ -1425,11 +1414,9 @@ DB_VIS_C if (m_hide) return; m_t << " <row>" << endl; - DocParamSect::Type parentType = DocParamSect::Unknown; DocParamSect *sect = 0; if (pl->parent() && pl->parent()->kind()==DocNode::Kind_ParamSect) { - parentType = ((DocParamSect*)pl->parent())->type(); sect=(DocParamSect*)pl->parent(); } @@ -1632,16 +1619,14 @@ DB_VIS_C void DocbookDocVisitor::pushEnabled() { DB_VIS_C - m_enabled.push(new bool(m_hide)); + m_enabled.push(m_hide); } void DocbookDocVisitor::popEnabled() { DB_VIS_C - bool *v=m_enabled.pop(); - ASSERT(v!=0); - m_hide = *v; - delete v; + m_hide=m_enabled.top(); + m_enabled.pop(); } void DocbookDocVisitor::writeMscFile(const QCString &baseName, DocVerbatim *s) @@ -1651,7 +1636,7 @@ DB_VIS_C int i; if ((i=shortName.findRev('/'))!=-1) { - shortName=shortName.right(shortName.length()-i-1); + shortName=shortName.right((int)shortName.length()-i-1); } QCString outDir = Config_getString(DOCBOOK_OUTPUT); writeMscGraphFromFile(baseName+".msc",outDir,shortName,MSC_BITMAP); @@ -1667,7 +1652,7 @@ DB_VIS_C int i; if ((i=shortName.findRev('/'))!=-1) { - shortName=shortName.right(shortName.length()-i-1); + shortName=shortName.right((int)shortName.length()-i-1); } QCString outDir = Config_getString(DOCBOOK_OUTPUT); PlantumlManager::instance()->generatePlantUMLOutput(baseName,outDir,PlantumlManager::PUML_BITMAP); @@ -1688,7 +1673,7 @@ DB_VIS_C int i; if ((i=baseName.findRev('/'))!=-1) { - baseName=baseName.right(baseName.length()-i-1); + baseName=baseName.right((int)baseName.length()-i-1); } if ((i=baseName.find('.'))!=-1) { @@ -1716,7 +1701,7 @@ DB_VIS_C int i; if ((i=shortName.findRev('/'))!=-1) { - shortName=shortName.right(shortName.length()-i-1); + shortName=shortName.right((int)shortName.length()-i-1); } QCString outDir = Config_getString(DOCBOOK_OUTPUT); writeDiaGraphFromFile(baseName+".dia",outDir,shortName,DIA_BITMAP); @@ -1737,7 +1722,7 @@ DB_VIS_C int i; if ((i=baseName.findRev('/'))!=-1) { - baseName=baseName.right(baseName.length()-i-1); + baseName=baseName.right((int)baseName.length()-i-1); } if ((i=baseName.find('.'))!=-1) { @@ -1765,7 +1750,7 @@ DB_VIS_C int i; if ((i=shortName.findRev('/'))!=-1) { - shortName=shortName.right(shortName.length()-i-1); + shortName=shortName.right((int)shortName.length()-i-1); } QCString outDir = Config_getString(DOCBOOK_OUTPUT); writeDotGraphFromFile(baseName+".dot",outDir,shortName,GOF_BITMAP); @@ -1786,7 +1771,7 @@ DB_VIS_C int i; if ((i=baseName.findRev('/'))!=-1) { - baseName=baseName.right(baseName.length()-i-1); + baseName=baseName.right((int)baseName.length()-i-1); } if ((i=baseName.find('.'))!=-1) { |