%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% VERBAUTO.STY
%
% Copyright (c) 1994 by Paul A. Thompson, All Rights Reserved.
% Copy freely as per the GNU Copyleft.
%
% Requires:
%   The New Font Selection Scheme (NFSS) as implemented in LaTeX2e.
%   VERBATIM.STY by Rainer Schoepf
%   VRBINPUT.STY by Bernd Raichle
%   HERE.STY by David Carlisle
%
% VRBAUTO allows you to perform verbatim input of subsections of a file, 
% and then automatically break up the section into pieces of a given
% length, which are output as figures.  These figures are posted using the [H]
% specification, which forces LaTeX to place the figure at the spot of
% invocation, rather than floating the figures to the top of the next page.
% 
% Options for the VERBAUTO specification include:
% o numbering of input lines
% o differential number of lines for the first page
% o specification of the font for the verbatim output
% o specification of the optional line numbering
%
% VERBAUTO is an adaptation of VRBSUBFILE, from Norman Walsh.  
% I fully acknowledge Mr./Dr. Walsh as the impremature of the code ensconced
% herein, but have included other features as indicated above.
%
% Comments and suggestions always welcome.
%   Paul A. Thompson
%   Department of Psychiatry, Data Analysis and Statistics Section
%   Case Western Reserve University
%   Cleveland, OH    44106
%   (216) 844-8946
%   pat@po.cwru.edu
%
% User interface:
%   VautoSubF[#1]#2#3#4#5#6#7#8
%     Input lines #2 to #3 of file #4.  If present, #1 indicates which lines
%     should be numbered.  For example, if #1 is 5, lines 5, 10, 15, etc.
%     will be numbered.  By default, lines are not numbered at all.
%     #5 is number of lines per figure for all but first figure, #6 is
%     figure caption, #7 is figure label and #8 is number of lines on first
%     piece of the figure
%
%  % [number]{start}{end}{filename}{#lines/p}{Caption}{label}{#lines/P1}
%
%   VautoSfFont[#1]#2
%     Use font #2 for verbatim input lines and, if present, use font #1 for
%     line numbers.  By default, #2 is \tt and #1 is \rm\tiny.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\fileversion{v1.0}
\def\filedate{93/03/01}
\typeout{Style-Option: `vrbauto'
   \fileversion \space <\filedate>  (ndw)}
\@ifundefined{verbatim@@@}{\input{verbatim.sty}\input{vrbinput.sty}}{}%
\@ifundefined{@HHfloat}{\input{here.sty}}{}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\newcounter{Vauto@LineNo}%     % current line number
\newcounter{Vauto@LineMod}%    % modulo to print on
\newcounter{Vauto@LineLoop}%   % loop count in line number (1..Mod)
\newcounter{Vauto@LinePage}%   % loop count in line number (1..Mod)
\newcounter{Vauto@LineStart}%  % first line to print
\newcounter{Vauto@LineCount}%  % number of lines to print
\newcounter{Vauto@PrintFlag}%  % print this line?
\newcounter{Vauto@Npage}%      % Number of pages
\newcounter{Vauto@Fignum}%     % Figure number - retain over figures
\newcounter{Vauto@Pagea}%      % # lines page 1
%
%%%% Default verbatim font and verbatim line number font
\def\Vauto@sfFont{\tt}%
\def\Vauto@sfLNF{\rm\tiny}%
%
%%%% Macros to change fonts
\def\Vauto@sbf[#1]#2{%
  \def\Vauto@sfFont{#2}%
  \def\Vauto@sfLNF{#1}%
}
\def\Vauto@svf#1{%
  \def\Vauto@sfFont{#1}%
}%
\def\VautoSfFont{\@ifnextchar[{\Vauto@sbf}{\Vauto@svf}}%
\def\Vauto@etab#1#2#3#4{%  {caption}{cont.}{label}%
  \begingroup \normalsize\fontfamily{\rmdefault}\selectfont%
    \caption{#1 #2}\ifnum#4=1 \label{#3} \fi \endgroup%
  \end{figure}% 
  \setcounter{figure}{\value{Vauto@Fignum}}%
  \begin{figure}[H]%
  \addtocounter{Vauto@Npage}{1}%
  \setcounter{Vauto@LinePage}{0}%
  \setcounter{Vauto@PrintFlag}{1}%
}%
%
%%%% Internal macro that does the work...
\def\Vauto@sf#1#2#3#4#5{\begingroup%
  \def\verbatim@font{\Vauto@sfFont\selectfont}%
  \setcounter{Vauto@Fignum}{\value{figure}}%
  \setcounter{Vauto@LineNo}{0}%
  \setcounter{Vauto@Npage}{1}%
  \setcounter{Vauto@LineLoop}{0}%
  \setcounter{Vauto@LinePage}{0}%
  \parskip=0pt%
  \def\verbatim@processline{%
    \addtocounter{Vauto@LineNo}{1}%
    \addtocounter{Vauto@LineLoop}{1}%
    \addtocounter{Vauto@LinePage}{1}%
    \setcounter{Vauto@PrintFlag}{1}%
    \ifnum\theVauto@LinePage=1 \ifnum\theVauto@Npage=1 \begin{figure}[H]\fi\fi%
    \ifnum\theVauto@LineStart>0%         we haven't reached first line yet...
      \setcounter{Vauto@PrintFlag}{0}%
      \addtocounter{Vauto@LineStart}{-1}%
    \else%
      \ifnum\theVauto@LineCount=0%       we're out of the "printable" region
        \setcounter{Vauto@PrintFlag}{0}%
      \else%
        \addtocounter{Vauto@LineCount}{-1}% decrease the line count
      \fi%
    \fi%
    \ifnum\theVauto@PrintFlag=1%
      \leavevmode%
      \ifnum\theVauto@LineLoop=\theVauto@LineMod%
        \llap{{\Vauto@sfLNF\selectfont \theVauto@LineNo}%
          \ \hskip\@totalleftmargin}%
          \setcounter{Vauto@LineLoop}{0}%
        \else%
          \llap{\phantom{\Vauto@sfLNF\selectfont 0}\ %
              \hskip\@totalleftmargin}%
        \fi%
        \the\verbatim@line\par%
    \else%
      \ifnum\theVauto@LineLoop=\theVauto@LineMod%
         \setcounter{Vauto@LineLoop}{0}%
      \fi%
    \fi%
    \ifnum\theVauto@LinePage=#5%         end of 1st page - may be different 
      \ifnum\theVauto@Npage=1% 
        \Vauto@etab{#3}{}{#4}{1}%
      \fi%
    \fi%
    \ifnum\theVauto@LinePage=#2%
      \Vauto@etab{#3}{(cont.)}{}{0}%
    \fi}%
  \verbatiminput{#1}%
  \endgroup%
}%
%
%%%% Macros to request verbatim subfiles
\def\Vauto@sfPlain#1#2#3#4#5#6#7{%
  \def\verbatim@finish{
    \begingroup \fontfamily{\rmdefault}\selectfont%
    \caption{#5 \ifnum\theVauto@Npage>1 (cont.) \fi}%
    \ifnum\theVauto@Npage=1 \label{#6} \fi \endgroup%
    \end{figure}%
  }%
  \setcounter{Vauto@LineMod}{-1}%
  \setcounter{Vauto@LineStart}{#1}%
  \setcounter{Vauto@LineCount}{#2}%
  \addtocounter{Vauto@LineCount}{-\theVauto@LineStart}%
  \addtocounter{Vauto@LineCount}{1}%
  \addtocounter{Vauto@LineStart}{-1}%
  \Vauto@sf{#3}{#4}{#5}{#6}{#7}%
}%
\def\Vauto@sfNumbered[#1]#2#3#4#5#6#7#8{%
  % [number]{start}{end}{filename}{#lines/p}{Caption}{label}{#lines/P1}
  \def\verbatim@finish{
    \begingroup \fontfamily{\rmdefault}\selectfont%
    \caption{#6 \ifnum\theVauto@Npage>1 (cont.) \fi}%
    \ifnum\theVauto@Npage=1 \label{#7} \fi \endgroup%
    \end{figure}%
  }%
  \setcounter{Vauto@LineMod}{#1}%
  \setcounter{Vauto@LineStart}{#2}%
  \setcounter{Vauto@LineCount}{#3}%
  \addtocounter{Vauto@LineCount}{-\theVauto@LineStart}%
  \addtocounter{Vauto@LineCount}{1}%
  \addtocounter{Vauto@LineStart}{-1}%
  \Vauto@sf{#4}{#5}{#6}{#7}{#8}%
}%
\def\VautoSubF{\@ifnextchar[{\Vauto@sfNumbered}{\Vauto@sfPlain}}%
