summaryrefslogtreecommitdiff
path: root/web/spiderweb/tools/tie/tie.c
blob: 679787ad26790b18f8066f97003fabdca40cf9d0 (plain)
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
/*2:*/
#line 66 "tie.web"

#include<stdio.h>
/*56:*/
#line 72 "character.web"

typedef char ASCII;
typedef char outer_char;

/*:56*//*61:*/
#line 133 "character.web"

typedef char ascii_code;
typedef FILE *text_file;


/*:61*/
#line 68 "tie.web"

/*9:*/
#line 28 "datadecl.web"

typedef char in_file_modes;
typedef char file_types;

/*:9*//*10:*/
#line 35 "datadecl.web"

typedef char boolean;

/*:10*//*11:*/
#line 45 "datadecl.web"

typedef char out_md_type;
typedef char *name_type;
typedef int buffer_index;
typedef int file_index;
typedef struct{
name_type name_of_file;
ascii_code buffer[100+1];
in_file_modes mode;
int lineno;
file_types type_of_file;
int limit;
}input_description;



/*:11*/
#line 69 "tie.web"

/*8:*/
#line 165 "tie.web"

int next_available_file= 0;
#line 1 "datadecl.web"
/*:8*//*12:*/
#line 63 "datadecl.web"

int actual_input,test_input;
boolean input_has_ended;
input_description input_organization[9+1];
text_file input_files[9+1];
int no_ch;
boolean prod_chf;
out_md_type out_mode;
int verbose= 0;



#line 168 "tie.web"




/*:12*//*14:*/
#line 190 "tie.web"
boolean lines_dont_match();
/*:14*//*16:*/
#line 204 "tie.web"
boolean e_of_ch_module();

/*:16*//*18:*/
#line 219 "tie.web"
boolean e_of_ch_module();

/*:18*//*21:*/
#line 236 "tie.web"
boolean file_open();

/*:21*//*40:*/
#line 529 "tie.web"
long int lines_processed= 0;
/*:40*//*49:*/
#line 11 "history.web"

int history;


/*:49*//*57:*/
#line 80 "character.web"

ASCII xord[0177];
outer_char xchr[0200];

/*:57*/
#line 70 "tie.web"

/*52:*/
#line 25 "error.web"

print_name_of_file(cur_index)
file_index cur_index;
{
fprintf(stderr,"%s",input_organization[cur_index].name_of_file);
}


/*:52*//*53:*/
#line 36 "error.web"

err_loc(i)
int i;
{
fprintf(stderr,
" (file %s, l.%d).\n",input_organization[i].name_of_file,
input_organization[i].lineno);

}

/*:53*//*55:*/
#line 55 "error.web"

jump_out(){exit(history==0?0:1);}
#line 1 "character.web"
/*:55*/
#line 71 "tie.web"


main(argc,argv)
int argc;
char * *argv;
{
int i,j;

/*50:*/
#line 17 "history.web"

history= 0;
/*:50*/
#line 79 "tie.web"

if(verbose)
{fprintf(stderr,"This is TIE, C Version 0.1 (ported to C)");putc('\n',stderr);};
/*7:*/
#line 137 "tie.web"

while(--argc>0){
if( * *++argv=='-')
switch( *++ *argv){
case'm':
prod_chf= 0;
break;
case'c':
prod_chf= 1;
break;
case'v':
verbose++;
break;
default:
fprintf(stderr,"Bad option -%c ignored\n",
 * *argv);
break;
}
else{
if(next_available_file>9)
{{putc('\n',stderr);fprintf(stderr,"too many files");};{fprintf(stderr,".");putc('\n',stderr);};history= 2;jump_out();};
input_organization[next_available_file++].name_of_file=  *argv;
}
}


/*:7*/
#line 83 "tie.web"
;
/*30:*/
#line 374 "tie.web"

common_init();
for(i= 0;i<next_available_file;i++){
input_organization[i].mode= 1;
input_organization[i].lineno= 0;
input_organization[i].type_of_file= 2;
input_organization[i].limit= 0;
for(j= 0;j<=100;j++)input_organization[i].buffer[j]= 0;
}
actual_input= 0;
out_mode= 1;
open_input();


/*:30*/
#line 84 "tie.web"
;
/*3:*/
#line 93 "tie.web"

input_has_ended= 0;
while(!input_has_ended||(actual_input!=0))process_line();
if(out_mode==3)
write_string(stdout,"@z\n");
/*41:*/
#line 530 "tie.web"
if(verbose)fprintf(stderr,"\n");


#line 1 "io.web"
/*:41*/
#line 98 "tie.web"
;


/*:3*/
#line 85 "tie.web"
;
/*4:*/
#line 105 "tie.web"

for(i= 1;i<next_available_file;i++)
if(input_organization[i].mode!=4)
{{putc('\n',stderr);fprintf(stderr,"! Change file entry did not match");};err_loc(i);history= 1;};


/*:4*/
#line 86 "tie.web"
;

/*51:*/
#line 20 "history.web"

switch(history){
case 0:if(verbose){fprintf(stderr,"(No errors were found.)");putc('\n',stderr);};break;
case 1:{fprintf(stderr,"(Pardon me, but I think I spotted something wrong.)");putc('\n',stderr);};break;
case 2:{fprintf(stderr,"(That was a fatal error, my friend.)");putc('\n',stderr);};break;
}
#line 1 "error.web"
/*:51*/
#line 88 "tie.web"

jump_out();
}

/*:2*//*13:*/
#line 177 "tie.web"

boolean lines_dont_match(i,j)
int i,j;
{
buffer_index k,lmt;
if(input_organization[i].limit!=input_organization[j].limit)
return 1;
lmt= input_organization[i].limit;
for(k= 0;k<lmt;k++)
if(input_organization[i].buffer[k]!=input_organization[j].buffer[k])
return 1;
return 0;
}
/*:13*//*15:*/
#line 194 "tie.web"

boolean e_of_ch_module(i)
int i;
{
return((input_organization[i].limit>=2)&&
(input_organization[i].buffer[0]=='@')&&
((input_organization[i].buffer[1]=='Z')||
(input_organization[i].buffer[1]=='z')));
}

/*:15*//*17:*/
#line 209 "tie.web"

boolean e_of_ch_preamble(i)
int i;
{
return((input_organization[i].limit>=2)&&
(input_organization[i].buffer[0]=='@')&&
((input_organization[i].buffer[1]=='Y')||
(input_organization[i].buffer[1]=='y')));
}

/*:17*//*20:*/
#line 228 "tie.web"

boolean file_open(f,name)
text_file *f;
name_type name;
{
return(( *f= fopen(name,"r"))!=NULL);
}

/*:20*//*22:*/
#line 240 "tie.web"

/*25:*/
#line 297 "tie.web"

init_change_file(i,b)
int i;
boolean b;
{
/*26:*/
#line 312 "tie.web"

while(1){
get_ln_from_file(i,input_files[i]);;
if(input_organization[i].mode==4)return;
if(input_organization[i].limit<2)continue;
if(input_organization[i].buffer[0]!='@')continue;
if((input_organization[i].buffer[1]>='X')
&&(input_organization[i].buffer[1]<='Z'))
input_organization[i].buffer[1]+= 'z'-'Z';
if(input_organization[i].buffer[1]=='x')break;
if((input_organization[i].buffer[1]=='y')||
(input_organization[i].buffer[1]=='z'))
if(b)
{{putc('\n',stderr);fprintf(stderr,"! Where is the matching @x?");};err_loc(i);history= 1;};

}



/*:26*/
#line 302 "tie.web"
;
/*27:*/
#line 333 "tie.web"

do{
get_ln_from_file(i,input_files[i]);;
if(input_organization[i].mode==4){
{{putc('\n',stderr);fprintf(stderr,"! Change file ended after @x");};err_loc(i);history= 1;};

return;
}
}while(input_organization[i].limit<=0);


/*:27*/
#line 303 "tie.web"
;
}


/*:25*/
#line 241 "tie.web"

open_input()
{
int i;
/*23:*/
#line 271 "tie.web"

if(!file_open(&(input_files[0]),input_organization[0].name_of_file)){
{{putc('\n',stderr);fprintf(stderr,"! Master file can\'t be opened");};{fprintf(stderr,".");putc('\n',stderr);};history= 2;jump_out();};
}

else{
if(verbose){
fprintf(stderr,"(");
print_name_of_file(0);
{fprintf(stderr,")");putc('\n',stderr);};
}
input_organization[0].type_of_file= 1;
get_ln_from_file(0,input_files[0]);;
}


/*:23*/
#line 245 "tie.web"
;
actual_input= 0;
no_ch= 0;
while(++no_ch<next_available_file){
if(!file_open(&(input_files[no_ch]),input_organization[no_ch].name_of_file)){
{{putc('\n',stderr);fprintf(stderr,"! Change file can\'t be opened");};{fprintf(stderr,".");putc('\n',stderr);};history= 2;jump_out();};
}

else{
if(verbose){
fprintf(stderr,"(");
print_name_of_file(no_ch);
{fprintf(stderr,")");putc('\n',stderr);};
}
init_change_file(no_ch,1);
}
}

if(--no_ch==0)
{{putc('\n',stderr);fprintf(stderr,"! No change file found");};{fprintf(stderr,".");putc('\n',stderr);};history= 2;jump_out();};

for(i= next_available_file;i<=9;i++)
input_organization[i].mode= 4;
}

/*:22*//*28:*/
#line 347 "tie.web"

put_line(j)
int j;
{
int i;
for(i= 0;i<input_organization[j].limit;i++)
fputc(xchr[input_organization[j].buffer[i]],stdout);
fputc('\n',stdout);
}

/*:28*//*29:*/
#line 358 "tie.web"

write_string(fp,s)
text_file fp;
char *s;
{
while( *s!='\0'){
putc( *s,fp);s++;}
}




/*:29*//*32:*/
#line 394 "tie.web"

process_line()
{
int i;
/*39:*/
#line 521 "tie.web"

if(++lines_processed%100==0&&verbose){
if(lines_processed%500==0)
fprintf(stderr,"%d",lines_processed);
else
fprintf(stderr,".");
}

/*:39*/
#line 398 "tie.web"
;
/*33:*/
#line 410 "tie.web"

while(e_of_ch_module(actual_input)){
if(input_organization[actual_input].type_of_file==1)

{{putc('\n',stderr);fprintf(stderr,"! This can\'t happen");};{fprintf(stderr,".");putc('\n',stderr);};history= 2;jump_out();};
input_organization[actual_input].mode= 1;
init_change_file(actual_input,1);
while((input_organization[actual_input].mode!=3)
&&(actual_input>0))actual_input--;
}
if(input_has_ended&&(actual_input==0))return;
test_input= (next_available_file);
i= actual_input;
while((test_input==(next_available_file))&&(i<no_ch)){
i++;
switch(input_organization[i].mode){
case 1:if(!lines_dont_match(actual_input,i)){
input_organization[i].mode= 2;
test_input= i;
}
break;
case 2:
if(lines_dont_match(actual_input,i))
{

input_organization[i].mode= 1;
{{putc('\n',stderr);fprintf(stderr,"! Sections do not match");};err_loc(actual_input);history= 1;};

err_loc(i);
init_change_file(i,0);
}
else test_input= i;
break;
case 3:;
break;
case 4:;
break;
}
}


/*:33*/
#line 399 "tie.web"
;
/*34:*/
#line 451 "tie.web"

if(prod_chf){
while(1){
/*35:*/
#line 464 "tie.web"

{
if(out_mode==1)
if(test_input!=(next_available_file)){
write_string(stdout,"@x\n");
out_mode= 2;
}
else break;
}


/*:35*/
#line 454 "tie.web"
;
/*36:*/
#line 477 "tie.web"

{
if(out_mode==2){
if(test_input==(next_available_file)){
write_string(stdout,"@y\n");
out_mode= 3;
}else{
if(input_organization[actual_input].type_of_file==1)
put_line(actual_input);
break;
}
}
}


/*:36*/
#line 455 "tie.web"
;
/*37:*/
#line 494 "tie.web"

{
if(out_mode==3){
if(input_organization[actual_input].type_of_file==2){
if(test_input==(next_available_file))put_line(actual_input);
break;
}else{
write_string(stdout,"@z\n");
out_mode= 1;
}
}
}


/*:37*/
#line 456 "tie.web"
;
}
}else
if(test_input==(next_available_file))put_line(actual_input);


/*:34*/
#line 400 "tie.web"
;
/*38:*/
#line 508 "tie.web"

get_ln_from_file(actual_input,input_files[actual_input]);;
if(test_input!=(next_available_file)){
get_ln_from_file(test_input,input_files[test_input]);;
if(e_of_ch_preamble(test_input)){
get_ln_from_file(test_input,input_files[test_input]);;
input_organization[test_input].mode= 3;
actual_input= test_input;
test_input= (next_available_file);
}
}

/*:38*/
#line 402 "tie.web"
;
}


/*:32*//*45:*/
#line 54 "io.web"

get_ln_from_file(i,cur_file)
int i;
text_file cur_file;
{
int final_limit;
int c;
if(input_organization[i].mode==4)return;
if(feof(cur_file))/*46:*/
#line 67 "io.web"

{
input_organization[i].mode= 4;
if(input_organization[i].type_of_file==1)input_has_ended= 1;
return;
}


/*:46*/
#line 62 "io.web"
;
/*47:*/
#line 79 "io.web"

(input_organization[i].lineno)++;
input_organization[i].limit= 0;final_limit= 0;
while((input_organization[i].limit<=100)&&(c= getc(cur_file))!=EOF
&&c!='\n')
{
input_organization[i].buffer[input_organization[i].limit]= xord[c];
(input_organization[i].limit)++;
if((input_organization[i].buffer[input_organization[i].limit-1]!=' ')
&&(input_organization[i].buffer[input_organization[i].limit-1]
!='\t'))
final_limit= input_organization[i].limit;
}
if(input_organization[i].limit>100)
if((c= getc(cur_file))!=EOF&&c!='\n'){
ungetc(c,cur_file);{{putc('\n',stderr);fprintf(stderr,"! Input line too long");};err_loc(i);history= 1;};

}
/*48:*/
#line 101 "io.web"

if(input_organization[i].limit==0&&c==EOF)
/*46:*/
#line 67 "io.web"

{
input_organization[i].mode= 4;
if(input_organization[i].type_of_file==1)input_has_ended= 1;
return;
}


/*:46*/
#line 103 "io.web"






#line 1 "history.web"
/*:48*/
#line 97 "io.web"

input_organization[i].limit= final_limit;

/*:47*/
#line 63 "io.web"
;
}

/*:45*//*58:*/
#line 96 "character.web"

common_init()
{
strcpy(xchr,"                                 !\"#$%&'()*+,-./0123456789\
:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ");
/*60:*/
#line 127 "character.web"


/*:60*//*64:*/
#line 551 "tie.web"

#line 552 "tie.web"
xchr['\t']= '\t';


/*:64*/
#line 101 "character.web"
;
/*59:*/
#line 108 "character.web"
{
int i;
for(i= 0;i<=0177;i++)xord[i]= '\040';
for(i= 1;i<0177;i++)xord[xchr[i]]= i;
}

/*:59*/
#line 102 "character.web"
;
}

/*:58*/