@z --- fwebmac.web ---

Copyright (C) 1987 Princeton University

Original authors:  D. Knuth, S. Levy

Upgraded by J.A. Krommes for FWEB version 1.51.

@x-----------------------------------------------------------------------------

\Title{fwebmac-1.52-$\beta$}
\author{John A. Krommes\\(after D. Knuth and S. Levy)}
\date{June 10, 1995}

\numberdefsfalse
\numbercodefalse

@Lx

@* INTRODUCTION.  These are the standard macros for \FWEB\ (v.~1.52)
listings (in addition to those of \.{PLAIN.TEX} and/or \LaTeX).  Beginning
with v.~1.50, \LaTeXe\ is supported.

WARNING: Some of these macros are not independent of stuff hard-coded
into \FWEAVE. In other words, if you change something here, you may also need
to recompile \FWEAVE. So caution!

@ Print a comment at the beginning of the \.{.sty} file that is created.
@A
% --- THIS IS fwebmac.sty ---

% DO NOT EDIT THIS FILE; it is generated automatically from fwebmac.web.
% This file must be included into all .tex files produced by FWEAVE. 
% You can weave fwebmac.web to see discussions of the fwebmac.sty logic.

% ---------------------------------------------------------------------------

@ First, we have a flag |\FWEBisloaded| that prevents \.{fwebmac.sty} from
being loaded twice.  For the use of this flag, see the Dirty Tricks
appendix of the \TeX book. 

@A
% If it's not defined yet, load in the macros.
\ifx\FWEBisloaded\relax\endinput\else\let\FWEBisloaded\relax\fi

@ We need to refer to various internal macros, so we make '\.{@@}' an
ordinary letter.
@f `\@@ 11
@A
\catcode`\@@=11

@ Here's something for trickery with catcodes.
@A
\chardef\other=12

@ One can comment stuff out by bracketing it with |\comment...\endcomment|.
@A
\long\def\comment#1\endcomment{}

@*1 The current version.
Various things need to know the current version number and date.
@A
\def\FWEBversion{1.52-$\beta$}
\def\FWEBdate{June 3, 1995}

@*1 Defining robust macros.
Robust commands are useful; we provide our own version if the \LaTeXe\
|\DeclareRobustCommand| isn't available.  (However, at present our own
version just defines a macro with $n$~arguments; it doesn't actually make
it robust for \TeX\ or ordinary \LaTeX.)

@A
\newcount\W@@count
\newcount\W@@counta
\newtoks\W@@tk

\ifx\DeclareRobustCommand\undefined

	\def\DeclareRobustCommand#1{\@@ifnextchar[%
{\W@@argdef#1}{\W@@argdef#1[0]}}

	\def\W@@argdef#1[#2]{\W@@tk={}%
	\W@@count=0
	\loop
	\ifnum\W@@count<#2
		\advance\W@@count by1
		\edef\next{\W@@tk={\the\W@@tk########\the\W@@count}}\next
	\repeat
	\edef\next{\def\noexpand#1\the\W@@tk}\next}

\fi

\ifx\@@ifnextchar\undefined

	\def\@@ifnextchar#1#2#3{\let\@@tempe#1
	\def\@@tempa{#2}%
	\def\@@tempb{#3}%
	\futurelet\@@tempc\@@ifnch}

	\def\@@ifnch{\ifx\@@tempc\@@sptoken
		\let\@@tempd\@@xifnch
	\else
		\ifx\@@tempc\@@tempe
			\let\@@tempd\@@tempa
		\else
			\let\@@tempd\@@tempb
		\fi
	\fi
	\@@tempd
	}

	{\def\:{\global\let\@@sptoken= } \: }

	\def\@@xifnch{\futurelet\@@tempc\@@ifnch}

\fi


\let\DRC\DeclareRobustCommand

@*1 Printing ``\TeX'' and ``\LaTeX'', and distinguishing between them.
\FWEB\ now offers full \LaTeX\ support.  Here's how to refer to it.
[Note the use of |\W@@t| (defined in \WEBsection{syn} below) rather than
|\@@|; the latter is used for other things in \FWEB.]
@A
\def\TeX{T\kern-0.1667em\lower0.5ex\hbox{E}\kern-0.125emX\W@@t}

\ifx\LaTeX\undefined
	\def\LaTeX{L\kern-0.36em\raise0.3ex\hbox{\Csc a}\kern-0.15em\TeX}
\fi

\newif\ifnoLaTeXe% By default, we have \LaTeXe.

\ifx\LaTeXe\undefined
	\noLaTeXetrue
	\def\LaTeXe{\LaTeX 2$_\varepsilon$}
\fi

@ One needs to distinguish whether or not \LaTeX\ is loaded.  Assuming that
only \TeX\ or \LaTeX\ will be used, one way of doing this is to
discriminate on whether |\pageno| is defined.  

@A
\newif\ifLaTeXisloaded

\ifx\pageno\undefined
	\LaTeXisloadedtrue
\fi

@*1 Convenience macros such as \.{\\FWEAVE} or \.{\\Fortran}.
Here's how to refer to the individual processors.  The user may wish to
redefine these.  Note that we use the primitive |\Wtypewriter|, since the
user can change the usual typewriter macro ``|\.|'' to something else.

@A
\DRC\WEB{\Wtypewriter{WEB}}
\DRC\FWEB{\Wtypewriter{FWEB}}
\DRC\CWEB{\Wtypewriter{CWEB}}
\DRC\TANGLE{\Wtypewriter{TANGLE}}	\let\Tangle\TANGLE
\DRC\WEAVE{\Wtypewriter{WEAVE}}		\let\Weave\WEAVE
\DRC\FTANGLE{\Wtypewriter{FTANGLE}}
\DRC\FWEAVE{\Wtypewriter{FWEAVE}}

@ Here's how one can refer to the individual languages.  The user may also wish
to redefine these.
@A
\DRC\C{C\W@@t}
\DRC\Cpp{\C{\tt ++}}
\DRC\FORTRAN{{\Csc Fortran}}	\let\Fortran\FORTRAN
\DRC\MAKE{{\tt MAKE}}		\let\Make\MAKE
\DRC\RATFOR{{\Csc Ratfor}}	\let\Ratfor\RATFOR
\DRC\UNIX{{\SC UNIX}}		\let\Unix\UNIX


@*1 Synonyms for macros such as \.{\\@@} usurped by \FWEB.
\modlabel{syn}
Now define a few things not known to \TeX, and remember some Plain \TeX\
stuff used for other purposes by \FWEB. 

@A
\ifLaTeXisloaded
\else
	\let\@@\relax
	\let\\\relax
	\let\protect\relax
\fi

\let\amp\&
\let\at\@@ 
\let\bslash\\
\let\caret\^
\let\dollar\$
\let\dstar\*
\let\equals\=
\let\leftbrace\{
\let\period\.
\let\rightbrace\}
\let\vertbar|
\let\PM\#
\let\PC\%

@
@A
\let\W@@t\@@
\let\W@@S\S

@ (The following was for Plain \TeX, and is probably obsolete.) 
Additionally, the TeXbook manual macro package \.{manmac} redefines the
following stuff: 

 |\iftitle \titlefont \rhead \pagewidth \pageheight \output|

\noindent If you want to include \.{manmac.tex} to get various macro
definitions, the best scheme is to use the `\.{-w}'~command-line option to
prevent \FWEAVE\ from outputting |\input fwebmac.sty| as the first output line.
Then include both files explicitly, in this order:

	|\input manmac|
	|\input fwebmac.sty|

\noindent You can do this by defining the first limbo text command as
follows:

 |@@l "\\input manmac \\input fwebmac.sty"|

@*1 Paragraph skip and indentation for \TeX\ text.

@A
\dimen0=\normalbaselineskip
\parskip=\dimen0 plus 1pt minus 6pt

% If you don't like spaces between paragraphs, change |\pardimen| to |0pt|.
\newskip\pardimen
\pardimen=\parskip 

%\pardimen 0pt% No stretch between paragraphs

% Indentation for the \TeX\ part is handled in a separate variable
% |\TeXindent| (the style-file parameter \.{indent.TeX}) from the variable
% |\notch| (the style-file parameter \.{indent.code}) used for
% definition and code parts.  
\newdimen\TeXindent
\TeXindent 1em% For paragraphs in the \TeX\ part.

@*1 Page numbering.
If \LaTeX\ is loaded, we equate |\pageno| to \LaTeX's counter so that the
|\label| macro works correctly.  

@A 
\ifLaTeXisloaded
	\let\pageno\c@@page% \WEB\ has its own name for the page number.
\fi

@* FONTS. Several fonts have been declared in addition to the standard ones of
\.{PLAIN} format:
$$\vbox{\halign{\.{\\#}\quad\hfil&---\quad#\hfil\cr
titlefont&\titlefont Title.\cr
ttitlefont&\ttitlefont Title.\cr
SC&\SC SMALL CAPS.\cr
Csc&\Csc CAPS/Small caps.\cr
tentex&\tentex \TeX\ extended character set, including~'\.{\ }'.\cr
bfit&\bfit Bold-faced italic.\cr
}}$$
The main font used for text is called |\mainfont|, which is |\let| to |\tenrm|.
The font used for comments is called |\cmntfont|.  By default, this is
|\let| to |\mainfont|.

@A
\ifnoLaTeXe
	\ifx\tenrm\undefined
		\font\tenrm=cmr10
	\fi
	\ifx\itfam\undefined
		\chardef\itfam4
	\fi
	\ifx\small\undefined
		\let\small\relax
	\fi
	\let\mainfont\tenrm \let\cmntfont\tenrm
	\font\eightrm=cmr8 \let\SC\eightrm 

	\font\titlefont=cmssbx10 scaled \magstep2% Sans serif
	\font\ttitlefont=cmtt10 scaled\magstep2% Typewriter type

	\font\tentex=cmtex10 % \TeX\ \.{extended char.\ set} (used in strings)
	\let\extendedtex\tentex
	\font\Csc=cmcsc10 % Caps/small caps.
	\font\tenbfit=cmbxti10 % \&{Intrinsic functions}
	\let\bfit\tenbfit % Doesn't work right in titles.

% Used for module-number subscript:
	\font\seventi=cmti7
	\font\sevenrm=cmr7
	\font\sevenbf=cmbx7

% For special handling of array indices:
	\font\sevenit=cmti7
	\scriptfont\itfam=\sevenit

@%\font\fiveit=cmti5
@%\scriptscriptfont\itfam=\fiveit
	\scriptscriptfont\itfam=\sevenit

	\def\mathrm#1{{\rm #1}}
	\def\mathit#1{{\it #1}}

\else % \LaTeXe
	\def\mainfont{\normalsize\usefont{OT1}{\rmdefault}{m}{n}}
	\let\cmntfont\mainfont

	\def\eightrm{\footnotesize\usefont{OT1}{\rmdefault}{m}{n}}
	\let\SC\eightrm

	\def\titlefont{\Large\usefont{OT1}{\sfdefault}{\bfdefault}{n}}
	\def\ttitlefont{\Large\usefont{OT1}{\ttdefault}{m}{n}}

	\def\extendedtex{\usefont{OT1}{\ttdefault}{m}{n}}
	\def\tentex{\normalsize\extendedtex}

	\def\Csc{\usefont{OT1}{\rmdefault}{m}{\scdefault}}

	\def\bfit{\usefont{OT1}{\rmdefault}{\bfdefault}{\itdefault}}
	\def\tenbfit{\normalsize\bfit}

	\def\seventi{\scriptsize\usefont{OT1}{\rmdefault}{m}{\itdefault}}
	\def\sevenrm{\scriptsize\usefont{OT1}{\rmdefault}{m}{n}}
	\def\sevenbf{\scriptsize\usefont{OT1}{\rmdefault}{\bfdefault}{n}}

	\def\fiveti{\tiny\usefont{OT1}{\rmdefault}{m}{\itdefault}}
	\def\fiverm{\tiny\usefont{OT1}{\rmdefault}{m}{n}}
	\def\fivebf{\tiny\usefont{OT1}{\rmdefault}{\bfdefault}{n}}

	\def\tensy{\normalsize\usefont{OT1}{cmsy}{m}{n}}

%	\def\pbf{\fontfamily{\rmdefault}\fontseries{\bfdefault}\fontshape{n}%
%		\selectfont}
%	\def\ptt{\fontfamily{\ttdefault}\fontseries{m}\fontshape{n}\selectfont}
\fi

@* HIGHLIGHTING MACROS.  
These are used for displaying identifiers, reserved words, intrinsic
functions, etc.  

@*1 The primitive highlighting macros.
Typically the user (or \FWEB\ automatically) does not
actually type these macros directly.  Instead of saying ``|\Wshort{x}|'',
one says ``|\|x|''.  The associations between the short-hand convenience
macros such as `|\||', `|\&|', etc.\ are made by an equating procedure
carried out by the |\Wbegin| macro (see \WEBsection{Wbegin} below).  The
short-hand names are style-file 
parameters that can be changed by the user.  For more information, consult
the on-line documentation, menu item |fwebmac params|.

@A
\DRC\Wshort[1]{\leavevmode\hbox{$#1$}}% One-letter identifiers such
	% as~\Wshort{x} look better this way.

\DRC\Wid[1]{\leavevmode\hbox{\it#1\/\kern.05em}}% Italic type for ordinary
	% identifiers such as \Wid{test}.

\DRC\WID[1]{\leavevmode\hbox{\small\it#1\/\kern.05em}}% For all \WID{UPPERCASE}.

% By default, macros are formatted the same way as ordinary identifiers.
% However, one can change the following definitions to get special effects.
% Either make your own version of |fwebmac.sty| (use a change file with
% |fwebmac.web|), or redefine |\WidD| and/or |\WidM| with an \.{@@l} command.
\let\WidD\Wid % Outer macro
\let\WidM\Wid % WEB macro

\DRC\Wreserved[1]{\leavevmode\hbox{\def\\{\tt\BS}\bf#1\/}}% Boldface type
	% for reserved words such as \Wreserved{int}.

\DRC\WRESERVED[1]{\leavevmode\hbox{\def\\{\tt\BS}\small\bf#1\/}}% Boldface type
	% for upper-case reserved words such as \WRESERVED{INTEGER}.


\DRC\Wintrinsic[1]{\leavevmode\hbox{\def\\{\tt\BS}\bfit#1\/\kern.05em}}%
	% Library/intrinsic function name such as \@@{sin}.

@*1 Equating abbreviations to the primitive highlighting macros.
In the following, we use |\gdef| instead of |\global\let| because we
might want to change the definition of, e.g., |\WidM| with an \.{@@l}
command, which comes {\it after} the |\Wbegin| statement.

@A
\def\W@@twodef#1#2#3#4{\gdef#1{#3}\gdef#2{#4}}

\def\W@@equate#1#2#3#4#5#6#7#8{%
	\W@@twodef#1\Wreserved\WRESERVED% |\&| by default.
	\gdef#2{\Wshort}% |\|| by default.
% Don't reorder the following four statements! In case arguments 3--6 are
% identical, one wants the ordinary identifier to win.
	\W@@twodef#5\WidM\WidM% |\\| by default.
	\W@@twodef#4\WidD\WidD% |\\| by default.
	\W@@twodef#3\Wid\WID% |\\| by default.
	\gdef#6{\Wintrinsic}% |\@@| by default.
	\W@@twodef#7\Wkeyword\Wkeyword% |\.| by default.
	\gdef#8{\Wtypewriter}}% |\.| by default.

@ Identifiers that are recognized as function or macro names are followed
by the construction\hfil\break
\.{\\WIN\{{\it name}\_{\it type}\}\{{\it module}\_{\it number}\}}.  The
cases for the first argument correspond to 
$$\vbox{\halign{#\hfil&\ ---\ #\hfil\cr
0&Generic name, defined by \.{@@[}.\cr
1&Function name.\cr
2&\WEB\ macro (\.{@@m}).\cr
3&Outer macro (\.{@@d}).\cr
4&Reserved name defined with~\.{@@`}.\cr
5&|@c typedef| name.\cr
}}$$
If the name was defined in the current module, the second argument will be
zero; otherwise it will be the section number in which the name was
defined.  The macro shows how to display the 0~state differently (here with
a bullet).   Also, note how combinations of underlining and fonts are used
to distinguish the various kinds of identifiers.

@A
\def\W@@zero{0}% For the comparison in |\WIN| below.

\DRC\WIN[2]{\ifmmode\def\ZZ{}\else\def\ZZ{\null$\null}\fi
	\ZZ_{\def\W@@rg{#2}\ifx\W@@rg\W@@zero{\bullet}\else\W@@IN{#1}{#2}\fi}\ZZ}


% Format the module-number subscript.
\gdef\W@@IN#1#2{%
	\ifcase#1
	 \underline{\hbox{\sevenrm\Wmodtrans{#2}}}% Generic name (\.{@@[}). [0]
	\or\hbox{\sevenrm\Wmodtrans{#2}}% Function name. [1]
	\or\underline{\hbox{\seventi\Wmodtrans{#2}}}% WEB macro. [2]
	\or\hbox{\seventi\Wmodtrans{#2}}% Outer macro. [3]
	\or\underline{\hbox{\sevenbf\Wmodtrans{#2}}}% \.{@@`}. [4]
	\or\hbox{\sevenbf\Wmodtrans{#2}}% \&{typedef}. [5]
	\else{\Wmodtrans{#2}}% Error trap.
	\fi
	}


@* STRINGS. Strings are indicated by ``\.{\\.\{\dots\}}''.  You can also
use this for typewriter type; remember to escape the appropriate symbols:
``\.{\ \\\#\%\$\^\_\{\}\~\&}''.  The string macro itself does not surround
its contents with an |\hbox|, in order that long strings can be broken by
discretionaries (done automatically by \FWEAVE).

@A
\DRC\Wtypewriter[1]{\relax\ifmmode\gdef\YY{\null$\null}\else\gdef\YY{}\fi
	\YY{\leavevmode\W@@INITSTR#1}\YY}

\let\Wkeyword\Wtypewriter

@*1 Nucleus for the string macro.
Here is the nucleus for the string macro~|\.| (more precisely, for
|\Wtypewriter|).

@A
\def\W@@INITSTR{%
	\extendedtex % Typewriter type for strings.  (We don't say
%|\tentex| here so the font can grow in a title.)
	\let\\=\BS % Backslash in a string: '\.\\'.
	\let\'=\RQ % Right quote in a string: '\.\''.
	\let\`=\LQ % Left quote in a string: '\.\`'.
	\let\{=\LB % Left brace in a string: '\.\LB'.
	\let\}=\RB % Right brace in a string: '\.\RB'.
	\let\~=\TL % Tilde in a string: '\.\~'.
	\let\ =\SP % Space in a string: '\.\ '.
	\let\_=\UL % Underline in a string: '\.\_'.
	\let\&=\AM % Ampersand in a string: '\.\&'.
	\def\0{\discretionary{\BS}{}{}}% \FWEB\ inserts this automatically every
	  % so often so very long strings will break. Broken strings will
	  % be marked by a backslash.
	\def\1{,\0}% \FWEB\ replaces commas in strings by this, so strings
		% tend to break after commas.
	\let\2\space % Ordinary space after control sequences in \TeX.
	\def\3{\space\space}% Translation of a tab in \TeX.
	}

@*1 Characters for strings.
@A
\DRC\#{\hbox{\tt\char35}}% Parameter sign: '\#'.
\DRC\${\hbox{\tt\char36}}% Dollar sign: '\$'.
\DRC\%{\hbox{\tt\char37}}% Percent sign: '\%'.
\DRC\^{\ifmmode\raise0.45ex\hbox{$\,\scriptstyle\mathchar"25E\,$}%
	\else\char`^ \fi}% Pointer or 
	% hat: '\^'. 
	% Circumflex accents can be obtained from |\^^D| instead of |\^|.
\def\AT!{@@}% Knuth's abbreviation for the at sign for control text: '\AT!'

@ The following funny business about asterisks is in case one wants to be
clever and make~`\.*' an active character (for example, for complex
conjugation). 
@A
\chardef\asterisk=`\*
\DRC\ast{\ifmmode{\displaystyle\mathchar"2203}\else\asterisk\fi} 

@ More stuff for strings.
@A
\chardef\AM=`\&% Ampersand character in a string: '\.\&'.
\chardef\BS=`\\% Backslash in a string: '\.\\'.
\DRC\ttBS{{\tt\BS}}% Literal backslash: '\ttBS'.
\chardef\LB=`\{% Left brace in a string: '\.\LB'.
\DRC\LQ{{\tt\char'22}}% Left quote in a string: '\.\`'.
\chardef\RB=`\}% Right brace in a string: '\.\RB'.
\DRC\RQ{{\tt\char'23}}% Right quote in a string: '\.\''.
\DRC\SP{{\tt\char`\ }}% (Visible) space in a string: '\.\ '.
\chardef\TL=`\~% Tilde in a string: '\.\~'.
\chardef\UL=`\_% Underline character in a string: '\.\_'.

@ Left quote outside a string:
@A
\DRC\LA{\hbox{\LQ}}

@* INDENTATION, LINEBREAKS, etc{.}.  These commands are mostly handled by the
macros~|\1| to~|\8|.

@*1 Demonstration of the indentation scheme.
First, here are some macros to draw vertical lines to show off the indentation
scheme.

@A
\newbox\rulebox
\newcount\ruleno

\def\rules#1{\leavevmode
	\ruleno=0
	\rlap{\vtop to 0pt{\null
		\def\R{\setbox0=\hbox{\the\ruleno}%
			\rlap{\vrule height0pt depth#1}%
			\kern-0.5\wd0\copy0\kern-0.5\wd0
			\advance\ruleno by1
			\hskip1em}
		\rlap{\R\R\R\R\R\R\R}
		\vss}}}

@ The indentation scheme is as follows.  The unit of indentation is
|\notch|.
@A
\newdimen\notch

@ Here is typical output.

\setbox\rulebox\vtop{\null
\ifnoLaTeXe
\else
	\let\\\>
\fi
\WY $\WP\WE:if:\WO{1}{}$\par
\WP\WMd$\@|A\WIN2{0}$\5
$\WO{2}{}$\par
\WP\WE:endif:\par
\WP\WMD$\\{ALPHA}$\5
$\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+%
\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+%
\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+%
\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+%
\\{xxx}+\\{yyy}+\\{xxx}{}$\par
\WY\WP$\\{main}(\,)$\1\1\6
\&{int} \1\\{abcde}, \\{abcde}, \\{abcde}, \\{abcde}, \\{abcde}, \\{abcde}, %
\\{abcde}, \\{abcde}, \\{abcde}, \\{abcde}, \\{abcde}, \\{abcde}, \\{abcde}, %
\\{abcde}, \\{abcde}, \\{abcde}, \\{abcde}, \\{abcde}, \\{abcde}, \\{abcde};\2%
\2\2\1\6
$\{{}$\6
\WE:if:$\WO{1111}+\WO{2222}+\WO{1111}+\WO{2222}+\WO{1111}+\WO{2222}+\WO{1111}+%
\WO{2222}+\WO{1111}+\WO{2222}+\\{aaaa}+\\{bbbb}+\WO{1111}+\WO{2222}+\WO{1111}+%
\WO{2222}+\WO{1111}+\WO{2222}+\WO{1111}+\WO{2222}+\WO{1111}+\WO{2222}$\WPs\7
$\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+%
\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+%
\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\z;{}$%
\7
\WE:endif:\WPs\6
$\}$\2\WY\par
}

\vbox{\noindent\rules{\dp\rulebox}\box\rulebox}

@*1 Indentation conventions.
Preprocessor commands in the definition part are far left, definition-part
commands such  
as~\.{@@m} are indented one notch, function names are at two notches, and
the body of functions is at three notches.  This distance is given the
special name |\W@@globalindent|:

@A
\newcount\W@@globalindent
\W@@globalindent=3 % Global indentation in notches.

@ The current indentation is called |\W@@ind|.  One also sometimes needs to save
and restore that.
@A
\newcount\W@@ind % Current indentation in notches.
\newcount\W@@lastind % Used for preprocessor commands.
\def\W@@saveind{\global\W@@lastind=\W@@ind}

@*1 Backspacing.
Each output line of code is a separate paragraph.  The scheme proceeds by
first setting |\W@@ind|~to the appropriate hanging indentation, then
backspacing appropriately.  Here are the backspace quantities.  Note that
one can't initialize the boxes here, because the value of |\notch| isn't
known until after |\Wbegin| (it's the style-file parameter \.{indent.code}).

@A
\newbox\b@@k  
\newbox\b@@kk 

\def\W@@setboxes#1{\notch=#1
	\setbox\b@@k=\hbox to -\notch{}% Backspace one notch.
	\setbox\b@@kk=\hbox to -2\notch{}% Backspace two notches.
	}

@*1 The macros |\1| to |\8|.
When there's the possibility that a line of code may be continued, we
advance the indentation and set |\hangindent|.
@A
\def\1{\global\advance\W@@ind by1\hangindent\W@@ind\notch}% Indent one more notch

@ Here we cancel the above.  One doesn't need to reset |\hangindent| because
this will always be followed by a~|\6| or~|\7|, which already does that.
@A
\def\2{\global\advance\W@@ind by-1{}}% Indent one less notch

@ Now we provide for an optional break within a statement.  (Note that the
argument is multiplied by~10.)
@A
\def\3#1{\hfil\penalty#10\hfilneg}% Optional break within a statement.

@ A simple command to backspace one notch.
@A
\def\4{\copy\b@@k}% Backspace one notch

@ Optional break (the |\yskipfalse| may be obsolete).
@A
\def\5{\hfil\penalty-1\hfilneg \kern2.5\notch\copy\b@@kk
	\yskipfalse\ignorespaces}

@ The next command forces a line break.
@A
\def\6{\ifmmode\else\par
	\hangindent\W@@ind\notch \noindent \kern\W@@ind\notch \copy\b@@kk \ignorespaces\fi}

@ This also forces a line break, but also adds some extra vertical space.
@A
\def\7{\WY\6}% Forced break and a little extra space.

@ No indentation.
@A
\def\8{\hskip-\W@@ind\notch \hskip 2\notch}

@
@A
\newif\ifyskip
\def\yskip{\medskip}

@* PREPROCESSOR COMMANDS.  The preprocessor commands are built out of the
previous ones.

First, we define a guaranteed space.
@A
\def\W@@Hspace{\hbox{ }}

@ Start a preprocessor command such as \.{@@\#if}.  When these are issued
in the code section (rather than in the definition section), one must
remember the present level of indentation.  That's restored with~|\WPs|.

@A
\DRC\WPR[1]{\copy\b@@kk \W@@saveind%	|\global\advance\W@@ind by 2|
	\1\Wreserved{@@#1}\W@@Hspace}

\DRC\WPs{\global\W@@ind=\W@@lastind}

@ The definition commands such as~\.{@@m} are similar, except that they
also take a language argument.
@A
\def\W@@defin#1#2{\4\W@@saveind
	\1\Wreserved{#1}\hbox{$^{\mathrm{#2}}$}\W@@Hspace}% Begin @@d, @@m, or @@f.

@* VARIOUS NUCLEII.
Here are some miscellaneous macros used by the innards of this macro package.

@A
\def\note#1#2.{\WY\noindent{\hangindent2em\baselineskip10pt\footnotesize
#1 #2.\par}}

@*1 Star macros.
@A
\def\W@@lapstar{\rlap{*}}

\newif\ifW@@modchanged

\def\W@@checkstar{\edef\W@@temp{\noexpand\W@@isstar\modstar\noexpand\*\relax}%
\W@@temp}

\def\W@@isstar#1\*#2\relax{\ifx#2\*\W@@modchangedtrue\else\W@@modchangedfalse\fi}

@*1 Printing the current include file.
If there's a current include file, it's printed at the start of each
section.  The macro |\WIF| is emitted by \FWEAVE\ and stores the current
include-file name into |\W@@includefile|.  |\WIF@@name| actually prints it,
according to the macro |\WIFfmt|.

@A
\def\W@@includefile{}

\def\WIF#1{\gdef\W@@includefile{#1}}

\def\WIF@@name{\ifx\W@@includefile\empty
	\else
		\ifLaTeXisloaded\else\ \fi
		\WIFfmt{\W@@includefile}%
	\fi}

\def\WIFfmt#1{[{\tt#1}]}

\def\W@@startsection{\WQ
	\W@@checkstar
	{\let\*=\W@@lapstar
	\ifLaTeXisloaded
		\leavevmode
	\else
		\noindent
		\bf\modstar.%
	\fi
	\WIF@@name% Print name of current include file, if there is one.
	\ifLaTeXisloaded\ \else\quad\fi
	}}

@* HARD-CODED MACROS.  
We now describe various macros hard-coded into \FWEAVE, and their support macros.

@*1 Comments.
Comments are C-style.  The long comment construction `|/* ...*/|' 
is output as `|\WC{ ... }|'; the short comment is output as `|\Wc{ ...}|'. 
The |\WC| and~|\Wc| macros aren't simply defined with an argument
whose text would be the comment because one wants the comment to be a group
and the user might be wanting to change catcodes inside that group; the
argument form would absorb catcodes before they were changed.

@A
\def\W@@skipbrace#1{\catcode`\{=1 }

\DRC\WC{\W@@cmnt{/\ast}{\W@@finishcomment}}% Long
\DRC\Wc{\W@@cmnt{//}{\XX}}% Short
\DRC\Wci{\W@@cmnt{}{\XX}}% No comment symbol at all; for special effects.

\def\W@@cmnt#1#2{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi% C-style cmnt
	\XX\hfil\penalty-1\hfilneg
	\ifyskip\else\quad\fi$#1\,$%
	\bgroup\cmntfont % The user can redefine the comment font |\cmntfont|.
		\aftergroup#2%
		\catcode`\{=\other\W@@skipbrace}

\def\W@@finishcomment{$\,\ast/$\XX}

\def\Wx#1{\kern-0.5\notch\hbox{\tt\%}}

@ Compiler directives are essentially comments, but are formatted more like
preprocessor commands.
@A
\def\WCDIR#1{\WPR?\Wtypewriter{#1}\WPs}

@*1 Code mode.  Code mode is entered by vertical bars, giving an effect
such as |@c x=y|.  Because we make |\WCD| a robust command, code mode may
be used inside the names of starred sections (\LaTeXe\ only).

@A
\DRC\WCD[1]{\ifmmode\hbox\fi{\ignorespaces#1}}

@*1 Definitions. Various definition section stuff.
@A
\def\WD:#1:{\W@@defin{@@D}{#1}}% Outer macro definition: `\.{@@D}' 
\def\Wd:#1:{\W@@defin{@@d}{#1}}% Outer macro definition: `\.{@@d}' 
\def\WUd:#1:{\W@@defin{@@u}{#1}}% Undef outer macro: `\.{@@u}'.
\def\WMD{\W@@defin{@@M}{}}% WEB macro definition: `\.{@@M}'.
\def\WMd{\W@@defin{@@m}{}}% WEB macro definition: `\.{@@m}'.
\def\WE:#1:{\WPR{\##1}}% WEB preprocessor command: `\.{@@\#if\dots}'.

\def\Wf:#1:{\W@@defin{@@f}{#1}}% Format definition: `\.{@@f}'.
\def\WF:#1:{\W@@defin{@@F}{#1}}% Format definition: `\.{@@F}'.

\def\Wl:#1:{\W@@defin{@@l}{#1}}% Limbo text definition: `\.{@@l}'.
\def\Wv:#1:{\W@@defin{@@v}{#1}}% Operator overloading: `\.{@@v}'.
\def\WWW:#1:{\W@@defin{@@W}{#1}}% Identifier overloading:  `\.{@@W}'.
\def\Ww:#1:{\W@@defin{@@w}{#1}}% Identifier overloading:  `\.{@@w}'.

@*1 Sections.  
\FWEB\ supports both page number or section-number references.
The style-file entry \.{encap.prefix} defines a \TeX\ macro---empty by
default for TeX, ``|\M|'' by default for \LaTeX.  When this macro is
non-empty, it encloses the integer section numbers that are spit out by \FWEAVE.
The |\Wbegin| macro uses |\W@@modequate| to define this macro to
|\Wmodtrans|, which is the primitive that actually interprets the section
number.  For \TeX, |\Wmodtrans| is just the identity, so one gets ordinary
section numbers.  For \LaTeX, |\Wmodtrans| converts into either page or
section numbers, depending on the setting of |\ifpagerefs|.  

@*2 Customizing the referencing style.
(As an example, the current document is produced with the non-default
settings |\numberdefsfalse| and |\numbercodefalse|.)
@A
\newif\ifpagerefs% Page references or module-number references?
\pagerefsfalse

\newif\ifnumberTeX% Do we start the \TeX\ part of unnamed sections with
% a section number? 
\numberTeXfalse

\newif\ifnumberdefs% As above, but for the definition part.
\numberdefstrue

\newif\ifnumbercode% As above, but for the code part.
\numbercodetrue

% The following works in conjunction with the \LaTeXe\ package |fwebnum|.
\newif\ifnumberunnamed% Number unnamed section?
\numberunnamedfalse

\newskip\Wuparindent
\let\Wrefstepcounter\refstepcounter

% The following flag is explained in \WEBsection{strip}.
\newif\ifstripzeros
\stripzerostrue % By default, we're bold.

\def\W@@modequate#1{\def\W@@temp{#1}%
\ifx\W@@temp\empty\else
	\gdef#1{\Wmodtrans}%
\fi}

@*2 Sectioning commands.
When LaTeX is selected with ``\.{-PL}'' (this is now the default), we use
LaTeX's sectioning 
commands.  The |\W@@depth| macro is defined at the bottom of the \.{aux} file
to be the maximum depth of the \.{@@*}$n$ commands, plus~1.  In other
words, it's the effective level of the unnamed sections.

@A
\newcount\W@@ssmax% Maximum depth of the \.{@@*}$n$ commands.
\newcount\W@@lsmax% Maximum local (per section) depth of the \.{@@*}$n$ commands.

\def\Wunnamed#1#2{\csname ifnumber#1\endcsname
	\gdef\Wnewoutname{#2}%
	\ifx\Woutname\Wnewoutname\else
		\8\.{"#2"} \Wscrap ${}\equiv{}$\6%
		\global\let\Woutname\Wnewoutname
	\fi\fi}

@ The |\W@@Lvmode| macro is basically a redefinition of \LaTeX's |\addpenalty|
command to include the |\vfil| and |\vfilneg| commands.  This is supposed
to encourage it to break between sections.

When |\secpenalty| is non-negative, however, |\addpenalty| is not
redefined, and breaking at sections is not encouraged.  The tricky thing is
to set |\secpenalty| at the appropriate place.  The solution is to use the
style-file and say ``\.{doc.preamble "\\secpenalty0"}''.  This is executed
just before the |\W@@raggedbottom| command during |\Wbegin|.

@A
\newcount\secpenalty
\secpenalty=-500 % Strongly encourage breaks at sections.

% Although the following is used only in \LaTeX, don't put it inside the
% |\ifLaTeXisloaded| because of \TeX's |\if| parsing.
\def\W@@Lvmode#1{
\if@@minipage\else
\if@@nobreak\else
\ifdim\lastskip=\z@@
	\vfil
	\penalty#1\relax
	\vfilneg
\else
	\@@tempskipb\lastskip
	\vskip-\lastskip
	\vfil
	\penalty#1
	\vfilneg
	\vskip\@@tempskipb
\fi\fi\fi}

\ifLaTeXisloaded

	\def\W@@raggedbottom{\def\@@textbottom{\vskip\z@@ \vfil}%
		\let\@@texttop\relax
% Very strongly encourage to break at beginning of sections.
		\@@secpenalty=\secpenalty
		\ifnum\secpenalty<0
			\def\addpenalty##1{%
				\ifvmode
					\W@@Lvmode{##1}%
				\else
					\@@noitemerr
				\fi}
		\fi
		}

@ The deepest named section is \.{1.1.1}, corresponding to a
sub-sub-section.  The associated unnamed section will then be a
sub-sub-sub-section, which we must declare.
@A
	\newcounter{subsubsubsection}

	\gdef\thesubsubsubsection{\thesubsubsection.\arabic{subsubsubsection}}

	\gdef\cl@@subsubsubsection{\@@elt{paragraph}}
	\gdef\l@@subsubsubsection{\@@dottedtocline{4}{3.8em}{3.2em}}
	\gdef\subsubsubsectionmark#1{}

 \ifnoLaTeXe
	\gdef\paragraph{\@@startsection{paragraph}{5}{\z@@}{3.25ex plus1ex
minus.2ex}{-1em}{\reset@@font\normalsize\bf}}
 \fi

% After the \.{aux} file is read, we must set things up based on the depth
% parameter |\W@@depth|. 
	\gdef\W@@setsecdepth{%
		\@@ifundefined{W@@depth}{\gdef\W@@depth{1}}{}%
		\setcounter{secnumdepth}{\W@@depth}%
		\setcounter{tocdepth}{\W@@depth}%
% Redefine appropriate section heading to begin the unnamed section.
% At the moment, this only works right if the major sections don't go down
% any deeper than 1.1.1.
		\ifnumberunnamed
			\Wuparindent0pt
			\addtocounter{secnumdepth}{1}%
			\gdef\WRefstepcounter##1{}%
		\else
			\Wuparindent-\parindent
			\global\let\WRefstepcounter\Wrefstepcounter
		\fi
		\ifcase\W@@depth % Level 0; should never happen.
		\or % Level 1
			\gdef\subsection{\WRefstepcounter{subsection}%
\@@startsection{subsection}{2}{\z@@}{-3.25ex plus-1ex minus-.2ex}{\Wuparindent}
{\reset@@font \normalsize \bf}}%
			\global\let\Wunnamedsect\subsection
		\or % Level 2
			\gdef\subsubsection{\WRefstepcounter{subsubsection}%
\@@startsection{subsubsection}{3}{\z@@}{-3.25ex plus-1ex minus-.2ex}
{\Wuparindent}{\reset@@font \normalsize \bf}}%
			\global\let\Wunnamedsect\subsubsection
		\or % Level 3
			\gdef\subsubsubsection{%
\WRefstepcounter{subsubsubsection}%
\@@startsection{subsubsubsection}{4}{\z@@}{-3.25ex plus-1ex minus-.2ex}
{\Wuparindent}{\reset@@font \normalsize \bf}}%
			\global\let\Wunnamedsect\subsubsubsection
		\else
			\global\let\Wunnamedsect\paragraph
		\fi
		}

@*2 Converting module numbers into section or page numbers.
Here is the primitive macro that converts a module number into \LaTeX's
section number or page number.  This works by label information written
to the \.{aux} file by the \FWEAVE\ section macros |\WM| and |\WN|.
@A
	\gdef\Wmodtrans#1{\@@ifundefined{r@@#1}
		{\W@@split{\##1}{\##1}{0}{0}}
		{\expandafter\expandafter\expandafter
			\W@@split\csname r@@#1\endcsname{#1}}%
		}

@ Here we convert the \.{aux} label info into a page or section number.
Pages are not too complicated.  The real problem comes with ensuring that
the unnamed sections are numbered at the deepest depth of the file, but
only for the particular section.  Because the mechanism is complicated, we
introduce a flag |\stripzeros| that can turn it off if it doesn't work.
\modlabel{strip}
@A
	\gdef\W@@split#1#2#3#4{%
		\ifpagerefs
			#2%
			\@@ifundefined{W@@#3}%
				{\setcounter{W@@tempcounter}{#4}%
				\addtocounter{W@@tempcounter}{-#3}%
\ifnum\value{W@@tempcounter}>25 \setcounter{W@@tempcounter}{25}\fi
				\hbox{\alph{W@@tempcounter}}}
				{}%
		\else
			\ifstripzeros
				\W@@strip#1.,%
			\else
				#1
			\fi
		\fi
		}

@ In order to know how to strip, each major section at level 0 writes out
to the \.{aux} file a line of the form |\Lastdepth{lastsect}{maxdepth}|.
When the \.{aux} file is read in,  |\Lastdepth| defines macros of the form
|\l@@lastsect|. These can then be used to control the zero stripping.

For example, the raw section number might be \S4.0.0.1, because the
maximum depth |\W@@depth| for some section (not necessarily \S4) was 3.
However, if \S4 had no subsections at all (a last depth of 1), we can
number the unnamed section \S4.1---i.e., we want to strip off $3 - 1 = 2$
units of `\.{.0}'.  This is what |\W@@STRIP| does.  The intermediate macros
beginning with |\W@@strip| take care of various subsidiary annoyances.

|\W@@strip| picks off the level-0 section number from its argument.  It
must also watch out for an argument of the form |\#5|, which arises when
the \LaTeX\ section number is undefined.
@A

	\def\W@@strip#1.#2,{\W@@first#1\relax \W@@tempc{#1}{#2}}

	\def\W@@first#1#2\relax{\ifx#1\#\def\W@@tempc##1##2{##1}\else
\def\W@@tempc##1##2{\W@@Strip{##1.##2}
{\@@ifundefined{l@@##1}{0}{\csname l@@##1\endcsname}}}\fi}

@ |\W@@Strip| gets two arguments of the form `\.{4.0.0.1.}' and the last
maximum depth.
@A
	\def\W@@Strip#1#2{\W@@STRIP#1\relax{#2}}

@ |\W@@STRIP| kills off the final dot, figures out how many zeros to strip,
constructs a macro definition with the appropriate template, then applies
it to the section number.
@A
	\def\W@@STRIP#1.\relax#2{{%
\W@@tk={}\W@@count=0
\W@@counta=\W@@depth
\advance\W@@counta by-#2 % How many zeros to strip.
\loop
\ifnum\W@@count<\W@@counta
	\advance\W@@count by1
	\edef\next{\W@@tk={\the\W@@tk.0}}\next % Build template `\.{.0.0\dots}'.
\repeat
% We must worry about the possibility that there are no zeros at all.
\let\eat\let
\edef\next{\def\noexpand\reduce####1\the\W@@tk####2\eat####3\eat
{####1####2}}%
\next
\edef\next{\noexpand\reduce#1\eat\the\W@@tk\eat\eat\relax}%
\def\eat##1{}%
\next}}

	\global\let\modno\empty
	\global\let\W@@name\empty

@*2 Beginning of unnamed section.
@A
	\def\WM#1.{\WMN#1.%
		\W@@mark{{\oldmodno}{\oldWname}}{{\modno}{\W@@name}}%
		\ifon
			\advance\W@@ss by10 %
			\W@@start{\ifnumberTeX\Wmodtrans{\modno}\fi}% ????
			\advance\W@@ss by-10 %
			\ignorespaces}
\else % No \LaTeX; for \TeX, one just gets module numbers.
	\def\Wmodtrans#1{#1}

	\outer\def\WM#1.{\WMN#1.\W@@mark\ifon\Wskip\W@@startsection\ignorespaces}
\fi % End of no \LaTeX.

@*2 Beginning of starred section.
Starred sections  (begun with~`\.{@@*}')
have associated level numbers, where 0~denotes the most significant level,
1~denotes a subsection, 2~denotes a subsubsection, and so on.  One can
indicate the level number in several ways.  By default, one can say
``\.{@@*3\ Section name.}'' or equivalently ``\.{@@*...\ Section name.}''
to set the level number to~3.  Alternatively, if one replaces the line below
``\.{\\W@@dotsafterfalse}'' with ``\.{\\W@@dotsaftertrue}'', one can instead say
``\.{@@*\ Section name....}'' (but don't do it).

For \TeX:  By default, major sections get a page break;
subsections don't.  Sections and subsections can be formatted in different
ways in the table of contents by enhancing the definition of~|\WZ|
(inside~|\Wcon|) to include an |\ifcase| construction.  

For \LaTeX:  The appropriate \LaTeX\ section command is used.

@A
\newcount\W@@ss % Counter for the dots.

\newif\ifW@@dotsafter % Do subsection dots come after or before the section name?
\W@@dotsafterfalse

\ifW@@dotsafter % ``@@* NAME...''
	\def\W@@before:#1.{\W@@defname{#1}\W@@dot}%
	\def\W@@fter{\W@@Nss}%
\else % ``@@*.. NAME.'' or ``@@*2 NAME.''
	\def\W@@before: {\futurelet\next\W@@check}%
	\def\W@@fter#1.{\W@@defname{#1}\W@@Nss}% Done after figuring out level.
	\def\W@@fter@@#1 #2.{\W@@defname{#2}\W@@Nss}%
\fi

\def\W@@check{\ifx\next.\def\next{\W@@dot.}% Count arbitrary dots.
	\else\ifx\next1\W@@sectionnum1%
	\else\ifx\next2\W@@sectionnum2%
	\else\ifx\next3\W@@sectionnum3%
	\else\ifx\next4\W@@sectionnum4% Highest numerical level allowed.
	\else\let\next\W@@fter
	\fi\fi\fi\fi\fi
	\next}%

\def\W@@sectionnum#1{\W@@ss#1\let\next\W@@fter@@}% Assign numerical sec.\ number.

\def\W@@defname#1{\gdef\W@@name{#1}}% Remember name of section.

\def\WN#1.{\WMN#1.\W@@ss=0 \W@@before:}% Begin a starred section.

@ Here we set up to output the maximum local section depth to the table of
contents.  For more explanation, see \WEBsection{strip}.
@A
% Put this here, not inside |\ifLaTeXisloaded|.
	\def\W@@outlsmax#1{\if@@filesw
	{%
% The following doesn't work if one uses something like \Roman for
% \thesection.  If we only used LaTeX, it would be trivial to fix by
% replacing \@currentlabel by \c@section (I think).
	\expandafter\W@@major\@@currentlabel.\relax
	\advance\W@@count by#1
	\advance\W@@count by-1
	\advance\W@@lsmax by1
	\edef\@@tempa{\write\@@auxout{\string\Lastdepth{\the\W@@count}%
{\the\W@@lsmax}}}% 
	\expandafter}\@@tempa
	\fi
	\W@@lsmax=0
	}

\ifLaTeXisloaded

	\def\W@@major#1.#2\relax{\W@@count=#1}% Get the major section.

	\def\Lastdepth#1#2{\edef\@@tempc{\gdef\expandafter\noexpand
\csname l@@#1\endcsname{#2}}\@@tempc}

\else
	\def\W@@outlsmax#1{}
\fi

@ Here we count the periods before or after the section name.
@A
\def\W@@dot{\futurelet\next\W@@Ns}

\def\W@@Ns{\ifx\next.%
	\advance\W@@ss by 1
	\let\next\W@@next
\else
	\let\next\W@@fter
\fi
\next}

\def\W@@next#1{\W@@dot}

@ Now actually begin the section.  Note the use of~|\ifcase| to
conditionally format the sections and subsections.  Also, the construction
|\ifon...\fi| brackets the section to conditionally suppress printing.
Finally, we make an entry in the table of contents for all starred names.
The first argument of the \.{\\WZ}~macro is the level number for this
section.  This can be used to format the table of contents in various ways.

The order of expansion is an issue in the~|\write| to the table of contents
file~|\W@@cont|.  One wants the macro~|\WZ| to be sent unexpanded, so we
|\let|~it equal to a primitive.  Also, it's possible that a~|\WIN| will
appear inside of~|\W@@name| (if the user included certain kind of code inside
the section name).  This shouldn't be expanded until later, so we turn that
into the temporarily unexpandable macro~|\WIM|.  (This is presumably
unnecessary for \LaTeXe, since |\WIN| is made robust.)

@A
% Page break for major sections.
\ifLaTeXisloaded
	\let\Wsectionbreak\relax
\else
	\def\Wsectionbreak{\ifcase\W@@ss\vfil\eject\fi}
\fi

% Running headline.
\def\rhead{\ifcase\W@@ss
		\uppercase{\ignorespaces\W@@name}%
	\else
		\ignorespaces\W@@name%
	\fi}% Define running headline.

\let\WZ\let % Now one can |\send| the control sequence |\WZ|
\let\WIM\let % This macro is made temporarily unexpandable; see |\WZ|.

\def\W@@Llabel#1{\@@bsphack
	\if@@filesw
		{\let\thepage\relax
		\let\W@@botmodno\relax
		\def\protect{\noexpand\noexpand\noexpand}%
		\edef\@@tempa{\write\@@auxout{\string\Newlabel{#1}%
{{\@@currentlabel}{\thepage}}{\W@@botmodno}}}%
		\expandafter}\@@tempa
		\if@@nobreak
			\ifvmode
				\nobreak
			\fi
		\fi
	\fi
	\@@esphack}

\ifLaTeXisloaded
	\gdef\W@@Nss{%
		\W@@mark{{\oldmodno}{\oldWname}}{{\modno}{\W@@name}}%
% Can't put this in |\WMN| since |\rhead| must be defined first. 
		\message{*\modno}% Progress report to the terminal.
		\ifon
			\ifnum\W@@ss>\W@@ssmax
				\global\W@@ssmax=\W@@ss% Keep track of max depth.
			\fi
			\ifnum\W@@ss>\W@@lsmax
				\global\W@@lsmax=\W@@ss% Maximum local depth.
			\fi
			\W@@start{\W@@name}%
			\ignorespaces
		}

	\def\steppagemodule{\noexpand\expandafter\expandafter\expandafter
{\addtocounter{pagemodule}{1}}\thepagemodule}

	\let\Wlabel\W@@Llabel

@ If the section name is exactly ``\.{INDEX}'' (or more precisely the
 contents of the style-file parameter |index.name|), we	issue the
|\beforeindex| command.  By default, this is defined as follows:  If
\.{multicol.sty} is not loaded, we switch into 
|\twocolumn| mode, thereby starting the index on a new page.  If it is
loaded, we just issue a |\newpage| command.  Later, after the beginning of
the \.{INDEX} section is executed, the |\startsection| command will begin
the multi-column mode.
@A
	\gdef\beforeindex{\ifx\multicols\undefined\twocolumn\else\newpage\fi}

	\gdef\W@@start#1{%
		{\let\protect\noexpand \xdef\Wupname{\W@@name}}%
		\ifx\Wupname\INDEX\beforeindex\fi
% Select the appropriate \LaTeX\ section command.
		\ifcase\W@@ss
			\let\Wsect\section % Level 0
		\or
			\let\Wsect\subsection % Level 1
		\or
			\let\Wsect\subsubsection % Level 2
		\else
			\let\Wsect\Wunnamedsect
		\fi
		\Wsect{#1}% LaTeX section heading.
		\ifnum\W@@ss=0 \W@@outlsmax{0}\fi
		\W@@mark{{\modno}{\W@@name}}{{\modno}{\W@@name}}%
		\Wlabel{\modno}% Section number to aux file.
		\@@ifundefined{r@@\modno}
			{\expandafter\xdef\csname r@@\modno\endcsname
				{{\@@currentlabel}{\thepage}{-1}}}
			{}% For present run.
%	\message{modno=\modno [\csname r@@\modno\endcsname]} % Debugging.
		\W@@startsection
		}
\else % No \LaTeX

\def\W@@Nss{%
	\let\protect\noexpand
	\W@@mark % Can't put this in |\WMN| since |\rhead| must be defined first. 
	\Wsectionbreak % Typeset the break between sections.
	\message{*\modno}% Progress report to the terminal.
	\ifon
		\ifcase\W@@ss\else\Wskip\fi
		\W@@startsection{\bf\ignorespaces\W@@name.\quad}%
		{\def\WIN{\WIM}%
		\edef\next{\write\W@@cont{\WZ{\the\W@@ss}{\W@@name}%
		{\modno}{\noexpand\the\pageno}}}\next}%
			% To contents file |CONTENTS.tex|.
		\ignorespaces}
\fi

@ The marks that are emitted just before |\Wsectionbreak| are of the form
``{\it modno}|\else|{\it section name}''.   Both  parts are used in the
page headers.  In handling the section name, one must take care to avoid
expanding the macro~|\WIN| prematurely.  This is done just as in~|\W@@Nss| above.

@A
\def\W@@markN{\def\W@@mark{{\def\WIN{\WIM}%
		\mark{\modno\noexpand\else\rhead}}}}

\ifx\selectfont\undefined
	\W@@markN
\else
	\def\W@@mark{{\def\WIN{\WIM}\let\protect\noexpand
		\mark{\modno\noexpand\else\rhead}}}
\fi

\def\Wmodno{\iftrue\topmark\fi}% Extracts the left-hand part of the mark.

\def\Whead{{\let\WIM\WIN
	\expandafter\iffalse\topmark\fi}}% Extracts the right-hand part.

@ Common code for |\WM|, |\WN|.  
@A
\def\WMN#1.{\par
	\parskip=\pardimen % Reset to \TeX\ spacing
	\parindent=\TeXindent
	{\ifLaTeXisloaded
		\global\let\oldmodno\modno
		\global\let\oldWname\W@@name
		\xdef\@@currentlabel{\modno}%
		\global\let\Woutname\empty
		\addtocounter{pagemodule}{1}%
	\fi
	\xdef\modstar{#1}%
	\let\*=\empty
	\xdef\modno{#1}%
	}
	\ifx\modno\modstar 
		\global\onmaybe 
	\else
		\global\ontrue 
	\fi
	}

\let\MN\WMN % Backward compatibility.

@*1 Nuweb mode.
When the `N' mode is in effect, code to be transcribed verbatim will be
bracketed by |\WBM|\dots|\WEM|.

@A
\def\Wscrap{{\footnotesize\Wmodtrans{\modno}%
	\ifW@@modchanged*\fi}}

{\gdef\@@verbatim{\if@@minipage \else \vskip \parskip \fi
\leftskip 
 \@@totalleftmargin \rightskip \z@@ \parindent \z@@ \parfillskip \@@flushglue
\parskip \z@@ \@@@@par \@@tempswafalse \def \par {\if@@tempswa \hbox {}\fi
\@@tempswatrue  
\@@@@par \penalty \interlinepenalty }\obeylines \tt \catcode ``=13
\@@noligs \let \do \@@makeother \dospecials}}

{\catcode`/=0 /catcode`/\=12 /catcode`/^^I=13 
/gdef/WBM{%/8/kern/notch
/begingroup
/parindent/W@@globalindent/notch /advance/parindent by-1/notch
/def/par{/endgraf/leavevmode}%
/catcode`^^I=13 /def^^I{/leavevmode/penalty10000/ / / / / / / / }%
/catcode``=13 /@@noligs /tt 
/let/do/@@makeother /dospecials 
/@@vobeyspaces/frenchspacing/obeylines 
/W@@M}
/gdef/W@@M#1\WEM{#1/endgroup}}

@*1 Constants.  Various kinds of constants are handled:  decimal~(|@c 10|),
hexadecimal~(|@c 0xA|), octal~(|@c 012|), boolean~(|@c 0b1010|), 
floating-point (|@c 1.5e-35|), double-precision (|@n @e3.2d100|),
long (|@c 99999L|), unsigned (|@c 99999U|),
unsigned long (|@c 999999UL|), and Hollerith (|@r 3Habc|).

@A
\def\WDP#1{\ifx E#1\else{\tt#1}\fi}% Used in the exponent macro below.

\DRC\WO[1]{%
	{% Make the next definitions local.
	\let\-\_%
	\let\d\$%
	\def\\{\let\_\-\let\$\d}%
	\def\?{\kern.2em}%
	\def\###1{\kern0.1em{\tt \ifcase##1F\or L\or U\or UL\else?\fi}}%C~constant. 
	\def\^##1{\cdot 10^{\aftergroup}\aftergroup\WDP\aftergroup##1}% Power of ten
	\def\_{_{\\\rm\aftergroup}}% Fortran-90 kind parameter.
	\def\%{{\rm H}\hbox{\aftergroup}\Wtypewriter{\aftergroup}}% Hollerith constant
	\def\&{0{\tt b}}% Binary constant.
	\def\~{\hbox{\rm\char'23\kern-.2em\it\aftergroup\?\aftergroup}}% Octal
	\def\`{\hbox{\rm\char"7D\tt\aftergroup}}#1}}% Double quotes for hex constant


@*1 Code mode.  Either begin the code section, or a preprocessor or
definition command.

The following command sets up~|\W@@ind|.  This somewhat peculiar construction
is for historical reasons.
@A
\def\WPr{\global\W@@ind=\W@@globalindent \1}

@ Now enter code mode.  Note that |\leavevmode| starts a new indented
paragraph; we then move in one more notch.
@A
\def\WP{\parskip=0pt \parindent=\notch
	\rightskip=0pt plus 100pt minus 10pt 
	\sfcode`;=3000
	\pretolerance 10000
@#if 0
	\hyphenpenalty 10000 \exhyphenpenalty 10000 % If one turns these on, the
	% discretionary breaks in strings won't work!
	\global\W@@ind=\W@@globalindent \1\ \unskip}
@#endif
	\WPr
	\leavevmode\kern\notch}

@ Here we leave code mode:
@A
\def\WQ{\rightskip=0pt
	\sfcode`;=1500 \pretolerance 200 \hyphenpenalty 50 \exhyphenpenalty 50 }

@* MISCELLANEOUS OPERATORS.
Most of these are also hard-coded into \FWEAVE, and emitted automatically.
@A
\def\WA{\note{See also}}% Cross-reference for multiply defined section names.

\def\Wauto[#1]{\Wtypewriter{[#1]}\ }

\DRC\WB{\mathopen{\Wtypewriter{@@/\ast}}}% Begin controlled comment.

\let\WG\ge % Greater than or equal sign: '$\WG$'.

\DRC\WI{\neq}% Unequal sign: '$\WI$'.  (Better reserve |\ne| for the
		% electron density~$n_e$.) 

\DRC\WJ{\Wtypewriter{@@\&}}% TANGLE's join operation: '\WJ'.

\let\WK\gets % Left arrow: '$\WK$'.

% The next one is used for statement labels in \Fortran\ and \Ratfor.
\let\Wlbl\llap

% The above puts the label on the same line as the things it's labeling. 
% Some other choices, courtesy of Bart Childs, are

% \def\Wlbl{\hskip-\notch} % jut into the left white space
% \def\Wlbl{} % Maintains indentation.

% To put the statement label on the previous line, use the `|-n:|' option.

\let\WL\le % Less than or equal sign: '$\WL$'.

\let\WLA\langle % Opening of template:  '$\WLA$'.
\let\WRA\rangle % Closing of template:  '$\WRA$'.

\DRC\WTLD{\.{@@\~}}

\def\Wskip{\vfil\penalty-100\vfilneg \vskip12ptminus3pt}% See |\WM|, etc.

\def\Wskipped#1{\8\mathhexbox278.\quad\Wtypewriter{@@I "#1"}\ \ {\it Section(s)
skipped}\dots\WP} 

\let\WPtr\Rightarrow % Fortran's stupid pointer assignment statement:
		% '$\WPtr$'. 

\let\WR=\lnot % Logical not: '$\WR$'.

\let\WS=\equiv % Equivalence sign: '$\WS$'.
\let\WSQ=\equiv % This symbol is used when defining a section name.

\DRC\WT{\mathclose{\Wtypewriter{@@\ast/}}}% Terminate controlled comment.

\def\WU{\note{This code is used in}}% Cross-reference for uses of sections.

\let\WV\lor % Logical or: '$\WV$'.

\let\WW=\land % Logical and: '$\WW$'.

@*1 Formatting a section name.
Here's how to format a section name. Argument~1 is the name, argument~2
is the section number, and argument~3 is the language symbol.
@A
\ifLaTeXisloaded
\else
	\let\footnotesize\eightrm
\fi

\def\WX#1:#2\X#3\X{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi
	\XX$\langle\,$#2{\footnotesize\kern.5em#1}%
$\,\rangle^{\mathrm{#3}}$\XX}

@
@A
\def\WY{\par
	\yskip
	\parskip=0pt} 

@
The following were for Pascal.
@<Unused@>=

\def\){\hbox{\Wtypewriter{@@\$}}}% sign for string pool check sum
\def\]{\hbox{\Wtypewriter{@@\\}}}% sign for forced line break

@*1 Questions and colons.
For C's construction `|@c x ? 1 : 0|'.
@A
\DRC\?{\mathrel?}

@ Colons have several uses.
@A
\DRC\Colon{\ifmmode\colon\else:\fi}

\DRC\CC{\mathord{::}}% For C:  '$x\CC y$'.
\DRC\CF{{}\mathbin{::}{}}% For \Fortran:  '$x\CF y$'.


@*1 Verbatim strings.
Verbatim strings are boxed for emphasis, like this:  \Wequals{This is a
verbatim string.}

@A
\DRC\=[1]{\kern2pt\hbox{\vrule\vtop{\vbox{\hrule
	\hbox{\strut\kern2pt\Wtypewriter{#1}\kern2pt}}
	\hrule}\vrule}\kern2pt}

\let\Wequals\=

@ 
@A
\let\~=\ignorespaces
\let\*=*

@*1 Accreting to modules.
The following symbol is used to denote accretions to already-existing
modules. 
@A
\def\PQ{\mathrel{+\mathord\equiv}}% '$\PQ$'.

@*1 Exponentiation.
The exponentiation macros strip away outer parentheses from the argument,
turning ``|x^(a+b)|'' into ``|@n x^(a+b)|''.
@A
\def\LP{(}% Must be |\def|, not |\let|.
\def\ISL#1#2]{\def\next{#1}}
\DRC\EE[1]{\ISL#1]\ifx\next\LP\EXP[#1]\else\EXP[(#1)]\fi}
\def\EXP[(#1)]{^{#1}}

@#if 0
\def\EE{\mathord{\hbox{\tt\^}}}% Poor-man's exponentiation; above is better.
@#endif

@*1 \Fortran.
@A
\let\SlSl\parallel% Concatenation: '$\SlSl$'.

\DRC\EQV{\mathrel{?{=}}}% `$x\EQV y$'.
\DRC\NEQV{\not\equiv}% `$x\NEQV y$'.

@ For \Fortran--90's `|@n (/a,b,c/)|'.
@A
\DRC\LS{\mathopen{({/}}}
\DRC\SR{\mathclose{{/})}}

@ The standard \Fortran\ \.{.FALSE.} and \.{.TRUE.} operators.
@A
\DRC\FALSE{{\cal F}}% '$\FALSE$'.
\DRC\TRUE{{\cal T}}% '$\TRUE$'.

@ Block/loop numbers in \Fortran.  {\it Note:  One can't replace the
|\bgroup| and |\egroup| by braces because of peculiarities of~|\Wc|.  Also,
if one puts an explicit comment on a line that will be labelled by
|\Wblock|, with the following definition one will get two comments side by
side.  However, this could be modified by setting a counter to the block
number and making a fancier definition of~|\WC| and~|\Wc|.}
@A
\def\Wblock#1{\Wc\bgroup\ Block #1\egroup}% `\Wblock{99}'

@*1 Macro tokens.
@A
\def\NN{\hbox{\#\#}}% '\NN'.
\def\NP{\hbox{\#!}}% '\NP'.
\def\NC{\hbox{\#:}}% '\NC'.
\def\ND{\hbox{\#.}}% '\ND'.
\def\Nq{\hbox{\#\tt'}}% '\Nq'.
\def\NQ{\hbox{\#\tt"}}% '\NQ'.

@*1 C operators.
@A
\mathchardef\TLD="0218 % '$\TLD$'.

\DRC\PP{\mathord{++}}% '$\PP$'.
\DRC\MM{\mathord{--}}% '$\MM$'.

\DRC\MG{\mathord{\to}}% '$\MG$'.

\DRC\Wcp{\mathrel{+{=}}} \let\PE\Wcp % `$x\PE y$'.
\DRC\Wcm{\mathrel{-{=}}} \let\ME\Wcm % `$x\ME y$'.
\DRC\Wcs{\mathrel{\ast{=}}} \let\TE\Wcs % `$x\Wcs y$'.
\DRC\Wcv{\mathrel{/{=}}} \let\FE\Wcv % `$x\FE y$'.
\DRC\Wcd{\mathrel{\%{=}}} \let\CE\Wcd % `$x\Wcd y$'.
\DRC\Wcx{\mathrel{\^\!{=}}}% `$x\Wcx y$'.
\DRC\Wca{\mathrel{\amp{=}}}% `$x\Wca y$'.
\DRC\Wco{\mathrel{\OR{=}}}% `$x\Wco y$'.
\DRC\Wcg{\mathrel{\GG\!{=}}}% `$x\Wcg y$'.
\DRC\Wcl{\mathrel{\LL\!{=}}}% `$x\Wcl y$'.

@ More C operators.
@A
\DRC\MOD{\mathrel{\%}}% `$x\MOD y$'.
\DRC\OR{{\,|\,}}% `$x\OR y$'.
\DRC\AND{{\,\amp\,}}% `$x\AND y$.

\DRC\GG{\mathrel{>\!>}}% `$x\GG y$'.
\DRC\LL{\mathrel{<\!<}}% `$x\LL y$'.

\DRC\HE{\mathrel{\uparrow=}}% `$x\HE y$'.

@*1 Braces.
We allow braces to be easily displayed outside of math mode.
@A
\let\openbraces=\{
\let\closebraces=\}
\def\{{\ifmmode\openbraces\else$\openbraces$\fi}
\def\}{\ifmmode\closebraces\else$\closebraces$\fi}

@*1 Metacomments.
@A
% Print the meta-comment symbols.
%\def\WBM{\6\8\Wreserved{@@(}}
%\def\WEM{\6\8\Wreserved{@@)}}

% Don't print the meta-comment symbols.
%\def\WBM{}
%\def\WEM{}

@* OVERLOADING OPERATORS.  Operator overloading is annoying because several
languages may be in use simultaneously.  Therefore, when we define an
overloaded  macro name, we append to it the language symbol, creating
macros such as |\op_C|.  These macros are typically defined automatically
at the beginning of the output file from information contained in
\.{@@v}~commands. 

@A
\newif\ifop
\newbox\dotbox

\def\Wunknown#1{\={??#1??}}% For unknown dot constant.

{\catcode`\_=11

\gdef\newop#1#2#3{%
	\edef\next{\def\expandafter\noexpand\csname _#1_#2\endcsname}%
	\next{#3}}

\gdef\newbinop#1#2#3{%
	\edef\next{\def\expandafter\noexpand\csname _#1_#2\endcsname}%
	\next{\mathrel{#3}}}

\gdef\newunop#1#2#3{%
	\edef\next{\def\expandafter\noexpand\csname _#1_#2\endcsname}%
	\next{\mathbin{#3}}}

\gdef\Wop#1#2{\setbox\dotbox\hbox{\tt .#1.}%
	\edef\nxt{\expandafter\noexpand\csname _#1_#2\endcsname}%
	\edef\ifnxt{\noexpand\ifx\expandafter\noexpand\csname _#1_#2\endcsname}%
	\ifnxt\empty
		\def\next{\box\dotbox}% Macro not defined; just use \.{.NAME.}.
	\else
		\def\next{\futurelet\nextchar\W@@q}% Be careful about |\EE|.
	\fi
	\next}%
}

\global\let\Wb\Wop
\global\let\Wu\Wop

\let\Lbrace{

\def\W@@q{\ifx\nextchar\Lbrace
		\let\next\nxt % There's an argument coming up.
	\else
		\ifop
			\def\next{\nxt{}\equiv\box\dotbox}%
		\else
			\let\next\nxt
		\fi
	\fi
	\opfalse
	\next}

@ The following macro translates overloaded identifiers into their \TeX\
equivalents.
@A
\DRC\WTeX[1]{\ [{\ifmmode\def\XX{}\else\def\XX{\null$\null}\fi
\XX#1\XX}]\ }

@* ACTIVE ARRAY INDICES.
The following is for special handling of array indices, when the |-W[|
option is used.
@A
\newtoks\W@@ARRAYarga
\newtoks\W@@ARRAYargb

\DRC\WXA[1]{\begingroup
% We don't want the identifiers to be in hboxes, because we want to get
% |\scriptstyle| for subscripts.  (One should always be in math mode here.)
	\def\Wshort##1{##1}%
	\def\Wid##1{\mathit{##1\/\kern.05em}}%
	\global\W@@ARRAYarga{#1}%
	\futurelet\W@@next\WARRAYm}

\def\WARRAYm{\ifx\W@@next\WXA
		\global\let\W@@next\WARRAYn% Multiple indices in C:  a[i][j][k]
	\else
		\global\let\W@@next\relax
		\WARRAY{\the\W@@ARRAYarga}% Typeset the accumulated indices.
	\fi
	\endgroup
	\W@@next}

\def\WARRAYn#1#2{\W@@ARRAYargb{#2}%
	\edef\W@@next{\noexpand\WXA{\the\W@@ARRAYarga,\the\W@@ARRAYargb}}%Concatenate
	\W@@next}

% Change the following definition---e.g., |\let\WARRAY\WSUB|---to get
% indices printed in interesting ways. 
\DRC\WARRAY[1]{[#1]}% Default definition.
\DRC\WSUB[1]{_{\scriptstyle#1}}% E.g., subscript indices.

@* MISCELLANEOUS MACROS.
@*1 Handle the \.{@@o}~command.
@A
\def\Wouto#1#2{\Wreserved{@@#1}\W@@Hspace\Wtypewriter{#2}}
\def\Wout#1{\Wouto{o}{#1}}
\def\WOut#1{\Wouto{O}{#1}}

@*1 Symbolic labels.
Assign a symbolic name to a module.  This scheme has no forward
referencing at present for plain \TeX, although this could easily be
extended.  For \LaTeX, forward referencing works because the \.{aux}~file
is used.
@A
% Label a section with an identifying name.
\def\modlabel#1{%
	\ifLaTeXisloaded
		\label{MOD#1}%
	\else
		\edef\next{\gdef\expandafter\noexpand\csname MOD#1\endcsname{\modno}}%
		\next
	\fi}

% Print the number of a labelled section.
\def\Wmodule#1{\ifLaTeXisloaded
		\ref{MOD#1}%
	\else
		\csname MOD#1\endcsname
	\fi} 

% Examples of references to sections.  
\def\WEBsection#1{section~\Wmodule{#1}}% |\section| is used by \LaTeX.
\def\WEBmodule#1{module~\Wmodule{#1}}
\let\module\WEBmodule% For backward compatibility.

@*1 Language commands.
 Language commands are printed in the left margin, following Knuth's
solution in Appendix~A of the \TeX book.  They are actually printed one
line down, because the language command is gobbled up before the line break
is emitted.

@A
\def\strutdepth{\dp\strutbox}

\def\W@@marginal#1{\strut\vadjust{\kern-\strutdepth\W@@specialmargin{#1}}}

\def\W@@specialmargin#1{\vtop to\strutdepth{
	\baselineskip\strutdepth
	\vss\llap{#1 }\null}}

\def\LANGUAGE#1{\W@@marginal{\smash{\vtop{\hbox{%
	\hbox{\tt @@L\lowercase{#1}:\enspace}}\null}}}\ignorespaces}

% Use the next one if you don't want language changes to be printed.
@#if 0
	\def\LANGUAGE#1{\relax\ignorespaces}
@#endif


@* PAGE FORMAT.
Now we deal with the overall page format.

@*1 Listing the changed modules.
If you want to list only the modules that have changed,
together with the index, put the command `|\let\maybe=\iffalse|' in
the limbo section before the first module of the \.{WEB} file. It's
customary to make this the first change in the change file.

@A
\newif\ifon 
\def\onmaybe{\let\ifon=\maybe} \let\maybe=\iftrue

@ Some flags, and the number of the table of contents.
@A
\newif\iftitle \newif\ifpagesaved

\newcount\contentspageno

@*1 Headers.
Top line on left-hand pages:
@A
\def\Wmodhd#1{ [#1]}

\def\WsetLmarks{
	\def\Wsecrange##1##2{%
		\def\W@@tempa{##1}\def\W@@tempb{##2}%
		\ifx\W@@tempa\W@@tempb
			\W@@S\Wmodtrans{##1}\Wmodhd{\###1}%
		\else
		    \W@@S\Wmodtrans{##1}--\W@@S\Wmodtrans{##2}%
\Wmodhd{\###1--\###2}%
		\fi}

	\gdef\@@leftmark##1##2##3##4{%
		\let\protect\relax
		\qquad\mainfont##2
		\hfill
		\Wtitle\qquad
		\ifnum##1>0%
		  \mainfont\Wsecrange{##1}{##3}% 
		\fi
		}

	\gdef\@@rightmark##1##2##3##4{%
		\let\protect\relax
		\ifnum##1>0
			\mainfont\Wsecrange{##1}{##3}%
		\fi
		\qquad\mainfont\Wtitle
		\hfill 
		\mainfont##2\qquad
		}

	\gdef\leftmark{%
\ifnoLaTeXe
\else
	\let\protect\@@unexpandable@@protect
\fi
\edef\W@@tempb{\expandafter\iftrue\botmark\fi}%
\edef\W@@tempa{\expandafter\iffalse\topmark\fi}%
\expandafter\expandafter\expandafter\@@leftmark\expandafter\W@@tempa\W@@tempb{}{}}

	\gdef\rightmark{%
\ifnoLaTeXe
\else
	\let\protect\@@unexpandable@@protect
\fi
\edef\W@@tempb{\expandafter\iftrue\botmark\fi}%
\edef\W@@tempa{\expandafter\iffalse\topmark\fi}%
\expandafter\expandafter\expandafter\@@rightmark\expandafter\W@@tempa\W@@tempb{}{}}

	\gdef\W@@markN{\gdef\W@@mark####1####2{{\def\WIN{\WIM}%
		\mark{####1\noexpand\else####2}}}}

	\ifx\selectfont\undefined
		\W@@markN
	\else
		\gdef\W@@mark##1##2{{%\def\WIN{\WIM}%
			\let\protect\@@unexpandable@@protect
			\mark{##1\noexpand\else##2}}}
	\fi
}

\ifLaTeXisloaded
	\WsetLmarks
\else
\def\lheader{\mainfont\the\pageno\eightrm\qquad\Whead\hfill\Wtitle\qquad
	\ifnum\pageno=\contentspageno\else
		\W@@S\mainfont\Wmodno
	\fi}

\def\rheader{\ifnum\pageno=\contentspageno\else
		\W@@S\mainfont\Wmodno
	\fi
	\eightrm\qquad\Wtitle\hfill\Whead
	\qquad\mainfont\the\pageno}
\fi

@*1 Page dimensions.
Here are the page dimensions (in inches).
@A
\def\pagewidtho{6.5}% The width of each page
\def\pageheighto{8.7}% The height of each page
\def\fullpageheighto{9}% Page height including headlines

\newdimen\pagewidth \pagewidth\pagewidtho in
\newdimen\pageheight \pageheight\pageheighto in
\newdimen\fullpageheight \fullpageheight\fullpageheighto in

\newdimen\pageshift \pageshift=0in% Shift righthand pages wrt lefthand ones

% Use after changing page size.
\def\setpage{\hsize\pagewidth 
	\vsize\pageheight
	\ifLaTeXisloaded
		\oddsidemargin=0pt
		\evensidemargin=0pt
		\topmargin=0pt
	\fi
	}
	
\ifLaTeXisloaded
\else
\def\magnify#1{\mag=#1
	\pagewidth\pagewidtho truein
	\pageheight\pageheighto truein
	\fullpageheight\fullpageheighto truein
	\setpage}

\fi

@*1 Plain \TeX\ output routine.
Here is the output routine for plain \TeX.  (For \LaTeX, we use its own
routine.) 
@A
\def\page{\box255 }

\newif\ifidenticalpageheads

\def\normaloutput#1#2#3{
	\ifodd\pageno\hoffset=\pageshift\fi
	\shipout\vbox
		{
		\vbox to\fullpageheight
			{
			\iftitle\global\titlefalse
			\else \hbox to\pagewidth
				{\vbox to10pt{}%
				\ifidenticalpageheads#2\else
				\ifodd\pageno
					#3% Pg nos alternate left \& right.
				\else#2\fi
				\fi
				}%	
			\fi
			\vfill#1% Parameter |#1| is the page itself.
			}
		}
	\global\advance\pageno by1}

\def\W@@name{{FWEB} OUTPUT}% This section name is reset by starred sections.

@ Here we provide a storage place for |\output|. If one includes a macro
package, such as \.{manmac}, that overrides the definition of |\output|
{\it after} \.{fwebmac.sty},  one can get back the \.{fwebmac.sty} definition by
saying 
		|\input manmac|
		|\output\Woutput|
@A
\newtoks\Woutput
\Woutput\output% Remember \FWEB's definition.


@*1 Time and date.
It's very useful to know exactly when one made the run.
@A
\newcount\minutes
\newcount\hours

\hours=\time
\divide\hours by 60
\multiply\hours by 60
\minutes=\time
\advance\minutes by -\hours
\divide\hours by 60

\def\Time{\the\hours:\ifnum\minutes<10 0\fi\the\minutes}

\def\Date{\ifcase\month\or
	January\or February\or March\or April\or May\or June\or
	July\or August\or September\or October\or November\or December\fi
	\space\number\day, \number\year}


@*1 Optional title for the code.
An optional title can be defined by the user in his limbo section. 
@A
\def\Wtitle{}

\ifLaTeXisloaded
	\ifnoLaTeXe
		\newcommand\Title[1]{\gdef\Wtitle{#1}%
			\title{\ttitlefont#1}}
	\else
		\newcommand\Title[2][\ttitlefont]{\gdef\Wtitle{{\large\tt#2}}%
			\title{#1#2}}
	\fi
\else
	\def\Title#1{\gdef\Wtitle{#1}} % Title on contents page.
\fi

@* TABLE OF CONTENTS. An entry is made in the table of contents for each
starred section.  

@*1 |\topofcontents| and |\botofcontents|.
One can customize things with |\topofcontents| and
|botofcontents|.  For more information, see the on-line documentation, menu
item ``Table of contents''.

@A
\ifLaTeXisloaded
	\def\topofcontents{}% We use \LaTeX's defaults.
\else
	\def\topofcontents{\centerline{\titlefont\Wtitle}
	  \vfill} % This is the default.
\fi

@ End the table of contents page:
@A
@#if 0
\def\botofcontents{\vfill}% This makes the bottom of the contents page empty.
@#endif

\ifLaTeXisloaded
	\def\botofcontents{}
\else
\def\botofcontents{\vfill
@#if 0
	\rightline{My Name}% You can personalize your output here, for example.
@#endif
	\rightline{\Date}
	\rightline{\Time}}
\fi

\ifLaTeXisloaded
	\contentspageno=1
	\pageno=\contentspageno
\else
	\contentspageno=0% Default page number for table of contents
\fi

@*1 Opening the contents file; the |\Wbegin| macro.
\modlabel{Wbegin}
Here we actually open up the contents file, which is the argument to
|\Wbegin|.  The |\Wbegin| macro is issued automatically just before the
stuff for the first module.  Also, \LaTeX\ does its own thing with the
|\end| command, so we redefine it.  To finish up the document, we write to
the \.{aux} file ``|\gdef\W@@depth{|$n$|}|'', where $n$~is the maximum
section depth that was achieved.

Whereas \LaTeX\ writes a |\newlabel| line to the table of contents in
response to a |\label| command, we write a |\Newlabel| command for every
section.  That macro is patterned after |\newlabel|, but has an extra
argument that is |\W@@botmodno|.  The |\Newlabel| information is read both by
the \FWEB\ processors (to correlate \LaTeX\ section numbers with integer
module numbers) and by |\FWEBend| to check whether labels have changed.
@A 
\newwrite\W@@cont % For the table of contents.

\ifLaTeXisloaded
	\def\Wfirst#1#2#3#4#5{#1}

	\def\W@@output{\setcounter{pagemodule}{0}%
		\xdef\W@@botmodno{\expandafter\Wfirst\botmark}}

	\def\W@@botmodno{0}

	\def\Newlabel#1#2#3{\@@ifundefined{r@@#1}{}%
		{\@@warning {Label `#1' multiply defined}}
		\global\@@namedef{r@@#1}{#2{#3}}
		\global\W@@lpha=#3
		\ifnum\W@@lpha=\W@@ref\global\advance\W@@pmcount by1
		\else
			\ifnum\W@@pmcount=1
			\edef\next{\gdef\csname W@@\the\W@@ref\endcsname{}}\next
			\fi
			\W@@ref=\W@@lpha
			\W@@pmcount=1
		\fi}
\fi

@ The arguments to |\Wbegin| are various style-file parameters, as follows:
$$\vbox{\halign{{\tt \##}\hfil& --- \vtop{\hsize0.75\hsize \noindent
\strut\tt #\strut}\hfil\cr 
1&LaTeX.class.options;LaTeX.package.options\cr
2&LaTeX.class;LaTeX.package\cr
3&indent.TeX\cr
4&indent.code\cr
5&contents.TeX\cr
6&\{format.reserved format.RESERVED\} \{format.short\_id\} \{format.id
format.ID\} \{format.outer\_macro format.OUTER\_MACRO\} \{format.WEB\_macro
format.WEB\_MACRO\} \{format.intrinsic\} \{format.keyword format.KEYWORD\}
\{format.typewriter\}\cr
7&encap.prefix\cr
8&\{doc.preamble;doc.postamble\}\cr
9&index.name\cr
}}$$

@A
\newcount\W@@ref
\W@@ref=-1

\newcount\W@@lpha

\newcount\W@@pmcount
\W@@pmcount=1

\outer\def\Wbegin[#1]#2#3#4#5#6#7#8#9{\edef\contentsfile{#5}%
	\def\readcontents{\input\contentsfile}%
	\W@@equate#6
	\W@@modequate{#7}%
	\edef\INDEX{#9}%
	\def\W@@splitprms##1##2[##3;##4]{\def##1{##3}\def##2{##4}}%
	\W@@splitprms\W@@preamble\W@@postamble[#8]%
	\ifLaTeXisloaded
		\def\FWEBend{
		  \global\advance\W@@ssmax by1
		  \immediate\write\@@auxout{\gdef\string\W@@depth{\the\W@@ssmax}}%
		  \W@@postamble
		  \W@@makeatend% Override |\makeatletter|
		  \end{document}}% \LaTeX\ redefines |\end|.
		\W@@splitprms\W@@prma\W@@prmb[#1]%
		\W@@splitprms\W@@prmc\W@@prmd[#2]%
		\ifnoLaTeXe
		   \edef\W@@temp{\noexpand\documentstyle[\W@@prma]{\W@@prmc}}%
			\W@@temp
		\else
			\documentclass[\W@@prma]{\W@@prmc}%
			\usepackage[\W@@prmb]{\W@@prmd}%
		\fi
% Set up defaults.
		\textwidth\pagewidth
		\textheight\pageheight
		\TeXindent#3
		\title{}%
		\author{}%
		\date{\today\\[3pt]\Time}%
		\pagestyle{myheadings}%
% Define the \FWEAVE\ output routine to be \LaTeX's.
		\newcounter{pagemodule}%
		\newcounter{W@@tempcounter}%
		\gdef\cl@@section{\@@elt{subsection}\cl@@subsection}
		\gdef\cl@@subsection{\@@elt{subsubsection}\cl@@subsubsection}
		\gdef\cl@@subsubsection{\@@elt{subsubsubsection}}
		\xdef\normaloutput##1##2##3{\the\output \noexpand\W@@output}%
		\W@@preamble
		\W@@raggedbottom
		\begin{document}
		\W@@setsecdepth
	\else % Plain \TeX.
		\immediate\openout\W@@cont=\contentsfile
		\def\FWEBend{\W@@postamble\end}
		\TeXindent#3
		\W@@preamble
	\fi
	\W@@setboxes{#4}% Set dimensions of backspace boxes.
% Here we print out a garbage page, so that the first |\topmark| won't be null.
	\output
		{\setbox0=\page% The first page is garbage
		\global\output{\normaloutput\page\lheader\rheader}%
		}%
	\setpage
	\vbox to \vsize{}
	}

@ We need to insert an extra test for changed labels that depends on the
|\Newlabel| information in the \.{.aux} file.  Now the \.{.aux} file is
read by the \.{\\end\{document\}} command; the reading is immediately
preceded by ``|\makeatletter|''.  To insert the new test, we augment that
command to include the appropriate redefinition of |\Newlabel|.  We must
also provide a cousin |\W@@testdef| to |\@@testdef| that recognizes the
extended name definitions (including |\W@@botmodno|) that we use for the
\FWEB\ section. 
@A
\def\W@@makeatend{\let\W@@makeatletter\makeatletter
	\def\makeatletter{\def\Newlabel{\W@@testdef r}%
	\W@@makeatletter}}

\def\W@@testdef#1#2#3#4{\def\reserved@@a{#3{#4}}%
\expandafter\ifx\csname#1@@#2\endcsname
		\reserved@@a
	\else
		\@@tempswatrue
	\fi
}

@
@A
\def\Wch{\note{The following sections were changed by the change file:}
	\let\*=\relax}

@* MACROS for the INDEX.
The index is written by default into \.{INDEX.tex}, but that
name can be overridden with the style-file parameter \.{index.tex}.

@*1 Beginning the index.
Here we begin the index.  In \LaTeX, if \.{multicol.sty} is not loaded, by
this time we should be in |\twocolumn| mode (from the |\beforeindex|
command).  If it is loaded, we begin multi-columns.  It's ended with the
|\Wfin| command.
@A
% The following two lines are for \TeX\ only.
\newbox\Sbox % Saved box preceding the index
\newbox\Lbox % Lefthand column in the index

\ifLaTeXisloaded
	\def\startindex{\ifx\multicols\undefined
				\medskip
			\else
				\begin{multicols}{2}%
			\fi
			}
\else
	\def\startindex{\par\vskip6pt plus 1fil}
\fi

@ The name of the |\Winx| macro is really the style-file parameter
 \.{index.preamble}. 
@A
\def\Winx{\startindex
\ifLaTeXisloaded
\else
	\write\W@@cont{ }% Ensure that the contents file isn't empty
	\closeout\W@@cont % The contents information has been fully gathered
	\output{\ifpagesaved\normaloutput{\box\Sbox}\lheader\rheader\fi
		\global\setbox\Sbox=\page \global\pagesavedtrue}
	\pagesavedfalse \eject % Eject the page-so-far and predecessors
	\setbox\Sbox\vbox{\unvbox\Sbox}% Take it out of its box
	\vsize=\pageheight \advance\vsize by -\ht\Sbox % The remaining height
	\hsize=.5\pagewidth \advance\hsize by -10pt
		% Column width for the index (20pt between cols)
	\parfillskip 0pt plus .6\hsize % Try to avoid almost empty lines
	\def\lr{L}% This tells whether the left or right column is next
	\output{\if L\lr\global\setbox\Lbox=\page \gdef\lr{R}
		\else\normaloutput{\vbox to\pageheight{\box\Sbox\vss
		\hbox to\pagewidth{\box\Lbox\hfil\page}}}\lheader\rheader
		\global\vsize\pageheight\gdef\lr{L}\global\pagesavedfalse\fi}
%	\message{Index:}
\fi
	\outer\def\:##1, {\par\hangindent2em\noindent##1:\kern1em}% Index entry
	\def\[##1]{$\underline{##1}$}% Underlined index item
	\def\(##1){$^{\rm ##1}$}% Language marker
	\let\Windexspace\medskip % Spacing between letter groups in index.
	\rm 
	\global\parskip 0pt plus .5pt
	\global\rightskip0pt plus 2.5em 
	\global\tolerance 10000
	\global\let\*=\W@@lapstar
	\global\hyphenpenalty 10000 
	\global\parindent0pt
	}

@*1 Ending the index.  
The name of the |\Wfin| macro is the style-file parameter \.{index.postamble}.
@A
\ifLaTeXisloaded
	\def\Wfin{\ifx\multicols\undefined\else\end{multicols}\fi}
\else
	\let\Wfin\relax
\fi

@* MACROS for the MODULE LIST.

@*1 Beginning the module list. This is the style file entry \.{modules.preamble}.
[Presently the |\mark| doesn't work right (at least in \LaTeX) for the first
page of the module list.  This is because |\onecolumn| and the mark are
somehow issued out of order. (But just putting the |\mark| before
|\onecolumn| doesn't work either.)]
@A
\def\Wmods{
\ifLaTeXisloaded
	\W@@outlsmax{1}%
	\onecolumn
	\parfillskip 0pt plus 1fil
	\def\W@@name{NAMES of the SECTIONS}
	\W@@mark{{0}{\W@@name}}{{0}{\W@@name}}
\else
	\par\vfill\eject 
	\ifpagesaved\null\vfill\eject\fi % Output a null index column
	\if L\lr\else\null\vfill\eject\fi % Finish the current page
	\parfillskip 0pt plus 1fil
	\def\rhead{NAMES OF THE SECTIONS}
	\output{\normaloutput\page\lheader\rheader}
	\setpage
\fi
	\def\note##1##2.{\quad{\footnotesize##1 ##2.}}
	\def\WU{\note{Used in}}% Cross-reference for uses of sections
	\def\:{\par\hangindent 2em}\let\*=*}


@* TERMINATION.

@*1 Miscellaneous run info.
@A
\def\Winfo#1#2#3#4{\bigskip
	\:{{\bf COMMAND LINE:}\ \ \Wtypewriter{#1}.}\smallskip
	\:{{\bf WEB FILE:}\ \ \Wtypewriter{#2}.}\smallskip
	\:{{\bf CHANGE FILE:}\ \ \Wtypewriter{#3}.}\smallskip
	\:{{\bf GLOBAL LANGUAGE:}\ \ \Wtypewriter{\rm #4}.}\medskip}

@*1 Finish the section names,  do the table of contents, and terminate.
@A
\ifLaTeXisloaded
	\def\W@@settoc#1{}%

	\def\Wtoc#1{\W@@settoc{#1}%
	\gdef\Newlabel##1##2##3{}%
	\setcounter{tocdepth}{\W@@depth}%
	\thispagestyle{empty}%
	\def\W@@name{TABLE of CONTENTS}%
	\W@@mark{{0}{\W@@name}}{{0}{\W@@name}}%
	\pagenumbering{roman}%
	\maketitle
	\topofcontents
	\tableofcontents
	\botofcontents
	\newpage
	\pagenumbering{arabic}%
	}

	\def\Wcon#1{\newpage
		\let\WIM\WIN % Restore the proper definition.
		\pageno=\contentspageno 
		\Wtoc{#1}%
		\FWEBend
		}
\else
\def\Wcon#1{\par\vfill\eject
	\rightskip 0pt \hyphenpenalty 50 \tolerance 200
	\setpage
	\output{\normaloutput\page\lheader\rheader}
	\titletrue % Prepare to output the table of contents
	\pageno=\contentspageno \def\rhead{TABLE OF CONTENTS}
	\topofcontents
	\catcode`\@@=11
	\hbox to\hsize{\hfil Section\hbox to3em{\hss Page}}
	\def\WZ##1##2##3##4{\hbox to\hsize{\kern##1em\ignorespaces##2
		\leaders\hbox to .5em{.\hfil}\hfil\ ##3\hbox to3em{\hss##4}}}
	\let\WIM\WIN % Restore the proper definition.
	\readcontents\relax % Read the contents info.
	\botofcontents 
	\FWEBend}
\fi


@ The |\begintt| and |\endtt| verbatim constructions, borrowed from \TeX.
@A
\newskip\ttglue

\ttglue=0.5em plus 0.25em minus 0.15em

\def\ttother{\catcode`\\=\other \catcode`\{=\other \catcode`\}=\other
	\catcode`\$=\other \catcode`\&=\other \catcode`\#=\other
	\catcode`\%=\other \catcode`\~=\other \catcode`\_=\other
	\catcode`\^=\other}

\def\ttverbatim{\begingroup \ttother \obeyspaces \obeylines \tt}

{\obeyspaces\gdef {\ }}

\def\begintt{$$\let\par=\endgraf
	\ttverbatim
	\parskip=0pt
	\rightskip=-\parindent
	\ttfinish}

\def\Begintt{\bgroup
	\let\par=\endgraf
	\ttverbatim
	\parskip=0pt
	\rightskip=-\parindent
	\ttFinish}

{\catcode`\|=0
	|catcode`|\=\other
	|obeylines%
	|gdef|ttfinish#1^^M#2\endtt{#1|vbox{#2}|endgroup$$}%
	|gdef|ttFinish#1\Endtt{#1|endgroup|egroup}}

\let\verticalbar|

\def\activebar{\catcode`\|=\active}

{\activebar
\gdef\normalbar{\activebar
	\let|\verticalbar}}

%\activebar

{\obeylines%
\gdef\ttbar{\activebar%
	{\obeylines\gdef|{\ttverbatim%
		\spaceskip=\ttglue%
		\let^^M=\ \let|=\endgroup}}}}

\let\WCX\Begintt

@
@A
\catcode`\@@=12

@* \INDEX.
