diff options
author | ax006ho <j.hoffmann@fh-aachen.de> | 2020-01-31 11:27:02 +0100 |
---|---|---|
committer | ax006ho <j.hoffmann@fh-aachen.de> | 2020-01-31 11:27:02 +0100 |
commit | 0260e1ba836973b2211a569a55b03af06846c068 (patch) | |
tree | 965eda277fa127040e9e0e569aebd248153551e4 | |
parent | c3b30e4b982f46048ee67868a69488343c5115d5 (diff) | |
download | listings-0260e1ba836973b2211a569a55b03af06846c068.tar.gz listings-0260e1ba836973b2211a569a55b03af06846c068.tar.bz2 |
removed some nital settings, added a lot of testcases
-rw-r--r-- | testing/keyval/numbering/numbering.tex | 131 |
1 files changed, 117 insertions, 14 deletions
diff --git a/testing/keyval/numbering/numbering.tex b/testing/keyval/numbering/numbering.tex index 52aebf5..eb3b63a 100644 --- a/testing/keyval/numbering/numbering.tex +++ b/testing/keyval/numbering/numbering.tex @@ -23,6 +23,8 @@ \usepackage{listings} +\lstset{style=code} + \begin{document} \lstset{% @@ -30,20 +32,56 @@ style=code, rangebeginprefix=//\ be:\ , rangeendprefix=//\ ee:\ , - includerangemarker=false } \lstset{% numbers=left, stepnumber=1, - firstnumber=10, } \section{Defining a range by keywords} \label{sec:defin-range-keyw} -It's nearly ok, firstnumber=10, but the first line shown is 11. -\lstinputlisting[linerange=isPalindrom-isPalindrom]{./Palindrom.java} +It's nearly ok, \texttt{firstnumber=10}, but the first line number printed is 11, +the value depends on \texttt{includerangemarker}. + +\makeatletter +\def\lst@InitLstNumber{% + \global\c@lstnumber\lst@firstnumber + \global\advance\c@lstnumber\lst@advancenumber + \global\advance\c@lstnumber-\lst@advancelstnum + \ifx \lst@firstnumber\c@lstnumber + \global\advance\c@lstnumber-\lst@advancelstnum + \fi% + \lst@ifincluderangemarker\else% + \global\advance\c@lstnumber by 1% + \fi% + } +\makeatother + +\texttt{includerangemarker=false}: +\lstinputlisting[ firstnumber=10, +includerangemarker=false, +linerange=isPalindrom-isPalindrom]{% + ./Palindrom.java} + +\texttt{includerangemarker=true}: +\lstinputlisting[ firstnumber=10, +includerangemarker=true, +linerange=isPalindrom-isPalindrom]{% + ./Palindrom.java} + +And now with \texttt{firstnumber=auto}: + +\texttt{includerangemarker=false}: +\lstinputlisting[includerangemarker=false, firstnumber=auto, +linerange=isPalindrom-isPalindrom]{% + ./Palindrom.java} + +\texttt{includerangemarker=true}: +\lstinputlisting[includerangemarker=true, firstnumber=auto, +linerange=isPalindrom-isPalindrom]{% + ./Palindrom.java} \section{Testing continuation} @@ -60,6 +98,7 @@ Numbering is continued (firstnumber=last) The listing's numbering should start with 10 (firstnumber=10 globally set by \lstinline|\lstset|): +\lstset{firstnumber=10} \lstinputlisting[linerange=14-16]{./Palindrom.java} Numbering is continued (firstnumber=last) \lstinputlisting[linerange=49-50, firstnumber=last]{./Palindrom.java} @@ -67,24 +106,25 @@ Numbering is continued (firstnumber=last) The continuation of the first listing shows a wrong number (should be 8, is 1; the numbering is wrong even if the continuation follows directly the first part): -\lstinputlisting[linerange=28-35, firstnumber=auto, name=check]{% +\lstinputlisting[linerange=28-35, name=check]{% ./Palindrom.java} -Even if the file names differ, continuation goes wrong: +Even if the file names differ, continuation goes wrong : -First file, first part is ok (firstnumber=auto, name=java): -\lstinputlisting[linerange=24-26, firstnumber=auto, name=java]{./Palindrom.java} +First file, first part is ok (firstnumber=auto globally set, name=java): +\lstset{firstnumber=auto} +\lstinputlisting[linerange=24-26, name=java]{./Palindrom.java} Second file, first part is ok (firstnumber=auto, name=fortran): -\lstinputlisting[linerange=13-16, firstnumber=auto, name=fortran]{./senseless.f08} +\lstinputlisting[linerange=13-16, name=fortran]{./senseless.f08} -First file, second part is wrong (firstnumber=auto, name=java should give -numbers from 4 on): -\lstinputlisting[linerange=29-31, firstnumber=last, name=java]{./Palindrom.java} +First file, second part is wrong (firstnumber=auto globally set above, +name=java should give numbers from 4 on):% +\lstinputlisting[linerange=29-31, name=java]{./Palindrom.java} Second file, second part is wrong (firstnumber=auto, name=fortran should give -numbers from 4 on): -\lstinputlisting[linerange=17-19, firstnumber=last, name=fortran]{./senseless.f08} +numbers from 4 on):% +\lstinputlisting[linerange=17-19, name=fortran]{./senseless.f08} \section{Debugging continuation} \label{sec:debugg-cont} @@ -123,6 +163,69 @@ again: \arabic{lstnumber} + +\section{Consecutive and non-consecutive numbering of (code) lines} +\label{sec:cons-non-cons} + +\lstset{firstnumber=auto,% +includerangemarker=true} + +\begin{filecontents}[overwrite,nosearch,noheader]{print_lines.c} +#include <stdio.h> +#include <stdlib.h> + +int main(int argc, char* argv[]) { + /* declaring variables */ + int i; + int limit; + + /* checking arguments */ + if ( argc > 1 ) { + limit = atoi(argv[1]); + } else { + limit = 100; + } + + /* counting lines */ + for (i = 0; i < limit; i++) { + printf("This is line %3.0d\n", i+1); + } + + return 0; +} +\end{filecontents} + +\begin{filecontents}[overwrite,nosearch,noheader]{print_lines.out} +This is line 1 +This is line 2 +This is line 3 +This is line 4 +This is line 5 +This is line 6 +This is line 7 +\end{filecontents} + +\makeatletter +\def\lst@MSkipToFirst{% + \global\advance\lst@lineno\@ne + \ifnum \lst@lineno=\lst@firstline + \def\lst@next{\lst@LeaveMode \global\lst@newlines\z@ + \lst@OnceAtEOL \global\let\lst@OnceAtEOL\@empty + \lst@InitLstNumber % Added to work with modified \lsthk@PreInit. + \lsthk@InitVarsBOL + %\c@lstnumber=\numexpr-1+\lst@lineno % this enforces the displayed line number + \lst@BOLGobble}% + \expandafter\lst@next + \fi} +\makeatother + +The code: +\lstinputlisting[linerange={6-7, 10-14, 17-19}, language={[ansi]c}]{./print_lines.c} + +The result: +\lstinputlisting[linerange={1-2, 6-7}, language={}]{./print_lines.out} + + \end{document} %%% Local Variables: |