Skip to content

Commit

Permalink
Check for remaining markers in the used header and footer for HTML an…
Browse files Browse the repository at this point in the history
…d LaTeX

Check for remaining markers in the used header and footer for HTML and LaTeX.
In case there are none  solved parts in the header / footer this might lead to unexpected results and errors.
  • Loading branch information
albert-github committed May 23, 2023
1 parent accb1cc commit 448cfb8
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/htmlgen.cpp
Expand Up @@ -67,6 +67,8 @@ static QCString g_mathjax_code;
static QCString g_latex_macro;
static constexpr auto hex="0123456789ABCDEF";

static const SelectionMarkerInfo htmlMarkerInfo = { '<', "<!--BEGIN ",10,"<!--END ",8,"-->",3 };

// note: this is only active if DISABLE_INDEX=YES, if DISABLE_INDEX is disabled, this
// part will be rendered inside menu.js
static void writeClientSearchBox(TextStream &t,const QCString &relPath)
Expand Down Expand Up @@ -596,8 +598,6 @@ static QCString substituteHtmlKeywords(const QCString &str,

result = substitute(result,"$relpath^",relPath); //<-- must be done after the previous substitutions

static const SelectionMarkerInfo htmlMarkerInfo = { '<', "<!--BEGIN ",10,"<!--END ",8,"-->",3 };

// remove conditional blocks
result = selectBlocks(result,
{
Expand Down Expand Up @@ -1125,20 +1125,28 @@ void HtmlGenerator::init()
{
g_header=fileToString(Config_getString(HTML_HEADER));
//printf("g_header='%s'\n",qPrint(g_header));
QCString result = substituteHtmlKeywords(g_header,QCString(),QCString());
checkBlocks(result,Config_getString(HTML_HEADER),htmlMarkerInfo);
}
else
{
g_header = ResourceMgr::instance().getAsString("header.html");
QCString result = substituteHtmlKeywords(g_header,QCString(),QCString());
checkBlocks(result,"<default header.html>",htmlMarkerInfo);
}

if (!Config_getString(HTML_FOOTER).isEmpty())
{
g_footer=fileToString(Config_getString(HTML_FOOTER));
//printf("g_footer='%s'\n",qPrint(g_footer));
QCString result = substituteHtmlKeywords(g_footer,QCString(),QCString());
checkBlocks(result,Config_getString(HTML_FOOTER),htmlMarkerInfo);
}
else
{
g_footer = ResourceMgr::instance().getAsString("footer.html");
QCString result = substituteHtmlKeywords(g_footer,QCString(),QCString());
checkBlocks(result,"<default footer.html>",htmlMarkerInfo);
}

if (Config_getBool(USE_MATHJAX))
Expand Down
13 changes: 11 additions & 2 deletions src/latexgen.cpp
Expand Up @@ -49,6 +49,9 @@

static QCString g_header;
static QCString g_footer;
static const SelectionMarkerInfo latexMarkerInfo = { '%', "%%BEGIN ",8 ,"%%END ",6, "",0 };

static QCString substituteLatexKeywords(const QCString &str, const QCString &title);

LatexCodeGenerator::LatexCodeGenerator(TextStream *t,const QCString &relPath,const QCString &sourceFileName)
: m_t(t), m_relPath(relPath), m_sourceFileName(sourceFileName)
Expand Down Expand Up @@ -554,19 +557,27 @@ void LatexGenerator::init()
{
g_header=fileToString(Config_getString(LATEX_HEADER));
//printf("g_header='%s'\n",qPrint(g_header));
QCString result = substituteLatexKeywords(g_header,QCString());
checkBlocks(result,Config_getString(LATEX_HEADER),latexMarkerInfo);
}
else
{
g_header = ResourceMgr::instance().getAsString("header.tex");
QCString result = substituteLatexKeywords(g_header,QCString());
checkBlocks(result,"<default header.tex>",latexMarkerInfo);
}
if (!Config_getString(LATEX_FOOTER).isEmpty())
{
g_footer=fileToString(Config_getString(LATEX_FOOTER));
//printf("g_footer='%s'\n",qPrint(g_footer));
QCString result = substituteLatexKeywords(g_footer,QCString());
checkBlocks(result,Config_getString(LATEX_FOOTER),latexMarkerInfo);
}
else
{
g_footer = ResourceMgr::instance().getAsString("footer.tex");
QCString result = substituteLatexKeywords(g_footer,QCString());
checkBlocks(result,"<default footer.tex>",latexMarkerInfo);
}

writeLatexMakefile();
Expand Down Expand Up @@ -791,8 +802,6 @@ static QCString substituteLatexKeywords(const QCString &str,
{ "$latex_batchmode", [&]() { return latex_batchmode(); } }
});

static const SelectionMarkerInfo latexMarkerInfo = { '%', "%%BEGIN ",8 ,"%%END ",6, "",0 };

// remove conditional blocks
result = selectBlocks(result,
{
Expand Down
63 changes: 63 additions & 0 deletions src/util.cpp
Expand Up @@ -7023,6 +7023,69 @@ QCString selectBlocks(const QCString &s,const SelectionBlockList &blockList,cons
return result;
}

void checkBlocks(const QCString &s, const QCString fileName,const SelectionMarkerInfo &markerInfo)
{
if (s.isEmpty()) return;

const char *p = s.data();
char c;
while ((c=*p))
{
if (c==markerInfo.markerChar) // potential start of marker
{
if (qstrncmp(p,markerInfo.beginStr,markerInfo.beginLen)==0) // start of begin marker
{
size_t len = markerInfo.beginLen;
bool negate = *(p+len)=='!';
if (negate) len++;
p += len;
QCString marker;
while (*p)
{
if (markerInfo.closeLen==0 && *p=='\n') // matching end of line
{
warn(fileName,-1,"Remaining begin replacement with marker '%s'",qPrint(marker));
break;
}
else if (markerInfo.closeLen!= 0 && qstrncmp(p,markerInfo.closeStr,markerInfo.closeLen)==0) // matching marker closing
{
p += markerInfo.closeLen;
warn(fileName,-1,"Remaining begin replacement with marker '%s'",qPrint(marker));
break;
}
marker += *p;
p++;
}
}
else if (qstrncmp(p,markerInfo.endStr,markerInfo.endLen)==0) // start of end marker
{
size_t len = markerInfo.endLen;
bool negate = *(p+len)=='!';
if (negate) len++;
p += len;
QCString marker;
while (*p)
{
if (markerInfo.closeLen==0 && *p=='\n') // matching end of line
{
warn(fileName,-1,"Remaining end replacement with marker '%s'",qPrint(marker));
break;
}
else if (markerInfo.closeLen!= 0 && qstrncmp(p,markerInfo.closeStr,markerInfo.closeLen)==0) // matching marker closing
{
p += markerInfo.closeLen;
warn(fileName,-1,"Remaining end replacement with marker '%s'",qPrint(marker));
break;
}
marker += *p;
p++;
}
}
}
p++;
}
}


QCString removeEmptyLines(const QCString &s)
{
Expand Down
1 change: 1 addition & 0 deletions src/util.h
Expand Up @@ -174,6 +174,7 @@ struct SelectionMarkerInfo
};

QCString selectBlocks(const QCString& s,const SelectionBlockList &blockList, const SelectionMarkerInfo &markerInfo);
void checkBlocks(const QCString& s,const QCString fileName, const SelectionMarkerInfo &markerInfo);

QCString removeEmptyLines(const QCString &s);

Expand Down

0 comments on commit 448cfb8

Please sign in to comment.