Skip to content

Commit 0c8bc0e

Browse files
committed
Merge branch 'feature/bug_lineno_split_examples' of https://github.com/albert-github/doxygen into albert-github-feature/bug_lineno_split_examples
2 parents 169a671 + 8d13a1a commit 0c8bc0e

10 files changed

+142
-26
lines changed

doc/commands.doc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2186,7 +2186,7 @@ Commands for displaying examples
21862186
\htmlonly</p></center><p>\endhtmlonly
21872187

21882188
<hr>
2189-
\section cmddontinclude \\dontinclude <file-name>
2189+
\section cmddontinclude \\dontinclude[{lineno}] <file-name>
21902190

21912191
\addindex \\dontinclude
21922192
This command can be used to parse a source file without actually
@@ -2197,6 +2197,8 @@ Commands for displaying examples
21972197
\ref cfg_example_path "EXAMPLE_PATH"
21982198
tag of doxygen's configuration file.
21992199

2200+
You can add option `{lineno}` to enable line numbers for the included code if desired.
2201+
22002202
The class and member declarations and definitions inside the code fragment
22012203
are 'remembered' during the parsing of the comment block that contained
22022204
the \c \\dontinclude command.

src/docbookvisitor.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,8 @@ DB_VIS_C
408408
m_t << "</computeroutput></literallayout>";
409409
break;
410410
case DocInclude::DontInclude:
411-
break;
411+
case DocInclude::DontIncWithLines:
412412
case DocInclude::HtmlInclude:
413-
break;
414413
case DocInclude::LatexInclude:
415414
break;
416415
case DocInclude::VerbInclude:
@@ -479,10 +478,25 @@ DB_VIS_C
479478
popEnabled();
480479
if (!m_hide)
481480
{
481+
FileDef *fd;
482+
if (!op->includeFileName().isEmpty())
483+
{
484+
QFileInfo cfi( op->includeFileName() );
485+
fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() );
486+
}
487+
482488
Doxygen::parserManager->getParser(m_langExt)
483489
->parseCode(m_ci,op->context(),
484490
op->text(),langExt,op->isExample(),
485-
op->exampleFile());
491+
op->exampleFile(),
492+
fd, // fileDef
493+
op->line(), // startLine
494+
-1, // endLine
495+
FALSE, // inline fragment
496+
0, // memberDef
497+
op->showLineNo() // show line numbers
498+
);
499+
if (fd) delete fd;
486500
}
487501
pushEnabled();
488502
m_hide=TRUE;

src/docparser.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ static QCString g_includeFileName;
112112
static QCString g_includeFileText;
113113
static uint g_includeFileOffset;
114114
static uint g_includeFileLength;
115+
static uint g_includeFileLine;
116+
static bool g_includeFileShowLineNo;
115117

116118

117119
/** Parser's context to store all global variables.
@@ -143,6 +145,8 @@ struct DocParserContext
143145
QCString includeFileText;
144146
uint includeFileOffset;
145147
uint includeFileLength;
148+
uint includeFileLine;
149+
bool includeFileLineNo;
146150

147151
TokenInfo *token;
148152
};
@@ -190,6 +194,8 @@ static void docParserPushContext(bool saveParamInfo=TRUE)
190194
ctx->includeFileText = g_includeFileText;
191195
ctx->includeFileOffset = g_includeFileOffset;
192196
ctx->includeFileLength = g_includeFileLength;
197+
ctx->includeFileLine = g_includeFileLine;
198+
ctx->includeFileLineNo = g_includeFileShowLineNo;
193199

194200
ctx->token = g_token;
195201
g_token = new TokenInfo;
@@ -228,6 +234,8 @@ static void docParserPopContext(bool keepParamInfo=FALSE)
228234
g_includeFileText = ctx->includeFileText;
229235
g_includeFileOffset = ctx->includeFileOffset;
230236
g_includeFileLength = ctx->includeFileLength;
237+
g_includeFileLine = ctx->includeFileLine;
238+
g_includeFileShowLineNo = ctx->includeFileLineNo;
231239

232240
delete g_token;
233241
g_token = ctx->token;
@@ -2004,6 +2012,8 @@ void DocInclude::parse()
20042012
DBG(("DocInclude::parse(file=%s,text=%s)\n",qPrint(m_file),qPrint(m_text)));
20052013
switch(m_type)
20062014
{
2015+
case DontIncWithLines:
2016+
// fall through
20072017
case IncWithLines:
20082018
// fall through
20092019
case Include:
@@ -2014,6 +2024,8 @@ void DocInclude::parse()
20142024
g_includeFileText = m_text;
20152025
g_includeFileOffset = 0;
20162026
g_includeFileLength = m_text.length();
2027+
g_includeFileLine = 0;
2028+
g_includeFileShowLineNo = (m_type == DontIncWithLines || m_type == IncWithLines);
20172029
//printf("g_includeFile=<<%s>>\n",g_includeFileText.data());
20182030
break;
20192031
case VerbInclude:
@@ -2059,6 +2071,7 @@ void DocIncOperator::parse()
20592071
const char *p = g_includeFileText;
20602072
uint l = g_includeFileLength;
20612073
uint o = g_includeFileOffset;
2074+
uint il = g_includeFileLine;
20622075
DBG(("DocIncOperator::parse() text=%s off=%d len=%d\n",qPrint(p),o,l));
20632076
uint so = o,bo;
20642077
bool nonEmpty = FALSE;
@@ -2070,6 +2083,7 @@ void DocIncOperator::parse()
20702083
char c = p[o];
20712084
if (c=='\n')
20722085
{
2086+
g_includeFileLine++;
20732087
if (nonEmpty) break; // we have a pattern to match
20742088
so=o+1; // no pattern, skip empty line
20752089
}
@@ -2081,10 +2095,12 @@ void DocIncOperator::parse()
20812095
}
20822096
if (g_includeFileText.mid(so,o-so).find(m_pattern)!=-1)
20832097
{
2098+
m_line = il;
20842099
m_text = g_includeFileText.mid(so,o-so);
20852100
DBG(("DocIncOperator::parse() Line: %s\n",qPrint(m_text)));
20862101
}
20872102
g_includeFileOffset = QMIN(l,o+1); // set pointer to start of new line
2103+
m_showLineNo = g_includeFileShowLineNo;
20882104
break;
20892105
case SkipLine:
20902106
while (o<l)
@@ -2095,6 +2111,7 @@ void DocIncOperator::parse()
20952111
char c = p[o];
20962112
if (c=='\n')
20972113
{
2114+
g_includeFileLine++;
20982115
if (nonEmpty) break; // we have a pattern to match
20992116
so=o+1; // no pattern, skip empty line
21002117
}
@@ -2106,13 +2123,15 @@ void DocIncOperator::parse()
21062123
}
21072124
if (g_includeFileText.mid(so,o-so).find(m_pattern)!=-1)
21082125
{
2126+
m_line = il;
21092127
m_text = g_includeFileText.mid(so,o-so);
21102128
DBG(("DocIncOperator::parse() SkipLine: %s\n",qPrint(m_text)));
21112129
break;
21122130
}
21132131
o++; // skip new line
21142132
}
21152133
g_includeFileOffset = QMIN(l,o+1); // set pointer to start of new line
2134+
m_showLineNo = g_includeFileShowLineNo;
21162135
break;
21172136
case Skip:
21182137
while (o<l)
@@ -2123,6 +2142,7 @@ void DocIncOperator::parse()
21232142
char c = p[o];
21242143
if (c=='\n')
21252144
{
2145+
g_includeFileLine++;
21262146
if (nonEmpty) break; // we have a pattern to match
21272147
so=o+1; // no pattern, skip empty line
21282148
}
@@ -2139,6 +2159,7 @@ void DocIncOperator::parse()
21392159
o++; // skip new line
21402160
}
21412161
g_includeFileOffset = so; // set pointer to start of new line
2162+
m_showLineNo = g_includeFileShowLineNo;
21422163
break;
21432164
case Until:
21442165
bo=o;
@@ -2150,6 +2171,7 @@ void DocIncOperator::parse()
21502171
char c = p[o];
21512172
if (c=='\n')
21522173
{
2174+
g_includeFileLine++;
21532175
if (nonEmpty) break; // we have a pattern to match
21542176
so=o+1; // no pattern, skip empty line
21552177
}
@@ -2161,13 +2183,15 @@ void DocIncOperator::parse()
21612183
}
21622184
if (g_includeFileText.mid(so,o-so).find(m_pattern)!=-1)
21632185
{
2186+
m_line = il;
21642187
m_text = g_includeFileText.mid(bo,o-bo);
21652188
DBG(("DocIncOperator::parse() Until: %s\n",qPrint(m_text)));
21662189
break;
21672190
}
21682191
o++; // skip new line
21692192
}
21702193
g_includeFileOffset = QMIN(l,o+1); // set pointer to start of new line
2194+
m_showLineNo = g_includeFileShowLineNo;
21712195
break;
21722196
}
21732197
}
@@ -5276,6 +5300,10 @@ void DocPara::handleInclude(const QCString &cmdName,DocInclude::Type t)
52765300
{
52775301
t = DocInclude::SnipWithLines;
52785302
}
5303+
else if (t==DocInclude::DontInclude && optList.contains("lineno"))
5304+
{
5305+
t = DocInclude::DontIncWithLines;
5306+
}
52795307
else if (t==DocInclude::Include && optList.contains("doc"))
52805308
{
52815309
t = DocInclude::IncludeDoc;

src/docparser.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,8 @@ class DocInclude : public DocNode
563563
{
564564
public:
565565
enum Type { Include, DontInclude, VerbInclude, HtmlInclude, LatexInclude,
566-
IncWithLines, Snippet , IncludeDoc, SnippetDoc, SnipWithLines};
566+
IncWithLines, Snippet , IncludeDoc, SnippetDoc, SnipWithLines,
567+
DontIncWithLines};
567568
DocInclude(DocNode *parent,const QCString &file,
568569
const QCString context, Type t,
569570
bool isExample,const QCString exampleFile,
@@ -623,6 +624,8 @@ class DocIncOperator : public DocNode
623624
}
624625
return "";
625626
}
627+
int line() const { return m_line; }
628+
bool showLineNo() const { return m_showLineNo; }
626629
QCString text() const { return m_text; }
627630
QCString pattern() const { return m_pattern; }
628631
QCString context() const { return m_context; }
@@ -638,6 +641,8 @@ class DocIncOperator : public DocNode
638641

639642
private:
640643
Type m_type;
644+
int m_line;
645+
bool m_showLineNo;
641646
QCString m_text;
642647
QCString m_pattern;
643648
QCString m_context;

src/htmldocvisitor.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,9 @@ void HtmlDocVisitor::visit(DocInclude *inc)
670670
forceStartParagraph(inc);
671671
}
672672
break;
673-
case DocInclude::DontInclude:
673+
case DocInclude::DontInclude:
674+
case DocInclude::LatexInclude:
675+
case DocInclude::DontIncWithLines:
674676
break;
675677
case DocInclude::HtmlInclude:
676678
{
@@ -679,8 +681,6 @@ void HtmlDocVisitor::visit(DocInclude *inc)
679681
if (inc->isBlock()) forceStartParagraph(inc);
680682
}
681683
break;
682-
case DocInclude::LatexInclude:
683-
break;
684684
case DocInclude::VerbInclude:
685685
forceEndParagraph(inc);
686686
m_t << /*PREFRAG_START <<*/ "<pre class=\"fragment\">";
@@ -762,6 +762,12 @@ void HtmlDocVisitor::visit(DocIncOperator *op)
762762
popEnabled();
763763
if (!m_hide)
764764
{
765+
FileDef *fd;
766+
if (!op->includeFileName().isEmpty())
767+
{
768+
QFileInfo cfi( op->includeFileName() );
769+
fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() );
770+
}
765771
Doxygen::parserManager->getParser(m_langExt)
766772
->parseCode(
767773
m_ci,
@@ -770,14 +776,15 @@ void HtmlDocVisitor::visit(DocIncOperator *op)
770776
langExt,
771777
op->isExample(),
772778
op->exampleFile(),
773-
0, // fileDef
774-
-1, // startLine
779+
fd, // fileDef
780+
op->line(), // startLine
775781
-1, // endLine
776782
FALSE, // inline fragment
777783
0, // memberDef
778-
TRUE, // show line numbers
784+
op->showLineNo(), // show line numbers
779785
m_ctx // search context
780786
);
787+
if (fd) delete fd;
781788
}
782789
pushEnabled();
783790
m_hide=TRUE;

src/latexdocvisitor.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,9 @@ void LatexDocVisitor::visit(DocInclude *inc)
494494
LatexCodeGenerator::setDoxyCodeOpen(FALSE);
495495
m_t << "\\end{DoxyCodeInclude}\n";
496496
break;
497-
case DocInclude::DontInclude:
498-
break;
499-
case DocInclude::HtmlInclude:
497+
case DocInclude::DontInclude:
498+
case DocInclude::DontIncWithLines:
499+
case DocInclude::HtmlInclude:
500500
break;
501501
case DocInclude::LatexInclude:
502502
m_t << inc->text();
@@ -572,9 +572,24 @@ void LatexDocVisitor::visit(DocIncOperator *op)
572572
popEnabled();
573573
if (!m_hide)
574574
{
575+
FileDef *fd;
576+
if (!op->includeFileName().isEmpty())
577+
{
578+
QFileInfo cfi( op->includeFileName() );
579+
fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() );
580+
}
581+
575582
Doxygen::parserManager->getParser(m_langExt)
576583
->parseCode(m_ci,op->context(),op->text(),langExt,
577-
op->isExample(),op->exampleFile());
584+
op->isExample(),op->exampleFile(),
585+
fd, // fileDef
586+
op->line(), // startLine
587+
-1, // endLine
588+
FALSE, // inline fragment
589+
0, // memberDef
590+
op->showLineNo() // show line numbers
591+
);
592+
if (fd) delete fd;
578593
}
579594
pushEnabled();
580595
m_hide=TRUE;

src/mandocvisitor.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,9 @@ void ManDocVisitor::visit(DocInclude *inc)
297297
m_t << ".PP" << endl;
298298
m_firstCol=TRUE;
299299
break;
300-
case DocInclude::DontInclude:
301-
break;
302-
case DocInclude::HtmlInclude:
303-
break;
300+
case DocInclude::DontInclude:
301+
case DocInclude::DontIncWithLines:
302+
case DocInclude::HtmlInclude:
304303
case DocInclude::LatexInclude:
305304
break;
306305
case DocInclude::VerbInclude:
@@ -387,9 +386,24 @@ void ManDocVisitor::visit(DocIncOperator *op)
387386
popEnabled();
388387
if (!m_hide)
389388
{
389+
FileDef *fd;
390+
if (!op->includeFileName().isEmpty())
391+
{
392+
QFileInfo cfi( op->includeFileName() );
393+
fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() );
394+
}
395+
390396
Doxygen::parserManager->getParser(m_langExt)
391397
->parseCode(m_ci,op->context(),op->text(),langExt,
392-
op->isExample(),op->exampleFile());
398+
op->isExample(),op->exampleFile(),
399+
fd, // fileDef
400+
op->line(), // startLine
401+
-1, // endLine
402+
FALSE, // inline fragment
403+
0, // memberDef
404+
op->showLineNo() // show line numbers
405+
);
406+
if (fd) delete fd;
393407
}
394408
pushEnabled();
395409
m_hide=TRUE;

src/perlmodgen.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ void PerlModDocVisitor::visit(DocInclude *inc)
729729
#endif
730730
return;
731731
case DocInclude::DontInclude: return;
732+
case DocInclude::DontIncWithLines: return;
732733
case DocInclude::HtmlInclude: type = "htmlonly"; break;
733734
case DocInclude::LatexInclude: type = "latexonly"; break;
734735
case DocInclude::VerbInclude: type = "preformatted"; break;

0 commit comments

Comments
 (0)