Debian Codegraph @

texk/web2c/cwebdir/ctang-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.30
20 \def\title{CTANGLE (Version 4.12.2)}
21 @y
22 \def\title{CTANGLE (Version 4.12.2 [\TeX~Live])}
23 @z
24
25 @x [0.0] l.34
26 \centerline{(Version 4.12.2)}
27 @y
28 \centerline{(Version 4.12.2 [\TeX~Live])}
29 @z
30
31 @x [0.0] l.36
32 \def\botofcontents{\vfill
33 @y
34 \def\covernote{\vbox{%
35 @z
36
37 @x [0.0] l.49
38 }
39 @y
40 }}\datecontentspage
41 @z
42
43 @x [1.1] l.64
44 @d banner "This is CTANGLE (Version 4.12.2)"
45 @y
46 @d banner "This is CTANGLE, Version 4.12.2"
47 /* will be extended by the \TeX~Live |versionstring| */
48 @z
49
50 @x [1.2] l.90
51 if (show_banner) puts(banner); /* print a ``banner line'' */
52 @y
53 if (show_banner) cb_show_banner(); /* print a ``banner line'' */
54 @z
55
56 @x [1.3] l.101
57 @i common.h
58 @y
59 @i comm-w2c.h
60 @z
61
62 @x [2.20] l.129
63 @ @d max_texts 4000 /* number of replacement texts, must be less than 10240 */
64 @d max_toks 270000 /* number of bytes in compressed \CEE/ code */
65 @y
66 @ @d max_texts 10239 /* number of replacement texts, must be less than 10240 */
67 @d max_toks 1000000 /* number of bytes in compressed \CEE/ code */
68 @z
69
70 @x [3.29] l.237
71 if (tok_ptr+2>tok_mem_end) overflow("token");
72 @y
73 if (tok_ptr+2>tok_mem_end) overflow(_("token"));
74 @z
75
76 @x [4.35] l.320
77 if (stack_ptr==stack_end) overflow("stack");
78 @y
79 if (stack_ptr==stack_end) overflow(_("stack"));
80 @z
81
82 @x [4.40] l.412
83 printf("%s","\n! Not present: <");
84 @y
85 printf("%s",_("\n! Not present: <"));
86 @z
87
88 @x [5.47] l.510
89 else overflow("output files");
90 @y
91 else overflow(_("output files"));
92 @z
93
94 @x [6.48] l.526
95 printf("%s","\n! No program text was specified."); mark_harmless();
96 @y
97 printf("%s",_("\n! No program text was specified.")); mark_harmless();
98 @z
99
100 @x [6.48] l.532
101 "\nWriting the output file (%s):" : @|
102 "\nWriting the output files: (%s)",C_file_name);
103 @y
104 _("\nWriting the output file (%s):") : @|
105 _("\nWriting the output files: (%s)"),C_file_name);
106 @z
107
108 @x [6.48] l.542
109 printf("%s","Done.");
110 @y
111 printf("%s",_("Done."));
112 @z
113
114 @x [6.50] l.556
115 @<Write all the named output files@>=
116 for (an_output_file=end_output_files; an_output_file>cur_out_file;) {
117 an_output_file--;
118 sprint_section_name(output_file_name,*an_output_file);
119 fclose(C_file);
120 if ((C_file=fopen(output_file_name,"wb"))==NULL)
121 fatal("! Cannot open output file ",output_file_name);
122 @.Cannot open output file@>
123 if (show_progress) { printf("\n(%s)",output_file_name); update_terminal(); }
124 cur_line=1;
125 @<Initialize the secondary output@>@;
126 @<Output material...@>@;
127 }
128 @y
129 @<Write all the named output files@>=
130 if (check_for_change) {
131 fclose(C_file); C_file=NULL;
132 @<Update the primary result when it has changed@>@;
133 }
134 for (an_output_file=end_output_files; an_output_file>cur_out_file;) {
135 an_output_file--;
136 sprint_section_name(output_file_name,*an_output_file);
137 if (check_for_change) @<Open the intermediate output file@>@;
138 else {
139 fclose(C_file);
140 if ((C_file=fopen(output_file_name,"wb"))==NULL)
141 fatal(_("! Cannot open output file "),output_file_name);
142 @.Cannot open output file@>
143 }
144 if (show_progress) { printf("\n(%s)",output_file_name); update_terminal(); }
145 cur_line=1;
146 @<Initialize the secondary output@>@;
147 @<Output material...@>@;
148 if (check_for_change) {
149 fclose(C_file); C_file=NULL;
150 @<Update the secondary results when they have changed@>@;
151 }
152 }
153 if (check_for_change)
154 strcpy(check_file_name,""); /* We want to get rid of the temporary file */
155 @z
156
157 @x [6.54] l.616
158 else if (a<050000) confusion("macro defs have strange char");
159 @y
160 else if (a<050000) confusion(_("macro defs have strange char"));
161 @z
162
163 @x [6.59] l.703
164 @ @<Case of an identifier@>=@t\1\quad@>
165 @y
166 @ Nowadays, most computer files are encoded in some form of ``Unicode''. A very
167 convenient special case is ``UTF-8'', a variable-length multi-byte encoding. In
168 order to avoid major surgery for the transliteration feature---as tempting as
169 the extended notation \.{@@l c3bc ue} might be---, \.{CTANGLE}
170 accepts the \.{+u} option to activate a ``poor man's UTF-8'' mechanism. The
171 first in a sequence of up to four high-bit bytes (amounting to more than
172 $2^{20}$~possible character representations) determines the number of bytes
173 used to represent the next character. Instead of extending the |translit| table
174 to this multi-byte scenario, we simply strip all but the last byte and use this
175 as the transliteration index.
176
177 % Exercise 11.6 from the TeXbook:
178 \def\frac#1/#2{\leavevmode\kern.1em\raise.5ex\hbox{\the\scriptfont0 #1}
179 \kern-.1em/\kern-.15em\lower.25ex\hbox{\the\scriptfont0 #2}}
180
181 \&{Example:} While in ``classic ASCII'' the German word {\it gr\"un\/} could be
182 treated with transliteration \.{@@l fc ue} (from codepage ISO/IEC~8859-1) to
183 get \.{gruen} as suggested above, in UTF-8 you'd be advised to use \.{@@l bc
184 ue} instead, because character {\it \"u\/} (latin small letter u with
185 diaeresis) is encoded as the two-byte sequence \.{c3 bc}, indicated by the
186 initial three bits of byte \.{c3} (\.{1100 0011}). Note that this simple
187 approach leads to the collision with character $\frac1/4$ (vulgar fraction one
188 quarter) with its two-byte encoding \.{c2 bc}.
189
190 @d transliterate_utf_eight flags['u']
191
192 @<Case of an identifier@>=@t\1\quad@>
193 @z
194
195 @x [6.59] l.708
196 if (ishigh(*j)) C_printf("%s",translit[(eight_bits)(*j)-0200]);
197 @^high-bit character handling@>
198 @y
199 if (ishigh(*j)) {
200 @^high-bit character handling@>
201 if (transliterate_utf_eight) {
202 if ((eight_bits)(*j)>=0360) j+=3;
203 else if ((eight_bits)(*j)>=0340) j+=2;
204 else if ((eight_bits)(*j)>=0300) j+=1;
205 }
206 C_printf("%s",translit[(eight_bits)(*j)-0200]);
207 }
208 @z
209
210 @x [7.67] l.840
211 err_print("! Input ended in mid-comment");
212 @y
213 err_print(_("! Input ended in mid-comment"));
214 @z
215
216 @x [7.67] l.853
217 err_print("! Section name ended in mid-comment"); loc--;
218 @y
219 err_print(_("! Section name ended in mid-comment")); loc--;
220 @z
221
222 @x [8.74] l.1004
223 err_print("! String didn't end"); loc=limit; break;
224 @y
225 err_print(_("! String didn't end")); loc=limit; break;
226 @z
227
228 @x [8.74] l.1008
229 err_print("! Input ended in middle of string"); loc=buffer; break;
230 @y
231 err_print(_("! Input ended in middle of string")); loc=buffer; break;
232 @z
233
234 @x [8.74] l.1026
235 printf("%s","\n! String too long: ");
236 @y
237 printf("%s",_("\n! String too long: "));
238 @z
239
240 @x [8.75] l.1041
241 case translit_code: err_print("! Use @@l in limbo only"); continue;
242 @y
243 case translit_code: err_print(_("! Use @@l in limbo only")); continue;
244 @z
245
246 @x [8.75] l.1046
247 err_print("! Double @@ should be used in control text");
248 @y
249 err_print(_("! Double @@ should be used in control text"));
250 @z
251
252 @x [8.76] l.1070
253 err_print("! Double @@ should be used in ASCII constant");
254 @y
255 err_print(_("! Double @@ should be used in ASCII constant"));
256 @z
257
258 @x [8.76] l.1076
259 err_print("! String didn't end"); loc=limit-1; break;
260 @y
261 err_print(_("! String didn't end")); loc=limit-1; break;
262 @z
263
264 @x [8.79] l.1108
265 err_print("! Input ended in section name");
266 @y
267 err_print(_("! Input ended in section name"));
268 @z
269
270 @x [8.79] l.1121
271 printf("%s","\n! Section name too long: ");
272 @y
273 printf("%s",_("\n! Section name too long: "));
274 @z
275
276 @x [8.80] l.1135
277 err_print("! Section name didn't end"); break;
278 @y
279 err_print(_("! Section name didn't end")); break;
280 @z
281
282 @x [8.80] l.1139
283 err_print("! Nesting of section names not allowed"); break;
284 @y
285 err_print(_("! Nesting of section names not allowed")); break;
286 @z
287
288 @x [8.81] l.1153
289 if (loc>=limit) err_print("! Verbatim string didn't end");
290 @y
291 if (loc>=limit) err_print(_("! Verbatim string didn't end"));
292 @z
293
294 @x [9.82] l.1177
295 @d app_repl(c) {
296 if (tok_ptr==tok_mem_end) overflow("token");
297 else *(tok_ptr++)=(eight_bits)c;
298 }
299 @y
300 @d app_repl(c) {
301 if (tok_ptr==tok_mem_end) overflow(_("token"));
302 else *(tok_ptr++)=(eight_bits)c;
303 }
304 @z
305
306 @x [9.83] l.1204
307 if (text_ptr>text_info_end) overflow("text");
308 @y
309 if (text_ptr>text_info_end) overflow(_("text"));
310 @z
311
312 @x [9.86] l.1250
313 case output_defs_code: if (t!=section_name) err_print("! Misplaced @@h");
314 @y
315 case output_defs_code: if (t!=section_name) err_print(_("! Misplaced @@h"));
316 @z
317
318 @x [9.86] l.1268
319 err_print("! @@d, @@f and @@c are ignored in C text"); continue;
320 @y
321 err_print(_("! @@d, @@f and @@c are ignored in C text")); continue;
322 @z
323
324 @x [9.87] l.1278
325 if (*try_loc=='=') err_print ("! Missing `@@ ' before a named section");
326 @y
327 if (*try_loc=='=') err_print (_("! Missing `@@ ' before a named section"));
328 @z
329
330 @x [9.88] l.1295
331 else err_print("! Double @@ should be used in string");
332 @y
333 else err_print(_("! Double @@ should be used in string"));
334 @z
335
336 @x [9.89] l.1344
337 default: err_print("! Unrecognized escape sequence");
338 @y
339 default: err_print(_("! Unrecognized escape sequence"));
340 @z
341
342 @x [10.93] l.1417
343 err_print("! Definition flushed, must start with identifier");
344 @y
345 err_print(_("! Definition flushed, must start with identifier"));
346 @z
347
348 @x [10.100] l.1498
349 err_print("! Double @@ should be used in control text");
350 @y
351 err_print(_("! Double @@ should be used in control text"));
352 @z
353
354 @x [10.100] l.1501
355 } @=/* otherwise fall through */@>@;
356 default: err_print("! Double @@ should be used in limbo");
357 @y
358 } @=/* otherwise fall through */@>@;
359 default: err_print(_("! Double @@ should be used in limbo"));
360 @z
361
362 @x [10.102] l.1516
363 err_print("! Improper hex number following @@l");
364 @y
365 err_print(_("! Improper hex number following @@l"));
366 @z
367
368 @x [10.102] l.1526
369 err_print("! Replacement string in @@l too long");
370 @y
371 err_print(_("! Replacement string in @@l too long"));
372 @z
373
374 @x [10.103] l.1540
375 puts("\nMemory usage statistics:");
376 printf("%td names (out of %ld)\n",@^system dependencies@>
377 (ptrdiff_t)(name_ptr-name_dir),(long)max_names);
378 printf("%td replacement texts (out of %ld)\n",
379 (ptrdiff_t)(text_ptr-text_info),(long)max_texts);
380 printf("%td bytes (out of %ld)\n",
381 (ptrdiff_t)(byte_ptr-byte_mem),(long)max_bytes);
382 printf("%td tokens (out of %ld)\n",
383 @y
384 puts(_("\nMemory usage statistics:"));
385 printf(_("%td names (out of %ld)\n"),@^system dependencies@>
386 (ptrdiff_t)(name_ptr-name_dir),(long)max_names);
387 printf(_("%td replacement texts (out of %ld)\n"),
388 (ptrdiff_t)(text_ptr-text_info),(long)max_texts);
389 printf(_("%td bytes (out of %ld)\n"),
390 (ptrdiff_t)(byte_ptr-byte_mem),(long)max_bytes);
391 printf(_("%td tokens (out of %ld)\n"),
392 @z
393
394 @x [11.104] l.1551
395 @** Index.
396 @y
397 @** Extensions to {\tentex CWEB}. The following sections introduce new or
398 improved features that have been created by numerous contributors over the
399 course of a quarter century.
400
401 Care has been taken to keep the original section numbering intact, so this new
402 material should nicely integrate with the original ``\&{104.~Index}.''
403
404 @* Output file update. Most \CEE/ projects are controlled by a \.{Makefile}
405 that automatically takes care of the temporal dependencies between the different
406 source modules. It may be convenient that \.{CWEB} doesn't create new output
407 for all existing files, when there are only changes to some of them. Thus the
408 \.{make} process will only recompile those modules where necessary. You can
409 activate this feature with the `\.{+c}' command-line option. The idea and basic
410 implementation of this mechanism can be found in the program \.{NUWEB} by
411 Preston Briggs, to whom credit is due.
412
413 @<Open the intermediate output file@>= {
414 if ((C_file=fopen(output_file_name,"a"))==NULL)
415 fatal(_("! Cannot open output file "),output_file_name);
416 @.Cannot open output file@>
417 else fclose(C_file); /* Test accessability */
418 if((C_file=fopen(check_file_name,"wb"))==NULL)
419 fatal(_("! Cannot open output file "),check_file_name);
420 }
421
422 @ @<Update the primary result...@>=
423 if((C_file=fopen(C_file_name,"r"))!=NULL) {
424 @<Set up the comparison of temporary output@>@;
425 @<Create the primary output depending on the comparison@>@;
426 } else
427 rename(check_file_name,C_file_name); /* This was the first run */
428
429 @ @<Set up the comparison of temporary output@>=
430 bool comparison=false;
431
432 if((check_file=fopen(check_file_name,"r"))==NULL)
433 fatal(_("! Cannot open output file "),check_file_name);
434 @.Cannot open output file@>
435
436 @<Compare the temporary output...@>@;
437
438 fclose(C_file); C_file=NULL;
439 fclose(check_file); check_file=NULL;
440
441 @ We hope that this runs fast on most systems.
442
443 @<Compare the temporary output to the previous output@>=
444 do {
445 char x[BUFSIZ],y[BUFSIZ];
446 int x_size = fread(x,sizeof(char),BUFSIZ,C_file);
447 int y_size = fread(y,sizeof(char),BUFSIZ,check_file);
448 comparison = (x_size == y_size) && !memcmp(x,y,x_size);
449 } while(comparison && !feof(C_file) && !feof(check_file));
450
451 @ Note the superfluous call to |remove| before |rename|. We're using it to
452 get around a bug in some implementations of |rename|.@^system dependencies@>
453
454 @<Create the primary output...@>=
455 if(comparison)
456 remove(check_file_name); /* The output remains untouched */
457 else {
458 remove(C_file_name);
459 rename(check_file_name,C_file_name);
460 }
461
462 @ The author of a \.{CWEB} program may want to write the \\{secondary} output
463 instead of to a file (in \.{@@(...@@>}) to \.{/dev/null} or \.{/dev/stdout} or
464 \.{/dev/stderr}. We must take care of the \\{temporary} output already written
465 to a file and finally get rid of that file.
466
467 @<Update the secondary results...@>=
468 if(0==strcmp("/dev/stdout",output_file_name))@/
469 @<Redirect temporary output to \.{/dev/stdout}@>@;
470 else if(0==strcmp("/dev/stderr",output_file_name))@/
471 @<Redirect temporary output to \.{/dev/stderr}@>@;
472 else if(0==strcmp("/dev/null",output_file_name))@/
473 @<Redirect temporary output to \.{/dev/null}@>@;
474 else { /* Hopefully a regular output file */
475 if((C_file=fopen(output_file_name,"r"))!=NULL) {
476 @<Set up the comparison of temporary output@>@;
477 @<Create the secondary output depending on the comparison@>@;
478 } else
479 rename(check_file_name,output_file_name); /* This was the first run */
480 }
481
482 @ Again, we use a call to |remove| before |rename|.
483
484 @<Create the secondary output...@>=
485 if(comparison)
486 remove(check_file_name); /* The output remains untouched */
487 else {
488 remove(output_file_name);
489 rename(check_file_name,output_file_name);
490 }
491
492 @ Copy secondary output to |stdout|.
493
494 @<Redirect temporary output to \.{/dev/stdout}@>={
495 @<Setup system redirection@>@;
496 do {
497 in_size = fread(in_buf,sizeof(char),BUFSIZ,check_file);
498 in_buf[in_size]='\0';
499 fprintf(stdout,"%s",in_buf);
500 } while(!feof(check_file));@/
501 fclose(check_file); check_file=NULL;
502 @<Create the secondary output...@>@;
503 }
504
505 @ Copy secondary output to |stderr|.
506
507 @<Redirect temporary output to \.{/dev/stderr}@>={
508 @<Setup system redirection@>@;
509 do {
510 in_size = fread(in_buf,sizeof(char),BUFSIZ,check_file);
511 in_buf[in_size]='\0';
512 fprintf(stderr,"%s",in_buf);
513 } while(!feof(check_file));@/
514 fclose(check_file); check_file=NULL;
515 @<Create the secondary output...@>@;
516 }
517
518 @ No copying necessary, just remove the temporary output file.
519
520 @<Redirect temporary output to \.{/dev/null}@>={
521 bool comparison=true;
522 @<Create the secondary output...@>@;
523 }
524
525 @ @<Setup system redirection@>=
526 char in_buf[BUFSIZ+1];
527 int in_size;
528 bool comparison=true;
529 if((check_file=fopen(check_file_name,"r"))==NULL)
530 fatal(_("! Cannot open output file "),check_file_name);
531 @.Cannot open output file@>
532
533 @* Print ``version'' information.
534 Don't do this at home, kids! Push our local macro to the variable in \.{COMMON}
535 for printing the |banner| and the |versionstring| from there.
536
537 @d max_banner 50
538
539 @<Common code...@>=
540 extern char cb_banner[];
541
542 @ @<Set init...@>=
543 strncpy(cb_banner,banner,max_banner-1);
544
545 @** Index.
546 @z
547