Skip to content

Commit 8d13a1a

Browse files
committed
Show line numbers in "split" examples
With the commands like `\skip`, `\skipline` it is possible to show parts of a file for further explanation / tutorials. They can be started with `\include` or `\dontinclude` but in case `\include` specifies that the line numbers have to be shown they are only shown in the full example and not in the split up example - show line numbers in split up example in case `lineno` is required - add `lineno` option to `\dontinclude` so here also line numbers can be shown.
1 parent abe69bd commit 8d13a1a

File tree

9 files changed

+127
-10
lines changed

9 files changed

+127
-10
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: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,25 @@ DB_VIS_C
479479
popEnabled();
480480
if (!m_hide)
481481
{
482+
FileDef *fd;
483+
if (!op->includeFileName().isEmpty())
484+
{
485+
QFileInfo cfi( op->includeFileName() );
486+
fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() );
487+
}
488+
482489
Doxygen::parserManager->getParser(m_langExt)
483490
->parseCode(m_ci,op->context(),
484491
op->text(),langExt,op->isExample(),
485-
op->exampleFile());
492+
op->exampleFile(),
493+
fd, // fileDef
494+
op->line(), // startLine
495+
-1, // endLine
496+
FALSE, // inline fragment
497+
0, // memberDef
498+
op->lineno() // show line numbers
499+
);
500+
if (fd) delete fd;
486501
}
487502
pushEnabled();
488503
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_includeFileLineNo;
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_includeFileLineNo;
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_includeFileLineNo = 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_includeFileLineNo = (m_type == DontIncWithLines || m_type == IncWithLines);
20172029
//printf("g_includeFile=<<%s>>\n",g_includeFileText.data());
20182030
break;
20192031
case VerbInclude:
@@ -2052,6 +2064,7 @@ void DocIncOperator::parse()
20522064
const char *p = g_includeFileText;
20532065
uint l = g_includeFileLength;
20542066
uint o = g_includeFileOffset;
2067+
uint il = g_includeFileLine;
20552068
DBG(("DocIncOperator::parse() text=%s off=%d len=%d\n",qPrint(p),o,l));
20562069
uint so = o,bo;
20572070
bool nonEmpty = FALSE;
@@ -2063,6 +2076,7 @@ void DocIncOperator::parse()
20632076
char c = p[o];
20642077
if (c=='\n')
20652078
{
2079+
g_includeFileLine++;
20662080
if (nonEmpty) break; // we have a pattern to match
20672081
so=o+1; // no pattern, skip empty line
20682082
}
@@ -2074,10 +2088,12 @@ void DocIncOperator::parse()
20742088
}
20752089
if (g_includeFileText.mid(so,o-so).find(m_pattern)!=-1)
20762090
{
2091+
m_line = il;
20772092
m_text = g_includeFileText.mid(so,o-so);
20782093
DBG(("DocIncOperator::parse() Line: %s\n",qPrint(m_text)));
20792094
}
20802095
g_includeFileOffset = QMIN(l,o+1); // set pointer to start of new line
2096+
m_lineno = g_includeFileLineNo;
20812097
break;
20822098
case SkipLine:
20832099
while (o<l)
@@ -2088,6 +2104,7 @@ void DocIncOperator::parse()
20882104
char c = p[o];
20892105
if (c=='\n')
20902106
{
2107+
g_includeFileLine++;
20912108
if (nonEmpty) break; // we have a pattern to match
20922109
so=o+1; // no pattern, skip empty line
20932110
}
@@ -2099,13 +2116,15 @@ void DocIncOperator::parse()
20992116
}
21002117
if (g_includeFileText.mid(so,o-so).find(m_pattern)!=-1)
21012118
{
2119+
m_line = il;
21022120
m_text = g_includeFileText.mid(so,o-so);
21032121
DBG(("DocIncOperator::parse() SkipLine: %s\n",qPrint(m_text)));
21042122
break;
21052123
}
21062124
o++; // skip new line
21072125
}
21082126
g_includeFileOffset = QMIN(l,o+1); // set pointer to start of new line
2127+
m_lineno = g_includeFileLineNo;
21092128
break;
21102129
case Skip:
21112130
while (o<l)
@@ -2116,6 +2135,7 @@ void DocIncOperator::parse()
21162135
char c = p[o];
21172136
if (c=='\n')
21182137
{
2138+
g_includeFileLine++;
21192139
if (nonEmpty) break; // we have a pattern to match
21202140
so=o+1; // no pattern, skip empty line
21212141
}
@@ -2132,6 +2152,7 @@ void DocIncOperator::parse()
21322152
o++; // skip new line
21332153
}
21342154
g_includeFileOffset = so; // set pointer to start of new line
2155+
m_lineno = g_includeFileLineNo;
21352156
break;
21362157
case Until:
21372158
bo=o;
@@ -2143,6 +2164,7 @@ void DocIncOperator::parse()
21432164
char c = p[o];
21442165
if (c=='\n')
21452166
{
2167+
g_includeFileLine++;
21462168
if (nonEmpty) break; // we have a pattern to match
21472169
so=o+1; // no pattern, skip empty line
21482170
}
@@ -2154,13 +2176,15 @@ void DocIncOperator::parse()
21542176
}
21552177
if (g_includeFileText.mid(so,o-so).find(m_pattern)!=-1)
21562178
{
2179+
m_line = il;
21572180
m_text = g_includeFileText.mid(bo,o-bo);
21582181
DBG(("DocIncOperator::parse() Until: %s\n",qPrint(m_text)));
21592182
break;
21602183
}
21612184
o++; // skip new line
21622185
}
21632186
g_includeFileOffset = QMIN(l,o+1); // set pointer to start of new line
2187+
m_lineno = g_includeFileLineNo;
21642188
break;
21652189
}
21662190
}
@@ -5269,6 +5293,10 @@ void DocPara::handleInclude(const QCString &cmdName,DocInclude::Type t)
52695293
{
52705294
t = DocInclude::SnipWithLines;
52715295
}
5296+
else if (t==DocInclude::DontInclude && optList.contains("lineno"))
5297+
{
5298+
t = DocInclude::DontIncWithLines;
5299+
}
52725300
else if (t==DocInclude::Include && optList.contains("doc"))
52735301
{
52745302
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,
@@ -612,6 +613,8 @@ class DocIncOperator : public DocNode
612613
m_isExample(isExample), m_exampleFile(exampleFile) { m_parent = parent; }
613614
Kind kind() const { return Kind_IncOperator; }
614615
Type type() const { return m_type; }
616+
int line() const { return m_line; }
617+
bool lineno() const { return m_lineno; }
615618
QCString text() const { return m_text; }
616619
QCString pattern() const { return m_pattern; }
617620
QCString context() const { return m_context; }
@@ -627,6 +630,8 @@ class DocIncOperator : public DocNode
627630

628631
private:
629632
Type m_type;
633+
int m_line;
634+
bool m_lineno;
630635
QCString m_text;
631636
QCString m_pattern;
632637
QCString m_context;

src/htmldocvisitor.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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->lineno(), // 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: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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->lineno() // show line numbers
591+
);
592+
if (fd) delete fd;
578593
}
579594
pushEnabled();
580595
m_hide=TRUE;

src/mandocvisitor.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,24 @@ void ManDocVisitor::visit(DocIncOperator *op)
387387
popEnabled();
388388
if (!m_hide)
389389
{
390+
FileDef *fd;
391+
if (!op->includeFileName().isEmpty())
392+
{
393+
QFileInfo cfi( op->includeFileName() );
394+
fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() );
395+
}
396+
390397
Doxygen::parserManager->getParser(m_langExt)
391398
->parseCode(m_ci,op->context(),op->text(),langExt,
392-
op->isExample(),op->exampleFile());
399+
op->isExample(),op->exampleFile(),
400+
fd, // fileDef
401+
op->line(), // startLine
402+
-1, // endLine
403+
FALSE, // inline fragment
404+
0, // memberDef
405+
op->lineno() // show line numbers
406+
);
407+
if (fd) delete fd;
393408
}
394409
pushEnabled();
395410
m_hide=TRUE;

src/rtfdocvisitor.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,24 @@ void RTFDocVisitor::visit(DocIncOperator *op)
550550
popEnabled();
551551
if (!m_hide)
552552
{
553+
FileDef *fd;
554+
if (!op->includeFileName().isEmpty())
555+
{
556+
QFileInfo cfi( op->includeFileName() );
557+
fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() );
558+
}
559+
553560
Doxygen::parserManager->getParser(m_langExt)
554561
->parseCode(m_ci,op->context(),op->text(),langExt,
555-
op->isExample(),op->exampleFile());
562+
op->isExample(),op->exampleFile(),
563+
fd, // fileDef
564+
op->line(), // startLine
565+
-1, // endLine
566+
FALSE, // inline fragment
567+
0, // memberDef
568+
op->lineno() // show line numbers
569+
);
570+
if (fd) delete fd;
556571
}
557572
pushEnabled();
558573
m_hide=TRUE;

src/xmldocvisitor.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,25 @@ void XmlDocVisitor::visit(DocIncOperator *op)
420420
popEnabled();
421421
if (!m_hide)
422422
{
423+
FileDef *fd;
424+
if (!op->includeFileName().isEmpty())
425+
{
426+
QFileInfo cfi( op->includeFileName() );
427+
fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() );
428+
}
429+
423430
Doxygen::parserManager->getParser(m_langExt)
424431
->parseCode(m_ci,op->context(),
425432
op->text(),langExt,op->isExample(),
426-
op->exampleFile());
433+
op->exampleFile(),
434+
fd, // fileDef
435+
op->line(), // startLine
436+
-1, // endLine
437+
FALSE, // inline fragment
438+
0, // memberDef
439+
op->lineno() // show line numbers
440+
);
441+
if (fd) delete fd;
427442
}
428443
pushEnabled();
429444
m_hide=TRUE;

0 commit comments

Comments
 (0)