%% 
%% This is file `docstrip.tex' generated
%% on <1990/2/24> with the docstrip utility (v1.1g). 
%% 
%% The original source file was `docstrip.doc'.
%% 
%% Copyright (C) 1989,1990 by Frank Mittelbach. All rights reserved. 
%% 
%% IMPORTANT NOTICE: 
%% 
%% You may use this file at your own risk. 
%% On some operating systems it might overwrite existing files. 
%% 
%% 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 different name and then change this copy. 
%% 
%% 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! 
%% 
%% You are NOT ALLOWED to distribute this file alone. You are NOT ALLOWED 
%% to take money to the distribution or use of this file except for some 
%% nominal charge for copying etc. 
%% 
\def\fileversion{v1.1g}
\def\filedate{90/02/24}
\def\docdate {90/02/24}

%% \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{TeX utility: `docstrip'
   \fileversion\space <\filedate> (FMi)}
\typeout{English documentation
 \@spaces\@spaces <\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{}

\let\maybe@message=\@gobble
\def\showprogress{\let\maybe@message\message}

\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{* 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}%
    \typeout{Processing \in@filename\space -> \out@filename}}

\def\check@filename{%
  \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
      \immediate\openin\@outfile \out@filename \relax
      \ifeof \@outfile \@okaytrue
      \else
       \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 \else \@okayfalse \fi
      \fi
      \immediate\closein\@outfile
    \fi
    \immediate\closein\@infile
  \fi
}

\def\write@postamble{%
    \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

\begingroup
\catcode`\%=12
\gdef\double@percent{%% }
\gdef\percent@{%}
\gdef\process@line{\advance\processed@line\@ne
  \@ifnextchar %\check@second
     {\advance\code@line\@ne\put@line}}
\gdef\check@second#1{\@ifnextchar
    %{\advance\meta@comment\@ne\put@line}{\advance
      \normal@comment\@ne\remove@}}
\endgroup

\def\owrite{\maybe@message{.}%
            \immediate\write\@outfile}

\def\put@line#1\@@{\owrite{\in@line}}

\def\remove@#1\@@{\maybe@message{\percent@}}

\def\setup@reading{%
       \immediate\openin\@infile \in@filename \relax
       \@sanitize
       \@makeother\{%
       \@makeother\}%
       \endlinechar\m@ne
       \par@cnt\z@}

\newcount\par@cnt

\def\process@file{%
\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\@@
    \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\processfile#1#2#3#4{%
   \def\main@filename{#1}%
   \def\infileext{#2}%
   \def\outfileext{#3}%
   \set@filenames
   \if #4t\check@filename\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). }
  \owrite{\double@percent }
  \owrite{\double@percent The original source file was `\in@filename'.}
  \owrite{\double@percent }
  \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\preamble{{%
  \let\out@filename\relax
  \let\in@filename\relax
  \@tempswatrue
  \def\@tempa{\end}
  \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). }
     \owrite{\double@percent }
     \owrite{\double@percent The original source file was `\in@filename'.}
     \owrite{\double@percent }}
  \loop
     \read\batch 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}}

\newif\ifmore@files \more@filestrue

\newread\batch

\ifx\undefined\batchfile
  \def\batchfile{docstrip.cmd}
  \@okaytrue
\else \@okayfalse\fi

\openin\batch \batchfile\relax \ifeof\batch
\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
  \@okaytrue
  \loop
  \ifeof\batch \@okayfalse \else
    \read\batch to \batch@line         % get input line
    \batch@line
  \fi
  \if@okay
  \repeat
  \more@filesfalse
 \fi
\fi

  \@whilesw\ifmore@files\fi
    {\ask@questions
     \@for\main@filename:=\filelist \do
       {\set@filenames
        \check@filename
        \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

