@z --- fwebmac.web ---

Copyright (C) 1987 Princeton University

Original authors:  D. Knuth, S. Levy

Upgraded by J.A. Krommes for FWEB version 1.31

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

\Title{FWEBMACL}

@Lx

@* INTRODUCTION.  These are the standard macros for \FWEB\ (v.~1.30)
listings (in addition to those of \.{PLAIN.TEX} and/or \LaTeX).

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 ---

% This file must be included into all .tex files produced by FWEAVE.  For
% the source for this file, please see fwebmacL.web.

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

@ 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

@ Various things need to know the current version number and date.
@A
\def\FWEBversion{1.32}
\def\FWEBdate{July 4, 1993}

@ \FWEB\ now offers full \LaTeX\ support.  Here's how to refer to it
(borrowed from \LaTeX's \.{\\p@@LaTeX} macro):
@A
\def\LaTeX{{\rm L\kern-0.36em\raise0.3ex\hbox{\Csc a}\kern-0.15em T%
	\kern-0.1667em \lower0.7ex\hbox{E}\kern-0.125em X}}

@ We need 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 |\documentstyle| is defined.  

@A
\newif\ifLaTeXisloaded

\ifx\documentstyle\undefined
\else
	\LaTeXisloadedtrue
\fi

@ \FWEB\ now supports \LaTeX's NFSS (new font selection scheme).  Macros
courtesy of Charles Karney, Princeton U.
@A
\ifx\selectfont\undefined\else
	\fontsize{10}{12pt}\rm % The standard font for bulk of document.
\fi

@ NFSS2 uses |\mathrm| and |\mathit|.  These won't be defined for Plain
\TeX\ and standard \LaTeX.
@A
\ifx\mathrm\undefined
	\let\mathrm\rm
\fi

\ifx\mathit\undefined
	\let\mathit\it
\fi

@ If \LaTeX\ is loaded, we equate |\pageno| to \LaTeX's counter so that the
|\label| macro works correctly.  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\Wdepth{|$n$|}|'', where $n$~is the maximum
section depth that was achieved.

@A 
\catcode`\@@=11

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

	\gdef\FWEBend{\advance\Wssmax by1
		\immediate\write\@@auxout{\gdef\string\Wdepth{\the\Wssmax}}%
	\end{document}}% \LaTeX\ redefines |\end|.
\else
	\let\FWEBend\end
\fi

\catcode`\@@=12

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

@ 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
\def\WEB{{\tt WEB}}
\def\FWEB{{\tt FWEB}}
\def\CWEB{{\tt CWEB}}
\def\TANGLE{{\tt TANGLE}} \let\Tangle\TANGLE
\def\WEAVE{{\tt WEAVE}}   \let\Weave\WEAVE
\def\FTANGLE{{\tt FTANGLE}}
\def\FWEAVE{{\tt FWEAVE}}

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

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

@ Now remember Plain \TeX\ stuff used for other purposes by \FWEB.

@A
\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\%

@ 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"|

@ Paragraph skip and indentation for \TeX\ text:

@A
\newdimen\pardimen
\dimen0=\normalbaselineskip
\parskip=\dimen0 plus 1pt

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

\parskip 0pt% No stretch between paragraphs

% Indentation for the \TeX\ part is handled in a separate variable
% |\TeXindent| from the variable |\notch| used for definition and code parts.
\newdimen\TeXindent
\TeXindent 1em% For paragraphs in the \TeX\ part.

@* FONTS. Several fonts have been declared in addition to the standard 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 font used for comments is called |\cmntfont|.  By default, this is
|\let| to |\tenrm|.

@A
\ifx\selectfont\undefined
	\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)
	\font\Csc=cmcsc10 % Caps/small caps.
	\font\tenbfit=cmbxti10 % \&{Intrinsic functions}

% 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

\else % NFSS
	\def\mainfont{\fontfamily{\rmdefault}\fontseries{m}\fontshape{n}%
		\normalsize}
	\let\cmntfont\mainfont

	\def\eightrm{\fontfamily{\rmdefault}\fontseries{m}\fontshape{n}%
		\footnotesize}
	\let\SC\eightrm

	\def\titlefont{\fontfamily{\sfdefault}\fontseries{\bfdefault}%
		\fontshape{n}\Large}
	\def\ttitlefont{\fontfamily{\ttdefault}\fontseries{m}\fontshape{n}%
		\Large}

	\def\tentex{\fontfamily{\ttdefault}\fontseries{m}\fontshape{n}%
		\normalsize}

	\def\Csc{\fontfamily{\rmdefault}\fontseries{m}\fontshape{\scdefault}%
		\normalsize}
	\def\tenbfit{\fontfamily{\rmdefault}\fontseries{\bfdefault}%
		\fontshape{\itdefault}\normalsize}

	\def\seventi{\fontfamily{\rmdefault}\fontseries{m}%
		\fontshape{\itdefault}\scriptsize}
	\def\sevenrm{\fontfamily{\rmdefault}\fontseries{m}\fontshape{n}%
		\scriptsize}
	\def\sevenbf{\fontfamily{\rmdefault}\fontseries{\bfdefault}%
		\fontshape{n}\scriptsize}

	\def\fiveti{\fontfamily{\rmdefault}\fontseries{m}%
		\fontshape{\itdefault}\tiny}
	\def\fiverm{\fontfamily{\rmdefault}\fontseries{m}\fontshape{n}\tiny}
	\def\fivebf{\fontfamily{\rmdefault}\fontseries{\bfdefault}%
		\fontshape{n}\tiny}

	\def\tensy{\fontfamily{cmsy}\fontseries{m}\fontshape{n}\normalsize}

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

% The next isn't really sufficient; this ought to be put into
% the definitions of |\tenpoint|, |\twelvepoint|, etc.
	\let\bfit\tenbfit 


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

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

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

% By default, macros are formatted the same way as ordinary identifiers.
% However, you 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

\def\Wreserved#1{\leavevmode\hbox{\def\\{\tt\BS}\bf#1\/}}% Boldface type
	% for reserved words such as \&{integer}.

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

% 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.
\def\Wequate#1#2#3#4#5#6#7#8{%
	\gdef#1{\Wreserved}% |\&| by default.
	\gdef#2{\Wshort}% |\|| by default.
% Don't reorder the following three statements! In case arguments 3--5 are
% identical, we want the ordinary identifier to win.
	\gdef#5{\WidM}% |\\| by default.
	\gdef#4{\WidD}% |\\| by default.
	\gdef#3{\Wid}% |\\| by default.
	\gdef#6{\Wintrinsic}% |\@@| by default.
	\gdef#7{\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\Wzero{0}

\def\WIN#1#2{\ifmmode\def\ZZ{}\else\def\ZZ{\null$\null}\fi
	\ZZ_{\def\next{#2}\ifx\next\Wzero{\bullet}\else[\WINo{#1}{#2}]\fi}\ZZ}


% Format the module-number subscript.
\gdef\WINo#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.

@A
\def\Wtypewriter#1{\relax\ifmmode\gdef\YY{\null$\null}\else\gdef\YY{}\fi
	\YY{\leavevmode\INITSTR#1}\YY}

\let\Wkeyword\Wtypewriter

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

@A
\def\INITSTR{%
	\tentex % Typewriter type for strings
	\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.
	}

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

@ The following funny business about asterisks is in case you want to be
clever and make~`\.*' an active character (for example, for complex
conjugation). 
@A
\chardef\asterisk=`\*
\def\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: '\.\\'.
\def\ttBS{{\tt\BS}}% Literal backslash: '\ttBS'.
\chardef\LB=`\{% Left brace in a string: '\.\LB'.
\def\LQ{{\tt\char'22}}% Left quote in a string: '\.\`'.
\chardef\RB=`\}% Right brace in a string: '\.\RB'.
\def\RQ{{\tt\char'23}}% Right quote in a string: '\.\''.
\def\SP{{\tt\char`\ }}% (Visible) space in a string: '\.\ '.
\chardef\TL=`\~% Tilde in a string: '\.\~'.
\chardef\UL=`\_% Underline character in a string: '\.\_'.


@
@A
\def\LA{\hbox{\LQ}}% Left quote outside a string

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

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
\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}

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 |\globalindent|:

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

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

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

@A
\newbox\bak  
\newbox\bakk 

\def\Wsetboxes#1{\notch=#1
	\setbox\bak=\hbox to -\notch{}% Backspace one notch.
	\setbox\bakk=\hbox to -2\notch{}% Backspace two notches.
	}

@ 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\ind by1\hangindent\ind\notch}% Indent one more notch

@ Here we cancel the above.  We don'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\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\bak}% Backspace one notch

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

@ The next command forces a line break.
@A
\def\6{\ifmmode\else\par
	\hangindent\ind\notch \noindent \kern\ind\notch \copy\bakk \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-\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\Hspace{\hbox{ }}

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

@A
\def\WPR#1{\copy\bakk \saveind%	|\global\advance\ind by 2|
	\1\Wreserved{@@#1}\Hspace}

\def\WPs{\global\ind=\lastind}

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

@* Various NUCLEII.

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

\def\lapstar{\rlap{*}}

\newif\ifWmodchanged

\def\Wcheckstar{\edef\Wtemp{\noexpand\Wisstar\modstar\noexpand\*\relax}\Wtemp}
\def\Wisstar#1\*#2\relax{\ifx#2\*\Wmodchangedtrue\else\Wmodchangedfalse\fi}

% If there's a current include file, it's printed at the start of each section.
\def\includefile{}
\def\WIF#1{\gdef\includefile{#1}}

\def\Wstartsection{\WQ
	\Wcheckstar
	{\let\*=\lapstar
	\ifLaTeXisloaded
		\leavevmode
	\else
		\noindent
		\bf\modstar.%
	\fi
	\ifx\includefile\empty
	\else
		\ifLaTeXisloaded\else\ \fi
		[{\tt\includefile}]%
	\fi
	\ifLaTeXisloaded\else
		\quad
	\fi
	}}

@* ALPHABET macros.  These are hard-coded into \FWEAVE.

@*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\skipbrace#1{\catcode`\{=1 }

\def\WC{\Wcmnt{\ast}{\finishcomment}}
\def\Wc{\Wcmnt{/}{\XX}}
\def\Wcmnt#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\skipbrace}

\def\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|.
@A
\def\WCD#1{\ifmmode\hbox\fi{\ignorespaces#1}}

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

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

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

@*1 Sections.  We support both page number or module-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 section numbers that are spit out by \FWEAVE.
The |\Wbegin| macro uses |\Wmodequate| 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 |\ifpages|.  

@A
\newif\ifpagerefs% Page references or module-number references.
\pagerefsfalse

\newif\ifnumberTeX% Do we start unnamed sections with section number?
\numberTeXfalse

\newif\ifnumberdefs%
\numberdefstrue

\newif\ifnumbercode%
\numbercodetrue

\def\Wmodequate#1{\def\Wtemp{#1}%
\ifx\Wtemp\empty\else
	\gdef#1{\Wmodtrans}%
\fi}

@ When LaTeX is selected with ``\.{-PL}'', we use LaTeX's sectioning
commands.  The |\Wdepth| 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\Wssmax% Maximum depth of the \.{@@*}$n$ commands.

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

\catcode`\@@=11

\def\WLvmode#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\Wraggedbottom{\def\@@textbottom{\vskip\z@@ \vfil}%
		\let\@@texttop\relax
% Very strongly encourage to break at beginning of sections.
		\@@secpenalty=-500
		\def\addpenalty##1{%
			\ifvmode
				\WLvmode{##1}%
			\else
				\@@noitemerr
			\fi}
		}

% After the \.{aux} file is read, we must set things up based on the depth
% paramter |\Wdepth|. 
	\gdef\Wsetsecdepth{%
		\@@ifundefined{Wdepth}{\gdef\Wdepth{1}}{}
		\setcounter{secnumdepth}{\Wdepth}
% 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.
		\ifcase\Wdepth % Level 0; should never happen.
		\or % Level 1
			\gdef\subsection{\refstepcounter{subsection}%
\@@startsection{subsection}{2}{\z@@}{-3.25ex plus-1ex minus-.2ex}{-\parindent}
{\reset@@font \normalsize \bf}}
			\global\let\Wunnamedsect\subsection
		\or % Level 2
			\gdef\subsubsection{\refstepcounter{subsubsection}%
\@@startsection{subsubsection}{3}{\z@@}{-3.25ex plus-1ex minus-.2ex}
{-\parindent}{\reset@@font \normalsize \bf}}
			\global\let\Wunnamedsect\subsubsection
		\else
			\global\let\Wunnamedsect\paragraph
		\fi
		}

% 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|.
	\gdef\Wmodtrans#1{\@@ifundefined{r@@#1}
		{\Wsplit{?}{?}{0}{0}}
		{\expandafter\expandafter\expandafter
			\Wsplit\csname r@@#1\endcsname{#1}}%
		}

% Convert the \.{aux} label info into page or section number.
	\gdef\Wsplit#1#2#3#4{%
		\ifpagerefs
			#2%
			\@@ifundefined{W@@#3}%
				{\setcounter{Wtempcounter}{#4}%
				\addtocounter{Wtempcounter}{-#3}%
				\hbox{\alph{Wtempcounter}}}
				{}%
		\else
			#1\fi}

	\let\modno\empty
	\let\Wname\empty

% Beginning of unnamed section.
	\def\WM#1.{\MN#1.%
		\Wmark{{\oldmodno}{\oldWname}}{{\modno}{\Wname}}%
		\ifon
			\advance\Wss by10
			\Wstart{\ifnumberTeX\Wmodtrans{\modno}\fi} % ????
			\advance\Wss by-10
			\ignorespaces}
\else
% For \TeX, we just get module numbers.
	\def\Wmodtrans#1{#1}

	\outer\def\WM#1.{\MN#1.\Wmark\ifon\Wskip\Wstartsection\ignorespaces}
\fi

\catcode`\@@=12

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

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.  (See how this is
done in |fwebman.tex|.)

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

@A
\newcount\Wss % Counter for the dots.

\newif\ifdotsafter % Do subsection dots come after or before the section name?
\dotsafterfalse

\ifdotsafter % ``@@* NAME...''
	\def\Wbefore:#1.{\Wdefname#1.\Wdot}%
	\def\Wafter{\WNss}%
\else % ``@@*.. NAME.'' or ``@@*2 NAME.''
	\def\Wbefore: #1{\def\next{\Wafter#1}% Case for neither dot nor number.
		\ifx#1.\def\next{\Wdot.}% Count arbitrary dots.
		\else\ifx#11\Wsectionnum1%
		\else\ifx#12\Wsectionnum2%
		\else\ifx#13\Wsectionnum3%
		\else\ifx#14\Wsectionnum4% Highest numerical level allowed.
		\fi\fi\fi\fi\fi
		\next}%
	\def\Wafter#1.{\Wdefname#1.\WNss}% Executed after figuring out level.
\fi

\def\Wsectionnum#1{\Wss#1\let\next\Wafter}% Assign numerical section number.
\def\Wdefname#1.{\def\Wname{#1}}% Remember name of section.

\outer\def\WN#1.{\MN#1.\Wss=0\Wbefore:}% Begin a starred section.

@ Here we count the periods before or after the section name.
@A
\def\Wdot{\futurelet\next\WNs}
\def\WNs{\ifx\next.\advance\Wss by 1\let\next\Wnext\else\let\next\Wafter\fi
	\next}
\def\Wnext#1{\Wdot}

@ 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~|\cont|.  We want 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~|\Wname| (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|.

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

% Running headline.
\def\rhead{\ifcase\Wss
		\uppercase{\ignorespaces\Wname}%
	\else
		\ignorespaces\Wname%
	\fi}% Define running headline.

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

\catcode`\@@=11

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

\ifLaTeXisloaded
	\gdef\Windexname{INDEX}

	\gdef\WNss{%
		\Wmark{{\oldmodno}{\oldWname}}{{\modno}{\Wname}}%
% Can't put this in |\MN| since |\rhead| must be defined first. 
		\message{*\modno}% Progress report to the terminal.
		\ifon
			\ifnum\Wss>\Wssmax
				\Wssmax=\Wss% Keep track of maximum depth.
			\fi
			\Wstart{\Wname}%
			\ignorespaces
		}

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

	\let\Wlabel\WLlabel

% If the section name is precisely ``\.{INDEX}'', we switch into
% |\twocolumn| mode, thereby starting the index on a new page.  This could
% be improved if we used \.{multicol.sty}, but we don't assume that people
% have that. 
	\gdef\Wstart#1{%
		\edef\Wupname{\Wname}
		\ifx\Wupname\Windexname\twocolumn\fi
% Select the appropriate \LaTeX\ section command.
		\ifcase\Wss
			\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.
		\Wmark{{\modno}{\Wname}}{{\modno}{\Wname}}%
		\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.
		\Wstartsection
		}
\else
\def\WNss{%
	\Wmark % Can't put this in |\MN| since |\rhead| must be defined first. 
	\Wsectionbreak % Typeset the break between sections.
	\message{*\modno}% Progress report to the terminal.
	\ifon
		\ifcase\Wss\else\Wskip\fi
		\Wstartsection{\bf\ignorespaces\Wname.\quad}%
		{\def\WIN{\WIM}%
		\edef\next{\write\cont{\WZ{\the\Wss}{\Wname}%
		{\modno}{\noexpand\the\pageno}}}\next}%
			% To contents file |CONTENTS.tex|.
		\ignorespaces}
\fi

\catcode`\@@=12

@ The marks that we emit just before |\Wsectionbreak| are of the form
``{\it modno}|\else|{\it section name}''.  We use both of the parts in the
page headers.  In handling the section name, we must take care to avoid
expanding the macro~|\WIN| prematurely.  This is done just as in~|\WNss| above.

@A
\def\WmarkN{\def\Wmark{{\def\WIN{\WIM}%
		\mark{\modno\noexpand\else\rhead}}}}

\ifx\selectfont\undefined
	\WmarkN
\else
	\def\Wmark{{\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
\catcode`\@@=11

\def\MN#1.{\par
	\parskip=\pardimen % Reset to \TeX\ spacing
	\parindent=\TeXindent
	{
	\ifLaTeXisloaded
		\global\let\oldmodno\modno
		\global\let\oldWname\Wname
		\xdef\@@currentlabel{\modno}%
		\global\let\Woutname\empty
		\addtocounter{pagemodule}{1}%
	\fi
	\xdef\modstar{#1}%
	\let\*=\empty
	\xdef\modno{#1}%
	}
	\ifx\modno\modstar 
		\onmaybe 
	\else
		\ontrue 
	\fi
	}

\catcode`\@@=12  

@*1 Nuweb mode.

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

{\catcode`\@@=11
\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`/@@=11
/gdef/WBM{%/8/kern/notch
/begingroup
/parindent/globalindent/notch /advance/parindent by-1/notch
/catcode``=13 /@@noligs /tt 
/let/do/@@makeother /dospecials 
/@@vobeyspaces/frenchspacing/obeylines 
/W@@M}
/gdef/W@@M#1#2\WEM{#2/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.

\def\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~|\ind|.  This somewhat peculiar construction
is for historical reasons.
@A
\def\WPr{\global\ind=\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 you turn these on, the
	% discretionary breaks in strings won't work!
	\global\ind=\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 }

@*1 Miscellaneous operators.
@A
\def\WA{\note{See also}}% Cross-reference for multiply defined section names.

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

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

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

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

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

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

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

\def\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$'.

\def\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$'.

@ 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} 

@* VARIOUS OPERATORS.

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

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

@  For C's construciton `|@c x ? 1 : 0|'.
@A
\def\?{\mathrel?}

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

\def\CC{\mathord{::}}% '$x\CC y$'.
\def\CF{{}\mathbin{::}{}}% '$x\CF y$'.


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

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

\let\Wequals\=

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

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

@
@A
\mathchardef\TLD="0218% '$\TLD$'.

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

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

@ 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}}
\def\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

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

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

@ Macro stuff:
@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'.

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

@ Compound operators.  The following are for~C.
@A
\def\Wcp{\mathrel{+{=}}} \let\PE\Wcp % `$x\PE y$'.
\def\Wcm{\mathrel{-{=}}} \let\ME\Wcm % `$x\ME y$'.
\def\Wcs{\mathrel{\ast{=}}} \let\TE\Wcs % `$x\Wcs y$'.
\def\Wcv{\mathrel{/{=}}} \let\FE\Wcv % `$x\FE y$'.
\def\Wcd{\mathrel{\%{=}}} \let\CE\Wcd % `$x\Wcd y$'.
\def\Wcx{\mathrel{\^\!{=}}}% `$x\Wcx y$'.
\def\Wca{\mathrel{\amp{=}}}% `$x\Wca y$'.
\def\Wco{\mathrel{\OR{=}}}% `$x\Wco y$'.
\def\Wcg{\mathrel{\GG\!{=}}}% `$x\Wcg y$'.
\def\Wcl{\mathrel{\LL\!{=}}}% `$x\Wcl y$'.

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

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

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

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

@ 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}

@ 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{}

@ Block/loop numbers in \Fortran.  \It{Note:  You can't replace the
|\bgroup| and |\egroup| by braces because of peculiarities of~|\Wc|.  Also,
if you put an explicit comment on a line that will be labelled by
|\Wblock|, with the following definition you'll 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}'

@* 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\Woq}% Be careful about |\EE|.
	\fi
	\next}%
}

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

\let\Lbrace{

\def\Woq{\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 translated overloaded identifiers into their \TeX\
equivalents.
@a
\def\WTeX#1{\ [{\ifmmode\def\XX{}\else\def\XX{\null$\null}\fi
\XX#1\XX}]\ }

@ The following is for special handling of array indices.
@a
\newtoks\WARRAYarga
\newtoks\WARRAYargb

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

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

\def\WARRAYn#1#2{\WARRAYargb{#2}%
	\edef\Wnext{\noexpand\WXA{\the\WARRAYarga,\the\WARRAYargb}}%Concatenate
	\Wnext}

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

@ Handle the \.{@@o}~command.
@a
\def\Wouto#1#2{\Wreserved{@@#1}\Hspace\Wtypewriter{#2}}
\def\Wout#1{\Wouto{o}{#1}}
\def\WOut#1{\Wouto{O}{#1}}

@* TITLES.  Now we deal with the overall page format.

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 your \.{WEB} file. It's
customary to make this the first change in your 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

@ Top line on left-hand pages:
@A
\catcode`\@@=11

\def\WsetLmarks{
	\def\Wsecrange##1##2{%
		\def\Wtempa{##1}\def\Wtempb{##2}%
		\ifx\Wtempa\Wtempb
			\Wmodtrans{##1} [\###1]%
		\else
			\Wmodtrans{##1}--\Wmodtrans{##2} [\###1--##2]%
		\fi}

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

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

	\gdef\leftmark{\edef\Wtempb{\expandafter\iftrue\botmark\fi}%
\edef\Wtempa{\expandafter\iffalse\topmark\fi}%
\expandafter\expandafter\expandafter\@@leftmark\expandafter\Wtempa\Wtempb{}{}}

	\gdef\rightmark{\edef\Wtempb{\expandafter\iftrue\botmark\fi}%
\edef\Wtempa{\expandafter\iffalse\topmark\fi}%
\expandafter\expandafter\expandafter\@@rightmark\expandafter\Wtempa\Wtempb{}{}}

	\gdef\WmarkN{\gdef\Wmark####1####2{{\def\WIN{\WIM}%
		\mark{####1\noexpand\else####2}}}}

	\ifx\selectfont\undefined
		\WmarkN
	\else
		\gdef\Wmark##1##2{{\def\WIN{\WIM}%
			\mark{##1\noexpand\else##2}}}
	\fi
}

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

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

\catcode`\@@=12  

@ 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

@ Here is the output routine for plain \TeX.
@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\Wname{{\tt FWEB} OUTPUT}% This section name is reset by starred sections.

@ It's very useful to know exactly when you 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}


@ An OPTIONAL TITLE can be defined by the user in his limbo section. 
@A
\def\Wtitle{}

\ifLaTeXisloaded
	\gdef\Title#1{\gdef\Wtitle{--- #1 ---}\title{\titlefont --- #1 ---}}
\else
	\def\Title#1{\def\Wtitle{--- #1\ ---}} % Title on contents page.
\fi

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

@* TABLE OF CONTENTS. An entry is made in the table of contents for each
starred section.  One can customize things with |\topofcontents| and
|botofcontents|. 
@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

@ 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.
@A 
\newwrite\cont % For the table of contents.

\newtoks\Woutputtoks

\catcode`\@@=11

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

	\Woutputtoks={\setcounter{pagemodule}{0}%
		\xdef\botmodno{\expandafter\Wfirst\botmark}}

	\def\botmodno{0}

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

\catcode`\@@=12

\newcount\Waref
\Waref=-1

\newcount\Walpha

\newcount\Wpmcount
\Wpmcount=1

\def\Wbegin[#1]#2#3#4#5#6#7{\edef\contentsfile{#5}%
	\def\readcontents{\input\contentsfile}%
	\Wequate#6
	\Wmodequate{#7}%
	\ifLaTeXisloaded
		\documentstyle[#1]{#2}%
% Set up defaults.
		\textwidth\pagewidth
		\textheight\pageheight
		\TeXindent#3
		\title{}%
		\author{}%
		\date{\today\\[3pt]\Time}%
		\pagestyle{myheadings}%
		\Wraggedbottom
% Define the \FWEAVE\ output routine to be \LaTeX's.
		\newcounter{pagemodule}%
		\newcounter{Wtempcounter}%
		\xdef\normaloutput##1##2##3{\the\output \the\Woutputtoks}%
		\begin{document}
		\Wsetsecdepth
	\else
		\TeXindent#3
	\fi
	\Wsetboxes{#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
		\ifLaTeXisloaded\else
			\immediate\openout\cont=\contentsfile
		\fi
		\global\output{\normaloutput\page\lheader\rheader}%
		}%
	\setpage
	\vbox to \vsize{}
	}

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

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

Here we begin the index:
@A
\newbox\Sbox % Saved box preceding the index
\newbox\Lbox % Lefthand column in the index

\ifLaTeXisloaded
	\def\startindex{\bigskip}
\else
	\def\startindex{\par\vskip6pt plus 1fil}
\fi

% The |\Winx| macro is really the style file entry \.{index.preamble}.
\def\Winx{\startindex
\ifLaTeXisloaded
\else
	\write\cont{}% Ensure that the contents file isn't empty
	\closeout\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
	\parskip 0pt plus .5pt
	\outer\def\:##1, {\par\hangindent2em\noindent##1:\kern1em}% Index entry
	\def\[##1]{$\underline{##1}$}% Underlined index item
	\def\(##1){$^{\mathrm ##1}$}% Language marker
	\let\Windexspace\medskip % Spacing between letter groups in index.
	\rm \rightskip0pt plus 2.5em \tolerance 10000 \let\*=\lapstar
	\hyphenpenalty 10000 \parindent0pt}

@ End the index.  This macro is the style-file entry \.{index.postamble}.
@A
\let\Wfin\relax

@ Begin the module list. This is the style file entry \.{modules.preamble}.
@A
\def\Wmods{
\ifLaTeXisloaded
	\onecolumn
	\parfillskip 0pt plus 1fil
	\def\Wname{NAMES of the SECTIONS}
	\Wmark{{0}{\Wname}}{{0}{\Wname}}
\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\*=*}


@* MISCELLANEOUS.

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}.}\medskip
	\:{{\bf GLOBAL LANGUAGE:}\ \ \Wtypewriter{\rm #4}.}\medskip}

@ Finish the section names,  do the table of contents, and terminate:
@A
\ifLaTeXisloaded
	\def\Wtoc{
	\gdef\Newlabel##1##2##3{}
	\setcounter{tocdepth}{\Wdepth}
	\thispagestyle{empty}
	\def\Wname{TABLE of CONTENTS}
	\Wmark{{0}{\Wname}}{{0}{\Wname}}%
	\pagenumbering{roman}
	\topofcontents
	\maketitle
	\tableofcontents
	\botofcontents
	\newpage
	\pagenumbering{arabic}
	}

	\def\Wcon{\newpage
		\let\WIM\WIN % Restore the proper definition.
		\pageno=\contentspageno 
		\Wtoc
		\FWEBend
		}
\else
\def\Wcon{\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


@ 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.

@ 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\marginal#1{\strut\vadjust{\kern-\strutdepth\specialmargin{#1}}}

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

\def\LANGUAGE#1{\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

@ 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
%	\catcode`\@@=0
	\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

@* INDEX.
