Debian Codegraph @

doc/libgraph/lgrind.sty

raw
1 %%
2 %% This is file `lgrind.sty',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% lgrind.dtx (with options: `package')
8 %%
9 %% LGrind is used to format source code of different programming
10 %% languages for LaTeX.
11 %%
12 %% LGrind is a major adaptation of Jerry Leichter's tgrind for LaTeX,
13 %% which was a notable improvement upon Van Jacobsen's tgrind for
14 %% plain TeX, which was adapted from vgrind, a troff prettyprinter.
15 %%
16 %% LGrind contains non-free code written by Van Jacobson, who does not answer
17 %% to any request for changing his licence. This software is therefore not
18 %% maintained. I also do not accept any cheques anymore.
19 %% Based on Van Jacobson's ``tgrindmac'', a macro package for TeX.
20 %% Modified, 1987 by Jerry Leichter. Put '@' in all internal names.
21 %% Modified, 1991 by George Reilly. Changed name from tgrind to lgrind.
22 %% Modified, 1995 by Michael Piefel. Made it work with \LaTeXe.
23 %% -1999 Hundreds of bells and whistles. No changelog here.
24 \NeedsTeXFormat{LaTeX2e}[1996/06/01]
25 \ProvidesPackage{lgrind}
26 [2002/01/28 v3.67 LGrind environment and supporting stuff]
27 %%stopzone % VIM syncing
28 \newcount\lc@unt
29 \newcount\ln@xt
30 \newcount\LGnuminterval
31 \LGnuminterval=10
32 \DeclareOption{nolineno}{\LGnuminterval=50000}
33 \DeclareOption{lineno5}{\LGnuminterval=5}
34 \newif\ifLGleftnum
35 \DeclareOption{leftno}{\LGleftnumtrue}
36 \newskip\LGindent
37 \LGindent=1.6667\parindent
38 \DeclareOption{noindent}{\LGindent=0pt}
39 \newif\ifLGnorules
40 \DeclareOption{norules}{\LGnorulestrue}
41 \newlength{\LGsloppy}
42 \setlength{\LGsloppy}{7.2pt}
43 \DeclareOption{fussy}{\LGsloppy=0pt}
44 \newcommand{\DefaultProc}{\@gobble}
45 \newcommand{\DefaultProcCont}{\@gobble}
46 \DeclareOption{procnames}{
47 \renewcommand{\DefaultProc}[1]{\renewcommand{\Procname}{#1}%
48 \global\setbox\procbox=\hbox{\PNsize #1}}
49 \renewcommand{\DefaultProcCont}[1]{\renewcommand\Procname{#1}
50 \global\setbox\procbox=\hbox{\PNsize\dots #1}}}
51 \newbox\procbox
52 \newcommand{\Procname}{}
53 \newif\ifLGnoprocindex
54 \DeclareOption{noprocindex}{\LGnoprocindextrue}
55 \ProcessOptions
56 \def\BGfont{\sffamily}
57 \def\CMfont{\rmfamily\itshape}
58 \def\NOfont{\sffamily}
59 \def\KWfont{\rmfamily\bfseries}
60 \def\STfont{\ttfamily}
61 \def\TTfont{\ttfamily\upshape}
62 \def\VRfont{\rmfamily}
63 \def\PNsize{\BGfont\small}
64 \def\LGsize{\small}
65 \def\LGfsize{\footnotesize}
66 \newif\ifLGinline
67 \newif\ifLGd@fault
68 \def\LGbegin{\ifLGinline$\hbox\else$$\vbox\fi\bgroup\LGd@faulttrue}
69 \def\LGend{\ifLGd@fault\egroup\ifLGinline$\else$$\fi\LGd@faultfalse\fi}
70 %%stopzone % VIM syncing
71 \newif\ifc@mment
72 \newif\ifstr@ng
73 \newif\ifright@
74 \newbox\ls@far
75 \newbox\tb@x
76 \newdimen\TBw@d
77 \newdimen\@ts
78 {\catcode`\_=\active \gdef\@setunder{\let_=\sp@ce}}
79 \newcommand{\lgrindhead}{}
80 \newcommand{\lgrindfilename}{}\newcommand{\lgrindfilesize}{}
81 \newcommand{\lgrindmodyear}{}\newcommand{\lgrindmodmonth}{}
82 \newcommand{\lgrindmodday}{}\newcommand{\lgrindmodtime}{}
83 \newenvironment{lgrind}[1][1]{%
84 \def\Line##1{\L{\LB{##1}}}%
85 \newcommand{\Head}[1]{\gdef\lgrindhead{##1}}%
86 \newcommand{\File}[6]{\gdef\lgrindfilename{##1}\message{(LGround: ##1)}%
87 \gdef\lgrindmodyear{##2}\gdef\lgrindmodmonth{##3}%
88 \gdef\lgrindmodday{##4}\gdef\lgrindmodtime{##5}%
89 \gdef\lgrindfilesize{##6}}%
90 \let\Proc=\DefaultProc%
91 \let\ProcCont=\DefaultProcCont%
92 \ifLGnoprocindex%
93 \let\index\@gobble%
94 \fi%
95 \hfuzz=\LGsloppy%
96 \def\NewPage{\filbreak\bigskip}%
97 \ifLGinline%
98 \def\L##1{\setbox\ls@far\null{\CF\strut##1}\ignorespaces}%
99 \else%
100 \let\r@ghtlno\relax\let\l@ftlno\relax%
101 \ifnum\LGnuminterval>\z@%
102 \ifLGleftnum%
103 \def\l@ftlno{\ifnum\lc@unt>\ln@xt%
104 \global\advance\ln@xt by\LGnuminterval%
105 \llap{{\normalfont\scriptsize\the\lc@unt\quad}}\fi}%
106 \def\r@ghtlno{\rlap{\enspace\box\procbox}}%
107 \else%
108 \def\r@ghtlno{\ifnum\lc@unt>\ln@xt%
109 \global\advance\ln@xt by\LGnuminterval%
110 \rlap{{\normalfont\scriptsize\enspace\the\lc@unt%
111 \enspace\box\procbox}}%
112 \else\rlap{\enspace\box\procbox}\fi}%
113 \fi%
114 \fi%
115 \def\L##1{\@@par\setbox\ls@far=\null\strut%
116 \global\advance\lc@unt by1%
117 \hbox to \linewidth{\hskip\LGindent\l@ftlno ##1\egroup%
118 \hfil\r@ghtlno}%
119 \ignorespaces}%
120 \fi%
121 \lc@unt=#1\advance\lc@unt by-1%
122 \ln@xt=\LGnuminterval\advance\ln@xt by-1%
123 \loop\ifnum\lc@unt>\ln@xt\advance\ln@xt by\LGnuminterval\repeat%
124 \def\LB{\hbox\bgroup\bgroup\box\ls@far\CF\let\next=}%
125 \def\Tab##1{\egroup\setbox\tb@x=\lastbox\TBw@d=\wd\tb@x%
126 \advance\TBw@d by 1\@ts\ifdim\TBw@d>##1\@ts%
127 \setbox\ls@far=\hbox{\box\ls@far \box\tb@x \sp@ce}\else%
128 \setbox\ls@far=\hbox to ##1\@ts{\box\ls@far \box\tb@x \hfil}\fi\LB}%
129 \ifLGinline\def\sp@ce{{\hskip .3333em}}%
130 \else \setbox\tb@x=\hbox{\texttt{0}}%
131 \@ts=0.8\wd\tb@x \def\sp@ce{{\hskip 1\@ts}}\fi%
132 \catcode`\_=\active \@setunder%
133 \def\CF{\ifc@mment\CMfont\else\ifstr@ng\STfont\fi\fi}%
134 \def\N##1{{\NOfont ##1}\global\futurelet\next\ic@r}%
135 \def\K##1{{\KWfont ##1}\global\futurelet\next\ic@r}%
136 \def\V##1{{\VRfont ##1}\global\futurelet\next\ic@r}%
137 \def\ic@r{\let\@tempa\/\ifx.\next\let\@tempa\relax%
138 \else\ifx,\next\let\@tempa\relax\fi\fi\@tempa}%
139 \def\C{\egroup\bgroup\CMfont \global\c@mmenttrue \global\right@false}%
140 \def\CE{\egroup\bgroup \global\c@mmentfalse}%
141 \def\S{\egroup\bgroup\STfont \global\str@ngtrue}%
142 \def\SE{\egroup\bgroup \global\str@ngfalse}%
143 \def\,{\relax \ifmmode\mskip\thinmuskip \else\thinspace \fi}%
144 \def\!{\relax \ifmmode\mskip-\thinmuskip \else\negthinspace \fi}%
145 %%stopzone % VIM syncing
146 \def\CH##1##2##3{\relax\ifmmode ##1\relax%
147 \else\ifstr@ng ##2\relax\else$##3$\fi\fi }%
148 \def\|{\CH|||}% not necessary for T1
149 \def\<{\CH<<<}% dto.
150 \def\>{\CH>>>}% dto.
151 \def\-{\CH---}% minus sign nicer than hyphen
152 \def\_{\ifstr@ng {\char'137}\else%
153 \leavevmode \kern.06em \vbox{\hrule width.35em}%
154 \ifdim\fontdimen\@ne\font=\z@ \kern.06em \fi\fi }%
155 \def\#{{\STfont\char'043}}%
156 \def\2{\CH\backslash {\char'134}\backslash }% % \
157 \def\3{\ifc@mment\ifright@ ''\global\right@false%
158 \else``\global\right@true \fi%
159 \else{\texttt{\char'042}}\fi}% % "
160 \def\5{{\texttt{\char'136}}}% % ^
161 \parindent\z@\parskip\z@ plus 1pt%
162 \bgroup\BGfont%
163 }
164 {\egroup\@@par} % end of environment lgrind
165 \def\lgrinde{\ifLGinline\else\LGsize\fi\begin{lgrind}}
166 \def\endlgrinde{\end{lgrind}}
167 \def\lagrind{\@ifstar{\@slagrind}{\@lagrind}}
168
169 \def\@lagrind{\@ifnextchar[{\@@lagrind}{\@@lagrind[t]}}
170 \def\@slagrind{\@ifnextchar[{\@@slagrind}{\@@slagrind[t]}}
171 \def\@@lagrind[#1]#2#3#4{%
172 \begin{figure}[#1]
173 \ifLGnorules\else\hrule\fi
174 \vskip .5\baselineskip
175 \begin{minipage}\columnwidth\LGsize\LGindent\z@
176 \begin{lgrind}
177 \input #2\relax
178 \end{lgrind}
179 \end{minipage}
180 \vskip .5\baselineskip plus .5\baselineskip
181 \ifLGnorules\else\hrule\fi\vskip .5\baselineskip
182 \begingroup
183 \setbox\z@=\hbox{#4}%
184 \ifdim\wd\z@>\z@
185 \caption{#3}%
186 \label{#4}%
187 \else
188 \captcont{#3}%
189 \fi
190 \endgroup
191 \vskip 2pt
192 \end{figure}
193 }
194 \def\@@slagrind[#1]#2#3#4{%
195 \begin{figure*}[#1]
196 \ifLGnorules\else\hrule\fi
197 \vskip .5\baselineskip
198 \begin{minipage}\linewidth\LGsize\LGindent\z@
199 \begin{lgrind}
200 \input #2\relax
201 \end{lgrind}
202 \end{minipage}
203 \vskip .5\baselineskip plus .5\baselineskip
204 \ifLGnorules\else\hrule\fi\vskip .5\baselineskip
205 \begingroup
206 \setbox\z@=\hbox{#4}%
207 \ifdim\wd\z@>\z@
208 \caption{#3}%
209 \label{#4}%
210 \else
211 \captcont{#3}%
212 \fi
213 \endgroup
214 \vskip 2pt
215 \end{figure*}
216 }
217 \def\lgrindfile#1{%
218 \par\addvspace{0.1in}
219 \ifLGnorules\else\hrule\fi
220 \vskip .5\baselineskip
221 \begingroup\LGfsize\LGindent\z@
222 \begin{lgrind}
223 \input #1\relax
224 \end{lgrind}
225 \endgroup
226 \vskip .5\baselineskip
227 \ifLGnorules\else\hrule\vspace{0.1in}\fi
228 }
229 \endinput
230 %%
231 %% End of file `lgrind.sty'.