1
% standard macros for CWEB listings (in addition to plain.tex)
2
% Version 3.67 --- July 2006
3
\ifx\renewenvironment\undefined\else\endinput\fi % LaTeX will use other macros
4
\xdef\fmtversion{\fmtversion+CWEB3.67}
5
\chardef\cwebversion=3 \chardef\cwebrevision=67
8
% Uncomment the following line if you want PDF goodies to be the default
9
%\ifx\pdf-\else\pdftrue\fi
10
\def\pdflinkcolor{0 0 1} % the RGB values for hyperlink color
12
\ifx\pdfoutput\undefined \pdftexfalse \else\ifnum\pdfoutput=0 \pdftexfalse
13
\else \pdftextrue \pdfoutput=1 \input pdfcolor \let\setcolor\pdfsetcolor \fi\fi
14
\newif\ifacro \ifpdf\acrotrue\fi \ifpdftex\acrotrue\fi
16
\let\:=\. % preserve a way to get the dot accent
17
% (all other accents will still work as usual)
19
\parskip 0pt % no stretch between paragraphs
20
\parindent 1em % for paragraphs and for the first line of C text
23
\let\mc=\ninerm % medium caps
24
\def\CEE/{{\mc C\spacefactor1000}}
25
\def\UNIX/{{\mc U\kern-.05emNIX\spacefactor1000}}
27
\def\CPLUSPLUS/{{\mc C\PP\spacefactor1000}}
28
\def\Cee{\CEE/} % for backward compatibility
30
% with this definition of \9 you can say @:sort key}{TeX code@>
31
% to alphabetize an index entry by the sort key but format with the TeX code
33
\let\sc=\eightrm % for smallish caps (NOT a caps-and-small-caps font)
36
%\font\tenss=cmss10 \let\cmntfont\tenss % alternative comment font
37
\font\titlefont=cmr7 scaled\magstep4 % title on the contents page
38
\font\ttitlefont=cmtt10 scaled\magstep2 % typewriter type in title
39
\font\tentex=cmtex10 % TeX extended character set (used in strings)
40
\fontdimen7\tentex=0pt % no double space after sentences
42
\def\\#1{\leavevmode\hbox{\it#1\/\kern.05em}} % italic type for identifiers
43
\def\|#1{\leavevmode\hbox{$#1$}} % one-letter identifiers look better this way
44
\def\{\leavevmode\hbox{\bf
45
\def\_{\kern.04em\vbox{\hrule width.3em height .6pt}\kern.08em}%
46
#1\/\kern.05em}} % boldface type for reserved words
47
\def\.#1{\leavevmode\hbox{\tentex % typewriter type for strings
48
\let\\=\BS % backslash in a string
49
\let\{=\LB % left brace in a string
50
\let\}=\RB % right brace in a string
51
\let\~=\TL % tilde in a string
52
\let\ =\SP % space in a string
53
\let\_=\UL % underline in a string
54
\let\&=\AM % ampersand in a string
55
\let\^=\CF % circumflex in a string
57
\def\){{\tentex\kern-.05em}\discretionary{\hbox{\tentex\BS}}{}{}}
58
\def\AT{@} % at sign for control text (not needed in versions >= 2.9)
59
\def\ATL{\par\noindent\bgroup\catcode`\_=12 \postATL} % print @l in limbo
60
\def\postATL#1 #2 {\bf letter \\{\uppercase{\char"#1}}
61
tangles as \tentex "#2"\egroup\par}
63
\def\noatl{\let\ATL=\noATL} % suppress output from @l
64
\def\ATH{{\acrofalse\X\kern-.5em:Preprocessor definitions\X}}
65
\let\PB=\relax % hook for program brackets |...| in TeX part or section name
67
\chardef\AM=`\& % ampersand character in a string
68
\chardef\BS=`\\ % backslash in a string
69
\chardef\LB=`\{ % left brace in a string
70
\chardef\RB=`\} % right brace in a string
71
\def\SP{{\tt\char`\ }} % (visible) space in a string
72
\chardef\TL=`\~ % tilde in a string
73
\chardef\UL=`\_ % underline character in a string
74
\chardef\CF=`\^ % circumflex character in a string
76
\newbox\PPbox % symbol for ++
77
\setbox\PPbox=\hbox{\kern.5pt\raise1pt\hbox{\sevenrm+\kern-1pt+}\kern.5pt}
79
\newbox\MMbox \setbox\MMbox=\hbox{\kern.5pt\raise1pt\hbox{\sevensy\char0
80
\kern-1pt\char0}\kern.5pt}
82
\newbox\MGbox % symbol for ->
83
\setbox\MGbox=\hbox{\kern-2pt\lower3pt\hbox{\teni\char'176}\kern1pt}
85
\def\MRL#1{\mathrel{\let\K==#1}}
86
%\def\MRL#1{\KK#1}\def\KK#1#2{\buildrel\;#1\over{#2}}
90
\mathchardef\AND="2026 % bitwise and; also \& (unary operator)
91
\let\OR=\mid % bitwise or
92
\let\XOR=\oplus % bitwise exclusive or
93
\def\CM{{\sim}} % bitwise complement
94
\newbox\MODbox \setbox\MODbox=\hbox{\eightrm\%}
95
\def\MOD{\mathbin{\copy\MODbox}}
96
\def\DC{\kern.1em{::}\kern.1em} % symbol for ::
97
\def\PA{\mathbin{.*}} % symbol for .*
98
\def\MGA{\mathbin{\MG*}} % symbol for ->*
101
\newbox\bak \setbox\bak=\hbox to -1em{} % backspace one em
102
\newbox\bakk\setbox\bakk=\hbox to -2em{} % backspace two ems
104
\newcount\ind % current indentation in ems
105
\def\1{\global\advance\ind by1\hangindent\ind em} % indent one more notch
106
\def\2{\global\advance\ind by-1} % indent one less notch
107
\def\3#1{\hfil\penalty#10\hfilneg} % optional break within a statement
108
\def\4{\copy\bak} % backspace one notch
109
\def\5{\hfil\penalty-1\hfilneg\kern2.5em\copy\bakk\ignorespaces}% optional break
110
\def\6{\ifmmode\else\par % forced break
111
\hangindent\ind em\noindent\kern\ind em\copy\bakk\ignorespaces\fi}
112
\def\7{\Y\6} % forced break and a little extra space
113
\def\8{\hskip-\ind em\hskip 2em} % no indentation
115
\newcount\gdepth % depth of current major group, plus one
116
\newcount\secpagedepth
117
\secpagedepth=3 % page breaks will occur for depths -1, 0, and 1
118
\newtoks\gtitle % title of current major group
119
\newskip\intersecskip \intersecskip=12pt minus 3pt % space between sections
120
\let\yskip=\smallskip
122
\def\note#1#2.{\Y\noindent{\hangindent2em%
123
\baselineskip10pt\eightrm#1~\ifacro{\pdfnote#2.}\else#2\fi.\par}}
125
\newtoks\toksA \newtoks\toksB \newtoks\toksC \newtoks\toksD
126
\newtoks\toksE \newtoks\toksF \newtoks\usersanitizer
127
\newcount\countA \countA=0 \newcount\countB \countB=0
128
\newcount\countC \countC=0
129
\newif\iftokprocessed \newif\ifTnum \newif\ifinstr
130
{\def\\{\global\let\spacechar= }\\ }
132
\ifacro % The following are pdf macros
133
\def\thewidth{\the\wd0 \space}
134
\def\theheight{\the\ht\strutbox\space}
135
\def\thedepth{\the\dp\strutbox\space}
137
\ifx\pdfannotlink\undefined\let\pdfannotlink\pdfstartlink\fi% for pdfTeX 0.14
138
\def\pdflink#1#2{\hbox{\pdfannotlink height\ht\strutbox depth\dp\strutbox
139
attr{/Border [0 0 0]} goto num #1 \BlueGreen #1\Black\pdfendlink}}
140
\else\def\pdflink#1#2{\setbox0=\hbox{\special{pdf: bc [ \pdflinkcolor ]}{#1}%
141
\special{pdf: ec}}\special{pdf: ann width \thewidth height \theheight
142
depth \thedepth << /Type /Annot /Subtype /Link
143
/Border [0 0 0] /A << /S /GoTo /D (#2) >> >>}\box0\relax}\fi
144
\def\pdfnote#1.{\setbox0=\hbox{\toksA={#1.}\toksB={}\maketoks}\the\toksA}
145
\def\firstsecno#1.{\setbox0=\hbox{\toksA={#1.}\toksB={}%
146
\def\makenote{\addtokens\toksB{\the\toksC}\def\makenote{\toksD={}
147
\toksC={}\let\space\empty}\makenote}\maketoks}}
148
\def\addtokens#1#2{\edef\addtoks{\noexpand#1={\the#1#2}}\addtoks}
149
\def\poptoks#1#2|ENDTOKS|{\let\first=#1\toksD={#1}%
150
\ifcat\noexpand\first0\countB=`#1\else\countB=0\fi\toksA={#2}}
151
\def\maketoks{\expandafter\poptoks\the\toksA|ENDTOKS|%
152
\ifnum\countB>`9 \countB=0 \fi
154
\ifnum0=\countC\else\makenote\fi
155
\ifx\first.\let\next=\maketoksdone\else
157
\addtokens\toksB{\the\toksD}
158
\ifx\first,\addtokens\toksB{\space}\fi
160
\else \addtokens\toksC{\the\toksD}\global\countC=1\let\next=\maketoks
164
\def\makenote{\addtokens\toksB
165
{\noexpand\pdflink{\the\toksC}{\romannumeral\the\toksC}}\toksC={}\global\countC=0}
166
\def\maketoksdone{\edef\st{\global\noexpand\toksA={\the\toksB}}\st}
167
\def\pdfURL#1#2{\ifpdftex\pdfannotlink height\ht\strutbox depth\dp\strutbox
168
attr {/Border [0 0 0]} user { /Type /Action /Subtype /Link /A
169
<< /S /URI /URI (#2) >>}\BlueGreen #1\Black \pdfendlink
170
\else \ifpdf{\setbox0=\hbox{\special{pdf: bc [ \pdflinkcolor ]}{#1}%
171
\special{pdf: ec}}\special{pdf: ann width \thewidth\space height \theheight
172
\space depth \thedepth\space << /Border [0 0 0]
173
/Type /Action /Subtype /Link /A << /S /URI /URI (#2) >> >>}\box0\relax}%
174
\else #1 ({\tt#2})\fi\fi}
175
{\catcode`\~=12 \gdef\TILDE/{~}} % ~ in a URL
176
{\catcode`\_=12 \gdef\UNDER/{_}} % _ in a URL
177
\def\sanitizecommand#1#2{\addtokens\usersanitizer
178
{\noexpand\dosanitizecommand\noexpand#1{#2}}}
179
\def\dosanitizecommand#1#2{\ifx\nxt#1\addF{#2}\fi}
181
\catcode`\[=1 \catcode`\]=2 \catcode`\{=12 \catcode`\}=12
182
\def\lbchar[{] \def\rbchar[}]
183
\catcode`\[=12 \catcode`\]=12 \catcode`\{=1 \catcode`\}=2
184
\catcode`\~=12 \def\tildechar{~} \catcode`\~=13
185
\catcode`\|=0 |catcode`|\=12 |def|bschar{\} |catcode`|\=0 \catcode`\|=12
186
\def\makeoutlinetoks{\Tnumfalse\afterassignment\makeolproctok\let\nxt= }
187
\def\makeolnexttok{\afterassignment\makeolproctok\let\nxt= }
188
\def\makeolgobbletok{\afterassignment\makeolnexttok\let\nxt= }
189
\def\addF#1{\addtokens\toksF{#1}\tokprocessedtrue}
190
% now comes a routine to "sanitize" section names, for pdf outlines
191
\def\makeolproctok{\tokprocessedfalse
192
\let\next\makeolnexttok % default
193
\ifx\nxt\outlinedone\let\next\outlinedone
194
\else\ifx{\nxt \else\ifx}\nxt \Tnumfalse \instrfalse % skip braces
195
\else\ifx$\nxt % or a $ sign
196
\else\ifx^\nxt \addF^\else\ifx_\nxt \addF_% sanitize ^ and _
197
\else\ifx\nxt\spacechar \addF\space
198
\else\if\noexpand\nxt\relax % we have a control sequence; is it one we know?
200
\else\ifx\nxt\onespace\addF\space
201
\else\the\usersanitizer
202
\iftokprocessed\else\makeolproctokctli
203
\iftokprocessed\else\makeolproctokctlii
204
\iftokprocessed\else\makeolproctokctliii % if not recognised, skip it
206
\else % we don't have a control sequence, it's an ordinary char
207
\ifx/\nxt \addF{\string\/}% quote chars special to PDF with backslash
208
\else\ifx(\nxt \addF{\string\(}\else\ifx)\nxt \addF{\string\)}%
209
\else\ifx[\nxt \addF{\string\[}\else\ifx]\nxt \addF{\string\]}%
210
\else\expandafter\makeolproctokchar\meaning\nxt
211
\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
214
\def\makeolproctokchar#1 #2 #3{\addF{#3}}
215
\def\makeolproctokctli{%
216
\ifx\nxt\CEE\addF{C}\let\next\makeolgobbletok % \CEE/
217
\else\ifx\nxt\UNIX\addF{UNIX}\let\next\makeolgobbletok % \UNIX/
218
\else\ifx\nxt\TEX\addF{TeX}\let\next\makeolgobbletok % \TEX/
219
\else\ifx\nxt\TeX\addF{TeX}\else\ifx\nxt\LaTeX\addF{LaTeX}%
220
\else\ifx\nxt\CPLUSPLUS\addF{C++}\let\next\makeolgobbletok % \CPLUSPLUS/
221
\else\ifx\nxt\Cee\addF{C}%
222
\else\ifx\nxt\PB \let\next\makeolgobbletok \tokprocessedtrue % \PB{...}
223
\else\ifx\nxt\.\tokprocessedtrue\instrtrue % \.{...}
225
\else\ifx\nxt\\\ifinstr\addF{\bschar\bschar}\else\tokprocessedtrue\fi
226
\else\ifx\nxt\&\ifinstr\addF&\else\tokprocessedtrue\fi
227
\else\ifx\nxt\~\ifTnum\addF{0}\else\addF\tildechar\fi % 077->\T{\~77}
228
\else\ifx\nxt\_\ifTnum\addF{E}\else\addF_\fi % 0.1E5->\T{0.1\_5}
229
\else\ifx\nxt\^\ifTnum\addF{0x}\else\addF^\fi % 0x77 -> \T{\^77}
230
\else\ifx\nxt\$\ifTnum\tokprocessedtrue\else\addF$\fi % \T{77\$L}
231
\else\ifx\nxt\{\addF\lbchar \else\ifx\nxt\}\addF\rbchar
232
\else\ifx\nxt\ \addF\space \else\ifx\nxt\#\addF{\string\#}%
233
\else\ifx\nxt\PP\addF{++}\else\ifx\nxt\MM\addF{--}%
234
\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
236
\def\makeolproctokctlii{%
237
\ifx\nxt\MG\addF{->}\else\ifx\nxt\GG\addF{>>}%
238
\else\ifx\nxt\LL\addF{<<}\else\ifx\nxt\NULL\addF{NULL}%
239
\else\ifx\nxt\AND\addF&\else\ifx\nxt\OR\addF|%
240
\else\ifx\nxt\XOR\addF^\else\ifx\nxt\CM\addF\tildechar
241
\else\ifx\nxt\MOD\addF{\string\%}\else\ifx\nxt\DC\addF{::}%
242
\else\ifx\nxt\PA\addF{.*}\else\ifx\nxt\MGA\addF{->*}%
243
\else\ifx\nxt\this\addF{this}\else\ifx\nxt\?\addF?%
244
\else\ifx\nxt\E\addF{==}\else\ifx\nxt\G\addF{>=}%
245
\else\ifx\nxt\I\addF{!=}\else\ifx\nxt\K\addF{=}%
246
\else\ifx\nxt\l\addF{l}\else\ifx\nxt\L\addF{L}%
247
\else\ifx\nxt\o\addF{o}\else\ifx\nxt\O\addF{O}%
248
\else\ifx\nxt\R\addF!%
249
\else\ifx\nxt\T \Tnumtrue \let\next\makeolgobbletok
250
\tokprocessedtrue % \T{number}
251
\else\ifx\nxt\AM\addF&\else\ifx\nxt\%\addF{\string\%}%
252
\fi\fi\fi\fi\fi \fi\fi\fi\fi\fi
253
\fi\fi\fi\fi\fi \fi\fi\fi\fi\fi
256
\def\makeolproctokctliii{%
257
\ifx\nxt\V\addF{||}\else\ifx\nxt\W\addF{&&}\else\ifx\nxt\Z\addF{<=}%
258
\else\ifx\nxt\*\addF*\else\ifx\nxt\Xand\addF{\space and\space}%
259
\else\ifx\nxt\Xandxeq\addF{\space and_eq\space}%
260
\else\ifx\nxt\Xbitand\addF{\space bitand\space}%
261
\else\ifx\nxt\Xbitor\addF{\space bitor\space}%
262
\else\ifx\nxt\Xcompl\addF{\space compl\space}%
263
\else\ifx\nxt\Xnot\addF{\space not\space}%
264
\else\ifx\nxt\Xnotxeq\addF{\space not_eq\space}%
265
\else\ifx\nxt\Xor\addF{\space or\space}%
266
\else\ifx\nxt\Xorxeq\addF{\space or_eq\space}%
267
\else\ifx\nxt\Xxor\addF{\space xor\space}%
268
\else\ifx\nxt\Xxorxeq\addF{\space xor_eq\space}%
269
\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
272
\def\outlinedone{\edef\outlinest{\global\noexpand\toksE={\the\toksF}}%
273
\outlinest\let\outlinedone=\relax}
274
\fi % End of pdf macros
276
\def\lapstar{\rlap{*}}
277
\def\stsec{\rightskip=0pt % get out of C mode (cf. \B)
278
\sfcode`;=1500 \pretolerance 200 \hyphenpenalty 50 \exhyphenpenalty 50
279
\noindent{\let\*=\lapstar\bf\secstar.\quad}%
280
\ifpdftex\smash{\raise\baselineskip\hbox to0pt{%
281
\let\*=\empty\pdfdest num \secstar fith}}
282
\else\ifpdf\smash{\raise\baselineskip\hbox to0pt{%
283
\let\*=\empty\special{%
284
pdf: dest (\romannumeral\secstar) [ @thispage /FitH @ypos ]}}}\fi\fi}
285
\let\startsection=\stsec
286
\def\defin#1{\global\advance\ind by 2 \1\&{#1 } } % begin `define' or `format'
287
\def\A{\note{See also section}} % xref for doubly defined section name
288
\def\As{\note{See also sections}} % xref for multiply defined section name
289
\def\B{\rightskip=0pt plus 100pt minus 10pt % go into C mode
292
\hyphenpenalty 1000 % so strings can be broken (discretionary \ is inserted)
293
\exhyphenpenalty 10000
294
\global\ind=2 \1\ \unskip}
295
\def\C#1{\5\5\quad$/\ast\,${\cmntfont #1}$\,\ast/$}
296
\let\SHC\C % "// short comments" treated like "/* ordinary comments */"
297
%\def\C#1{\5\5\quad$\triangleright\,${\cmntfont#1}$\,\triangleleft$}
298
%\def\SHC#1{\5\5\quad$\diamond\,${\cmntfont#1}}
299
\def\D{\defin{\#define}} % macro definition
300
\let\E=\equiv % equivalence sign
301
\def\ET{ and~} % conjunction between two section numbers
302
\def\ETs{, and~} % conjunction between the last two of several section numbers
303
\def\F{\defin{format}} % format definition
304
\let\G=\ge % greater than or equal sign
305
% \H is long Hungarian umlaut accent
306
\let\I=\ne % unequal sign
307
\def\J{\.{@\&}} % TANGLE's join operation
308
\let\K== % assignment operator
309
%\let\K=\leftarrow % "honest" alternative to standard assignment operator
310
% \L is Polish letter suppressed-L
311
\outer\def\M#1{\MN{#1}\ifon\vfil\penalty-100\vfilneg % beginning of section
312
\vskip\intersecskip\startsection\ignorespaces}
313
\outer\def\N#1#2#3.{% beginning of starred section
314
\ifacro{\toksF={}\makeoutlinetoks#3\outlinedone\outlinedone}\fi
315
\gdepth=#1\gtitle={#3}\MN{#2}%
316
\ifon\ifnum#1<\secpagedepth \vfil\eject % force page break if depth is small
317
\else\vfil\penalty-100\vfilneg\vskip\intersecskip\fi\fi
318
\message{*\secno} % progress report
319
\def\stripprefix##1>{}\def\gtitletoks{#3}%
320
\edef\gtitletoks{\expandafter\stripprefix\meaning\gtitletoks}%
321
\edef\next{\write\cont{\ZZ{\gtitletoks}{#1}{\secno}% write to contents file
322
{\noexpand\the\pageno}{\the\toksE}}}\next % \ZZ{title}{depth}{sec}{page}{ss}
323
\ifpdftex\expandafter\xdef\csname curr#1\endcsname{\secno}
324
\ifnum#1>0\countB=#1 \advance\countB by-1
325
\advancenumber{chunk\the\countB.\expnumber{curr\the\countB}}\fi\fi
326
\ifpdf\special{pdf: outline #1 << /Title (\the\toksE) /Dest
327
[ @thispage /FitH @ypos ] >>}\fi
328
\ifon\startsection{\bf#3.\quad}\ignorespaces}
329
\def\MN#1{\par % common code for \M, \N
330
{\xdef\secstar{#1}\let\*=\empty\xdef\secno{#1}}% remove \* from section name
331
\ifx\secno\secstar \onmaybe \else\ontrue \fi
332
\mark{{{\tensy x}\secno}{\the\gdepth}{\the\gtitle}}}
333
% each \mark is {section reference or null}{depth plus 1}{group title}
334
% \O is Scandinavian letter O-with-slash
335
% \P is paragraph sign
336
\def\Q{\note{This code is cited in section}} % xref for mention of a section
337
\def\Qs{\note{This code is cited in sections}} % xref for mentions of a section
338
\let\R=\lnot % logical not
340
\def\T#1{\leavevmode % octal, hex or decimal constant
341
\hbox{$\def\?{\kern.2em}%
342
% \def\$##1{\egroup_{\,\rm##1}\bgroup}% suffix to constant % versions < 3.67
343
\def\$##1{\egroup_{\rm##1}\bgroup}% suffix to constant
344
\def\_{\cdot 10^{\aftergroup}}% power of ten (via dirty trick)
345
\let\~=\oct \let\^=\hex {#1}$}}
346
\def\U{\note{This code is used in section}} % xref for use of a section
347
\def\Us{\note{This code is used in sections}} % xref for uses of a section
348
\let\V=\lor % logical or
349
\let\W=\land % logical and
350
\def\X#1:#2\X{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi %$% section name
351
\XX$\langle\,${\let\I=\ne#2\eightrm\kern.5em
352
\ifacro{\pdfnote#1.}\else#1\fi}$\,\rangle$\XX}
355
\let\ZZ=\let % now you can \write the control sequence \ZZ
358
\def\Xand{\W} \def\Xandxeq{\MRL{{\AND}{\K}}} \def\Xbitand{\AND}
359
\def\Xbitor{\OR} \def\Xcompl{\CM} \def\Xnot{\R} \def\Xnotxeq{\I} \def\Xor{\V}
360
\def\Xorxeq{\MRL{{\OR}{\K}}} \def\Xxor{\XOR} \def\Xxorxeq{\MRL{{\XOR}{\K}}}
362
%\def\oct{\hbox{\rm\char'23\kern-.2em\it\aftergroup\?\aftergroup}} % WEB style
363
%\def\hex{\hbox{\rm\char"7D\tt\aftergroup}} % WEB style
364
\def\oct{\hbox{$^\circ$\kern-.1em\it\aftergroup\?\aftergroup}}% CWEB style
365
\def\hex{\hbox{$^{\scriptscriptstyle\#}$\tt\aftergroup}} % CWEB style
366
\def\vb#1{\leavevmode\hbox{\kern2pt\vrule\vtop{\vbox{\hrule
367
\hbox{\strut\kern2pt\.{#1}\kern2pt}}
368
\hrule}\vrule\kern2pt}} % verbatim string
370
\def\onmaybe{\let\ifon=\maybe} \let\maybe=\iftrue
371
\newif\ifon \newif\iftitle \newif\ifpagesaved
374
\def\lheader{\headertrue\mainfont\the\pageno\eightrm\qquad\grouptitle
375
\hfill\title\qquad\mainfont\topsecno} % top line on left-hand pages
376
\def\rheader{\headertrue\mainfont\topsecno\eightrm\qquad\title\hfill
377
\grouptitle\qquad\mainfont\the\pageno} % top line on right-hand pages
378
\def\grouptitle{\let\i=I\let\j=J\uppercase\expandafter{\expandafter
380
\def\topsecno{\expandafter\takeone\topmark}
381
\def\takeone#1#2#3{#1}
382
\def\taketwo#1#2#3{#2}
383
\def\takethree#1#2#3{#3}
384
\def\nullsec{\eightrm\kern-2em} % the \kern-2em cancels \qquad in headers
386
\let\page=\pagebody \raggedbottom
387
% \def\page{\box255 }\normalbottom % faster, but loses plain TeX footnotes
388
\def\normaloutput#1#2#3{\ifodd\pageno\hoffset=\pageshift\fi
390
\vbox to\fullpageheight{
391
\iftitle\global\titlefalse
392
\else\hbox to\pagewidth{\vbox to10pt{}\ifodd\pageno #3\else#2\fi}\fi
393
\vfill#1}} % parameter #1 is the page itself
394
\global\advance\pageno by1}
396
\gtitle={\.{CWEB} output} % this running head is reset by starred sections
397
\mark{\noexpand\nullsec0{\the\gtitle}}
398
\def\title{\expandafter\uppercase\expandafter{\jobname}}
399
\def\topofcontents{\centerline{\titlefont\title}\vskip.7in
400
\vfill} % this material will start the table of contents page
401
\def\startpdf{\ifpdftex\pdfcatalog{/PageMode /UseOutlines}\else
402
\ifpdf{\special{pdf: docview << /PageMode /UseOutlines >>}}\fi\fi}
403
\def\botofcontents{\vfill
404
\centerline{\covernote}} % this material will end the table of contents page
406
\def\contentspagenumber{0} % default page number for table of contents
407
\newdimen\pagewidth \pagewidth=6.5in % the width of each page
408
\newdimen\pageheight \pageheight=8.7in % the height of each page
409
\newdimen\fullpageheight \fullpageheight=9in % page height including headlines
410
\newdimen\pageshift \pageshift=0in % shift righthand pages wrt lefthand ones
411
\def\magnify#1{\mag=#1\pagewidth=6.5truein\pageheight=8.7truein
412
\fullpageheight=9truein\setpage}
413
\def\setpage{\hsize\pagewidth\vsize\pageheight} % use after changing page size
414
\def\contentsfile{\jobname.toc} % file that gets table of contents info
415
\def\readcontents{\input \contentsfile}
416
\def\readindex{\input \jobname.idx}
417
\def\readsections{\input \jobname.scn}
420
\output{\setbox0=\page % the first page is garbage
421
\openout\cont=\contentsfile
422
\write\cont{\catcode `\noexpand\@=11\relax} % \makeatletter
423
\global\output{\normaloutput\page\lheader\rheader}}
425
\vbox to \vsize{} % the first \topmark won't be null
427
\def\ch{\note{The following sections were changed by the change file:}
429
\newbox\sbox % saved box preceding the index
430
\newbox\lbox % lefthand column in the index
431
\def\inx{\par\vskip6pt plus 1fil % we are beginning the index
432
\def\page{\box255 } \normalbottom
433
\write\cont{} % ensure that the contents file isn't empty
434
\write\cont{\catcode `\noexpand\@=12\relax} % \makeatother
435
\closeout\cont % the contents information has been fully gathered
436
\output{\ifpagesaved\normaloutput{\box\sbox}\lheader\rheader\fi
437
\global\setbox\sbox=\page \global\pagesavedtrue}
438
\pagesavedfalse \eject % eject the page-so-far and predecessors
439
\setbox\sbox\vbox{\unvbox\sbox} % take it out of its box
440
\vsize=\pageheight \advance\vsize by -\ht\sbox % the remaining height
441
\hsize=.5\pagewidth \advance\hsize by -10pt
442
% column width for the index (20pt between cols)
443
\parfillskip 0pt plus .6\hsize % try to avoid almost empty lines
444
\def\lr{L} % this tells whether the left or right column is next
445
\output{\if L\lr\global\setbox\lbox=\page \gdef\lr{R}
446
\else\normaloutput{\vbox to\pageheight{\box\sbox\vss
447
\hbox to\pagewidth{\box\lbox\hfil\page}}}\lheader\rheader
448
\global\vsize\pageheight\gdef\lr{L}\global\pagesavedfalse\fi}
450
\parskip 0pt plus .5pt
451
\outer\def\I##1, ##2.{\par\hangindent2em\noindent##1:\kern1em
452
\ifacro\pdfnote##2.\else##2\fi.} % index entry
453
\def\[##1]{$\underline{##1}$} % underlined index item
454
\rm \rightskip0pt plus 2.5em \tolerance 10000 \let\*=\lapstar
455
\hyphenpenalty 10000 \parindent0pt
457
\def\fin{\par\vfill\eject % this is done when we are ending the index
458
\ifpagesaved\null\vfill\eject\fi % output a null index column
459
\if L\lr\else\null\vfill\eject\fi % finish the current page
460
\parfillskip 0pt plus 1fil
461
\def\grouptitle{NAMES OF THE SECTIONS}
462
\let\topsecno=\nullsec
463
\message{Section names:}
464
\output={\normaloutput\page\lheader\rheader}
466
\def\note##1##2.{\quad{\eightrm##1~\ifacro{\pdfnote##2.}\else{##2}\fi.}}
467
\def\Q{\note{Cited in section}} % crossref for mention of a section
468
\def\Qs{\note{Cited in sections}} % crossref for mentions of a section
469
\def\U{\note{Used in section}} % crossref for use of a section
470
\def\Us{\note{Used in sections}} % crossref for uses of a section
471
\def\I{\par\hangindent 2em}\let\*=*
472
\ifacro \def\outsecname{Names of the sections} \let\Xpdf\X
473
\ifpdftex \makebookmarks \pdfdest name {NOS} fitb
474
\pdfoutline goto name {NOS} count -\secno {\outsecname}
475
\def\X##1:##2\X{\Xpdf##1:##2\X \firstsecno##1.%
476
{\toksF={}\makeoutlinetoks##2\outlinedone\outlinedone}%
477
\pdfoutline goto num \the\toksA \expandafter{\the\toksE}}
479
\special{pdf: outline -1 << /Title (\outsecname)
480
/Dest [ @thispage /FitH @ypos ] >>}
481
\def\X##1:##2\X{\Xpdf##1:##2\X \firstsecno##1.%
482
{\toksF={}\makeoutlinetoks##2\outlinedone\outlinedone}%
483
\special{pdf: outline 0 << /Title (\the\toksE)
484
/A << /S /GoTo /D (\romannumeral\the\toksA) >> >>}}
487
\def\makebookmarks{\let\ZZ=\writebookmarkline \readcontents\relax}
488
\def\expnumber#1{\expandafter\ifx\csname#1\endcsname\relax 0%
489
\else \csname#1\endcsname \fi} % Petr Olsak's macros from texinfo.tex
490
\def\advancenumber#1{\countA=\expnumber{#1}\relax \advance\countA by1
491
\expandafter\xdef\csname#1\endcsname{\the\countA}}
492
\def\writebookmarkline#1#2#3#4#5{{%
493
\let\(=\let \let\)=\let \let\[=\let \let\]=\let \let\/=\let
494
\pdfoutline goto num #3 count -\expnumber{chunk#2.#3} {#5}}}
495
\def\con{\par\vfill\eject % finish the section names
496
% \ifodd\pageno\else\titletrue\null\vfill\eject\fi % for duplex printers
497
\rightskip 0pt \hyphenpenalty 50 \tolerance 200
498
\setpage \output={\normaloutput\page\lheader\rheader}
499
\titletrue % prepare to output the table of contents
500
\pageno=\contentspagenumber
501
\def\grouptitle{TABLE OF CONTENTS}
502
\message{Table of contents:}
503
\topofcontents \startpdf
504
\line{\hfil Section\hbox to3em{\hss Page}}
505
\let\ZZ=\contentsline
506
\readcontents\relax % read the contents info
507
\botofcontents \end} % print the contents page(s) and terminate
508
\def\contentsline#1#2#3#4#5{\ifnum#2=0 \smallbreak\fi
509
\line{\consetup{#2}#1
510
\rm\leaders\hbox to .5em{.\hfil}\hfil
511
\ \ifacro\pdflink{#3}{\romannumeral#3}\else#3\fi\hbox to3em{\hss#4}}}
512
\def\consetup#1{\ifcase#1 \bf % depth -1 (@**)
514
\or \hskip2em % depth 1 (@*1)
515
\or \hskip4em \or \hskip6em \or \hskip8em \or \hskip10em % depth 2,3,4,5
516
\else \hskip12em \fi} % depth 6 or more
517
\def\noinx{\let\inx=\end} % no indexes or table of contents
518
\def\nosecs{\let\FIN=\fin \def\fin{\let\parfillskip=\end \FIN}}
519
% no index of section names or table of contents
520
\def\nocon{\let\con=\end} % no table of contents
521
\def\today{\ifcase\month\or
522
January\or February\or March\or April\or May\or June\or
523
July\or August\or September\or October\or November\or December\fi
524
\space\number\day, \number\year}
526
\def\hours{\twodigits=\time \divide\twodigits by 60 \printtwodigits
527
\multiply\twodigits by-60 \advance\twodigits by\time :\printtwodigits}
529
\def\printtwodigits{\advance\twodigits100
530
\expandafter\gobbleone\number\twodigits
531
\advance\twodigits-100 }
532
\def\TeX{{\ifmmode\it\fi
533
\leavevmode\hbox{T\kern-.1667em\lower.424ex\hbox{E}\hskip-.125em X}}}
534
\def\,{\relax\ifmmode\mskip\thinmuskip\else\thinspace\fi}
535
\def\datethis{\def\startsection{\leftline{\sc\today\ at \hours}\bigskip
536
\let\startsection=\stsec\stsec}}
537
% say `\datethis' in limbo, to get your listing timestamped before section 1
538
%\def\datecontentspage{% versions up to 3.65
539
% \def\topofcontents{\leftline{\sc\today\ at \hours}\bigskip
540
% \centerline{\titlefont\title}\vfill}} % timestamps the contents page
541
\def\datecontentspage{% changed in version 3.66
542
\def\botofcontents{\vfill
543
\centerline{\covernote}
545
\leftline{\sc\today\ at \hours}}} % timestamps the contents page