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