This repository has been archived by the owner on Jun 19, 2023. It is now read-only.
/
comm-w2c.ch
1412 lines (1236 loc) · 37.3 KB
/
comm-w2c.ch
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
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
@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}-w2c.ch has been @>
@q created from the set of change files {comm,ctang,cweav}-patch.ch, @>
@q {comm,ctang,cweav}-ansi.ch, {comm,ctang,cweav}-extensions.ch, @>
@q {comm,ctang,cweav}-output.ch, {comm,ctang,cweav}-i18n.ch, and @>
@q cweav-twill.ch for CTWILL, and {comm,ctang,cweav,ctwill}-texlive.ch @>
@q with the 'tie' processor and is used as a monolithic changefile for @>
@q {common,ctangle,cweave}.w in TeX Live. @>
@q Please send comments, suggestions, etc. to tex-k@@tug.org. @>
@x
\def\title{Common code for CTANGLE and CWEAVE (Version 3.64)}
@y
\def\Kpathsea/{{\mc KPATHSEA\spacefactor1000}}
\def\title{Common code for CTANGLE and CWEAVE (\TeX~Live)}
@z
@x
\centerline{(Version 3.64)}
@y
\centerline{(Version 3.64 [\TeX~Live])}
@z
@x
@s not_eq normal @q unreserve a C++ keyword @>
@y
@s boolean int
@s uint8_t int
@s uint16_t int
@z
@x
|program|.
@d ctangle 0
@d cweave 1
@y
|program|. And \.{CTWILL} adds some extra twists.
@d ctangle 0
@d cweave 1
@d ctwill 2
@z
@x
typedef short boolean;
boolean program; /* \.{CWEAVE} or \.{CTANGLE}? */
@y
int program; /* \.{CWEAVE} or \.{CTANGLE} or \.{CTWILL}? */
@z
@x
void
common_init()
@y
void
common_init(void)
@z
@x
@<Initialize pointers@>;
@<Set the default options common to \.{CTANGLE} and \.{CWEAVE}@>;
@<Scan arguments and open output files@>;
@y
@<Initialize pointers@>@;
@<Set up |PROGNAME| feature and initialize the search path mechanism@>@;
@<Set locale and bind language catalogs@>@;
@<Set the default options common to \.{CTANGLE} and \.{CWEAVE}@>@;
@<Scan arguments and open output files@>@;
@z
@x
@d not_eq 032 /* `\.{!=}'\,; corresponds to MIT's {\tentex\char'32} */
@y
@d non_eq 032 /* `\.{!=}'\,; corresponds to MIT's {\tentex\char'32} */
@z
@x
@d buf_size 100 /* for \.{CWEAVE} and \.{CTANGLE} */
@y
@d buf_size 1000 /* for \.{CWEAVE} and \.{CTANGLE} */
@z
@x
@d xisspace(c) (isspace(c)&&((unsigned char)c<0200))
@d xisupper(c) (isupper(c)&&((unsigned char)c<0200))
@y
@d xisspace(c) (isspace((eight_bits)c)&&((eight_bits)c<0200))
@d xisupper(c) (isupper((eight_bits)c)&&((eight_bits)c<0200))
@z
@x
int input_ln(fp) /* copies a line into |buffer| or returns 0 */
FILE *fp; /* what file to read from */
@y
static boolean input_ln(@t\1\1@> /* copies a line into |buffer| or returns 0 */
FILE *fp@t\2\2@>) /* what file to read from */
@z
@x
if ((*(k++) = c) != ' ') limit = k;
@y
if ((*(k++) = c) != ' ' && c != '\r') limit = k;
@z
@x
ungetc(c,fp); loc=buffer; err_print("! Input line too long");
@y
ungetc(c,fp); loc=buffer; err_print(_("! Input line too long"));
@z
@x
@d max_file_name_length 60
@y
@d max_file_name_length 1024
@z
@x
char alt_web_file_name[max_file_name_length]; /* alternate name to try */
@y
@z
@x
@d lines_dont_match (change_limit-change_buffer != limit-buffer ||
strncmp(buffer, change_buffer, limit-buffer))
@y
@d lines_dont_match (change_limit-change_buffer != limit-buffer || @|
strncmp(buffer, change_buffer, (size_t)(limit-buffer)))
@z
@x
void
prime_the_change_buffer()
@y
static void
prime_the_change_buffer(void)
@z
@x
if (xisupper(buffer[1])) buffer[1]=tolower(buffer[1]);
@y
if (xisupper(buffer[1])) buffer[1]=tolower((eight_bits)buffer[1]);
@z
@x
err_print("! Missing @@x in change file");
@y
err_print(_("! Missing @@x in change file"));
@z
@x
err_print("! Change file ended after @@x");
@y
err_print(_("! Change file ended after @@x"));
@z
@x
change_limit=change_buffer+(limit-buffer);
strncpy(change_buffer,buffer,limit-buffer+1);
@y
change_limit=change_buffer+(ptrdiff_t)(limit-buffer);
strncpy(change_buffer,buffer,(size_t)(limit-buffer+1));
@z
@x
void
check_change() /* switches to |change_file| if the buffers match */
@y
static void
check_change(void) /* switches to |change_file| if the buffers match */
@z
@x
err_print("! Change file ended before @@y");
@y
err_print(_("! Change file ended before @@y"));
@z
@x
char xyz_code=xisupper(buffer[1])? tolower(buffer[1]): buffer[1];
@y
char xyz_code=xisupper(buffer[1])? tolower((eight_bits)buffer[1]): buffer[1];
@z
@x
err_print("! CWEB file ended during a change");
@y
err_print(_("! CWEB file ended during a change"));
@z
@x
loc=buffer+2; err_print("! Where is the matching @@y?");
@y
loc=buffer+2; err_print(_("! Where is the matching @@y?"));
@z
@x
err_print("of the preceding lines failed to match");
@y
err_print(_("of the preceding lines failed to match"));
@z
@x
void
reset_input()
@y
void
reset_input(void)
@z
@x
if ((web_file=fopen(web_file_name,"r"))==NULL) {
strcpy(web_file_name,alt_web_file_name);
if ((web_file=fopen(web_file_name,"r"))==NULL)
fatal("! Cannot open input file ", web_file_name);
}
@y
if ((found_filename=kpse_find_cweb(web_file_name))==NULL || @|
(web_file=fopen(found_filename,"r"))==NULL) {
fatal(_("! Cannot open input file "), web_file_name);
} else if (strlen(found_filename) < max_file_name_length) {
/* Copy name for |#line| directives. */
if (strcmp(web_file_name, found_filename))
strcpy(web_file_name, found_filename +
((strncmp(found_filename,"./",2)==0) ? 2 : 0));
free(found_filename);
} else fatal(_("! Filename too long\n"), found_filename);
@z
@x
if ((change_file=fopen(change_file_name,"r"))==NULL)
fatal("! Cannot open change file ", change_file_name);
@y
if ((found_filename=kpse_find_cweb(change_file_name))==NULL || @|
(change_file=fopen(found_filename,"r"))==NULL) {
fatal(_("! Cannot open change file "), change_file_name);
} else if (strlen(found_filename) < max_file_name_length) {
/* Copy name for |#line| directives. */
if (strcmp(change_file_name, found_filename))
strcpy(change_file_name, found_filename +
((strncmp(found_filename,"./",2)==0) ? 2 : 0));
free(found_filename);
} else fatal(_("! Filename too long\n"), found_filename);
@z
@x
@d max_sections 2000 /* number of identifiers, strings, section names;
must be less than 10240 */
@y
@d max_sections 10239 /* number of identifiers, strings, section names;
must be less than 10240 */
@z
@x
typedef unsigned short sixteen_bits;
@y
typedef uint8_t eight_bits;
typedef uint16_t sixteen_bits;
@z
@x
int get_line() /* inputs the next line */
@y
boolean get_line(void) /* inputs the next line */
@z
@x
err_print("! Include file name not given");
@y
err_print(_("! Include file name not given"));
@z
@x
err_print("! Too many nested includes");
@y
err_print(_("! Too many nested includes"));
@z
@x
@ When an \.{@@i} line is found in the |cur_file|, we must temporarily
stop reading it and start reading from the named include file. The
\.{@@i} line should give a complete file name with or without
double quotes.
If the environment variable \.{CWEBINPUTS} is set, or if the compiler flag
of the same name was defined at compile time,
\.{CWEB} will look for include files in the directory thus named, if
it cannot find them in the current directory.
(Colon-separated paths are not supported.)
The remainder of the \.{@@i} line after the file name is ignored.
@y
@ When an \.{@@i} line is found in the |cur_file|, we must temporarily
stop reading it and start reading from the named include file. The
\.{@@i} line should give a complete file name with or without
double quotes.
The actual file lookup is done with the help of the \Kpathsea/ library;
see section~\X90:File lookup with \Kpathsea/\X~for details. % FIXME
The remainder of the \.{@@i} line after the file name is ignored.
@z
@x
err_print("! Include file name too long"); goto restart;}
@y
err_print(_("! Include file name too long")); goto restart;}
@z
@x
char temp_file_name[max_file_name_length];
char *cur_file_name_end=cur_file_name+max_file_name_length-1;
char *k=cur_file_name, *kk;
int l; /* length of file name */
@y
char *cur_file_name_end=cur_file_name+max_file_name_length-1;
char *k=cur_file_name;
@z
@x
if ((cur_file=fopen(cur_file_name,"r"))!=NULL) {
@y
if ((found_filename=kpse_find_cweb(cur_file_name))!=NULL && @|
(cur_file=fopen(found_filename,"r"))!=NULL) {
/* Copy name for |#line| directives. */
if (strlen(found_filename) < max_file_name_length) {
if (strcmp(cur_file_name, found_filename))
strcpy(cur_file_name, found_filename +
((strncmp(found_filename,"./",2)==0) ? 2 : 0));
free(found_filename);
} else fatal(_("! Filename too long\n"), found_filename);
@z
@x
kk=getenv("CWEBINPUTS");
if (kk!=NULL) {
if ((l=strlen(kk))>max_file_name_length-2) too_long();
strcpy(temp_file_name,kk);
}
else {
#ifdef CWEBINPUTS
if ((l=strlen(CWEBINPUTS))>max_file_name_length-2) too_long();
strcpy(temp_file_name,CWEBINPUTS);
#else
l=0;
#endif /* |CWEBINPUTS| */
}
if (l>0) {
if (k+l+2>=cur_file_name_end) too_long();
@.Include file name ...@>
for (; k>= cur_file_name; k--) *(k+l+1)=*k;
strcpy(cur_file_name,temp_file_name);
cur_file_name[l]='/'; /* \UNIX/ pathname separator */
if ((cur_file=fopen(cur_file_name,"r"))!=NULL) {
cur_line=0; print_where=1;
goto restart; /* success */
}
}
include_depth--; err_print("! Cannot open include file"); goto restart;
@y
include_depth--; err_print(_("! Cannot open include file")); goto restart;
@z
@x
err_print("! Change file ended without @@z");
@y
err_print(_("! Change file ended without @@z"));
@z
@x
if (xisupper(buffer[1])) buffer[1]=tolower(buffer[1]);
@y
if (xisupper(buffer[1])) buffer[1]=tolower((eight_bits)buffer[1]);
@z
@x
err_print("! Where is the matching @@z?");
@y
err_print(_("! Where is the matching @@z?"));
@z
@x
void
check_complete(){
if (change_limit!=change_buffer) { /* |changing| is 0 */
strncpy(buffer,change_buffer,change_limit-change_buffer+1);
limit=buffer+(int)(change_limit-change_buffer);
@y
void
check_complete(void) {
if (change_limit!=change_buffer) { /* |changing| is 0 */
strncpy(buffer,change_buffer,(size_t)(change_limit-change_buffer+1));
limit=buffer+(ptrdiff_t)(change_limit-change_buffer);
@z
@x
err_print("! Change file entry did not match");
@y
err_print(_("! Change file entry did not match"));
@z
@x
@d max_bytes 90000 /* the number of bytes in identifiers,
index entries, and section names; must be less than $2^{24}$ */
@d max_names 4000 /* number of identifiers, strings, section names;
must be less than 10240 */
@y
@d max_bytes 1000000 /* the number of bytes in identifiers,
index entries, and section names; must be less than $2^{24}$ */
@d max_names 10239 /* number of identifiers, strings, section names;
must be less than 10240 */
@z
@x
@d length(c) (c+1)->byte_start-(c)->byte_start /* the length of a name */
@y
@d length(c) (size_t)((c+1)->byte_start-(c)->byte_start) /* the length of a name */
@z
@x
@d hash_size 353 /* should be prime */
@y
@d hash_size 8501 /* should be prime */
@z
@x
extern int names_match();
@y
extern boolean names_match(name_pointer,const char *,size_t,eight_bits);@/
@z
@x
name_pointer
id_lookup(first,last,t) /* looks up a string in the identifier table */
char *first; /* first character of string */
char *last; /* last character of string plus one */
char t; /* the |ilk|; used by \.{CWEAVE} only */
{
char *i=first; /* position in |buffer| */
@y
name_pointer
id_lookup(@t\1\1@> /* looks up a string in the identifier table */
const char *first, /* first character of string */
const char *last, /* last character of string plus one */
char t@t\2\2@>) /* the |ilk|; used by \.{CWEAVE} only */
{
const char *i=first; /* position in |buffer| */
@z
@x
l=last-first; /* compute the length */
@y
l=(int)(last-first); /* compute the length */
@z
@x
void init_p();
@y
extern void init_p(name_pointer,eight_bits);@/
@z
@x
if (byte_ptr+l>byte_mem_end) overflow("byte memory");
if (name_ptr>=name_dir_end) overflow("name");
@y
if (byte_ptr+l>byte_mem_end) overflow(_("byte memory"));
if (name_ptr>=name_dir_end) overflow(_("name"));
@z
@x
if (program==cweave) init_p(p,t);
@y
init_p(p,t);
@z
@x
void
print_section_name(p)
name_pointer p;
@y
void
print_section_name(
name_pointer p)
@z
@x
term_write(s,ss-s); p=q->link; q=p;
} else {
term_write(s,ss+1-s); p=name_dir; q=NULL;
@y
term_write(s,(size_t)(ss-s)); p=q->link; q=p;
} else {
term_write(s,(size_t)(ss+1-s)); p=name_dir; q=NULL;
@z
@x
void
sprint_section_name(dest,p)
char*dest;
name_pointer p;
@y
void
sprint_section_name(
char *dest,
name_pointer p)
@z
@x
strncpy(dest,s,ss-s), dest+=ss-s;
@y
strncpy(dest,s,(size_t)(ss-s)), dest+=ss-s;
@z
@x
void
print_prefix_name(p)
name_pointer p;
@y
void
print_prefix_name(
name_pointer p)
@z
@x
int web_strcmp(j,j_len,k,k_len) /* fuller comparison than |strcmp| */
char *j, *k; /* beginning of first and second strings */
int j_len, k_len; /* length of strings */
@y
static int web_strcmp(@t\1\1@> /* fuller comparison than |strcmp| */
char *j, /* beginning of first string */
int j_len, /* length of first string */
char *k, /* beginning of second string */
int k_len@t\2\2@>) /* length of second string */
@z
@x
extern void init_node();
@y
extern void init_node(name_pointer);@/
@z
@x
name_pointer
add_section_name(par,c,first,last,ispref) /* install a new node in the tree */
name_pointer par; /* parent of new node */
int c; /* right or left? */
char *first; /* first character of section name */
char *last; /* last character of section name, plus one */
int ispref; /* are we adding a prefix or a full name? */
@y
static name_pointer
add_section_name(@t\1\1@> /* install a new node in the tree */
name_pointer par, /* parent of new node */
int c, /* right or left? */
char *first, /* first character of section name */
char *last, /* last character of section name, plus one */
int ispref@t\2\2@>) /* are we adding a prefix or a full name? */
@z
@x
int name_len=last-first+ispref; /* length of section name */
@y
int name_len=(int)(last-first)+ispref; /* length of section name */
@z
@x
if (s+name_len>byte_mem_end) overflow("byte memory");
if (name_ptr+1>=name_dir_end) overflow("name");
@y
if (s+name_len>byte_mem_end) overflow(_("byte memory"));
if (name_ptr+1>=name_dir_end) overflow(_("name"));
@z
@x
void
extend_section_name(p,first,last,ispref)
name_pointer p; /* name to be extended */
char *first; /* beginning of extension text */
char *last; /* one beyond end of extension text */
int ispref; /* are we adding a prefix or a full name? */
@y
static void
extend_section_name(@t\1\1@>
name_pointer p, /* name to be extended */
char *first, /* beginning of extension text */
char *last, /* one beyond end of extension text */
int ispref@t\2\2@>) /* are we adding a prefix or a full name? */
@z
@x
int name_len=last-first+ispref;
@y
int name_len=(int)(last-first)+ispref;
@z
@x
if (name_ptr>=name_dir_end) overflow("name");
@y
if (name_ptr>=name_dir_end) overflow(_("name"));
@z
@x
if (s+name_len>byte_mem_end) overflow("byte memory");
@y
if (s+name_len>byte_mem_end) overflow(_("byte memory"));
@z
@x
name_pointer
section_lookup(first,last,ispref) /* find or install section name in tree */
char *first, *last; /* first and last characters of new name */
int ispref; /* is the new name a prefix or a full name? */
@y
name_pointer
section_lookup(@t\1\1@> /* find or install section name in tree */
char *first,char *last, /* first and last characters of new name */
int ispref@t\2\2@>) /* is the new name a prefix or a full name? */
@z
@x
int name_len=last-first+1;
@y
int name_len=(int)(last-first)+1;
@z
@x
printf("\n! Ambiguous prefix: matches <");
@y
fputs(_("\n! Ambiguous prefix: matches <"),stdout);
@z
@x
printf(">\n and <");
@y
fputs(_(">\n and <"),stdout);
@z
@x
printf("\n! New name is a prefix of <");
@y
fputs(_("\n! New name is a prefix of <"),stdout);
@z
@x
printf("\n! New name extends <");
@y
fputs(_("\n! New name extends <"),stdout);
@z
@x
printf("\n! Section name incompatible with <");
@y
fputs(_("\n! Section name incompatible with <"),stdout);
@z
@x
printf(">,\n which abbreviates <");
@y
fputs(_(">,\n which abbreviates <"),stdout);
@z
@x
int section_name_cmp();
@y
static int section_name_cmp(char **,int,name_pointer);@/
@z
@x
int section_name_cmp(pfirst,len,r)
char **pfirst; /* pointer to beginning of comparison string */
int len; /* length of string */
name_pointer r; /* section name being compared */
@y
static int section_name_cmp(@t\1\1@>
char **pfirst, /* pointer to beginning of comparison string */
int len, /* length of string */
name_pointer r@t\2\2@>) /* section name being compared */
@z
@x
*pfirst=first+(ss-s);
@y
*pfirst=first+(ptrdiff_t)(ss-s);
@z
@x
if (q!=name_dir) {len -= ss-s; s=q->byte_start; r=q; continue;}
@y
if (q!=name_dir) {len -= (int)(ss-s); s=q->byte_start; r=q; continue;}
@z
@x
|equiv_or_xref| as a pointer to a |char|.
@<More elements of |name...@>=
char *equiv_or_xref; /* info corresponding to names */
@y
|equiv_or_xref| as a pointer to |void|.
@<More elements of |name...@>=
void *equiv_or_xref; /* info corresponding to names */
@z
@x
void err_print();
@y
extern void err_print(const char *);@/
@z
@x
void
err_print(s) /* prints `\..' and location of error message */
char *s;
@y
void
err_print(@t\1\1@> /* prints `\..' and location of error message */
const char *s@t\2\2@>)
@z
@x
printf(". (l. %d of change file)\n", change_line);
else if (include_depth==0) printf(". (l. %d)\n", cur_line);
else printf(". (l. %d of include file %s)\n", cur_line, cur_file_name);
@y
printf(_(". (l. %d of change file)\n"), change_line);
else if (include_depth==0) printf(_(". (l. %d)\n"), cur_line);
else printf(_(". (l. %d of include file %s)\n"), cur_line, cur_file_name);
@z
@x
int wrap_up();
extern void print_stats();
@y
extern int wrap_up(void);@/
extern void print_stats(void);@/
@z
@x
@ Some implementations may wish to pass the |history| value to the
operating system so that it can be used to govern whether or not other
programs are started. Here, for instance, we pass the operating system
a status of 0 if and only if only harmless messages were printed.
@^system dependencies@>
@y
@ On multi-tasking systems like the {\mc AMIGA} it is very convenient to
know a little bit more about the reasons why a program failed. The four
levels of return indicated by the |history| value are very suitable for
this purpose. Here, for instance, we pass the operating system a status
of~0 if and only if the run was a complete success. Any warning or error
message will result in a higher return value, so that {\mc AREXX} scripts
can be made sensitive to these conditions.
@^system dependencies@>
@d RETURN_OK 0 /* No problems, success */
@d RETURN_WARN 5 /* A warning only */
@d RETURN_ERROR 10 /* Something wrong */
@d RETURN_FAIL 20 /* Complete or severe failure */
@z
@x
int wrap_up() {
putchar('\n');
@y
int wrap_up(void) {
if (show_progress) new_line;
@z
@x
@<Print the job |history|@>;
@y
@<Print the job |history|@>@;
@<Remove the temporary file if not already done@>@;
@z
@x
if (history > harmless_message) return(1);
else return(0);
@y
switch(history) {
case harmless_message: return RETURN_WARN;
case error_message: return RETURN_ERROR;
case fatal_message: return RETURN_FAIL;
default: return RETURN_OK;
}
@z
@x
case spotless: if (show_happiness) printf("(No errors were found.)\n"); break;
case harmless_message:
printf("(Did you see the warning message above?)\n"); break;
case error_message:
printf("(Pardon me, but I think I spotted something wrong.)\n"); break;
case fatal_message: printf("(That was a fatal error, my friend.)\n");
@y
case spotless:
if (show_happiness) puts(_("(No errors were found.)")); break;
case harmless_message:
puts(_("(Did you see the warning message above?)")); break;
case error_message:
puts(_("(Pardon me, but I think I spotted something wrong.)")); break;
case fatal_message:
puts(_("(That was a fatal error, my friend.)"));
@z
@x
void fatal(), overflow();
@y
extern void fatal(const char *,const char *);@/
extern void overflow(const char *);@/
@z
@x
@c void
fatal(s,t)
char *s,*t;
@y
@c void
fatal(
const char *s,const char *t)
@z
@x
if (*s) printf(s);
@y
if (*s) fputs(s,stdout);
@z
@x
@c void
overflow(t)
char *t;
@y
@c void
overflow(
const char *t)
@z
@x
printf("\n! Sorry, %s capacity exceeded",t); fatal("","");
@y
printf(_("\n! Sorry, %s capacity exceeded"),t); fatal("","");
@z
@x
@d confusion(s) fatal("! This can't happen: ",s)
@y
@d confusion(s) fatal(_("! This can't happen: "),s)
@z
@x
@d show_happiness flags['h'] /* should lack of errors be announced? */
@y
@d show_happiness flags['h'] /* should lack of errors be announced? */
@d make_xrefs flags['x'] /* should cross references be output? */
@z
@x
char scn_file_name[max_file_name_length]; /* name of |scn_file| */
@y
char scn_file_name[max_file_name_length]; /* name of |scn_file| */
char check_file_name[max_file_name_length]; /* name of |check_file| */
@z
@x
boolean flags[128]; /* an option for each 7-bit code */
@y
boolean flags[128]; /* an option for each 7-bit code */
const char *use_language=""; /* prefix of \.{cwebmac.tex} in \TEX/ output */
@z
@x
show_banner=show_happiness=show_progress=1;
@y
@z
@x
An omitted change file argument means that |"/dev/null"| should be used,
when no changes are desired.
@y
An omitted change file argument means that |"/dev/null"| or---on non-\UNIX/
systems the contents of the compile-time variable |DEV_NULL| (\TeX~Live) or
|_DEV_NULL| (Amiga)---should be used, when no changes are desired.
@z
@x
void scan_args();
@y
static void scan_args(void);@/
@z
@x
void
scan_args()
@y
static void
scan_args(void)
@z
@x
boolean flag_change;
@y
@z
@x
while (--argc > 0) {
@y
@#
#if defined DEV_NULL
strncpy(change_file_name,DEV_NULL,max_file_name_length-2);
change_file_name[max_file_name_length-2]='\0';
#elif defined _DEV_NULL
strncpy(change_file_name,_DEV_NULL,max_file_name_length-2);
change_file_name[max_file_name_length-2]='\0';
#else
strcpy(change_file_name,"/dev/null");
#endif
@^system dependencies@>
while (--argc > 0) {
@z
@x
while (*s) {
if (*s=='.') dot_pos=s++;
else if (*s=='/') dot_pos=NULL,name_pos=++s;
else s++;
}
@y
while (*s) {
if (*s=='.') dot_pos=s++;
else if (*s==DIR_SEPARATOR || *s==DEVICE_SEPARATOR || *s=='/')
dot_pos=NULL,name_pos=++s;
else s++;
}
@^system dependencies@>
@z
@x
if (found_change<=0) strcpy(change_file_name,"/dev/null");
@y
@z
@x
@ We use all of |*argv| for the |web_file_name| if there is a |'.'| in it,
otherwise we add |".w"|. If this file can't be opened, we prepare an
|alt_web_file_name| by adding |"web"| after the dot.
The other file names come from adding other things
after the dot. We must check that there is enough room in
|web_file_name| and the other arrays for the argument.
@y
@ We use all of |*argv| for the |web_file_name| if there is a |'.'| in it,
otherwise we add |".w"|. The other file names come from adding other things
after the dot. We must check that there is enough room in |web_file_name| and
the other arrays for the argument.
@z
@x
sprintf(alt_web_file_name,"%s.web",*argv);
@y
@z
@x
if (strcmp(*argv,"-")==0) found_change=-1;
else {
@y
if (strcmp(*argv,"-")!=0) {
@z
@x
found_change=1;
}
@y
}
found_change=1;
@z
@x
if (flags['x']) { /* indexes will be generated */
@y
if (make_xrefs) { /* indexes will be generated */
@z
@x
@ @<Handle flag...@>=
{
if (**argv=='-') flag_change=0;
else flag_change=1;
for(dot_pos=*argv+1;*dot_pos>'\0';dot_pos++)
@y
@ @d flag_change (**argv!='-')
@<Handle flag...@>=
{
if (strcmp("-help",*argv)==0 || strcmp("--help",*argv)==0)
@.--help@>
@<Display help message and |exit|@>@;
if (strcmp("-version",*argv)==0 || strcmp("--version",*argv)==0)
@.--version@>
@<Display version information and |exit|@>@;