%% 
%% This is file `docstrip.tex' generated
%% on <1990/6/4> with the docstrip utility (v1.1i). 
%% 
%% The original source file was `docstrip.doc'.
%% Included modules: `stats'.
%% 
%% Copyright (C) 1989,1990 by Frank Mittelbach. All rights reserved. 
%% 
%% IMPORTANT NOTICE: 
%% 
%% You may use this file at your own risk. 
%% 
%% If you think this is a bad hack you're right, but it's up to you 
%% to write something better. 
%% 
%% IMPORTANT NOTICE: 
%% 
%% You are not allowed to change this file. You may however copy this file 
%% to a file with a different name and then change the copy. 
%% 
%% You are NOT ALLOWED to distribute this file alone. You are NOT ALLOWED 
%% to take money for the distribution or use of this file (or a changed 
%% version) except for a nominal charge for copying etc. 
%% 
%% You are allowed to distribute this file under the condition that it is 
%% distributed together with all files mentioned in readme.mz1. 
%% 
%% If you receive only some of these files from someone, complain! 
%% 
%% 
%% However, if these files are distributed by established suppliers as part 
%% of a complete TeX distribution, and the structure of the distribution 
%% would make it difficult to distribute the whole set of files, *those 
%% parties* are allowed to distribute only some of the files provided that 
%% it is made clear that the user will get a complete distribution-set upon 
%% request to that supplier (not me). 
%% Notice that this permission is not granted to the end user. 
%% 
%% 
%% 
%% Error Reports in case of UNCHANGED versions to 
%% 
%% F. Mittelbach 
%% Eichenweg 29 
%% D-6500 Mainz 1 
%% Federal Republic of Germany 
%% Bitnet: <PZF5HZ@DRUEDS2> 
%% 

\def\fileversion{v1.1i}
\def\filedate{90/05/24}
\def\docdate {90/03/17}

%% \CheckSum{0}
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%%
\nofiles

\makeatletter


%% correcting a LaTeX bug first...
\def\@xtypein[#1]#2{\typeout{#2}\read\sixt@@n to#1\ifx #1\@defpar
  \def#1{}\else
   \@iden{\expandafter\@strip\expandafter
   #1#1\@gobble\@gobble} \@gobble\fi\@typein}

\typeout{LaTeX utility: `docstrip'
   \fileversion\space <\filedate> (FMi)}
\typeout{English documentation
 \@spaces\@spaces\space\space <\docdate> (FMi)}
\typeout{}
\typeout{**********************************************************}
\typeout{* This program converts documented macro-files into fast *}
\typeout{* loadable files by stripping of (nearly) all comments!
                                                            \space*}
\typeout{**********************************************************}
\typeout{}

\def\test@batchfile{%
  \ifx\undefined\batchfile
    \let\batchfile\default@batchfile
    \@okaytrue \else \@okayfalse \fi
  \openin\batch@stream \batchfile\relax
  \ifeof\batch@stream
    \if@okay \else
      \typeout{*************************************************}
      \typeout{* Could not find your \string\batchfile=\batchfile}
      \typeout{* Try to continue without it}
      \typeout{*************************************************}
    \fi
  \else
    \if@okay
      \typeout{*************************************************}
      \typeout{* Batch file docstrip.cmd found. Use it ? (y/n) *}
      \typein[\answer]
              {*************************************************}
      \def\@tempa{y}%
    \else \let\answer\@tempa \fi
    \ifx\@tempa\answer \process@batchfile \fi
  \fi}

\def\ask@questions{%
   \typeout{}
   \typeout{***************************************************}
   \typeout{* First type the extension of your input file(s): *}
   \typein[\infileext]
           {***************************************************}
   \typeout{}
   \typeout{**************************************************}
   \typeout{* Now type the extension of your output file(s): *}
   \typein[\outfileext]
           {**************************************************}
   \typeout{}
   \typeout{**************************************************}
   \typeout{* Now give the name(s) of module(s) to include: \space *}
   \typein[\includelist]
           {**************************************************}
   \typeout{}
   \typeout{**************************************************}
   \typeout{* Finally give the list of input file(s) without *}
   \typeout{* extension separated by commas if necessary:\@spaces*}
   \typein[\filelist]
           {**************************************************}}

\newif\if@okay
\newread\@infile
\newread\@outfile

\def^^L{ }

\def\set@filenames{%
    \edef\in@filename{\main@filename.\infileext}%
    \edef\out@filename{\main@filename.\outfileext}}

\def\check@filenames{%
  \ifx\infileext\outfilext
    \typeout{}
    \typeout{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
    \typeout{! Not possible to read from and write to the same file !}
    \typeout{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
    \@okayfalse
  \else
    \@okaytrue
    \immediate\openin\@infile \in@filename \relax
    \ifeof \@infile
      \@okayfalse
      \typeout{}
      \typeout{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
      \typeout{! Input file `\in@filename' not found !}
      \typeout{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
    \else
      \check@outfile
    \fi
    \immediate\closein\@infile
  \fi}

\def\check@outfile{%
   \immediate\openin\@outfile \out@filename \relax
   \ifeof \@outfile \@okaytrue
   \else
     \@okayfalse
     \typeout{}
     \typeout{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
     \typeout{! Output file `\out@filename' already exists.}
     \typeout{! Do you want to overwrite it? (yes/no)}
     \typein[\answer]{!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
     \def\@tempa{yes}%
     \ifx\answer\@tempa \@okaytrue \fi
    \fi
    \immediate\closein\@outfile}

\def\write@postamble{%
    \owrite{\string\endinput}%
    \owrite{\double@percent}%
    \owrite{\double@percent End of file `\out@filename'.}%
    \immediate\closeout\@outfile}

  \newcount\numberof@files
  \newcount\meta@comment
  \newcount\normal@comment
  \newcount\code@line
  \newcount\processed@line
  \newcount\summeta@comment
  \newcount\sumnormal@comment
  \newcount\sumcode@line
  \newcount\sumprocessed@line

\def\process@line{%
  \advance\processed@line\@ne
    \futurelet\next\process@@line}

\begingroup
\catcode`\*=12
\lccode`\*=`\%
\lowercase{%
\gdef\double@percent{** }
\gdef\percent@{*}
\gdef\process@@line{%
    \if*\next
      \expandafter\check@second
    \else
  \advance\code@line\@ne
  \endlast@module
           \expandafter\put@line
    \fi}
\gdef\check@@second{%
  \if*\next
 \advance\meta@comment\@ne
          \let\next\put@line
 \endlast@module
   \else
    \if<\next
      \let\next\check@module
    \else
 \advance\normal@comment\@ne
 \endlast@module
      \let\next\remove@line
    \fi
  \fi
  \next}
}

\endgroup

\gdef\check@second#1{\futurelet\next\check@@second}

\def\check@module<{\futurelet\next\check@@module}

\def\check@@module{%
    \if+\next
       \let\next\plus@module
    \else
      \if-\next
        \let\next\minus@module
      \else
 \advance\normal@comment\@ne
 \endlast@module
          \let\next\remove@line
      \fi
    \fi
    \next}

\def\module@included#1#2{%
   \ifin@module
     \def\@tempa{#1#2}%
     \ifx\@tempa\curr@module \else
     \maybe@message{>}\in@modulefalse \module@included#1{#2}\fi
   \else
     \in@moduletrue
     \def\curr@module{#1#2}%
     \maybe@message{<#1#2}%
      \inclcurr@modulefalse
      \@for\@tempa:=#2\do
      {\edef\@tempb{\noexpand\in@{\@tempa,}{\includelist,}}%
      \@tempb \ifin@ \inclcurr@moduletrue \fi}%
    \fi
}

 \def\endlast@module{%
   \ifin@module
     \maybe@message{>}\in@modulefalse \fi}

 \newif\ifin@module
\newif\ifinclcurr@module

\def\plus@module+#1>{%
  \module@included+{#1}%
  \ifinclcurr@module
 \advance\code@line\@ne
          \expandafter\put@module
  \else
 \advance\normal@comment\@ne
          \expandafter\remove@line
  \fi}

\def\minus@module-#1>{%
  \module@included-{#1}%
  \ifinclcurr@module
 \advance\normal@comment\@ne
          \expandafter\remove@line
  \else
 \advance\code@line\@ne
          \expandafter\put@module
  \fi}

\def\in@#1#2{%
  \def\in@@##1#1##2##3\in@@{%
    \ifx\in@##2\in@false\else\in@true\fi}%
  \in@@#2#1\in@\in@@}

\newif\ifin@

\def\include#1{\def\includelist{#1}}

\include{}

\def\owrite{%
 \maybe@message{.}%
  \immediate\write\@outfile}

\let\end@inline\relax

\def\put@module#1\end@inline{\owrite{#1}}

\def\put@line#1\end@inline{\owrite{\in@line}}

\def\remove@line#1\end@inline{%
 \maybe@message{\percent@}%
}

\def\setup@reading{%
       \immediate\openin\@infile \in@filename \relax
       \@sanitize
       \@makeother\{%
       \@makeother\}%
       \endlinechar\m@ne
       \par@cnt\z@}

{\@makeother\ \global\let\@sptoken= }
\def\@xifnch#1{\futurelet\@tempc\@ifnch}

\newcount\par@cnt

\def\process@file{%
\typeout{}%
\typeout{Processing \in@filename\space
         \ifx\includelist\@empty \else
           (\includelist) \fi
         -> \out@filename}%
\typeout{}%
\begingroup
  \setup@reading
  \loop
    \read\@infile to\in@line
    \ifx\@empty\in@line
      \advance\par@cnt\@ne
    \else
      \par@cnt\z@
    \fi
    \ifnum \par@cnt<2
      \expandafter\process@line\in@line\end@inline
    \else
  \maybe@message{/}%
    \fi
  \ifeof\@infile \@tempswafalse \else \@tempswatrue \fi
  \if@tempswa
  \repeat
  \immediate\closein\@infile
    \typeout{Lines \space processed: \the\processed@line}
    \typeout{Comments removed: \the\normal@comment}
    \typeout{Comments \space passed: \the\meta@comment}
    \typeout{Codelines passed: \the\code@line}
    \global\advance\sumprocessed@line\processed@line
    \global\advance\sumnormal@comment\normal@comment
    \global\advance\summeta@comment\meta@comment
    \global\advance\sumcode@line\code@line
    \global\advance\numberof@files\@ne
 \endgroup}

\def\generatefile#1#2#3{%
 \def\out@filename{#1}%
 \typeout{}%
 \typeout{Generating \out@filename:}%
 \typeout{}%
 \if#2t\check@outfile\else\@okaytrue\fi
 \if@okay
   \def\from##1##2{\owrite{\double@percent ##1
                   \if!##2!\else \space
                    (with modules: `##2')\fi}}%
   \edef\reference@lines{\owrite{\double@percent }%
       \owrite{\double@percent The original source files were:}%
       \owrite{\double@percent }%
       #3}%
    \def\from##1##2{\def\in@filename{##1}%
                    \def\includelist{##2}%
                    \process@file}%
    \write@preamble#3\write@postamble
    \let\reference@lines\original@refs
 \fi}

\def\processfile#1#2#3#4{%
   \def\main@filename{#1}%
   \def\infileext{#2}%
   \def\outfileext{#3}%
   \set@filenames
   \if #4t\check@filenames\fi
   \if@okay
     \write@preamble
     \process@file
     \write@postamble
   \else \@okaytrue \fi}

\def\write@preamble{%
  \immediate\openout\@outfile \out@filename \relax
  \owrite{\double@percent This is file `\out@filename' generated}%
  \owrite{\double@percent on <\the\year/\the\month/\the\day> with
                          the docstrip utility (\fileversion). }%
  \reference@lines
  \owrite{\double@percent IMPORTANT NOTICE:}%
  \owrite{\double@percent You are not allowed to distribute this file.}%
  \owrite{\double@percent For distribution of the original source see }%
  \owrite{\double@percent the copyright notice in the file `\in@filename'. }%
  \owrite{\double@percent }}

\def\original@refs{%
  \owrite{\double@percent }%
  \owrite{\double@percent The original source file was `\in@filename'.}%
  \ifx\includelist\@empty\else
    \owrite{\double@percent Included modules: `\includelist'.}\fi
  \owrite{\double@percent }}

\let\reference@lines\original@refs

\def\default@batchfile{docstrip.cmd}


\let\showprogress\relax
\let\keepsilent  \relax
  \def\showprogress{\let\maybe@message\message}
  \def\keepsilent{\let\maybe@message\@gobble}

\def\preamble{\begingroup
  \let\reference@lines\relax
  \let\out@filename\relax
  \let\in@filename\relax
  \@tempswatrue
  \def\@tempa{\endpreamble}%
  \def\@tempb{\par}%
  \gdef\write@preamble{%
     \immediate\openout\@outfile \out@filename \relax
     \owrite{\double@percent }%
     \owrite{\double@percent This is file `\out@filename' generated}%
     \owrite{\double@percent on <\the\year/\the\month/\the\day> with
                             the docstrip utility (\fileversion). }%
     \reference@lines}%
  \loop
     \read\batch@stream to \batch@line   % get stuff for preamble
     \ifx\batch@line\@tempa \@tempswafalse \else
        \xdef\write@preamble{\write@preamble\owrite
               {\double@percent
                \ifx\batch@line\@tempb\else\batch@line\fi}}\fi
  \if@tempswa
  \repeat\endgroup}

\newif\ifmore@files \more@filestrue

\newread\batch@stream

\def\process@batchfile{%
  \@okaytrue
  \let\endinput\@okayfalse
  \loop
  \ifeof\batch@stream \@okayfalse \else
    \read\batch@stream to \batch@line         % get input line
    \batch@line
  \fi
  \if@okay
  \repeat
  \more@filesfalse}


 \showprogress

\test@batchfile

  \@whilesw\ifmore@files\fi
    {\ask@questions
     \@for\main@filename:=\filelist \do
       {\set@filenames
        \check@filenames
        \if@okay
           \write@preamble
           \process@file
           \write@postamble
        \fi}%
     \typein[\answer]{More files to process? (yes/no)}
     \def\@tempa{yes}%
     \ifx\answer\@tempa \else \more@filesfalse \fi}

  \typeout{}
    \typeout{Overall statistics:}
    \typeout{Files \space processed: \the\numberof@files}
    \typeout{Lines \space processed: \the\sumprocessed@line}
    \typeout{Comments removed: \the\sumnormal@comment}
    \typeout{Comments \space passed: \the\summeta@comment}
    \typeout{Codelines passed: \the\sumcode@line}

\@@end


\endinput
%% 
%% End of file `docstrip.tex'.
