m-cweb.mkiv /size: 22 Kb    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=m-cweb,
3%D        version=1997.01.15,
4%D          title=\CONTEXT\ Extra Modules,
5%D       subtitle=\CWEB\ Pretty Printing Macros,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14%D This module has to be redone in the mkiv way and I do that stepwise so the
15%D current code is not okay.
16
17% todo:
18%
19% \deactivateCWEB in output routine
20% status info
21% linked entries
22% parskip en parindent
23% breaks and whitespace
24% fonts ... now math abuse down here
25
26%D \gdef\CWEBquote#1.{{\em Quote :}\ #1.} % checks the .
27%D
28%D This module (re)implements the \CWEB\ macros as defined in the file \type
29%D {cwebmac.tex}. \CWEB\ uses short, often one character long, names for macros.
30%D This is no real problem because no one is supposed to read and understand the
31%D files generated by \CWEB. The standard macros are meant for \PLAIN\ \TEX\ users.
32%D In \CONTEXT\ and other macro packages however, there is a potential conflict with
33%D format specific or user defined commands. Furthermore, the \CWEB\ macros
34%D implement their own output routines. When integrating \CWEB\ documents in another
35%D environment, the \CWEB\ specific macros have to be made local. The first part of
36%D this module is dedicated to this feature.
37%D
38%D Instead of using \type {\def} and \type {\let} for defining macros, we use:
39%D
40%D \starttyping
41%D \defCEBmacro arguments {meaning}
42%D \letCEBmacro arguments {meaning}
43%D \stoptyping
44%D
45%D \CWEB\ files contain implicit calls to macros that generate the table of contents,
46%D the lists of sections and the index. Because we want to be much more flexible, we
47%D implemented our own alternatives, and therefore have to bypass the original ones.
48%D The next macro is used for defining these obsolete \CWEB\ macros. The dummies
49%D take care of arguments.
50%D
51%D \starttyping
52%D \defCEBdummy arguments {meaning}
53%D \stoptyping
54%D
55%D The list of \CWEB\ specific macro names is saved in a \TOKENLIST. This serves two
56%D purposes. First it enables us to activate the \CWEB\ macros, which are saved
57%D under a different name, second it can be used to temporary restore the meanings,
58%D for instance when the output routine builds the page.
59%D
60%D We don't provide specific formatting commands. We just assume \CONTEXT\ being
61%D used (so you can use all it provides) and|/|or that specific user macros are
62%D implemented somewhere else.
63
64\unprotect
65
66\newtoks\CWEBmacros
67
68%D Activating and deactivating is done by means of:
69%D
70%D \starttyping
71%D \activateCWEB
72%D \deactivateCWEB
73%D \stoptyping
74%D
75%D These are implemented as:
76
77\unexpanded\def\activateCWEB
78  {\let\doCWEB\activateCWEBmacro
79   \the\CWEBmacros}
80
81\unexpanded\def\deactivateCWEB
82  {\let\doCWEB\deactivateCWEBmacro
83   \the\CWEBmacros}
84
85%D The three definition macros append the name of the macro to the list. The first
86%D two macros save the meaning, the last one assigns \type {{}} to the macro and
87%D gobbles original meaning.
88
89\installcorenamespace{newCWEB}
90\installcorenamespace{oldCWEB}
91
92\unexpanded\def\defCWEBmacro#1%
93  {\appendtoks\doCWEB#1\to\CWEBmacros
94   \setuvalue{\??newCWEB\string#1}}
95
96\unexpanded\def\letCWEBmacro#1%
97  {\appendtoks\doCWEB#1\to\CWEBmacros
98   \letvalue{\??newCWEB\string#1}}
99
100\unexpanded\def\defCWEBdummy#1#2#%
101  {\appendtoks\doCWEB#1\to\CWEBmacros
102   \setuvalue{\??newCWEB\string#1}#2{}%
103   \gobbleoneargument}
104
105%D The macro \type {\defCWEBdummy} of course takes care of the argument. This leaves
106%D the two (de|)|activating macros:
107
108\unexpanded\def\CWEBmacro#1%
109  {\getvalue{\??newCWEB\string#1}}
110
111\unexpanded\def\activateCWEBmacro#1%
112  {\letvalue{\??oldCWEB\string#1}=#1%
113   \unexpanded\def#1{\CWEBmacro#1}}
114
115\unexpanded\def\deactivateCWEBmacro#1%
116  {\expandafter\let\expandafter#1\csname\??oldCWEB\string#1\endcsname}
117
118\protect
119
120%D I did consider loading the \CWEB\ macros using temporary substitutes of \type
121%D {\def}, \type {\font}, \type {\newbox} etc. The main problem is that the file
122%D contains more than definitions and taking all kind of assignments into account
123%D too would not make things easier. So I decided to stick to the method as just
124%D described.
125%D
126%D Now we're ready for the real job. What follows is a partial adaption of the file
127%D \type {cwebmac.tex}, version 3.1, dated September 1994 and written by Levy and
128%D Knuth. When possible we kept the original meaning, but we've granted ourselves
129%D the freedom to reformat the macro's for readibility.
130%D
131%D We'll only present the macros we actually use. The source however contains the
132%D original implementation.
133%D
134%D The next is based on the standard macros for CWEB listings (in addition to \type
135%D {plain.tex}) Version 3.1 --- September 1994.
136
137%D \macros{.}
138%D
139%D \CWEBquote preserve a way to get the dot accent (all other accents will still
140%D work as usual).
141
142\letCWEBmacro\: = \.
143
144%D \macros{CEE,UNIX,TEX,CPLUSPLUS}
145%D
146%D Next come some logo's. It does not make much sense to use the \CONTEXT\ logo
147%D mechanism here, so we simply say:
148
149\defCWEBmacro      \CEE/{{\tx C\spacefactor1000}}
150\defCWEBmacro     \UNIX/{{\tx UNIX\spacefactor1000}}
151\defCWEBmacro      \TEX/{\TeX}
152\defCWEBmacro\CPLUSPLUS/{{\tx C\PP\spacefactor1000}}
153\defCWEBmacro       \Cee{\CEE/} % for backward compatibility
154
155%D \macros{\ }
156%D
157%D Now we come to the real work: the short commands that make up the typography.
158%D
159%D \CWEBquote italic type for identifiers.
160
161\defCWEBmacro\\#1%
162  {\dontleavehmode
163   \hbox{\it#1\/\kern.05em}}
164
165%D \macros{\string|}
166%D
167%D \CWEBquote one letter identifiers look better this way.
168
169\defCWEBmacro\|#1%
170  {\dontleavehmode
171   \hbox{$#1$}}
172
173%D \macros{\string\&}
174%D
175%D \CWEBquote boldface type for reserved words.
176
177\defCWEBmacro\&#1%
178  {\dontleavehmode
179   \hbox{\bf#1\/\kern.05em}}
180
181%D \macros{.}
182%D
183%D Here we use the previously saved period. This macro takes care of special
184%D characters in strings.
185
186\defCWEBmacro\.#1%
187  {\dontleavehmode
188   \hbox
189     {\tttf      % typewriter type for strings
190      \let\\=\BS % backslash in a string
191      \let\{=\LB % left brace in a string
192      \let\}=\RB % right brace in a string
193      \let\~=\TL % tilde in a string
194      \let\ =\SP % space in a string
195      \let\_=\UL % underline in a string
196      \let\&=\AM % ampersand in a string
197      \let\^=\CF % circumflex in a string
198      #1\kern.05em}}
199
200%D \macros{)}
201%D
202%D Some discretionary hack.
203
204\defCWEBmacro\)%
205  {\discretionary{\hbox{\tttf\BS}}{}{}}
206
207%D \macros{AT}
208%D
209%D \CWEBquote at sign for control text (not needed in versions $>=$ 2.9).
210
211\defCWEBmacro\AT{@}
212
213%D \macros{ATL,postATL,NOATL}
214%D
215%D A two step macro that handles whatever.
216
217\defCWEBmacro\ATL
218  {\par
219   \noindent
220   \bgroup
221   \catcode`\_=12
222   \postATL}
223
224\defCWEBmacro\postATL#1 #2 %
225  {\bf letter \\{\WORD{\char"#1}} tangles as \tttf \quotation{#2}%
226   \egroup
227   \par}
228
229\defCWEBmacro\noATL#1 #2 %
230  {}
231
232%D \macros{noatl}
233%D
234%D \CWEBquote suppress output from \type {@l}.
235
236\defCWEBmacro\noatl
237  {\let\ATL\noATL}
238
239% \defCWEBmacro\ATH%
240%   {\X\kern-.5em:Preprocessor definitions\X}
241
242%D \macros{PB}
243%D
244%D \CWEBquote hook for program brackets {\tttf\string|...\string|} in \TEX\ part or
245%D section name.
246
247\defCWEBmacro\PB
248  {\relax}
249
250\letCWEBmacro\AM \letterampersand  % ampersand character in a string
251\letCWEBmacro\BS \letterbackslash  % backslash in a string
252\letCWEBmacro\LB \letterleftbrace  % left brace in a string
253\letCWEBmacro\RB \letterrightbrace % right brace in a string
254\letCWEBmacro\TL \lettertilde      % tilde in a string
255\letCWEBmacro\UL \letterunderscore % underline character in a string
256\letCWEBmacro\CF \letterhat        % circumflex character in a string
257\letCWEBmacro\SP \textvisiblespace % (visible) space in a string
258
259%D We're in mathmode, otherwise we could have:
260%D
261%D \starttyping
262%D \defCWEBmacro\PP{\raise.15em\hbox{\tx\textplus \kern-.05em\textplus }}
263%D \defCWEBmacro\MM{\raise.15em\hbox{\tx\textminus\kern .10em\textminus}}
264%D \defCWEBmacro\MG{\raise.15em\hbox{\rightarrow}}
265%D \stoptyping
266
267\defCWEBmacro\PP % symbol for ++
268  {\kern.05em
269   \raise.1em\hbox{$\scriptstyle+\kern-.1em+$}%
270   \kern.05em}
271
272\defCWEBmacro\MM % symbol for --
273  {\kern.05em
274   \raise.1em\hbox{$\scriptstyle-\kern-.1em-$}%
275   \kern.05em}
276
277\defCWEBmacro\MG
278  {\kern-.2em
279   \lower.3em\hbox{$\rightarrow$}%
280   \kern .1em}
281
282\defCWEBmacro\MRL#1%
283  {\mathrel{\let\K==#1}}
284
285% \def\MRL  #1{\KK#1}
286% \def\KK #1#2{\buildrel\;#1\over{#2}}
287
288\letCWEBmacro\GG   = \gg
289\letCWEBmacro\LL   = \ll
290\letCWEBmacro\NULL = \Lambda
291
292\letCWEBmacro\AND  = \mathampersand  % bitwise and; also \& (unary operator)
293
294\letCWEBmacro\OR   = \mid                     % bitwise or
295\letCWEBmacro\XOR  = \oplus                   % bitwise exclusive or
296\defCWEBmacro\CM     {{\sim}}                 % bitwise complement
297\defCWEBmacro\MOD    {\mathbin{\tx\%}}
298\defCWEBmacro\DC     {\kern.1em{::}\kern.1em} % symbol for ::
299\defCWEBmacro\PA     {\mathbin{.*}}           % symbol for .*
300\defCWEBmacro\MGA    {\mathbin{\MG*}}         % symbol for ->*
301\defCWEBmacro\this   {\&{this}}
302
303\newcount\CWEBind  % current indentation in ems
304
305\defCWEBmacro\1%     indent one more notch
306  {\global\advance\CWEBind \plusone
307   \hangindent\CWEBind \emwidth}
308
309\defCWEBmacro\2%     indent one less notch
310  {\global\advance\CWEBind \minusone}
311
312\defCWEBmacro\3#1%   optional break within a statement
313  {\hfil
314   \penalty#10\relax
315   \hfilneg}
316
317\defCWEBmacro\4%   backspace one notch
318  {\hpack to -1em{}}
319
320\defCWEBmacro\5%   optional break
321  {\hfil
322   \penalty\minusone
323   \hfilneg
324   \kern2.5em
325   \hpack to -2em{}%
326   \ignorespaces}
327
328\defCWEBmacro\6%   forced break
329   {\ifmmode \else
330      \par
331      \hangindent\CWEBind em
332      \noindent
333      \kern\CWEBind em
334      \hpack to -2em{}%
335      \ignorespaces
336    \fi}
337
338\defCWEBmacro\7%   forced break and a little extra space
339  {\Y
340   \6}
341
342\defCWEBmacro\8%   no indentation
343  {\hskip-\CWEBind em
344   \hskip 2em}
345
346\defCWEBmacro\9#1%
347  {}
348
349\newcount\CWEBgdepth  % depth of current major group, plus one
350\newcount\CWEBsecpagedepth
351
352\CWEBsecpagedepth=3   % page breaks will occur for depths -1, 0, and 1
353
354\defCWEBmacro\?%
355  {\mathrel?}
356
357\defCWEBmacro\lapstar
358  {\rlap{*}}
359
360\defCWEBmacro\defin#1%
361  {\global\advance\CWEBind by 2 \1\&{#1 } } % begin `define' or `format'
362
363\defCWEBmacro\B%
364 {\rightskip=0pt plus 100pt minus 10pt % go into C mode
365  \sfcode`;=3000
366  \pretolerance 10000
367  \hyphenpenalty 1000 % so strings can be broken (discretionary \ is inserted)
368  \exhyphenpenalty 10000
369  \global\CWEBind=2 \1\ \unskip}
370
371\defCWEBmacro\C#1%
372  {\5\5\quad$/\ast\,${\ss\detokenize{#1}}$\,\ast/$}
373
374\defCWEBmacro\SHC#1%
375  {\5\5\quad$//\,${\ss#1}}
376
377\defCWEBmacro\D% macro definition
378  {\defin{\#define}}
379
380\letCWEBmacro\E=\equiv % equivalence sign
381
382% \def\ET% conjunction between two section numbers
383%   { and~}
384%
385% \def\ETs% conjunction between the last two of several section numbers
386%   {, and~}
387
388\defCWEBmacro\F% format definition
389  {\defin{format}}
390
391\letCWEBmacro\G = \ge % greater than or equal sign
392
393% \H is long Hungarian umlaut accent
394
395\letCWEBmacro\I = \ne % unequal sign
396
397\defCWEBmacro\J% TANGLE's join operation
398  {\.{@\&}}
399
400\letCWEBmacro\K = \leftarrow % "honest" alternative to standard assignment operator
401
402% \L is Polish letter suppressed-L
403% \O is Scandinavian letter O-with-slash
404% \P is paragraph sign
405
406\defCWEBmacro\Q  {\note{This code is cited in section}}  % xref for mention of a section
407\defCWEBmacro\Qs {\note{This code is cited in sections}} % xref for mentions of a section
408
409% \S is section sign
410
411\defCWEBmacro\T#1%
412  {\dontleavehmode % octal, hex or decimal constant
413   \hbox
414     {$\def\?{\kern.2em}%
415      \def\$##1{\egroup_{\,\rm##1}\bgroup}% suffix to constant
416      \def\_{\cdot 10^{\aftergroup}}% power of ten (via dirty trick)
417      \let\~=\oct
418      \let\^=\hex
419      {#1}$}}
420
421\defCWEBmacro\U  {\note{This code is used in section}} % xref for use of a section
422\defCWEBmacro\Us {\note{This code is used in sections}} % xref for uses of a section
423
424\letCWEBmacro\R  = \lnot % logical not
425\letCWEBmacro\V  = \lor  % logical or
426\letCWEBmacro\W  = \land % logical and
427
428\unprotect
429
430\def\theCWEByskip {\blank[\v!small]}
431\def\theCWEBvskip {\blank[\v!big]}
432
433\protect
434
435\defCWEBmacro\Y%
436  {\par
437   \yskip}
438
439\defCWEBmacro\yskip
440  {\theCWEByskip}
441
442\letCWEBmacro\Z  = \le
443\letCWEBmacro\ZZ = \relax
444\letCWEBmacro\*  = *
445
446\defCWEBmacro\oct
447  {\hbox{$^\circ$\kern-.1em\it\aftergroup\?\aftergroup}}
448
449\defCWEBmacro\hex
450  {\hbox{$^{\scriptscriptstyle\#}$\tt\aftergroup}}
451
452\defCWEBmacro\vb#1%
453  {\dontleavehmode
454   \hbox
455     {\kern.2em
456      \vrule
457      \vtop
458        {\vbox
459           {\hrule
460            \hbox{\strut\kern.2em\.{#1}\kern.2em}}
461         \hrule}%
462      \vrule
463      \kern.2em}} % verbatim string
464
465\def\onmaybe
466  {\let\ifon=\maybe}
467
468\let\maybe=\iftrue
469
470\newif\ifon
471
472\def\botofcontents
473  {\vfill
474   \centerline{\covernote}} % this material will end the table of contents page
475
476\def\covernote
477  {}
478
479% some leftover
480
481\defCWEBmacro\contentspagenumber{0} % default page number for table of contents
482
483\defCWEBdummy\magnify#1%  magnify the page
484  {}
485
486\defCWEBmacro\ch
487  {\note{The following sections were changed by the change file:}
488   \let\*=\relax}
489
490\defCWEBmacro\consetup#1%
491  {\ifcase#1 \bf        % depth -1 (@**)
492   \or                  % depth  0 (@*)
493   \or       \hskip 2em % depth  1 (@*1)
494   \or       \hskip 4em % depth  2 (@*2)
495   \or       \hskip 6em % depth  3 (@*3)
496   \or       \hskip 8em % depth  4 (@*4)
497   \or       \hskip10em % depth  5 (@*5)
498   \else     \hskip12em
499   \fi}                 % depth  6 or more
500
501\defCWEBdummy \inx    {} % index
502\defCWEBdummy \fin    {} % finish
503\defCWEBdummy \con    {} % table of contents and finish
504
505\defCWEBdummy \noinx  {} % no indexes or table of contents
506\defCWEBdummy \nosecs {} % no index of section names or table of contents
507\defCWEBdummy \nocon  {} % no table of contents
508
509\defCWEBmacro\,%
510  {\relax
511   \ifmmode
512     \mskip\thinmuskip
513   \else
514     \thinspace
515   \fi}
516
517\defCWEBdummy\datethis         {} % say `\datethis' in limbo, to get your listing timestamped before section 1
518\defCWEBdummy\datecontentspage {} % timestamps the contents page
519
520\defCWEBmacro\TeX
521  {{\ifmmode\it\fi
522    \dontleavehmode
523    \hbox{T\kern-.1667em\lower.424ex\hbox{E}\hskip-.125em X}}}
524
525% alternative implementation
526
527\newif\ifCWEBnotes
528
529\defCWEBmacro\Q   {\CWEBnotesfalse \note{This code is cited in section}}  % xref for mention of a section
530\defCWEBmacro\Qs  {\CWEBnotestrue  \note{This code is cited in sections}} % xref for mentions of a section
531
532\defCWEBmacro\U   {\CWEBnotesfalse \note{This code is used in section}}  % xref for use of a section
533\defCWEBmacro\Us  {\CWEBnotestrue  \note{This code is used in sections}} % xref for uses of a section
534
535\defCWEBmacro\A   {\CWEBnotesfalse \note{See also section}}  % xref for doubly defined section name
536\defCWEBmacro\As  {\CWEBnotestrue  \note{See also sections}} % xref for multiply defined section name
537
538\defCWEBmacro\ET  { and~}  % conjunction between two section numbers
539\defCWEBmacro\ETs {, and~} % conjunction between the last two of several section numbers
540
541\def\processCWEBsectionnumber#1%
542  {\bgroup
543   \def\[##1]{##1}%
544   \xdef\CWEBreference{#1}%
545   \egroup
546   \CWEBcomma{\goto{#1}[web:\CWEBreference]}}
547
548\unexpanded\def\processCWEBsectionnumbers[#1]%
549  {\bgroup
550   \def\CWEBcomma{\def\CWEBcomma{, }}%
551   \processlist(),\processCWEBsectionnumber(#1)%
552   \egroup}
553
554\unexpanded\def\processCWEBsectionnotes
555  {\catcode`\s=12
556   \doprocessCWEBsectionnotes}
557
558\def\doprocessCWEBsectionnote#1\ET#2#3.%
559  {\processCWEBsectionnumbers[#1]%
560   \if#2s%
561     {, and~\goto{##3}[web:#3]}%
562   \else
563     { and~\goto{##2##3}[web:#2#3]}%
564   \fi}%
565
566\unexpanded\def\doprocessCWEBsectionnotes#1.%
567  {\ifCWEBnotes
568     \doprocessCWEBsectionnote#1.%
569   \else
570     \goto{#1}[web:#1]%
571   \fi
572   \afterCWEBnote % inside group!
573   \egroup}
574
575\let\afterCWEBnote\relax
576
577\defCWEBmacro\note#1%
578  {\bgroup
579   \Y\noindent
580   \def\afterCWEBnote{\par}%
581   \hangindent2em
582   %\baselineskip10pt
583   \tx#1~\processCWEBsectionnotes}
584
585\unexpanded\def\oldCWEBmacroX#1:#2\X% original
586  {\ifmmode
587     \gdef\XX{\null$\null}%
588   \else
589     \glet\XX\empty
590   \fi % section name
591   \XX$\langle\,${#2\tx\kern.5em#1}$\,\rangle$\XX}
592
593\defCWEBmacro\ATH
594  {\oldCWEBmacroX\kern-.5em:Preprocessor definitions\X}
595
596\unexpanded\def\newCWEBmacroX#1:#2\X% original
597  {\ifmmode
598     \gdef\XX{\null$\null}%
599   \else
600     \glet\XX\empty
601   \fi % section name
602   \XX$\langle\,$%
603   {#2\tx\kern.5em\processCWEBsectionnumbers[{#1}]}%
604   $\,\rangle$\XX}
605
606\defCWEBmacro\X#1:#2\X%
607  {\newCWEBmacroX#1:#2\X}
608
609%D The next code is a bit messy because there is skipping over content
610%D and we have \type {\fi}'s in the source.
611
612\let\CWEBsecno\empty
613
614\definelist[cweb]
615
616\defCWEBmacro\startsection
617  {\rightskip=0pt % get out of C mode (cf. \B)
618   \sfcode`;=1500
619   \pretolerance 200
620   \hyphenpenalty 50
621   \exhyphenpenalty 50
622   \noindent
623   \bgroup
624   \let\*=\lapstar
625   \gotoCWEBsection{\bf\CWEBsecstar.\quad}[\CWEBsecno]%
626   \egroup}
627
628\defCWEBmacro\MN#1%
629  {\par % common code for \M, \N
630   \begingroup
631     \xdef\CWEBsecstar{#1}%
632     \let\*=\empty
633     \xdef\CWEBsecno{#1}% remove \* from section name
634   \endgroup
635   \ifx\CWEBsecno\CWEBsecstar
636     \onmaybe
637   \else
638     \ontrue
639   \fi}
640
641\defCWEBmacro\M#1%
642  {\MN{#1}%
643   \ifon
644     \vfil
645     \penalty-100
646     \vfilneg % beginning of section
647     \theCWEBvskip
648     \startsection
649     \pagereference[web:#1]%
650     \expanded{\marking[CWEBsectionnumber]{\secno}}%
651     \expanded{\marking[CWEBsectiondepth]{\the\CWEBgdepth}}%
652     \ignorespaces}
653
654\defCWEBmacro\N#1#2#3.%
655  {\CWEBgdepth=#1%
656   \MN{#2}% beginning of starred section
657   \ifon
658     \ifnum#1<\CWEBsecpagedepth
659       \page
660     \else
661       \vfil
662       \penalty-100
663       \vfilneg
664       \theCWEBvskip
665     \fi
666   \fi
667   \writedatatolist[cweb][section=\CWEBsecno,title={#3},depth=#1]%
668   \ifon
669     \startsection
670     \pagereference[web:#2]%
671     \marking[CWEBsectiontitle] {#3}%
672     \expanded{\marking[CWEBsectionnumber]{\CWEBsecno}}%
673     \expanded{\marking[CWEBsectiondepth]{\the\CWEBgdepth}}%
674     {\bf#3.\quad}%
675     \ignorespaces}
676
677\newif\iflinktoCWEBfile
678
679\def\setCWEBlinkfile#1%
680  {\linktoCWEBfiletrue
681   \def\otherCWEBfile{#1}}
682
683\unprotect
684
685\unexpanded\def\gotoCWEBsection#1[#2]%
686  {\iflinktoCWEBfile
687     \bgroup
688       \setupinteraction[\c!color=,\c!style=]%
689       \let\savedreferenceprefix=\referenceprefix
690       \goto{#1}[\otherCWEBfile::\savedreferenceprefix web:#2]%
691     \egroup
692   \else
693     #1%
694   \fi}
695
696\protect
697
698\unexpanded\def\ignoreCWEBinput
699  {\def\input ##1 {\let\input\normalinput}}
700
701\unexpanded\def\loadCWEBmacros#1%
702  {\let\oldN=\N
703   \def\N{\bgroup\setbox0=\vbox\bgroup\endinput}%
704   \ignoreCWEBinput
705   \ReadFile{#1.tex}%
706   \egroup\egroup
707   \let\N=\oldN}
708
709\unexpanded\def\resetCWEBcontext
710  {\catcode`\|=\othercatcode % used in context discretionaries
711   \everypar   \emptytoks    % used for context indentation and floats
712   \parskip    \zeropoint    % no stretch between cweb paragraphs
713   \parindent  \emwidth}     % is related to cweb backspace etc
714
715\unexpanded\def\processCWEBsource #1 %
716  {\bgroup
717   \resetCWEBcontext
718   \activateCWEB
719   \ignoreCWEBinput
720   \let\end\relax
721   \marking[CWEBfilename]{#1}
722   \ReadFile{#1.tex}\relax
723   \par
724   \egroup}
725
726\unexpanded\def\resetCWEBindexentry
727  {\xdef\currentCWEBindexentry{}}
728
729\unexpanded\def\showCWEBindexentry#1% can be redefined
730  {\theCWEBvskip
731   \vskip3\lineheight
732   \goodbreak
733   \vskip-3\lineheight
734   {\pagereference[web:#1]\bf#1}%
735   \theCWEBvskip}
736
737
738    \def\dodofindfirstcharacter#1%
739      {\ifx#1\relax
740         \let\next=\egroup
741       \else
742         \handlecase
743           {\expandafter\ifnum\expandafter\catcode\expandafter`#1=11
744            \def\next##1\relax{\egroup\def\firstcharacter{#1}}%
745         \fi}%
746       \fi
747       \next}
748
749    \def\dofindfirstcharacter#1#2%
750      {\def\firstcharacter{}%
751       \bgroup
752       \defconvertedargument\ascii{#2}%
753       \let\next\dodofindfirstcharacter
754       \let\handlecase#1%
755       \expandafter\next\ascii\relax}
756
757    \def\FINDFIRSTCHARACTER
758      {\dofindfirstcharacter\uppercase}
759
760
761
762\unexpanded\def\checkCWEBindexentry#1%
763  {\bgroup
764   \def\\##1{##1}%  a dummy that also removes the {}
765   \def\|##1{##1}%  another dummy
766   \def\.##1{*##1}% and another (the typewriter one)
767   \def\&##1{##1}%  and a last one
768   \def\9##1{##1}%  hold this one
769   \catcode`*=11
770   \expandafter\def\expandafter\entry\expandafter{#1}%
771   \defconvertedcommand\ascii\entry
772   \expanded{\FINDFIRSTCHARACTER{\ascii}}%
773   \doifnot{\currentCWEBindexentry}{\firstcharacter}
774     {\doifnot{\firstcharacter}{*} % signal for \firstbunch
775        {\global\let\currentCWEBindexentry=\firstcharacter
776         \showCWEBindexentry{\currentCWEBindexentry}}}%
777   \egroup}
778
779\unexpanded\def\theCWEBbeforeindex {\startcolumns}
780\unexpanded\def\theCWEBafterindex  {\stopcolumns}
781
782\unexpanded\def\processCWEBindex #1 %
783  {\par
784   \bgroup
785   \forgetall
786   \setupalign[verytolerant,flushleft,nothyphenated]
787   \resetCWEBcontext
788   \activateCWEB
789   \resetCWEBindexentry
790   \def\I##1, %
791     {\par
792      \checkCWEBindexentry{##1}%
793      \hangindent2em
794      \noindent##1:\kern1em%
795      \def\next####1.{\processCWEBsectionnumbers[{####1}]}%
796      \next}%
797   \def\[##1]%
798     {$\underline{##1}$}%
799   \let\*=\lapstar
800   \marking[CWEBfilename]{#1}
801   \marking[CWEBsectiontitle]{index}
802   \marking[CWEBsectionnumber]{}
803   \marking[CWEBsectiondepth]{}
804%    \loadCWEBmacros{#1}
805   \theCWEBbeforeindex
806   \ReadFile{#1.idx}\relax
807   \theCWEBafterindex
808   \par
809   \egroup}
810
811\unexpanded\def\processCWEBsections #1 %
812  {\par
813   \bgroup
814   \forgetall
815   \resetCWEBcontext
816   \activateCWEB
817 % \loadCWEBmacros{#1}
818   \parfillskip = 0pt plus 1fil
819   \parindent   = 0pt
820   \let\topsecno=\nullsec
821   \def\note##1%
822     {\quad
823      \bgroup
824      \tx
825      ##1~\processCWEBsectionnotes}
826   \def\Q {\CWEBnotesfalse \note{Cited in section}}  % crossref for mention of a section
827   \def\Qs{\CWEBnotestrue  \note{Cited in sections}} % crossref for mentions of a section
828   \def\U {\CWEBnotesfalse \note{Used in section}}   % crossref for use of a section
829   \def\Us{\CWEBnotestrue  \note{Used in sections}}  % crossref for uses of a section
830   \def\I {\par\hangindent 2em}%
831   \let\*=*
832   \marking[CWEBfilename]{#1}
833   \marking[CWEBsectiontitle]{sections}
834   \marking[CWEBsectionnumber]{}
835   \marking[CWEBsectiondepth]{}
836%    \loadCWEBmacros{#1}
837   \ReadFile{#1.scn}\relax
838   \botofcontents
839   \par
840   \egroup}
841
842\unexpanded\def\processCWEBcontents #1 %
843  {\par
844   \bgroup
845   \forgetall
846   \resetCWEBcontext
847   \activateCWEB
848   \marking[CWEBfilename]{#1}
849   \marking[CWEBsectiontitle]{table of contents}
850   \marking[CWEBsectionnumber]{}
851   \marking[CWEBsectiondepth]{}
852   \forgetall
853   \placelist[cweb][criterium=all,command=\CWEBlistentry]
854   \par
855   \egroup}
856
857% {all}
858%
859% \structurelistuservariable
860% \rawstructurelistuservariable
861%
862% \goto{#3}[web:#3]
863
864\installstructurelistprocessor{cweb}
865  {\begingroup
866   \advance\leftskip 3em
867   \advance\rightskip3em
868   \currentlistentrydestinationattribute
869   \dontleavehmode
870   \llap{\hbox \currentlistentryreferenceattribute{number} to 3em{\structurelistuservariable{section}\hss}}%
871   \structurelistuservariable{title}%
872   \hfill
873   \rlap{\hbox \currentlistentryreferenceattribute{page}   to 3em{\hss\structurelistuservariable{depth}}}%
874   \par
875   \endgroup}
876
877\endinput
878