diff options
Diffstat (limited to 'src/docbookvisitor.cpp')
-rw-r--r-- | src/docbookvisitor.cpp | 476 |
1 files changed, 242 insertions, 234 deletions
diff --git a/src/docbookvisitor.cpp b/src/docbookvisitor.cpp index d444b7b..25fc21e 100644 --- a/src/docbookvisitor.cpp +++ b/src/docbookvisitor.cpp @@ -13,8 +13,7 @@ * */ - -#include <qfileinfo.h> +#include <fstream> #include "docbookvisitor.h" #include "docparser.h" @@ -35,6 +34,7 @@ #include "emoji.h" #include "plantuml.h" #include "growbuf.h" +#include "fileinfo.h" #if 0 #define DB_VIS_C DB_VIS_C1(m_t) @@ -48,12 +48,12 @@ #define DB_VIS_C2a(x,y) #endif -static QCString filterId(const char *s) +static QCString filterId(const QCString &s) { + if (s.isEmpty()) return s; static GrowBuf growBuf; growBuf.clear(); - if (s==0) return ""; - const char *p=s; + const char *p=s.data(); char c; while ((c=*p++)) { @@ -84,15 +84,13 @@ static bool supportedHtmlAttribute(const QCString &name) } -void DocbookDocVisitor::visitCaption(const QList<DocNode> &children) +void DocbookDocVisitor::visitCaption(const DocNodeList &children) { - QListIterator<DocNode> cli(children); - DocNode *n; - for (cli.toFirst();(n=cli.current());++cli) n->accept(this); + for (const auto &n : children) n->accept(this); } -void DocbookDocVisitor::visitPreStart(FTextStream &t, - const QList<DocNode> &children, +void DocbookDocVisitor::visitPreStart(TextStream &t, + const DocNodeList &children, bool hasCaption, const QCString &name, const QCString &width, @@ -101,17 +99,17 @@ void DocbookDocVisitor::visitPreStart(FTextStream &t, { if (hasCaption && !inlineImage) { - t << " <figure>" << endl; - t << " <title>" << endl; + t << " <figure>\n"; + t << " <title>\n"; visitCaption(children); - t << " </title>" << endl; + t << " </title>\n"; } else { - t << " <informalfigure>" << endl; + t << " <informalfigure>\n"; } - t << " <mediaobject>" << endl; - t << " <imageobject>" << endl; + t << " <mediaobject>\n"; + t << " <imageobject>\n"; t << " <imagedata"; if (!width.isEmpty()) { @@ -126,42 +124,42 @@ void DocbookDocVisitor::visitPreStart(FTextStream &t, t << " depth=\"" << convertToDocBook(height) << "\""; } t << " align=\"center\" valign=\"middle\" scalefit=\"0\" fileref=\"" << name << "\">"; - t << "</imagedata>" << endl; - t << " </imageobject>" << endl; + t << "</imagedata>\n"; + t << " </imageobject>\n"; if (hasCaption && !inlineImage) { - t << " <!--" << endl; // Needed for general formatting with title for other formats + t << " <!--\n"; // Needed for general formatting with title for other formats } } -void DocbookDocVisitor::visitPostEnd(FTextStream &t, bool hasCaption, bool inlineImage) +void DocbookDocVisitor::visitPostEnd(TextStream &t, bool hasCaption, bool inlineImage) { - t << endl; + t << "\n"; if (hasCaption && !inlineImage) { - t << " -->" << endl; // Needed for general formatting with title for other formats + t << " -->\n"; // Needed for general formatting with title for other formats } - t << " </mediaobject>" << endl; + t << " </mediaobject>\n"; if (hasCaption && !inlineImage) { - t << " </figure>" << endl; + t << " </figure>\n"; } else { - t << " </informalfigure>" << endl; + t << " </informalfigure>\n"; } } -DocbookDocVisitor::DocbookDocVisitor(FTextStream &t,CodeOutputInterface &ci) - : DocVisitor(DocVisitor_Docbook), m_t(t), m_ci(ci) +DocbookDocVisitor::DocbookDocVisitor(TextStream &t,CodeOutputInterface &ci,const QCString &langExt) + : DocVisitor(DocVisitor_Docbook), m_t(t), m_ci(ci),m_langExt(langExt) { DB_VIS_C - // m_t << "<section>" << endl; + // m_t << "<section>\n"; } DocbookDocVisitor::~DocbookDocVisitor() { DB_VIS_C - // m_t << "</section>" << endl; + // m_t << "</section>\n"; } //-------------------------------------- @@ -244,9 +242,9 @@ void DocbookDocVisitor::visit(DocLineBreak *) { DB_VIS_C if (m_hide) return; - m_t << endl << "<literallayout> 
</literallayout>" << endl; + m_t << "\n<literallayout> 
</literallayout>\n"; // gives nicer results but gives problems as it is not allowed in <pare> and also problems with dblatex - // m_t << endl << "<sbr/>" << endl; + // m_t << "\n" << "<sbr/>\n"; } void DocbookDocVisitor::visit(DocHorRuler *) @@ -311,10 +309,15 @@ void DocbookDocVisitor::visit(DocVerbatim *s) { DB_VIS_C if (m_hide) return; - SrcLangExt langExt = getLanguageFromFileName(m_langExt); + QCString lang = m_langExt; + if (!s->language().isEmpty()) // explicit language setting + { + lang = s->language(); + } + SrcLangExt langExt = getLanguageFromCodeLang(lang); switch(s->type()) { - case DocVerbatim::Code: // fall though + case DocVerbatim::Code: m_t << "<literallayout><computeroutput>"; getCodeParser(m_langExt).parseCode(m_ci,s->context(), s->text(), @@ -347,22 +350,23 @@ DB_VIS_C QCString baseName(4096); QCString name; QCString stext = s->text(); - m_t << "<para>" << endl; + m_t << "<para>\n"; name.sprintf("%s%d", "dot_inline_dotgraph_", dotindex); baseName.sprintf("%s%d", - (Config_getString(DOCBOOK_OUTPUT)+"/inline_dotgraph_").data(), + qPrint(Config_getString(DOCBOOK_OUTPUT)+"/inline_dotgraph_"), dotindex++ ); - QFile file(baseName+".dot"); - if (!file.open(IO_WriteOnly)) + std::string fileName = baseName.str()+".dot"; + std::ofstream file(fileName,std::ofstream::out | std::ofstream::binary); + if (!file.is_open()) { - err("Could not open file %s.dot for writing\n",baseName.data()); + err("Could not open file %s for writing\n",fileName.c_str()); } - file.writeBlock( stext, stext.length() ); + file.write( stext.data(), stext.length() ); file.close(); writeDotFile(baseName, s); - m_t << "</para>" << endl; - if (Config_getBool(DOT_CLEANUP)) file.remove(); + m_t << "</para>\n"; + if (Config_getBool(DOT_CLEANUP)) Dir().remove(fileName); } break; case DocVerbatim::Msc: @@ -371,40 +375,41 @@ DB_VIS_C QCString baseName(4096); QCString name; QCString stext = s->text(); - m_t << "<para>" << endl; + m_t << "<para>\n"; name.sprintf("%s%d", "msc_inline_mscgraph_", mscindex); baseName.sprintf("%s%d", (Config_getString(DOCBOOK_OUTPUT)+"/inline_mscgraph_").data(), mscindex++ ); - QFile file(baseName+".msc"); - if (!file.open(IO_WriteOnly)) + std::string fileName = baseName.str()+".msc"; + std::ofstream file(fileName,std::ofstream::out | std::ofstream::binary); + if (!file.is_open()) { - err("Could not open file %s.msc for writing\n",baseName.data()); + err("Could not open file %s for writing\n",fileName.c_str()); } QCString text = "msc {"; text+=stext; text+="}"; - file.writeBlock( text, text.length() ); + file.write( text.data(), text.length() ); file.close(); writeMscFile(baseName,s); - m_t << "</para>" << endl; - if (Config_getBool(DOT_CLEANUP)) file.remove(); + m_t << "</para>\n"; + if (Config_getBool(DOT_CLEANUP)) Dir().remove(fileName); } break; case DocVerbatim::PlantUML: { static QCString docbookOutput = Config_getString(DOCBOOK_OUTPUT); - QCString baseName = PlantumlManager::instance()->writePlantUMLSource(docbookOutput,s->exampleFile(),s->text(),PlantumlManager::PUML_BITMAP); + QCString baseName = PlantumlManager::instance().writePlantUMLSource(docbookOutput,s->exampleFile(),s->text(),PlantumlManager::PUML_BITMAP,s->engine(),s->srcFile(),s->srcLine()); QCString shortName = baseName; int i; if ((i=shortName.findRev('/'))!=-1) { shortName=shortName.right((int)shortName.length()-i-1); } - m_t << "<para>" << endl; + m_t << "<para>\n"; writePlantUMLFile(baseName,s); - m_t << "</para>" << endl; + m_t << "</para>\n"; } break; } @@ -427,8 +432,8 @@ DB_VIS_C case DocInclude::IncWithLines: { m_t << "<literallayout><computeroutput>"; - QFileInfo cfi( inc->file() ); - FileDef *fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() ); + FileInfo cfi( inc->file().str() ); + FileDef *fd = createFileDef( cfi.dirPath(), cfi.fileName() ); getCodeParser(inc->extension()).parseCode(m_ci,inc->context(), inc->text(), langExt, @@ -476,8 +481,8 @@ DB_VIS_C break; case DocInclude::SnipWithLines: { - QFileInfo cfi( inc->file() ); - FileDef *fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() ); + FileInfo cfi( inc->file().str() ); + FileDef *fd = createFileDef( cfi.dirPath(), cfi.fileName() ); m_t << "<literallayout><computeroutput>"; getCodeParser(inc->extension()).parseCode(m_ci, inc->context(), @@ -511,9 +516,9 @@ DB_VIS_C { if (!m_hide) { - m_t << "<programlisting>"; + m_t << "<programlisting linenumbering=\"unnumbered\">"; } - pushEnabled(); + pushHidden(m_hide); m_hide = TRUE; } QCString locLangExt = getFileNameExtension(op->includeFileName()); @@ -521,14 +526,14 @@ DB_VIS_C SrcLangExt langExt = getLanguageFromFileName(locLangExt); if (op->type()!=DocIncOperator::Skip) { - popEnabled(); + m_hide = popHidden(); if (!m_hide) { FileDef *fd = 0; if (!op->includeFileName().isEmpty()) { - QFileInfo cfi( op->includeFileName() ); - fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() ); + FileInfo cfi( op->includeFileName().str() ); + fd = createFileDef( cfi.dirPath(), cfi.fileName() ); } getCodeParser(locLangExt).parseCode(m_ci,op->context(), @@ -543,17 +548,17 @@ DB_VIS_C ); if (fd) delete fd; } - pushEnabled(); + pushHidden(m_hide); m_hide=TRUE; } if (op->isLast()) { - popEnabled(); + m_hide = popHidden(); if (!m_hide) m_t << "</programlisting>"; } else { - if (!m_hide) m_t << endl; + if (!m_hide) m_t << "\n"; } } @@ -562,14 +567,14 @@ void DocbookDocVisitor::visit(DocFormula *f) DB_VIS_C if (m_hide) return; - if (f->isInline()) m_t << "<inlinemediaobject>" << endl; - else m_t << " <mediaobject>" << endl; - m_t << " <imageobject>" << endl; + if (f->isInline()) m_t << "<inlinemediaobject>\n"; + else m_t << " <mediaobject>\n"; + m_t << " <imageobject>\n"; m_t << " <imagedata "; - m_t << "align=\"center\" valign=\"middle\" scalefit=\"0\" fileref=\"" << f->relPath() << f->name() << ".png\"/>" << endl; - m_t << " </imageobject>" << endl; - if (f->isInline()) m_t << "</inlinemediaobject>" << endl; - else m_t << " </mediaobject>" << endl; + m_t << "align=\"center\" valign=\"middle\" scalefit=\"0\" fileref=\"" << f->relPath() << f->name() << ".png\"/>\n"; + m_t << " </imageobject>\n"; + if (f->isInline()) m_t << "</inlinemediaobject>\n"; + else m_t << " </mediaobject>\n"; } void DocbookDocVisitor::visit(DocIndexEntry *ie) @@ -578,7 +583,7 @@ DB_VIS_C if (m_hide) return; m_t << "<indexterm><primary>"; filter(ie->entry()); - m_t << "</primary></indexterm>" << endl; + m_t << "</primary></indexterm>\n"; } void DocbookDocVisitor::visit(DocSimpleSectSep *) @@ -646,7 +651,7 @@ void DocbookDocVisitor::visitPre(DocPara *) { DB_VIS_C if (m_hide) return; - m_t << endl; + m_t << "\n"; m_t << "<para>"; } @@ -655,7 +660,7 @@ void DocbookDocVisitor::visitPost(DocPara *) DB_VIS_C if (m_hide) return; m_t << "</para>"; - m_t << endl; + m_t << "\n"; } void DocbookDocVisitor::visitPre(DocRoot *) @@ -679,161 +684,161 @@ DB_VIS_C case DocSimpleSect::See: if (m_insidePre) { - m_t << "<formalpara><title>" << theTranslator->trSeeAlso() << "</title>" << endl; + m_t << "<formalpara><title>" << theTranslator->trSeeAlso() << "</title>\n"; } else { - m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trSeeAlso()) << "</title>" << endl; + m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trSeeAlso()) << "</title>\n"; } break; case DocSimpleSect::Return: if (m_insidePre) { - m_t << "<formalpara><title>" << theTranslator->trReturns()<< "</title>" << endl; + m_t << "<formalpara><title>" << theTranslator->trReturns()<< "</title>\n"; } else { - m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trReturns()) << "</title>" << endl; + m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trReturns()) << "</title>\n"; } break; case DocSimpleSect::Author: if (m_insidePre) { - m_t << "<formalpara><title>" << theTranslator->trAuthor(TRUE, TRUE) << "</title>" << endl; + m_t << "<formalpara><title>" << theTranslator->trAuthor(TRUE, TRUE) << "</title>\n"; } else { - m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trAuthor(TRUE, TRUE)) << "</title>" << endl; + m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trAuthor(TRUE, TRUE)) << "</title>\n"; } break; case DocSimpleSect::Authors: if (m_insidePre) { - m_t << "<formalpara><title>" << theTranslator->trAuthor(TRUE, FALSE) << "</title>" << endl; + m_t << "<formalpara><title>" << theTranslator->trAuthor(TRUE, FALSE) << "</title>\n"; } else { - m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trAuthor(TRUE, FALSE)) << "</title>" << endl; + m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trAuthor(TRUE, FALSE)) << "</title>\n"; } break; case DocSimpleSect::Version: if (m_insidePre) { - m_t << "<formalpara><title>" << theTranslator->trVersion() << "</title>" << endl; + m_t << "<formalpara><title>" << theTranslator->trVersion() << "</title>\n"; } else { - m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trVersion()) << "</title>" << endl; + m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trVersion()) << "</title>\n"; } break; case DocSimpleSect::Since: if (m_insidePre) { - m_t << "<formalpara><title>" << theTranslator->trSince() << "</title>" << endl; + m_t << "<formalpara><title>" << theTranslator->trSince() << "</title>\n"; } else { - m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trSince()) << "</title>" << endl; + m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trSince()) << "</title>\n"; } break; case DocSimpleSect::Date: if (m_insidePre) { - m_t << "<formalpara><title>" << theTranslator->trDate() << "</title>" << endl; + m_t << "<formalpara><title>" << theTranslator->trDate() << "</title>\n"; } else { - m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trDate()) << "</title>" << endl; + m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trDate()) << "</title>\n"; } break; case DocSimpleSect::Note: if (m_insidePre) { - m_t << "<note><title>" << theTranslator->trNote() << "</title>" << endl; + m_t << "<note><title>" << theTranslator->trNote() << "</title>\n"; } else { - m_t << "<note><title>" << convertToDocBook(theTranslator->trNote()) << "</title>" << endl; + m_t << "<note><title>" << convertToDocBook(theTranslator->trNote()) << "</title>\n"; } break; case DocSimpleSect::Warning: if (m_insidePre) { - m_t << "<warning><title>" << theTranslator->trWarning() << "</title>" << endl; + m_t << "<warning><title>" << theTranslator->trWarning() << "</title>\n"; } else { - m_t << "<warning><title>" << convertToDocBook(theTranslator->trWarning()) << "</title>" << endl; + m_t << "<warning><title>" << convertToDocBook(theTranslator->trWarning()) << "</title>\n"; } break; case DocSimpleSect::Pre: if (m_insidePre) { - m_t << "<formalpara><title>" << theTranslator->trPrecondition() << "</title>" << endl; + m_t << "<formalpara><title>" << theTranslator->trPrecondition() << "</title>\n"; } else { - m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trPrecondition()) << "</title>" << endl; + m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trPrecondition()) << "</title>\n"; } break; case DocSimpleSect::Post: if (m_insidePre) { - m_t << "<formalpara><title>" << theTranslator->trPostcondition() << "</title>" << endl; + m_t << "<formalpara><title>" << theTranslator->trPostcondition() << "</title>\n"; } else { - m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trPostcondition()) << "</title>" << endl; + m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trPostcondition()) << "</title>\n"; } break; case DocSimpleSect::Copyright: if (m_insidePre) { - m_t << "<formalpara><title>" << theTranslator->trCopyright() << "</title>" << endl; + m_t << "<formalpara><title>" << theTranslator->trCopyright() << "</title>\n"; } else { - m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trCopyright()) << "</title>" << endl; + m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trCopyright()) << "</title>\n"; } break; case DocSimpleSect::Invar: if (m_insidePre) { - m_t << "<formalpara><title>" << theTranslator->trInvariant() << "</title>" << endl; + m_t << "<formalpara><title>" << theTranslator->trInvariant() << "</title>\n"; } else { - m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trInvariant()) << "</title>" << endl; + m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trInvariant()) << "</title>\n"; } break; case DocSimpleSect::Remark: // <remark> is miising the <title> possibility if (m_insidePre) { - m_t << "<formalpara><title>" << theTranslator->trRemarks() << "</title>" << endl; + m_t << "<formalpara><title>" << theTranslator->trRemarks() << "</title>\n"; } else { - m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trRemarks()) << "</title>" << endl; + m_t << "<formalpara><title>" << convertToDocBook(theTranslator->trRemarks()) << "</title>\n"; } break; case DocSimpleSect::Attention: if (m_insidePre) { - m_t << "<caution><title>" << theTranslator->trAttention() << "</title>" << endl; + m_t << "<caution><title>" << theTranslator->trAttention() << "</title>\n"; } else { - m_t << "<caution><title>" << convertToDocBook(theTranslator->trAttention()) << "</title>" << endl; + m_t << "<caution><title>" << convertToDocBook(theTranslator->trAttention()) << "</title>\n"; } break; case DocSimpleSect::User: case DocSimpleSect::Rcs: case DocSimpleSect::Unknown: if (s->hasTitle()) - m_t << "<formalpara>" << endl; + m_t << "<formalpara>\n"; else - m_t << "<para>" << endl; + m_t << "<para>\n"; break; } } @@ -848,21 +853,21 @@ DB_VIS_C case DocSimpleSect::Rcs: case DocSimpleSect::Unknown: if (s->hasTitle()) - m_t << "</formalpara>" << endl; + m_t << "</formalpara>\n"; else - m_t << "</para>" << endl; + m_t << "</para>\n"; break; case DocSimpleSect::Note: - m_t << "</note>" << endl; + m_t << "</note>\n"; break; case DocSimpleSect::Attention: - m_t << "</caution>" << endl; + m_t << "</caution>\n"; break; case DocSimpleSect::Warning: - m_t << "</warning>" << endl; + m_t << "</warning>\n"; break; default: - m_t << "</formalpara>" << endl; + m_t << "</formalpara>\n"; break; } } @@ -915,10 +920,10 @@ DB_VIS_C if (m_hide) return; m_t << "<section xml:id=\"_" << stripPath(s->file()); if (!s->anchor().isEmpty()) m_t << "_1" << s->anchor(); - m_t << "\">" << endl; + m_t << "\">\n"; m_t << "<title>"; filter(s->title()); - m_t << "</title>" << endl; + m_t << "</title>\n"; } void DocbookDocVisitor::visitPost(DocSection *) @@ -932,7 +937,30 @@ void DocbookDocVisitor::visitPre(DocHtmlList *s) DB_VIS_C if (m_hide) return; if (s->type()==DocHtmlList::Ordered) - m_t << "<orderedlist>\n"; + { + m_t << "<orderedlist"; + for (const auto &opt : s->attribs()) + { + if (opt.name=="type") + { + if (opt.value=="1") + m_t << " numeration=\"arabic\""; + else if (opt.value=="a") + m_t << " numeration=\"loweralpha\""; + else if (opt.value=="A") + m_t << " numeration=\"upperalpha\""; + else if (opt.value=="i") + m_t << " numeration=\"lowerroman\""; + else if (opt.value=="I") + m_t << " numeration=\"upperroman\""; + } + else if (opt.name=="start") + { + m_t << " startingnumber=\"" << opt.value << "\""; + } + } + m_t << ">\n"; + } else m_t << "<itemizedlist>\n"; } @@ -1008,8 +1036,8 @@ void DocbookDocVisitor::visitPre(DocHtmlTable *t) DB_VIS_C 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; + m_t << "<informaltable frame=\"all\">\n"; + m_t << " <tgroup cols=\"" << (unsigned int)t->numColumns() << "\" align=\"left\" colsep=\"1\" rowsep=\"1\">\n"; for (uint i = 0; i <t->numColumns(); i++) { // do something with colwidth based of cell width specification (be aware of possible colspan in the header)? @@ -1021,10 +1049,10 @@ void DocbookDocVisitor::visitPost(DocHtmlTable *) { DB_VIS_C if (m_hide) return; - if (m_bodySet.top()) m_t << " </tbody>" << endl; + if (m_bodySet.top()) m_t << " </tbody>\n"; m_bodySet.pop(); - m_t << " </tgroup>" << endl; - m_t << "</informaltable>" << endl; + m_t << " </tgroup>\n"; + m_t << "</informaltable>\n"; } void DocbookDocVisitor::visitPre(DocHtmlRow *tr) @@ -1047,14 +1075,12 @@ DB_VIS_C m_t << " <row "; - HtmlAttribListIterator li(tr->attribs()); - HtmlAttrib *opt; - for (li.toFirst();(opt=li.current());++li) + for (const auto &opt : tr->attribs()) { - if (supportedHtmlAttribute(opt->name)) + if (supportedHtmlAttribute(opt.name)) { // process supported attributes only - m_t << " " << opt->name << "='" << convertToDocBook(opt->value) << "'"; + m_t << " " << opt.name << "='" << convertToDocBook(opt.value) << "'"; } } m_t << ">\n"; @@ -1079,35 +1105,33 @@ DB_VIS_C if (m_hide) return; m_t << "<entry"; - HtmlAttribListIterator li(c->attribs()); - HtmlAttrib *opt; - for (li.toFirst();(opt=li.current());++li) + for (const auto &opt : c->attribs()) { - if (opt->name=="colspan") + if (opt.name=="colspan") { m_t << " namest='c" << m_colCnt << "'"; - int cols = opt->value.toInt(); + int cols = opt.value.toInt(); m_colCnt += (cols - 1); m_t << " nameend='c" << m_colCnt << "'"; } - else if (opt->name=="rowspan") + else if (opt.name=="rowspan") { - int extraRows = opt->value.toInt() - 1; + int extraRows = opt.value.toInt() - 1; m_t << " morerows='" << extraRows << "'"; } - else if (opt->name=="class") + else if (opt.name=="class") { - if (opt->value.left(13)=="markdownTable") // handle markdown generated attributes + if (opt.value.left(13)=="markdownTable") // handle markdown generated attributes { - if (opt->value.right(5)=="Right") + if (opt.value.right(5)=="Right") { m_t << " align='right'"; } - else if (opt->value.right(4)=="Left") + else if (opt.value.right(4)=="Left") { m_t << " align='left'"; } - else if (opt->value.right(6)=="Center") + else if (opt.value.right(6)=="Center") { m_t << " align='center'"; } @@ -1115,13 +1139,13 @@ DB_VIS_C } else { - m_t << " class='" << convertToDocBook(opt->value) << "'"; + m_t << " class='" << convertToDocBook(opt.value) << "'"; } } - else if (supportedHtmlAttribute(opt->name)) + else if (supportedHtmlAttribute(opt.name)) { // process supported attributes only - m_t << " " << opt->name << "='" << convertToDocBook(opt->value) << "'"; + m_t << " " << opt.name << "='" << convertToDocBook(opt.value) << "'"; } } m_t << ">"; @@ -1166,7 +1190,14 @@ void DocbookDocVisitor::visitPre(DocHRef *href) { DB_VIS_C if (m_hide) return; - m_t << "<link xlink:href=\"" << convertToDocBook(href->url()) << "\">"; + if (href->url().at(0) != '#') + { + m_t << "<link xlink:href=\"" << convertToDocBook(href->url()) << "\">"; + } + else + { + startLink(href->file(),filterId(href->url().mid(1))); + } } void DocbookDocVisitor::visitPost(DocHRef *) @@ -1196,7 +1227,7 @@ DB_VIS_C if (img->type()==DocImage::DocBook) { if (m_hide) return; - m_t << endl; + m_t << "\n"; QCString baseName=img->name(); int i; if ((i=baseName.findRev('/'))!=-1 || (i=baseName.findRev('\\'))!=-1) @@ -1207,7 +1238,7 @@ DB_VIS_C } else { - pushEnabled(); + pushHidden(m_hide); m_hide=TRUE; } } @@ -1233,23 +1264,11 @@ DB_VIS_C { m_file=fd->absFilePath(); } - QFile inImage(m_file); - QFile outImage(Config_getString(DOCBOOK_OUTPUT)+"/"+baseName.data()); - if (inImage.open(IO_ReadOnly)) - { - if (outImage.open(IO_WriteOnly)) - { - char *buffer = new char[inImage.size()]; - inImage.readBlock(buffer,inImage.size()); - outImage.writeBlock(buffer,inImage.size()); - outImage.flush(); - delete[] buffer; - } - } + copyFile(m_file,Config_getString(DOCBOOK_OUTPUT)+"/"+baseName); } else { - popEnabled(); + m_hide = popHidden(); } } @@ -1257,7 +1276,7 @@ void DocbookDocVisitor::visitPre(DocDotFile *df) { DB_VIS_C if (m_hide) return; - startDotFile(df->file(),df->width(),df->height(),df->hasCaption(),df->children()); + startDotFile(df->file(),df->width(),df->height(),df->hasCaption(),df->children(),df->srcFile(),df->srcLine()); } void DocbookDocVisitor::visitPost(DocDotFile *df) @@ -1271,7 +1290,7 @@ void DocbookDocVisitor::visitPre(DocMscFile *df) { DB_VIS_C if (m_hide) return; - startMscFile(df->file(),df->width(),df->height(),df->hasCaption(),df->children()); + startMscFile(df->file(),df->width(),df->height(),df->hasCaption(),df->children(),df->srcFile(),df->srcLine()); } void DocbookDocVisitor::visitPost(DocMscFile *df) @@ -1284,7 +1303,7 @@ void DocbookDocVisitor::visitPre(DocDiaFile *df) { DB_VIS_C if (m_hide) return; - startDiaFile(df->file(),df->width(),df->height(),df->hasCaption(),df->children()); + startDiaFile(df->file(),df->width(),df->height(),df->hasCaption(),df->children(),df->srcFile(),df->srcLine()); } void DocbookDocVisitor::visitPost(DocDiaFile *df) @@ -1314,7 +1333,7 @@ DB_VIS_C if (m_hide) return; if (ref->isSubPage()) { - startLink(0,ref->anchor()); + startLink(QCString(),ref->anchor()); } else { @@ -1343,30 +1362,30 @@ void DocbookDocVisitor::visitPost(DocSecRefItem *) { DB_VIS_C if (m_hide) return; - m_t << "</tocentry>" << endl; + m_t << "</tocentry>\n"; } void DocbookDocVisitor::visitPre(DocSecRefList *) { DB_VIS_C if (m_hide) return; - m_t << "<toc>" << endl; + m_t << "<toc>\n"; } void DocbookDocVisitor::visitPost(DocSecRefList *) { DB_VIS_C if (m_hide) return; - m_t << "</toc>" << endl; + m_t << "</toc>\n"; } void DocbookDocVisitor::visitPre(DocParamSect *s) { DB_VIS_C if (m_hide) return; - m_t << endl; - m_t << " <formalpara>" << endl; - m_t << " <title>" << endl; + m_t << "\n"; + m_t << " <formalpara>\n"; + m_t << " <title>\n"; switch(s->type()) { case DocParamSect::Param: m_t << theTranslator->trParameters(); break; @@ -1376,9 +1395,9 @@ DB_VIS_C default: ASSERT(0); } - m_t << " </title>" << endl; - m_t << " <para>" << endl; - m_t << " <table frame=\"all\">" << endl; + m_t << "</title>\n"; + m_t << " <para>\n"; + m_t << " <table frame=\"all\">\n"; int ncols = 2; if (s->type() == DocParamSect::Param) { @@ -1387,24 +1406,24 @@ DB_VIS_C if (hasInOutSpecs && hasTypeSpecs) ncols += 2; else if (hasInOutSpecs || hasTypeSpecs) ncols += 1; } - m_t << " <tgroup cols=\"" << ncols << "\" align=\"left\" colsep=\"1\" rowsep=\"1\">" << endl; + m_t << " <tgroup cols=\"" << ncols << "\" align=\"left\" colsep=\"1\" rowsep=\"1\">\n"; for (int i = 1; i <= ncols; i++) { - if (i == ncols) m_t << " <colspec colwidth=\"4*\"/>" << endl; - else m_t << " <colspec colwidth=\"1*\"/>" << endl; + if (i == ncols) m_t << " <colspec colwidth=\"4*\"/>\n"; + else m_t << " <colspec colwidth=\"1*\"/>\n"; } - m_t << " <tbody>" << endl; + m_t << " <tbody>\n"; } void DocbookDocVisitor::visitPost(DocParamSect *) { DB_VIS_C if (m_hide) return; - m_t << " </tbody>" << endl; - m_t << " </tgroup>" << endl; - m_t << " </table>" << endl; - m_t << " </para>" << endl; - m_t << " </formalpara>" << endl; + m_t << " </tbody>\n"; + m_t << " </tgroup>\n"; + m_t << " </table>\n"; + m_t << " </para>\n"; + m_t << " </formalpara>\n"; m_t << " "; } @@ -1412,7 +1431,7 @@ void DocbookDocVisitor::visitPre(DocParamList *pl) { DB_VIS_C if (m_hide) return; - m_t << " <row>" << endl; + m_t << " <row>\n"; DocParamSect *sect = 0; if (pl->parent() && pl->parent()->kind()==DocNode::Kind_ParamSect) @@ -1422,7 +1441,7 @@ DB_VIS_C if (sect && sect->hasInOutSpecifier()) { - m_t << " <entry>"; + m_t << "<entry>"; if (pl->direction()!=DocParamSect::Unspecified) { if (pl->direction()==DocParamSect::In) @@ -1438,44 +1457,40 @@ DB_VIS_C m_t << "in,out"; } } - m_t << " </entry>"; + m_t << "</entry>"; } if (sect && sect->hasTypeSpecifier()) { - QListIterator<DocNode> li(pl->paramTypes()); - DocNode *type; - m_t << " <entry>"; - for (li.toFirst();(type=li.current());++li) + m_t << "<entry>"; + for (const auto &type : pl->paramTypes()) { if (type->kind()==DocNode::Kind_Word) { - visit((DocWord*)type); + visit((DocWord*)type.get()); } else if (type->kind()==DocNode::Kind_LinkedWord) { - visit((DocLinkedWord*)type); + visit((DocLinkedWord*)type.get()); } else if (type->kind()==DocNode::Kind_Sep) { - m_t << " " << ((DocSeparator *)type)->chars() << " "; + m_t << " " << ((DocSeparator *)type.get())->chars() << " "; } } - m_t << " </entry>"; + m_t << "</entry>"; } - QListIterator<DocNode> li(pl->parameters()); - DocNode *param; - if (!li.toFirst()) + if (pl->parameters().empty()) { - m_t << " <entry></entry>" << endl; + m_t << "<entry></entry>\n"; } else { - m_t << " <entry>"; + m_t << "<entry>"; int cnt = 0; - for (li.toFirst();(param=li.current());++li) + for (const auto ¶m : pl->parameters()) { if (cnt) { @@ -1483,25 +1498,25 @@ DB_VIS_C } if (param->kind()==DocNode::Kind_Word) { - visit((DocWord*)param); + visit((DocWord*)param.get()); } else if (param->kind()==DocNode::Kind_LinkedWord) { - visit((DocLinkedWord*)param); + visit((DocLinkedWord*)param.get()); } cnt++; } - m_t << "</entry>" << endl; + m_t << "</entry>"; } - m_t << " <entry>"; + m_t << "<entry>"; } void DocbookDocVisitor::visitPost(DocParamList *) { DB_VIS_C if (m_hide) return; - m_t << "</entry>" << endl; - m_t << " </row>" << endl; + m_t << "</entry>\n"; + m_t << " </row>\n"; } void DocbookDocVisitor::visitPre(DocXRefItem *x) @@ -1592,7 +1607,7 @@ DB_VIS_C } -void DocbookDocVisitor::filter(const char *str) +void DocbookDocVisitor::filter(const QCString &str) { DB_VIS_C m_t << convertToDocBook(str); @@ -1604,7 +1619,7 @@ DB_VIS_C m_t << "<link linkend=\"_" << stripPath(file); if (!anchor.isEmpty()) { - if (file) m_t << "_1"; + if (!file.isEmpty()) m_t << "_1"; m_t << anchor; } m_t << "\">"; @@ -1616,19 +1631,6 @@ DB_VIS_C m_t << "</link>"; } -void DocbookDocVisitor::pushEnabled() -{ -DB_VIS_C - m_enabled.push(m_hide); -} - -void DocbookDocVisitor::popEnabled() -{ -DB_VIS_C - m_hide=m_enabled.top(); - m_enabled.pop(); -} - void DocbookDocVisitor::writeMscFile(const QCString &baseName, DocVerbatim *s) { DB_VIS_C @@ -1639,7 +1641,7 @@ DB_VIS_C shortName=shortName.right((int)shortName.length()-i-1); } QCString outDir = Config_getString(DOCBOOK_OUTPUT); - writeMscGraphFromFile(baseName+".msc",outDir,shortName,MSC_BITMAP); + writeMscGraphFromFile(baseName+".msc",outDir,shortName,MSC_BITMAP,s->srcFile(),s->srcLine()); visitPreStart(m_t, s->children(), s->hasCaption(), s->relPath() + shortName + ".png", s->width(), s->height()); visitCaption(s->children()); visitPostEnd(m_t, s->hasCaption()); @@ -1655,7 +1657,7 @@ DB_VIS_C shortName=shortName.right((int)shortName.length()-i-1); } QCString outDir = Config_getString(DOCBOOK_OUTPUT); - PlantumlManager::instance()->generatePlantUMLOutput(baseName,outDir,PlantumlManager::PUML_BITMAP); + PlantumlManager::instance().generatePlantUMLOutput(baseName,outDir,PlantumlManager::PUML_BITMAP); visitPreStart(m_t, s->children(), s->hasCaption(), s->relPath() + shortName + ".png", s->width(),s->height()); visitCaption(s->children()); visitPostEnd(m_t, s->hasCaption()); @@ -1665,7 +1667,9 @@ void DocbookDocVisitor::startMscFile(const QCString &fileName, const QCString &width, const QCString &height, bool hasCaption, - const QList<DocNode> &children + const DocNodeList &children, + const QCString &srcFile, + int srcLine ) { DB_VIS_C @@ -1681,8 +1685,8 @@ DB_VIS_C } baseName.prepend("msc_"); QCString outDir = Config_getString(DOCBOOK_OUTPUT); - writeMscGraphFromFile(fileName,outDir,baseName,MSC_BITMAP); - m_t << "<para>" << endl; + writeMscGraphFromFile(fileName,outDir,baseName,MSC_BITMAP,srcFile,srcLine); + m_t << "<para>\n"; visitPreStart(m_t, children, hasCaption, baseName + ".png", width, height); } @@ -1691,7 +1695,7 @@ void DocbookDocVisitor::endMscFile(bool hasCaption) DB_VIS_C if (m_hide) return; visitPostEnd(m_t, hasCaption); - m_t << "</para>" << endl; + m_t << "</para>\n"; } void DocbookDocVisitor::writeDiaFile(const QCString &baseName, DocVerbatim *s) @@ -1704,7 +1708,7 @@ DB_VIS_C shortName=shortName.right((int)shortName.length()-i-1); } QCString outDir = Config_getString(DOCBOOK_OUTPUT); - writeDiaGraphFromFile(baseName+".dia",outDir,shortName,DIA_BITMAP); + writeDiaGraphFromFile(baseName+".dia",outDir,shortName,DIA_BITMAP,s->srcFile(),s->srcLine()); visitPreStart(m_t, s->children(), s->hasCaption(), shortName, s->width(),s->height()); visitCaption(s->children()); visitPostEnd(m_t, s->hasCaption()); @@ -1714,7 +1718,9 @@ void DocbookDocVisitor::startDiaFile(const QCString &fileName, const QCString &width, const QCString &height, bool hasCaption, - const QList<DocNode> &children + const DocNodeList &children, + const QCString &srcFile, + int srcLine ) { DB_VIS_C @@ -1730,8 +1736,8 @@ DB_VIS_C } baseName.prepend("dia_"); QCString outDir = Config_getString(DOCBOOK_OUTPUT); - writeDiaGraphFromFile(fileName,outDir,baseName,DIA_BITMAP); - m_t << "<para>" << endl; + writeDiaGraphFromFile(fileName,outDir,baseName,DIA_BITMAP,srcFile,srcLine); + m_t << "<para>\n"; visitPreStart(m_t, children, hasCaption, baseName + ".png", width, height); } @@ -1740,7 +1746,7 @@ void DocbookDocVisitor::endDiaFile(bool hasCaption) DB_VIS_C if (m_hide) return; visitPostEnd(m_t, hasCaption); - m_t << "</para>" << endl; + m_t << "</para>\n"; } void DocbookDocVisitor::writeDotFile(const QCString &baseName, DocVerbatim *s) @@ -1753,7 +1759,7 @@ DB_VIS_C shortName=shortName.right((int)shortName.length()-i-1); } QCString outDir = Config_getString(DOCBOOK_OUTPUT); - writeDotGraphFromFile(baseName+".dot",outDir,shortName,GOF_BITMAP); + writeDotGraphFromFile(baseName+".dot",outDir,shortName,GOF_BITMAP,s->srcFile(),s->srcLine()); visitPreStart(m_t, s->children(), s->hasCaption(), s->relPath() + shortName + "." + getDotImageExtension(), s->width(),s->height()); visitCaption(s->children()); visitPostEnd(m_t, s->hasCaption()); @@ -1763,7 +1769,9 @@ void DocbookDocVisitor::startDotFile(const QCString &fileName, const QCString &width, const QCString &height, bool hasCaption, - const QList<DocNode> &children + const DocNodeList &children, + const QCString &srcFile, + int srcLine ) { DB_VIS_C @@ -1780,8 +1788,8 @@ DB_VIS_C baseName.prepend("dot_"); QCString outDir = Config_getString(DOCBOOK_OUTPUT); QCString imgExt = getDotImageExtension(); - writeDotGraphFromFile(fileName,outDir,baseName,GOF_BITMAP); - m_t << "<para>" << endl; + writeDotGraphFromFile(fileName,outDir,baseName,GOF_BITMAP,srcFile,srcLine); + m_t << "<para>\n"; visitPreStart(m_t, children, hasCaption, baseName + "." + imgExt, width, height); } @@ -1789,8 +1797,8 @@ void DocbookDocVisitor::endDotFile(bool hasCaption) { DB_VIS_C if (m_hide) return; - m_t << endl; + m_t << "\n"; visitPostEnd(m_t, hasCaption); - m_t << "</para>" << endl; + m_t << "</para>\n"; } |