-
Notifications
You must be signed in to change notification settings - Fork 5
/
common.cxx
1586 lines (1298 loc) · 30.7 KB
/
common.cxx
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
/*1:*/
#line 62 "common.w"
/*4:*/
#line 54 "comm-foo.h"
#include <ctype.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef HAVE_GETTEXT
#define HAVE_GETTEXT 0
#endif
#line 66 "comm-foo.h"
#if HAVE_GETTEXT
#include <libintl.h>
#else
#line 70 "comm-foo.h"
#define gettext(a) a
#endif
#line 72 "comm-foo.h"
/*:4*//*93:*/
#line 624 "comm-foo.ch"
#if HAVE_GETTEXT
#include <locale.h>
#else
#line 628 "comm-foo.ch"
#define setlocale(a,b) ""
#define bindtextdomain(a,b) ""
#define textdomain(a) ""
#endif
#line 632 "comm-foo.ch"
/*:93*/
#line 63 "common.w"
#define _(s) gettext(s) \
#define and_and 04
#define lt_lt 020
#define gt_gt 021
#define plus_plus 013
#define minus_minus 01
#define minus_gt 031
#define non_eq 032
#define lt_eq 034
#define gt_eq 035
#define eq_eq 036
#define or_or 037
#define dot_dot_dot 016
#define colon_colon 06
#define period_ast 026
#define minus_gt_ast 027 \
#define compress(c) if(loc++<=limit) return c \
#define xisalpha(c) (isalpha((int) (c) ) &&((eight_bits) (c) <0200) )
#define xisdigit(c) (isdigit((int) (c) ) &&((eight_bits) (c) <0200) )
#define xisspace(c) (isspace((int) (c) ) &&((eight_bits) (c) <0200) )
#define xislower(c) (islower((int) (c) ) &&((eight_bits) (c) <0200) )
#define xisupper(c) (isupper((int) (c) ) &&((eight_bits) (c) <0200) )
#define xisxdigit(c) (isxdigit((int) (c) ) &&((eight_bits) (c) <0200) )
#define isxalpha(c) ((c) =='_'||(c) =='$') \
#define ishigh(c) ((eight_bits) (c) > 0177) \
\
#define max_include_depth 10 \
#define max_file_name_length 60
#define cur_file file[include_depth]
#define cur_file_name file_name[include_depth]
#define cur_line line[include_depth]
#define web_file file[0]
#define web_file_name file_name[0] \
#define length(c) (size_t) ((c+1) ->byte_start-(c) ->byte_start)
#define print_id(c) term_write((c) ->byte_start,length(c) )
#define llink link
#define rlink dummy.Rlink
#define root name_dir->rlink \
#define ilk dummy.Ilk \
#define spotless 0
#define harmless_message 1
#define error_message 2
#define fatal_message 3
#define mark_harmless() if(history==spotless) history= harmless_message
#define mark_error() history= error_message
#define confusion(s) fatal(_("! This can't happen: ") ,s) \
\
#define show_banner flags['b']
#define show_progress flags['p']
#define show_happiness flags['h']
#define show_stats flags['s']
#define make_xrefs flags['x']
#define check_for_change flags['c'] \
#define update_terminal() fflush(stdout)
#define new_line() putchar('\n')
#define term_write(a,b) fflush(stdout) ,fwrite(a,sizeof(char) ,b,stdout) \
#define buf_size 200
#define longest_name 10000 \
#define long_buf_size (buf_size+longest_name)
#define max_bytes 100000 \
#define max_names 5000 \
#define max_sections 2000 \
#define lines_dont_match (change_limit-change_buffer!=limit-buffer|| \
strncmp(buffer,change_buffer,(size_t) (limit-buffer) ) !=0) \
#define if_section_start_make_pending(b) \
*limit= '!'; \
for(loc= buffer;xisspace(*loc) ;loc++) ; \
*limit= ' '; \
if(*loc=='@'&&(xisspace(*(loc+1) ) ||*(loc+1) =='*') ) change_pending= b \
#define too_long() {include_depth--; \
err_print(_("! Include file name too long") ) ;goto restart;} \
#define hash_size 353 \
#define first_chunk(p) ((p) ->byte_start+2)
#define prefix_length(p) (size_t) ((eight_bits) *((p) ->byte_start) *256+ \
(eight_bits) *((p) ->byte_start+1) )
#define set_prefix_length(p,m) (*((p) ->byte_start) = (char) ((m) /256) , \
*((p) ->byte_start+1) = (char) ((m) %256) ) \
#define less 0
#define equal 1
#define greater 2
#define prefix 3
#define extension 4 \
#define bad_extension 5 \
#define RETURN_OK 0
#define RETURN_WARN 5
#define RETURN_ERROR 10
#define RETURN_FAIL 20 \
#define flag_change (**argv!='-')
#define max_path_length (BUFSIZ-2) \
#define PATH_SEPARATOR separators[0]
#define DIR_SEPARATOR separators[1]
#define DEVICE_SEPARATOR separators[2] \
#line 64 "common.w"
/*2:*/
#line 32 "comm-foo.h"
typedef bool boolean;
typedef uint8_t eight_bits;
typedef uint16_t sixteen_bits;
typedef enum{
ctangle,cweave,ctwill
}cweb;
extern cweb program;
extern int phase;
/*:2*//*5:*/
#line 94 "comm-foo.h"
extern char section_text[];
extern char*section_text_end;
extern char*id_first;
extern char*id_loc;
/*:5*//*6:*/
#line 112 "comm-foo.h"
extern char buffer[];
extern char*buffer_end;
extern char*loc;
extern char*limit;
/*:6*//*7:*/
#line 129 "comm-foo.h"
extern int include_depth;
extern FILE*file[];
extern FILE*change_file;
extern char file_name[][max_file_name_length];
extern char change_file_name[];
extern int line[];
extern int change_line;
extern int change_depth;
extern boolean input_has_ended;
extern boolean changing;
extern boolean web_file_open;
/*:7*//*9:*/
#line 149 "comm-foo.h"
extern sixteen_bits section_count;
extern boolean changed_section[];
extern boolean change_pending;
extern boolean print_where;
/*:9*//*10:*/
#line 164 "comm-foo.h"
typedef struct name_info{
char*byte_start;
struct name_info*link;
union{
struct name_info*Rlink;
eight_bits Ilk;
}dummy;
void*equiv_or_xref;
}name_info;
typedef name_info*name_pointer;
typedef name_pointer*hash_pointer;
extern char byte_mem[];
extern char*byte_mem_end;
extern char*byte_ptr;
extern name_info name_dir[];
extern name_pointer name_dir_end;
extern name_pointer name_ptr;
extern name_pointer hash[];
extern hash_pointer hash_end;
extern hash_pointer hash_ptr;
/*:10*//*12:*/
#line 209 "comm-foo.h"
extern int history;
/*:12*//*14:*/
#line 228 "comm-foo.h"
extern int argc;
extern char**argv;
extern char C_file_name[];
extern char tex_file_name[];
extern char idx_file_name[];
extern char scn_file_name[];
extern char check_file_name[];
extern boolean flags[];
extern const char*use_language;
/*:14*//*15:*/
#line 244 "comm-foo.h"
extern FILE*C_file;
extern FILE*tex_file;
extern FILE*idx_file;
extern FILE*scn_file;
extern FILE*active_file;
extern FILE*check_file;
/*:15*/
#line 65 "common.w"
/*18:*/
#line 79 "common.w"
#line 41 "comm-foo.ch"
cweb program;
#line 81 "common.w"
/*:18*//*19:*/
#line 88 "common.w"
int phase;
/*:19*//*21:*/
#line 126 "common.w"
char section_text[longest_name+1];
char*section_text_end= section_text+longest_name;
char*id_first;
char*id_loc;
/*:21*//*22:*/
#line 146 "common.w"
char buffer[long_buf_size];
char*buffer_end= buffer+buf_size-2;
char*loc= buffer;
char*limit= buffer;
/*:22*//*25:*/
#line 190 "common.w"
int include_depth;
FILE*file[max_include_depth];
FILE*change_file;
char file_name[max_include_depth][max_file_name_length];
char change_file_name[max_file_name_length];
static char alt_web_file_name[max_file_name_length];
int line[max_include_depth];
int change_line;
int change_depth;
boolean input_has_ended;
boolean changing;
boolean web_file_open= false;
/*:25*//*26:*/
#line 216 "common.w"
static char change_buffer[buf_size];
static char*change_limit;
/*:26*//*42:*/
#line 545 "common.w"
sixteen_bits section_count;
boolean changed_section[max_sections];
boolean change_pending;
boolean print_where= false;
/*:42*//*43:*/
#line 590 "common.w"
char byte_mem[max_bytes];
char*byte_mem_end= byte_mem+max_bytes-1;
name_info name_dir[max_names];
name_pointer name_dir_end= name_dir+max_names-1;
/*:43*//*44:*/
#line 601 "common.w"
char*byte_ptr;
name_pointer name_ptr;
/*:44*//*46:*/
#line 621 "common.w"
name_pointer hash[hash_size]= {NULL};
hash_pointer hash_end= hash+hash_size-1;
hash_pointer hash_ptr;
/*:46*//*65:*/
#line 999 "common.w"
int history= spotless;
/*:65*//*73:*/
#line 1124 "common.w"
int argc;
char**argv;
char C_file_name[max_file_name_length];
char tex_file_name[max_file_name_length];
char idx_file_name[max_file_name_length];
#line 374 "comm-foo.ch"
char scn_file_name[max_file_name_length];
char check_file_name[max_file_name_length];
#line 1131 "common.w"
boolean flags[128];
/*:73*//*83:*/
#line 1267 "common.w"
FILE*C_file;
FILE*tex_file;
FILE*idx_file;
FILE*scn_file;
#line 464 "comm-foo.ch"
FILE*active_file;
FILE*check_file;
#line 1273 "common.w"
#line 481 "comm-foo.ch"
/*:83*//*86:*/
#line 509 "comm-foo.ch"
const char*use_language= "";
/*:86*//*89:*/
#line 555 "comm-foo.ch"
char include_path[max_path_length+2];
char*p,*path_prefix,*next_path_prefix;
#ifndef SEPARATORS
#define SEPARATORS "://"
#endif
#line 562 "comm-foo.ch"
char separators[]= SEPARATORS;
/*:89*/
#line 66 "common.w"
/*3:*/
#line 43 "comm-foo.h"
extern void common_init(void);
/*:3*//*8:*/
#line 143 "comm-foo.h"
extern boolean get_line(void);
extern void check_complete(void);
extern void reset_input(void);
/*:8*//*11:*/
#line 187 "comm-foo.h"
extern name_pointer id_lookup(const char*,const char*,eight_bits);
extern name_pointer section_lookup(char*,char*,boolean);
extern void print_prefix_name(name_pointer);
extern void print_section_name(name_pointer);
extern void sprint_section_name(char*,name_pointer);
extern boolean names_match(name_pointer,const char*,size_t,eight_bits);
extern void init_node(name_pointer);
/*:11*//*13:*/
#line 212 "comm-foo.h"
extern int wrap_up(void);
extern void err_print(const char*);
extern void fatal(const char*,const char*);
extern void overflow(const char*);
extern void print_stats(void);
/*:13*//*24:*/
#line 176 "common.w"
static boolean input_ln(FILE*);
/*:24*//*28:*/
#line 237 "common.w"
static void prime_the_change_buffer(void);
/*:28*//*33:*/
#line 334 "common.w"
static void check_change(void);
/*:33*//*55:*/
#line 760 "common.w"
static int web_strcmp(char*,size_t,char*,size_t);
static name_pointer add_section_name(name_pointer,int,char*,char*,boolean);
static void extend_section_name(name_pointer,char*,char*,boolean);
/*:55*//*64:*/
#line 987 "common.w"
static int section_name_cmp(char**,size_t,name_pointer);
/*:64*//*76:*/
#line 1184 "common.w"
static void scan_args(void);
/*:76*//*87:*/
#line 521 "comm-foo.ch"
static boolean set_path(char*,char*);
/*:87*/
#line 67 "common.w"
/*:1*//*20:*/
#line 95 "common.w"
void
common_init(void)
{
/*45:*/
#line 605 "common.w"
name_dir->byte_start= byte_ptr= byte_mem;
name_ptr= name_dir+1;
name_ptr->byte_start= byte_mem;
root= NULL;
/*:45*/
#line 99 "common.w"
#line 47 "comm-foo.ch"
/*94:*/
#line 633 "comm-foo.ch"
setlocale(LC_MESSAGES,setlocale(LC_CTYPE,""));
bindtextdomain("cweb","/usr/share/locale/");
textdomain("cweb");
/*:94*/
#line 47 "comm-foo.ch"
/*74:*/
#line 1137 "common.w"
show_banner= show_happiness= show_progress= make_xrefs= true;
/*:74*/
#line 48 "comm-foo.ch"
#line 101 "common.w"
/*84:*/
#line 481 "comm-foo.ch"
scan_args();
if(program==ctangle){
if(check_for_change)/*90:*/
#line 573 "comm-foo.ch"
{
if((C_file= fopen(C_file_name,"a"))==NULL)
fatal(_("! Cannot open output file "),C_file_name);
else fclose(C_file);
strcpy(check_file_name,C_file_name);
if(check_file_name[0]!='\0'){
char*dot_pos= strrchr(check_file_name,'.');
if(dot_pos==NULL)strcat(check_file_name,".ttp");
else strcpy(dot_pos,".ttp");
}
if((C_file= fopen(check_file_name,"wb"))==NULL)
fatal(_("! Cannot open output file "),check_file_name);
}
/*:90*/
#line 484 "comm-foo.ch"
else if((C_file= fopen(C_file_name,"wb"))==NULL)
fatal(_("! Cannot open output file "),C_file_name);
}
else{
if(check_for_change)/*91:*/
#line 588 "comm-foo.ch"
{
if((tex_file= fopen(tex_file_name,"a"))==NULL)
fatal(_("! Cannot open output file "),tex_file_name);
else fclose(tex_file);
strcpy(check_file_name,tex_file_name);
if(check_file_name[0]!='\0'){
char*dot_pos= strrchr(check_file_name,'.');
if(dot_pos==NULL)strcat(check_file_name,".wtp");
else strcpy(dot_pos,".wtp");
}
if((tex_file= fopen(check_file_name,"wb"))==NULL)
fatal(_("! Cannot open output file "),check_file_name);
}
/*:91*/
#line 490 "comm-foo.ch"
else if((tex_file= fopen(tex_file_name,"wb"))==NULL)
fatal(_("! Cannot open output file "),tex_file_name);
}
#line 1285 "common.w"
#line 499 "comm-foo.ch"
/*:84*/
#line 101 "common.w"
}
/*:20*//*23:*/
#line 156 "common.w"
static boolean input_ln(
FILE*fp)
{
int c= EOF;
char*k;
if(feof(fp))return false;
limit= k= buffer;
while(k<=buffer_end&&(c= getc(fp))!=EOF&&c!='\n')
if((*(k++)= c)!=' ')limit= k;
if(k> buffer_end){
while((c= getc(fp))!=EOF&&c!='\n');
#line 54 "comm-foo.ch"
loc= buffer;err_print(_("! Input line too long"));
#line 169 "common.w"
}
if(c==EOF&&limit==buffer)return false;
return true;
}
/*:23*//*27:*/
#line 227 "common.w"
static void
prime_the_change_buffer(void)
{
change_limit= change_buffer;
/*29:*/
#line 243 "common.w"
while(true){
change_line++;
if(!input_ln(change_file))return;
if(limit<buffer+2)continue;
if(buffer[0]!='@')continue;
if(xisupper(buffer[1]))buffer[1]= tolower((int)buffer[1]);
if(buffer[1]=='x')break;
if(buffer[1]=='y'||buffer[1]=='z'||buffer[1]=='i'){
loc= buffer+2;
#line 60 "comm-foo.ch"
err_print(_("! Missing @x in change file"));
#line 254 "common.w"
}
}
/*:29*/
#line 232 "common.w"
/*30:*/
#line 260 "common.w"
do{
change_line++;
if(!input_ln(change_file)){
#line 66 "comm-foo.ch"
err_print(_("! Change file ended after @x"));
#line 265 "common.w"
return;
}
}while(limit==buffer);
/*:30*/
#line 233 "common.w"
/*31:*/
#line 270 "common.w"
change_limit= change_buffer+(ptrdiff_t)(limit-buffer);
strncpy(change_buffer,buffer,(size_t)(limit-buffer+1));
/*:31*/
#line 234 "common.w"
}
/*:27*//*32:*/
#line 296 "common.w"
static void
check_change(void)
{
int n= 0;
if(lines_dont_match)return;
change_pending= false;
if(!changed_section[section_count]){
if_section_start_make_pending(true);
if(!change_pending)changed_section[section_count]= true;
}
while(true){
changing= print_where= true;change_line++;
if(!input_ln(change_file)){
#line 72 "comm-foo.ch"
err_print(_("! Change file ended before @y"));
#line 311 "common.w"
change_limit= change_buffer;changing= false;
return;
}
if(limit> buffer+1&&buffer[0]=='@'){
if(xisupper(buffer[1]))buffer[1]= tolower((int)buffer[1]);
/*34:*/
#line 336 "common.w"
if(buffer[1]=='x'||buffer[1]=='z'){
#line 84 "comm-foo.ch"
loc= buffer+2;err_print(_("! Where is the matching @y?"));
#line 339 "common.w"
}
else if(buffer[1]=='y'){
if(n> 0){
loc= buffer+2;
printf("\n! Hmm... %d ",n);
#line 90 "comm-foo.ch"
err_print(_("of the preceding lines failed to match"));
#line 346 "common.w"
}
change_depth= include_depth;
return;
}
/*:34*/
#line 318 "common.w"
}
/*31:*/
#line 270 "common.w"
change_limit= change_buffer+(ptrdiff_t)(limit-buffer);
strncpy(change_buffer,buffer,(size_t)(limit-buffer+1));
/*:31*/
#line 320 "common.w"
changing= false;cur_line++;
while(!input_ln(cur_file)){
if(include_depth==0){
#line 78 "comm-foo.ch"
err_print(_("! CWEB file ended during a change"));
#line 325 "common.w"
input_has_ended= true;return;
}
include_depth--;cur_line++;
}
if(lines_dont_match)n++;
}
}
/*:32*//*35:*/
#line 362 "common.w"
boolean get_line(void)
{
restart:
if(changing&&include_depth==change_depth)
/*38:*/
#line 470 "common.w"
{
change_line++;
if(!input_ln(change_file)){
#line 195 "comm-foo.ch"
err_print(_("! Change file ended without @z"));
#line 474 "common.w"
buffer[0]= '@';buffer[1]= 'z';limit= buffer+2;
}
if(limit> buffer){
if(change_pending){
if_section_start_make_pending(false);
if(change_pending){
changed_section[section_count]= true;change_pending= false;
}
}
*limit= ' ';
if(buffer[0]=='@'){
if(xisupper(buffer[1]))buffer[1]= tolower((int)buffer[1]);
if(buffer[1]=='x'||buffer[1]=='y'){
loc= buffer+2;
#line 201 "comm-foo.ch"
err_print(_("! Where is the matching @z?"));
#line 490 "common.w"
}
else if(buffer[1]=='z'){
prime_the_change_buffer();changing= !changing;print_where= true;
}
}
}
}
/*:38*/
#line 367 "common.w"
if(!changing||include_depth> change_depth){
/*37:*/
#line 453 "common.w"
{
cur_line++;
while(!input_ln(cur_file)){
print_where= true;
if(include_depth==0){input_has_ended= true;break;}
else{
fclose(cur_file);include_depth--;
if(changing&&include_depth==change_depth)break;
cur_line++;
}
}
if(!changing&&!input_has_ended)
if(limit-buffer==change_limit-change_buffer)
if(buffer[0]==change_buffer[0])
if(change_limit> change_buffer)check_change();
}
/*:37*/
#line 369 "common.w"
if(changing&&include_depth==change_depth)goto restart;
}
if(input_has_ended)return false;
loc= buffer;*limit= ' ';
if(buffer[0]=='@'&&(buffer[1]=='i'||buffer[1]=='I')){
loc= buffer+2;*limit= '"';
while(*loc==' '||*loc=='\t')loc++;
if(loc>=limit){
#line 96 "comm-foo.ch"
err_print(_("! Include file name not given"));
#line 379 "common.w"
goto restart;
}
if(include_depth>=max_include_depth-1){
#line 102 "comm-foo.ch"
err_print(_("! Too many nested includes"));
#line 384 "common.w"
goto restart;
}
include_depth++;
/*36:*/
#line 407 "common.w"
{
char temp_file_name[max_file_name_length];
char*cur_file_name_end= cur_file_name+max_file_name_length-1;
char*kk,*k= cur_file_name;
size_t l;
if(*loc=='"'){
loc++;
while(*loc!='"'&&k<=cur_file_name_end)*k++= *loc++;
if(loc==limit)k= cur_file_name_end+1;
}else
while(*loc!=' '&&*loc!='\t'&&*loc!='"'&&k<=cur_file_name_end)*k++= *loc++;
if(k> cur_file_name_end)too_long();
*k= '\0';
if((cur_file= fopen(cur_file_name,"r"))!=NULL){
cur_line= 0;print_where= true;
goto restart;
}
#line 162 "comm-foo.ch"
if(false==set_path(include_path,getenv("CWEBINPUTS"))){
include_depth--;goto restart;
}
path_prefix= include_path;
while(path_prefix){
for(kk= temp_file_name,p= path_prefix,l= 0;
p&&*p&&*p!=PATH_SEPARATOR;
*kk++= *p++,l++);
if(path_prefix&&*path_prefix&&*path_prefix!=PATH_SEPARATOR&&
*--p!=DEVICE_SEPARATOR&&*p!=DIR_SEPARATOR){
*kk++= DIR_SEPARATOR;l++;
}
if(k+l+2>=cur_file_name_end)too_long();
strcpy(kk,cur_file_name);
if((cur_file= fopen(temp_file_name,"r"))!=NULL){
cur_line= 0;print_where= true;goto restart;
}
if((next_path_prefix= strchr(path_prefix,PATH_SEPARATOR))!=NULL)
path_prefix= next_path_prefix+1;
else break;
}
#line 189 "comm-foo.ch"
include_depth--;err_print(_("! Cannot open include file"));goto restart;
#line 451 "common.w"
}
/*:36*/
#line 388 "common.w"
}
return true;
}
#line 117 "comm-foo.ch"
/*:35*//*39:*/
#line 502 "common.w"
void
check_complete(void){
if(change_limit!=change_buffer){
strncpy(buffer,change_buffer,(size_t)(change_limit-change_buffer+1));
limit= buffer+(ptrdiff_t)(change_limit-change_buffer);
changing= true;change_depth= include_depth;loc= buffer;
#line 207 "comm-foo.ch"
err_print(_("! Change file entry did not match"));
#line 510 "common.w"
}
}
/*:39*//*40:*/
#line 518 "common.w"
void
reset_input(void)
{
limit= buffer;loc= buffer+1;buffer[0]= ' ';
/*41:*/
#line 533 "common.w"
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)
#line 213 "comm-foo.ch"
fatal(_("! Cannot open input file "),web_file_name);
#line 538 "common.w"
}
web_file_open= true;
if((change_file= fopen(change_file_name,"r"))==NULL)
#line 219 "comm-foo.ch"
fatal(_("! Cannot open change file "),change_file_name);
#line 544 "common.w"
/*:41*/
#line 523 "common.w"
include_depth= cur_line= change_line= 0;
change_depth= include_depth;
changing= true;prime_the_change_buffer();changing= !changing;
limit= buffer;loc= buffer+1;buffer[0]= ' ';input_has_ended= false;
}
/*:40*//*48:*/
#line 630 "common.w"
name_pointer
id_lookup(
const char*first,
const char*last,
eight_bits t)
{
const char*i= first;
int h;
size_t l;
name_pointer p;
if(last==NULL)for(last= first;*last!='\0';last++);
l= (size_t)(last-first);
/*49:*/
#line 653 "common.w"
h= (int)((eight_bits)*i);
while(++i<last)h= (h+h+(int)((eight_bits)*i))%hash_size;
/*:49*/
#line 643 "common.w"
/*50:*/
#line 661 "common.w"
p= hash[h];
while(p&&!names_match(p,first,l,t))p= p->link;
if(p==NULL){
p= name_ptr;
p->link= hash[h];hash[h]= p;
}
/*:50*/
#line 644 "common.w"
if(p==name_ptr)/*51:*/
#line 672 "common.w"
{
#line 226 "comm-foo.ch"
if(byte_ptr+l> byte_mem_end)overflow(_("byte memory"));
if(name_ptr>=name_dir_end)overflow(_("name"));
#line 675 "common.w"
strncpy(byte_ptr,first,l);
(++name_ptr)->byte_start= byte_ptr+= l;
#line 233 "comm-foo.ch"
if(program!=ctangle)p->ilk= t,init_node(p);
#line 678 "common.w"
}
/*:51*/
#line 645 "common.w"
return p;
}
/*:48*//*52:*/
#line 704 "common.w"
void
print_section_name(
name_pointer p)
{
char*ss,*s= first_chunk(p);
name_pointer q= p+1;
while(p!=name_dir){
ss= (p+1)->byte_start-1;
if(*ss==' '&&ss>=s)p= q->link,q= p;
else ss++,p= name_dir,q= NULL;