% Produce verbatim listings of various sorts
\def\uncatcodespecials{\def\do##1{\catcode`##1=12 } \dospecials}
\def\setupverbatim{%
    \par \tt \spaceskip=0pt     % Make sure we get fixed tt spacing
    \obeylines\uncatcodespecials\obeyspaces\verbatimdefs
}
% This macro turns on verbatim mode until ?endverbatim is seen.
\def\verbatim{\begingroup \setupverbatim
  \parskip=0pt plus .02\baselineskip \parindent=0pt
   \catcode`\ =13 \catcode`\^^M=13 \catcode`\?=0
   \verbatimgobble}
{\catcode`\^^M=13{\catcode`\ =13\gdef\verbatimdefs{\def^^M{\ \par}\let =\ }}
  \gdef\verbatimgobble#1^^M{}}
% This defines ?endverbatim to end the group which begins with \verbatim
\let\endverbatim=\endgroup
% Input a file in verbatim mode.  Sometimes useful for including
% real-life examples into a paper.
\def\verbfile#1{\begingroup\setupverbatim
    \parskip=0pt plus .02\baselineskip \parindent=0pt
    \input#1 \endgroup
}
% This is the same as the above, but it adds line numbers to each
% line of the file printed.
\newcount\lineno
\newtoks\filename \newtoks\dummy
\newcount\linestart \newcount\linestop
\def\listing#1{\lineno=0\begingroup\setupverbatim
    \parskip=0pt plus .02\baselineskip \parindent=30pt
    \everypar{\advance\lineno by 1 \llap{\the\lineno\quad }}\input#1
    \endgroup
}
%% \endinput
% Like above but the 2nd and 3rd arguments specify line numbers
% for a range for subset listings
\def\sublisting#1#2#3{\lineno=0\begingroup\setupverbatim
    \parskip=0pt plus .02\baselineskip \parindent=30pt
    \everypar{\llap{\the\lineno\quad }}%
\linestart #2 \advance\linestart by -1
\ifnum\linestart<0 \linestart=0 \fi
\linestop  #3 \advance\linestop  by 1
\ifnum\linestop<2 \linestop=2 \fi
% Open the file
    \openin15=#1
    \ifeof15\loop
      \immediate\write16{Could not find file #1}
      \immediate\write16{Please input another filename}
      \closein15 \read16 to\filename
      \openin15=\filename
      \ifeof15 \repeat\fi
      \fi
% Copy some lines
    \loop
      \read15 to\dummy \advance\lineno by 1
      \ifeof15 \linestop=\lineno \fi
      \ifnum\lineno>\linestart
         \ifnum\lineno<\linestop \dummy \fi \fi
      \ifnum\lineno<\linestop \repeat
    \closein15
%
    \endgroup
}
\endinput
