Skip to content

Commit 44f85e4

Browse files
authored
Merge pull request doxygen#11446 from albert-github/feature/bug_endless_substitute
Incorrect substitute pattern in header / footer
2 parents b0df39e + 47c0fa1 commit 44f85e4

File tree

4 files changed

+59
-36
lines changed

4 files changed

+59
-36
lines changed

src/htmlgen.cpp

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
#define DBG_HTML(x)
6363

6464
static QCString g_header;
65+
static QCString g_header_file;
66+
static QCString g_footer_file;
6567
static QCString g_footer;
6668
static QCString g_mathjax_code;
6769
static QCString g_latex_macro;
@@ -317,7 +319,8 @@ static QCString getSearchBox(bool serverSide, QCString relPath, bool highlightSe
317319
return t.str();
318320
}
319321

320-
static QCString substituteHtmlKeywords(const QCString &str,
322+
static QCString substituteHtmlKeywords(const QCString &file,
323+
const QCString &str,
321324
const QCString &title,
322325
const QCString &relPath,
323326
const QCString &navPath=QCString())
@@ -580,13 +583,13 @@ static QCString substituteHtmlKeywords(const QCString &str,
580583
}
581584

582585
// first substitute generic keywords
583-
QCString result = substituteKeywords(str,title,
586+
QCString result = substituteKeywords(file,str,title,
584587
convertToHtml(Config_getString(PROJECT_NAME)),
585588
convertToHtml(Config_getString(PROJECT_NUMBER)),
586589
convertToHtml(Config_getString(PROJECT_BRIEF)));
587590

588591
// then do the HTML specific keywords
589-
result = substituteKeywords(result,
592+
result = substituteKeywords(file,result,
590593
{
591594
// keyword value getter
592595
{ "$navpath", [&]() { return navPath; } },
@@ -1144,29 +1147,33 @@ void HtmlGenerator::init()
11441147
//writeLogo(dname);
11451148
if (!Config_getString(HTML_HEADER).isEmpty())
11461149
{
1147-
g_header=fileToString(Config_getString(HTML_HEADER));
1150+
g_header_file=Config_getString(HTML_HEADER);
1151+
g_header=fileToString(g_header_file);
11481152
//printf("g_header='%s'\n",qPrint(g_header));
1149-
QCString result = substituteHtmlKeywords(g_header,QCString(),QCString());
1153+
QCString result = substituteHtmlKeywords(g_header_file,g_header,QCString(),QCString());
11501154
checkBlocks(result,Config_getString(HTML_HEADER),htmlMarkerInfo);
11511155
}
11521156
else
11531157
{
1154-
g_header = ResourceMgr::instance().getAsString("header.html");
1155-
QCString result = substituteHtmlKeywords(g_header,QCString(),QCString());
1158+
g_header_file="header.html";
1159+
g_header = ResourceMgr::instance().getAsString(g_header_file);
1160+
QCString result = substituteHtmlKeywords(g_header_file,g_header,QCString(),QCString());
11561161
checkBlocks(result,"<default header.html>",htmlMarkerInfo);
11571162
}
11581163

11591164
if (!Config_getString(HTML_FOOTER).isEmpty())
11601165
{
1161-
g_footer=fileToString(Config_getString(HTML_FOOTER));
1166+
g_footer_file=Config_getString(HTML_FOOTER);
1167+
g_footer=fileToString(g_footer_file);
11621168
//printf("g_footer='%s'\n",qPrint(g_footer));
1163-
QCString result = substituteHtmlKeywords(g_footer,QCString(),QCString());
1169+
QCString result = substituteHtmlKeywords(g_footer_file,g_footer,QCString(),QCString());
11641170
checkBlocks(result,Config_getString(HTML_FOOTER),htmlMarkerInfo);
11651171
}
11661172
else
11671173
{
1168-
g_footer = ResourceMgr::instance().getAsString("footer.html");
1169-
QCString result = substituteHtmlKeywords(g_footer,QCString(),QCString());
1174+
g_footer_file = "footer.html";
1175+
g_footer = ResourceMgr::instance().getAsString(g_footer_file);
1176+
QCString result = substituteHtmlKeywords(g_footer_file,g_footer,QCString(),QCString());
11701177
checkBlocks(result,"<default footer.html>",htmlMarkerInfo);
11711178
}
11721179

@@ -1481,7 +1488,7 @@ void HtmlGenerator::startFile(const QCString &name,const QCString &,
14811488
}
14821489

14831490
m_lastFile = fileName;
1484-
m_t << substituteHtmlKeywords(g_header,convertToHtml(filterTitle(title)),m_relPath);
1491+
m_t << substituteHtmlKeywords(g_header_file,g_header,convertToHtml(filterTitle(title)),m_relPath);
14851492

14861493
m_t << "<!-- " << theTranslator->trGeneratedBy() << " Doxygen "
14871494
<< getDoxygenVersion() << " -->\n";
@@ -1581,7 +1588,7 @@ void HtmlGenerator::writeLogo()
15811588
void HtmlGenerator::writePageFooter(TextStream &t,const QCString &lastTitle,
15821589
const QCString &relPath,const QCString &navPath)
15831590
{
1584-
t << substituteHtmlKeywords(g_footer,convertToHtml(lastTitle),relPath,navPath);
1591+
t << substituteHtmlKeywords(g_footer_file,g_footer,convertToHtml(lastTitle),relPath,navPath);
15851592
}
15861593

15871594
void HtmlGenerator::writeFooter(const QCString &navPath)
@@ -3137,7 +3144,7 @@ void HtmlGenerator::writeSearchPage()
31373144
if (f.is_open())
31383145
{
31393146
TextStream t(&f);
3140-
t << substituteHtmlKeywords(g_header,"Search","");
3147+
t << substituteHtmlKeywords(g_header_file,g_header,"Search","");
31413148

31423149
t << "<!-- " << theTranslator->trGeneratedBy() << " Doxygen "
31433150
<< getDoxygenVersion() << " -->\n";
@@ -3203,7 +3210,7 @@ void HtmlGenerator::writeExternalSearchPage()
32033210
if (f.is_open())
32043211
{
32053212
TextStream t(&f);
3206-
t << substituteHtmlKeywords(g_header,"Search","");
3213+
t << substituteHtmlKeywords(g_header_file,g_header,"Search","");
32073214

32083215
t << "<!-- " << theTranslator->trGeneratedBy() << " Doxygen "
32093216
<< getDoxygenVersion() << " -->\n";

src/latexgen.cpp

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@
4949
#include "moduledef.h"
5050

5151
static QCString g_header;
52+
static QCString g_header_file;
5253
static QCString g_footer;
54+
static QCString g_footer_file;
5355
static const SelectionMarkerInfo latexMarkerInfo = { '%', "%%BEGIN ",8 ,"%%END ",6, "",0 };
5456

55-
static QCString substituteLatexKeywords(const QCString &str, const QCString &title);
57+
static QCString substituteLatexKeywords(const QCString &file, const QCString &str, const QCString &title);
5658

5759
LatexCodeGenerator::LatexCodeGenerator(TextStream *t,const QCString &relPath,const QCString &sourceFileName)
5860
: m_t(t), m_relPath(relPath), m_sourceFileName(sourceFileName)
@@ -636,28 +638,32 @@ void LatexGenerator::init()
636638

637639
if (!Config_getString(LATEX_HEADER).isEmpty())
638640
{
639-
g_header=fileToString(Config_getString(LATEX_HEADER));
641+
g_header_file=Config_getString(LATEX_HEADER);
642+
g_header=fileToString(g_header_file);
640643
//printf("g_header='%s'\n",qPrint(g_header));
641-
QCString result = substituteLatexKeywords(g_header,QCString());
642-
checkBlocks(result,Config_getString(LATEX_HEADER),latexMarkerInfo);
644+
QCString result = substituteLatexKeywords(g_header_file,g_header,QCString());
645+
checkBlocks(result,g_header_file,latexMarkerInfo);
643646
}
644647
else
645648
{
646-
g_header = ResourceMgr::instance().getAsString("header.tex");
647-
QCString result = substituteLatexKeywords(g_header,QCString());
649+
g_header_file = "header.tex";
650+
g_header = ResourceMgr::instance().getAsString(g_header_file);
651+
QCString result = substituteLatexKeywords(g_header_file,g_header,QCString());
648652
checkBlocks(result,"<default header.tex>",latexMarkerInfo);
649653
}
650654
if (!Config_getString(LATEX_FOOTER).isEmpty())
651655
{
652-
g_footer=fileToString(Config_getString(LATEX_FOOTER));
656+
g_footer_file=Config_getString(LATEX_FOOTER);
657+
g_footer=fileToString(g_footer_file);
653658
//printf("g_footer='%s'\n",qPrint(g_footer));
654-
QCString result = substituteLatexKeywords(g_footer,QCString());
655-
checkBlocks(result,Config_getString(LATEX_FOOTER),latexMarkerInfo);
659+
QCString result = substituteLatexKeywords(g_footer_file,g_footer,QCString());
660+
checkBlocks(result,g_footer_file,latexMarkerInfo);
656661
}
657662
else
658663
{
659-
g_footer = ResourceMgr::instance().getAsString("footer.tex");
660-
QCString result = substituteLatexKeywords(g_footer,QCString());
664+
g_footer_file = "footer.tex";
665+
g_footer = ResourceMgr::instance().getAsString(g_footer_file);
666+
QCString result = substituteLatexKeywords(g_footer_file,g_footer,QCString());
661667
checkBlocks(result,"<default footer.tex>",latexMarkerInfo);
662668
}
663669

@@ -787,7 +793,8 @@ static QCString latex_batchmode()
787793
return "";
788794
}
789795

790-
static QCString substituteLatexKeywords(const QCString &str,
796+
static QCString substituteLatexKeywords(const QCString &file,
797+
const QCString &str,
791798
const QCString &title)
792799
{
793800
bool compactLatex = Config_getBool(COMPACT_LATEX);
@@ -855,13 +862,13 @@ static QCString substituteLatexKeywords(const QCString &str,
855862
QCString projectNumber = Config_getString(PROJECT_NUMBER);
856863

857864
// first substitute generic keywords
858-
QCString result = substituteKeywords(str,title,
865+
QCString result = substituteKeywords(file,str,title,
859866
convertToLaTeX(Config_getString(PROJECT_NAME),false),
860867
convertToLaTeX(projectNumber,false),
861868
convertToLaTeX(Config_getString(PROJECT_BRIEF),false));
862869

863870
// additional LaTeX only keywords
864-
result = substituteKeywords(result,
871+
result = substituteKeywords(file,result,
865872
{
866873
// keyword value getter
867874
{ "$latexdocumentpre", [&]() { return theTranslator->latexDocumentPre(); } },
@@ -908,7 +915,7 @@ void LatexGenerator::startIndexSection(IndexSection is)
908915
switch (is)
909916
{
910917
case IndexSection::isTitlePageStart:
911-
m_t << substituteLatexKeywords(g_header,convertToLaTeX(Config_getString(PROJECT_NAME),m_codeGen->insideTabbing()));
918+
m_t << substituteLatexKeywords(g_header_file,g_header,convertToLaTeX(Config_getString(PROJECT_NAME),m_codeGen->insideTabbing()));
912919
break;
913920
case IndexSection::isTitlePageAuthor:
914921
break;
@@ -1260,7 +1267,7 @@ void LatexGenerator::endIndexSection(IndexSection is)
12601267
case IndexSection::isPageDocumentation2:
12611268
break;
12621269
case IndexSection::isEndIndex:
1263-
m_t << substituteLatexKeywords(g_footer,convertToLaTeX(Config_getString(PROJECT_NAME),m_codeGen->insideTabbing()));
1270+
m_t << substituteLatexKeywords(g_footer_file,g_footer,convertToLaTeX(Config_getString(PROJECT_NAME),m_codeGen->insideTabbing()));
12641271
break;
12651272
}
12661273
}

src/util.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3561,9 +3561,10 @@ QCString showFileDefMatches(const FileNameLinkedMap *fnMap,const QCString &n)
35613561

35623562
//----------------------------------------------------------------------
35633563

3564-
QCString substituteKeywords(const QCString &s,const KeywordSubstitutionList &keywords)
3564+
QCString substituteKeywords(const QCString &file, const QCString &s,const KeywordSubstitutionList &keywords)
35653565
{
35663566
std::string substRes;
3567+
int line = 1;
35673568
const char *p = s.data();
35683569
if (p)
35693570
{
@@ -3600,6 +3601,7 @@ QCString substituteKeywords(const QCString &s,const KeywordSubstitutionList &key
36003601
else
36013602
{
36023603
//printf("missing argument\n");
3604+
warn(file,line,"Missing argument for '{}'",kw.keyword);
36033605
p+=keyLen;
36043606
}
36053607
}
@@ -3610,13 +3612,20 @@ QCString substituteKeywords(const QCString &s,const KeywordSubstitutionList &key
36103612
//printf("found '%s'->'%s'\n",kw.keyword,qPrint(getValue()));
36113613
p+=keyLen;
36123614
}
3615+
else
3616+
{
3617+
//printf("%s %d Expected arguments, none specified '%s'\n",qPrint(file), line, qPrint(kw.keyword));
3618+
warn(file,line,"Expected arguments for '{}' but none were specified",kw.keyword);
3619+
p+=keyLen;
3620+
}
36133621
found = true;
36143622
break;
36153623
}
36163624
}
36173625
}
36183626
if (!found) // copy
36193627
{
3628+
if (c=='\n') line++;
36203629
substRes+=c;
36213630
p++;
36223631
}
@@ -3704,10 +3713,10 @@ static QCString projectLogoSize()
37043713
return sizeVal;
37053714
}
37063715

3707-
QCString substituteKeywords(const QCString &s,const QCString &title,
3716+
QCString substituteKeywords(const QCString &file,const QCString &s,const QCString &title,
37083717
const QCString &projName,const QCString &projNum,const QCString &projBrief)
37093718
{
3710-
return substituteKeywords(s,
3719+
return substituteKeywords(file,s,
37113720
{
37123721
// keyword value getter
37133722
{ "$title", [&]() { return !title.isEmpty() ? title : projName; } },

src/util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ struct KeywordSubstitution
247247

248248
using KeywordSubstitutionList = std::vector<KeywordSubstitution>;
249249

250-
QCString substituteKeywords(const QCString &s,const KeywordSubstitutionList &keywords);
250+
QCString substituteKeywords(const QCString &file,const QCString &s,const KeywordSubstitutionList &keywords);
251251

252-
QCString substituteKeywords(const QCString &s,const QCString &title,
252+
QCString substituteKeywords(const QCString &file,const QCString &s,const QCString &title,
253253
const QCString &projName,const QCString &projNum,const QCString &projBrief);
254254

255255
int getPrefixIndex(const QCString &name);

0 commit comments

Comments
 (0)