1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
|
@q Changes for CWEB in TeX Live from numerous contributors. @>
@q This file is in the Public Domain. @>
@q Most of the original Kpathsea changes by Wlodek Bzyl and Olaf Weber @>
@q were merged with the set of change files of the CWEBbin project; @>
@q see https://github.com/ascherer/cwebbin for the original parts. @>
@q This stripped change file {comm,ctang,cweav,ctwill,cwebman}-w2c.ch @>
@q has been created from the elaborate set of change files @>
@q {comm,ctang,cweav,cwebman}-patch.ch, @>
@q {comm,cweav,cwebman}-extensions.ch, {comm,ctang,cweav}-output.ch, @>
@q {comm,ctang,cweav}-i18n.ch, and cweav-twill.ch for CTWILL, and @>
@q {comm,ctang,cweav,ctwill,cwebman}-texlive.ch with the 'tie' processor @>
@q and is used as a monolithic changefile for {common,ctangle,cweave}.w @>
@q and cwebman.tex in TeX Live. @>
@q Please send comments, suggestions, etc. to tex-k@@tug.org. @>
@x
\def\title{CWEAVE (Version 4.2)}
@y
\def\title{CWEAVE (Version 4.2 [\TeX~Live])}
@z
@x
\centerline{(Version 4.2)}
@y
\centerline{(Version 4.2 [\TeX~Live])}
@z
@x
\def\botofcontents{\vfill
@y
\def\covernote{\vbox{%
@z
@x
}
@y
}}\datecontentspage
@z
@x
@d banner "This is CWEAVE (Version 4.2)"
@y
@d banner "This is CWEAVE, Version 4.2"
/* will be extended by the \TeX~Live |versionstring| */
@z
@x
if (show_banner) puts(banner); /* print a ``banner line'' */
@y
if (show_banner) cb_show_banner(); /* print a ``banner line'' */
@z
@x
@i common.h
@y
@i comm-w2c.h
@z
@x
@d append_xref(c) if (xref_ptr==xmem_end) overflow("cross-reference");
@y
@d append_xref(c) if (xref_ptr==xmem_end) overflow(_("cross-reference"));
@z
@x
err_print("! String didn't end"); loc=limit; break;
@y
err_print(_("! String didn't end")); loc=limit; break;
@z
@x
err_print("! Input ended in middle of string"); loc=buffer; break;
@y
err_print(_("! Input ended in middle of string")); loc=buffer; break;
@z
@x
fputs("\n! String too long: ",stdout);
@y
fputs(_("\n! String too long: "),stdout);
@z
@x
case translit_code: err_print("! Use @@l in limbo only"); continue;
@y
case translit_code: err_print(_("! Use @@l in limbo only")); continue;
@z
@x
err_print("! Input ended in section name");
@y
err_print(_("! Input ended in section name"));
@z
@x
fputs("\n! Section name too long: ",stdout);
@y
fputs(_("\n! Section name too long: "),stdout);
@z
@x
err_print("! Section name didn't end"); break;
@y
err_print(_("! Section name didn't end")); break;
@z
@x
err_print("! Control codes are forbidden in section name"); break;
@y
err_print(_("! Control codes are forbidden in section name")); break;
@z
@x
err_print("! Control text didn't end"); loc=limit;
@y
err_print(_("! Control text didn't end")); loc=limit;
@z
@x
err_print("! Control codes are forbidden in control text");
@y
err_print(_("! Control codes are forbidden in control text"));
@z
@x
if (loc>=limit) err_print("! Verbatim string didn't end");
@y
if (loc>=limit) err_print(_("! Verbatim string didn't end"));
@z
@x
if (++section_count==max_sections) overflow("section number");
@y
if (++section_count==max_sections) overflow(_("section number"));
@z
@x
case translit_code: err_print("! Use @@l in limbo only"); continue;
@y
case translit_code: err_print(_("! Use @@l in limbo only")); continue;
@z
@x
err_print("! Missing left identifier of @@s");
@y
err_print(_("! Missing left identifier of @@s"));
@z
@x
err_print("! Missing right identifier of @@s");
@y
err_print(_("! Missing right identifier of @@s"));
@z
@x
fputs("\n! Never defined: <",stdout);
print_section_name(p); putchar('>'); mark_harmless;
@y
fputs(_("\n! Never defined: <"),stdout);
print_section_name(p); putchar('>'); mark_harmless;
@z
@x
fputs("\n! Never used: <",stdout);
print_section_name(p); putchar('>'); mark_harmless;
@y
fputs(_("\n! Never used: <"),stdout);
print_section_name(p); putchar('>'); mark_harmless;
@z
@x
@ In particular, the |finish_line| procedure is called near the very
beginning of phase two. We initialize the output variables in a slightly
tricky way so that the first line of the output file will be
`\.{\\input cwebmac}'.
@<Start \TEX/...@>=
out_ptr=out_buf+1; out_line=1; active_file=tex_file;
*out_ptr='c'; tex_printf("\\input cwebma");
@y
@ In particular, the |finish_line| procedure is called near the very
beginning of phase two. We initialize the output variables in a slightly
tricky way so that the first line of the output file will be dependent of
the user language set by the `\.{+l}' option and its argument. If you call
\.{CWEAVE} with `\.{+lX}' (or `\.{-lX}' as well), where `\.X' is the
(possibly empty) string of characters to the right of~`\.l', `\.X'~will be
prepended to `\.{cwebmac.tex}', e.g., if you call \.{CWEAVE} with
`\.{+ldeutsch}', you will receive the line `\.{\\input deutschcwebmac}'.
Without this option the first line of the output file will be
`\.{\\input cwebmac}'.
@<Start \TEX/...@>=
out_ptr=out_buf+1; out_line=1; active_file=tex_file; *out_ptr='c';
tex_puts("\\input ");
tex_printf(use_language);
tex_puts("cwebma");
@z
@x
printf("\n! Line had to be broken (output l. %d):\n",out_line);
@y
printf(_("\n! Line had to be broken (output l. %d):\n"),out_line);
@z
@x
default: err_print("! Double @@ should be used in limbo");
@y
default: err_print(_("! Double @@ should be used in limbo"));
@z
@x
@d app_tok(c) {if (tok_ptr+2>tok_mem_end) overflow("token"); *(tok_ptr++)=c;}
@y
@d app_tok(c) {if (tok_ptr+2>tok_mem_end) overflow(_("token")); *(tok_ptr++)=c;}
@z
@x
err_print("! Input ended in mid-comment");
@y
err_print(_("! Input ended in mid-comment"));
@z
@x
if (bal>1) err_print("! Missing } in comment");
@y
if (bal>1) err_print(_("! Missing } in comment"));
@z
@x
else {err_print("! Extra } in comment");
@y
else {err_print(_("! Extra } in comment"));
@z
@x
if (bal>1) err_print("! Missing } in comment");
@y
if (bal>1) err_print(_("! Missing } in comment"));
@z
@x
err_print("! Illegal use of @@ in comment");
@y
err_print(_("! Illegal use of @@ in comment"));
@z
@x
@d inner_tok_flag 5*id_flag /* signifies a token list in `\pb' */
@c
static void
print_text(@t\1\1@> /* prints a token list for debugging; not used in |main| */
@y
@d inner_tok_flag 5*id_flag /* signifies a token list in `\pb' */
@c
#if 0
static void
print_text(@t\1\1@> /* prints a token list for debugging; not used in |main| */
@z
@x
}
@y
}
#endif
@z
@x
@ @<Predecl...@>=@+static void print_text(text_pointer p);
@y
@ @<Predecl...@>=
#if 0
static void print_text(text_pointer p);
#endif
@z
@x
@<Cases for |exp|@>=
if (cat1==lbrace || cat1==int_like || cat1==decl) {
make_underlined(pp); big_app1(pp); big_app(indent); app(indent);
reduce(pp,1,fn_decl,0,1);
}
@y
@<Cases for |exp|@>=
if(cat1==lbrace || cat1==int_like || cat1==decl) {
make_underlined(pp); big_app1(pp);
if (indent_param_decl) {
big_app(indent); app(indent);
}
reduce(pp,1,fn_decl,0,1);
}
@z
@x
@ @<Cases for |decl_head|@>=
if (cat1==comma) {
big_app2(pp); big_app(' '); reduce(pp,2,decl_head,-1,33);
}
else if (cat1==ubinop) {
big_app1(pp); big_app('{'); big_app1(pp+1); big_app('}');
reduce(pp,2,decl_head,-1,34);
}
else if (cat1==exp && cat2!=lpar && cat2!=exp && cat2!=cast) {
make_underlined(pp+1); squash(pp,2,decl_head,-1,35);
}
else if ((cat1==binop||cat1==colon) && cat2==exp && (cat3==comma ||
cat3==semi || cat3==rpar))
squash(pp,3,decl_head,-1,36);
else if (cat1==cast) squash(pp,2,decl_head,-1,37);
else if (cat1==lbrace || cat1==int_like || cat1==decl) {
big_app1(pp); big_app(indent); app(indent); reduce(pp,1,fn_decl,0,38);
}
else if (cat1==semi) squash(pp,2,decl,-1,39);
@y
@ @<Cases for |decl_head|@>=
if (cat1==comma) {
big_app2(pp); big_app(' '); reduce(pp,2,decl_head,-1,33);
}
else if (cat1==ubinop) {
big_app1(pp); big_app('{'); big_app1(pp+1); big_app('}');
reduce(pp,2,decl_head,-1,34);
}
else if (cat1==exp && cat2!=lpar && cat2!=exp && cat2!=cast) {
make_underlined(pp+1); squash(pp,2,decl_head,-1,35);
}
else if ((cat1==binop||cat1==colon) && cat2==exp && (cat3==comma ||
cat3==semi || cat3==rpar))
squash(pp,3,decl_head,-1,36);
else if (cat1==cast) squash(pp,2,decl_head,-1,37);
else if (cat1==lbrace || cat1==int_like || cat1==decl) {
big_app1(pp);
if (indent_param_decl) {
big_app(indent); app(indent);
}
reduce(pp,1,fn_decl,0,38);
}
else if (cat1==semi) squash(pp,2,decl,-1,39);
@z
@x
@ @<Cases for |decl|@>=
if (cat1==decl) {
big_app1(pp); big_app(force); big_app1(pp+1);
reduce(pp,2,decl,-1,40);
}
else if (cat1==stmt || cat1==function) {
big_app1(pp); big_app(big_force);
big_app1(pp+1); reduce(pp,2,cat1,-1,41);
}
@y
@ @<Cases for |decl|@>=
if (cat1==decl) {
big_app1(pp); big_app(force); big_app1(pp+1);
reduce(pp,2,decl,-1,40);
}
else if (cat1==stmt || cat1==function) {
big_app1(pp);
if(order_decl_stmt) big_app(big_force);
else big_app(force);
big_app1(pp+1); reduce(pp,2,cat1,-1,41);
}
@z
@x
@ @<Cases for |fn_decl|@>=
if (cat1==decl) {
big_app1(pp); big_app(force); big_app1(pp+1); reduce(pp,2,fn_decl,0,51);
}
else if (cat1==stmt) {
big_app1(pp); app(outdent); app(outdent); big_app(force);
big_app1(pp+1); reduce(pp,2,function,-1,52);
}
@y
@ @<Cases for |fn_decl|@>=
if (cat1==decl) {
big_app1(pp); big_app(force); big_app1(pp+1); reduce(pp,2,fn_decl,0,51);
}
else if (cat1==stmt) {
big_app1(pp);
if (indent_param_decl) {
app(outdent); app(outdent);
}
big_app(force);
big_app1(pp+1); reduce(pp,2,function,-1,52);
}
@z
@x
overflow("token");
@y
overflow(_("token"));
@z
@x
overflow("text");
@y
overflow(_("text"));
@z
@x
if (tok_ptr+6>tok_mem_end) overflow("token");
@y
if (tok_ptr+6>tok_mem_end) overflow(_("token"));
@z
@x
printf("\nIrreducible scrap sequence in section %d:",section_count);
@y
printf(_("\nIrreducible scrap sequence in section %d:"),section_count);
@z
@x
printf("\nTracing after l. %d:\n",cur_line); mark_harmless;
@y
printf(_("\nTracing after l. %d:\n"),cur_line); mark_harmless;
@z
@x
overflow("scrap/token/text");
@y
overflow(_("scrap/token/text"));
@z
@x
else err_print("! Double @@ should be used in strings");
@y
else err_print(_("! Double @@ should be used in strings"));
@z
@x
if (next_control!='|') err_print("! Missing '|' after C text");
@y
if (next_control!='|') err_print(_("! Missing '|' after C text"));
@z
@x
if (stack_ptr==stack_end) overflow("stack");
@y
if (stack_ptr==stack_end) overflow(_("stack"));
@z
@x
fputs("\n! Illegal control code in section name: <",stdout);
@y
fputs(_("\n! Illegal control code in section name: <"),stdout);
@z
@x
fputs("\n! C text in section name didn't end: <",stdout);
@y
fputs(_("\n! C text in section name didn't end: <"),stdout);
@z
@x
if (j>buffer+long_buf_size-3) overflow("buffer");
@y
if (j>buffer+long_buf_size-3) overflow(_("buffer"));
@z
@x
if (j>buffer+long_buf_size-4) overflow("buffer");
@y
if (j>buffer+long_buf_size-4) overflow(_("buffer"));
@z
@x
reset_input(); if (show_progress) fputs("\nWriting the output file...",stdout);
@y
reset_input(); if (show_progress) fputs(_("\nWriting the output file..."),stdout);
@z
@x
err_print("! TeX string should be in C text only"); break;
@y
err_print(_("! TeX string should be in C text only")); break;
@z
@x
err_print("! You can't do that in TeX text"); break;
@y
err_print(_("! You can't do that in TeX text")); break;
@z
@x
err_print("! Improper macro definition");
@y
err_print(_("! Improper macro definition"));
@z
@x
default: err_print("! Improper macro definition"); break;
@y
default: err_print(_("! Improper macro definition")); break;
@z
@x
if (scrap_ptr!=scrap_info+2) err_print("! Improper format definition");
@y
if (scrap_ptr!=scrap_info+2) err_print(_("! Improper format definition"));
@z
@x
err_print("! You need an = sign after the section name");
@y
err_print(_("! You need an = sign after the section name"));
@z
@x
err_print("! You can't do that in C text");
@y
err_print(_("! You can't do that in C text"));
@z
@x
if (no_xref) {
finish_line();
out_str("\\end");
@.\\end@>
finish_line();
}
@y
if (no_xref) {
finish_line();
out_str("\\end");
@.\\end@>
active_file=tex_file;
}
@z
@x
phase=3; if (show_progress) fputs("\nWriting the index...",stdout);
@y
phase=3; if (show_progress) fputs(_("\nWriting the index..."),stdout);
@z
@x
fatal("! Cannot open index file ",idx_file_name);
@y
fatal(_("! Cannot open index file "),idx_file_name);
@z
@x
fatal("! Cannot open section file ",scn_file_name);
@y
fatal(_("! Cannot open section file "),scn_file_name);
@z
@x
@.\\end@>
finish_line();
fclose(active_file);
}
@y
@.\\end@>
}
finish_line(); fclose(active_file); active_file=NULL;
@<Update the result when it has changed@>@;
@z
@x
fputs("Done.",stdout);
@y
fputs(_("Done."),stdout);
@z
@x
if (sort_ptr>=scrap_info_end) overflow("sorting");
@y
if (sort_ptr>=scrap_info_end) overflow(_("sorting"));
@z
@x
puts("\nMemory usage statistics:");
@.Memory usage statistics:@>
printf("%ld names (out of %ld)\n",
(ptrdiff_t)(name_ptr-name_dir),(long)max_names);
printf("%ld cross-references (out of %ld)\n",
(ptrdiff_t)(xref_ptr-xmem),(long)max_refs);
printf("%ld bytes (out of %ld)\n",
(ptrdiff_t)(byte_ptr-byte_mem),(long)max_bytes);
puts("Parsing:");
printf("%ld scraps (out of %ld)\n",
(ptrdiff_t)(max_scr_ptr-scrap_info),(long)max_scraps);
printf("%ld texts (out of %ld)\n",
(ptrdiff_t)(max_text_ptr-tok_start),(long)max_texts);
printf("%ld tokens (out of %ld)\n",
(ptrdiff_t)(max_tok_ptr-tok_mem),(long)max_toks);
printf("%ld levels (out of %ld)\n",
(ptrdiff_t)(max_stack_ptr-stack),(long)stack_size);
puts("Sorting:");
printf("%ld levels (out of %ld)\n",
(ptrdiff_t)(max_sort_ptr-scrap_info),(long)max_scraps);
@y
puts(_("\nMemory usage statistics:"));
@.Memory usage statistics:@>
printf(_("%ld names (out of %ld)\n"),
(ptrdiff_t)(name_ptr-name_dir),(long)max_names);
printf(_("%ld cross-references (out of %ld)\n"),
(ptrdiff_t)(xref_ptr-xmem),(long)max_refs);
printf(_("%ld bytes (out of %ld)\n"),
(ptrdiff_t)(byte_ptr-byte_mem),(long)max_bytes);
puts(_("Parsing:"));
printf(_("%ld scraps (out of %ld)\n"),
(ptrdiff_t)(max_scr_ptr-scrap_info),(long)max_scraps);
printf(_("%ld texts (out of %ld)\n"),
(ptrdiff_t)(max_text_ptr-tok_start),(long)max_texts);
printf(_("%ld tokens (out of %ld)\n"),
(ptrdiff_t)(max_tok_ptr-tok_mem),(long)max_toks);
printf(_("%ld levels (out of %ld)\n"),
(ptrdiff_t)(max_stack_ptr-stack),(long)stack_size);
puts(_("Sorting:"));
printf(_("%ld levels (out of %ld)\n"),
(ptrdiff_t)(max_sort_ptr-scrap_info),(long)max_scraps);
@z
@x
@** Index.
@y
@** Extensions to \.{CWEB}. The following sections introduce new or improved
features that have been created by numerous contributors over the course of a
quarter century.
Care has been taken to keep the original section numbering intact, so this new
material should nicely integrate with the original ``\&{263.~Index}.''
@* Formatting alternatives.
\.{CWEAVE} indents declarations after old-style function definitions.
With the \.{-i} option they will come out flush left. You won't see
any difference if you use ANSI-style function definitions.
@d indent_param_decl flags['i'] /* should formal parameter declarations be indented? */
@<Set init...@>=
indent_param_decl=true;
@ The original manual described the \.{-o} option for \.{CWEAVE}, but this was
not yet present. Here is a simple implementation. The purpose is to suppress
the extra space between local variable declarations and the first statement in
a function block.
@d order_decl_stmt flags['o'] /* should declarations and statements be separated? */
@<Set init...@>=
order_decl_stmt=true;
@* Output file update. Most \CEE/ projects are controlled by a
\.{Makefile} that automatically takes care of the temporal dependecies
between the different source modules. It is suitable that \.{CWEB} doesn't
create new output for all existing files, when there are only changes to
some of them. Thus the \.{make} process will only recompile those modules
where necessary. The idea and basic implementation of this mechanism can
be found in the program \.{NUWEB} by Preston Briggs, to whom credit is due.
@<Update the result...@>=
if((tex_file=fopen(tex_file_name,"r"))!=NULL) {
char x[BUFSIZ],y[BUFSIZ];
int x_size,y_size,comparison=false;
if((check_file=fopen(check_file_name,"r"))==NULL)
fatal(_("! Cannot open output file "),check_file_name);
@.Cannot open output file@>
if (temporary_output) @<Compare the temporary output...@>@;
fclose(tex_file); tex_file=NULL;
fclose(check_file); check_file=NULL;
@<Take appropriate action depending on the comparison@>@;
} else
rename(check_file_name,tex_file_name); /* This was the first run */
strcpy(check_file_name,""); /* We want to get rid of the temporary file */
@ We hope that this runs fast on most systems.
@<Compare the temporary output to the previous output@>=
do {
x_size = fread(x,1,BUFSIZ,tex_file);
y_size = fread(y,1,BUFSIZ,check_file);
comparison = (x_size == y_size); /* Do not merge these statements! */
if(comparison) comparison = !memcmp(x,y,x_size);
} while(comparison && !feof(tex_file) && !feof(check_file));
@ Note the superfluous call to |remove| before |rename|. We're using it to
get around a bug in some implementations of |rename|.
@<Take appropriate action...@>=
if(comparison)
remove(check_file_name); /* The output remains untouched */
else {
remove(tex_file_name);
rename(check_file_name,tex_file_name);
}
@* Put ``version'' information in a single spot.
Don't do this at home, kids! Push our local macro to the variable in \.{COMMON}
for printing the |banner| and the |versionstring| from there.
@d max_banner 50
@<Common code...@>=
extern char cb_banner[];
@ @<Set init...@>=
strncpy(cb_banner,banner,max_banner-1);
@** Index.
@z
|