zip the unpacked directory below distrib
[latex2e.git] / base / docstrip.dtx
blob81f6cdba5136227a6f988c2ef5cf8a63ba9519b0
1 % \iffalse meta-comment
3 % Copyright 1993-2014
4 % The LaTeX3 Project and any individual authors listed elsewhere
5 % in this file. 
6
7 % This file is part of the LaTeX base system.
8 % -------------------------------------------
9
10 % It may be distributed and/or modified under the
11 % conditions of the LaTeX Project Public License, either version 1.3c
12 % of this license or (at your option) any later version.
13 % The latest version of this license is in
14 %    http://www.latex-project.org/lppl.txt
15 % and version 1.3c or later is part of all distributions of LaTeX 
16 % version 2005/12/01 or later.
17
18 % This file has the LPPL maintenance status "maintained".
19
20 % The list of all files belonging to the LaTeX base distribution is
21 % given in the file `manifest.txt'. See also `legal.txt' for additional
22 % information.
23
24 % The list of derived (unpacked) files belonging to the distribution 
25 % and covered by LPPL is defined by the unpacking scripts (with 
26 % extension .ins) which are part of the distribution.
27
28 % \fi
29 \catcode`\{=1
30 \catcode`\}=2
31 \def\filename{docstrip.dtx}
32 \def\fileversion{2.5d}
33 \def\filedate{2005/07/29}
34 \def\docdate {2014/04/19}
35 % \CheckSum{2439}
36 %% \CharacterTable
37 %%  {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
38 %%   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
39 %%   Digits        \0\1\2\3\4\5\6\7\8\9
40 %%   Exclamation   \!     Double quote  \"     Hash (number) \#
41 %%   Dollar        \$     Percent       \%     Ampersand     \&
42 %%   Acute accent  \'     Left paren    \(     Right paren   \)
43 %%   Asterisk      \*     Plus          \+     Comma         \,
44 %%   Minus         \-     Point         \.     Solidus       \/
45 %%   Colon         \:     Semicolon     \;     Less than     \<
46 %%   Equals        \=     Greater than  \>     Question mark \?
47 %%   Commercial at \@     Left bracket  \[     Backslash     \\
48 %%   Right bracket \]     Circumflex    \^     Underscore    \_
49 %%   Grave accent  \`     Left brace    \{     Vertical bar  \|
50 %%   Right brace   \}     Tilde         \~}
53 %\iffalse
55 %% The docstrip program for use with TeX.
56 %% Copyright (C) 1989-1991 Frank Mittelbach
57 %% Copyright (C) 1992-1995 Johannes Braams, Denys Duchier, 
58 %%                         Frank Mittelbach
59 %% Copyright (C) 1995 Marcin Woli\'nski
60 %% Copyright (C) 1996-1997 Mark Wooding, Marcin Woli\'nski
61 %% Copyright (C) 1998-2003 LaTeX3 project and the above authors
62 %% All rights are reserved.
65 % \fi
67 % \changes{2.0b}{1991/05/29}{Added bugfix from Denys}
68 % \changes{2.0c}{1991/05/29}{Allow almost all characters in guard (DD)}
69 % \changes{2.0d}{1991/05/31}{Started merging in some of Franks code}
70 % \changes{2.0j}{1992/03/05}{Wrote introduction}
71 % \changes{2.0m}{1992/04/21}{Renamed all macros that deal with the
72 %                           parsing of boolean expressions}
73 % \changes{2.0m}{1992/04/25}{Removed dependency from ltugboat,
74 %                          incorporated driver file into source.}
75 % \changes{2.0m}{1992/04/25}{Added some missing percents; corrected some
76 %                          typos}
77 % \changes{2.0m-DL}{1992/05/08}{Various small corrections to English and
78 %                           typos}
79 % \changes{2.0q}{1992/07/01}{Changed all dates to yy/mm/dd for better
80 %                          sorting}
81 % \changes{2.2a}{1993/12/02}{Update for LaTeX2e}
82 % \changes{2.2c}{1993/12/17}{Renamed texsys.tex to texsys.cfg.}
83 % \changes{2.3a}{1995/08/17}{Swapped Primary with Secondary since
84 %                         expressions are generally described bottom-up}
85 % \changes{2.3b}{1995/08/22}{Completely changed expressions parser}
86 % \changes{2.3b}{1995/08/23}{Removed mechanism for checking if  previous
87 %                    one-line guard is same as current (\cs{testOption},
88 %                    \cs{closeOption})---this is not a common
89 %                    case and testing complicates things unnecessarily}
90 % \changes{2.3c}{1995/08/24}{When file is multiply listed in \cs{file}
91 %                         clause it \emph{is} multiply read}
92 % \changes{2.3c}{1995/09/04}{Changed   some   dirty  tricks  to  be
93 %                         less/more dirty---all uses of \cs{afterfi}}
94 % \changes{2.3e}{1995/09/25}{Directories support}
95 % \changes{2.3e}{1995/10/24}{added \cs{makepathname} to support
96 %                         systems with bizzare pathnames}
97 % \changes{2.3e}{1995/10/25}{batch files work by \cs{input}}
98 % \changes{2.3e}{1996/10/02}{Introduced ``open lists''}
99 % \changes{2.4a}{1996/06/06}{Add stream limits (MDW)}
100 % \changes{2.4c}{1996/06/11}{Add initex support (DPC)}
102 % \DoNotIndex{\#,\$,\%,\&,\@,\\,\{,\},\^,\_,\~,\ }
103 % \DoNotIndex{\@ne}
104 % \DoNotIndex{\advance,\begingroup,\catcode,\closein,\closeout}
105 % \DoNotIndex{\day,\def,\edef,\else,\empty,\endgroup,\errmessage}
106 % \DoNotIndex{\expandafter,\fi,\futurelet,\gdef,\global,\if,\ifeof}
107 % \DoNotIndex{\ifx,\immediate,\let,\loop,\m@ne,\message,\month}
108 % \DoNotIndex{\newcount}
109 % \DoNotIndex{\newif,\newlinechar,\newread,\newtoks,\newwrite}
110 % \DoNotIndex{\noexpand,\openin,\openout,\par,\read,\relax,\repeat}
111 % \DoNotIndex{\space,\the,\undefined,\write,\xdef,\year,\z@}
113 % ^^A some definitions for this documentation
115 % \newcommand{\ds}{\textsf{DocStrip}} ^^A maybe?
116 % \newcommand{\bsl}{\protect\bslash}
117 % \newcommand{\note}[1]{\marginpar{\textbf{#1}}}
118 % \newcommand{\netaddress}[1]{\texttt{#1}}
120 % ^^A override the default in doc.sty
121 % \makeatletter
122 % \renewenvironment{theglossary}{%
123 %    \glossary@prologue%
124 %    \GlossaryParms \let\item\@idxitem \ignorespaces}%
125 %   {}
126 % \makeatother
129 % \changes{2.1c}{1993/02/25}{Added a setting for StandardModuleDepth}
130 % \setcounter{StandardModuleDepth}{1}
132 % \title{The \ds{} program%
133 %         \thanks{This file has version number \fileversion,
134 %                 last revised \filedate,
135 %                 documentation dated \docdate.}}
137 % \changes{2.1b}{1993/02/23}{modified mailaddress of Johannes}
138 % \changes{2.4i}{1998/01/18}{removed mail addresses as it is hopeless
139 %                            to keep them uptodate}
140 % \author{%
141 %   Frank Mittelbach
142 %  \and
143 %   Denys Duchier
144 %  \and
145 %   Johannes Braams 
146 %  \and
147 %   Marcin Woli\'nski 
148 %  \and
149 %   Mark Wooding 
150 % }
152 % \date{Printed \today}
154 % \maketitle
156 % \begin{abstract}
157 %    This document describes the implementation of the \ds{} program.
158 %    The original version of this program was developed by Frank
159 %    Mittelbach to accompany his \texttt{doc.sty} which enables literate
160 %    programming in \LaTeX\@. Denys Duchier rewrote it to run either
161 %    with \TeX\ or with \LaTeX, and to allow full boolean expressions in
162 %    conditional guards instead of just comma-separated lists.
163 %    Johannes Braams re-united the two implementations, documented and
164 %    debugged the code.
166 %    In September 1995 Marcin Woli\'nski changed many parts of the
167 %    program to make use of \TeX's ability to write to multiple files
168 %    at the same time to avoid re-reading sources.  The performance
169 %    improvement of version~2.3 came at a price of compatibility with
170 %    some more obscure operating systems which limit the number of
171 %    files a process can keep open. This was corrected in September
172 %    1996 by Mark Wooding and his changes were ``creatively merged''
173 %    by Marcin Woli\'nski who made at the same time changes in batch
174 %    files processing, handling of preambles and introduced ``verbatim
175 %    mode''. After all that, David Carlisle merged the new version into
176 %    the \LaTeX\ sources, and made a few other changes, principally
177 %    making \ds{} work under initex, and removing the need for
178 %    batch files to say \verb|\def\batchfile{...}|.
179 % \end{abstract}
181 % \section{Introduction}
183 % \subsection{Why the \ds{} program?} When Frank Mittelbach created
184 %    the \texttt{doc} package, he invented a way to combine \TeX\ code
185 %    and its documentation. From then on it was more or less possible
186 %    to do literate programming in \TeX.
188 %    This way of writing \TeX\ programs obviously has great
189 %    advantages, especially when the program becomes larger than a
190 %    couple of macros.  There is one drawback however, and that is
191 %    that such programs may take longer than expected to run because
192 %    \TeX\ is an interpreter and has to decide for each line of the
193 %    program file what it has to do with it. Therefore, \TeX\ programs
194 %    may be speeded up by removing all comments from them.
196 %    By removing the comments from a \TeX\ program a new problem is
197 %    introduced. We now have two versions of the program and both of
198 %    them {\em have\/} to be maintained. Therefore it would be nice to
199 %    have a possibility to remove the comments automatically, instead
200 %    of doing it by hand. So we need a program to remove comments from
201 %    \TeX\ programs. This could be programmed in any high level
202 %    language, but maybe not everybody has the right compiler to
203 %    compile the program.  Everybody who wants to remove comments from
204 %    \TeX\ programs has \TeX\@.  Therefore the \ds{} program is
205 %    implemented entirely in \TeX.
207 % \subsection{Functions of the \ds{} program} 
209 %    Having created the \ds{} program to remove comment lines from
210 %    \TeX\ programs\footnote{Note that only comment lines, that is
211 %    lines that start with a single \texttt{\%} character, are removed;
212 %    all other comments stay in the code.} it became feasible to do more
213 %    than just strip comments.\\ Wouldn't it be nice to have a way to
214 %    include parts of the code only when some condition is set true?
215 %    Wouldn't it be as nice to have the possibility to split the
216 %    source of a \TeX\ program into several smaller files and combine
217 %    them later into one `executable'?\\ Both these wishes have been
218 %    implemented in the \ds{} program.
220 % \section{How to use the \ds{} program}
221 %    A number of ways exist to use the \ds{} program:
222 %    \begin{enumerate}
223 % \item The usual way to use \ds{} is to write a \emph{batch file}
224 %        in such a way that it can be directly processed by \TeX{}.
225 %       The batch file should contain the commands described below for
226 %       controlling the \ds{} program.
227 %    This allows you to set up a distribution where you can instruct
228 %        the user to simply run
229 %      \begin{quote}
230 %        \texttt{TEX} \meta{batch file}
231 %      \end{quote}
232 %        to generate the executable versions of your files from the
233 %        distribution sources.
234 %        Most of the \LaTeX\  distribution is packaged this way.
235 %        To produce such a batch file include a statement in your 
236 %         `batch file' that
237 %        instructs \TeX\ to read \texttt{docstrip.tex}. 
238 %        The beginning of such a file would look like:
239 %\begin{verbatim}
240 %    \input docstrip
241 %    ...
242 %\end{verbatim}
243 %    By convention the batch file should have extension |.ins|. But
244 %    these days \ds{} in fact work with any extension.
246 %    \item Alternatively you can instruct \TeX\ to read the file
247 %        \texttt{docstrip.tex} and to see what happens. \TeX\ will ask
248 %        you a few questions about the file you would like to be
249 %        processed. When you have answered these questions it does
250 %        its job and strips the comments from your \TeX\ code.
251 %    \end{enumerate}
253 % \section{Configuring \ds}
254 % \subsection{Selecting output directories}
255 % \changes{2.3e}{1996/09/19}{Added documentation}
256 %    Inspired by a desire to simplify reinstallations of \LaTeXe{} and
257 %    to support operating systems which have an upper limit on the
258 %    number of files allowed in a directory, \ds\ now allows
259 %    installation scripts to specify output directories for files it
260 %    creates. We suggest using TDS (\TeX\ directory structure) names
261 %    of directories relative to \texttt{texmf} here. However these
262 %    names should be thought of as a labels rather than actual names
263 %    of directories. They get translated to actual system-dependent
264 %    pathnames according to commands contained in a configuration file
265 %    named \texttt{docstrip.cfg}.
267 %    The configuration file is read by \ds{} just before it starts to
268 %    process any batch file commands.
270 %    If this file is not present \ds{} uses some default settings which
271 %    ensure that files are only written to the current directory.
272 %    However by use of this configuration file, a site maintainer can
273 %    `enable' features of \ds{} that allow files to be written to
274 %    alternative directories.
276 % \DescribeMacro{\usedir}
277 %    Using this macro package author can tell where a file should be
278 %    installed. All |\file|s generated in the scope of that
279 %    declaration are written to a directory specified by its one
280 %    argument. For example in \LaTeXe{} installation following
281 %    declarations are used:
282 %\begin{verbatim}
283 %    \usedir{tex/latex/base}
284 %    \usedir{makeindex}
285 %\end{verbatim}
286 %    And standard packages use
287 %\begin{verbatim}
288 %    \usedir{tex/latex/tools}
289 %    \usedir{tex/latex/babel} 
290 %\end{verbatim}
291 %    etc.
293 % \DescribeMacro{\showdirectory}
294 %    Used to display directory names in messages. If some label is not
295 %    defined it expands to |UNDEFINED (label is ...)| otherwise to a
296 %    directory name. It is probably a good idea for every installation
297 %    script to display at startup list of all directories that would
298 %    be used and asking user to confirm that.
300 %    The above macros are used by package/installation script
301 %    author. The following macros are used in a configuration file,
302 %    |docstrip.cfg|, by a system administrator to
303 %    describe her/his local directory structure.
305 % \DescribeMacro{\BaseDirectory} This macro is administrator's way of
306 %    saying ``yes, I want to use that directories support of
307 %    yours''. \ds{} will write only to current directory unless your
308 %    config has a call to this macro. (This means \ds{} won't write to
309 %    random directories unless you tell it to, which is nice.) Using
310 %    this macro you can specify a base directory for \TeX-related
311 %    stuff. E.g., for many Unix systems that would be
312 %\begin{verbatim}
313 %    \BaseDirectory{/usr/local/lib/texmf}
314 %\end{verbatim}
315 %    and for standard em\TeX{} installation 
316 %\begin{verbatim}
317 %    \BaseDirectory{c:/emtex}
318 %\end{verbatim}
320 % \DescribeMacro{\DeclareDir} 
321 %    Having specified the base directory you should tell \ds{} how to
322 %    interpret labels used in |\usedir| commands. This is done with
323 %    |\DeclareDir| with two arguments. The first is the label and the
324 %    second is actual name of directory relative to base
325 %    directory. For example to teach \ds{} using standard em\TeX{}
326 %    directories one would say:
327 %\begin{verbatim}
328 %    \BaseDirectory{c:/emtex}
329 %    \DeclareDir{tex/latex/base}{texinput/latex2e}
330 %    \DeclareDir{tex/latex/tools}{texinput/tools}
331 %    \DeclareDir{makeindex}{idxstyle}
332 %\end{verbatim}
333 %    This will cause base latex files and font descriptions to be
334 %    written to directory |c:\emtex\texinput\latex2e|, files of
335 %    \texttt{tools} package to |c:\emtex\texinput\tools| and makeindex
336 %    files to |c:\emtex\idxstyle|.
338 %    Sometimes it is desirable to put some files outside of the base
339 %    directory. For that reason |\DeclareDir| has a star form
340 %    specifying absolute pathname. For example one could say
341 %\begin{verbatim}
342 %    \DeclareDir*{makeindex}{d:/tools/texindex/styles}
343 %\end{verbatim}
345 %    \DescribeMacro{\UseTDS}
346 %    Users of systems conforming to TDS may well ask here ``do I
347 %    really need to put a dozen of lines like
348 %\begin{verbatim}
349 %    \DeclareDir{tex/latex/base}{tex/latex/base}
350 %\end{verbatim}
351 %    in my config file''. The answer is |\UseTDS|. This macro causes
352 %    \ds{} to use labels themselves for any directory you haven't
353 %    overriden with |\DeclareDir|. The default behaviour is to raise
354 %    an error on undefined labels because some users may want to know
355 %    exactly where files go and not to allow \ds{} to write to random
356 %    places. However I (MW) think this is pretty cool and my
357 %    config says just (I'm running te\TeX{} under Linux)
358 %\begin{verbatim}
359 %    \BaseDirectory{/usr/local/teTeX/texmf}
360 %    \UseTDS
361 %\end{verbatim}
363 %    The important thing to note here is that it is impossible to create
364 %    a new directory from inside \TeX{}. So however you configure
365 %    \ds, you need to create all needed directories before running
366 %    the installation.  Authors may want to begin
367 %    every installation script by displaying a list of directories
368 %    that will be used and asking user if he's sure all of them
369 %    exist.
371 %    Since file name syntax is OS specific \ds{} tries to guess it
372 %    from the current directory syntax. It should succeed for Unix,
373 %    MSDOS, Macintosh and VMS. However \ds{} will only initially
374 %    know the current directory syntax if it is used with \LaTeX.
375 %    If used with plain\TeX\ or initex it will not have this
376 %    information\footnote{Except when processing the main
377 %    \texttt{unpack.ins} batch file for the \LaTeX\ distribution, which
378 %    takes special measures so that initex can learn the directory
379 %    syntax.}.
380 %    If you often use \ds{} with formats other than \LaTeX\ you should
381 %    \emph{start} the file |docstrip.cfg| with a definition of
382 %    |\WriteToDir|.  E.g.,
383 %   |\def\WriteToDir{./}| on MSDOS/Unix,
384 %   |\def\WriteToDir{:}| on Macintosh,
385 %   |\def\WriteToDir{[]}| on VMS.
386 %  
387 %    If your system requires something
388 %    completely different you can define in |docstrip.cfg| macros
389 %    |\dirsep| and |\makepathname|. Check for their definition in the
390 %    implementation part. If you want some substantially different
391 %    scheme of translating |\usedir| labels into directory names try
392 %    redefining macro |\usedir|. 
394 % \subsection{Setting maximum numbers of streams}
396 % \DescribeMacro{\maxfiles}
397 %    In support of some of the more obscure operating systems, there's
398 %    a limit on the number of files a program can have open.  This can
399 %    be expressed to \ds\ through the |\maxfiles| macro.  If the number
400 %    of streams \ds\ is allowed to open is $n$, your configuration file
401 %    can say |\maxfiles{|$n$|}|, and \ds\ won't try to open more files
402 %    than this.  Note that this limit won't include files which are
403 %    already open.  There'll usually be two of these: the installation
404 %    script which you started, and the file |docstrip.tex| which it
405 %    included; you must bear these in mind yourself.  \ds\ assumes
406 %    that it can open at least four files before it hits some kind of
407 %    maximum: if this isn't the case, you have real problems.
409 % \DescribeMacro{\maxoutfiles}
410 %    Maybe instead of having a limit on the number of files \TeX\ can
411 %    have open, there's a limit on the number of files it can write
412 %    to (e.g., \TeX\ itself imposes a limit of 16~files being written
413 %    at a time).  This can be expressed by saying |\maxoutfiles{|$m$|}|
414 %    in a configuration file.  You must be able to have at least one
415 %    output file open at a time; otherwise \ds\ can't do anything at
416 %    all.
418 %    Both these options would typically be put in the |docstrip.cfg|
419 %    file.
422 % \section{The user interface}
424 % \subsection{The main program}
425 % \DescribeMacro{\processbatchFile} The `main program' starts with
426 %    trying to process a batch file, this is accomplished by calling
427 %    the macro |\processbatchFile|. It counts the number of batch
428 %    files it processes, so that when the number of files processed is
429 %    still zero after the call to |\processbatchFile| appropriate
430 %    action can be taken.
432 % \DescribeMacro{\interactive} When no batch files have been processed
433 %    the macro |\interactive| is called. It prompts the user for
434 %    information. First the extensions of the input and output files
435 %    is determined. Then a question about optional code is asked and
436 %    finally the user can give a list of files that have to be
437 %    processed.
439 % \DescribeMacro{\ReportTotals} When the \texttt{stats} option is
440 %    included in the \ds{}-program it keeps a record of the number of
441 %    files and lines that are processed.  Also the number of comments
442 %    removed and passed as well as the number of code lines that were
443 %    passed to the output are accounted. The macro |\ReportTotals|
444 %    shows a summary of this information.
446 % \subsection{Batchfile commands}
448 %    The commands described in this section are available to build a
449 %    batch file for \TeX.
451 % \DescribeMacro{\input}
452 % All \ds{} batch files should start with the line: |\input docstrip| 
454 % Do not use the  \LaTeX\ syntax |\input{docstrip}| as batch files may
455 % be used with plain~\TeX\ or ini\TeX.
456 % You may that old batch files always have a line
457 % |\def\batchfile{|\meta{filename}|}|
458 % just before the input.
459 % Such usage is still supported but is now discouraged, as it causes
460 % \TeX\ to re-input the same file, using up one of its limited number
461 % of input streams.
463 % \DescribeMacro{\endbatchfile}
464 % All batch files should end with this command. Any lines after this
465 % in the file are ignored. In old files that start
466 % |\def\batchfile{|\ldots\ this command is optional, but is a good
467 % idea anyway. If this command is omitted from a batchfile then
468 % normally \TeX\ will go to its interactive |*| prompt, so you may 
469 % stop \ds{} by typing |\endbatchfile| to this prompt.
471 % \DescribeMacro{\generate}
472 % \DescribeMacro{\file}
473 % \DescribeMacro{\from}
474 %    The main reason for constructing a \ds{} command file is to
475 %    describe what files should be generated, from what sources and
476 %    what optional (`guarded') pieces of code should be included. The
477 %    macro |\generate| is used to give \TeX\ this information. Its
478 %    syntax is:
479 %    \begin{quote}
480 %    |\generate{|[|\file{|\meta{output}|}{|[|\from{|^^A
481 %                    \meta{input}|}{|\meta{optionlist}|}|]*|}|]*|}|
482 %    \end{quote}
483 %    The \meta{output} and \meta{input} are normal file specifications
484 %    as are appropriate for your computer system. The
485 %    \meta{optionlist} is a comma separated list of `options' that
486 %    specify which optional code fragments in \meta{input} should be
487 %    included in \meta{output}. Argument to |\generate| may contain
488 %    some local declarations (e.g., the |\use...| commands described
489 %    below) that will apply to all |\file|s after them. Argument to
490 %    |\generate| is executed inside a group, so all local declarations
491 %    are undone when |\generate| concludes.
493 %    It is possible to specify multiple input files, each with its own
494 %    \meta{optionlist}. This is indicated by the notation [\ldots]*.
495 %    Moreover there can be many |\file| specifications in one
496 %    |\generate| clause. This means that all these \meta{output} files
497 %    should be generated while reading each of \meta{input} files
498 %    once. Input files are read in order of first appearance in this
499 %    clause. E.g.
500 %\begin{verbatim}
501 %    \generate{\file{p1.sty}{\from{s1.dtx}{foo,bar}}
502 %              \file{p2.sty}{\from{s2.dtx}{baz}
503 %                            \from{s3.dtx}{baz}}
504 %              \file{p3.sty}{\from{s1.dtx}{zip}
505 %                            \from{s2.dtx}{zip}}
506 %             }
507 %\end{verbatim}
508 %    will cause \ds{} to read files \texttt{s1.dtx}, \texttt{s2.dtx},
509 %    \texttt{s3.dtx} (in that order) and produce files
510 %    \texttt{p1.sty}, \texttt{p2.sty}, \texttt{p3.sty}.
512 %    The restriction to at most 16 output streams open in a while
513 %     does not mean that you can produce at most 16 files with one
514 %    |\generate|. In the example above only 2 streams are needed,
515 %    since while \texttt{s1.dtx} is processed only \texttt{p1.sty} and
516 %    \texttt{p3.sty} are being generated; while reading
517 %    \texttt{s2.dtx} only \texttt{p2.sty} and \texttt{p3.sty}; and
518 %    while reading \texttt{s3.dtx} file \texttt{p2.sty} . However
519 %    example below needs 3 streams:
520 %\begin{verbatim}
521 %    \generate{\file{p1.sty}{\from{s1.dtx}{foo,bar}}
522 %              \file{p2.sty}{\from{s2.dtx}{baz}
523 %                            \from{s3.dtx}{baz}}
524 %              \file{p3.sty}{\from{s1.dtx}{zip}
525 %                            \from{s3.dtx}{zip}}
526 %             }
527 %\end{verbatim}
528 %    Although while reading \texttt{s2.dtx} file \texttt{p3.sty} is
529 %    not written it must remain open since some parts of
530 %    \texttt{s3.dtx} will go to it later.
532 %    Sometimes it is not possible to create a file by reading  all
533 %    sources once. Consider the following example:
534 %\begin{verbatim}
535 %    \generate{\file{p1.sty}{\from{s1.dtx}{head}
536 %                            \from{s2.dtx}{foo}
537 %                            \from{s1.dtx}{tail}}
538 %              \file{s1.drv}{\from{s1.dtx}{driver}}
539 %             }
540 %\end{verbatim}
541 %    To generate \texttt{p1.sty} file \texttt{s1.dtx} must be read
542 %    twice: first time with option \texttt{head}, then file
543 %    \texttt{s2.dtx} is read and then \texttt{s1.dtx} again this time
544 %    with option \texttt{tail}.  \ds{} handles this case correctly: if
545 %    inside one |\file| declaration there are multiple |\from|es with
546 %    the same input file this file \emph{is} read multiple times.
548 %    If the order of |\from|s specified in one of your |\file|
549 %    specifications does not match the order of input files
550 %    established by previous |\file|s, \ds{} will raise an error and
551 %    abort. Then you may either read one of next sections or give up
552 %    and put that file in separate |\generate| (but then sources will
553 %    be read again just for that file).
555 %    \paragraph{For impatient.} Try following algorithm: Find
556 %    file that is generated from largest number of sources, start
557 %    writing |\generate| clause with this file and its sources in
558 %    proper order. Take other files that are to be generated and add
559 %    them checking if they don't contradict order of sources for the
560 %    first one. If this doesn't work read next sections.
562 %    \paragraph{For mathematicians.} Relation ``file $A$ must  be
563 %    read before file $B$'' is a partial order on the set of all your
564 %    source files.  Each |\from| clause adds a chain to this order.
565 %    What you have to do is to perform a topological sort i.e. to
566 %    extend partial order to linear one.  When you have done it just
567 %    list your source files in |\generate| in such a way that order of
568 %    their first appearance in the clause matches linear order. If
569 %    this cannot be achieved read next paragraph. (Maybe future
570 %    versions of \ds{} will perform this sort automatically, so all
571 %    these troubles will disappear.)
573 %    \paragraph{For that who must know that all.} There  is  a
574 %    diverse case when it's not possible to achieve proper order of
575 %    reading source files. Suppose you have to generate two files,
576 %    first from \texttt{s1.dtx} and \texttt{s3.dtx} (in that order)
577 %    and second from \texttt{s2.dtx} and \texttt{s3.dtx}.  Whatever
578 %    way you specify this the files will be read in either as
579 %    \texttt{s1 s3 s2} or \texttt{s2 s3 s1}. The key to solution is
580 %    magical macro |\needed| that marks a file as needed to be input
581 %    but not directing any output from it to current |\file|. In our
582 %    example proper specification is:
583 %\begin{verbatim}
584 %    \generate{\file{p1.sty}{\from{s1.dtx}{foo}
585 %                            \needed{s2.dtx}
586 %                            \from{s3.dtx}{bar}}
587 %              \file{p2.sty}{\from{s2.dtx}{zip}
588 %                            \from{s3.dtx}{zap}}
589 %             }
590 %\end{verbatim}
593 %  \DescribeMacro{\askforoverwritetrue}
594 %  \DescribeMacro{\askforoverwritefalse}
595 %    These macros specify what should happen if a file that is to be
596 %    generated already exists. If |\askforoverwritetrue| is active
597 %    (the default) the user is asked whether the file should be
598 %    overwritten. If however |\askforoverwritefalse| was issued
599 %    existing files will be overwritten silently.  These switches are
600 %    local and can be issued in any place in the file even inside
601 %    |\generate| clause (between |\file|s however).
603 %  \DescribeMacro{\askonceonly}
604 %  You might not want to set |\askforoverwritefalse| in a batch file
605 %  as that says that it us always all right to overwrite other people's
606 %  files. However for large installations, such as the base \LaTeX\
607 %  distribution,  being asked individually about hundreds of files
608 %  is not very helpful either. A batchfile may therefore specify
609 %  |\askonceonly|. This means that after the first time the batchfile
610 %  asks the user a question, the user is given an option of to change
611 %  the behaviour so that `yes' will be automatically assumed for all
612 %  future questions. This applies to any use of the \ds{} commamnd
613 %  |\Ask| including, but not restricted to, the file overwrite
614 %  questions controlled by |\askforoverwritetrue|.
616 % \DescribeMacro{\preamble}
617 % \DescribeMacro{\endpreamble}
618 % \DescribeMacro{\postamble}
619 % \DescribeMacro{\endpostamble}
620 %    It is possible to add a number of lines to the output of the
621 %    \ds{} program. The information you want to add to the start of
622 %    the output file should be listed between the |\preamble| and
623 %    |\endpreamble| commands; the lines you want to add to the end of
624 %    the output file should be listed between the |\postamble| and
625 %    |\endpostamble| commands. Everything that \ds{} finds for both
626 %    the pre- and postamble it writes to the output file, but preceded
627 %    with value of |\MetaPrefix| (default is two \%-characters). If
628 %    you include a |^^J| character in one of these lines, everything
629 %    that follows it on the same line is written to a new line in the
630 %    output file.  This `feature' can be used to add a |\typeout| or
631 %    |\message| to the stripped file.
633 % \DescribeMacro{\declarepreamble}
634 % \DescribeMacro{\declarepostamble}
635 % \DescribeMacro{\usepreamble}
636 % \DescribeMacro{\usepostamble}
637 % \DescribeMacro{\nopreamble}
638 % \DescribeMacro{\nopostamble}
639 %    Sometimes it is desirable to have different preambles for different
640 %    files  of  a  larger  package  (e.g.,  because  some  of them are
641 %    customisable  configuration  files and they should be marked as
642 %    such). In such a case one can say |\declarepreamble\somename|,
643 %    then type in his/her preamble, end it with |\endpreamble|,
644 %    and  later  on  |\usepreamble\somename|  to  switch   to   this
645 %    preamble.  
646 %    If no preamble  should be used you can deploy the |\nopreamble|
647 %    command. This command is equivalent to saying  |\usepreamble\empty|.
648 %    The  same  mechanism works for postambles, |\use...|
649 %    declarations are local and can appear inside |\generate|.
651 %    Commands   |\preamble|   and   |\postamble| define and  activate
652 %    pre(post)ambles named |\defaultpreamble| and |\defaultpostamble|. 
654 % \DescribeMacro{\batchinput} 
655 %    The batch file commands can be put into several batch files which
656 %    are then executed from a master batch file. This is, for example,
657 %    useful if a distribution consists of several distinct parts. You
658 %    can then write individual batch files for every part and in
659 %    addition a master file that simply calls the batch files for the
660 %    parts.  For this, call the individual batch files from the master
661 %    file with the command |\batchinput{|\meta{file}|}|. Don't use
662 %    |\input| for this purpose, this command 
663 %    should be used only for calling the \ds{} program as explained
664 %    above and is ignored when used for any other purpose.
666 % \DescribeMacro{\ifToplevel} 
667 %    When batch files are nested you may want to suppress certain
668 %    commands in the lower-level batch files such as terminal
669 %    messages. For this purpose you can use the |\ifToplevel| command
670 %    which executes its argument only if the current batch file is the
671 %    outermost one. Make sure that you put the opening brace of the
672 %    argument into the same line as the command itself, otherwise the
673 %    \ds{} program will get confused.
675 % \DescribeMacro{\showprogress}
676 % \DescribeMacro{\keepsilent}
677 %    When the option \texttt{stats} is included in \ds{} it can
678 %    write message to the terminal as each line of the input file(s) is
679 %    processed. This message consists of a single character, indicating
680 %    kind of that particular line. We use the
681 %    following characters:
682 %    \begin{itemize}
683 % \item[\texttt{\%}] Whenever an input line is a comment
684 %        \texttt{\%}-character is written to the terminal.
685 % \item[\texttt{.}] Whenever a code line is encountered
686 %        a \texttt{.}-character is written on the terminal.
687 % \item[\texttt{/}] When a number of empty lines appear in a row in the
688 %        input file, at most one of them is retained. The \ds{}
689 %        program signals the removal of an empty line with the 
690 %        \texttt{/}-character.
691 % \item[\texttt{<}] When a `guard line' is found in the input and it
692 %        starts a block of optionally included code, this is signalled
693 %        on the terminal by showing the \texttt{<}-character, together
694 %        with the boolean expression of the guard.
695 % \item[\texttt{>}] The end of a conditionally included block of code is
696 %        indicated by showing the \texttt{>}-character.
697 %    \end{itemize}
698 %    This feature is turned on by default when the option
699 %    \texttt{stats} is included, otherwise it is turned off. The
700 %    feature can be toggled with the commands |\showprogress| and
701 %    |\keepsilent|.
704 %  \subsubsection{Supporting old interface}
706 % \DescribeMacro{\generateFile}
707 %    Here is the old syntax for specifing  what  files  are  to  be
708 %    generated. It allows specification of just one output file.
709 %    \begin{quote}
710 %    |\generateFile{|\meta{output}|}{|\meta{ask}|}{|[|\from{|^^A
711 %                    \meta{input}|}{|\meta{optionlist}|}|]*|}|
712 %    \end{quote}
713 %    The meaning of \meta{output}, \meta{input} and
714 %    \meta{optionslist} is just as for |\generate|.  With
715 %    \meta{ask} you can instruct \TeX\ to either silently overwrite a
716 %    previously existing file (|f|) or to issue a warning and ask you
717 %    if it should overwrite the existing file (|t|) (it overrides the
718 %    |\askforoverwrite| setting).
720 % \DescribeMacro{\include}
721 % \DescribeMacro{\processFile}
722 %    The earlier version of the \ds{} program supported a
723 %    different kind of command to tell \TeX\ what to do. This command
724 %    is less powerful than |\generateFile|; it can be used when
725 %    \meta{output} is created from one \meta{input}. The syntax is:
726 %    \begin{quote}
727 %    |\include{|\meta{optionlist}|}|
729 %    |\processFile{|\meta{name}|}{|\meta{inext}^^A
730 %                              |}{|\meta{outext}^^A
731 %                              |}{|\meta{ask}|}|
732 %    \end{quote}
733 %    This command is based on environments where filenames are
734 %    constructed of two parts, the name and the extension, separated
735 %    with a dot. The syntax of this command assumes that the
736 %    \meta{input} and \meta{output} share the same name and only
737 %    differ in their extension. This command is retained to be
738 %    backwards compatible with the older version of \ds{}, but its use
739 %    is not encouraged.
741 % \section{Conditional inclusion of code}
743 %    When you use the \ds{} program to strip comments out of
744 %    \TeX\ macro files you have the possibility to make more than one
745 %    stripped macro file from one documented file. This is achieved by
746 %    the support for optional code. The optional code is marked
747 %    in the documented file with a `guard'.
749 %    A guard is a boolean expression that is enclosed in |<| and |>|.
750 %    It also {\em has\/} to follow the |%| at the beginning of the line.
751 %    For example:
752 %\begin{verbatim}
753 %    ...
754 %    %<bool>\TeX code
755 %    ...
756 %\end{verbatim}
757 %    In this example the line of code will be included in \meta{output}
758 %    if the option \texttt{bool} is present in the \meta{optionlist} of
759 %    the |\generateFile| command.
761 %    The syntax for the boolean expressions is:
763 %\DeleteShortVerb\|
764 %    \begin{tabular}{lcl}
765 %    \meta{Expression} & $::=$ & \meta{Secondary}
766 %                            [\{\texttt{|}, \texttt{,}\} 
767 %                            \meta{Secondary}]*\\
768 %    \meta{Secondary}    & $::=$ & 
769 %                        \meta{Primary} [\texttt{\&}
770 %                         \meta{Primary}]*\\
771 %    \meta{Primary}  & $::=$ & 
772 %                        \meta{Terminal} $|$ \texttt{!}\meta{Primary}
773 %                        $|$ \texttt{(}\meta{Expression}\texttt{)}\\
774 %    \end{tabular}
776 %    The \texttt{|} stands for disjunction, the \texttt{\&} stands for
777 %    conjunction and the \texttt{!}\ stands for negation. The
778 %    \meta{Terminal} is any sequence of letters and evaluates to
779 %    \meta{true} iff\footnote{iff stands for `if and only if'} it
780 %    occurs in the list of options that have to be included.
781 %\MakeShortVerb\|
783 %    Two kinds of optional code are supported: one can either have
784 %    optional code that `fits' on one line of text, like the example
785 %    above, or one can have blocks of optional code.
787 %    To distinguish both kinds of optional code the `guard modifier'
788 %    has been introduced. The `guard modifier' is one character that
789 %    immediately follows the |<| of the guard. It can be either |*|
790 %    for the beginning of a block of code, or |/| for the end of a
791 %    block of code\footnote{To be compatible with the earlier version
792 %    of \ds{} also \texttt{+} and \texttt{-} are supported as `guard
793 %    modifiers'.  However, there is an incompatibility with the
794 %    earlier version since a line with a \texttt{+}-modified guard is
795 %    not included inside a block with a guard that evaluates to false,
796 %    in contrast to the previous behaviour.}.  The beginning and
797 %    ending guards for a block of code have to be on a line by
798 %    themselves.
800 %    When a block of code is {\em not\/} included, any guards that occur
801 %    within that block are {\em not\/} evaluated.
803 % \section{Those other languages}
804 %    Since \TeX\ is an open system some of \TeX\ packages include
805 %    non-\TeX\ files. Some authors use \ds\ to generate PostScript
806 %    headers, shell scripts or programs in other languages. For them
807 %    the comments-stripping activity of \ds\ may cause some
808 %    trouble. This section describes how to produce non-\TeX\ files
809 %    with \ds\ effectively.
811 % \subsection{Stuff \ds\ puts in every file}
812 %    First problem when producing files in ``other'' languages is that
813 %    \ds\ adds some bits to the begining and end of every generated
814 %    file that may not fit with the syntax of the language in
815 %    question. So we'll study carefully what exactly goes where.
817 %    The whole text put on begining of file is kept in a macro defined
818 %    by |\declarepreamble|. Every line of input presented to
819 %    |\declarepreamble| is prepended with current value of
820 %    |\MetaPrefix|. Standard \ds\ header is inserted before your text,
821 %    and macros |\inFileName|, |\outFileName| and |\ReferenceLines|
822 %    are used as placeholders for information which will be filled in
823 %    later (specifically for each output file). Don't try to redefine
824 %    these macros. After
825 %\begin{verbatim}
826 %    \declarepreamble\foo
827 %    ____________________________
828 %    Package FOO for use with TeX
829 %    \endpreamble 
830 %\end{verbatim}
831 %    macro |\foo| is defined as
832 %\begin{verbatim}
833 %    %%^^J
834 %    %% This is file `\outFileName ',^^J
835 %    %% generated with the docstrip utility.^^J
836 %    \ReferenceLines^^J
837 %    %% ____________________________^^J
838 %    %% Package FOO for use with TeX.
839 %\end{verbatim}
840 %    You can play with it freely or even define it from scratch. To
841 %    embed the preamble in Adobe structured comments just use |\edef|:
842 %\begin{verbatim}
843 %    \edef\foo{\perCent!PS-Adobe-3.0^^J%
844 %              \DoubleperCent\space Title: \outFileName^^J%
845 %              \foo^^J%
846 %              \DoubleperCent\space EndComments}
847 %\end{verbatim}
848 %    After that use |\usepreamble\foo| to select your new preamble.
849 %    Everything above works as well for postambles.
851 %    You may also prevent \ds\ from adding anything to your file, and
852 %    put any language specific invocations directly in your code:
853 %\begin{verbatim}
854 %    \generate{\usepreamble\empty
855 %              \usepostamble\empty
856 %              \file{foo.ps}{\from{mypackage.dtx}{ps}}}
857 %\end{verbatim}
858 %    or alternatively |\nopreamble| and |\nopostamble|.
860 % \subsection{Meta comments}
861 %    You can change the prefix used for putting meta comments to
862 %    output files by redefining |\MetaPrefix|. Its default value is
863 %    |\DoubleperCent|. The preamble uses value of |\MetaPrefix|
864 %    current at time of |\declarepreamble| while meta comments in the
865 %    source file use value current at time of |\generate|. Note that
866 %    this means that you cannot produce concurrently two files using
867 %    different |\MetaPrefix|es.
868 %    
869 % \subsection{Verbatim mode}
870 %    If your programming language uses some construct that can
871 %    interferes badly with \ds\ (e.g., percent in column one) you may
872 %    need a way for preventing it from being stripped off. For that
873 %    purpose \ds\ features `verbatim mode'.
875 %    A `Guard expression' of the form |%<<|\meta{END-TAG} marks
876 %    the start of a section that will be copied verbatim upto a line
877 %    containing only a percent in column 1 followed by \meta{END-TAG}. 
878 %    You can select any \meta{END-TAG} you want, but note that spaces
879 %     count here. Example:
880 %\begin{verbatim}
881 %    %<*myblock>
882 %    some stupid()
883 %       #computer<program>
884 %    %<<COMMENT
885 %    % These two lines are copied verbatim (including percents
886 %    %% even if \MetaPrefix is something different than %%).
887 %    %COMMENT
888 %       using*strange@programming<language>
889 %    %</myblock>
890 %\end{verbatim}
891 %    And the output is (when stripped with \texttt{myblock} defined):
892 %\begin{verbatim}
893 %    some stupid()
894 %       #computer<program>
895 %    % These two lines are copied verbatim (including percents
896 %    %% even if \MetaPrefix is something different than %%).
897 %       using*strange@programming<language>
898 %\end{verbatim}
900 %\StopEventually{%
901 %^^A \section{Conclusion}
902 %  \PrintIndex
903 %  \PrintChanges
904 %^^A \makesignature
905 % }
907 % \section{Producing the documentation}
909 %    We provide a short driver file that can be extracted by the
910 %    \ds{} program using the conditional `\textsf{driver}'.  To
911 %    allow the use of \texttt{docstrip.dtx} as a program at Ini\TeX{}
912 %    time (e.g., to strip
913 %    off its own comments) we need to add a bit of primitive code.
914 %    With this extra checking it is still possible to process this
915 %    file with \LaTeXe{} to typeset the documentation.
916 % \changes{2.1b}{1993/02/23}{Added fontdefinitions for doc to the driver
917 %                          file, in order to get the layout of the code
918 %                          right; also added the layout definitions
919 %                          that are in effect in \texttt{doc.drv}}
920 % \changes{2.1c}{1993/02/23}{Remove definitions for fonts again}
921 % \changes{2.2f}{1994/02/26}{Allow direct processing of source}
922 %    \begin{macrocode}
923 %<*driver>
924 %    \end{macrocode}
925 %    If |\documentclass| is undefined, e.g., if Ini\TeX{} or plain
926 %    \TeX{} is used for formatting, we bypass the driver file.
928 % \changes{2.3a}{1995/08/20}{Changed driver}
929 %    We use some trickery to avoid issuing |\end{document}| when
930 %    the |\ifx| construction is unfinished. If condition below is
931 %    true a |\fi| is constructed on the fly, the |\ifx| is completed,
932 %    and the real |\fi| will never be seen as it comes after 
933 %    |\end{document}|. On the other hand if condition is false
934 %    \TeX\ skips over |\csname fi\endcsname| having no idea that
935 %    this could stand for |\fi|, driver is skipped and only then
936 %    the condition completed.
938 %    Additional guard |gobble| prevents \ds\ from extracting
939 %    these tricks to real driver file.
940 %    \begin{macrocode}
941 %<*gobble>
942 \ifx\jobname\relax\let\documentclass\undefined\fi
943 \ifx\documentclass\undefined
944 \else \csname fi\endcsname
945 %</gobble>
946 %    \end{macrocode}
947 %    Otherwise we process the following lines which will result in
948 %    formatting the documentation.
949 %    \begin{macrocode}
950  \documentclass{ltxdoc}
951     \EnableCrossrefs 
952  % \DisableCrossrefs 
953  % use \DisableCrossrefs if the 
954  % index is ready 
955  \RecordChanges 
956  % \OnlyDescription
957  \typeout{Expect some Under- and overfull boxes}
958  \begin{document}
959    \DocInput{docstrip.dtx}
960  \end{document}
961 %<*gobble>
963 %</gobble>
964 %</driver>
965 %    \end{macrocode}
968 % \section{The implementation}
970 % \subsection{Initex initializations}
971 % Allow this program to run with |initex|.
972 % The |Z| trickery saves the need to worry about |\outer| stuff in
973 % plain \TeX.
974 %    \begin{macrocode}
975 %<*initex>
976 \catcode`\Z=\catcode`\%
977 \ifnum13=\catcode`\~{\egroup\else
978   \catcode`\Z=9
980 Z  \catcode`\{=1  \catcode`\}=2 
981 Z  \catcode`\#=6  \catcode`\^=7
982 Z  \catcode`\@=11 \catcode`\^^L=13
983 Z  \let\bgroup={  \let\egroup=}
985 Z  \dimendef\z@=10 \z@=0pt \chardef\@ne=1 \countdef\m@ne=22 \m@ne=-1
986 Z  \countdef\count@=255
988 Z  \def\wlog{\immediate\write\m@ne} \def\space{ }
990 Z  \count10=22 % allocates \count registers 23, 24, ...
991 Z  \count15=9 % allocates \toks registers 10, 11, ...
992 Z  \count16=-1 % allocates input streams 0, 1, ...
993 Z  \count17=-1 % allocates output streams 0, 1, ...
995 Z  \def\alloc@#1#2#3{\advance\count1#1\@ne#2#3\count1#1\relax}
997 Z  \def\newcount{\alloc@0\countdef} \def\newtoks{\alloc@5\toksdef}
998 Z  \def\newread{\alloc@6\chardef}   \def\newwrite{\alloc@7\chardef}
1000 Z \def\newif#1{%
1001 Z   \count@\escapechar \escapechar\m@ne
1002 Z     \let#1\iffalse
1003 Z     \@if#1\iftrue
1004 Z     \@if#1\iffalse
1005 Z   \escapechar\count@}
1006 Z \def\@if#1#2{%
1007 Z   \expandafter\def\csname\expandafter\@gobbletwo\string#1%
1008 Z                     \expandafter\@gobbletwo\string#2\endcsname
1009 Z                        {\let#1#2}}
1011 Z  \def\@gobbletwo#1#2{}
1012 Z  \def\@gobblethree#1#2#3{}
1014 Z  \def\loop#1\repeat{\def\body{#1}\iterate}
1015 Z  \def\iterate{\body \let\next\iterate \else\let\next\relax\fi \next}
1016 Z  \let\repeat\fi
1018 Z  \def\empty{}
1020 Z  \def\tracingall{\tracingcommands2 \tracingstats2 
1021 Z    \tracingpages1 \tracingoutput1 \tracinglostchars1 
1022 Z    \tracingmacros2 \tracingparagraphs1 \tracingrestores1 
1023 Z    \showboxbreadth 10000 \showboxdepth 10000 \errorstopmode
1024 Z    \errorcontextlines 10000 \tracingonline1 }
1026 \bgroup}\fi\catcode`\Z=11
1027 \let\bgroup={  \let\egroup=}
1028 %</initex>
1029 %    \end{macrocode}
1031 % \subsection{Declarations and initializations}
1033 %    In order to be able to include the \texttt{@}-sign in control
1034 %    sequences its category code is changed to \meta{letter}.  The
1035 %    `program' guard here allows most of the code to be excluded when
1036 %    extracting the driver file.
1037 %    \begin{macrocode}
1038 %<*program>
1039 \catcode`\@=11
1040 %    \end{macrocode}
1042 %    When we want to write multiple lines to the terminal with one
1043 %    statement, we need a character that tells \TeX\ to break the lines.
1044 %    We use \verb=^^J= for this purpose.
1045 %    \begin{macrocode}
1046 \newlinechar=`\^^J
1047 %    \end{macrocode}
1049 % \subsubsection{Switches}
1050 % \begin{macro}{\ifGenerate}
1051 %    The program will check if a
1052 %    file of the same name as the file it would be creating already
1053 %    exists. The switch |\ifGenerate| is used to indicate if the
1054 %    stripped file has to be generated.
1055 %    \begin{macrocode}
1056 \newif\ifGenerate
1057 %    \end{macrocode}
1058 % \end{macro}
1060 % \begin{macro}{\ifContinue}
1061 %    The switch |\ifContinue| is used in various places in the
1062 %    program to indicate if a |\loop| has to end.
1063 %    \begin{macrocode}
1064 \newif\ifContinue
1065 %    \end{macrocode}
1066 % \end{macro}
1068 % \begin{macro}{\ifForlist}
1069 % \changes{2.0g}{1991/06/05}{Macro added.}
1070 %    The program contains an implementation of a for-loop, based on
1071 %    plain \TeX{}'s |\loop| macros. The implementation needs a
1072 %    switch to terminate the loop.
1073 %    \begin{macrocode}
1074 \newif\ifForlist
1075 %    \end{macrocode}
1076 % \end{macro}
1078 % \begin{macro}{\ifDefault}
1079 %    The switch |\ifDefault| is used to indicate whether the
1080 %    default batch file has to be used.
1081 % \changes{2.0f}{1991/06/04}{Macro added.} 
1082 %    \begin{macrocode}
1083 \newif\ifDefault
1084 %    \end{macrocode}
1085 % \end{macro}
1087 % \begin{macro}{\ifMoreFiles}
1088 %    The switch |\ifMoreFiles| is used to decide if the user
1089 %    wants more files to be processed. It is used only in interactive
1090 %    mode; initially it evaluates to \meta{true}.
1091 % \changes{2.0h}{1991/06/19}{Macro added.}
1092 %    \begin{macrocode}
1093 \newif\ifMoreFiles \MoreFilestrue
1094 %    \end{macrocode}
1095 % \end{macro}
1096 % \begin{macro}{\ifaskforoverwrite}
1097 %    The switch |\askforoverwrite| is used to  decide  if  the  user
1098 %    should be asked when a file is to be overwritten.
1099 %    \begin{macrocode}
1100 \newif\ifaskforoverwrite \askforoverwritetrue
1101 %    \end{macrocode}
1102 % \end{macro}
1104 % \subsubsection{Count registers}
1105 % \begin{macro}{\blockLevel}
1106 %    Optionally included blocks of code can be nested. The counter
1107 %    |\blockLevel| will be used to keep track of the level of
1108 %    nesting.  Its initial value is zero.
1109 %    \begin{macrocode}
1110 \newcount\blockLevel \blockLevel\z@
1111 %    \end{macrocode}
1112 % \end{macro}
1114 % \begin{macro}{\emptyLines}
1115 %    The count register |\emptyLines| is used to count the number
1116 %    of consecutive empty input lines. Only the first will be copied
1117 %    to the output file.
1118 % \changes{2.0i}{1990/06/27}{Macro added}
1119 %    \begin{macrocode}
1120 \newcount\emptyLines \emptyLines \z@
1121 %    \end{macrocode}
1122 % \end{macro}
1124 % \begin{macro}{\processedLines}
1125 % \begin{macro}{\commentsRemoved}
1126 % \begin{macro}{\commentsPassed}
1127 % \begin{macro}{\codeLinesPassed}
1128 %    To be able to provide the user with some statistics about the
1129 %    stripping process four counters are allocated if the statistics
1130 %    have been included when this program was \ds{}ped.  The number of
1131 %    lines processed is stored in the counter |\processedLines|.
1132 %    The number of lines containing comments that are not written on
1133 %    the output file is stored in the counter |\commentsRemoved|;
1134 %    the number of comments copied to the output file is stored in the
1135 %    counter |\commentsPassed|.  The number of lines containing
1136 %    macro code that are copied to the output file is stored in the
1137 %    counter |\codeLinesPassed|.
1138 %    \begin{macrocode}
1139 %<*stats>
1140 \newcount\processedLines   \processedLines  \z@
1141 \newcount\commentsRemoved  \commentsRemoved \z@
1142 \newcount\commentsPassed   \commentsPassed  \z@
1143 \newcount\codeLinesPassed  \codeLinesPassed \z@
1144 %    \end{macrocode}
1145 % \end{macro}
1146 % \end{macro}
1147 % \end{macro}
1148 % \end{macro}
1150 % \changes{2.0e}{1991/05/31}{Added counter allocation for the processing
1151 %                           of multiple files}
1152 % \begin{macro}{\TotalprocessedLines}
1153 % \begin{macro}{\TotalcommentsRemoved}
1154 % \begin{macro}{\TotalcommentsPassed}
1155 % \begin{macro}{\TotalcodeLinesPassed}
1156 %    When more than one file is processed and when statistics have
1157 %    been included we provide the user also with information about the
1158 %    total amount of lines processed. For this purpose four more count
1159 %    registers are allocated here.
1160 %    \begin{macrocode}
1161 \newcount\TotalprocessedLines   \TotalprocessedLines  \z@
1162 \newcount\TotalcommentsRemoved  \TotalcommentsRemoved \z@
1163 \newcount\TotalcommentsPassed   \TotalcommentsPassed  \z@
1164 \newcount\TotalcodeLinesPassed  \TotalcodeLinesPassed \z@
1165 %</stats>
1166 %    \end{macrocode}
1167 % \end{macro}
1168 % \end{macro}
1169 % \end{macro}
1170 % \end{macro}
1172 % \begin{macro}{\NumberOfFiles}
1173 %    When more than one file is processed, the number of files is
1174 %    stored in the count register |\NumberOfFiles|.
1175 % \changes{2.4h}{1997/07/07}{Declare counter always pr/2429}
1176 %    \begin{macrocode}
1177 \newcount\NumberOfFiles \NumberOfFiles\z@
1178 %    \end{macrocode}
1179 % \end{macro}
1181 % \subsubsection{I/O streams}
1182 % \begin{macro}{\inFile}
1183 %    For reading the file with documented \TeX-code, an input stream
1184 %    |\inFile| is allocated.
1185 %    \begin{macrocode}
1186 \newread\inFile
1187 %    \end{macrocode}
1188 % \end{macro}
1190 % \changes{2.3a}{1995/08/18}{No allocated streams for console}
1191 % \begin{macro}{\ttyin}
1192 % \begin{macro}{\ttyout}
1193 %    Communication with the user goes through (nonexistent) stream 16.
1194 %    \begin{macrocode}
1195 \chardef\ttyin16
1196 \chardef\ttyout16
1197 %    \end{macrocode}
1198 % \end{macro}
1199 % \end{macro}
1201 % \begin{macro}{\inputcheck}
1202 %    This stream is only used for checking for existence of files. 
1203 %    \begin{macrocode}
1204 \newread\inputcheck
1205 %    \end{macrocode}
1206 % \end{macro}
1208 %  \begin{macro}{\ifToplevel}
1209 %    Execute the argument if current batch file is the outermost one.
1210 %    Otherwise suppress it.
1211 %    \begin{macrocode}
1212 \newif\iftopbatchfile \topbatchfiletrue
1213 \def\ifToplevel{\relax\iftopbatchfile
1214    \expandafter\iden \else \expandafter\@gobble\fi}
1215 %    \end{macrocode}
1216 %  \end{macro}
1218 % \begin{macro}{\batchinput}
1219 % \changes{2.0n}{1992/04/26}{Added macro}
1220 % \changes{2.1a}{1993/02/22}{Completely redefined (so that it works)}
1222 %    When the file \texttt{docstrip.tex} is read because of an
1223 %    |\input| statement in a batch file we have to prevent an
1224 %    endless loop (well, limited by \TeX's stack). Therefore we save
1225 %    the original primitive |\input| and define a new macro with
1226 %    an argument delimited by \verb*= = (i.e.\ a space) that just
1227 %    gobbles the argument.  Since the end-of-line character is
1228 %    converted by \TeX{} to a space.  This means that |\input| is not
1229 %    available as a command within batch files. 
1231 % \begin{macro}{\@@input}
1232 % \changes{2.1a}{1993/02/22}{Macro added}
1233 %    We therefore keep a copy of the original under the name
1234 %    |\@@input| for internal use. If \ds{} runs under \LaTeX{} this
1235 %    command is already defined, so we make a quick test.
1236 %    \begin{macrocode}
1237 \ifx\undefined\@@input \let\@@input\input\fi
1238 %    \end{macrocode}
1239 % \end{macro}
1240 %    
1241 %    To allow the nesting of batch files the |\batchinput| command is
1242 %    provided it takes one argument, the name of the batch file to
1243 %    switch to.
1244 %    \begin{macrocode}
1245 \def\batchinput#1{%
1246 %    \end{macrocode}
1247 %    We start a new group and locally redefine |\batchFile| to hold
1248 %    the new batch file name. We toggle the |\iftopbatchfile| switch
1249 %    since this definitely is not top batch file.
1250 %    \begin{macrocode}
1251    \begingroup
1252      \def\batchfile{#1}%
1253      \topbatchfilefalse
1254      \Defaultfalse
1255      \usepreamble\org@preamble
1256      \usepostamble\org@postamble
1257      \let\destdir\WriteToDir
1258 %    \end{macrocode}
1259 %    After this we can simply call |\processbatchFile| which will
1260 %    open the new batch file and read it until it
1261 %    is exhausted. Note that if the batch file is not available, or
1262 %    misspelled this routine will produce a warning and return.
1263 %    \begin{macrocode}
1264      \processbatchFile
1265 %    \end{macrocode}
1266 %    The value of |\batchfile| as well as local definitions of
1267 %    preambles, directories etc. will be restored
1268 %    at this  closing |\endgroup|, so that further processing
1269 %    continues in the calling batch file.
1270 %    \begin{macrocode}
1271    \endgroup
1273 %    \end{macrocode}
1274 % \begin{macro}{\skip@input}
1275 % \changes{2.0j}{1992/03/03}{Added macro}
1276 % \changes{2.0n}{1992/04/26}{Argument delimited by space not \cs{relax}}
1277 % \changes{2.0n}{1992/04/26}{Macro renamed from \cs{skipinput}} 
1278 %    And here is the promised redefinition of |\input|:
1279 %    \begin{macrocode}
1280 \def\skip@input#1 {}
1281 \let\input\skip@input
1282 %    \end{macrocode}
1283 % \end{macro}
1284 % \end{macro}
1286 % \subsubsection{Empty macros and macros that expand to a string}
1287 % \begin{macro}{\guardStack}
1288 %    \changes{2.0k}{1992/04/06}{Renamed from \texttt{\bsl blockStack}}
1289 %    Because blocks of code that will conditionally be included in the
1290 %    output can be nested, a stack is maintained to keep track of
1291 %    these blocks. The main reason for this is that we want to be able
1292 %    to check if the blocks are properly nested. The stack itself is
1293 %    stored in |\guardStack|.
1294 %    \begin{macrocode}
1295 \def\guardStack{}
1296 %    \end{macrocode}
1297 % \end{macro}
1299 % \begin{macro}{\blockHead}
1300 %    The macro |\blockHead| is used for storing and retrieving
1301 %    the boolean expression that starts a block.
1302 %    \begin{macrocode}
1303 \def\blockHead{}
1304 %    \end{macrocode}
1305 % \end{macro}
1307 % \begin{macro}{\yes}
1308 % \begin{macro}{\y}
1309 %    When the user is asked a question that he has to answer with either
1310 %    \meta{yes} or \meta{no}, his response has to be evaluated. For this
1311 %    reason the macros |\yes| and |\y| are defined.
1312 %    \begin{macrocode}
1313 \def\yes{yes}
1314 \def\y{y}
1315 %    \end{macrocode}
1316 % \begin{macro}{\n}
1317 %    We also define |\n| for use in \ds{} command files.
1318 % \changes{2.1e}{1993/03/09}{Macro added}
1319 %    \begin{macrocode}
1320 \def\n{n}
1321 %    \end{macrocode}
1322 % \end{macro}
1323 % \end{macro}
1324 % \end{macro}
1326 % \begin{macro}{\Defaultbatchile}
1327 % \changes{2.0f}{1991/06/04}{Macro added.}
1328 %    When the \ds{} program has to process a batch file it
1329 %    can look for a batch file with a default name. This name
1330 %    is stored in |\DefaultbatchFile|.
1331 %    \begin{macrocode}
1332 \def\DefaultbatchFile{docstrip.cmd}
1333 %    \end{macrocode}
1334 % \end{macro}
1336 % \begin{macro}{\perCent}
1337 % \begin{macro}{\DoubleperCent}
1338 % \begin{macro}{\MetaPrefix}
1339 %    To be able to display percent-signs on the terminal, a
1340 %    \texttt{\%} with category code 12 is stored in |\perCent| and
1341 %    |\DoubleperCent|. The macro |\MetaPrefix| is put on begining of
1342 %    every meta-comment line. It is defined indirect way since some
1343 %    applications need redefining it.
1344 %    \begin{macrocode}
1345 {\catcode`\%=12
1346  \gdef\perCent{%}
1347  \gdef\DoubleperCent{%%}
1349 \let\MetaPrefix\DoubleperCent
1350 %    \end{macrocode}
1351 % \end{macro}
1352 % \end{macro}
1353 % \end{macro}
1354 %    In order to allow formfeeds in the input we define a one-character
1355 %    control sequence \verb=^^L=.
1356 %    \begin{macrocode}
1357 \def^^L{ }
1358 %    \end{macrocode}
1360 %    The only result of using |\Name| is slowing down execution since
1361 %    its typical use (e.g., |\Name\def{foo bar}...|) has exactly the
1362 %    same number of tokens as its expansion. However I think that it's
1363 %    easier to read. The meaning of |\Name| as a black box is:
1364 %    ``construct a name from second parameter and then pass it to your
1365 %    first parameter as a parameter''.
1367 %    |\@stripstring| is used to get tokens building name of a macro
1368 %    without leading backslash.
1369 %    \begin{macrocode}
1370 \def\Name#1#2{\expandafter#1\csname#2\endcsname}
1371 \def\@stripstring{\expandafter\@gobble\string}
1372 %    \end{macrocode}
1374 % \subsubsection{Miscellaneous variables}
1375 % \begin{macro}{\sourceFileName}
1376 %    The macro |\sourceFileName| is used to store the name of the
1377 %    current input file.
1378 % \end{macro}
1379 % \begin{macro}{\batchfile}
1380 %    The macro |\batchfile| is used to store the name of the
1381 %    batch file.
1382 % \end{macro}
1383 % \begin{macro}{\inLine}
1384 %    The macro |\inLine| is used to store the lines, read from
1385 %    the input file, before further processing.
1386 % \end{macro}
1387 % \begin{macro}{\answer}
1388 %    When some interaction with the user is needed the macro
1389 %    |\answer| is used to store his response.
1390 % \end{macro}
1391 % \begin{macro}{\tmp}
1392 %    Sometimes something has to be temporarily stored in a control
1393 %    sequence.  For these purposes the control sequence |\tmp| is
1394 %    used.
1395 % \end{macro}
1397 % \subsection{Support macros}
1398 %    \subsubsection{The stack mechanism}
1400 %    It is possible to have `nested guards'. This means that within a
1401 %    block of optionally included code a subgroup is only included
1402 %    when an additional option is specified. To keep track of the
1403 %    nesting of the guards the currently `open' guard can be pushed on
1404 %    the stack |\guardStack| and later popped off the stack again. The
1405 %    macros that implement this stack mechanism are loosely based on
1406 %    code that is developed in the context of the \LaTeX3 project.
1408 %    To be able to implement a stack mechanism we need a couple of
1409 %    support macros.
1410 % \begin{macro}{\eltStart}
1411 %    \changes{2.0k}{1992/04/06}{Macro added}
1412 % \begin{macro}{\eltEnd}
1413 %    \changes{2.0k}{1992/04/06}{Macro added}
1414 %    The macros |\eltStart| and |\eltEnd| are used to delimit a stack
1415 %    element. They are both empty.
1416 %    \begin{macrocode}
1417 \def\eltStart{}
1418 \def\eltEnd{}
1419 %    \end{macrocode}
1420 % \end{macro}
1421 % \end{macro}
1423 % \begin{macro}{\qStop}
1424 %    \changes{2.0k}{1992/04/06}{Macro added}
1425 %    The macro |\qStop| is a so-called `quark', a macro that expands to
1426 %    itself\footnote{The concept of `quarks' is developed for the
1427 %    \LaTeX3 project.}.
1428 %    \begin{macrocode}
1429 \def\qStop{\qStop}
1430 %    \end{macrocode}
1431 % \end{macro}
1433 % \begin{macro}{\pop}
1434 %    \changes{2.0k}{1992/04/06}{Macro added} The macro
1435 %    |\pop|\meta{stack}\meta{cs} `pops' the top element from the
1436 %    stack. It assigns the value of the top element to \meta{cs} and
1437 %    removes it from \meta{stack}. When \meta{stack} is empty a
1438 %    warning is issued and \meta{cs} is assigned an empty value.
1439 %    \begin{macrocode}
1440 \def\pop#1#2{%
1441   \ifx#1\empty
1442     \Msg{Warning: Found end guard without matching begin}%
1443     \let#2\empty
1444   \else
1445 %    \end{macrocode}
1446 %    To be able to `peel' off the first guard we use an extra macro
1447 %    |\popX| that receives both the expanded and the unexpanded stack
1448 %    in its arguments. The expanded stack is delimited with the quark
1449 %    |\qStop|.
1450 %    \begin{macrocode}
1451     \def\tmp{\expandafter\popX #1\qStop #1#2}%
1452     \expandafter\tmp\fi}
1453 %    \end{macrocode}
1454 % \begin{macro}{\popX}
1455 %    \changes{2.0k}{1992/04/06}{Macro added} When the stack is expanded
1456 %    the elements are surrounded with |\eltStart| and |\eltEnd|. The
1457 %    first element of the stack is assigned to |#4|.
1458 %    \begin{macrocode}
1459 \def\popX\eltStart #1\eltEnd #2\qStop #3#4{\def#3{#2}\def#4{#1}}
1460 %    \end{macrocode}
1461 % \end{macro}
1462 % \end{macro}
1464 % \begin{macro}{\push}
1465 %    \changes{2.0k}{1992/04/06}{Macro added}
1466 %    Guards can be pushed on the stack using the macro
1467 %    |\push|\meta{stack}\meta{guard}. Again we need a secondary macro
1468 %    (|\pushX|) that has both the expanded and the unexpanded stack as
1469 %    arguments.
1470 %    \begin{macrocode}
1471 \def\push#1#2{\expandafter\pushX #1\qStop #1{\eltStart #2\eltEnd}}
1472 %    \end{macrocode}
1473 % \begin{macro}{\pushX}
1474 %    \changes{2.0k}{1992/04/06}{Macro added}
1475 %    The macro |\pushX| picks up the complete expansion of the stack as
1476 %    its first argument and places the guard in |#3| on the `top'.
1477 %    \begin{macrocode}
1478 \def\pushX #1\qStop #2#3{\def #2{#3#1}}
1479 %    \end{macrocode}
1480 % \end{macro}
1481 % \end{macro}
1483 % \subsubsection{Programming structures}
1485 % \begin{macro}{\forlist}
1486 % \changes{2.0g}{1991/06/05}{Macro added.}
1487 %    When the program is used in interactive mode the
1488 %    user can supply a list of files that have to be processed.
1489 %    In order to process this list a for-loop is needed. This
1490 %    implementation of such a programming construct is based on the
1491 %    use of the \verb=\loop{=\meta{body}\verb=}\repeat= macro that
1492 %    is defined in plain \TeX\@. The syntax for this loop is:
1493 %    \begin{flushleft}
1494 %    |\for|\meta{control sequence} |:=| \meta{list} 
1495 %    |\do|\\
1496 %    \meta{body}\\
1497 %    |\od|
1498 %    \end{flushleft}
1499 %    The \meta{list} should be a comma separated list.
1501 %    The first actions that have to be taken are to set the switch
1502 %    |\ifForlist| to \meta{true} and to store the loop condition
1503 %    in the macro |\ListCondition|. This is done using an
1504 %    |\edef| to allow for a control sequence that contains a
1505 %    \meta{list}.
1506 %    \begin{macrocode}
1507 \def\forlist#1:=#2\do#3\od{%
1508     \edef\ListCondition{#2}%
1509     \Forlisttrue
1510 %    \end{macrocode}
1511 %    Then we start the loop.
1512 %    We store the first element from the |\ListCondition| in the
1513 %    macro that was supplied as the first argument to |\forlist|.
1514 %    This element is then removed from the |\ListCondition|.
1515 %    \begin{macrocode}
1516     \loop
1517       \edef#1{\expandafter\FirstElt\ListCondition,\empty.}%
1518       \edef\ListCondition{\expandafter\OtherElts\ListCondition,\empty.}%
1519 %    \end{macrocode}
1520 %    When the first element from the \meta{list} is empty, we are done
1521 %    processing, so we switch |\ifForlist| to \meta{false}.
1522 %    When it is not empty we execute the third argument that should
1523 %    contain \TeX\ commands to execute.
1524 %    \begin{macrocode}
1525       \ifx#1\empty \Forlistfalse \else#3\fi
1526 %    \end{macrocode}
1527 %    Finally we test the switch |\ifForlist| to decide whether the
1528 %    loop has to be continued.
1529 %    \begin{macrocode}
1530       \ifForlist
1531     \repeat}
1532 %    \end{macrocode}
1533 % \begin{macro}{\FirstElt}
1534 % \changes{2.0g}{1991/06/05}{Macro added.}
1535 %    The macro |\FirstElt| is used to get the first element from a
1536 %    comma-separated list.
1537 %    \begin{macrocode}
1538 \def\FirstElt#1,#2.{#1}
1539 %    \end{macrocode}
1540 % \end{macro}
1541 % \begin{macro}{\OtherElts}
1542 % \changes{2.0g}{1991/06/05}{Macro added.}
1543 %    The macro |\OtherElts| is used to get all elements {\em but\/}
1544 %    the first element from a comma-separated list.
1545 %    \begin{macrocode}
1546 \def\OtherElts#1,#2.{#2}
1547 %    \end{macrocode}
1548 % \end{macro}
1549 % \end{macro}
1551 % \begin{macro}{\whileswitch}
1552 % \changes{2.0h}{1991/06/19}{Macro added.} When the program is used in
1553 %    interactive mode the user might want to process several files
1554 %    with different options or extensions.  This goal could be reached
1555 %    by running the program several times, but it is more
1556 %    user-friendly to ask if he would like to process more files when
1557 %    we are done processing his last request.  To accomplish this we
1558 %    need the implementation of a \texttt{while}-loop.  Again plain
1559 %    \TeX's \verb=\loop{=\meta{body}\verb=}\repeat= is used to
1560 %    implement this programming structure.
1562 %    The syntax for this loop is:
1563 %    \begin{flushleft}
1564 %    |\whileswitch|\meta{switch} \verb|\fi| \meta{list}
1565 %    \verb={=\meta{body}\verb=}=\\
1566 %    \end{flushleft}
1567 %    The first argument to this macro has to be a switch, defined
1568 %    using |\newif|; the second argument contains the statements
1569 %    to execute while the switch evaluates to \meta{true}.
1570 %    \begin{macrocode}
1571 \def\whileswitch#1\fi#2{#1\loop#2#1\repeat\fi}
1572 %    \end{macrocode}
1573 % \end{macro}
1575 % \changes{2.3a}{1995/08/18}{New mechanism: output streams allocation}
1577 % \subsubsection{Output streams allocator}
1579 % For each of sixteen output streams  available  we  have  a  macro
1580 % named |\s@0| through |\s@15| saying if the stream is assigned to a
1581 % file~(1) or not~(0). Initially all streams are not assigned.
1583 % We also declare 16 counters which will be needed by the conditional
1584 % code inclusion algorithm.
1586 %    \begin{macrocode}
1587 \ifx\@tempcnta\undefined \newcount\@tempcnta \fi
1588 \@tempcnta=0
1589 \loop
1590 \Name\chardef{s@\number\@tempcnta}=0
1591 \csname newcount\expandafter\endcsname%
1592   \csname off@\number\@tempcnta\endcsname
1593 \advance\@tempcnta1
1594 \ifnum\@tempcnta<16\repeat
1595 %    \end{macrocode}
1597 % We will use \emph{The \TeX book} style list to search through streams.
1599 %    \begin{macrocode}
1600 \let\s@do\relax
1601 \edef\@outputstreams{%
1602   \s@do\Name\noexpand{s@0}\s@do\Name\noexpand{s@1}%
1603   \s@do\Name\noexpand{s@2}\s@do\Name\noexpand{s@3}%
1604   \s@do\Name\noexpand{s@4}\s@do\Name\noexpand{s@5}%
1605   \s@do\Name\noexpand{s@6}\s@do\Name\noexpand{s@7}%
1606   \s@do\Name\noexpand{s@8}\s@do\Name\noexpand{s@9}%
1607   \s@do\Name\noexpand{s@10}\s@do\Name\noexpand{s@11}%
1608   \s@do\Name\noexpand{s@12}\s@do\Name\noexpand{s@13}%
1609   \s@do\Name\noexpand{s@14}\s@do\Name\noexpand{s@15}%
1610   \noexpand\@nostreamerror
1611   }
1612 %    \end{macrocode}
1614 % \begin{macro}{\@nostreamerror}\begin{macro}{\@streamfound}
1615 % When |\@outputstreams| is executed |\s@do| is defined to do
1616 % something on condition   of   some   test.    If   condition
1617 % always   fails   macro |\@nostreamerror| on the end of the list
1618 % causes an error. When condition succeeds  |\@streamfound|  is
1619 % called,  which  gobbles  rest of the list including the ending
1620 % |\@nostreamerror|. It also gobbles |\fi| ending the condition, so
1621 % the |\fi| is reinserted.
1623 %    \begin{macrocode}
1624 \def\@nostreamerror{\errmessage{No more output streams!}}
1625 \def\@streamfound#1\@nostreamerror{\fi}
1626 %    \end{macrocode}
1627 % \end{macro}\end{macro}
1629 % |\@stripstr| is auxiliary macro eating characters |\s@|
1630 % (backslash,s,@). It is defined in somewhat strange way since |\s@|
1631 % must have all category code  12  (other).  This  macro  is  used to
1632 % extract stream numbers from stream names.
1634 %    \begin{macrocode}
1635 \bgroup\edef\x{\egroup
1636  \def\noexpand\@stripstr\string\s@{}}
1638 %    \end{macrocode}
1640 % \begin{macro}{\StreamOpen}\begin{macro}{\StreamPut}
1641 % \begin{macro}{\StreamClose}
1642 % Here is stream opening operator. Its parameter should be a  macro
1643 % named the  same  as  the  external  file  being  opened. E.g., to
1644 % write to file |foo.tex|   use    |\StreamOpen\foo|,    then
1645 % |\StreamPut\foo|    and |\StreamClose\foo|.
1647 %    \begin{macrocode}
1648 \chardef\stream@closed=16
1649 \def\StreamOpen#1{%
1650   \chardef#1=\stream@closed 
1651   \def\s@do##1{\ifnum##1=0
1652     \chardef#1=\expandafter\@stripstr\string##1 %
1653     \global\chardef##1=1 %
1654     \immediate\openout#1=\csname pth@\@stripstring#1\endcsname %
1655     \@streamfound
1656     \fi}
1657   \@outputstreams
1658   }
1659 \def\StreamClose#1{%
1660   \immediate\closeout#1%
1661   \def\s@do##1{\ifnum#1=\expandafter\@stripstr\string##1 %
1662     \global\chardef##1=0 %
1663     \@streamfound
1664     \fi}
1665   \@outputstreams
1666   \chardef#1=\stream@closed
1667   }
1668 \def\StreamPut{\immediate\write}
1669 %    \end{macrocode}
1670 % \end{macro}\end{macro}\end{macro}
1672 % \subsubsection{Input and Output}
1674 % \begin{macro}{\maybeMsg}
1675 % \begin{macro}{\showprogress}
1676 % \begin{macro}{\keepsilent}
1677 %    When this program is used it can optionally show its progress on
1678 %    the terminal. In that case it will write a special character to
1679 %    the terminal (and the transcript file) for each input line. This
1680 %    option is on by default when statistics are included in 
1681 %    \texttt{docstrip.tex}. It is off when statistics are excluded. The
1682 %    commands |\showprogress| and |\keepsilent| can be used
1683 %    to choose otherwise.
1684 %    \begin{macrocode}
1685 \def\showprogress{\let\maybeMsg\message}
1686 \def\keepsilent{\let\maybeMsg\@gobble}
1687 %<*stats>
1688 \showprogress
1689 %</stats>
1690 %<-stats>\keepsilent
1691 %    \end{macrocode}
1692 % \end{macro}
1693 % \end{macro}
1694 % \end{macro}
1696 % \begin{macro}{\Msg}
1697 %    For displaying messages on the terminal the macro |\Msg| is
1698 %    defined to write {\em immediately\/} to |\ttyout|.
1699 %    \begin{macrocode}
1700 \def\Msg{\immediate\write\ttyout}
1701 %    \end{macrocode}
1702 % \end{macro}
1704 % \begin{macro}{\Ask}
1705 %    The macro
1706 %    \verb=\Ask{=\meta{cs}\verb=}{=\meta{string}\verb=}= is a
1707 %    slightly modified copy of the \LaTeX\ macro |\typein|. It is
1708 %    used to ask the user a question.  The \meta{string} will be
1709 %    displayed on his terminal and the response will be stored in the
1710 %    \meta{cs}. The trailing space left over from the carriage return
1711 %    is stripped off by the macro |\strip|. If the user just
1712 %    types a carriage return, the result will be an empty macro.
1713 % \changes{2.0i}{1991/06/27}{Added check for just \protect\meta{CR}}
1714 %    \begin{macrocode}
1715 \def\iden#1{#1}
1716 \def\strip#1#2 \@gobble{\def #1{#2}}
1717 \def\@defpar{\par}
1718 \def\Ask#1#2{%
1719     \message{#2}\read\ttyin to #1\ifx#1\@defpar\def#1{}\else
1720     \iden{\expandafter\strip
1721        \expandafter#1#1\@gobble\@gobble} \@gobble\fi}
1722 %    \end{macrocode}
1723 % \end{macro}
1725 % \begin{macro}{\OriginalAsk}
1726 % \changes{2.4e}{1996/10/24}{macro added (was in unpack.ins) (DPC)}
1727 %    \begin{macrocode}
1728 \let\OriginalAsk=\Ask
1729 %    \end{macrocode}
1730 % \end{macro}
1733 % \begin{macro}{\askonceonly}
1734 % \changes{2.4e}{1996/10/22}
1735 %      {macro added (essentially from unpack.ins) (DPC)}
1736 %    \begin{macrocode}
1737 \def\askonceonly{%
1738   \def\Ask##1##2{%
1739     \OriginalAsk{##1}{##2}%
1740     \global\let\Ask\OriginalAsk
1741     \Ask\noprompt{%
1742       By default you will be asked this question for every file.^^J%
1743       If you enter `y' now,^^J%
1744       I will asssume `y' for all future questions^^J%
1745       without prompting.}%
1746     \ifx\y\noprompt\let\noprompt\yes\fi
1747     \ifx\yes\noprompt\gdef\Ask####1####2{\def####1{y}}\fi}}
1748 %    \end{macrocode}
1749 % \end{macro}
1751 % \subsubsection{Miscellaneous}
1753 % \begin{macro}{\@gobble}
1754 % \changes{2.0a}{1991/05/25}{Macro added.}
1755 %    A macro that has an argument and puts it in the bitbucket.
1756 %    \begin{macrocode}
1757 \def\@gobble#1{}
1758 %    \end{macrocode}
1759 % \end{macro}
1761 % \begin{macro}{\Endinput}
1762 % \changes{2.0f}{1991/06/04}{Macro added.} When a \texttt{doc} file
1763 %    contains a \verb+\endinput+ on a line by itself this normally
1764 %    means that anything following in this file should be ignored.
1765 %    Therefore we need a macro containing |\endinput| as its
1766 %    replacement text to check this against |\inLine| (the
1767 %    current line from the current input file). Of course the
1768 %    backslash has to have the correct |\catcode|. One way of
1769 %    doing this is feeding \verb=\\= to the |\string| operation
1770 %    and afterwards removing one of the |\| characters.
1771 %    \begin{macrocode}
1772 \edef\Endinput{\expandafter\@gobble\string\\endinput}
1773 %    \end{macrocode}
1774 % \end{macro}
1776 % \begin{macro}{\makeOther}
1777 %    During the process of reading a file with \TeX\ code the category
1778 %    code of all special characters has to be changed to \meta{other}.
1779 %    The macro |\makeOther| serves this purpose.
1780 %    \begin{macrocode}
1781 \def\makeOther#1{\catcode`#1=12\relax}
1782 %    \end{macrocode}
1783 % \end{macro}
1785 % \begin{macro}{\end}
1786 % \changes{2.0h}{1991/06/19}{Macro added.} For now we want the \ds{}
1787 %    program to be compatible with both plain \TeX\ and \LaTeX\@.
1788 %    \LaTeX\  hides plain \TeX{}'s |\end| command and
1789 %    calls it |\@@end|. We unhide it here.
1790 %    \begin{macrocode}
1791 \ifx\undefined\@@end\else\let\end\@@end\fi
1792 %    \end{macrocode}
1793 % \end{macro}
1795 % \begin{macro}{\@addto}
1796 %    A macro extending macro's definition. The trick with |\csname|
1797 %    is necessary to get around |\newtoks| being outer in plain \TeX{}
1798 %    and \LaTeX\ version 2.09.
1799 %    \begin{macrocode}
1800 \ifx\@temptokena\undefined \csname newtoks\endcsname\@temptokena\fi
1801 %    \end{macrocode}
1803 %    \begin{macrocode}
1804 \def\@addto#1#2{%
1805   \@temptokena\expandafter{#1}%
1806   \edef#1{\the\@temptokena#2}}
1807 %    \end{macrocode}
1808 % \end{macro}
1810 % \begin{macro}{\@ifpresent}
1811 %    This macro checks if its first argument  is  present  on  a
1812 %    list passed as the second argument. Depending on the result
1813 %    it executes either its third or fourth argument.
1815 %    \begin{macrocode}
1816 \def\@ifpresent#1#2#3#4{%
1817   \def\tmp##1#1##2\qStop{\ifx!##2!}%
1818   \expandafter\tmp#2#1\qStop #4\else #3\fi
1819   }
1820 %    \end{macrocode}
1821 % \end{macro}
1823 % \begin{macro}{\tospaces}
1824 %    This macro converts its argument delimited with |\secapsot| to
1825 %    appropriate number of spaces. We need this for smart displaying
1826 %    messages on the screen.
1828 %    |\@spaces| are used when we need many spaces in a row.
1829 %    \begin{macrocode}
1830 \def\tospaces#1{%
1831   \ifx#1\secapsot\secapsot\fi\space\tospaces}
1832 \def\secapsot\fi\space\tospaces{\fi}
1833 \def\@spaces{\space\space\space\space\space}
1834 %    \end{macrocode}
1835 % \end{macro}
1837 % \begin{macro}{\uptospace}
1838 % \changes{2.3c}{1995/08/24}{Macro added}
1839 %    This  macro extracts from its argument delimited with |\qStop|
1840 %    part up to first occurence of space.
1841 %    \begin{macrocode}
1842 \def\uptospace#1 #2\qStop{#1}
1843 %    \end{macrocode}
1844 % \end{macro}
1846 % \begin{macro}{\afterfi}
1847 % \changes{2.3c}{1995/09/04}{Macro added}
1848 %    This macro can be used in conditionals to perform some actions
1849 %    (its  first  parameter) after the condition is completed (i.e.
1850 %    after  reading the matching |\fi|. Second parameter is used to
1851 %    gobble the rest of |\if ... \fi|  construction  (some  |\else|
1852 %    maybe). Note that this won't work in nested |\if|s!
1853 %    \begin{macrocode}
1854 \def\afterfi#1#2\fi{\fi#1}
1855 %    \end{macrocode}
1856 % \end{macro}
1857 % \begin{macro}{\@ifnextchar}
1858 % \changes{2.3e}{1995/09/25}{Macro added}
1859 %    This is one of \LaTeX's  macros  not  defined  by  plain.   My
1860 %    devious   definition   differs   from  the  standard  one  but
1861 %    functionality is the same.
1862 %    \begin{macrocode}
1863 \def\@ifnextchar#1#2#3{\bgroup
1864   \def\reserved@a{\ifx\reserved@c #1 \aftergroup\@firstoftwo
1865     \else \aftergroup\@secondoftwo\fi\egroup
1866     {#2}{#3}}%
1867   \futurelet\reserved@c\@ifnch
1868   }
1869 \def\@ifnch{\ifx \reserved@c \@sptoken \expandafter\@xifnch
1870       \else \expandafter\reserved@a
1871       \fi}
1872 \def\@firstoftwo#1#2{#1}
1873 \def\@secondoftwo#1#2{#2}
1874 \iden{\let\@sptoken= } %
1875 \iden{\def\@xifnch} {\futurelet\reserved@c\@ifnch}
1876 %    \end{macrocode}
1877 % \end{macro}
1878 % \begin{macro}{\kernel@ifnextchar}
1879 %   \changes{v2.5d}{2005/07/29}{Added macro} 
1880 %   The 2003/12/01 release of \LaTeX\ incorporated this macro to avoid
1881 %   problems with \texttt{amsmath} but this also means that we have to
1882 %   perform the same trick here when people use \LaTeX\ on a
1883 %   installation file containing |\ProvidesFile|.
1884 %    \begin{macrocode}
1885 \let\kernel@ifnextchar\@ifnextchar
1886 %    \end{macrocode}
1887 % \end{macro}
1890 % \subsection{The evaluation of boolean expressions}
1892 %    For clarity we repeat here the syntax for the boolean expressions
1893 %    in a somewhat changed but equivalent way:
1895 % \DeleteShortVerb\|
1896 %    \begin{tabular}{lcl}
1897 %    \meta{Expression} & $::=$ & \meta{Secondary} $|$
1898 %                            \meta{Secondary} \{\texttt{|}, \texttt{,}\}
1899 %                              \meta{Expression}\\
1900 %    \meta{Secondary}    & $::=$ & \meta{Primary} $|$
1901 %                         \meta{Primary} \texttt{\&}
1902 %                              \meta{Secondary}\\
1903 %    \meta{Primary}  & $::=$ & 
1904 %                         \meta{Terminal} $|$ \texttt{!}\meta{Primary}
1905 %                                  $|$ 
1906 %                         \texttt{(}\meta{Expression}\texttt{)}\\
1907 %    \end{tabular}
1909 %    The \texttt{|} stands for disjunction, the \texttt{\&} stands for
1910 %    conjunction and the \texttt{!}\ stands for negation. The
1911 %    \meta{Terminal} is any sequence of letters and evaluates to
1912 %    \meta{true} iff it occurs in the list of options that have to be
1913 %    included.
1914 % \MakeShortVerb\|
1916 %    Since we can generate multiple output files  from  one  input,
1917 %    same  guard  expressions  can  be  computed several times with
1918 %    different options. For that reason we  first  ``compile''  the
1919 %    expression   to  the  form  of  one  parameter  macro  |\Expr|
1920 %    expanding to nested |\if|s that when  given  current  list  of
1921 %    options  produces  1  or  0  as  a  result. The idea is to say
1922 %    |\if1\Expr{|\meta{current set  of  options}|}...\fi|  for  all
1923 %    output files.
1925 %    Here is a table recursively defining  translations  for  right
1926 %    sides  of the grammar. $\tau(X)$ denotes translation of~$X$.
1927 %    
1928 % \DeleteShortVerb\|
1929 % \MakeShortVerb\"
1930 %    \begingroup
1931 %     \addtolength\arraycolsep{-2.1pt}
1932 %    \begin{eqnarray*}
1933 %    \tau(\meta{Terminal})&=&"\t@<Terminal>,#1,<Terminal>,\qStop"\\
1934 %   \tau(!\meta{Primary})&=&"\if1"\,\tau(\meta{Primary})\,"0\else1\fi"\\
1935 %    \tau(\mbox{\texttt{(}\meta{Expression}\texttt{)}})
1936 %                         &=&\tau(\meta{Expression})\\
1937 %    \tau(\mbox{\meta{Primary}\texttt{\&}\meta{Secondary}})
1938 %                         &=&"\if0"\,\tau(\meta{Primary})\,"0\else"
1939 %                             \,\tau(\meta{Secondary})\,"\fi"\\
1940 %    \tau(\mbox{\meta{Secondary}\texttt{|}\meta{Expression}})
1941 %                         &=&"\if1"\,\tau(\meta{Secondary})\,"1\else"
1942 %                            \,\tau(\meta{Expression})\,"\fi"
1943 %    \end{eqnarray*}
1944 %    \endgroup
1945 % \DeleteShortVerb\"
1946 % \MakeShortVerb\|
1947 %    |\t@<Terminal>|  denotes macro with name constructed from |t@|
1948 %    with appended tokens of terminal. E.g., for terminal |foo|  the
1949 %    translation would be
1950 %\begin{verbatim}
1951 %    \t@foo,#1,foo,\qStop
1952 %\end{verbatim}
1953 %    This will  end up in definition of |\Expr|,  so |#1| here will
1954 %    be substituted by current list  of  options  when  |\Expr|  is
1955 %    called. Macro |\t@foo| would be defined as
1956 %\begin{verbatim}
1957 %    \def\t@foo#1,foo,#2\qStop{\ifx>#2>0\else1\fi}
1958 %\end{verbatim}
1959 %    When  called  as  above  this  will  expand to |1| if |foo| is
1960 %    present on current list of options and to |0| otherwise.
1962 %    Macros  below  work  in  ``almost  expand-only''   mode   i.e.
1963 %    expression is analyzed only by expansion but we have to define
1964 %    some macros on the way (e.g., |\Expr| and |\t@foo|).
1966 %    The   first   parameter   of   each   of   these   macros   is
1967 %    ``continuation''   (in  the  sense  similar  to  the  language
1968 %    \textsc{Scheme}). Continuation is a function of at  least  one
1969 %    argument  (parameter)  being  the  value  of previous steps of
1970 %    computation.   For   example   macro   |\Primary|   constructs
1971 %    translation of \meta{Primary} expression. When it decides that
1972 %    expression is completed it calls its continuation  (its  first
1973 %    argument)   passing   to  it  whole  constructed  translation.
1974 %    Continuation may expect more arguments if it wants to see what
1975 %    comes next on the input.
1977 %    We  will perform recursive descent parse, but definitions will
1978 %    be presented in bottom-up order.
1980 % \begin{macro}{\Terminal}
1982 %    \meta{Terminal}s are  recognized  by  macro  |\Terminal|.  The
1983 %    proper   way   of   calling  it  is  |\Terminal{|\meta{current
1984 %    continuation}|}{}|.     Parameters     are:      continuation,
1985 %    \meta{Terminal}  so  far  and  next  character from the input.
1986 %    Macro checks if |#3| is one of terminal-ending characters  and
1987 %    then  takes  appropriate  actions.  Since  there  are 7 ending
1988 %    chars  and probably one |\csname| costs  less  than  7  nested
1989 %    |\if|s we construct a name and check if it is defined.
1991 %    We must expand |\ifx| completely before taking next actions so
1992 %    we use |\afterfi|.
1993 %    \begin{macrocode}
1994 \def\Terminal#1#2#3{%
1995   \expandafter\ifx\csname eT@#3\endcsname\relax
1996 %    \end{macrocode}
1997 %    If condition is true |#3| belongs to  current  \meta{Terminal}
1998 %    so we append it to \meta{Terminal}-so-far and call |\Terminal|
1999 %    again. 
2000 %    \begin{macrocode}
2001     \afterfi{\Terminal{#1}{#2#3}}\else
2002 %    \end{macrocode}
2003 %    When condition is false it's time to end  the  \meta{Terminal}
2004 %    so we call macro |\TerminalX|. Next character is reinserted to
2005 %    the input.
2007 %    In both cases continuation is passed unchanged.
2008 %    \begin{macrocode}
2009     \afterfi{\TerminalX{#1}{#2}#3}\fi
2010   }
2011 %    \end{macrocode}
2012 % \end{macro}
2014 % \begin{macro}{\eT@}
2015 %    Here we define macros marking characters  that  cannot  appear
2016 %    inside  terminal.  The value is not important as long as it is
2017 %    different from |\relax|.
2018 %    \begin{macrocode}
2019 \Name\let{eT@>}=1
2020 \Name\let{eT@&}=1 \Name\let{eT@!}=1
2021 \Name\let{eT@|}=1 \Name\let{eT@,}=1
2022 \Name\let{eT@(}=1 \Name\let{eT@)}=1
2023 %    \end{macrocode}
2024 % \end{macro}
2026 % \begin{macro}{\TerminalX}
2027 %    This macro should end scanning of \meta{Terminal}.  Parameters
2028 %    are continuation and gathered tokens of \meta{Terminal}.
2030 %    Macro starts by issuing an error message if \meta{Terminal} is
2031 %    empty.
2032 %    \begin{macrocode}
2033 \def\TerminalX#1#2{%
2034   \ifx>#2> \errmessage{Error in expression: empty terminal}\fi
2035 %    \end{macrocode}
2036 %    Then  a  macro  is  constructed  for  checking   presence   of
2037 %    \meta{Terminal} in options list.
2038 %    \begin{macrocode}
2039   \Name\def{t@#2}##1,#2,##2\qStop{\ifx>##2>0\else1\fi}%
2040 %    \end{macrocode}
2041 %    And  then  current  continuation is called with translation of
2042 %    \meta{Terminal} according to formula
2043 %    $$\tau(\meta{Terminal})=|\t@<Terminal>,#1,<Terminal>,\qStop|$$
2044 %    \begin{macrocode}
2045   #1{\Name\noexpand{t@#2},##1,#2,\noexpand\qStop}%
2046   }
2047 %    \end{macrocode}
2048 % \end{macro}
2050 % \begin{macro}{\Primary}
2051 %    Parameters are continuation and next character from the input.
2052 %    
2053 %    According to the syntax \meta{Primari}es can have three forms.
2054 %    This  makes us use even more dirty tricks than usual. Note the
2055 %    |\space| after a series of |\ifx|s. This  series  produces  an
2056 %    one  digit  number of case to be executed. The number is given
2057 %    to  |\ifcase|  and  |\space|  stops  \TeX{}  scanning  for   a
2058 %    \meta{number}.  Use of |\ifcase| gives possibility to have one
2059 %    of three actions  selected  without  placing  them  in  nested
2060 %    |\if|s and so to use |\afterfi|.
2061 %    \begin{macrocode}
2062 \def\Primary#1#2{%
2063   \ifcase \ifx!#20\else\ifx(#21\else2\fi\fi\space 
2064 %    \end{macrocode}
2065 %    First case is for |!| i.e.  negated \meta{Primary}.   In  this
2066 %    case   we  call  |\Primary|  recursively  but  we  create  new
2067 %    continuation:   macro  |\NPrimary|  that  will  negate  result
2068 %    passed  by  |\Primary|  and  pass  it  to current continuation
2069 %    (|#1|).
2070 %    \begin{macrocode}
2071   \afterfi{\Primary{\NPrimary{#1}}}\or
2072 %    \end{macrocode}
2073 %    When next character is |(| we call |\Expression| giving it  as
2074 %    continuation  macro  |\PExpression|  which  will just pass the
2075 %    result up but ensuring first that a |)| comes next.
2076 %    \begin{macrocode}
2077   \afterfi{\Expression{\PExpression{#1}}}\or
2078 %    \end{macrocode}
2079 %    Otherwise we start a \meta{Terminal}. |#2| is  not  passed  as
2080 %    \meta{Terminal}-so-far  but reinserted to input since we didn't
2081 %    check if it can appear in a \meta{Terminal}.
2082 %    \begin{macrocode}
2083   \afterfi{\Terminal{#1}{}#2}\fi
2084   }
2085 %    \end{macrocode}
2086 % \end{macro}
2088 % \begin{macro}{\NPrimary}
2089 %    Parameters    are   continuation   and   previously   computed
2090 %    \meta{Primary}.
2091 %    
2092 %    This macro negates result of previous  computations  according
2093 %    to the rule
2094 %    $$\tau(!\meta{Primary})
2095 %         =|\if1|\,\tau(\meta{Primary})\,|0\else1\fi|$$
2096 %    \begin{macrocode}
2097 \def\NPrimary#1#2{%
2098   #1{\noexpand\if1#20\noexpand\else1\noexpand\fi}%
2099   }
2100 %    \end{macrocode}   
2101 % \end{macro}
2103 % \begin{macro}{\PExpression}
2104 %    Parameters: continuation,  \meta{Expression},  next  character
2105 %    from  input. We are checking if character is |)| and then pass
2106 %    unchanged result to our continuation.
2107 %    \begin{macrocode}
2108 \def\PExpression#1#2#3{% 
2109   \ifx)#3\else
2110     \errmessage{Error in expression: expected right parenthesis}\fi
2111   #1{#2}}
2112 %    \end{macrocode}
2113 % \end{macro}
2115 % \begin{macro}{\Secondary}
2116 %    Each \meta{Secondary} expression starts  with  \meta{Primary}.
2117 %    Next checks will be performed by |\SecondaryX|.
2118 %    \begin{macrocode}
2119 \def\Secondary#1{%
2120   \Primary{\SecondaryX{#1}}}
2121 %    \end{macrocode}
2122 % \end{macro}
2124 % \begin{macro}{\SecondaryX}
2125 %    Parameters:  continuation, translation of \meta{Primary}, next
2126 %    character. We start by checking if next character is |&|.
2127 %    \begin{macrocode}
2128 \bgroup\catcode`\&=12
2129 \gdef\SecondaryX#1#2#3{%
2130   \ifx&#3%
2131 %    \end{macrocode}
2132 %    If it is  we  should  parse  next  \meta{Secondary}  and  then
2133 %    combine  it with results so far. Note that |\SecondaryXX| will
2134 %    have 3 parameters.
2135 %    \begin{macrocode}
2136   \afterfi{\Secondary{\SecondaryXX{#1}{#2}}}\else
2137 %    \end{macrocode}
2138 %    Otherwise   \meta{Secondary}   turned   out   to    be    just
2139 %    \meta{Primary}. We call continuation passing to it translation
2140 %    of that \meta{Primary} not forgetting to reinsert |#3| to  the
2141 %    input as it does not belong here.
2142 %    \begin{macrocode}
2143   \afterfi{#1{#2}#3}\fi
2144   }
2145 \egroup
2146 %    \end{macrocode}   
2147 % \end{macro}
2149 % \begin{macro}{\SecondaryXX}
2150 %    Parameters:   continuation,   translation  of  \meta{Primary},
2151 %    translation of \meta{Secondary}. We construct  translation  of
2152 %    whole construction according to the rule:
2153 %    $$\tau(\mbox{\meta{Primary}\texttt{\&}\meta{Secondary}})
2154 %                         =|\if0|\,\tau(\meta{Primary})\,|0\else|
2155 %                             \,\tau(\meta{Secondary})\,|\fi| $$
2156 %    and pass it to our continuation.
2157 %    \begin{macrocode}
2158 \def\SecondaryXX#1#2#3{%
2159   #1{\noexpand\if0#20\noexpand\else#3\noexpand\fi}}
2160 %    \end{macrocode}
2161 % \end{macro}
2163 % \begin{macro}{\Expression}
2164 %    Every   \meta{Expression}  starts  with  \meta{Secondary}.  We
2165 %    construct new continuation and pass it to |\Secondary|.
2166 %    \begin{macrocode}
2167 \def\Expression#1{%
2168   \Secondary{\ExpressionX{#1}}}
2169 %    \end{macrocode}   
2170 % \end{macro}
2172 % \begin{macro}{\ExpressionX}
2173 %    Parameters:  continuation,  translation  of  \meta{Secondary},
2174 %    next   character.   We   perform   check   if   character   is
2175 %    \texttt{\char`\|} or |,|.
2176 %    \begin{macrocode}
2177 \def\ExpressionX#1#2#3{%
2178   \if0\ifx|#31\else\ifx,#31\fi\fi0
2179 %    \end{macrocode}
2180 %    If it is not \meta{Expression} is just a \meta{Secondary}.  We
2181 %    pass its translation to continuation and reinsert |#3|.
2182 %    \begin{macrocode}
2183   \afterfi{#1{#2}#3}\else
2184 %    \end{macrocode}
2185 %    If  we  are  dealing  with complex \meta{Expression} we should
2186 %    parse another |\Expression| now.
2187 %    \begin{macrocode}
2188   \afterfi{\Expression{\ExpressionXX{#1}{#2}}}\fi
2189   }
2190 %    \end{macrocode}
2191 % \end{macro}
2193 % \begin{macro}{\ExpressionXX}
2194 %    Parameters:  continuation,  translation  of  \meta{Secondary},
2195 %    translation of \meta{Expression}.
2196 %    We finish up translating  of  \meta{Expression}  according  to   
2197 %    the formula:
2198 %    $$\tau(\mbox{\meta{Secondary}\texttt{\char`\|}\meta{Expression}})
2199 %                         =|\if1|\,\tau(\meta{Secondary})\,|1\else|
2200 %                            \,\tau(\meta{Expression})\,|\fi|$$
2201 %    \begin{macrocode}
2202 \def\ExpressionXX#1#2#3{%
2203   #1{\noexpand\if1#21\noexpand\else#3\noexpand\fi}}
2204 %    \end{macrocode}   
2205 % \end{macro}
2207 % \begin{macro}{\StopParse}
2208 %    Here is initial continuation for whole parse process. It  will
2209 %    be  used  by  |\Evaluate|. Note that we assume that expression
2210 %    has |>| on its end.  This macro  eventually  defines  |\Expr|.
2211 %    Parameters:   translation  of whole \meta{Expression} and next
2212 %    character from input.
2213 %    \begin{macrocode}
2214 \def\StopParse#1#2{%
2215   \ifx>#2 \else\errmessage{Error in expression: spurious #2}\fi
2216   \edef\Expr##1{#1}}
2217 %    \end{macrocode}
2218 % \end{macro}
2220 % \begin{macro}{\Evaluate}   
2221 %    This macro is used to start  parsing.  We  call  |\Expression|
2222 %    with  continuation  defined  above.   On  end of expression we
2223 %    append a |>|.
2224 %    \begin{macrocode}
2225 \def\Evaluate#1{%
2226   \Expression\StopParse#1>}
2227 %    \end{macrocode}
2228 % \end{macro}
2230 % \subsection{Processing the input lines}
2232 % \begin{macro}{\normalLine}
2233 %    The macro |\normalLine| writes its argument (which has to be
2234 %    delimited with |\endLine|) on all active output files i.e.
2235 %    those with off-counters equal to zero.
2236 %    If statistics are included, the counter
2237 %    |\codeLinesPassed| is incremented by $1$.
2238 %    \begin{macrocode}
2239 \def\normalLine#1\endLine{%
2240 %<*stats>
2241   \advance\codeLinesPassed\@ne
2242 %</stats>
2243   \maybeMsg{.}%
2244   \def\inLine{#1}%
2245   \let\do\putline@do
2246   \activefiles
2247   }
2248 %    \end{macrocode}
2249 % \end{macro}
2251 % \begin{macro}{\putline@do}
2252 % \changes{2.3b}{1995/08/22}{Change for pre-constructed
2253 %                            off-counters' names}
2254 %    This is a value for |\do| when copying line to output files.
2255 %    \begin{macrocode}
2256 \def\putline@do#1#2#3{%
2257   \StreamPut#1{\inLine}}
2258 %    \end{macrocode}
2259 % \end{macro}
2261 % \begin{macro}{\removeComment}
2262 %    The macro |\removeComment| throws its argument (which has to be
2263 %    delimited with |\endLine|) away. When statistics are included
2264 %    in the program the removed comment is counted.
2265 %    \begin{macrocode}
2267 \def\removeComment#1\endLine{%
2268 %<*stats>
2269     \advance\commentsRemoved\@ne
2270 %</stats>
2271     \maybeMsg{\perCent}}
2272 %    \end{macrocode}
2273 % \end{macro}
2275 % \begin{macro}{\putMetaComment}
2276 % \changes{2.3e}{1996/09/16}{Introduced \cs{MetaPrefix}}
2277 %    If a line starts with two consecutive percent signs, it is
2278 %    considered to be a {\em MetaComment\/}. Such a comment line is
2279 %    passed on to the output file unmodified.
2280 %    \begin{macrocode}
2281 \bgroup\catcode`\%=12
2282 \iden{\egroup
2283 \def\putMetaComment%}#1\endLine{%
2284 %    \end{macrocode}
2285 %    If statistics are included the line is counted.
2286 %    \begin{macrocode}
2287 %<*stats>
2288   \advance\commentsPassed\@ne
2289 %</stats>
2290 %    \end{macrocode}
2291 %    The macro |\putMetaComment| has one argument, delimited with
2292 %    |\endLine|. It brings the source line with |%%| stripped. We
2293 %    prepend to it |\MetaPrefix| (which can be different from |%%|)
2294 %    and send the line to all active files. 
2295 %    \begin{macrocode}
2296   \edef\inLine{\MetaPrefix#1}%
2297   \let\do\putline@do
2298   \activefiles
2299   }
2300 %    \end{macrocode}
2301 % \end{macro}
2304 % \begin{macro}{\processLine}
2305 % \changes{2.3a}{1995/08/18}{Adaptation for concurrent version}
2306 % \changes{2.3a}{1995/08/20}{Trying to avoid assignments}
2307 %    Each line that is read from the input stream has to be processed
2308 %    to see if it has to be written on the output stream. This task
2309 %    is performed by calling the macro |\processLine|.
2310 %    In order to do
2311 %    that, it needs to check whether the line starts with a
2312 %    `\texttt{\%}'.  Therefore the macro is globally defined within a
2313 %    group. Within this group the category code of `\texttt{\%}' is
2314 %    changed to 12 (other).  Because a comment character is needed,
2315 %    the category code of `\texttt{*}' is changed to 14 (comment
2316 %    character).
2318 %    The macro increments counter |\processedLines| by $1$ if
2319 %    statistics are included. We cannot include this line with
2320 %    |%<*stats>| since the category of \texttt{\%} is changed and the
2321 %    file must be loadable unstripped. So the whole definition is
2322 %    repeated embedded in guards.
2324 %    The next token from the input stream is passed in |#1|. If it is
2325 %    a `\texttt{\%}' further processing has to be done by
2326 %    |\processLineX|; otherwise this is normal (not commented out)
2327 %    line.
2328 %    
2329 %    In either case the character read is reinserted to the input
2330 %    as it may have to be written out.
2332 %    \begin{macrocode}
2333 %<*!stats>
2334 \begingroup
2335 \catcode`\%=12 \catcode`\*=14
2336 \gdef\processLine#1{*
2337   \ifx%#1
2338     \expandafter\processLineX
2339   \else
2340     \expandafter\normalLine
2341   \fi
2342   #1}
2343 \endgroup
2344 %</!stats>
2345 %<*stats>
2346 \begingroup
2347 \catcode`\%=12 \catcode`\*=14
2348 \gdef\processLine#1{*
2349   \advance\processedLines\@ne
2350   \ifx%#1
2351     \expandafter\processLineX
2352   \else
2353     \expandafter\normalLine
2354   \fi
2355   #1}
2356 \endgroup
2357 %</stats>
2358 %    \end{macrocode}
2359 % \end{macro}
2362 % \begin{macro}{\processLineX}
2363 % \changes{2.3a}{1995/08/20}{Trying to avoid assignments}
2364 %    This macro is also defined within a group, 
2365 %    because it also has to check if the next
2366 %    token in the input stream is a `\texttt{\%}' character.
2368 %    If the second token in the current line happens to be a
2369 %    `\texttt{\%}', a \meta{MetaComment} has been found. This has to
2370 %    be copied in its entirety to the output.  Another possible second
2371 %    character is `\texttt{<}', which introduces a guard expression.
2372 %    The processing of such an expression is started by calling
2373 %    |\checkOption|.
2375 %    When the token was neither a `\texttt{\%}' nor a `\texttt{<}',
2376 %    the line contains a normal comment that has to be removed.
2378 %    We express conditions in such a way that all actions appear
2379 %    on first nesting level of |\if|s. In such conditions just one
2380 %    expandafter pushes us outside whole construction. A thing to
2381 %    watch here is |\relax|. It stops search for numeric constant.
2382 %    If it wasn't here \TeX\ would expand the first case of |\ifcase|
2383 %    before knowing the value.
2385 %    \begin{macrocode}
2386 \begingroup
2387 \catcode`\%=12 \catcode`\*=14
2388 \gdef\processLineX%#1{*
2389   \ifcase\ifx%#10\else
2390          \ifx<#11\else 2\fi\fi\relax
2391     \expandafter\putMetaComment\or
2392     \expandafter\checkOption\or
2393     \expandafter\removeComment\fi
2394   #1}
2395 \endgroup
2396 %    \end{macrocode}
2397 % \end{macro}
2399 % \subsection{The handling of options}
2401 % \begin{macro}{\checkOption}
2402 %    \changes{2.3a}{1995/08/18}{Adapted to concurrent version}
2403 %  \changes{2.3a}{1995/08/20}{Trying to avoid assignments}
2404 %  \changes{2.3e}{1996/09/16}{Verbatim mode}
2405 %    When the macros that process a line have found that the line
2406 %    starts with `\texttt{\%<}', a guard line has been encountered.
2407 %    The first character of a guard can be an asterisk (\texttt{*}), a
2408 %    slash (\texttt{/}) a plus (\texttt{+}), a minus (\texttt{-}), a
2409 %    less-than sign (\texttt{<}) starting verbatim mode or
2410 %    any other character that can be found in an option name. This
2411 %    means that we have to peek at the next token and 
2412 %    decide what kind of guard we have. 
2413 %    
2414 %    We reinsert |#1| as it may be needed by |\doOption|.
2415 %    \begin{macrocode}
2416 \def\checkOption<#1{%
2417   \ifcase
2418     \ifx*#10\else \ifx/#11\else
2419     \ifx+#12\else \ifx-#13\else
2420     \ifx<#14\else 5\fi\fi\fi\fi\fi\relax
2421   \expandafter\starOption\or
2422   \expandafter\slashOption\or
2423   \expandafter\plusOption\or
2424   \expandafter\minusOption\or
2425   \expandafter\verbOption\or
2426   \expandafter\doOption\fi
2427   #1}
2428 %    \end{macrocode}
2429 % \end{macro}
2431 % \begin{macro}{\doOption}
2432 %    When no guard modifier is found by |\checkOptions|, the
2433 %    macro |\doOption| is called. It evaluates a boolean
2434 %    expression. The result of this evaluation is stored in 
2435 %    |\Expr|. The guard only affects the current
2436 %    line,  so  |\do|  is  defined in such a way that depending on the
2437 %    result of the  test |\if1\Expr{|\meta{options}|}|,  the  current
2438 %    line is either copied to the output stream or removed. Then
2439 %    the test is computed for all active output files.
2440 %    \begin{macrocode}
2441 \def\doOption#1>#2\endLine{%
2442   \maybeMsg{<#1 . >}%
2443   \Evaluate{#1}%
2444   \def\do##1##2##3{%
2445     \if1\Expr{##2}\StreamPut##1{#2}\fi
2446     }%
2447   \activefiles
2448   }
2449 %    \end{macrocode}
2450 % \end{macro}
2452 % \begin{macro}{\plusOption}
2453 %    When a `\texttt{+}' is found as a guard modifier,
2454 %    |\plusOption| is called. This macro is very similar to
2455 %    |\doOption|, the only difference being that displayed
2456 %    message now contains `\texttt{+}'.
2457 %    \begin{macrocode}
2458 \def\plusOption+#1>#2\endLine{%
2459   \maybeMsg{<+#1 . >}%
2460   \Evaluate{#1}%
2461   \def\do##1##2##3{%
2462     \if1\Expr{##2}\StreamPut##1{#2}\fi
2463     }%
2464   \activefiles
2465   }
2466 %    \end{macrocode}
2467 % \end{macro}
2469 % \begin{macro}{\minusOption}
2470 %    When a `\texttt{-}' is found as a guard modifier,
2471 %    |\minusOption| is called. This macro is very similar to
2472 %    |\plusOption|, the difference is that condition is negated.
2473 %    \begin{macrocode}
2474 \def\minusOption-#1>#2\endLine{%
2475   \maybeMsg{<-#1 . >}%
2476   \Evaluate{#1}%
2477   \def\do##1##2##3{%
2478     \if1\Expr{##2}\else \StreamPut##1{#2}\fi
2479     }%
2480   \activefiles
2481   }
2482 %    \end{macrocode}
2483 % \end{macro}
2485 % \begin{macro}{\starOption}
2486 %    \changes{2.3a}{1995/08/18}{Adapted to concurrent version}
2487 %    When a `\texttt{*}' is found as a guard modifier,
2488 %    |\starOption| is called. In this case a block of code will
2489 %    be included in the output on the condition that the guard
2490 %    expression evaluates to \meta{true}.
2492 %    The current line is gobbled as |#2|, because it only contains
2493 %    the guard and possibly a comment.
2495 %    \begin{macrocode}
2496 \def\starOption*#1>#2\endLine{%
2497 %    \end{macrocode}
2498 %    First we optionally write
2499 %    a message to the terminal to indicate that a new option starts
2500 %    here.
2501 %    \begin{macrocode}
2502   \maybeMsg{<*#1}%
2503 %    \end{macrocode}
2504 %    Then we push the current contents of |\blockHead| on the
2505 %    stack of blocks, |\guardStack| and increment  the counter
2506 %    |\blockLevel| to indicate that we are now one level of
2507 %    nesting deeper.
2508 % \changes{2.0k}{1992/04/06}{Use new stack mechanism}
2509 % \changes{2.0k}{1992/04/09}{The macro that holds the guard needs to be
2510 %    expanded}
2511 %    \begin{macrocode}
2512   \expandafter\push\expandafter\guardStack\expandafter{\blockHead}%
2513   \advance\blockLevel\@ne
2514 %    \end{macrocode}
2515 %    The guard for this block of code is now stored in
2516 %    |\blockHead|.
2517 %    \begin{macrocode}
2518   \def\blockHead{#1}%
2519 %    \end{macrocode}
2520 %    Now we evaluate guard expression for all output files 
2521 %    updating off-counters. Then we create new list of active
2522 %    output files. Only files that were active in the outer block
2523 %    can remain active now.
2524 %    \begin{macrocode}
2525   \Evaluate{#1}%
2526   \let\do\checkguard@do
2527   \outputfiles
2528   \let\do\findactive@do
2529   \edef\activefiles{\activefiles}
2530   }
2531 %    \end{macrocode}
2532 % \end{macro}
2534 % \begin{macro}{\checkguard@do}
2535 % \changes{2.3b}{1995/08/22}{Change for pre-constructed
2536 %                            off-counters' names}
2537 %    This form of |\do| updates off-counts according to the value of
2538 %    guard expression.
2539 %    \begin{macrocode}
2540 \def\checkguard@do#1#2#3{%
2541 %    \end{macrocode}
2542 %    If this block of code occurs inside another block of code that is
2543 %    {\em not\/} included in the output, we increment the off counter.
2544 %    In that case the guard expression will not be
2545 %    evaluated, because a block inside another block that is excluded
2546 %    from the output will also be excluded, regardless of the
2547 %    evaluation of its guard.
2548 %    \begin{macrocode}
2549   \ifnum#3>0
2550     \advance#3\@ne
2551 %    \end{macrocode}
2552 %    When the off count has  value 0, we have
2553 %    to evaluate the guard expression. If the result is \meta{false}
2554 %    we increase the off-counter.
2555 %    \begin{macrocode}
2556   \else
2557     \if1\Expr{#2}\else
2558       \advance#3\@ne\fi
2559   \fi}
2560 %    \end{macrocode}
2561 % \end{macro}
2563 % \begin{macro}{\findactive@do}
2564 % \changes{2.3b}{1995/08/22}{Change for pre-constructed
2565 %                            off-counters' names}
2566 %    This form of |\do| picks elements of output files list which
2567 %    have off-counters equal to zero.
2568 %    \begin{macrocode}
2569 \def\findactive@do#1#2#3{%
2570   \ifnum#3=0
2571     \noexpand\do#1{#2}#3\fi}
2572 %    \end{macrocode}
2573 % \end{macro}
2575 % \begin{macro}{\slashOption}
2576 %    \changes{2.3a}{1995/08/18}{Adapted for concurrent version}
2577 %    The macro |\slashOption| is the counterpart to
2578 %    |\starOption|.  It indicates the end of a block of
2579 %    conditionally included code.  We store the argument in the
2580 %    temporary control sequence |\tmp|.
2581 %    \begin{macrocode}
2582 \def\slashOption/#1>#2\endLine{%
2583   \def\tmp{#1}%
2584 %    \end{macrocode}
2585 %    When the counter |\blockLevel| has a value less than $1$,
2586 %    this `end-of-block' line has no corresponding `start-of-block'.
2587 %    Therefore we signal an error and ignore this end of block.
2588 %    \begin{macrocode}
2589   \ifnum\blockLevel<\@ne
2590     \errmessage{Spurious end block </\tmp> ignored}%
2591 %    \end{macrocode}
2592 %    Next we compare the contents of |\tmp| with the contents
2593 %    of |\blockHead|. The latter macro contains the last guard for
2594 %    a block of code that was encountered. If the contents match, we
2595 %    pop the previous guard from the stack.
2596 %    \changes{2.0k}{1992/04/06}{Use new stack mechanism}
2597 %    \begin{macrocode}
2598   \else
2599     \ifx\tmp\blockHead
2600       \pop\guardStack\blockHead
2601 %    \end{macrocode}
2602 %    When the contents of the two macros don't match something is
2603 %    amiss. We signal this to the user, but accept the `end-of-block'.
2604 %\note{Is this the desired behaviour??}
2605 %    \begin{macrocode}
2606     \else
2607       \errmessage{Found </\tmp> instead of </\blockHead>}%
2608     \fi
2609 %    \end{macrocode}
2610 %    When the end of a block of optionally included code is encountered
2611 %    we optionally signal this on the terminal and decrement the counter
2612 %    |\blockLevel|.
2613 %    \begin{macrocode}
2614     \maybeMsg{>}%
2615     \advance\blockLevel\m@ne
2616 %    \end{macrocode}
2617 %    The last thing that has to be done is to decrement off-counters and
2618 %    make new list of active files. Now whole list of output files has
2619 %    to be searched since some inactive files could have been
2620 %    reactivated.
2621 %    \begin{macrocode}
2622   \let\do\closeguard@do
2623   \outputfiles
2624   \let\do\findactive@do
2625   \edef\activefiles{\outputfiles}
2626   \fi
2627   }
2628 %    \end{macrocode}
2629 % \end{macro}
2631 % \begin{macro}{\closeguard@do}
2632 % \changes{2.3b}{1995/08/22}{Change for pre-constructed
2633 %                            off-counters' names}
2634 %    This macro decrements non-zero off-counters.
2635 %    \begin{macrocode}
2636 \def\closeguard@do#1#2#3{%
2637   \ifnum#3>0
2638     \advance#3\m@ne
2639   \fi}
2640 %    \end{macrocode}
2641 % \end{macro}
2644 %  \begin{macro}{\verbOption}
2645 %  \changes{2.3e}{1996/09/16}{Macro added}
2646 %  \changes{2.4g}{1996/12/13}{Reset \cs{putline@do} for /2340}
2647 %    This macro is called when a line starts with |%<<|. It reads a
2648 %    bunch of lines in verbatim mode: the lines are passed unchanged
2649 %    to the output without even checking for starting |%|. This way of
2650 %    processing ends when a line containing only a percent sign
2651 %    followed by stop mark given on the |%<<| line is found.
2652 %    \begin{macrocode}
2653 \def\verbOption<#1\endLine{{%
2654   \edef\verbStop{\perCent#1}\maybeMsg{<<<}%
2655   \let\do\putline@do
2656   \loop
2657     \ifeof\inFile\errmessage{Source file ended while in verbatim
2658                              mode!}\fi
2659     \read\inFile to \inLine
2660   \if 1\ifx\inLine\verbStop 0\fi 1% if not inLine==verbStop
2661     \activefiles
2662     \maybeMsg{.}%
2663   \repeat
2664   \maybeMsg{>}%
2665   }}
2666 %    \end{macrocode}
2667 %  \end{macro}
2669 % \subsection{Batchfile commands}
2670 % \changes{2.3e}{1996/10/02}{Added doc}
2671 %    \ds{} keeps information needed to control inclusion of sources in
2672 %    several list structures. Lists are macros expanding to a series
2673 %    of calls to macro |\do| with two or three parameters. 
2674 %    Subsequently |\do| is redefined in various ways and list
2675 %    macros sometimes are executed to perform some action on every
2676 %    element, and sometimes are used inside an |\edef| to make new
2677 %    list of elements having some properties. For every input file
2678 %    \meta{infile} the following lists are kept:
2679 %    \begin{itemize}
2680 %    \item[\cs{b@}\meta{infile}] the ``open list''---names of all output
2681 %               files such that their generation should start with
2682 %               reading of \meta{infile},
2683 %    \item[\cs{o@}\meta{infile}] the ``output list''---names of all
2684 %               output files generated from that source together with
2685 %               suitable sets of options (guards),
2686 %    \item[\cs{e@}\meta{infile}] the ``close list''---names of all
2687 %               output files that should be closed when this source is
2688 %               read.
2689 %    \end{itemize}
2691 %    For every output file name \meta{outfile} \ds{} keeps following
2692 %    information: 
2693 %    \begin{itemize}
2694 %    \item[\cs{pth@}\meta{outfile}] full pathname (including file name),
2695 %    \item[\cs{ref@}\meta{outfile}] reference lines for the file,
2696 %    \item[\cs{in@}\meta{outfile}] names of all source files separated
2697 %               with spaces (needed by \cs{InFileName}),
2698 %    \item[\cs{pre@}\meta{outfile}] preamble template (as defined with
2699 %               |\declarepreamble|),
2700 %    \item[\cs{post@}\meta{outfile}] postamble template. 
2701 %    \end{itemize}
2703 % \begin{macro}{\generate}
2704 % \changes{2.3a}{1995/08/20}{Messages changed}
2705 % \changes{2.4a}{1996/06/06}{Repeat processing of files until all
2706 %                           done (MDW)}
2707 %    This macro executes its argument in a group. |\inputfiles| is
2708 %    a list of files to be read, |\filestogenerate| list of names
2709 %    of output files (needed for the message below). |\file|s
2710 %    contained in |#1| define |\inputfiles| in such a way that all
2711 %    that has to be done when the parameter is executed is to call
2712 %    this macro. |\inputfiles| command is called over and over again
2713 %    until no output files had to be postponed.
2714 %    \begin{macrocode}
2715 \def\generate#1{\begingroup
2716   \let\inputfiles\empty \let\filestogenerate\empty
2717   \let\file\@file
2718   #1
2719   \ifx\filestogenerate\empty\else
2720   \Msg{^^JGenerating file(s) \filestogenerate}\fi
2721   \def\inFileName{\csname in@\outFileName\endcsname}%
2722   \def\ReferenceLines{\csname ref@\outFileName\endcsname}%
2723   \processinputfiles
2724   \endgroup}
2725 %    \end{macrocode}
2726 % \end{macro}
2728 %  \begin{macro}{\processinputfiles}
2729 % \changes{2.4a}{1996/10/02}{Macro added (MW)}
2730 %    This is a recurrent function which processes input files until
2731 %    they are all gone.
2732 %    \begin{macrocode}
2733 \def\processinputfiles{%
2734   \let\newinputfiles\empty
2735   \inputfiles
2736   \let\inputfiles\newinputfiles
2737   \ifx\inputfiles\empty\else
2738     \expandafter\processinputfiles
2739   \fi
2740   }
2741 %    \end{macrocode}
2742 %  \end{macro}
2744 % \begin{macro}{\file}
2745 %    The first argument is the file to produce, the second
2746 %    argument contains the list of input files. Each entry should have
2747 %    the format
2748 %    \verb=\from{=\meta{filename.ext}\verb=}{=\meta{options}\verb=}=.
2750 % \changes{2.3a}{1995/08/20}{Messages changed}
2751 % ^^A   The macro starts by displaying a message on the terminal to
2752 % ^^A   indicate which file is going to be made.
2753 %    The switch |\ifGenerate| is initially set to \meta{true}.
2754 %    \begin{macrocode}
2755 \def\file#1#2{\errmessage{Command `\string\file' only allowed in
2756                           argument to `\string\generate'}}
2757 \def\@file#1{%
2758   \Generatetrue
2759 %    \end{macrocode}
2760 %    Next we construct full path name for output file and check if we
2761 %    have to be careful about overwriting existing files. If the user
2762 %    specified |\askforoverwritetrue| we will ask him if he wants to
2763 %    overwrite an existing file. Otherwise we simply go ahead.
2764 %    \begin{macrocode}
2765   \makepathname{#1}%
2766   \ifaskforoverwrite
2767 %    \end{macrocode}
2768 %    We try to open a file with the name of the output file for
2769 %    reading.  If this succeeds the file exists and we ask the user if
2770 %    he wants to overwrite the file.
2771 % \changes{2.0p}{1992/06/26}{Added \cs{WriteToDir} (FMi).}
2772 % \changes{2.3a}{1995/08/18}{Changed \cs{@empty} (which was undefined)
2773 %                            to \cs{empty}}
2774 % \changes{2.3e}{1995/09/25}{Changed \cs{WriteToDir} to \cs{destdir}}
2775 %    \begin{macrocode}
2776     \immediate\openin\inFile\@pathname\relax
2777     \ifeof\inFile\else
2778       \Ask\answer{File \@pathname\space already exists 
2779                   \ifx\empty\destdir somewhere \fi
2780                   on the system.^^J% 
2781                   Overwrite it%
2782                   \ifx\empty\destdir\space if necessary\fi
2783                   ? [y/n]}%
2784 %    \end{macrocode}
2785 %    We set the switch |\ifGenerate| according to his answer. We
2786 %    allow for both ``\texttt{y}'' and ``\texttt{yes}''.
2787 %    \begin{macrocode}
2788       \ifx\y  \answer \else
2789       \ifx\yes\answer \else
2790                       \Generatefalse\fi\fi\fi
2791 %    \end{macrocode}
2792 %    Don't forget to close the file just opened as we want to write
2793 %    to it.
2794 %    \begin{macrocode}
2795     \closein\inFile
2796   \fi
2797 %    \end{macrocode}
2798 % \changes{2.3e}{1995/09/25}{Destination directory handling}
2799 %   If file is to be generated we save its destination pathname  and
2800 %   pass control to macro |\@fileX|.
2801 %   Note that file name is turned into control sequence and |\else|
2802 %   branch is skipped before calling |\@fileX|.
2803 %    \begin{macrocode}
2804   \ifGenerate
2805   \Name\let{pth@#1}\@pathname
2806   \@addto\filestogenerate{\@pathname\space}%
2807   \Name\@fileX{#1\expandafter}%
2808   \else
2809 %    \end{macrocode}
2810 %    In case we were not allowed to overwrite an existing file
2811 %    we inform the user that we are {\em not\/} generating his file
2812 %    and we gobble |\from| specifications.
2813 %    \begin{macrocode}
2814     \Msg{Not generating file \@pathname^^J}%
2815   \expandafter\@gobble
2816   \fi
2817   }
2818 %    \end{macrocode}
2819 % \end{macro}
2821 % \begin{macro}{\@fileX}
2822 %    We put name of current output file in |\curout| and initialize
2823 %    |\curinfiles|  (the list of source files for this output file)
2824 %    to empty---these will be needed  by  |\from|.  Then  we  start
2825 %    defining preamble for the current file.
2826 %    \begin{macrocode}
2827 \def\@fileX#1#2{%
2828   \chardef#1=\stream@closed
2829   \def\curout{#1}%
2830   \let\curinfiles\empty
2831   \let\curinnames\empty
2832   \def\curref{\MetaPrefix ^^J%
2833               \MetaPrefix\space The original source files were:^^J%
2834               \MetaPrefix ^^J}%
2835 %    \end{macrocode}
2836 %    Next we execute second parameter. |\from|s will add reference
2837 %    lines to the preamble.
2838 %    \begin{macrocode}
2839   \let\from\@from \let\needed\@needed
2840   #2%
2841   \let\from\err@from \let\needed\err@needed
2842 %    \end{macrocode}
2843 %    We check order of input files.  
2844 %    \begin{macrocode}
2845   \checkorder
2846 %    \end{macrocode}
2847 %    Each |\from| clause defines |\curin| to be its first parameter.
2848 %    So now |\curin| holds name of last input file for current output
2849 %    file. This means that current output file should be closed after
2850 %    processing |\curin|. We add |#1| to proper `close list'.
2851 %    \begin{macrocode}
2852   \Name\@addto{e@\curin}{\noexpand\closeoutput{#1}}%
2853 %    \end{macrocode}
2854 %    Last we save all the interesting information about current file.
2855 %    \begin{macrocode}
2856   \Name\let{pre@\@stripstring#1\expandafter}\currentpreamble
2857   \Name\let{post@\@stripstring#1\expandafter}\currentpostamble
2858   \Name\edef{in@\@stripstring#1}{\expandafter\iden\curinnames}
2859   \Name\edef{ref@\@stripstring#1}{\curref}
2860   }
2861 %    \end{macrocode}
2862 % \end{macro}
2864 %  \begin{macro}{\checkorder}
2865 %    This macro checks  if  the order  of  files  in  |\curinfiles|
2866 %    agrees  with that of |\inputfiles|. The coding is somewhat
2867 %    clumsy.
2868 %    \begin{macrocode}
2869 \def\checkorder{%
2870   \expandafter\expandafter\expandafter
2871   \checkorderX\expandafter\curinfiles
2872   \expandafter\qStop\inputfiles\qStop
2873   }
2874 \def\checkorderX(#1)#2\qStop#3\qStop{%
2875   \def\tmp##1\readsource(#1)##2\qStop{%
2876     \ifx!##2! \order@error
2877     \else\ifx!#2!\else 
2878        \checkorderXX##2%
2879     \fi\fi}%
2880   \def\checkorderXX##1\readsource(#1)\fi\fi{\fi\fi
2881     \checkorderX#2\qStop##1\qStop}%
2882   \tmp#3\readsource(#1)\qStop
2883   }
2884 \def\order@error#1\fi\fi{\fi
2885   \errmessage{DOCSTRIP error: Incompatible order of input
2886               files specified for file
2887               `\iden{\expandafter\uptospace\curin} \qStop'.^^J
2888               Read DOCSTRIP documentation for explanation.^^J
2889               This is a serious problem, I'm exiting}\end
2890   }
2891 %    \end{macrocode}
2892 %  \end{macro}
2894 % \begin{macro}{\needed}
2895 % \changes{2.3c}{1995/08/24}{Macro added}     
2896 % \changes{2.3e}{1996/09/12}{Forced expansion of argument to fix a bug
2897 %                with filenames containing macros}
2898 % \begin{macro}{\@needed}
2899 %    This  macro  uniquizes  name  of  an  input  file  passed as a
2900 %    parameter and marks it as needed to  be  input.  It  is  used
2901 %    internally  by  |\from|, but can also be issued in argument to
2902 %    |\file| to influence the order in which files are read.
2903 %    \begin{macrocode}
2904 \def\needed#1{\errmessage{\string\needed\space can only be used in
2905                argument to \string\file}}
2906 \let\err@needed\needed
2907 \def\@needed#1{%
2908   \edef\reserved@a{#1}%
2909   \expandafter\@need@d\expandafter{\reserved@a}}
2910 \def\@need@d#1{%
2911   \@ifpresent{(#1)}\curinfiles
2912 %    \end{macrocode}
2913 %    If  |#1|  is present on list of input files for current output
2914 %    file we add a space on end of its name and try again. The idea
2915 %    is  to construct a name that will look different for \TeX\ but
2916 %    will lead to the same file when seen by operating system.
2917 %    \begin{macrocode}
2918     {\@need@d{#1 }}%
2919 %    \end{macrocode}
2920 %    When it is not we check if |#1| is  present  in  the  list  of
2921 %    files to be processed. If not we add it and initialize list of
2922 %    output files for that input and  list  of  output  files  that
2923 %    should   be  closed  when  this  file  closes.   We  also  add
2924 %    constructed name to |\curinfiles| and define  |\curin|  to  be
2925 %    able to access constructed name from |\@from|.
2926 %    \begin{macrocode}
2927     {\@ifpresent{\readsource(#1)}\inputfiles
2928        {}{\@addto\inputfiles{\noexpand\readsource(#1)}%
2929        \Name\let{b@#1}\empty
2930        \Name\let{o@#1}\empty
2931        \Name\let{e@#1}\empty}%
2932      \@addto\curinfiles{(#1)}%
2933      \def\curin{#1}}%
2934   }
2935 %    \end{macrocode}
2936 % \end{macro}
2937 % \end{macro}
2939 % \begin{macro}{\from}
2940 % \changes{2.3c}{1995/08/24}{part of code moved to \cs{needed}}     
2941 %    |\from| starts by adding a line to  preamble for output file.
2942 %    \begin{macrocode}
2943 \def\from#1#2{\errmessage{Command `\string\from' only allowed in
2944                           argument to `\string\file'}}
2945 \let\err@from\from
2946 \def\@from#1#2{%
2947   \@addto\curref{\MetaPrefix\space #1 \if>#2>\else
2948                               \space (with options: `#2')\fi^^J}%
2949 %    \end{macrocode}
2950 %    Then we mark the file as needed input file.
2951 %    \begin{macrocode}
2952   \needed{#1}%
2953 %    \end{macrocode}
2954 % \changes{2.3e}{1996/10/02}{Introduced ``open list''}
2955 %    If this is the first |\from| in current |\file| (i.e. if the
2956 %    |\curinnames| so far is empty) the file name is added to the
2957 %    ``open list'' for the current input file.
2958 %    And |\do|\meta{current output}|{|\meta{options}|}| is appended
2959 %    to the list of output files for current input file.
2960 %    \begin{macrocode}
2961   \ifx\curinnames\empty
2962      \Name\@addto{b@\curin}{\noexpand\openoutput\curout}%
2963   \fi
2964   \@addto\curinnames{ #1}%
2965   \Name\@addto{o@\curin}{\noexpand\do\curout{#2}}%
2966   }
2967 %    \end{macrocode}
2968 % \end{macro}
2970 % \begin{macro}{\readsource}
2971 % \changes{2.4a}{1996/06/06}{Extensively hacked to honour stream
2972 %                            limits (MDW)}
2973 % \changes{2.3a}{1995/08/18}{Renamed to \cs{readsource}; adaptation for
2974 %                            concurrent version}
2975 % \changes{2.0f}{1991/06/04}{Added check for lines with \texttt{\bsl
2976 %    endinput}} This macro is called for each input file that
2977 %    is to be processed.
2979 %    \begin{macrocode}
2980 \def\readsource(#1){%
2981 %    \end{macrocode}
2982 %    We try to open the input file. If this doesn't succeed, we
2983 %    tell the user so and nothing else happens.
2984 %    \begin{macrocode}
2985   \immediate\openin\inFile\uptospace#1 \qStop\relax
2986   \ifeof\inFile
2987     \errmessage{Cannot find file \uptospace#1 \qStop}%
2988   \else
2989 %    \end{macrocode}
2990 %    If statistics are included we nullify line counters
2991 %    \begin{macrocode}
2992 %<*stats>
2993     \processedLines\z@
2994     \commentsRemoved\z@
2995     \commentsPassed\z@
2996     \codeLinesPassed\z@
2997 %</stats>
2998 %    \end{macrocode}
2999 % \changes{2.3b}{1995/08/22}{Change for pre-constructed
3000 %                            off-counters' names}
3001 % \changes{2.3e}{1996/10/02}{Introduced ``open list''}
3002 %    When the input file was successfully opened, we try to open all
3003 %    needed output files by executing the ``open list''. 
3004 %    If any of files couldn't be opened because of number of streams
3005 %    limits, their names are put into |\refusedfiles| list. This list
3006 %    subsequently becomes the open list for the next pass.
3007 %    \begin{macrocode}
3008     \let\refusedfiles\empty
3009     \csname b@#1\endcsname
3010     \Name\let{b@#1}\refusedfiles
3011 %    \end{macrocode}
3012 %    Now all output files that could be opened are open. So we go
3013 %    through the ``output list'' and for every open file we display a
3014 %    message and zero the off-counter, while closed files are appended
3015 %    to |\refusedfiles|. 
3016 %    \begin{macrocode}
3017     \Msg{} \def\@msg{Processing file \uptospace#1 \qStop}
3018     \def\change@msg{%
3019       \edef\@msg{\@spaces\@spaces\@spaces\space
3020         \expandafter\tospaces\uptospace#1 \qStop\secapsot}
3021       \let\change@msg\relax}
3022     \let\do\showfiles@do
3023     \let\refusedfiles\empty
3024     \csname o@#1\endcsname
3025 %    \end{macrocode}
3026 %    If |\refusedfiles| is nonempty current source file needs reread,
3027 %    so we append it to |\newinputfiles|.
3028 %    \begin{macrocode}
3029     \ifx\refusedfiles\empty\else
3030       \@addto\newinputfiles{\noexpand\readsource(#1)}
3031     \fi
3032 %    \end{macrocode}
3033 %    Finally we define |\outputfiles| and construct off-counters
3034 %    names. Now |\do|s will have 3 parameters! All output files become
3035 %    active.
3036 %    \begin{macrocode}
3037     \let\do\makeoutlist@do
3038     \edef\outputfiles{\csname o@#1\endcsname}%
3039     \let\activefiles\outputfiles
3040     \Name\let{o@#1}\refusedfiles
3041 %    \end{macrocode}
3042 %    Now we change the category code of a lot of characters to
3043 %    \meta{other} and make sure that no extra spaces appear in the
3044 %    lines read by setting the |\endlinechar| to $-1$.
3045 %    \begin{macrocode}
3046     \makeOther\ \makeOther\\\makeOther\$%
3047     \makeOther\#\makeOther\^\makeOther\^^K%
3048     \makeOther\_\makeOther\^^A\makeOther\%%
3049     \makeOther\~\makeOther\{\makeOther\}\makeOther\&%
3050     \endlinechar-1\relax
3051 %    \end{macrocode}
3052 %    Then we start a loop to process the lines in the file one by one.
3053 %    \begin{macrocode}
3054     \loop
3055       \read\inFile to\inLine
3056 %    \end{macrocode}
3057 %    The first thing we check is whether the current line
3058 %    contains an |\endinput|. To allow also real |\endinput|
3059 %    commands in the source file, |\endinput| is only recognized
3060 %    when it occurs directly at the beginning of a line.
3061 %    \begin{macrocode}
3062       \ifx\inLine\Endinput
3063 %    \end{macrocode}
3064 %    In this case we output a message to inform the programmer (in
3065 %    case this was a mistake) and end the loop immediately by setting
3066 %    \verb=Continue= to \meta{false}. Note that |\endinput| is
3067 %    not placed into the output file. This is important in cases where
3068 %    the output file is generated from several \texttt{doc} files.
3069 %    \begin{macrocode}
3070         \Msg{File #1 ended by \string\endinput.}%
3071         \Continuefalse
3072       \else
3073 %    \end{macrocode}
3074 % \changes{2.0j}{1992/03/03}{First check for end of file before check
3075 %    for empty lines} When the end of the file is found we have to
3076 %    interrupt the loop.
3077 %    \begin{macrocode}
3078        \ifeof\inFile
3079          \Continuefalse
3080 %    \end{macrocode}
3081 % \changes{2.0i}{1991/06/27}{Added check for consecutive empty lines}
3082 %    If the file did not end we check if the input line is empty.
3083 %    If it is, the counter |\emptyLines| is incremented.
3084 %    \begin{macrocode}
3085        \else
3086          \Continuetrue
3087          \ifx\inLine\empty
3088             \advance\emptyLines\@ne
3089           \else
3090             \emptyLines\z@
3091           \fi
3092 %    \end{macrocode}
3093 %    When the number of empty lines seen so far exceeds 1, we skip them.
3094 %    If it doesn't, the expansion of |\inLine| is fed to |\processLine|
3095 %    with |\endLine| appended to indicate the end of the line.
3096 %    \begin{macrocode}
3097           \ifnum \emptyLines<2
3098             \expandafter\processLine\inLine\endLine
3099           \else
3100             \maybeMsg{/}%
3101           \fi
3102        \fi
3103       \fi
3104 %    \end{macrocode}
3105 %    When the processing of the line is finished, we check if there is
3106 %    more to do, in which case we repeat the loop.
3107 %    \begin{macrocode}
3108     \ifContinue
3109     \repeat
3110 %    \end{macrocode}
3111 %    The input file is closed.
3112 %    \begin{macrocode}
3113     \closein\inFile
3114 %    \end{macrocode}
3115 %    We close output files for which this was the last input file.
3116 %    \begin{macrocode}
3117   \csname e@#1\endcsname
3118 %    \end{macrocode}
3119 %    If the user was interested in statistics, we inform him of the
3120 %    number of lines processed, the number of comments that were
3121 %    either removed or passed and the number of codelines that were
3122 %    written to the output file. Also the totals are updated.
3123 %    \begin{macrocode}
3124 %<*stats>
3125     \Msg{Lines \space processed: \the\processedLines^^J%
3126          Comments removed: \the\commentsRemoved^^J%
3127          Comments \space passed: \the\commentsPassed^^J%
3128          Codelines passed: \the\codeLinesPassed^^J}%
3129       \global\advance\TotalprocessedLines  by \processedLines
3130       \global\advance\TotalcommentsRemoved by \commentsRemoved
3131       \global\advance\TotalcommentsPassed  by \commentsPassed
3132       \global\advance\TotalcodeLinesPassed by \codeLinesPassed
3133 %</stats>
3134 %    \end{macrocode}
3135 %    The |\NumberOfFiles| need to be known even if no statistics are
3136 %    gathered so we update it always.
3137 % \changes{2.4h}{1997/07/07}{update \cs{NumberOfFiles} even if stats are
3138 %      not gathered pr/2429}
3139 %    \begin{macrocode}
3140       \global\advance\NumberOfFiles by \@ne
3141     \fi}
3142 %    \end{macrocode}
3143 % \end{macro}
3145 %  \begin{macro}{\showfiles@do}
3146 % \changes{2.4a}{1996/10/02}{Macro added (MW)} 
3147 %    A message is displayed on the terminal telling the user what we
3148 %    are about to do. For each open output file we display one line
3149 %    saying what options it is generated with and the off-counter
3150 %    associated with the file is zeroed. First line contains also name
3151 %    of input file.
3152 %    Names of output files that are closed are appended to
3153 %    |\refusedfiles|. 
3154 %    \begin{macrocode}
3155 \def\showfiles@do#1#2{%
3156   \ifnum#1=\stream@closed
3157     \@addto\refusedfiles{\noexpand\do#1{#2}}%
3158   \else
3159     \Msg{\@msg
3160          \ifx>#2>\else\space(#2)\fi
3161          \space -> \@stripstring#1}
3162     \change@msg
3163   \csname off@\number#1\endcsname=\z@
3164   \fi
3166 %    \end{macrocode}
3167 %  \end{macro}
3169 % \begin{macro}{\makeoutlist@do}
3170 % \changes{2.3b}{1995/08/22}{Macro added --- pre-constructed
3171 %                            off-counters' names}
3172 %   This macro selects only open output files and constructs names for
3173 %   off-counters.
3174 %    \begin{macrocode}
3175 \def\makeoutlist@do#1#2{%
3176   \ifnum#1=\stream@closed\else
3177     \noexpand\do#1{#2}\csname off@\number#1\endcsname
3178   \fi}
3179 %    \end{macrocode}
3180 % \end{macro}
3182 % \begin{macro}{\openoutput}
3183 % \changes{2.3e}{1996/10/02}{Change for ``open lists'' -- renamed from
3184 %                            \cs{ensureopen@do}} 
3185 % \changes{2.4a}{1996/06/06}{Check whether there are streams left (MDW)}
3186 %    This macro opens output streams if possible.
3187 %    \begin{macrocode}
3188 \def\openoutput#1{%
3189 %    \end{macrocode}
3190 %    If both maxfile counters are non-zero\dots
3191 %    \begin{macrocode}
3192   \if 1\ifnum\@maxfiles=\z@ 0\fi
3193        \ifnum\@maxoutfiles=\z@ 0\fi1%
3194 %    \end{macrocode}
3195 %    \dots the stream may be opened and counters decremented. But if
3196 %    that cannot be done\dots
3197 %    \begin{macrocode}
3198     \advance\@maxfiles\m@ne
3199     \advance\@maxoutfiles\m@ne
3200     \StreamOpen#1%
3201     \WritePreamble#1%
3202   \else
3203 %    \end{macrocode}
3204 %    \dots the file is added to the ``refuse list''.
3205 %    \begin{macrocode}
3206      \@addto\refusedfiles{\noexpand\openoutput#1}%
3207   \fi
3208   }
3209 %    \end{macrocode}
3210 % \end{macro}
3212 % \begin{macro}{\closeoutput}
3213 % \changes{2.4a}{1996/06/06}
3214 %      {Don't close the file if it's not open (MDW)} 
3215 %    This macro closes open output stream when it is no longer
3216 %    needed and increments maxfiles counters.
3217 %    \begin{macrocode}
3218 \def\closeoutput#1{%
3219   \ifnum#1=\stream@closed\else
3220     \WritePostamble#1%
3221     \StreamClose#1%
3222     \advance\@maxfiles\@ne
3223     \advance\@maxoutfiles\@ne
3224   \fi}
3225 %    \end{macrocode}
3226 % \end{macro}
3228 % \subsubsection{Preamble and postamble}
3230 %  \begin{macro}{\ds@heading}
3231 % \changes{2.3e}{1996/09/16}{Macro added.}
3232 %    This is a couple of lines, stating what file is being written and
3233 %    how it was created. 
3234 %    \begin{macrocode}
3235 \def\ds@heading{%
3236   \MetaPrefix ^^J%
3237   \MetaPrefix\space This is file `\outFileName',^^J%
3238   \MetaPrefix\space  generated with the docstrip utility.^^J%
3239   }
3240 %    \end{macrocode}
3241 %  \end{macro}
3243 %  \begin{macro}{\AddGenerationDate}
3244 % \changes{2.3d}{1995/11/17}{(DPC) Macro added.}
3245 %  Older versions of \ds{} added the date that any file was generated
3246 % and the version number of \ds{}. This confused some people as they
3247 % mistook this for the version/date of the file that was being
3248 % written. So now this information is not normally written, but
3249 % a batch file may call this to get an old style header.
3250 %    \begin{macrocode}
3251 \def\AddGenerationDate{%
3252   \def\ds@heading{%
3253     \MetaPrefix ^^J%
3254     \MetaPrefix\space This is file `\outFileName', generated %
3255            on <\the\year/\the\month/\the\day> ^^J%
3256     \MetaPrefix\space with the docstrip utility (\fileversion).^^J%
3257  }}
3258 %    \end{macrocode}
3259 %  \end{macro}
3261 % \begin{macro}{\declarepreamble}
3262 % \changes{2.3a}{1995/08/18}{renamed from \cs{preamble};
3263 %                            interface changed}
3264 % \changes{2.0e}{1991/06/01}{Macro added.} 
3265 % \changes{2.3e}{1995/09/25}
3266 %     {Change for batchfiles working by \cs{input}}
3267 % \changes{2.3e}{1996/09/16}{Change to allow customization.}
3268 %    When a batch file is used the
3269 %    user can specify a preamble of his own that will be written to
3270 %    each file that is created. This can be useful to include an extra
3271 %    copyright notice in the stripped version of a file.  Also a
3272 %    warning that both versions of a file should {\em always\/} be
3273 %    distributed together could be written to a stripped file by
3274 %    including it in such a preamble.
3276 %    Every line that is written to |\outFile| that belongs to the
3277 %    preamble is preceded by two percent characters. This will prevent
3278 %    \ds{} from stripping these lines off the file.
3280 %    The preamble should be started with the macro
3281 %    |\declarepreamble|; it is ended by |\endpreamble|. All
3282 %    processing is done within a group in order to be able to locally
3283 %    change some values.
3285 %    |\ReferenceLines| is let equal |\relax| to be unexpandable.
3286 %    \begin{macrocode}
3287 \let\inFileName\relax
3288 \let\outFileName\relax
3289 \let\ReferenceLines\relax
3290 \def\declarepreamble{\begingroup
3291 \catcode`\^^M=13 \catcode`\ =12 %
3292 \declarepreambleX}
3293 {\catcode`\^^M=13 %
3294 \gdef\declarepreambleX#1#2
3295 \endpreamble{\endgroup%
3296   \def^^M{^^J\MetaPrefix\space}%
3297   \edef#1{\ds@heading%
3298           \ReferenceLines%
3299           \MetaPrefix\space\checkeoln#2\empty}}%
3300 \gdef\checkeoln#1{\ifx^^M#1\else\expandafter#1\fi}%
3302 %    \end{macrocode}
3303 % \end{macro}
3305 % \begin{macro}{\declarepostamble}
3306 % \changes{2.0e}{1991/06/01}{Macro added.}
3307 % \changes{2.3e}{1995/09/25}
3308 %     {Change for batchfiles working by \cs{input}}
3309 %    Just as a preamble can be
3310 %    specified in a batch file, the same can be done for a {\em
3311 %    post\/}amble.
3313 %    The definition of |\declarepostamble| is very much like the
3314 %    definition above of |\declarepreamble|.
3315 %    \begin{macrocode}
3316 \def\declarepostamble{\begingroup
3317 \catcode`\ =12 \catcode`\^^M=13
3318 \declarepostambleX}
3319 {\catcode`\^^M=13 %
3320 \gdef\declarepostambleX#1#2
3321 \endpostamble{\endgroup%
3322   \def^^M{^^J\MetaPrefix\space}%
3323   \edef#1{\MetaPrefix\space\checkeoln#2\empty^^J%
3324           \MetaPrefix ^^J%
3325           \MetaPrefix\space End of file `\outFileName'.%
3326   }}%
3328 %    \end{macrocode}
3329 % \end{macro}
3331 % \begin{macro}{\usepreamble}
3332 % \begin{macro}{\usepostamble}
3333 %    Macros for selecting [pre/post]amble to be used.
3334 %    \begin{macrocode}
3335 \def\usepreamble#1{\def\currentpreamble{#1}}
3336 \def\usepostamble#1{\def\currentpostamble{#1}}
3337 %    \end{macrocode}
3338 % \end{macro}
3339 % \end{macro}
3341 % \begin{macro}{\nopreamble}
3342 % \changes{2.4i}{1998/01/18}{Macro added. pr/2726}
3343 % \begin{macro}{\nopostamble}
3344 % \changes{2.4i}{1998/01/18}{Macro added. pr/2726}
3345 %    Shortcuts for disabling the writing of [pre/post]ambles.
3346 %    This is not done by disabling |\WritePreamble| or |\WritePostamble|
3347 %    since that wouldn't
3348 %    revertable afterwards. Instead the empty [pre/post]ambles are handled
3349 %    specially in those macros.
3350 %    \begin{macrocode}
3351 \def\nopreamble{\usepreamble\empty}
3352 \def\nopostamble{\usepostamble\empty}
3353 %    \end{macrocode}
3354 % \end{macro}
3355 % \end{macro}
3357 % \begin{macro}{\preamble}
3358 % \changes{2.3c}{1995/08/28}{Bug fixed: default preamble is now selected
3359 %                             not only defined}
3360 % \begin{macro}{\postamble}
3361 % \changes{2.3c}{1995/08/28}{As for \cs{preamble}}
3362 %    For backward compatibility we provide these macros defining
3363 %    default preamble and postamble.
3364 %    \begin{macrocode}
3365 \def\preamble{\usepreamble\defaultpreamble
3366   \declarepreamble\defaultpreamble}
3367 \def\postamble{\usepostamble\defaultpostamble
3368   \declarepostamble\defaultpostamble}
3369 %    \end{macrocode}   
3370 % \end{macro}
3371 % \end{macro}
3372 % \begin{macro}{\org@preamble}
3373 %  \changes{2.3a}{1995/08/18}{Macro added}
3374 % \changes{2.3c}{1995/11/16}{With \cs{inFileName} again}
3375 % \begin{macro}{\org@postamble}
3376 %  \changes{2.3a}{1995/08/18}{Macro added}
3377 %    Default values to use if nothing different is provided.
3378 % \changes{2.2j}{1995/08/06}{Updated default preamble}
3379 % \changes{2.5a}{1998/04/03}{Updated default preamble}
3380 %    \begin{macrocode}
3381 \declarepreamble\org@preamble
3383 IMPORTANT NOTICE:
3385 For the copyright see the source file.
3387 Any modified versions of this file must be renamed
3388 with new filenames distinct from \outFileName.
3390 For distribution of the original source see the terms
3391 for copying and modification in the file \inFileName.
3393 This generated file may be distributed as long as the
3394 original source files, as listed above, are part of the
3395 same distribution. (The sources need not necessarily be
3396 in the same archive or directory.)
3397 \endpreamble
3398 %    \end{macrocode}
3400 %    \begin{macrocode}
3401 \edef\org@postamble{\string\endinput^^J%
3402   \MetaPrefix ^^J%
3403   \MetaPrefix\space End of file `\outFileName'.%
3404   }
3405 %    \end{macrocode}
3407 %    \begin{macrocode}
3408 \let\defaultpreamble\org@preamble
3409 \let\defaultpostamble\org@postamble
3410 %    \end{macrocode}
3412 %    \begin{macrocode}
3413 \usepreamble\defaultpreamble
3414 \usepostamble\defaultpostamble
3415 %    \end{macrocode}
3416 % \end{macro}
3417 % \end{macro}
3419 % \begin{macro}{\originaldefault}
3420 % \changes{2.5a}{1998/04/03}{Macro added}
3421 % \changes{2.5b}{1998/04/28}{Macro renamed from \cs{orginaldefault} 
3422 %   to \cs{originaldefault}}
3423 % The default preamble header changed in v2.5 to allow distribution
3424 % of generated files as long as source also distributed. If you need
3425 % the original default, not allowing distribution of generated files
3426 % add |\usepreamble\originaldefault| to your .ins files.
3427 % Note then that your file can not be included in most TeX distributions
3428 % on CD which are distributed `pre-installed' with all \LaTeX\ files
3429 % extracted form th edocumented sources and moved to a suitable
3430 % directory in \TeX's search path.
3431 %    \begin{macrocode}
3432 \declarepreamble\originaldefault
3434 IMPORTANT NOTICE:
3436 For the copyright see the source file.
3438 You are *not* allowed to modify this file.
3440 You are *not* allowed to distribute this file.
3441 For distribution of the original source see the terms
3442 for copying and modification in the file \inFileName.
3444 \endpreamble
3445 %    \end{macrocode}
3446 % \end{macro}
3448 % \begin{macro}{\WritePreamble}
3449 % \changes{2.0e}{1991/06/01}{Macro added.}
3450 % \changes{2.3c}{1995/11/16}{Added definitions of \cs{inFileName} and
3451 %                            \cs{outFileName}}
3452 % \changes{2.3d}{1995/11/17}{(DPC) Macro added.}
3453 % \changes{2.4i}{1998/01/18}{Test for \cs{empty} postamble and
3454 %        don't write it out. pr/2726}
3455 %    \begin{macrocode}
3456 \def\WritePreamble#1{%
3457 %    \end{macrocode}
3458 %    We write out only non-empty preambles.
3459 %    \begin{macrocode}
3460   \expandafter\ifx\csname pre@\@stripstring#1\endcsname\empty
3461   \else
3462     \edef\outFileName{\@stripstring#1}%
3463 %    \end{macrocode}
3464 %    Then the reference lines that tell from what source file(s) the
3465 %    stripped file was created and user supplied preamble.
3466 %    \begin{macrocode}
3467     \StreamPut#1{\csname pre@\@stripstring#1\endcsname}%
3468   \fi}
3469 %    \end{macrocode}
3470 % \end{macro}
3472 % \begin{macro}{\WritePostamble}
3473 % \changes{2.0e}{1991/06/01}{Macro added.}
3474 % \changes{2.3c}{1995/11/16}{Added defs of \cs{inFileName} and
3475 %                            \cs{outFileName}}
3476 % \changes{2.4i}{1998/01/18}{Test for \cs{empty} postamble and
3477 %        don't write it out.  pr/2726}
3478 %    Postamble attributed to |#1| is written out. The
3479 %    last line written identifies the file again.
3480 %    \begin{macrocode}
3481 \def\WritePostamble#1{%
3482 %    \end{macrocode}
3483 %    We write out only non-empty postambles.
3484 %    \begin{macrocode}
3485   \expandafter\ifx\csname post@\@stripstring#1\endcsname\empty
3486   \else
3487     \edef\outFileName{\@stripstring#1}%
3488     \StreamPut#1{\csname post@\@stripstring#1\endcsname}%
3489   \fi}
3490 %    \end{macrocode}
3491 % \end{macro}
3493 % \subsection{Support for writing to specified directories}
3495 %    As we've seen before every output file is written to  directory
3496 %    specifed  by  the  value of |\destdir| current at the moment of
3497 %    this file's  |\file|  declaration.
3499 % \begin{macro}{\usedir}
3500 %  \changes{2.3e}{1995/09/15}{Macro added}
3501 %    This macro when called should translate its one argument into a
3502 %    directory name and define |\destdir| to that value.  The default
3503 %    for |\usedir| is to ignore its argument and return name of
3504 %    current directory (if known).  This can be changed by commands
3505 %    from |docstrip.cfg| file.
3507 %    |\showdirectory| is used just to display directory name for
3508 %    user's information.
3509 %    \begin{macrocode}
3510 \def\usedir#1{\edef\destdir{\WriteToDir}}
3511 \def\showdirectory#1{\WriteToDir}
3512 %    \end{macrocode}
3513 % \end{macro}
3515 % \begin{macro}{\BaseDirectory}
3516 % \changes{2.3e}{1995/09/15}{Macro added}
3517 % \changes{2.4e}{1996/10/22}{\cs{@setwritetodir} added (DPC)}
3518 %    This is config file command for specifing root directory of the 
3519 %    \TeX{}  hierarchy.  It enables the whole directory
3520 %    selecting mechanism by redefining |\usedir|.
3521 %    First make sure that the directory syntax commands have been set
3522 %    up by calling |\@setwritedir|, so that the value of |\dirsep|
3523 %   used by the |\edef| is (hopefully) correct.
3524 %    \begin{macrocode}
3525 \def\BaseDirectory#1{%
3526   \@setwritetodir
3527   \let\usedir\alt@usedir
3528   \let\showdirectory\showalt@directory
3529   \edef\basedir{#1\dirsep}}
3530 %    \end{macrocode}
3531 % \end{macro}
3533 % \begin{macro}{\convsep}
3534 % \changes{2.3e}{1995/09/15}{Macro added}
3535 %    This macro loops through slashes in its argument replacing them
3536 %    with  current  |\dirsep|.  It  should   be   called
3537 %    |\convsep some/directory/name/\qStop| (with slash on the end).
3538 %    \begin{macrocode}
3539 \def\convsep#1/#2\qStop{%
3540   #1\ifx\qStop#2\qStop \pesvnoc\fi\convsep\dirsep#2\qStop}
3541 \def\pesvnoc#1\qStop{\fi}
3542 %    \end{macrocode}
3543 % \end{macro}
3545 % \begin{macro}{\alt@usedir}
3546 % \changes{2.3e}{1995/09/15}{Macro added}
3547 %    Directory name construction macro enabling writing to various
3548 %    directories. 
3549 %    \begin{macrocode}
3550 \def\alt@usedir#1{%
3551   \Name\ifx{dir@#1}\relax
3552     \undefined@directory{#1}%
3553   \else 
3554     \edef\destdir{\csname dir@#1\endcsname}%
3555   \fi}
3556 \def\showalt@directory#1{%
3557   \Name\ifx{dir@#1}\relax
3558     \showundef@directory{#1}%
3559   \else\csname dir@#1\endcsname\fi}
3560 %    \end{macrocode}
3561 % \end{macro}
3563 %  \begin{macro}{\undefined@directory}
3564 % \changes{2.4a}{1996/10/04}{Macro added (MW)}
3565 % \changes{2.4e}{1996/10/22}{Help text added (DPC)}
3566 %    This macro comes into action when undefined label is spotted. The
3567 %    action is to raise an error and define |\destdir| to point to the
3568 %    current directory.
3569 %    \begin{macrocode}
3570 \def\undefined@directory#1{%
3571   \errhelp{docstrip.cfg should specify a target directory for^^J%
3572    #1 using \DeclareDir or \UseTDS.}%
3573   \errmessage{You haven't defined the output directory for `#1'.^^J%
3574             Subsequent files will be written to the current directory}%
3575   \let\destdir\WriteToDir
3576   }
3577 \def\showundef@directory#1{UNDEFINED (label is #1)}
3578 %    \end{macrocode}
3579 %  \end{macro}
3581 %  \begin{macro}{\undefined@TDSdirectory}
3582 % \changes{2.4a}{1996/10/04}{Macro added (MW)}
3583 %    This happens when label is undefined while using TDS. The label
3584 %    is converted to use proper separators and appended to base
3585 %    directory name.
3586 %    \begin{macrocode}
3587 \def\undefined@TDSdirectory#1{%
3588   \edef\destdir{%
3589     \basedir\convsep#1/\qStop
3590   }}
3591 \def\showundef@TDSdirectory#1{\basedir\convsep#1/\qStop}
3592 %    \end{macrocode}
3593 %  \end{macro}
3595 %  \begin{macro}{\UseTDS}
3596 % \changes{2.4a}{1996/10/04}{Macro added (MW)}
3597 % \changes{2.4e}{1996/10/22}{\cs{@setwritetodir} added (DPC)}
3598 %    Change of behaviour for undefined labels is done simply:
3599 %    \begin{macrocode}
3600 \def\UseTDS{%
3601   \@setwritetodir
3602   \let\undefined@directory\undefined@TDSdirectory
3603   \let\showundef@directory\showundef@TDSdirectory
3604   }
3605 %    \end{macrocode}
3606 %  \end{macro}
3608 % \begin{macro}{\DeclareDir}
3609 % \changes{2.3e}{1995/09/15}{Macro added}
3610 % \changes{2.4e}{1996/10/22}{\cs{@setwritetodir} added (DPC)}
3611 %    This macro remaps some directory name to another.
3612 %    \begin{macrocode}
3613 \def\DeclareDir{\@ifnextchar*{\DeclareDirX}{\DeclareDirX\basedir*}}
3614 \def\DeclareDirX#1*#2#3{%
3615   \@setwritetodir
3616   \Name\edef{dir@#2}{#1#3}}
3617 %    \end{macrocode}
3618 % \end{macro}
3621 % \subsubsection{Compatibility with older versions}
3623 % \begin{macro}{\generateFile}
3624 %    Main macro of previous versions of \ds.
3625 %    \begin{macrocode}
3626 \def\generateFile#1#2#3{{%
3627   \ifx t#2\askforoverwritetrue
3628   \else\askforoverwritefalse\fi
3629   \generate{\file{#1}{#3}}%
3630   }}    
3631 %    \end{macrocode}
3632 % \end{macro}
3634 %    To support command files that were written for the first version
3635 %    of \ds{} the commands |\include| and |\processFile|
3636 %    are defined here. The use of this interface is not recommended
3637 %    as it may be removed in a future release of \ds{}.
3639 % \begin{macro}{\include}
3640 % \changes{2.0f}{1991/06/04}{Macro added} To provide the \ds{} program
3641 %    with a list of options that should be included in the output the
3642 %    command \verb=\include{=\meta{Options}\verb=}= can be used. This
3643 %    macro is meant to be used in conjunction with the
3644 %    |\processFile| command.
3645 %    \begin{macrocode}
3646 \def\include#1{\def\Options{#1}}
3647 %    \end{macrocode}
3648 % \end{macro}
3650 % \begin{macro}{\processFile}
3651 % \changes{2.0f}{1991/06/04}{Supply \texttt{\bsl generateFile} with
3652 %                          \texttt{\bsl Options}}
3653 %\DeleteShortVerb\|
3654 %    The macro
3655 %    \verb=\processFile{=\meta{filename}\verb=}{=\meta{inext}\verb=}{=%
3656 %\unskip\meta{outext}\verb=}{=\meta{t{\fontshape{n}\ttfamily|}f}\verb=}=
3657 %    can be used when a single input file is used to produce
3658 %    a single output file. The macro is also used in the interactive
3659 %    mode of the \ds{} program.
3660 %\MakeShortVerb\|
3662 %    The arguments \meta{inext} and \meta{outext} denote the
3663 %    extensions of the input and output files respectively. The fourth
3664 %    argument can be used to specify if an existing file should be
3665 %    overwritten without asking. If \meta{t} is specified the program
3666 %    will ask for permission before overwriting an existing file.
3668 %    This macro is defined using the more generic macro |\generateFile|.
3669 %    \begin{macrocode}
3670 \def\processFile#1#2#3#4{%
3671   \generateFile{#1.#3}{#4}{\from{#1.#2}{\Options}}}
3672 %    \end{macrocode}
3673 % \end{macro}
3675 % \begin{macro}{\processfile}
3676 % \begin{macro}{\generatefile}
3677 % \changes{2.0m}{1991/04/23}{Now issue a warning when \cs{processfile}
3678 %     or \cs{generatefile} are used}
3679 %    Early
3680 %    versions of \ds{} defined |\processfile| and
3681 %    |\generatefile| instead of the commands as they are defined in
3682 %    this version. To remain upwards compatible, we still provide
3683 %    these commands, but issue a warning when they are used.
3684 %    \begin{macrocode}
3685 \def\processfile{\Msg{%
3686     ^^Jplease use \string\processFile\space instead of 
3687        \string\processfile!^^J}%
3688     \processFile}
3689 \def\generatefile{\Msg{%
3690     ^^Jplease use \string\generateFile\space instead of 
3691       \string\generatefile!^^J}%
3692     \generateFile}
3693 %    \end{macrocode}
3694 % \end{macro}
3695 % \end{macro}
3698 % \subsection{Limiting open file streams}
3700 % (This section was written by Mark Wooding)
3702 % \begin{macro}{\maxfiles}
3703 % \changes{2.4a}{1996/06/06}{Macro added (MDW)}
3704 % Some operating systems with duff libraries or other restrictions
3705 % can't cope with all the files which \ds\ tries to output at once.
3706 % A configuration file can say |\maxfiles{|\meta{number}|}| to
3707 % describe the maximum limit for the environment.
3709 % I'll need a counter for this value, so I'd better allocate one.
3711 %    \begin{macrocode}
3712 \newcount\@maxfiles
3713 %    \end{macrocode}
3715 % The configuration command |\maxfiles| is just slightly prettier than
3716 % an assignment, for \LaTeX\ people.  It also gives me an opportunity
3717 % to check that the limit is vaguely sensible.  I need at least 4
3718 % streams: 
3719 % \begin{enumerate}
3720 % \item A batch file.
3721 % \item A sub batch file, which \LaTeX's installation utility uses.
3722 % \item An input stream for reading an unstripped file.
3723 % \item An output stream for writing a stripped file.
3724 % \end{enumerate}
3726 %    \begin{macrocode}
3727 \def\maxfiles#1{%
3728   \@maxfiles#1\relax
3729   \ifnum\@maxfiles<4
3730     \errhelp{I'm not a magician.  I need at least four^^J%
3731              streams to be able to work properly, but^^J%
3732              you've only let me use \the\@maxfiles.}%
3733     \errmessage{\noexpand\maxfiles limit is too strict.}%
3734     \@maxfiles4
3735   \fi
3737 %    \end{macrocode}
3739 % \changes{2.4a}{1996/10/03}{No default limit since batchfiles are now
3740 %                            \cs{input} (MW)} 
3741 % Since batchfiles are now |\input|ed there should be no default limit
3742 % here. I'll just use some abstract large number.
3743 %    \begin{macrocode}
3744 \maxfiles{1972} % year of my birth (MW)
3745 %    \end{macrocode}
3747 % \end{macro}
3749 % \begin{macro}{\maxoutfiles}
3750 % \changes{2.4a}{1996/06/06}{Macro added (MDW)}
3752 % Maybe there's a restriction on just output streams.  (Well, there is:
3753 % I know, because \TeX\ only allows 16.)  I may as well allow the
3754 % configuration to set this up.
3756 % Again, I need a counter.
3758 %    \begin{macrocode}
3759 \newcount\@maxoutfiles
3760 %    \end{macrocode}
3762 % And now the macro.  I need at least one output stream which I think is
3763 % reasonable.
3765 %    \begin{macrocode}
3766 \def\maxoutfiles#1{%
3767   \@maxoutfiles=#1\relax
3768   \ifnum\@maxoutfiles<1
3769     \@maxoutfiles1
3770     \errhelp{I'm not a magician.  I need at least one output^^J%
3771              stream to be able to do anything useful at all.^^J%
3772              Please be reasonable.}%
3773     \errmessage{\noexpand\maxoutfiles limit is insane}%
3774   \fi
3776 %    \end{macrocode}
3778 % The default limit is 16, because that's what \TeX\ says.
3780 %    \begin{macrocode}
3781 \maxoutfiles{16}
3782 %    \end{macrocode}
3784 % \end{macro}
3786 % \begin{macro}{\checkfilelimit}
3788 % This checks the file limit when a new batch file is started.  If
3789 % there's fewer than two files left here, we're not going to be able
3790 % to strip any files.  The file limit counter is local to the group
3791 % which is set up around |\batchinput|, so that's all pretty cool.
3793 %    \begin{macrocode}
3794 \def\checkfilelimit{%
3795   \advance\@maxfiles\m@ne
3796   \ifnum\@maxfiles<2 %
3797     \errhelp{There aren't enough streams left to do any unpacking.^^J%
3798              I can't do anything about this, so complain at the^^J%
3799              person who made such a complicated installation.}%
3800     \errmessage{Too few streams left.}%
3801     \end
3802   \fi
3804 %    \end{macrocode}
3806 % \end{macro}
3808 % \subsection{Interaction with the user}
3810 % \begin{macro}{\strip@meaning}
3811 % Throw away the first part of |\meaning| output.
3812 % \changes{2.4c}{1996/06/11}{Macro added (DPC)}
3813 %    \begin{macrocode}
3814 \def\strip@meaning#1>{}
3815 %    \end{macrocode}
3816 % \end{macro}
3818 % \begin{macro}{\processbatchFile}
3819 % \changes{2.0f}{1991/06/04}{Macro added.}
3820 % \changes{2.3e}{1995/09/25}{Batch file is \cs{input}ed not \cs{read}}
3821 %    When \ds{} is run it always tries to use a batch file.
3823 %    For this purpose it calls the macro |\processbatchFile|. 
3825 % \changes{2.4a}{1996/06/06}
3826 %      {Added check for file limits (MDW)}
3827 % \changes{2.4c}{1996/06/11}
3828 %      {Add \cs{jobname} checks (DPC)}
3829 % \changes{2.4d}{1996/06/17}
3830 %      {Move \cs{jobname} checks to top level (DPC)}
3831 %    The first thing is to check if there are any input streams left.
3832 %    \begin{macrocode}
3833 \def\processbatchFile{%
3834   \checkfilelimit
3835   \let\next\relax
3836 %    \end{macrocode}
3837 %    Now we try to open the batch file for reading.
3838 %    \begin{macrocode}
3839   \openin\inputcheck \batchfile\relax
3840   \ifeof\inputcheck
3841 %    \end{macrocode}
3842 %    If we didn't succeed in opening the file, we assume that it does
3843 %    not exist. If we tried the default filename, we silently
3844 %    continue; the \ds{} program will switch to interactive mode in
3845 %    this case.
3846 %    \begin{macrocode}
3847     \ifDefault
3848     \else
3849 %    \end{macrocode}
3850 % \changes{2.4d}{1996/10/17}{Missing batchfile an error (DPC)}
3851 %    If we failed to open the user-supplied file, something is wrong
3852 %    and we warn him about it. This will also result in a switch to
3853 %    interactive mode.
3854 %    \begin{macrocode}
3855       \errhelp
3856         {A batchfile specified in \batchinput could not be found.}%
3857       \errmessage{^^J%
3858            **************************************************^^J%
3859            * Could not find your \string\batchfile=\batchfile.^^J%
3860            **************************************************}%
3861     \fi
3862   \else
3863 %    \end{macrocode}
3864 %    When we were successful in opening a file, we again have to check
3865 %    whether it was the default file. In that case we tell the user
3866 %    we found that file and ask him if he wants to use it.
3867 %    \begin{macrocode}
3868     \ifDefault
3869       \Msg{**************************************************^^J%
3870            * Batchfile \DefaultbatchFile\space found Use it? (y/n)?}%
3871       \Ask\answer{%
3872              **************************************************}%
3873     \else
3874 %    \end{macrocode}
3875 %    When it was the user-supplied file we can safely assume he wants
3876 %    to use it so we set |\answer| to \texttt{y}.
3877 %    \begin{macrocode}
3878       \let\answer\y
3879     \fi
3880 %    \end{macrocode}
3881 % If the macro |\answer| contains  a  \texttt{y}  we  can  read  in  the
3882 % batchfile. We do it in an indirect way---after completing |\if|s.
3883 %    \begin{macrocode}
3884     \ifx\answer\y
3885       \closein\inputcheck
3886       \def\next{\@@input\batchfile\relax}%
3887     \fi
3888   \fi
3889   \next}
3890 %    \end{macrocode}
3891 % \end{macro}
3893 % \begin{macro}{\ReportTotals}
3894 % \changes{2.0g}{1991/06/05}{Macro added.} The macro
3895 %    |\ReportTotals| can be used to report total statistics for
3896 %    all files processed. This code is only included in the program if
3897 %    the option \texttt{stats} is included.
3898 %    \begin{macrocode}
3899 %<*stats>
3900 \def\ReportTotals{%
3901   \ifnum\NumberOfFiles>\@ne
3902     \Msg{Overall statistics:^^J%
3903          Files \space processed: \the\NumberOfFiles^^J%
3904          Lines \space processed: \the\TotalprocessedLines^^J%
3905          Comments removed: \the\TotalcommentsRemoved^^J%
3906          Comments \space passed: \the\TotalcommentsPassed^^J%
3907          Codelines passed: \the\TotalcodeLinesPassed}%
3908   \fi}
3909 %</stats>
3910 %    \end{macrocode}
3911 % \end{macro}
3913 % \begin{macro}{\SetFileNames}
3914 %    The macro |\SetFileNames| is used when the program runs in
3915 %    interactive mode and the user was asked to supply extensions and
3916 %    a list of filenames.
3917 %    \begin{macrocode}
3918 \def\SetFileNames{%
3919     \edef\sourceFileName{\MainFileName.\infileext}%
3920     \edef\destFileName{\MainFileName.\outfileext}}
3921 %    \end{macrocode}
3922 % \end{macro}
3924 % \begin{macro}{\CheckFileNames}
3925 %    In interactive mode, the user gets asked for the extensions for
3926 %    the input and output files. Also the name or names of the input
3927 %    files (without extension) is asked for. Then the names of the
3928 %    input and output files are constructed from this information by
3929 %    |\SetFileNames|. This assumes that the name of the input file is
3930 %    the same as the name of the output file. But we should not write
3931 %    to the same file we're reading from so the extensions should
3932 %    differ.
3934 %    The macro |\CheckFileNames| makes sure that the output goes to a
3935 %    different file to the one where the input comes from.
3936 %    \begin{macrocode}
3937 \def\CheckFileNames{%
3938     \ifx\sourceFileName\destFileName
3939 %    \end{macrocode}
3940 %    If input and output files are the same we signal an error and stop
3941 %    processing.
3942 %    \begin{macrocode}
3943       \Msg{^^J%
3944      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!^^J%
3945      ! It is not possible to read from and write to the same file !^^J%
3946      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!^^J}%
3947       \Continuefalse
3948     \else
3949 %    \end{macrocode}
3950 %    If they are not the same we check if the input file exists by
3951 %    trying to open it for reading.
3952 %    \begin{macrocode}
3953       \Continuetrue
3954       \immediate\openin\inFile \sourceFileName\relax
3955       \ifeof\inFile
3956 %    \end{macrocode}
3957 %    If an end of file was found, the file couldn't be opened, so we
3958 %    signal an error and stop processing.
3959 %    \begin{macrocode}
3960         \Msg{^^J%
3961               !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!^^J%
3962               ! Your input file `\sourceFileName' was not found !^^J%
3963               !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!^^J}%
3964         \Continuefalse
3965       \else
3966 %    \end{macrocode}
3967 %    The last check we have to make is if the output file already
3968 %    exists.  Therefore we try to open it for reading.
3969 %    As a precaution we first close the input stream.
3970 % \changes{2.0p}{1992/06/26}{Added \cs{WriteToDir} (FMi).}
3971 % \changes{2.0r}{1992/08/17}{Use \cs{inFile} for reading}
3972 % \changes{2.0r}{1992/08/17}{Moved \cs{closein} statements}
3973 %    \begin{macrocode}
3974         \immediate\closein\inFile
3975         \immediate\openin\inFile\destdir \destFileName\relax
3976         \ifeof\inFile
3977 %    \end{macrocode}
3978 %    If this fails, it didn't exist and all is well.
3979 %    \begin{macrocode}
3980           \Continuetrue
3981         \else
3982 %    \end{macrocode}
3983 %    If opening of the output file for reading succeeded we have to
3984 %    ask the user if he wants to overwrite it. We assume he doesn't
3985 %    want to overwrite it, so the switch |\ifContinue| is initially
3986 %    set to \meta{false}. Only if he answers the question positively
3987 %    with `\texttt{y}' or `\texttt{yes}' we set the switch back to
3988 %    \meta{true}.
3989 % \changes{2.0p}{1992/06/26}{Changed question about overwriting.}
3990 %    \begin{macrocode}
3991           \Continuefalse
3992           \Ask\answer{File \destdir\destFileName\space already 
3993                       exists 
3994                       \ifx\empty\destdir somewhere \fi
3995                       on the system.^^J% 
3996                       Overwrite it%
3997                       \ifx\empty\destdir\space if necessary\fi
3998                       ? [y/n]}%
3999           \ifx\y  \answer \Continuetrue \else
4000           \ifx\yes\answer \Continuetrue \else
4001           \fi\fi
4002         \fi
4003 %    \end{macrocode}
4004 %    All checks have been performed now, so we can close any file that
4005 %    was opened just for this purpose.
4006 %    \begin{macrocode}
4007       \fi
4008     \fi
4009     \closein\inFile}
4010 %    \end{macrocode}
4011 % \end{macro}
4013 % \begin{macro}{\interactive}
4014 %    The macro |\interactive| implements the interactive mode of the
4015 %    \ds{} program. The macro is implemented using the
4016 %    \meta{while} construction. While the switch |\ifMoreFiles| remains
4017 %    true, we continue processing.
4018 %    \begin{macrocode}
4019 \def\interactive{%
4020   \whileswitch\ifMoreFiles\fi%
4021 %    \end{macrocode}
4022 %    To keep macro redefinitions local we start a group and ask the
4023 %    user some questions about what he wants us to do.
4024 %    \begin{macrocode}
4025    {\begingroup
4026       \AskQuestions
4027 %    \end{macrocode}
4028 %    The names of the files that have to be processed are stored as a
4029 %    comma-separated list in the macro |\filelist| by |\AskQuestions|.
4030 %    We use a \meta{for} loop to process the files one by one.
4031 %    \begin{macrocode}
4032       \forlist\MainFileName:=\filelist
4033       \do
4034 %    \end{macrocode}
4035 %    First the names of the input and output files are constructed
4036 %    and a check is made if all filename information is correct.
4037 %    \begin{macrocode}
4038         \SetFileNames
4039         \CheckFileNames
4040         \ifContinue
4041 %    \end{macrocode}
4042 %    If everything was well, produce output file.
4043 % \changes{2.0q}{1992/07/01}{Preceded filename by \cs{WriteToDir}}
4044 %    \begin{macrocode}
4045         \generateFile{\destFileName}{f}%
4046                      {\from{\sourceFileName}{\Options}}
4047         \fi%
4048 %    \end{macrocode}
4049 %    This process is repeated until |\filelist| is exhausted.
4050 %    \begin{macrocode}
4051       \od
4052     \endgroup
4053 %    \end{macrocode}
4054 %    Maybe the user wants more files to be processed, possibly with
4055 %    another set of options, so we give him the opportunity.
4056 %    \begin{macrocode}
4057     \Ask\answer{More files to process (y/n)?}%
4058     \ifx\y  \answer\MoreFilestrue \else
4059     \ifx\yes\answer\MoreFilestrue \else
4060 %    \end{macrocode}
4061 %    If he didn't want to process any more files, the switch
4062 %    |\ifMoreFiles| is set to \meta{false} in order to interrupt the
4063 %    \meta{while} loop.
4064 %    \begin{macrocode}
4065                    \MoreFilesfalse\fi\fi
4066    }}
4067 %    \end{macrocode}
4068 % \end{macro}
4070 % \begin{macro}{\AskQuestions}
4071 % \changes{2.0e}{1991/06/01}{Macro added.}
4072 %    The macro |\AskQuestions| is called by |\interactive| to get
4073 %    some information from the user concerning the files that need
4074 %    to be processed.
4075 %    \begin{macrocode}
4076 \def\AskQuestions{%
4077     \Msg{^^J%
4078          ****************************************************}%
4079 %    \end{macrocode}
4080 %    We want to know the extension of the input files,
4081 %    \begin{macrocode}
4082     \Ask\infileext{%
4083          * First type the extension of your input file(s): \space  *}%
4084     \Msg{****************************************************^^J^^J%
4085          ****************************************************}%
4086 %    \end{macrocode}
4087 %    the extension of the output files,
4088 %    \begin{macrocode}
4089     \Ask\outfileext{%
4090          * Now type the extension of your output file(s) \space: *}%
4091     \Msg{****************************************************^^J^^J%
4092          ****************************************************}%
4093 %    \end{macrocode}
4094 %    if options are to be included and
4095 %    \begin{macrocode}
4096     \Ask\Options{%
4097        * Now type the name(s) of option(s) to include \space\space: *}%
4098     \Msg{****************************************************^^J^^J%
4099          ****************************************************^^J%
4100        * Finally give the list of input file(s) without \space\space*}%
4101 %    \end{macrocode}
4102 %    the name of the input file or a list of names, separated by commas.
4103 %    \begin{macrocode}
4104     \Ask\filelist{%
4105          * extension seperated by commas if necessary %
4106                                   \space\space\space\space: *}%
4107     \Msg{****************************************************^^J}}%
4108 %    \end{macrocode}
4109 % \end{macro}
4111 % \subsection{The main program}
4112 %    When \TeX\ processes the \ds{} program it displays
4113 %    a message about the version of the program and its function
4114 %    on the terminal.
4115 %    \begin{macrocode}
4116 \Msg{Utility: `docstrip' \fileversion\space <\filedate>^^J%
4117      English documentation \space\space\space <\docdate>}%
4118 \Msg{^^J%
4119      **********************************************************^^J%
4120      * This program converts documented macro-files into fast *^^J%
4121      * loadable files by stripping off (nearly) all comments! *^^J%
4122      **********************************************************^^J}%
4123 %    \end{macrocode}
4126 %  \begin{macro}{\WriteToDir}
4127 %    Macro |\WriteToDir| is either empty or holds the prefix
4128 %    necessary to read a file from the current directory. Under UNIX
4129 %    this is |./| but a lot of other systems addopted this concept.
4130 %    This macro is a default value for |\destdir|.
4132 %    The definition of this macro is now delayed until |\@setwritedir|
4133 %    is called.
4134 % \changes{2.0p}{1992/06/26}{Macro added (FMi).}
4135 % \changes{2.2a}{1993/12/02}{check texsys file}
4136 % \changes{2.2d}{1994/01/20}{do not read dircheck/texsys file}
4137 % \changes{2.4e}{1996/10/22}{set in \cs{@setwritedir} (DPC)}
4138 %  \end{macro}
4140 % \begin{macro}{\makepathname}
4141 % \changes{2.3e}{1995/10/24}{Macro added}
4142 % \changes{2.4e}{1996/10/22}{set in \cs{@setwritedir} (DPC)}
4143 %    This macro should define |\@pathname| to full path name made by
4144 %    combining current value of |\destdir| with its one argument being
4145 %    a file name.  Its default value defined here is suitable for
4146 %    \textsc{unix, ms-dos} and Macintosh, but for some systems it may
4147 %    be needed to redefine this in \texttt{docstrip.cfg} file.  We
4148 %    provide such redefinition for VMS here.  
4150 %    Macro |\dirsep| holds directory separator specific for a
4151 %    system. Default value suitable for UNIX and DOS is slash. It
4152 %    comes in action when |\usedir| labels are used directly.
4154 %    The definition of this macro is now delayed until |\@setwritedir|
4155 %    is called.
4156 % \end{macro}
4158 % \begin{macro}{\@setwritedir}
4159 % \changes{2.4e}{1996/10/22}{macro added (DPC)}
4160 % The following tests try to automatically set |\WriteToDir|,
4161 % |\dirname| and |\makepathname| in Unix, Mac, or VMS style.
4162 % The tests are not run at the top level but held in this macro
4163 % so that a configuration file has a chance to define |\WriteToDir|
4164 % which allows the other two to be set automatically. The tests could
4165 % more simply be run after the configuration file is read, but the
4166 % configuration commands like |\BaseDirectory| need (at least at
4167 % present)  to have |\dirsep| correctly defined. It does not define
4168 % any command that is already defined, so by defining these commands
4169 % a configuration file can produce different effects for special needs.
4170 % So this command is called by |BaseDirectory|, |\UseTDS|,
4171 % |\DeclareDir| and finally at the top level after the cfg is run.
4172 % It begins by redefining itself to be a no-op so it effectively is
4173 % only called once.
4174 %    \begin{macrocode}
4175 \def\@setwritetodir{%
4176   \let\setwritetodir\relax
4177 %    \end{macrocode}
4179 %    \begin{macrocode}
4180   \ifx\WriteToDir\@undefined
4181     \ifx\@currdir\@undefined
4182       \def\WriteToDir{}%
4183     \else
4184       \let\WriteToDir\@currdir
4185     \fi
4186   \fi
4187 %    \end{macrocode}
4189 %    \begin{macrocode}
4190   \let\destdir\WriteToDir
4191 %    \end{macrocode}
4193 % VMS Style.
4194 %    \begin{macrocode}
4195   \def\tmp{[]}%
4196   \ifx\tmp\WriteToDir
4197     \ifx\dirsep\@undefined
4198       \def\dirsep{.}%
4199     \fi
4200     \ifx\makepathname\@undefined
4201       \def\makepathname##1{%
4202         \edef\@pathname{\ifx\WriteToDir\destdir
4203           \WriteToDir\else[\destdir]\fi##1}}%
4204     \fi
4205   \fi
4206 %    \end{macrocode}
4208 % Unix and Mac styles.
4209 %    \begin{macrocode}
4210   \ifx\dirsep\@undefined
4211     \def\dirsep{/}%
4212     \def\tmp{:}%
4213     \ifx\tmp\WriteToDir
4214       \def\dirsep{:}%
4215     \fi
4216   \fi
4217 %    \end{macrocode}
4219 %    \begin{macrocode}
4220   \ifx\makepathname\@undefined
4221     \def\makepathname##1{%
4222       \edef\@pathname{\destdir\ifx\empty\destdir\else
4223            \ifx\WriteToDir\destdir\else\dirsep\fi\fi##1}}%
4224   \fi}
4225 %    \end{macrocode}
4226 % \end{macro}
4229 % If the user has a |docstrip.cfg| file, use it now.
4230 % \changes{2.4d}{1995/10/17}{Move config file test to outer level (DPC)}
4231 %    This macro tries to read \texttt{docstrip.cfg} file.  If this 
4232 %    succeeds executes its first argument, otherwise the second.
4233 %    \begin{macrocode}
4234 \immediate\openin\inputcheck=docstrip.cfg\relax
4235 \ifeof\inputcheck
4236   \Msg{%
4237      ********************************************************^^J%
4238      * No Configuration file found, using default settings. *^^J%
4239      ********************************************************^^J}%
4240 \else
4241   \Msg{%
4242      ******************************************^^J%
4243      * Using Configuration file docstrip.cfg. *^^J%
4244      ******************************************^^J}%
4245   \closein\inputcheck
4246   \afterfi{\@@input docstrip.cfg\relax}
4248 %    \end{macrocode}
4250 % Now run |\@setwritedir| in case it has not already been run
4251 % by a command in a configuration file.
4252 %    \begin{macrocode}
4253 \@setwritetodir
4254 %    \end{macrocode}
4256 % \begin{macro}{\process@first@batchfile}
4257 % \changes{2.4d}{1996/10/17}
4258 %      {Macro added (DPC)}
4259 % Process the batch file, and then terminate cleanly.
4260 % This may be set to |\relax| for `new style' batch files that
4261 % do not start with |\def\batchfile{|\ldots
4262 %    \begin{macrocode}
4263 \def\process@first@batchfile{%
4264   \processbatchFile  
4265   \ifnum\NumberOfFiles=\z@
4266     \interactive
4267   \fi
4268   \endbatchfile}
4269 %    \end{macrocode}
4270 % \end{macro}
4272 % \begin{macro}{\endbatchfile}
4273 % \changes{2.4d}{1996/10/17}
4274 %      {Macro added (DPC)}
4275 % User level command to end batch file processing.
4276 % At the top level, returns totals and then stops \TeX.
4277 % At nested levels just does |\endinput|.
4278 %    \begin{macrocode}
4279 \def\endbatchfile{%
4280   \iftopbatchfile
4281 %<*stats>
4282     \ReportTotals
4283 %</stats>
4284     \expandafter\end
4285   \else
4286     \endinput
4287   \fi}
4288 %    \end{macrocode}
4289 % \end{macro}
4291 %    Now we see whether to process a batch file.
4292 % \changes{2.4d}{1996/10/17}
4293 %      {Move default batchfile check to outer level (DPC)}
4296 % \begin{macro}{\@jobname}
4297 % \changes{2.4d}{1996/10/17}
4298 %      {Macro added (DPC)}
4299 % Jobname (catcode 12)
4300 %    \begin{macrocode}
4301 \edef\@jobname{\lowercase{\def\noexpand\@jobname{\jobname}}}%
4302 \@jobname
4303 %    \end{macrocode}
4304 % \end{macro}
4307 % \begin{macro}{\@docstrip}
4308 % \changes{2.4d}{1996/10/17}
4309 %      {Macro added (DPC)}
4310 % docstrip (catcode 12)
4311 %    \begin{macrocode}
4312 \def\@docstrip{docstrip}%
4313 \edef\@docstrip{\expandafter\strip@meaning\meaning\@docstrip}
4314 %    \end{macrocode}
4315 % \end{macro}
4317 %    First check whether the user has
4318 %    defined the control sequence |\batchfile|. If he did, it should
4319 %    contain the name of the file to process. 
4320 %    If he didn't, try the current file, unless that is |docstrip.tex|
4321 %    in which case a default name is tried. 
4322 %    Whether or not the default batch file is used is
4323 %    remembered by setting the switch |\ifDefault| to \meta{true} or
4324 %    \meta{false}.
4325 %    \begin{macrocode}
4326 \Defaultfalse
4327 %    \end{macrocode}
4329 %    \begin{macrocode}
4330 \ifx\undefined\batchfile
4331 %    \end{macrocode}
4332 % |\@jobname| is lowercase jobname (catcode 12)\\
4333 % |\@docstrip| is docstrip (catcode 12)
4334 %    \begin{macrocode}
4335   \ifx\@jobname\@docstrip
4336 %    \end{macrocode}
4337 % Set the batchfile to the default
4338 %    \begin{macrocode}
4339     \let\batchfile\DefaultbatchFile
4340     \Defaulttrue
4341 %    \end{macrocode}
4342 %  Else don't process a new batchfile, just carry on with past the end
4343 % of this file. In this case processing will move to the initial
4344 % batchfile which \emph{must} then be terminated by |\endbatchfile| or
4345 % \TeX\ will fall to the star prompt.
4346 %    \begin{macrocode}
4347   \else
4348     \let\process@first@batchfile\relax
4349   \fi
4351 \process@first@batchfile
4352 %    \end{macrocode}
4354 %    \begin{macrocode}
4355 %</program>
4356 %    \end{macrocode}
4358 % \Finale
4359 \endinput