Debian Codegraph @

texk/web2c/cwebdir/ctwill-w2c.ch

raw
1 @q Changes for CWEB in TeX Live from numerous contributors. @>
2 @q This file is in the Public Domain. @>
3
4 @q Most of the original Kpathsea changes by Wlodek Bzyl and Olaf Weber @>
5 @q were merged with the set of change files of the CWEBbin project; @>
6 @q see https://github.com/ascherer/cwebbin for the original parts. @>
7
8 @q This stripped change file {comm,ctang,cweav,ctwill,cwebman}-w2c.ch @>
9 @q has been created from the elaborate set of change files @>
10 @q {comm,ctang,cweav,cwebman}-patch.ch, @>
11 @q {comm,cweav,cwebman}-extensions.ch, {comm,ctang,cweav}-output.ch, @>
12 @q {comm,ctang,cweav}-i18n.ch, and cweav-twill.ch for CTWILL, and @>
13 @q {comm,ctang,cweav,ctwill,cwebman}-texlive.ch with the 'tie' processor @>
14 @q and is used as a monolithic changefile for {common,ctangle,cweave}.w @>
15 @q and cwebman.tex in TeX Live. @>
16
17 @q Please send comments, suggestions, etc. to tex-k@@tug.org. @>
18
19 @x [0.0] l.1
20 % This file is part of CWEB.
21 % This program by Silvio Levy and Donald E. Knuth
22 % is based on a program by Knuth.
23 % It is distributed WITHOUT ANY WARRANTY, express or implied.
24 @y
25 % This program by Don Knuth is based on CWEAVE by Levy and Knuth.
26 % It's somewhat flaky, so you probably shouldn't try to use it.
27 @z
28
29 @x [0.0] l.23
30 % Here is TeX material that gets inserted after \input cwebmac
31 @y
32 % Here is TeX material that gets inserted after \input ctwimac
33 \def\contentspagenumber{0} % default page number for table of contents
34 \datethis % Put timestamp before section 1
35 @z
36
37 @x [0.0] l.34
38 \def\title{CWEAVE (Version 4.12.2)}
39 @y
40 \def\Kpathsea/{{\mc KPATHSEA\spacefactor1000}} \ifacro\sanitizecommand\Kpathsea{KPATHSEA}\fi
41 \def\title{CTWILL (Version 4.12.2 [\TeX~Live])}
42 @z
43
44 @x [0.0] l.36
45 \centerline{\titlefont The {\ttitlefont CWEAVE} processor}
46 @y
47 \centerline{\titlefont The {\ttitlefont CTWILL} processor}
48 @z
49
50 @x [0.0] l.38
51 \centerline{(Version 4.12.2)}
52 @y
53 \centerline{(Version 4.12.2 [\TeX~Live])}
54 @z
55
56 @x [0.0] l.40
57 \def\botofcontents{\vfill
58 @y
59 \def\covernote{\vbox{%
60 @z
61
62 @x [0.0] l.53
63 }
64 @y
65 }}
66 @z
67
68 @x [1.1] l.58
69 This is the \.{CWEAVE} program by Silvio Levy and Donald E. Knuth,
70 based on \.{WEAVE} by Knuth.
71 We are thankful to Steve Avery,
72 Nelson Beebe, Hans-Hermann Bode (to whom the original \CPLUSPLUS/ adaptation
73 is due), Klaus Guntermann, Norman Ramsey, Tomas Rokicki, Joachim Schnitter,
74 Joachim Schrod, Lee Wittenberg, Saroj Mahapatra, Cesar Augusto Rorato
75 Crusius, and others who have contributed improvements.
76
77 The ``banner line'' defined here should be changed whenever \.{CWEAVE}
78 is modified.
79
80 @d banner "This is CWEAVE (Version 4.12.2)"
81 @y
82 This is the \.{CTWILL} program by D. E. Knuth, based
83 on \.{CWEAVE} by Silvio Levy and D.~E. Knuth. It is also based on
84 \.{TWILL}, a private \.{WEB} program that Knuth wrote to produce
85 Volumes B and~D of {\sl Computers {\char`\&} Typesetting\/} in 1985.
86 \.{CTWILL} was hacked together hastily in June, 1992, to generate pages for
87 Knuth's book about the Stanford GraphBase, and updated even more hastily
88 in March, 1993, to generate final copy for that book. The main idea was to
89 extend \.{CWEAVE} so that ``mini-indexes'' could appear.
90 No time was available to make \.{CTWILL} into a refined or complete system,
91 nor even to fully update the program documentation below. Subsequent changes
92 were made only to maintain compatibility with \.{CWEAVE}. Further information
93 can be found in Knuth's article ``Mini-indexes for literate programs,''
94 reprinted in {\sl Digital Typography\/} (1999), 225--245.
95
96 A kind of ``user manual'' for \.{CTWILL} can be found in the appendix
97 \X270:Mogrify \.{CWEAVE} into \.{CTWILL}\X~and beyond, together with
98 additional material specific to \.{CTWILL}. % FIXME
99 Until then, \.{CWEAVE}'s sequence of sections will be preserved.
100
101 The ``banner line'' defined here should be changed whenever \.{CTWILL} is
102 modified. The version number parallels the corresponding version of \.{CWEAVE}.
103
104 @d banner "This is CTWILL, Version 4.12.2"
105 /* will be extended by the \TeX~Live |versionstring| */
106 @z
107
108 @x [1.2] l.93
109 program=cweave;
110 @y
111 program=ctwill;
112 @z
113
114 @x [1.2] l.97
115 if (show_banner) puts(banner); /* print a ``banner line'' */
116 @y
117 if (show_banner) cb_show_banner(); /* print a ``banner line'' */
118 @z
119
120 @x [1.3] l.111
121 @i common.h
122 @y
123 @i comm-w2c.h
124 @z
125
126 @x [2.21] l.182
127 turned on during the first phase.
128
129 @<Private...@>=
130 static bool change_exists; /* has any section changed? */
131 @y
132 turned on during the first phase---NOT!
133 @z
134
135 @x [2.23] l.216
136 @ @d max_refs 30000 /* number of cross-references; must be less than 65536 */
137 @y
138 @ @d max_refs 65535 /* number of cross-references; must be less than 65536 */
139 @z
140
141 @x [2.25] l.245
142 @d append_xref(c) if (xref_ptr==xmem_end) overflow("cross-reference");
143 @y
144 @d append_xref(c) if (xref_ptr==xmem_end) overflow(_("cross-reference"));
145 @z
146
147 @x [2.30] l.336
148 @d max_toks 30000 /* number of symbols in \CEE/ texts being parsed;
149 must be less than 65536 */
150 @d max_texts 8000 /* number of phrases in \CEE/ texts being parsed;
151 must be less than 10240 */
152 @y
153 @d max_toks 65535 /* number of symbols in \CEE/ texts being parsed;
154 must be less than 65536 */
155 @d max_texts 10239 /* number of phrases in \CEE/ texts being parsed;
156 must be less than 10240 */
157 @z
158
159 @x [2.32] l.356
160 @ Here are the two procedures needed to complete |id_lookup|:
161 @y
162 @ Here are the two procedures needed to complete |id_lookup|:
163 @s perm_meaning int
164 @z
165
166 @x [2.32] l.373
167 p->xref=(void *)xmem;
168 @y
169 p->xref=(void *)xmem;
170 if (p!=name_dir) {
171 struct perm_meaning *q=get_meaning(p);
172 q->stamp=0;
173 q->link=NULL;
174 q->perm.id=p;
175 q->perm.prog_no=q->perm.sec_no=0;
176 strcpy(q->perm.tex_part,"\\uninitialized");
177 }
178 @z
179
180 @x [2.33] l.376
181 @ And here's a small helper function to simplify the code.
182
183 @d update_node(p) (p)->xref=(void *)xref_ptr
184 @y
185 @ And here are two small helper functions to simplify the code.
186
187 @d update_node(p) (p)->xref=(void *)xref_ptr
188 @d get_meaning(p) (p)-name_dir+cur_meaning
189 @z
190
191 @x [2.34] l.435
192 id_lookup("extern",NULL,int_like);
193 @y
194 @#
195 ext_loc=id_lookup("extern",NULL,int_like)-name_dir;
196 @#
197 @z
198
199 @x [2.34] l.448
200 id_lookup("int",NULL,raw_int);
201 @y
202 @#
203 int_loc=id_lookup("int",NULL,raw_int)-name_dir;
204 @#
205 @z
206
207 @x [3.36] l.543
208 @d ord 0207 /* control code for `\.{@@'}' */
209 @d join 0210 /* control code for `\.{@@\&}' */
210 @d thin_space 0211 /* control code for `\.{@@,}' */
211 @d math_break 0212 /* control code for `\.{@@\v}' */
212 @d line_break 0213 /* control code for `\.{@@/}' */
213 @d big_line_break 0214 /* control code for `\.{@@\#}' */
214 @d no_line_break 0215 /* control code for `\.{@@+}' */
215 @d pseudo_semi 0216 /* control code for `\.{@@;}' */
216 @d macro_arg_open 0220 /* control code for `\.{@@[}' */
217 @d macro_arg_close 0221 /* control code for `\.{@@]}' */
218 @d trace 0222 /* control code for `\.{@@0}', `\.{@@1}' and `\.{@@2}' */
219 @d translit_code 0223 /* control code for `\.{@@l}' */
220 @d output_defs_code 0224 /* control code for `\.{@@h}' */
221 @d format_code 0225 /* control code for `\.{@@f}' and `\.{@@s}' */
222 @d definition 0226 /* control code for `\.{@@d}' */
223 @d begin_C 0227 /* control code for `\.{@@c}' */
224 @d section_name 0230 /* control code for `\.{@@<}' */
225 @d new_section 0231 /* control code for `\.{@@\ }' and `\.{@@*}' */
226 @y
227 @d meaning 0207 /* control code for `\.{@@\$}' */
228 @d suppress 0210 /* control code for `\.{@@-}' */
229 @d temp_meaning 0211 /* control code for `\.{@@\%}' */
230 @d right_start 0212 /* control code for `\.{@@r}' */
231 @d ord 0213 /* control code for `\.{@@'}' */
232 @d join 0214 /* control code for `\.{@@\&}' */
233 @d thin_space 0215 /* control code for `\.{@@,}' */
234 @d math_break 0216 /* control code for `\.{@@\v}' */
235 @d line_break 0217 /* control code for `\.{@@/}' */
236 @d big_line_break 0220 /* control code for `\.{@@\#}' */
237 @d no_line_break 0221 /* control code for `\.{@@+}' */
238 @d pseudo_semi 0222 /* control code for `\.{@@;}' */
239 @d macro_arg_open 0224 /* control code for `\.{@@[}' */
240 @d macro_arg_close 0225 /* control code for `\.{@@]}' */
241 @d trace 0226 /* control code for `\.{@@0}', `\.{@@1}' and `\.{@@2}' */
242 @d translit_code 0227 /* control code for `\.{@@l}' */
243 @d output_defs_code 0230 /* control code for `\.{@@h}' */
244 @d format_code 0231 /* control code for `\.{@@f}' and `\.{@@s}' */
245 @d definition 0232 /* control code for `\.{@@d}' */
246 @d begin_C 0233 /* control code for `\.{@@c}' */
247 @d section_name 0234 /* control code for `\.{@@<}' */
248 @d new_section 0235 /* control code for `\.{@@\ }' and `\.{@@*}' */
249 @z
250
251 @x [3.38] l.586
252 ccode['\'']=ord;
253 @y
254 ccode['\'']=ord;
255 ccode['$']=meaning; ccode['%']=temp_meaning; ccode['-']=suppress;
256 ccode['r']=ccode['R']=right_start;
257 @z
258
259 @x [3.40] l.607
260 static eight_bits skip_TeX(void);
261
262 @ @c
263 @y
264 static eight_bits skip_TeX(void);
265
266 @ We look for a clue about the program's title, because this will become
267 part of all meanings.
268
269 @c
270 @z
271
272 @x [3.41] l.613
273 if (loc>limit && get_line()==false) return;
274 @y
275 if (loc>limit && get_line()==false) return;
276 if (loc==buffer && strncmp(buffer,"\\def\\title{",11)==0) {
277 loc=buffer+10;
278 title_lookup(); /* this program's title will be code zero */
279 }
280 @z
281
282 @x [4.43] l.669
283 \yskip\hang |xref_roman|, |xref_wildcard|, |xref_typewriter|, |TeX_string|,
284 @y
285 \yskip\hang |xref_roman|, |xref_wildcard|, |xref_typewriter|, |TeX_string|,
286 |meaning|, |suppress|,
287 @z
288
289 @x [4.46] l.730
290 @d right_preproc 0217 /* ends a preprocessor command */
291 @y
292 @d right_preproc 0223 /* ends a preprocessor command */
293 @z
294
295 @x [4.57] l.887
296 err_print("! String didn't end"); loc=limit; break;
297 @y
298 err_print(_("! String didn't end")); loc=limit; break;
299 @z
300
301 @x [4.57] l.891
302 err_print("! Input ended in middle of string"); loc=buffer; break;
303 @y
304 err_print(_("! Input ended in middle of string")); loc=buffer; break;
305 @z
306
307 @x [4.57] l.910
308 printf("%s","\n! String too long: ");
309 @y
310 printf("%s",_("\n! String too long: "));
311 @z
312
313 @x [4.59] l.929
314 case translit_code: err_print("! Use @@l in limbo only"); continue;
315 @y
316 case translit_code: err_print(_("! Use @@l in limbo only")); continue;
317 @z
318
319 @x [4.59] l.931
320 case underline: xref_switch=def_flag; continue;
321 @y
322 case underline: xref_switch=def_flag; continue;
323 case temp_meaning: temp_switch=!temp_switch; continue;
324 case right_start: right_start_switch=true; continue;
325 @z
326
327 @x [4.59] l.937
328 case xref_roman: case xref_wildcard: case xref_typewriter: case noop:
329 @y
330 case xref_roman: case xref_wildcard: case xref_typewriter: case noop:
331 case meaning: case suppress:
332 @z
333
334 @x [4.62] l.967
335 err_print("! Input ended in section name");
336 @y
337 err_print(_("! Input ended in section name"));
338 @z
339
340 @x [4.62] l.980
341 printf("%s","\n! Section name too long: ");
342 @y
343 printf("%s",_("\n! Section name too long: "));
344 @z
345
346 @x [4.63] l.994
347 err_print("! Section name didn't end"); break;
348 @y
349 err_print(_("! Section name didn't end")); break;
350 @z
351
352 @x [4.63] l.998
353 err_print("! Control codes are forbidden in section name"); break;
354 @y
355 err_print(_("! Control codes are forbidden in section name")); break;
356 @z
357
358 @x [4.64] l.1008
359 skip_restricted(void)
360 {
361 @y
362 skip_restricted(void)
363 { int c=ccode[(eight_bits)*(loc-1)];
364 @z
365
366 @x [4.64] l.1015
367 err_print("! Control text didn't end"); loc=limit;
368 @y
369 err_print(_("! Control text didn't end")); loc=limit;
370 @z
371
372 @x [4.64] l.1020
373 err_print("! Control codes are forbidden in control text");
374 @y
375 err_print(_("! Control codes are forbidden in control text"));
376 @z
377
378 @x [4.64] l.1021
379 @.Control codes are forbidden...@>
380 @y
381 @.Control codes are forbidden...@>
382 if (c==meaning && phase==2) @<Process a user-generated meaning@>@;
383 else if (c==suppress && phase==2) @<Suppress mini-index entry@>@;
384 @z
385
386 @x [4.66] l.1035
387 if (loc>=limit) err_print("! Verbatim string didn't end");
388 @y
389 if (loc>=limit) err_print(_("! Verbatim string didn't end"));
390 @z
391
392 @x [5.68] l.1060
393 skip_limbo(); change_exists=false;
394 @y
395 skip_limbo();
396 @<Give a default title to the program, if necessary@>@;
397 @z
398
399 @x [5.68] l.1063
400 changed_section[section_count]=change_exists;
401 /* the index changes if anything does */
402 @y
403 @z
404
405 @x [5.70] l.1072
406 if (++section_count==max_sections) overflow("section number");
407 @y
408 if (++section_count==max_sections) overflow(_("section number"));
409 @z
410
411 @x [5.70] l.1073
412 changed_section[section_count]=changing;
413 /* it will become |true| if any line changes */
414 @y
415 @z
416
417 @x [5.70] l.1082
418 if (changed_section[section_count]) change_exists=true;
419 @y
420 @z
421
422 @x [5.74] l.1161
423 case translit_code: err_print("! Use @@l in limbo only"); continue;
424 @y
425 case translit_code: err_print(_("! Use @@l in limbo only")); continue;
426 @z
427
428 @x [5.74] l.1166
429 case xref_roman: case xref_wildcard: case xref_typewriter:
430 @y
431 case xref_roman: case xref_wildcard: case xref_typewriter:
432 case meaning: case suppress:
433 @z
434
435 @x [5.79] l.1248
436 err_print("! Missing left identifier of @@s");
437 @y
438 err_print(_("! Missing left identifier of @@s"));
439 @z
440
441 @x [5.79] l.1253
442 err_print("! Missing right identifier of @@s");
443 @y
444 err_print(_("! Missing right identifier of @@s"));
445 @z
446
447 @x [5.82] l.1301
448 printf("%s","\n! Never defined: <");
449 print_section_name(p); putchar('>'); mark_harmless();
450 @y
451 printf("%s",_("\n! Never defined: <"));
452 print_section_name(p); putchar('>'); mark_harmless();
453 @z
454
455 @x [5.82] l.1307
456 printf("%s","\n! Never used: <");
457 print_section_name(p); putchar('>'); mark_harmless();
458 @y
459 printf("%s",_("\n! Never used: <"));
460 print_section_name(p); putchar('>'); mark_harmless();
461 @z
462
463 @x [6.89] l.1396
464 @ In particular, the |finish_line| procedure is called near the very
465 beginning of phase two. We initialize the output variables in a slightly
466 tricky way so that the first line of the output file will be
467 `\.{\\input cwebmac}'.
468
469 @<Start \9{t}\TEX/...@>=
470 out_ptr=out_buf+1; out_line=1; active_file=tex_file;
471 tex_printf("\\input cwebma"); *out_ptr='c';
472 @y
473 @ In particular, the |finish_line| procedure is called near the very
474 beginning of phase two. We initialize the output variables in a slightly
475 tricky way so that the first line of the output file will be dependent of
476 the user language set by the `\.{+l}' option and its argument. If you call
477 \.{CTWILL} with `\.{+lX}' (or `\.{-lX}' as well), where `\.X' is the
478 (possibly empty) string of characters to the right of~`\.l', `\.X'~will
479 be prepended to `\.{ctwimac.tex}', e.g., if you call \.{CTWILL} with
480 `\.{+ldeutsch}', you will receive the line `\.{\\input deutschctwimac}'.
481 Without this option the first line of the output file will be
482 `\.{\\input ctwimac}'. Or, if the user has specified proofing by
483 saying \.{+P} on the command line, it's `\.{\\input ctproofmac}' (resp.\
484 \.{\\input Xctproofmac} with option \.{+lX}), a set of macros used when
485 debugging mini-index entries.
486
487 @d proofing flags['P']
488
489 @<Start \9{t}\TEX/...@>=
490 out_ptr=out_buf+1; out_line=1; active_file=tex_file;
491 tex_puts("\\input ");
492 tex_printf(use_language);
493 tex_puts(proofing?"ctproofma":"ctwima");
494 *out_ptr='c';
495 @z
496
497 @x [6.90] l.1413
498 @d out(c) {if (out_ptr>=out_buf_end) break_out(); *(++out_ptr)=c;}
499 @y
500 @d out(c)
501 {if (ms_mode) { /* outputting to |ministring_buf| */
502 if (ministring_ptr<ministring_buf_end)
503 *ministring_ptr++=c;
504 } else {
505 if (out_ptr>=out_buf_end) break_out();
506 *(++out_ptr)=c;
507 }
508 }
509 @z
510
511 @x [6.94] l.1461
512 printf("\n! Line had to be broken (output l. %d):\n",out_line);
513 @y
514 printf(_("\n! Line had to be broken (output l. %d):\n"),out_line);
515 @z
516
517 @x [6.95] l.1470
518 |def_flag|, so it cannot have more than five decimal digits. If
519 the section is changed, we output `\.{\\*}' just after the number.
520 @y
521 |def_flag|, so it cannot have more than five decimal digits.
522 @z
523
524 @x [6.96] l.1484
525 if (changed_section[n]) out_str("\\*");
526 @.\\*@>
527 @y
528 @z
529
530 @x [7.99] l.1542
531 default: err_print("! Double @@ should be used in limbo");
532 @y
533 case right_start: right_start_switch=true; break;
534 default: err_print(_("! Double @@ should be used in limbo"));
535 @z
536
537 @x [7.101] l.1584
538 @d app_tok(c) {if (tok_ptr+2>tok_mem_end) overflow("token"); *(tok_ptr++)=c;}
539 @y
540 @d app_tok(c) {if (tok_ptr+2>tok_mem_end) overflow(_("token")); *(tok_ptr++)=c;}
541 @z
542
543 @x [7.101] l.1596
544 err_print("! Input ended in mid-comment");
545 @y
546 err_print(_("! Input ended in mid-comment"));
547 @z
548
549 @x [7.101] l.1601
550 if (bal>1) err_print("! Missing } in comment");
551 @y
552 if (bal>1) err_print(_("! Missing } in comment"));
553 @z
554
555 @x [7.101] l.1617
556 else {err_print("! Extra } in comment");
557 @y
558 else {err_print(_("! Extra } in comment"));
559 @z
560
561 @x [7.102] l.1629
562 if (bal>1) err_print("! Missing } in comment");
563 @y
564 if (bal>1) err_print(_("! Missing } in comment"));
565 @z
566
567 @x [7.103] l.1637
568 err_print("! Illegal use of @@ in comment");
569 @y
570 err_print(_("! Illegal use of @@ in comment"));
571 @z
572
573 @x [8.106] l.1754
574 @d attr_head 69 /* denotes beginning of attribute */
575 @y
576 @d attr_head 69 /* denotes beginning of attribute */
577 @d title 70 /* program name or header name in a ``meaning'' */
578 @z
579
580 @x [8.110] l.2128
581 @i prod.w
582 @y
583 @i prod-twill.w
584 @z
585
586 @x [9.113] l.2178
587 static scrap scrap_info[max_scraps]; /* memory array for scraps */
588 @y
589 static scrap scrap_info[max_scraps]; /* memory array for scraps */
590 static scrap null_scrap; /* a scrap with empty translation */
591 @z
592
593 @x [9.114] l.2187
594 @ @<Set init...@>=
595 @y
596 @ @<Set init...@>=
597 null_scrap.trans=&tok_start[0];
598 @z
599
600 @x [9.116] l.2248
601 update_terminal();
602 @y
603 puts("|"); update_terminal();
604 @z
605
606 @x [9.124] l.2559
607 the |for| loop below.
608
609 @c
610 @y
611 the |for| loop below.
612
613 We use the fact that |make_underlined| has been called immediately preceding
614 |make_reserved|, hence |tok_loc| has been set.
615
616 @c
617 static token_pointer tok_loc; /* where the first identifier appears */
618 @#
619 @z
620
621 @x [9.124] l.2567
622 token_pointer tok_loc; /* pointer to |tok_value| */
623 if ((tok_loc=find_first_ident(p->trans))<=operator_found)
624 return; /* this should not happen */
625 @y
626 if (tok_loc<=operator_found) return; /* this should not happen */
627 @z
628
629 @x [9.125] l.2596
630 token_pointer tok_loc; /* where the first identifier appears */
631 @y
632 @z
633
634 @x [9.128] l.2650
635 @<Cases for |exp|@>=
636 if (cat1==lbrace || cat1==int_like || cat1==decl) {
637 make_underlined(pp); big_app(dindent); big_app1(pp);
638 reduce(pp,1,fn_decl,0,1);
639 }
640 @y
641 @<Cases for |exp|@>=
642 if(cat1==lbrace || cat1==int_like || cat1==decl) {
643 make_underlined(pp); make_ministring(pp);
644 if (indent_param_decl) big_app(dindent); big_app1(pp);
645 reduce(pp,1,fn_decl,0,1);
646 }
647 @z
648
649 @x [9.128] l.2665
650 make_underlined (pp); squash(pp,2,tag,-1,7);
651 @y
652 make_underlined (pp);
653 if (tok_loc>operator_found) {
654 strcpy(ministring_buf,"label");
655 new_meaning(((*tok_loc)%id_flag)+name_dir);
656 }
657 squash(pp,2,tag,-1,7);
658 @z
659
660 @x [9.138] l.2754
661 @ @<Cases for |decl_head|@>=
662 if (cat1==comma) {
663 big_app2(pp); app(opt); app('9'); reduce(pp,2,decl_head,-1,33);
664 }
665 else if (cat1==ubinop) {
666 big_app1_insert(pp,'{'); big_app('}'); reduce(pp,2,decl_head,-1,34);
667 }
668 else if (cat1==exp && cat2!=lpar && cat2!=lbrack && cat2!=exp && cat2!=cast) {
669 make_underlined(pp+1); squash(pp,2,decl_head,-1,35);
670 }
671 else if ((cat1==binop||cat1==colon) && cat2==exp && (cat3==comma ||
672 cat3==semi || cat3==rpar))
673 squash(pp,3,decl_head,-1,36);
674 else if (cat1==cast) squash(pp,2,decl_head,-1,37);
675 else if (cat1==int_like || cat1==lbrace || cat1==decl) {
676 big_app(dindent); squash(pp,1,fn_decl,0,38);
677 }
678 else if (cat1==semi) squash(pp,2,decl,-1,39);
679 @y
680 @ @<Cases for |decl_head|@>=
681 if (cat1==comma) {
682 big_app2(pp); app(opt); app('9'); reduce(pp,2,decl_head,-1,33);
683 }
684 else if (cat1==ubinop) {
685 big_app1_insert(pp,'{'); big_app('}');
686 reduce(pp,2,decl_head,-1,34);
687 }
688 else if (cat1==exp && cat2!=lpar && cat2!=lbrack && cat2!=exp && cat2!=cast) {
689 make_underlined(pp+1); make_ministring(pp+1);
690 squash(pp,2,decl_head,-1,35);
691 }
692 else if ((cat1==binop||cat1==colon) && cat2==exp && (cat3==comma ||
693 cat3==semi || cat3==rpar))
694 squash(pp,3,decl_head,-1,36);
695 else if (cat1==cast) squash(pp,2,decl_head,-1,37);
696 else if (cat1==int_like || cat1==lbrace || cat1==decl) {
697 if (indent_param_decl) big_app(dindent);
698 squash(pp,1,fn_decl,0,38);
699 }
700 else if (cat1==semi) squash(pp,2,decl,-1,39);
701 @z
702
703 @x [9.139] l.2776
704 @ @<Cases for |decl|@>=
705 if (cat1==decl) {
706 big_app1_insert(pp,force); reduce(pp,2,decl,-1,40);
707 }
708 else if (cat1==stmt || cat1==function) {
709 big_app1_insert(pp,big_force); reduce(pp,2,cat1,-1,41);
710 }
711 @y
712 @ @<Cases for |decl|@>=
713 if (cat1==decl) {
714 big_app1_insert(pp,force); reduce(pp,2,decl,-1,40);
715 }
716 else if (cat1==stmt || cat1==function) {
717 big_app1_insert(pp,order_decl_stmt ? big_force : force);
718 reduce(pp,2,cat1,-1,41);
719 }
720 @z
721
722 @x [9.141] l.2802
723 make_underlined(pp+1); make_reserved(pp+1);
724 @y
725 make_underlined(pp+1); make_reserved(pp+1); make_ministring(pp+1);
726 @z
727
728 @x [9.143] l.2833
729 @ @<Cases for |fn_decl|@>=
730 if (cat1==decl) {
731 big_app1_insert(pp,force); reduce(pp,2,fn_decl,0,51);
732 }
733 else if (cat1==stmt) {
734 big_app1(pp); app(outdent); app(outdent); big_app(force);
735 big_app1(pp+1); reduce(pp,2,function,-1,52);
736 }
737 @y
738 @ @<Cases for |fn_decl|@>=
739 if (cat1==decl) {
740 big_app1_insert(pp,force); reduce(pp,2,fn_decl,0,51);
741 }
742 else if (cat1==stmt) {
743 big_app1(pp);
744 if (indent_param_decl) {
745 app(outdent); app(outdent);
746 }
747 big_app(force); big_app1(pp+1); reduce(pp,2,function,-1,52);
748 }
749 @z
750
751 @x [9.153] l.2937
752 big_app1_insert(pp,dindent); reduce(pp,2,fn_decl,0,73);
753 @y
754 big_app1(pp); if (indent_param_decl) big_app(dindent);
755 big_app1(pp+1); reduce(pp,2,fn_decl,0,73);
756 @z
757
758 @x [9.156] l.2963
759 big_app1_insert(pp, (cat1==decl || cat1==function) ? big_force :
760 force_lines ? force : break_space); reduce(pp,2,cat1,-1,76);
761 @y
762 big_app1_insert(pp, (cat1==decl || cat1==function) ? @|
763 ( order_decl_stmt ? big_force : force ) : @|
764 ( force_lines ? force : break_space ) ); reduce(pp,2,cat1,-1,76);
765 @z
766
767 @x [9.158] l.2971
768 if (cat1==define_like) make_underlined(pp+2);
769 @y
770 if (cat1==define_like) { /* \#\&{define} is analogous to \&{extern} */
771 make_underlined(pp+2);
772 if (tok_loc>operator_found) {
773 /* no time to work out this case; I'll handle \&{define}s by brute force
774 in the \.{aux} file, since they usually don't go in mini-index */
775 }
776 }
777 @z
778
779 @x [9.167] l.3068
780 if (cat1==prelangle) reduce(pp+1,0,langle,1,100);
781 else reduce(pp,0,exp,-2,101);
782 @y
783 if (cat1==prelangle) reduce(pp+1,0,langle,1,121);
784 else reduce(pp,0,exp,-2,122);
785 @z
786
787 @x [9.168] l.3073
788 big_app1_insert(pp,' '); reduce(pp,2,else_like,-2,102);
789 @y
790 big_app1_insert(pp,' '); reduce(pp,2,else_like,-2,123);
791 @z
792
793 @x [9.173] l.3105
794 @ @<Cases for |typedef_like|@>=
795 if ((cat1==int_like || cat1==cast) && (cat2==comma || cat2==semi))
796 reduce(pp+1,0,exp,-1,115);
797 else if (cat1==int_like) {
798 big_app1_insert(pp,' '); reduce(pp,2,typedef_like,0,116);
799 }
800 else if (cat1==exp && cat2!=lpar && cat2!=lbrack && cat2!=exp && cat2!=cast) {
801 make_underlined(pp+1); make_reserved(pp+1);
802 big_app1_insert(pp,' '); reduce(pp,2,typedef_like,0,117);
803 }
804 else if (cat1==comma) squash(pp,2,typedef_like,0,118);
805 else if (cat1==semi) squash(pp,2,decl,-1,119);
806 else if (cat1==ubinop && (cat2==ubinop || cat2==cast)) {
807 big_app('{'); big_app1_insert(pp+1,'}'); reduce(pp+1,2,cat2,0,120);
808 }
809 @y
810 @ Here \.{CTWILL} deviates from the normal productions introduced in
811 version 3.6, because those productions bypass |decl_head| (thereby
812 confusing |make_ministring|, which depends on the |decl_head| productions
813 to deduce the type). We revert to an older syntax that was
814 less friendly to \CPLUSPLUS/ but good enough for me.@^system dependencies@>
815
816 @<Cases for |typedef_like|@>=
817 if (cat1==decl_head) {
818 if ((cat2==exp&&cat3!=lpar&&cat3!=exp)||cat2==int_like) {
819 make_underlined(pp+2); make_reserved(pp+2); make_ministring(pp+2);
820 squash(pp+1,2,decl_head,0,200);
821 }
822 else if (cat2==semi) {
823 big_app1(pp); big_app(' '); big_app2(pp+1); reduce(pp,3,decl,-1,201);
824 }
825 } else if (cat1==int_like && cat2==raw_int &&
826 (cat3==semi || cat3==comma)) reduce(pp+2,0,exp,1,202);
827 @z
828
829 @x [9.186] l.3292
830 overflow("token");
831 @y
832 overflow(_("token"));
833 @z
834
835 @x [9.186] l.3296
836 overflow("text");
837 @y
838 overflow(_("text"));
839 @z
840
841 @x [9.190] l.3351
842 if (tok_ptr+6>tok_mem_end) overflow("token");
843 @y
844 if (tok_ptr+6>tok_mem_end) overflow(_("token"));
845 @z
846
847 @x [9.191] l.3357
848 printf("\nIrreducible scrap sequence in section %d:",(int)section_count);
849 @y
850 printf(_("\nIrreducible scrap sequence in section %d:"),(int)section_count);
851 @z
852
853 @x [9.192] l.3367
854 printf("\nTracing after l. %d:\n",cur_line); mark_harmless();
855 @y
856 printf(_("\nTracing after l. %d:\n"),cur_line); mark_harmless();
857 @z
858
859 @x [10.196] l.3453
860 case ignore: case xref_roman: case xref_wildcard:
861 @y
862 case ignore: case xref_roman: case xref_wildcard:
863 case meaning: case suppress:
864 @z
865
866 @x [10.197] l.3499
867 overflow("scrap/token/text");
868 @y
869 overflow(_("scrap/token/text"));
870 @z
871
872 @x [10.199] l.3584
873 else err_print("! Double @@ should be used in strings");
874 @y
875 else err_print(_("! Double @@ should be used in strings"));
876 @z
877
878 @x [10.202] l.3649
879 else app_scrap(p->ilk,maybe_math);
880 }
881 }
882 @y
883 else app_scrap(p->ilk,maybe_math);
884 }
885 }
886 @<Flag the usage of this identifier, for the mini-index@>@;
887 @z
888
889 @x [10.203] l.3667
890 if (next_control!='|') err_print("! Missing '|' after C text");
891 @y
892 if (next_control!='|') err_print(_("! Missing '|' after C text"));
893 @z
894
895 @x [10.204] l.3682
896 to \.{\\PB}. Although \.{cwebmac} ignores \.{\\PB}, other macro packages
897 @y
898 to \.{\\PB}. Although \.{ctwimac} ignores \.{\\PB}, other macro packages
899 @z
900
901 @x [10.205] l.3712
902 app(tok_flag+(int)(p-tok_start));
903 @y
904 app(tok_flag+(int)(p-tok_start));
905 app(inserted);
906 @z
907
908 @x [11.211] l.3808
909 if (stack_ptr==stack_end) overflow("stack");
910 @y
911 if (stack_ptr==stack_end) overflow(_("stack"));
912 @z
913
914 @x [11.224] l.4131
915 printf("%s","\n! Illegal control code in section name: <");
916 @y
917 printf("%s",_("\n! Illegal control code in section name: <"));
918 @z
919
920 @x [11.225] l.4146
921 printf("%s","\n! C text in section name didn't end: <");
922 @y
923 printf("%s",_("\n! C text in section name didn't end: <"));
924 @z
925
926 @x [11.225] l.4158
927 if (j>buffer+long_buf_size-3) overflow("buffer");
928 @y
929 if (j>buffer+long_buf_size-3) overflow(_("buffer"));
930 @z
931
932 @x [11.226] l.4166
933 if (j>buffer+long_buf_size-4) overflow("buffer");
934 @y
935 if (j>buffer+long_buf_size-4) overflow(_("buffer"));
936 @z
937
938 @x [12.227] l.4181
939 if (show_progress) printf("%s","\nWriting the output file...");
940 @y
941 if (show_progress) printf("%s",_("\nWriting the output file..."));
942 @z
943
944 @x [12.227] l.4183
945 section_count=0; format_visible=true; copy_limbo();
946 @y
947 temp_switch=false; temp_meaning_ptr=temp_meaning_stack;
948 @<Read the \.{.aux} file, if present; then open it for output@>@;
949 section_count=0; format_visible=true; right_start_switch=false; copy_limbo();
950 @z
951
952 @x [12.229] l.4212
953 static bool group_found=false; /* has a starred section occurred? */
954
955 @ @<Translate the \9{c}current section@>= {
956 section_count++;
957 @y
958 static bool group_found=false; /* has a starred section occurred? */
959 static bool right_start_switch; /* has `\.{@@r}' occurred recently? */
960 static bool temp_switch; /* has `\.{@@\%}' occurred recently? */
961
962 @ @d usage_sentinel (struct perm_meaning *)1
963 @<Translate the \9{c}current section@>= {
964 section_count++;
965 temp_switch=false; temp_meaning_ptr=temp_meaning_stack;
966 top_usage=usage_sentinel;
967 @z
968
969 @x [12.231] l.4230
970 If the section has changed, we put \.{\\*} just after the section number.
971 @y
972 @z
973
974 @x [12.231] l.4233
975 if (*(loc-1)!='*') out_str("\\M");
976 @y
977 if (*(loc-1)!='*') {
978 if (right_start_switch) {
979 out_str("\\shortpage\n"); right_start_switch=false;
980 @.\\shortpage@>
981 }
982 out_str("\\M");
983 }
984 @z
985
986 @x [12.231] l.4248
987 @.\\N@>
988 @y
989 @.\\N@>
990 if (right_start_switch) {
991 out('N'); right_start_switch=false;
992 @.\\NN@>
993 }
994 @z
995
996 @x [12.231] l.4255
997 out('{'); out_section(section_count); out('}');
998 @y
999 out('{'); out_section(section_count); out('}');
1000 flush_buffer(out_ptr,false,false);
1001 @z
1002
1003 @x [12.232] l.4263
1004 case '@@': out('@@'); break;
1005 @y
1006 case '@@': out('@@'); break;
1007 case temp_meaning: temp_switch=!temp_switch; break;
1008 case right_start: right_start_switch=true; break;
1009 @z
1010
1011 @x [12.232] l.4266
1012 case section_name: loc-=2; next_control=get_next(); /* skip to \.{@@>} */
1013 @y
1014 case meaning: case suppress:
1015 case section_name: loc-=2; next_control=get_next(); /* reprocess */
1016 @z
1017
1018 @x [12.232] l.4268
1019 err_print("! TeX string should be in C text only");
1020 @y
1021 err_print(_("! TeX string should be in C text only"));
1022 @z
1023
1024 @x [12.232] l.4271
1025 err_print("! Verbatim string should be in C text only"); break;
1026 @y
1027 err_print(_("! Verbatim string should be in C text only")); break;
1028 @z
1029
1030 @x [12.232] l.4277
1031 err_print("! You can't do that in TeX text"); break;
1032 @y
1033 err_print(_("! You can't do that in TeX text")); break;
1034 @z
1035
1036 @x [12.233] l.4291
1037 outer_parse(); finish_C(format_visible); format_visible=true;
1038 doing_format=false;
1039 }
1040 @y
1041 outer_parse();
1042 if (is_macro) @<Make ministring for a new macro@>@;
1043 finish_C(format_visible); format_visible=true;
1044 doing_format=false;
1045 }
1046 @z
1047
1048 @x [12.236] l.4343
1049 @<Start \9{a}a macro...@>= {
1050 @y
1051 @<Start \9{a}a macro...@>= {
1052 is_macro=true;
1053 @z
1054
1055 @x [12.236] l.4349
1056 err_print("! Improper macro definition");
1057 @y
1058 err_print(_("! Improper macro definition"));
1059 @z
1060
1061 @x [12.236] l.4350
1062 @.Improper macro definition@>
1063 else {
1064 app('$'); app_cur_id(false);
1065 @y
1066 @.Improper macro definition@>
1067 else {
1068 id_being_defined=id_lookup(id_first,id_loc,normal);
1069 app('$'); app_cur_id(false);
1070 def_diff=(*loc!='(');
1071 @z
1072
1073 @x [12.236] l.4362
1074 } @=/* otherwise fall through */@>@;
1075 default: err_print("! Improper macro definition"); break;
1076 @y
1077 } @=/* otherwise fall through */@>@;
1078 default: err_print(_("! Improper macro definition")); break;
1079 @z
1080
1081 @x [12.237] l.4372
1082 @ @<Start \9{a}a format...@>= {
1083 doing_format=true;
1084 @y
1085 @ @<Start \9{a}a format...@>= {
1086 doing_format=true;
1087 is_macro=false;
1088 @z
1089
1090 @x [12.237] l.4389
1091 if (scrap_ptr!=scrap_info+2) err_print("! Improper format definition");
1092 @y
1093 if (scrap_ptr!=scrap_info+2) err_print(_("! Improper format definition"));
1094 @z
1095
1096 @x [12.240] l.4424
1097 err_print("! You need an = sign after the section name");
1098 @y
1099 err_print(_("! You need an = sign after the section name"));
1100 @z
1101
1102 @x [12.241] l.4446
1103 err_print("! You can't do that in C text");
1104 @y
1105 err_print(_("! You can't do that in C text"));
1106 @z
1107
1108 @x [12.246] l.4516
1109 out_str("\\fi"); finish_line();
1110 @.\\fi@>
1111 @y
1112 finish_line(); out_str("\\mini"); finish_line();
1113 @.\\mini@>
1114 @<Output information about usage of id's defined in other sections@>@;
1115 out_str("}\\FI"); finish_line();
1116 @.\\FI@>
1117 @z
1118
1119 @x [13.247] l.4537
1120 if (show_progress) printf("%s","\nWriting the index...");
1121 @y
1122 if (show_progress) printf("%s",_("\nWriting the index..."));
1123 @z
1124
1125 @x [13.247] l.4539
1126 if (change_exists) {
1127 @<Tell about changed sections@>@;
1128 finish_line(); flush_buffer(out_buf,false,false);
1129 /* insert a blank line, it looks nice */
1130 }
1131 @y
1132 @z
1133
1134 @x [13.247] l.4548
1135 fatal("! Cannot open index file ",idx_file_name);
1136 @y
1137 fatal(_("! Cannot open index file "),idx_file_name);
1138 @z
1139
1140 @x [13.247] l.4560
1141 fatal("! Cannot open section file ",scn_file_name);
1142 @y
1143 fatal(_("! Cannot open section file "),scn_file_name);
1144 @z
1145
1146 @x [13.247] l.4572
1147 fclose(active_file);
1148 @y
1149 fclose(active_file); active_file=tex_file=NULL;
1150 if (check_for_change) @<Update the result when it has changed@>@;
1151 @z
1152
1153 @x [13.247] l.4575
1154 printf("%s","Done.");
1155 @y
1156 printf("%s",_("Done."));
1157 @z
1158
1159 @x [13.249] l.4583
1160 the index section itself.
1161
1162 @<Tell about changed sections@>=
1163 /* remember that the index is already marked as changed */
1164 sixteen_bits k_section=0; /* runs through the sections */
1165 while (!changed_section[++k_section]);
1166 out_str("\\ch ");
1167 @.\\ch@>
1168 out_section(k_section);
1169 while (k_section<section_count) {
1170 while (!changed_section[++k_section]);
1171 out_str(", "); out_section(k_section);
1172 }
1173 out('.');
1174 @y
1175 the index section itself---NOT!
1176 @z
1177
1178 @x [13.257] l.4727
1179 if (sort_ptr>=scrap_info_end) overflow("sorting");
1180 @y
1181 if (sort_ptr>=scrap_info_end) overflow(_("sorting"));
1182 @z
1183
1184 @x [13.262] l.4772
1185 @ @<Output the name...@>=
1186 switch (cur_name->ilk) {@+char *p; /* index into |byte_mem| */@+@t}\6{\4@>
1187 @y
1188 @ We don't format the index completely; the \.{twinx} program does the
1189 rest of the job. Compare this code with section |@<Mini-output...@>|.
1190
1191 @<Output the name...@>=
1192 switch (cur_name->ilk) {
1193 @z
1194
1195 @x [13.262] l.4774
1196 case normal: case func_template:
1197 @y
1198 case normal:
1199 @z
1200
1201 @x [13.262] l.4776
1202 else {@+bool all_caps=true;@+@t}\6{@>
1203 @y
1204 else {@+bool all_caps=true;@+char *p;
1205 /* index into |byte_mem| */ @+@t}\6{@>
1206 @z
1207
1208 @x [13.262] l.4791
1209 case roman: not_an_identifier: out_name(cur_name,false); goto name_done;
1210 case custom:
1211 out_str("$\\");
1212 for (p=cur_name->byte_start;p<(cur_name+1)->byte_start;p++)
1213 out(*p=='_'? 'x': *p=='$'? 'X': *p);
1214 out('$');
1215 goto name_done;
1216 @y
1217 case roman: out_str(" ");
1218 not_an_identifier: out_name(cur_name,false); goto name_done;
1219 case custom: out_str("\\$"); break;
1220 @.\\\$@>
1221 @z
1222
1223 @x [13.262] l.4801
1224 out_name(cur_name,true);
1225 @y
1226 out_name(cur_name,proofing);
1227 @z
1228
1229 @x [13.269] l.4864
1230 puts("\nMemory usage statistics:");
1231 @.Memory usage statistics:@>
1232 printf("%td names (out of %ld)\n",@^system dependencies@>
1233 (ptrdiff_t)(name_ptr-name_dir),(long)max_names);
1234 printf("%td cross-references (out of %ld)\n",
1235 (ptrdiff_t)(xref_ptr-xmem),(long)max_refs);
1236 printf("%td bytes (out of %ld)\n",
1237 (ptrdiff_t)(byte_ptr-byte_mem),(long)max_bytes);
1238 puts("Parsing:");
1239 printf("%td scraps (out of %ld)\n",
1240 (ptrdiff_t)(max_scr_ptr-scrap_info),(long)max_scraps);
1241 printf("%td texts (out of %ld)\n",
1242 (ptrdiff_t)(max_text_ptr-tok_start),(long)max_texts);
1243 printf("%td tokens (out of %ld)\n",
1244 (ptrdiff_t)(max_tok_ptr-tok_mem),(long)max_toks);
1245 printf("%td levels (out of %ld)\n",
1246 (ptrdiff_t)(max_stack_ptr-stack),(long)stack_size);
1247 puts("Sorting:");
1248 printf("%td levels (out of %ld)\n",
1249 (ptrdiff_t)(max_sort_ptr-scrap_info),(long)max_scraps);
1250 @y
1251 puts(_("\nMemory usage statistics:"));
1252 @.Memory usage statistics:@>
1253 printf(_("%td names (out of %ld)\n"),@^system dependencies@>
1254 (ptrdiff_t)(name_ptr-name_dir),(long)max_names);
1255 printf(_("%td cross-references (out of %ld)\n"),
1256 (ptrdiff_t)(xref_ptr-xmem),(long)max_refs);
1257 printf(_("%td bytes (out of %ld)\n"),
1258 (ptrdiff_t)(byte_ptr-byte_mem),(long)max_bytes);
1259 printf(_("%td temp meanings (out of %ld)\n"),
1260 (ptrdiff_t)(max_temp_meaning_ptr-temp_meaning_stack),
1261 (long)max_meanings);
1262 printf(_("%td titles (out of %ld)\n"),
1263 (ptrdiff_t)(title_code_ptr-title_code),(long)max_titles);
1264 puts(_("Parsing:"));
1265 printf(_("%td scraps (out of %ld)\n"),
1266 (ptrdiff_t)(max_scr_ptr-scrap_info),(long)max_scraps);
1267 printf(_("%td texts (out of %ld)\n"),
1268 (ptrdiff_t)(max_text_ptr-tok_start),(long)max_texts);
1269 printf(_("%td tokens (out of %ld)\n"),
1270 (ptrdiff_t)(max_tok_ptr-tok_mem),(long)max_toks);
1271 printf(_("%td levels (out of %ld)\n"),
1272 (ptrdiff_t)(max_stack_ptr-stack),(long)stack_size);
1273 puts(_("Sorting:"));
1274 printf(_("%td levels (out of %ld)\n"),
1275 (ptrdiff_t)(max_sort_ptr-scrap_info),(long)max_scraps);
1276 @z
1277
1278 @x [14.270] l.4886
1279 @** Index.
1280 @y
1281 @q Section 270. @>
1282 @** Mogrify {\tentex CWEAVE} into {\tentex CTWILL}. The following sections
1283 introduce material that is specific to \.{CTWILL}.
1284
1285 Care has been taken to keep the original section numbering of \.{CWEAVE}
1286 up to this point intact, so this new material should nicely integrate
1287 with the original ``\&{270.~Index}.''
1288
1289 @q Section 2->271. @>
1290 @* {\tentex CTWILL} user manual.
1291 Here is a sort of user manual for \.{CTWILL}---which is exactly like
1292 \.{CWEAVE} except that it produces much better documentation, for which you
1293 must work harder. As with \.{CWEAVE}, input comes from a source file
1294 \.{foo.w} and from an optional (but now almost mandatory) change file
1295 \.{foo.ch}; output goes to \.{foo.tex}, \.{foo.idx}, and \.{foo.scn}.
1296 Unlike \.{CWEAVE}, there is an additional output file, \.{foo.aux},
1297 which records all nonexternal definitions. The \.{.aux} file also
1298 serves as an input file on subsequent runs. You should run \.{CTWILL}
1299 twice, once to prime the pump and once to get decent answers.
1300
1301 Moreover, you must run the output twice through \TeX. (This double duplicity
1302 suggested the original name \.{TWILL}.) After `\.{tex} \.{foo}' you
1303 will have output that looks like final pages except that the entries
1304 of mini-indexes won't be alphabetized. \TeX\ will say `This is the first
1305 pass', and it will produce a weird file called \.{foo.ref}. Say
1306 $$\.{refsort < foo.ref > foo.sref}$$
1307 and then another `\.{tex} \.{foo}' will produce alphabetized output.
1308 While \TeX\ runs it emits messages filled with numeric data, indicating how
1309 much space is consumed by each program section. If you can decipher these
1310 numbers (see \.{ctwimac.tex}), you can use them to fine-tune the page
1311 layout. You might be tempted to do fine tuning by editing \.{foo.tex}
1312 directly, but it's better to incorporate all changes into \.{foo.ch}.
1313
1314 The mini-indexes list identifiers that are used but not defined on
1315 each two-page spread. At the end of each section, \.{CTWILL} gives
1316 \TeX\ a list of identifiers used in that section and information
1317 about where they are defined. The macros in \.{ctwimac.tex} figure out
1318 which identifiers should go in each mini-index, based on how the pages
1319 break. (Yes, those macros are pretty hairy.)
1320
1321 The information that \.{CTWILL} concocts from \.{foo.w} is not always
1322 correct. Sometimes you'll use an identifier that you don't want
1323 indexed; for example, your exposition might talk about |f(x)| when you
1324 don't mean to refer to program variables |f| or |x|. Sometimes you'll
1325 use an identifier that's defined in a header file, unknown to
1326 \.{CTWILL}. Sometimes you'll define a single identifier in several
1327 different places, and \.{CTWILL} won't know which definition to choose.
1328 But all is not lost. \.{CTWILL} guesses right most of the time, and you can
1329 give it the necessary hints in other places via your change file.
1330
1331 If you think it's easy to write a completely automatic system that doesn't
1332 make \.{CTWILL}'s mistakes and doesn't depend so much on change files,
1333 please do so.
1334
1335 \.{CTWILL} uses a very simple method to generate mini-index info. By
1336 understanding this method, you will understand how to fix it when things
1337 go wrong. Every identifier has a current ``meaning,'' consisting of its
1338 abstract type and the number of the section in which it was most recently
1339 defined. For example, if your \Cee\ program says `\&{char}~$*$|s|' in section~3,
1340 the meaning of~|s| gets changed to `\&{char}~$*$,~\S3' while \.{CTWILL}
1341 is processing that section. If you refer to~|s| in section~10, and if
1342 |s|~hasn't been redefined in the meantime, and if section~10 doesn't
1343 wind up on the same two-page spread as section~3, the mini-index generated
1344 by section~10 will say ``|s|:~\&{char}~$*$,~\S3.''
1345
1346 The current meaning of every identifier is initially `\.{\\uninitialized}'.
1347 Then \.{CTWILL} reads the \.{.aux} file for your job, if any; this
1348 \.{.aux} file contains all definitions of new meanings in the previous
1349 run, so it tells \.{CTWILL} about definitions that will be occurring
1350 in the future. If all identifiers have a unique definition, they will
1351 have a unique and appropriate meaning in the mini-indexes.
1352
1353 But some identifiers, like parameters to procedures, may be defined
1354 several times. Others may not be defined at all, because they are
1355 defined elsewhere and mentioned in header files included by the \Cee\
1356 preprocessor. To solve this problem, \.{CTWILL} provides mechanisms by which
1357 the current meaning of an identifier can be temporarily or permanently
1358 changed.
1359
1360 For example, the operation
1361 $$\.{@@\$s \{FOO\}3 \\\&\{char\} \$*\$@@>}$$
1362 changes the current meaning of |s| to the \TeX\ output of `\.{\\\&\{char\}}
1363 \.{\$*\$}' in section~3 of program {\sc FOO}. All entries in the \.{.aux}
1364 file are expressed in the form of this \.{@@\$} operator; therefore you
1365 can use a text editor to paste such entries into a \.{.ch} file, whenever
1366 you want to tell \.{CTWILL} about definitions that are out of order
1367 or from other programs.
1368
1369 Before reading the \.{.aux} file, \.{CTWILL} actually looks for a file
1370 called \.{system.bux}, which will be read if present. And after
1371 \.{foo.aux}, a third possibility is \.{foo.bux}. The general
1372 convention is to put definitions of system procedures such as |printf|
1373 into \.{system.bux}, and to put definitions found in specifically
1374 foo-ish header files into \.{foo.bux}. Like the \.{.aux}
1375 files, \.{.bux} files should contain only \.{@@\$} specifications;
1376 this rule corresponds to the fact that `bux' is the plural of `\$'.
1377 The \.{.bux} files may also contain \.{@@i} includes.
1378
1379 A companion operation \.{@@\%} signifies that all \.{@@\$}
1380 specifications from the present point to the beginning of the next
1381 section will define {\it temporary\/} meanings instead of permanent
1382 ones. Temporary meanings are placed into the
1383 mini-index of the current section; the permanent (current) meaning of
1384 the identifier will not be changed, nor will it appear in the
1385 mini-index of the section. If several temporary meanings are assigned
1386 to the same identifier in a section, all will appear in the mini-index.
1387 Each \.{@@\%} toggles the temporary/permanent convention; thus, after
1388 an even number of \.{@@\%} operations in a section, meanings specified
1389 by \.{@@\$} are permanent.
1390
1391 The operation \.{@@-} followed by an identifier followed by \.{@@>}
1392 specifies that the identifier should not generate a mini-index entry
1393 in the current section (unless, of course, a temporary meaning is assigned).
1394
1395 If \.{@@-foo@@>} appears in a section where a new permanent meaning is
1396 later defined by the semantics of~\Cee, the current meaning of \\{foo}
1397 will not be redefined; moreover, this current meaning, which may have
1398 been changed by \.{@@\$foo ...@@>}, will also be written to the
1399 \.{.aux} file. Therefore you can control what \.{CTWILL} outputs; you
1400 can keep it from repeatedly contaminating the \.{.aux} file with
1401 things you don't like.
1402
1403 The meaning specified by \.{@@\$...@@>} generally has four components:
1404 an identifier (followed by space), a program name (enclosed in braces),
1405 a section number (followed by space), and a \TeX\ part. The \TeX\ part
1406 must have fewer than 80 characters. If the \TeX\ part starts
1407 with `\.=', the mini-index entry will contain an equals sign instead
1408 of a colon; for example,
1409 $$\.{@@\$buf\_size \{PROG\}10 =\\T\{200\}@@>}$$
1410 generates either `$\\{buf\_size}=200$, \S10' or
1411 `$\\{buf\_size}=200$, {\sc PROG}~\S10', depending on whether
1412 `{\sc PROG}' is or isn't the title of the current program. If the
1413 \TeX\ part is `\.{\\zip}', the mini-index entry will contain neither
1414 colon nor equals, just a comma. The program name and section number
1415 can also be replaced by a string. For example,
1416 $$\.{@@\$printf "<stdio.h>" \\zip@@>}$$
1417 will generate a mini-index entry like `\\{printf}, \.{<stdio.h>}.'.
1418
1419 A special ``proofmode'' is provided so that you can check \.{CTWILL}'s
1420 conclusions about cross-references. Run \.{CTWILL} with the
1421 flag \.{+P}, and \TeX\ will produce a specially formatted document
1422 ({\it without\/} mini-indexes)
1423 in which you can check that your specifications are correct.
1424 You should always do this before generating mini-indexes, because
1425 mini-indexes can mask errors if page breaks are favorable but the
1426 errors might reveal themselves later after your program has changed.
1427 The proofmode output is much easier to check than the mini-indexes themselves.
1428
1429 The control code \.{@@r} or \.{@@R} causes \.{CTWILL} to emit
1430 the \TeX\ macro `\.{\\shortpage}' just before starting the next
1431 section of the program. This causes the section to appear at the top of
1432 a right-hand page, if it would ordinarily have appeared near the bottom
1433 of a left-hand page and split across the pages. (The \.{\\shortpage} macro
1434 is fragile and should be used only in cases where it will not mess up
1435 the output; insert it only when fine-tuning a set of pages.) If the
1436 next section is a starred section, the behavior is slightly different
1437 (but still fragile): The starred section will either be postponed to
1438 a left-hand page, if it normally would begin on a right-hand page,
1439 or vice versa. In other words, \.{@@r@@*} inverts the left/right logic.
1440
1441 \.{CTANGLE} does not recognize the operations \.{@@\$}, \.{@@\%}, \.{@@-},
1442 and \.{@@r}, which are unique to \.{CTWILL}. But that is no problem,
1443 since you use them only in change files set up for book publishing,
1444 which are quite different from the change files you set up for tangling.
1445
1446 (End of user manual.)
1447
1448 @d max_tex_chars 80 /* limit on the \TeX\ part of a meaning */
1449
1450 @q Section 25->272. @>
1451 @* Temporary and permanent meanings.
1452 \.{CTWILL} has special data structures to keep track of current
1453 and temporary meanings. These structures were not designed for maximum
1454 efficiency; they were designed to be easily grafted into \.{CWEAVE}'s
1455 existing code without major surgery.
1456
1457 @d max_meanings 100 /* max temporary meanings per section */
1458 @d max_titles 100 /* max distinct program or header names in meanings */
1459
1460 @<Type...@>=
1461 typedef struct {
1462 name_pointer id; /* identifier whose meaning is being recorded */
1463 sixteen_bits prog_no; /* title of program or header in which defined */
1464 sixteen_bits sec_no; /* section number in which defined */
1465 char tex_part[max_tex_chars]; /* \TeX\ part of meaning */
1466 } meaning_struct;
1467
1468 @q Section 26->273. @>
1469 @ @<Private...@>=
1470 static struct perm_meaning {
1471 meaning_struct perm; /* current meaning of an identifier */
1472 int stamp; /* last section number in which further output suppressed */
1473 struct perm_meaning *link; /* another meaning to output in this section */
1474 } cur_meaning[max_names]; /* the current ``permanent'' meanings */
1475 static struct perm_meaning *top_usage; /* first meaning to output in this section */
1476 static meaning_struct temp_meaning_stack[max_meanings]; /* the current ``temporary'' meanings */
1477 static meaning_struct *temp_meaning_stack_end=temp_meaning_stack+max_meanings-1;
1478 /* end of |temp_meaning_stack| */
1479 static meaning_struct *temp_meaning_ptr; /* first available slot in |temp_meaning_stack| */
1480 static meaning_struct *max_temp_meaning_ptr; /* its maximum value so far */
1481 static name_pointer title_code[max_titles]; /* program names seen so far */
1482 static name_pointer *title_code_end=title_code+max_titles-1;
1483 /* end of |title_code| */
1484 static name_pointer *title_code_ptr; /* first available slot in |title_code| */
1485 static char ministring_buf[max_tex_chars]; /* \TeX\ code being generated */
1486 static char *ministring_buf_end=ministring_buf+max_tex_chars-1;
1487 /* end of |ministring_buf| */
1488 static char *ministring_ptr; /* first available slot in |ministring_buf| */
1489 static bool ms_mode; /* are we outputting to |ministring_buf|? */
1490
1491 @q Section 27->274. @>
1492 @ @<Set init...@>=
1493 max_temp_meaning_ptr=temp_meaning_stack;
1494 title_code_ptr=title_code;
1495 ms_mode=false;
1496
1497 @q Section 275. @>
1498 @ @<Predec...@>=@+static void new_meaning(name_pointer);
1499
1500 @q Section 30->276. @>
1501 @ The |new_meaning| routine changes the current ``permanent meaning''
1502 when an identifier is redeclared. It gets the |tex_part| from
1503 |ministring_buf|.
1504
1505 @c
1506 static void
1507 new_meaning(
1508 name_pointer p)
1509 {
1510 struct perm_meaning *q=get_meaning(p);
1511 if (q->stamp!=section_count) {
1512 if (*(ministring_ptr-1)==' ') ministring_ptr--;
1513 if (ministring_ptr>=ministring_buf_end)
1514 strcpy(ministring_buf,"\\zip"); /* ignore |tex_part| if too long */
1515 @.\\zip@>
1516 else *ministring_ptr='\0';
1517 q->perm.prog_no=0; /* |q->perm.id=p| */
1518 q->perm.sec_no=section_count;
1519 strcpy(q->perm.tex_part,ministring_buf);
1520 }
1521 @<Write the new meaning to the \.{.aux} file@>@;
1522 }
1523
1524 @q Section 75->277. @>
1525 @ @<Process a user-generated meaning@>=
1526 { char *first=id_first;
1527 while (xisspace(*first)) first++;
1528 loc=first;
1529 while (xisalpha(*loc)||xisdigit(*loc)||isxalpha(*loc)) loc++;
1530 if (*loc++!=' ')
1531 err_print(_("! Identifier in meaning should be followed by space"));
1532 else {@+ int n=0;
1533 name_pointer p=id_lookup(first,loc-1,normal);
1534 sixteen_bits t=title_lookup();
1535 if (*(loc-1)=='}')
1536 for (;xisdigit(*loc);loc++)@^system dependencies@>
1537 if (n < INT_MAX / 10) n=10*n+(*loc)-'0';
1538 if (*loc++!=' ')
1539 err_print(_("! Location in meaning should be followed by space"));
1540 else @<Digest the meaning of |p|, |t|, |n|@>@;
1541 }
1542 loc=id_loc+2;
1543 }
1544
1545 @q Section 76->278. @>
1546 @ @<Suppress mini-index entry@>=
1547 { char *first=id_first,*last=id_loc;
1548 while (xisspace(*first)) first++;
1549 while (xisspace(*(last-1))) last--;
1550 if (first<last) {
1551 struct perm_meaning *q=get_meaning(id_lookup(first,last,normal));
1552 q->stamp=section_count; /* this is what actually suppresses output */
1553 }
1554 }
1555
1556 @q Section 77->279. @>
1557 @ @<Digest...@>=
1558 { meaning_struct *m;
1559 struct perm_meaning *q=get_meaning(p);
1560 if (temp_switch) {
1561 m=temp_meaning_ptr++;
1562 if (temp_meaning_ptr>max_temp_meaning_ptr) {
1563 if (temp_meaning_ptr>=temp_meaning_stack_end)
1564 overflow(_("temp meanings"));
1565 max_temp_meaning_ptr=temp_meaning_ptr;
1566 }
1567 } else m=&(q->perm);
1568 m->id=p;
1569 m->prog_no=t;
1570 m->sec_no=n;
1571 if (id_loc-loc>=max_tex_chars) strcpy(m->tex_part,"\\zip");
1572 @.\\zip@>
1573 else { char *q=m->tex_part;
1574 while (loc<id_loc) *q++=*loc++;
1575 *q='\0';
1576 }
1577 }
1578
1579 @q Section 141->280/1. @>
1580 @* Make ministrings.
1581 \.{CTWILL} needs the following procedure, which appends tokens of a
1582 translated text until coming to |tok_loc|, then suppresses text that may
1583 appear between parentheses or brackets. The calling routine |make_ministring|
1584 should set |ident_seen=false| first. (This is admittedly tricky.)
1585
1586 @<Private var...@>=
1587 static bool ident_seen;
1588
1589 @ @c
1590 static bool app_supp(
1591 text_pointer p)
1592 { token_pointer j;
1593 if (ident_seen && **p>=tok_flag)
1594 switch (**(**p-tok_flag+tok_start)) {
1595 case '(': app_str("(\\,)"); goto catch14;
1596 case '[': app_str("[\\,]"); goto catch14;
1597 }
1598 for (j=*p;j<*(p+1);j++)
1599 if (*j<tok_flag) {
1600 if (*j==inserted) break;
1601 if (j==tok_loc) ident_seen=true;
1602 else app(*j);
1603 } else if (*j>=inner_tok_flag) confusion(_("inner"));
1604 else if (app_supp(*j-tok_flag+tok_start)) goto catch14;
1605 return false;
1606 catch14: return *(*(p+1)-1)=='9'; /* was production 14 used? */
1607 }
1608
1609 @q Section 282. @>
1610 @ @<Predec...@>=@+static bool app_supp(text_pointer);
1611
1612 @q Section 142->283. @>
1613 @ The trickiest part of \.{CTWILL} is the procedure |make_ministring(pp+l)|,
1614 with offset $l\in\{0,1,2\}$, which tries to figure out a symbolic form of
1615 definition after |make_underlined(pp+l)| has been called. We rely heavily
1616 on the existing productions, which force the translated texts to have a
1617 structure that's decodable even though the underlying |cat| and |mathness|
1618 codes have disappeared.
1619
1620 @c static void
1621 make_ministring(scrap_pointer p)
1622 {
1623 if (tok_loc<=operator_found) return;
1624 @<Append the type of the declaree; |return| if it begins with \&{extern}@>@;
1625 null_scrap.mathness=((p->mathness)%4)*5; big_app1(&null_scrap);
1626 /* now we're ready for the mathness that follows (I think);
1627 (without the mod 4 times 5, comments posed a problem,
1628 namely in cases like |int a(b,c)| followed by comment) */
1629 ident_seen=false;@+app_supp(p->trans);
1630 null_scrap.mathness=10; big_app1(&null_scrap);
1631 /* now |cur_mathness==no_math| */
1632 ms_mode=true; ministring_ptr=ministring_buf;
1633 if (p==pp+2) *ministring_ptr++='=';
1634 make_output(); /* translate the current text into a ministring */
1635 tok_ptr=*(--text_ptr); /* delete that text */
1636 new_meaning(((*tok_loc)%id_flag)+name_dir);
1637 cur_mathness=maybe_math; /* restore it */
1638 }
1639
1640 @q Section 284. @>
1641 @ @<Predec...@>=@+static void make_ministring(scrap_pointer);
1642
1643 @q Section 43->285. @>
1644 @ @<Private...@>=
1645 static sixteen_bits int_loc, ext_loc; /* locations of special reserved words */
1646
1647 @q Section 143->286. @>
1648 @ Here we use the fact that a |decl_head| comes from |int_like| only in
1649 production~27, whose translation is fairly easy to recognize. (Well,
1650 production 28 has been added for \CPLUSPLUS/, but we hope that doesn't
1651 mess us up.) And we also use other similar facts.
1652
1653 If an identifier is given an \&{extern} definition, we don't change
1654 its current meaning, but we do suppress mini-index entries to its
1655 current meaning in other sections.
1656
1657 @<Append the type of the declaree; |return| if it begins with \&{extern}@>=
1658 if (p==pp) { app(int_loc+res_flag); app(' '); cur_mathness=no_math; }
1659 else {
1660 text_pointer q=(p-1)->trans, r;
1661 token t;
1662 int ast_count=0; /* asterisks preceding the expression */
1663 bool non_ast_seen=false; /* have we seen a non-asterisk? */
1664 while (true) {
1665 if (*(q+1)==*q+1) {
1666 r=q;@+break; /* e.g., \&{struct}; we're doing production 45 or 46 */
1667 }
1668 if (**q<tok_flag) confusion(_("find type"));
1669 r=**q-tok_flag+tok_start;
1670 if ((t=*(*(q+1)-2))>=tok_flag && **(t-tok_flag+tok_start)=='*') {
1671 /* production 34 */
1672 if (!non_ast_seen) ast_count++; /* count immediately preceding |*|'s */
1673 } else non_ast_seen=true;
1674 if (*(*q+1)==' ' && *(q+1)==*q+2) break; /* production 27 */
1675 if (*(*q+1)=='{' && *(*q+2)=='}' && *(*q+3)=='$' && *(*q+4)==' '@|
1676 && *(q+1)==*q+5) break; /* production 27 in disguise */
1677 q=r;
1678 }
1679 while (**r>=tok_flag) {
1680 if (*(r+1)>*r+9 && *(*r+1)=='{' && *(*r+2)=='}' && *(*r+3)=='$' @|
1681 && *(*r+4)==indent) q=**r-tok_flag+tok_start; /* production 49 */
1682 r=**r-tok_flag+tok_start;
1683 }
1684 if (**r==ext_loc+res_flag) return; /* \&{extern} gives no definition */
1685 @<Append tokens for type |q|@>@;
1686 }
1687
1688 @q Section 144->287. @>
1689 @ @<Append tokens for type |q|@>=
1690 cur_mathness=no_math; /* it was |maybe_math| */
1691 if (*(q+1)==*q+8 && *(*q+1)==' ' && *(*q+3)==' ') {
1692 app(**q);@+app(' ');@+app(*(*q+2)); /* production 46 */
1693 } else if ((t=*(*(q+1)-1))>=tok_flag && **(r=t-tok_flag+tok_start)=='\\'
1694 && *(*r+1)=='{') app(**q); /* |struct_like| identifier */
1695 else app((q-tok_start)+tok_flag);
1696 while (ast_count) {
1697 big_app('{');@+app('*');@+app('}');@+ast_count--;
1698 }
1699
1700 @q Section 253->288. @>
1701 @ @<Private...@>=
1702 static bool is_macro; /* it's a macro def, not a format def */
1703 static bool def_diff; /* |false| iff the current macro has parameters */
1704 static name_pointer id_being_defined; /* the definee */
1705
1706 @q Section 257->289. @>
1707 @ @<Make ministring for a new macro@>=
1708 {
1709 ms_mode=true; ministring_ptr=ministring_buf;
1710 *ministring_ptr++='=';
1711 if (def_diff) { /* parameterless */
1712 scrap_pointer s=scrap_ptr;
1713 text_pointer t;
1714 token_pointer j;
1715 while (s->cat==insert) s--;
1716 if ((s-1)->cat==dead && s->cat==exp && **(t=s->trans)=='\\'
1717 && *(*t+1)=='T') /* it's just a constant */
1718 for (j=*t;j<*(t+1);j++) *ministring_ptr++=*j;
1719 else out_str("macro");
1720 } else out_str("macro (\\,)");
1721 new_meaning(id_being_defined);
1722 }
1723
1724 @q Section 246->290. @>
1725 @* Process {\tentex .aux} files.
1726
1727 @<Private...@>=
1728 static FILE *aux_file;
1729 static char aux_file_name[max_file_name_length]; /* name of \.{.aux} file */
1730
1731 @q Section 247->291. @>
1732 @ @<Read the \.{.aux} file, if present; then open it for output@>=
1733 memcpy(aux_file_name,tex_file_name,strlen(tex_file_name)-4);
1734 strcat(aux_file_name,".bux");
1735 include_depth=1; /* we simulate \.{@@i} */
1736 strcpy(cur_file_name,aux_file_name); /* first in, third out */
1737 if ( (found_filename = kpse_find_cweb(cur_file_name)) @|
1738 && (cur_file=fopen(found_filename,"r")) ) {
1739 @<Set up |cur_file_name| for opened |cur_file|@>@;
1740 cur_line=0; include_depth++;
1741 }
1742 strcpy(aux_file_name+strlen(aux_file_name)-4,".aux");@/
1743 strcpy(cur_file_name,aux_file_name); /* second in, second out */
1744 if ((cur_file=fopen(cur_file_name,"r"))) { cur_line=0; include_depth++; }
1745 strcpy(cur_file_name,"system.bux"); /* third in, first out */
1746 if ( (found_filename = kpse_find_cweb(cur_file_name)) @|
1747 && (cur_file=fopen(found_filename,"r")) ) {
1748 @<Set up |cur_file_name| for opened |cur_file|@>@;
1749 cur_line=0;
1750 }
1751 else include_depth--;
1752 if (include_depth) { /* at least one new file was opened */
1753 while (get_next()==meaning) ; /* new meaning is digested */
1754 if (include_depth) err_print(_("! Only @@$ is allowed in aux and bux files"));
1755 finish_line(); loc=buffer; /* now reading beginning of line 1 */
1756 }
1757 if ((aux_file=fopen(aux_file_name,"wb"))==NULL)
1758 fatal(_("! Cannot open aux output file "),aux_file_name);
1759
1760 @q Section 31->292. @>
1761 @ @<Write the new meaning to the \.{.aux} file@>=
1762 {@+int n=q->perm.prog_no;
1763 ms_mode=false;@/
1764 fprintf(aux_file,"@@$%.*s %.*s",@|
1765 (int)length(p),p->byte_start,@|
1766 (int)length(title_code[n]),title_code[n]->byte_start);
1767 if (*(title_code[n]->byte_start)=='{') fprintf(aux_file,"%d",q->perm.sec_no);
1768 fprintf(aux_file," %s@@>\n",q->perm.tex_part);
1769 }
1770
1771 @q Section 268->293. @>
1772 @* Usage of identifiers.
1773 The following code is performed for each identifier parsed during
1774 a section. Variable |top_usage| is always nonzero; it has the sentinel
1775 value~1 initially, then it points to each variable scheduled for
1776 possible citation. A variable is on this list if and only if its
1777 |link| field is nonzero. All variables mentioned in the section are
1778 placed on the list, unless they are reserved and their current
1779 \TeX\ meaning is uninitialized.
1780
1781 @<Flag the usage of this identifier, for the mini-index@>=
1782 { struct perm_meaning *q=get_meaning(p);
1783 if (!abnormal(p) || strcmp(q->perm.tex_part,"\\uninitialized")!=0)
1784 if (q->link==NULL) {
1785 q->link=top_usage;
1786 top_usage=q;
1787 }
1788 }
1789
1790 @q Section 269->294. @>
1791 @ @<Output information about usage of id's defined in other sections@>=
1792 { struct perm_meaning *q;
1793 while (temp_meaning_ptr>temp_meaning_stack) {
1794 out_mini(--temp_meaning_ptr);
1795 q=get_meaning(temp_meaning_ptr->id);
1796 q->stamp=section_count; /* suppress output from ``permanent'' data */
1797 }
1798 while (top_usage!=usage_sentinel) {
1799 q=top_usage;
1800 top_usage=q->link;
1801 q->link=NULL;
1802 if (q->stamp!=section_count) out_mini(&(q->perm));
1803 }
1804 }
1805
1806 @q Section 270->295. @>
1807 @ @c static void
1808 out_mini(
1809 meaning_struct *m)
1810 { char s[max_tex_chars+10];
1811 name_pointer cur_name=m->id;
1812 if (m->prog_no==0) { /* reference within current program */
1813 if (m->sec_no==section_count) return; /* defined in current section */
1814 snprintf(s,max_tex_chars+10,"\\[%d",m->sec_no);
1815 } else { name_pointer n=title_code[m->prog_no];
1816 if (*(n->byte_start)=='{')
1817 snprintf(s,max_tex_chars+10,"\\]%.*s%d",(int)length(n),n->byte_start,m->sec_no);
1818 else snprintf(s,max_tex_chars+10,"\\]%.*s",(int)length(n),n->byte_start);
1819 }
1820 out_str(s); out(' ');
1821 @<Mini-output the name at |cur_name|@>@;
1822 out(' '); out_str(m->tex_part); finish_line();
1823 }
1824
1825 @q Section 270->296. @>
1826 @ @<Predec...@>=@+static void out_mini(meaning_struct *);
1827
1828 @q Section 271->297. @>
1829 @ Compare this code with section |@<Output the name...@>|.
1830
1831 @<Mini-output...@>=
1832 switch (cur_name->ilk) {@+char *p; /* index into |byte_mem| */@+@t}\6{\4@>
1833 case normal: case func_template:
1834 if (is_tiny(cur_name)) out_str("\\|");
1835 else {@+bool all_caps=true;@+@t}\6{@>
1836 for (p=cur_name->byte_start;p<(cur_name+1)->byte_start;p++)
1837 if (xislower(*p)) { /* not entirely uppercase */
1838 all_caps=false; break;
1839 }
1840 out_str(all_caps ? "\\." : "\\\\");
1841 }
1842 break;
1843 @.\\|@>
1844 @.\\.@>
1845 @.\\\\@>
1846 case wildcard: out_str("\\9"); break;
1847 @.\\9@>
1848 case typewriter: out_str("\\."); break;
1849 @.\\.@>
1850 case roman: break;
1851 case custom:
1852 out_str("$\\");
1853 for (p=cur_name->byte_start;p<(cur_name+1)->byte_start;p++)
1854 out(*p=='_'? 'x': *p=='$'? 'X': *p);
1855 out('$');
1856 goto name_done;
1857 default: out_str("\\&");
1858 @.\\\&@>
1859 }
1860 out_name(cur_name,true);
1861 name_done:@;
1862
1863 @q Section 28->298. @>
1864 @* Handle program title.
1865 Here's a routine that converts a program title from the buffer
1866 into an internal number for the |prog_no| field of a meaning.
1867 It advances |loc| past the title found.
1868
1869 @c static sixteen_bits title_lookup(void)
1870 {
1871 char *first=loc,*last; /* boundaries */
1872 name_pointer *p;
1873 if (*loc=='"') {
1874 while (++loc<=limit && *loc!='"') if (*loc=='\\') loc++;
1875 } else if (*loc=='{') {
1876 int balance=1; /* excess of left over right */
1877 while (++loc<=limit) {
1878 if (*loc==' ' && balance==1)
1879 *loc='}'; /* Skip ``version'' after module name and fall through */
1880 if (*loc=='}' && --balance==0) break;
1881 if (*loc=='{') balance++;
1882 }
1883 } else err_print(_("! Title should be enclosed in braces or doublequotes"));
1884 last=++loc;
1885 if (last>limit) err_print(_("! Title name didn't end"));
1886 if (title_code_ptr==title_code_end) overflow(_("titles"));
1887 *title_code_ptr=id_lookup(first,last,title);
1888 for (p=title_code;true;p++) if (*p==*title_code_ptr) break;
1889 if (p==title_code_ptr) title_code_ptr++;
1890 return p-title_code;
1891 }
1892
1893 @q Section 299. @>
1894 @ @<Predec...@>=@+static sixteen_bits title_lookup(void);
1895
1896 @q Section 29->300. @>
1897 @ @<Give a default title to the program, if necessary@>=
1898 if (title_code_ptr==title_code) { /* no \.{\\def\\title} found in limbo */
1899 char *saveloc=loc,*savelimit=limit; /* save */
1900 loc=limit+1; limit=loc;
1901 *limit++='{';
1902 memcpy(limit,tex_file_name,strlen(tex_file_name)-4);
1903 limit+=strlen(tex_file_name)-4;
1904 *limit++='}';
1905 title_lookup();@/
1906 loc=saveloc; limit=savelimit; /* restore */
1907 }
1908
1909 @q Section 301. @>
1910 @** Extensions to {\tentex CWEB}. The following sections introduce new or
1911 improved features that have been created by numerous contributors over the
1912 course of a quarter century.
1913
1914 @* Formatting alternatives.
1915 \.{CWEAVE} indents declarations after old-style function definitions and
1916 long parameter lists of modern function definitions.
1917 With the \.{-i} option they will come out flush left.
1918
1919 @d indent_param_decl flags['i'] /* should formal parameter declarations be indented? */
1920
1921 @<Set init...@>=
1922 indent_param_decl=true;
1923
1924 @ The original manual described the \.{-o} option for \.{CWEAVE}, but this was
1925 not yet present. Here is a simple implementation. The purpose is to suppress
1926 the extra space between local variable declarations and the first statement in
1927 a function block.
1928
1929 @d order_decl_stmt flags['o'] /* should declarations and statements be separated? */
1930
1931 @<Set init...@>=
1932 order_decl_stmt=true;
1933
1934 @* Output file update. Most \CEE/ projects are controlled by a \.{Makefile}
1935 that automatically takes care of the temporal dependencies between the different
1936 source modules. It may be convenient that \.{CWEB} doesn't create new output
1937 for all existing files, when there are only changes to some of them. Thus the
1938 \.{make} process will only recompile those modules where necessary. You can
1939 activate this feature with the `\.{+c}' command-line option. The idea and basic
1940 implementation of this mechanism can be found in the program \.{NUWEB} by
1941 Preston Briggs, to whom credit is due.
1942
1943 @<Update the result...@>= {
1944 if((tex_file=fopen(tex_file_name,"r"))!=NULL) {
1945 bool comparison=false;
1946
1947 if((check_file=fopen(check_file_name,"r"))==NULL)
1948 fatal(_("! Cannot open output file "),check_file_name);
1949 @.Cannot open output file@>
1950
1951 @<Compare the temporary output...@>@;
1952
1953 fclose(tex_file); tex_file=NULL;
1954 fclose(check_file); check_file=NULL;
1955
1956 @<Take appropriate action depending on the comparison@>@;
1957 } else
1958 rename(check_file_name,tex_file_name); /* This was the first run */
1959
1960 strcpy(check_file_name,""); /* We want to get rid of the temporary file */
1961 }
1962
1963 @ We hope that this runs fast on most systems.
1964
1965 @<Compare the temporary output to the previous output@>=
1966 do {
1967 char x[BUFSIZ],y[BUFSIZ];
1968 int x_size = fread(x,sizeof(char),BUFSIZ,tex_file);
1969 int y_size = fread(y,sizeof(char),BUFSIZ,check_file);
1970 comparison = (x_size == y_size) && !memcmp(x,y,x_size);
1971 } while(comparison && !feof(tex_file) && !feof(check_file));
1972
1973 @ Note the superfluous call to |remove| before |rename|. We're using it to
1974 get around a bug in some implementations of |rename|.@^system dependencies@>
1975
1976 @<Take appropriate action...@>=
1977 if(comparison)
1978 remove(check_file_name); /* The output remains untouched */
1979 else {
1980 remove(tex_file_name);
1981 rename(check_file_name,tex_file_name);
1982 }
1983
1984 @* Print ``version'' information.
1985 Don't do this at home, kids! Push our local macro to the variable in \.{COMMON}
1986 for printing the |banner| and the |versionstring| from there.
1987
1988 @d max_banner 50
1989
1990 @<Common code...@>=
1991 extern char cb_banner[];
1992
1993 @ @<Set init...@>=
1994 strncpy(cb_banner,banner,max_banner-1);
1995
1996 @* File lookup with \Kpathsea/. The \.{CTANGLE} and \.{CWEAVE} programs from
1997 the original \.{CWEB} package use the compile-time default directory or the
1998 value of the environment variable \.{CWEBINPUTS} as an alternative place to be
1999 searched for files, if they could not be found in the current directory.
2000
2001 This version uses the \Kpathsea/ mechanism for searching files.
2002 The directories to be searched for come from three sources:
2003 \smallskip
2004 {\parindent1em
2005 \item{(a)} a user-set environment variable \.{CWEBINPUTS}
2006 (overridden by \.{CWEBINPUTS\_cweb});
2007 \item{(b)} a line in \Kpathsea/ configuration file \.{texmf.cnf},\hfil\break
2008 e.g., \.{CWEBINPUTS=\$TEXMFDOTDIR:\$TEXMF/texmf/cweb//}\hfil\break
2009 or \.{CWEBINPUTS.cweb=\$TEXMFDOTDIR:\$TEXMF/texmf/cweb//};
2010 \item{(c)} compile-time default directories (specified in
2011 \.{texmf.in}),\hfil\break
2012 i.e., \.{\$TEXMFDOTDIR:\$TEXMF/texmf/cweb//}.\par}
2013 @.CWEBINPUTS@>
2014
2015 @d kpse_find_cweb(name) kpse_find_file(name,kpse_cweb_format,true)
2016
2017 @<Include files@>=
2018 #include <kpathsea/tex-file.h> /* |@!kpse_find_file| */
2019
2020 @ @<Set up |cur_file_name|...@>=
2021 if (strlen(found_filename) < max_file_name_length) {
2022 if (strcmp(cur_file_name,found_filename)) {
2023 strcpy(cur_file_name,found_filename + @|
2024 ((strncmp(found_filename,"./",2)==0) ? 2 : 0)); /* Strip path prefix */
2025 }
2026 free(found_filename);
2027 }@+else fatal(_("! Filename too long\n"), found_filename);
2028
2029 @** Index.
2030 @z
2031