lstdoc.sty 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. %%
  2. %% This is file `lstdoc.sty',
  3. %% generated with the docstrip utility.
  4. %%
  5. %% The original source files were:
  6. %%
  7. %% listings.dtx (with options: `doc')
  8. %%
  9. %% Please read the software license in listings.dtx or listings.dvi.
  10. %%
  11. %% (w)(c) 1996/1997/1998/1999/2000 Carsten Heinz and/or any other author
  12. %% listed elsewhere in this file.
  13. %%
  14. %% This file is distributed under the terms of the LaTeX Project Public
  15. %% License from CTAN archives in directory macros/latex/base/lppl.txt.
  16. %% Either version 1.0 or, at your option, any later version.
  17. %%
  18. %% The listings package is free software.
  19. %%
  20. %% However, if you distribute the package as part of a commercial
  21. %% product or if you use the package to prepare a document and sell the
  22. %% document (books, journals, and so on), I'd like to encourage you to
  23. %% make a donation to the LaTeX3 fund. The size of this `license fee'
  24. %% should depend on the value of the package for your product.
  25. %%
  26. %% If you use the package to typeset a non-commercial document, please
  27. %% send me a copy of the document (.dvi, .ps, .pdf, hardcopy, etc.) to
  28. %% support further development.
  29. %%
  30. %% Permission is granted to change this file. You are not allowed to
  31. %% distribute any changed version of this file, neither under the same
  32. %% name nor under a different one.
  33. %%
  34. %% Send comments and ideas on the package, error reports and additional
  35. %% programming languages to <[email protected]>.
  36. %%
  37. \lst@AddToAtTop{\try@load@fontshape}{\def\space{ }}
  38. \def\lst@BeginRemark#1{%
  39. \begin{quote}\topsep0pt\let\small\footnotesize\small#1:}
  40. \def\lst@EndRemark{\end{quote}}
  41. \newenvironment{TODO}
  42. {\lst@BeginRemark{To do}}{\lst@EndRemark}
  43. \newenvironment{ALTERNATIVE}
  44. {\lst@BeginRemark{Alternative}}{\lst@EndRemark}
  45. \newenvironment{REMOVED}
  46. {\lst@BeginRemark{Removed}}{\lst@EndRemark}
  47. \newenvironment{OLDDEF}
  48. {\lst@BeginRemark{Old definition}}{\lst@EndRemark}
  49. \long\def\m@cro@#1#2#3{\endgroup \topsep\MacroTopsep \trivlist
  50. \edef\saved@macroname{\string#3}%
  51. \def\makelabel##1{\llap{##1}}%
  52. \if@inlabel
  53. \let\@tempa\@empty \count@\macro@cnt
  54. \loop \ifnum\count@>\z@
  55. \edef\@tempa{\@tempa\hbox{\strut}}\advance\count@\m@ne \repeat
  56. \edef\makelabel##1{\llap{\vtop to\baselineskip
  57. {\@tempa\hbox{##1}\vss}}}%
  58. \advance \macro@cnt \@ne
  59. \else \macro@cnt\@ne \fi
  60. \edef\@tempa{\noexpand\item[%
  61. #1%
  62. \noexpand\PrintMacroName
  63. \else
  64. \expandafter\noexpand\csname Print#2Name\endcsname % MODIFIED
  65. \fi
  66. {\string#3}]}%
  67. \@tempa
  68. \global\advance\c@CodelineNo\@ne
  69. #1%
  70. \SpecialMainIndex{#3}\nobreak
  71. \DoNotIndex{#3}%
  72. \else
  73. \csname SpecialMain#2Index\endcsname{#3}\nobreak % MODIFIED
  74. \fi
  75. \global\advance\c@CodelineNo\m@ne
  76. \ignorespaces}
  77. \def\macro{\begingroup
  78. \catcode`\\12
  79. \MakePrivateLetters \m@cro@ \iftrue {Macro}}% MODIFIED
  80. \def\environment{\begingroup
  81. \catcode`\\12
  82. \MakePrivateLetters \m@cro@ \iffalse {Env}}% MODIFIED
  83. \def\newdocenvironment#1#2#3#4{%
  84. \@namedef{#1}{#3\begingroup \catcode`\\12\relax
  85. \MakePrivateLetters \m@cro@ \iffalse {#2}}%
  86. \@namedef{end#1}{#4\endmacro}%
  87. \@ifundefined{Print#2Name}{\expandafter
  88. \let\csname Print#2Name\endcsname\PrintMacroName}{}%
  89. \@ifundefined{SpecialMain#2Index}{\expandafter
  90. \let\csname SpecialMain#2Index\endcsname\SpecialMainIndex}{}}
  91. \newdocenvironment{aspect}{Aspect}{}{}
  92. \def\PrintAspectName#1{}
  93. \def\SpecialMainAspectIndex#1{%
  94. \@bsphack
  95. \index{aspects:\levelchar\protect\aspectname{#1}\encapchar main}%
  96. \@esphack}
  97. \newdocenvironment{lstkey}{Key}{}{}
  98. \def\PrintKeyName#1{\strut\keyname{#1}\ }
  99. \def\SpecialMainKeyIndex#1{%
  100. \@bsphack
  101. \index{keys:\levelchar\protect\keyname{#1}\encapchar main}%
  102. \@esphack}
  103. \newcounter{argcount}
  104. \def\labelargcount{\texttt{\#\arabic{argcount}}\hskip\labelsep$=$}
  105. \def\macroargs{\list\labelargcount
  106. {\usecounter{argcount}\leftmargin=2\leftmargin
  107. \parsep \z@ \@plus\z@ \@minus\z@
  108. \topsep4\p@ \@plus\p@ \@minus2\p@
  109. \itemsep\z@ \@plus\z@ \@minus\z@
  110. \def\makelabel##1{\hss\llap{##1}}}}
  111. \def\endmacroargs{\endlist\@endparenv}
  112. \lst@RequireAspects{writefile}
  113. \newbox\lst@samplebox
  114. \lstnewenvironment{lstsample}[2]
  115. {\lst@TestEOLChar{#1}\global\let\lst@intname\@empty
  116. \gdef\lst@sample{#1}%
  117. \setbox\lst@samplebox=\hbox\bgroup
  118. \setkeys{lst}{language={},style={},tabsize=4,gobble=5,%
  119. basicstyle=\small\ttfamily,basewidth=0.51em}
  120. #2%
  121. \lst@BeginAlsoWriteFile{\jobname.tmp}}
  122. {\lst@EndWriteFile\egroup
  123. \ifdim \wd\lst@samplebox>.5\linewidth
  124. \begin{center}%
  125. \begin{minipage}{0.9\linewidth}%
  126. \hbox to\linewidth{\box\lst@samplebox\hss}%
  127. \end{minipage}%
  128. \end{center}%
  129. \lst@sampleInput
  130. \else
  131. \begin{center}%
  132. \begin{minipage}{0.45\linewidth}\lst@sampleInput\end{minipage}%
  133. \qquad
  134. \begin{minipage}{0.45\linewidth}%
  135. \hbox to\linewidth{\box\lst@samplebox\hss}%
  136. \end{minipage}%
  137. \end{center}%
  138. \fi}
  139. \def\lst@sampleInput{%
  140. \MakePercentComment\catcode`\^^M=10\relax
  141. \small\lst@sample
  142. {\setkeys{lst}{SelectCharTable=\lst@ReplaceInput{\^\^I}%
  143. {\lst@ProcessTabulator}}%
  144. \leavevmode \input{\jobname.tmp}}\MakePercentIgnore}
  145. \def\lstscanlanguages#1#2#3{%
  146. \begingroup
  147. \def\lst@DefDriver@##1##2##3##4[##5]##6{%
  148. \lst@false
  149. \lst@lAddTo\lst@scan{##6(##5),}%
  150. \begingroup
  151. \@ifnextchar[{\lst@XDefDriver{##1}##3}{\lst@DefDriver@@##3}}%
  152. \def\lst@XXDefDriver[##1]{}%
  153. \lst@InputCatcodes
  154. \def\lst@dontinput{#3}%
  155. \let\lst@scan\@empty
  156. \lst@for{#2}\do{%
  157. \lst@IfOneOf##1\relax\lst@dontinput
  158. {}%
  159. {\InputIfFileExists{##1}{}{}}}%
  160. \global\let\@gtempa\lst@scan
  161. \endgroup
  162. \let#1\@gtempa}
  163. \def\lstprintlanguages#1{%
  164. \def\do##1{\setbox\@tempboxa\hbox{##1\space\space}%
  165. \ifdim\wd\@tempboxa<.5\linewidth \wd\@tempboxa.5\linewidth
  166. \else \wd\@tempboxa\linewidth \fi
  167. \box\@tempboxa\allowbreak}%
  168. \begin{quote}
  169. \par\noindent
  170. \hyphenpenalty=\@M \rightskip=\z@\@plus\linewidth\relax
  171. \lst@BubbleSort#1%
  172. \expandafter\lst@NextLanguage#1\relax(\relax),%
  173. \end{quote}}
  174. \def\lst@NextLanguage#1(#2),{%
  175. \ifx\relax#1\else
  176. \def\lst@language{#1}\def\lst@dialects{(#2),}%
  177. \expandafter\lst@NextLanguage@
  178. \fi}
  179. \def\lst@NextLanguage@#1(#2),{%
  180. \def\lst@temp{#1}%
  181. \ifx\lst@temp\lst@language
  182. \lst@lAddTo\lst@dialects{(#2),}%
  183. \expandafter\lst@NextLanguage@
  184. \else
  185. \do{\lst@language
  186. \ifx\lst@dialects\lst@emptydialect\else
  187. \expandafter\lst@NormedDef\expandafter\lst@language
  188. \expandafter{\lst@language}%
  189. \space(%
  190. \lst@BubbleSort\lst@dialects
  191. \expandafter\lst@PrintDialects\lst@dialects(\relax),%
  192. )%
  193. \fi}%
  194. \def\lst@next{\lst@NextLanguage#1(#2),}%
  195. \expandafter\lst@next
  196. \fi}
  197. \def\lst@emptydialect{(),}
  198. \def\lst@PrintDialects(#1),{%
  199. \ifx\@empty#1\@empty empty\else
  200. \lst@PrintDialect{#1}%
  201. \fi
  202. \lst@PrintDialects@}
  203. \def\lst@PrintDialects@(#1),{%
  204. \ifx\relax#1\else
  205. ,\lst@PrintDialect{#1}%
  206. \expandafter\lst@PrintDialects@
  207. \fi}
  208. \def\lst@PrintDialect#1{%
  209. \lst@NormedDef\lst@temp{#1}%
  210. \expandafter\ifx\csname lstdd@\lst@language\endcsname\lst@temp
  211. \texttt{\underbar{#1}}%
  212. \else
  213. \texttt{#1}%
  214. \fi}
  215. \def\lst@IfLE#1#2\@empty#3#4\@empty{%
  216. \ifx #1\relax
  217. \let\lst@next\@firstoftwo
  218. \else \ifx #3\relax
  219. \let\lst@next\@secondoftwo
  220. \else
  221. \lowercase{\ifx#1#3}%
  222. \def\lst@next{\lst@IfLE#2\@empty#4\@empty}%
  223. \else
  224. \lowercase{\ifnum`#1<`#3}\relax
  225. \let\lst@next\@firstoftwo
  226. \else
  227. \let\lst@next\@secondoftwo
  228. \fi
  229. \fi
  230. \fi \fi
  231. \lst@next}
  232. \def\lst@BubbleSort#1{%
  233. \ifx\@empty#1\else
  234. \lst@false
  235. \expandafter\lst@BubbleSort@#1\relax,\relax,%
  236. \expandafter\lst@BubbleSort@\expandafter,\lst@sorted
  237. \relax,\relax,%
  238. \let#1\lst@sorted
  239. \lst@if
  240. \def\lst@next{\lst@BubbleSort#1}%
  241. \expandafter\expandafter\expandafter\lst@next
  242. \fi
  243. \fi}
  244. \def\lst@BubbleSort@#1,#2,{%
  245. \ifx\@empty#1\@empty
  246. \def\lst@sorted{#2,}%
  247. \def\lst@next{\lst@BubbleSort@@}%
  248. \else
  249. \let\lst@sorted\@empty
  250. \def\lst@next{\lst@BubbleSort@@#1,#2,}%
  251. \fi
  252. \lst@next}
  253. \def\lst@BubbleSort@@#1,#2,{%
  254. \ifx\relax#1\else
  255. \ifx\relax#2%
  256. \lst@lAddTo\lst@sorted{#1,}%
  257. \expandafter\expandafter\expandafter\lst@BubbleSort@@@
  258. \else
  259. \lst@IfLE #1\relax\@empty #2\relax\@empty
  260. {\lst@lAddTo\lst@sorted{#1,#2,}}%
  261. {\lst@true \lst@lAddTo\lst@sorted{#2,#1,}}%
  262. \expandafter\expandafter\expandafter\lst@BubbleSort@@
  263. \fi
  264. \fi}
  265. \def\lst@BubbleSort@@@#1\relax,{}
  266. \endinput
  267. %%
  268. %% End of file `lstdoc.sty'.