OSDN Git Service

GIT-20170514.
[clfsja/cross-lfs-ja.git] / ctie / ctie-k.c
1 #define version_number "1.1"
2 #define banner "This is CTIE, Version 1.1"
3 #define copyright  \
4 "Copyright 2002,2003 Julian Gilbey.  All rights reserved.  There is no warranty.\n\
5 Run with the --version option for other important information." \
6  \
7
8 #define kpse_find_cweb(name) kpse_find_file(name,kpse_cweb_format,true)  \
9
10 #define buf_size 1024
11 #define max_file_index 32 \
12
13 #define xisupper(c) (isupper(c) &&((unsigned char) c<0200) )  \
14  \
15
16 #define spotless 0
17 #define troublesome 1
18 #define fatal 2 \
19
20 #define max_include_files 20 \
21
22 #define max_file_name_length 1024 \
23
24 #define too_long() {total_include_files--;free(new_inc) ; \
25 err_print(i,"! Include file name too long") ;goto restart;} \
26
27 #define fatal_error(i,s,t) { \
28 fprintf(stderr,"\n%s",s) ; \
29 err_print(i,t) ; \
30 history= fatal; \
31 exit(wrap_up() ) ; \
32 } \
33  \
34
35 #define none (-1)  \
36
37 /*2:*/
38 #line 89 "./ctie.w"
39
40 /*10:*/
41 #line 172 "./ctie.w"
42
43 #include <stdio.h> 
44
45
46 #line 126 "./ctie-k.ch"
47 /*:10*//*39:*/
48 #line 715 "./ctie.w"
49
50 #include <errno.h> 
51
52
53 /*:39*//*72:*/
54 #line 454 "./ctie-k.ch"
55
56 #include <kpathsea/kpathsea.h> 
57
58 /*:72*/
59 #line 90 "./ctie.w"
60
61 /*12:*/
62 #line 211 "./ctie.w"
63
64 #define search 0
65 #define test 1
66 #define reading 2
67 #define ignore 3
68 typedef int in_file_modes;
69 #define unknown 0
70 #define master 1
71 #define chf 2
72 typedef int file_types;
73
74
75 /*:12*//*13:*/
76 #line 229 "./ctie.w"
77
78 #define normal 0
79 #define pre 1
80 #define post 2
81 typedef int out_md_type;
82
83
84 /*:13*//*14:*/
85 #line 239 "./ctie.w"
86
87 typedef int file_index;
88
89
90 /*:14*//*15:*/
91 #line 246 "./ctie.w"
92
93 typedef struct _indsc{
94 char file_name[max_file_name_length];
95 long line;
96 FILE*the_file;
97 struct _indsc*parent;
98 }include_description;
99
100
101 /*:15*//*16:*/
102 #line 259 "./ctie.w"
103
104 typedef struct _idsc{
105 string file_name;
106 char buffer[buf_size];
107 in_file_modes mode;
108 long line;
109 file_types type_of_file;
110 include_description*current_include;
111 char*buffer_end;
112 char*limit;
113 char*loc;
114 FILE*the_file;
115 int dont_match;
116 }input_description;
117
118
119 /*:16*/
120 #line 91 "./ctie.w"
121
122 /*30:*/
123 #line 584 "./ctie.w"
124
125 #line 223 "./ctie-k.ch"
126 void err_print P2H(file_index,char*);
127 #line 586 "./ctie.w"
128
129 /*:30*//*35:*/
130 #line 673 "./ctie.w"
131
132 #line 243 "./ctie-k.ch"
133 int wrap_up P1H(void);
134 #line 675 "./ctie.w"
135
136 /*:35*//*37:*/
137 #line 696 "./ctie.w"
138
139 #line 249 "./ctie-k.ch"
140 void pfatal_error P2H(char*,char*);
141 #line 698 "./ctie.w"
142
143 /*:37*//*69:*/
144 #line 1232 "./ctie.w"
145
146 #line 392 "./ctie-k.ch"
147 void usage_help P1H(void);
148 void print_version_and_exit P2H(string,string);
149 #line 1235 "./ctie.w"
150
151
152 /*:69*/
153 #line 92 "./ctie.w"
154
155 /*9:*/
156 #line 162 "./ctie.w"
157
158 int history= spotless;
159
160
161 /*:9*//*17:*/
162 #line 286 "./ctie.w"
163
164 int total_include_files= 0;
165
166 /*:17*//*18:*/
167 #line 292 "./ctie.w"
168
169 file_index actual_input,test_input,no_ch;
170 file_types prod_chf= unknown;
171 out_md_type out_mode;
172
173 /*:18*//*20:*/
174 #line 309 "./ctie.w"
175
176 input_description*input_organisation[max_file_index+1];
177
178
179 /*:20*//*24:*/
180 #line 406 "./ctie.w"
181
182 boolean input_has_ended= false;
183
184
185 /*:24*//*41:*/
186 #line 742 "./ctie.w"
187
188 FILE*out_file;
189 string out_name;
190
191
192 #line 273 "./ctie-k.ch"
193 /*:41*//*68:*/
194 #line 1217 "./ctie.w"
195
196 string CTIEHELP[]= {
197 "Usage: ctie -[mc] outfile master changefile(s)",
198 "  Create a new master file or change file from the given",
199 "  master (C)WEB file and changefiles.",
200 "  All filenames are taken literally; no suffixes are added.",
201 "",
202 "-m  create a new master file from original (C)WEB and change file(s)",
203 "-c  create a master change file for original (C)WEB file from changefile(s)",
204 "--help      display this help and exit",
205 "--version   display version information and exit",
206 NULL
207 };
208
209
210 /*:68*//*73:*/
211 #line 459 "./ctie-k.ch"
212
213 string file_open_mode;
214 #line 1278 "./ctie.w"
215
216
217 /*:73*/
218 #line 93 "./ctie.w"
219
220 /*31:*/
221 #line 589 "./ctie.w"
222
223 #line 230 "./ctie-k.ch"
224 void err_print P2C(file_index,i,char*,s)
225
226 #line 592 "./ctie.w"
227 {
228 char*k,*l;
229 fprintf(stderr,*s=='!'?"\n%s":"%s",s);
230 if(i>=0)/*32:*/
231 #line 611 "./ctie.w"
232
233 {
234 register input_description*inp_desc= input_organisation[i];
235 register include_description*inc_desc= inp_desc->current_include;
236
237 if(inc_desc!=NULL){
238 fprintf(stderr,". (l. %ld of include file %s",inc_desc->line,
239 inc_desc->file_name);
240 fprintf(stderr," included from l. %ld of %s file %s)\n",
241 inp_desc->line,
242 inp_desc->type_of_file==master?"master":"change",
243 inp_desc->file_name);
244 }
245 else
246 fprintf(stderr,". (l. %ld of %s file %s)\n",inp_desc->line,
247 inp_desc->type_of_file==master?"master":"change",
248 inp_desc->file_name);
249 l= (inp_desc->loc>=inp_desc->limit?inp_desc->limit:inp_desc->loc);
250 if(l> inp_desc->buffer){
251 for(k= inp_desc->buffer;k<l;k++)
252 if(*k=='\t')putc(' ',stderr);
253 else putc(*k,stderr);
254 putc('\n',stderr);
255 for(k= inp_desc->buffer;k<l;k++)
256 putc(' ',stderr);
257 }
258 for(k= l;k<inp_desc->limit;k++)
259 putc(*k,stderr);
260 putc('\n',stderr);
261 }
262
263
264 /*:32*/
265 #line 595 "./ctie.w"
266
267 else putc('\n',stderr);
268 fflush(stderr);
269 history= troublesome;
270 }
271
272 /*:31*//*38:*/
273 #line 699 "./ctie.w"
274
275 #line 256 "./ctie-k.ch"
276 void pfatal_error P2C(char*,s,char*,t)
277 #line 702 "./ctie.w"
278 {
279 char*strerr= strerror(errno);
280
281 fprintf(stderr,"\n%s%s",s,t);
282 if(strerr)fprintf(stderr," (%s)\n",strerr);
283 else fprintf(stderr,"\n");
284 history= fatal;
285 exit(wrap_up());
286 }
287
288
289 /*:38*/
290 #line 94 "./ctie.w"
291
292 /*21:*/
293 #line 328 "./ctie.w"
294
295 #line 143 "./ctie-k.ch"
296 boolean get_line P2C(file_index,i,boolean,do_includes)
297 #line 331 "./ctie.w"
298 {
299 register input_description*inp_desc= input_organisation[i];
300 register FILE*fp;
301
302 if(inp_desc->mode==ignore)return false;
303
304 restart:
305 if(inp_desc->current_include!=NULL){
306 register include_description*inc_desc= inp_desc->current_include;
307
308 fp= inc_desc->the_file;
309 /*26:*/
310 #line 426 "./ctie.w"
311
312 {
313 register int c;
314 register char*k;
315
316 if(feof(fp))
317 /*27:*/
318 #line 452 "./ctie.w"
319
320 {
321 include_description*temp= inc_desc->parent;
322
323 fclose(fp);
324 free(inc_desc);
325 total_include_files--;
326 inp_desc->current_include= temp;
327 goto restart;
328 }
329
330
331 /*:27*/
332 #line 432 "./ctie.w"
333
334
335 inp_desc->limit= k= inp_desc->buffer;
336 while(k<=inp_desc->buffer_end&&(c= getc(fp))!=EOF&&c!='\n')
337 if((*(k++)= c)!=' ')inp_desc->limit= k;
338 if(k> inp_desc->buffer_end)
339 if((c= getc(fp))!=EOF&&c!='\n'){
340 ungetc(c,fp);inp_desc->loc= inp_desc->buffer;
341 err_print(i,"! Input line too long");
342
343 }
344 if(c==EOF&&inp_desc->limit==inp_desc->buffer)
345 /*27:*/
346 #line 452 "./ctie.w"
347
348 {
349 include_description*temp= inc_desc->parent;
350
351 fclose(fp);
352 free(inc_desc);
353 total_include_files--;
354 inp_desc->current_include= temp;
355 goto restart;
356 }
357
358
359 /*:27*/
360 #line 444 "./ctie.w"
361
362
363 inc_desc->line++;
364 }
365
366 /*:26*/
367 #line 342 "./ctie.w"
368
369 }
370 else{
371 fp= inp_desc->the_file;
372 /*22:*/
373 #line 366 "./ctie.w"
374
375 {
376 register int c;
377 register char*k;
378
379 if(feof(fp))
380 /*23:*/
381 #line 394 "./ctie.w"
382
383 {
384 inp_desc->mode= ignore;
385 inp_desc->limit= NULL;
386 if(inp_desc->type_of_file==master)input_has_ended= true;
387 fclose(fp);
388 return false;
389 }
390
391
392 /*:23*/
393 #line 372 "./ctie.w"
394
395
396 inp_desc->limit= k= inp_desc->buffer;
397 while(k<=inp_desc->buffer_end&&(c= getc(fp))!=EOF&&c!='\n')
398 if((*(k++)= c)!=' ')inp_desc->limit= k;
399 if(k> inp_desc->buffer_end)
400 if((c= getc(fp))!=EOF&&c!='\n'){
401 ungetc(c,fp);inp_desc->loc= inp_desc->buffer;
402 err_print(i,"! Input line too long");
403
404 }
405 if(c==EOF&&inp_desc->limit==inp_desc->buffer)
406 /*23:*/
407 #line 394 "./ctie.w"
408
409 {
410 inp_desc->mode= ignore;
411 inp_desc->limit= NULL;
412 if(inp_desc->type_of_file==master)input_has_ended= true;
413 fclose(fp);
414 return false;
415 }
416
417
418 /*:23*/
419 #line 384 "./ctie.w"
420
421
422 /*25:*/
423 #line 414 "./ctie.w"
424
425 inp_desc->line++;
426 if(inp_desc->type_of_file==master&&inp_desc->line%100==0){
427 if(inp_desc->line%500==0)printf("%ld",inp_desc->line);
428 else putchar('.');
429 fflush(stdout);
430 }
431
432
433 /*:25*/
434 #line 387 "./ctie.w"
435
436 }
437
438
439 /*:22*/
440 #line 346 "./ctie.w"
441
442 }
443
444 if(do_includes)
445 /*28:*/
446 #line 467 "./ctie.w"
447
448 {
449 inp_desc->loc= inp_desc->buffer;
450 *inp_desc->limit= ' ';
451 if(*inp_desc->buffer=='@'&&
452 (inp_desc->buffer[1]=='i'||inp_desc->buffer[1]=='I')){
453 inp_desc->loc= inp_desc->buffer+2;
454 *inp_desc->limit= '"';
455 while(*inp_desc->loc==' '||*inp_desc->loc=='\t')
456 inp_desc->loc++;
457 if(inp_desc->loc>=inp_desc->limit){
458 err_print(i,"! Include file name not given");
459
460 goto restart;
461 }
462 if(total_include_files>=max_include_files){
463 err_print(i,"! Too many nested includes");
464
465 goto restart;
466 }
467 total_include_files++;
468 /*29:*/
469 #line 507 "./ctie.w"
470
471 {
472 include_description*new_inc;
473 #line 166 "./ctie-k.ch"
474 char*file_name_end;
475 string fullname;
476 char*k;
477 #line 514 "./ctie.w"
478
479 new_inc= (include_description*)malloc(sizeof(include_description));
480 if(new_inc==NULL)
481 fatal_error(i,"! No memory for new include descriptor","");
482 new_inc->line= 0;
483 k= new_inc->file_name;
484 file_name_end= k+max_file_name_length-1;
485
486 if(*inp_desc->loc=='"'){
487 inp_desc->loc++;
488 while(*inp_desc->loc!='"'&&k<=file_name_end)
489 *k++= *inp_desc->loc++;
490 if(inp_desc->loc==inp_desc->limit)
491 k= file_name_end+1;
492 }else
493 while(*inp_desc->loc!=' '&&*inp_desc->loc!='\t'&&
494 *inp_desc->loc!='"'&&k<=file_name_end)*k++= *inp_desc->loc++;
495 if(k> file_name_end)too_long();
496
497 *k= '\0';
498 #line 174 "./ctie-k.ch"
499 fullname= kpse_find_cweb(new_inc->file_name);
500 if(fullname)
501 new_inc->the_file= fopen(fullname,"r");
502 if(fullname!=NULL&&new_inc->the_file!=NULL){
503 free(fullname);
504 #line 535 "./ctie.w"
505 new_inc->parent= inp_desc->current_include;
506 inp_desc->current_include= new_inc;
507 goto restart;
508 }
509 #line 563 "./ctie.w"
510 total_include_files--;
511 free(new_inc);
512 #line 212 "./ctie-k.ch"
513 if(fullname){
514 free(fullname);
515 err_print(i,"! Cannot open include file");
516 }else
517 err_print(i,"! Cannot find include file");
518 #line 566 "./ctie.w"
519
520 goto restart;
521 }
522
523
524
525 /*:29*/
526 #line 488 "./ctie.w"
527 ;
528 }
529 }
530
531
532 /*:28*/
533 #line 351 "./ctie.w"
534
535 return true;
536 }
537
538
539 /*:21*//*34:*/
540 #line 663 "./ctie.w"
541
542 #line 237 "./ctie-k.ch"
543 int wrap_up P1H(void)
544 #line 665 "./ctie.w"
545 {
546 /*36:*/
547 #line 682 "./ctie.w"
548
549 switch(history){
550 case spotless:
551 printf("\n(No errors were found.)\n");break;
552 case troublesome:
553 printf("\n(Pardon me, but I think I spotted something wrong.)\n");break;
554 case fatal:printf("(That was a fatal error, my friend.)\n");
555 }
556
557
558 /*:36*/
559 #line 666 "./ctie.w"
560 ;
561 if(history> spotless)return 1;
562 else return 0;
563 }
564
565 /*:34*//*44:*/
566 #line 791 "./ctie.w"
567
568 #line 342 "./ctie-k.ch"
569 boolean lines_dont_match P2C(file_index,i,file_index,j)
570 #line 794 "./ctie.w"
571 {
572 register input_description*iptr= input_organisation[i],
573 *jptr= input_organisation[j];
574
575 if(iptr->limit-iptr->buffer!=jptr->limit-jptr->buffer)
576 return true;
577 return strncmp(iptr->buffer,jptr->buffer,iptr->limit-iptr->buffer);
578 }
579
580
581 /*:44*//*45:*/
582 #line 808 "./ctie.w"
583
584 #line 349 "./ctie-k.ch"
585 void init_change_file P1C(file_index,i)
586 #line 811 "./ctie.w"
587 {
588 register input_description*inp_desc= input_organisation[i];
589 char ccode;
590
591 inp_desc->limit= inp_desc->buffer;
592 /*46:*/
593 #line 827 "./ctie.w"
594
595 while(1){
596 if(!get_line(i,false))return;
597 if(inp_desc->limit<inp_desc->buffer+2)continue;
598 if(inp_desc->buffer[0]!='@')continue;
599 ccode= inp_desc->buffer[1];
600 if(xisupper(ccode))ccode= tolower(ccode);
601 if(ccode=='x')break;
602 if(ccode=='y'||ccode=='z'||ccode=='i'){
603 inp_desc->loc= inp_desc->buffer+2;
604 err_print(i,"! Missing @x in change file");
605
606 }
607 }
608
609 /*:46*/
610 #line 816 "./ctie.w"
611
612 /*47:*/
613 #line 844 "./ctie.w"
614
615 do{
616 if(!get_line(i,true)){
617 err_print(i,"! Change file ended after @x");
618
619 return;
620 }
621 }while(inp_desc->limit==inp_desc->buffer);
622
623
624 /*:47*/
625 #line 817 "./ctie.w"
626
627 inp_desc->dont_match= 0;
628 }
629
630
631 /*:45*//*48:*/
632 #line 857 "./ctie.w"
633
634 #line 356 "./ctie-k.ch"
635 void put_line P1C(file_index,j)
636 #line 860 "./ctie.w"
637 {
638 char*ptr= input_organisation[j]->buffer;
639 char*lmt= input_organisation[j]->limit;
640
641 while(ptr<lmt)putc(*ptr++,out_file);
642 putc('\n',out_file);
643 }
644
645
646 /*:48*//*49:*/
647 #line 872 "./ctie.w"
648
649 #line 363 "./ctie-k.ch"
650 boolean e_of_ch_module P1C(file_index,i)
651 #line 875 "./ctie.w"
652 {
653 register input_description*inp_desc= input_organisation[i];
654
655 if(inp_desc->limit==NULL){
656 err_print(i,"! Change file ended without @z");
657
658 return true;
659 }else if(inp_desc->limit>=inp_desc->buffer+2)
660 if(inp_desc->buffer[0]=='@'&&
661 (inp_desc->buffer[1]=='Z'||inp_desc->buffer[1]=='z'))
662 return true;
663 return false;
664 }
665
666
667 /*:49*//*50:*/
668 #line 893 "./ctie.w"
669
670 #line 370 "./ctie-k.ch"
671 boolean e_of_ch_preamble P1C(file_index,i)
672 #line 896 "./ctie.w"
673 {
674 register input_description*inp_desc= input_organisation[i];
675
676 if(inp_desc->limit>=inp_desc->buffer+2&&inp_desc->buffer[0]=='@')
677 if(inp_desc->buffer[1]=='Y'||inp_desc->buffer[1]=='y'){
678 if(inp_desc->dont_match> 0){
679 inp_desc->loc= inp_desc->buffer+2;
680 fprintf(stderr,"\n! Hmm... %d ",inp_desc->dont_match);
681 err_print(i,"of the preceding lines failed to match");
682 }
683 return true;
684 }
685 return false;
686 }
687
688
689
690 /*:50*//*61:*/
691 #line 1105 "./ctie.w"
692
693 #line 376 "./ctie-k.ch"
694 void usage_error P1H(void)
695 #line 1107 "./ctie.w"
696 {
697 /*62:*/
698 #line 1118 "./ctie.w"
699
700 #line 382 "./ctie-k.ch"
701 {
702 extern KPSEDLL string kpathsea_version_string;
703 printf("%s (%s)\n",banner,kpathsea_version_string);
704 }
705 #line 1120 "./ctie.w"
706 printf("%s\n",copyright);
707
708
709 /*:62*/
710 #line 1108 "./ctie.w"
711 ;
712 fprintf(stderr,"Usage: ctie -[mc] outfile master changefile(s)\n");
713 fprintf(stderr,"Type ctie --help for more information\n");
714 exit(1);
715 }
716
717
718 /*:61*/
719 #line 95 "./ctie.w"
720
721 /*3:*/
722 #line 101 "./ctie.w"
723
724 #line 32 "./ctie-k.ch"
725 int main P2C(int,argc,string*,argv)
726 #line 104 "./ctie.w"
727 {
728 #line 38 "./ctie-k.ch"
729 /*5:*/
730 #line 84 "./ctie-k.ch"
731
732 kpse_set_program_name(argv[0],"ctie");
733
734 /*:5*/
735 #line 38 "./ctie-k.ch"
736 ;
737 /*19:*/
738 #line 300 "./ctie.w"
739
740 actual_input= 0;
741 out_mode= normal;
742
743 /*:19*/
744 #line 39 "./ctie-k.ch"
745 ;
746 #line 106 "./ctie.w"
747 /*63:*/
748 #line 1135 "./ctie.w"
749
750 {
751 if(argc> max_file_index+5-1)usage_error();
752 no_ch= -1;
753 while(--argc> 0){
754 argv++;
755 if(strcmp("-help",*argv)==0||strcmp("--help",*argv)==0)
756 /*66:*/
757 #line 1202 "./ctie.w"
758
759 usage_help();
760
761
762
763 /*:66*/
764 #line 1142 "./ctie.w"
765 ;
766 if(strcmp("-version",*argv)==0||strcmp("--version",*argv)==0)
767 /*67:*/
768 #line 1208 "./ctie.w"
769
770 {
771 print_version_and_exit("CTIE",version_number);
772
773 }
774
775
776 /*:67*/
777 #line 1144 "./ctie.w"
778 ;
779 if(**argv=='-')/*64:*/
780 #line 1158 "./ctie.w"
781
782 if(prod_chf!=unknown)usage_error();
783 else
784 switch(*(*argv+1)){
785 case'c':case'C':prod_chf= chf;break;
786 case'm':case'M':prod_chf= master;break;
787 default:usage_error();
788 }
789
790
791 /*:64*/
792 #line 1145 "./ctie.w"
793
794 else/*65:*/
795 #line 1172 "./ctie.w"
796
797 {
798 if(no_ch==(-1)){
799 out_name= *argv;
800 }else{
801 register input_description*inp_desc;
802
803 inp_desc= (input_description*)malloc(sizeof(input_description));
804 if(inp_desc==NULL)
805 fatal_error(-1,"! No memory for input descriptor","");
806
807 inp_desc->mode= search;
808 inp_desc->line= 0;
809 inp_desc->type_of_file= chf;
810 inp_desc->limit= inp_desc->buffer;
811 inp_desc->buffer[0]= ' ';
812 inp_desc->loc= inp_desc->buffer+1;
813 inp_desc->buffer_end= inp_desc->buffer+buf_size-2;
814 inp_desc->file_name= *argv;
815 inp_desc->current_include= NULL;
816 input_organisation[no_ch]= inp_desc;
817 }
818 no_ch++;
819 }
820
821
822 /*:65*/
823 #line 1146 "./ctie.w"
824
825 }
826 if(no_ch<=0||prod_chf==unknown)usage_error();
827 }
828
829
830 /*:63*/
831 #line 106 "./ctie.w"
832
833 /*62:*/
834 #line 1118 "./ctie.w"
835
836 #line 382 "./ctie-k.ch"
837 {
838 extern KPSEDLL string kpathsea_version_string;
839 printf("%s (%s)\n",banner,kpathsea_version_string);
840 }
841 #line 1120 "./ctie.w"
842 printf("%s\n",copyright);
843
844
845 /*:62*/
846 #line 107 "./ctie.w"
847 ;
848 /*42:*/
849 #line 277 "./ctie-k.ch"
850
851 {
852 string fullname;
853
854 fullname= kpse_find_cweb(input_organisation[0]->file_name);
855 if(fullname)
856 input_organisation[0]->the_file= fopen(fullname,"r");
857
858 if(fullname==NULL||input_organisation[0]->the_file==NULL){
859 if(fullname){
860 pfatal_error("! Cannot open master file ",
861 input_organisation[0]->file_name);
862 }else{
863 fatal_error(-1,"! Cannot find master file ",
864 input_organisation[0]->file_name);
865 }
866 }
867 else free(fullname);
868
869
870 #line 759 "./ctie.w"
871 printf("(%s)\n",input_organisation[0]->file_name);
872 input_organisation[0]->type_of_file= master;
873 get_line(0,true);
874 }
875
876
877 /*:42*/
878 #line 108 "./ctie.w"
879
880 /*43:*/
881 #line 313 "./ctie-k.ch"
882
883 {
884 file_index i;
885 string fullname;
886
887 i= 1;
888 while(i<no_ch){
889 fullname= kpse_find_cweb(input_organisation[i]->file_name);
890 if(fullname)
891 input_organisation[i]->the_file= fopen(fullname,"r");
892
893 if(fullname==NULL||input_organisation[i]->the_file==NULL){
894 if(fullname){
895 pfatal_error("! Cannot open change file ",
896 input_organisation[i]->file_name);
897 }else{
898 fatal_error(-1,"! Cannot find change file ",
899 input_organisation[i]->file_name);
900 }
901 }
902 else free(fullname);
903
904
905 #line 780 "./ctie.w"
906 printf("(%s)\n",input_organisation[i]->file_name);
907 init_change_file(i);
908 i++;
909 }
910 }
911
912
913 /*:43*/
914 #line 109 "./ctie.w"
915
916 /*40:*/
917 #line 729 "./ctie.w"
918
919 {
920 out_file= fopen(out_name,"w");
921 if(out_file==NULL){
922 pfatal_error("! Cannot open/create output file","");
923
924 }
925 }
926
927
928 /*:40*/
929 #line 110 "./ctie.w"
930
931 /*59:*/
932 #line 1074 "./ctie.w"
933
934 actual_input= 0;
935 input_has_ended= false;
936 while(input_has_ended==false||actual_input!=0)
937 /*51:*/
938 #line 917 "./ctie.w"
939
940 {
941 file_index test_file;
942
943 /*52:*/
944 #line 934 "./ctie.w"
945
946 {
947 register input_description*inp_desc;
948 while(actual_input> 0&&e_of_ch_module(actual_input)){
949 inp_desc= input_organisation[actual_input];
950 if(inp_desc->type_of_file==master){
951
952 fatal_error(-1,"! This can't happen: change file is master file","");
953
954 }
955 inp_desc->mode= search;
956 init_change_file(actual_input);
957 while((input_organisation[actual_input]->mode!=reading
958 &&actual_input> 0))
959 actual_input--;
960 }
961 }
962
963
964 /*:52*/
965 #line 921 "./ctie.w"
966
967 if(input_has_ended&&actual_input==0)break;
968 /*53:*/
969 #line 960 "./ctie.w"
970
971 test_input= none;
972 test_file= actual_input;
973 while(test_input==none&&test_file<no_ch-1){
974 test_file++;
975 switch(input_organisation[test_file]->mode){
976 case search:
977 if(lines_dont_match(actual_input,test_file)==false){
978 input_organisation[test_file]->mode= test;
979 test_input= test_file;
980 }
981 break;
982 case test:
983 if(lines_dont_match(actual_input,test_file)){
984
985 input_organisation[test_file]->dont_match++;
986 }
987 test_input= test_file;
988 break;
989 case reading:
990 break;
991 case ignore:
992 break;
993 }
994 }
995
996
997 /*:53*/
998 #line 923 "./ctie.w"
999
1000 /*54:*/
1001 #line 993 "./ctie.w"
1002
1003 if(prod_chf==chf){
1004 while(1){
1005 /*55:*/
1006 #line 1007 "./ctie.w"
1007
1008 if(out_mode==normal){
1009 if(test_input!=none){
1010 fprintf(out_file,"@x\n");
1011 out_mode= pre;
1012 }else break;
1013 }
1014
1015
1016 /*:55*/
1017 #line 996 "./ctie.w"
1018
1019 /*56:*/
1020 #line 1021 "./ctie.w"
1021
1022 if(out_mode==pre){
1023 if(test_input==none){
1024 fprintf(out_file,"@y\n");
1025 out_mode= post;
1026 }else{
1027 if(input_organisation[actual_input]->type_of_file==master)
1028 put_line(actual_input);
1029 break;
1030 }
1031 }
1032
1033
1034 /*:56*/
1035 #line 997 "./ctie.w"
1036
1037 /*57:*/
1038 #line 1040 "./ctie.w"
1039
1040 if(out_mode==post){
1041 if(input_organisation[actual_input]->type_of_file==chf){
1042 if(test_input==none)put_line(actual_input);
1043 break;
1044 }else{
1045 fprintf(out_file,"@z\n\n");
1046 out_mode= normal;
1047 }
1048 }
1049
1050
1051 /*:57*/
1052 #line 998 "./ctie.w"
1053
1054 }
1055 }else
1056 if(test_input==none)put_line(actual_input);
1057
1058
1059 /*:54*/
1060 #line 924 "./ctie.w"
1061
1062 /*58:*/
1063 #line 1055 "./ctie.w"
1064
1065 get_line(actual_input,true);
1066 if(test_input!=none){
1067 get_line(test_input,true);
1068 if(e_of_ch_preamble(test_input)==true){
1069 get_line(test_input,true);
1070 input_organisation[test_input]->mode= reading;
1071 actual_input= test_input;
1072 test_input= none;
1073 }
1074 }
1075
1076
1077 /*:58*/
1078 #line 925 "./ctie.w"
1079
1080 }
1081
1082
1083 /*:51*/
1084 #line 1078 "./ctie.w"
1085
1086 if(out_mode==post)
1087 fprintf(out_file,"@z\n");
1088
1089
1090 /*:59*/
1091 #line 111 "./ctie.w"
1092
1093 /*60:*/
1094 #line 1087 "./ctie.w"
1095
1096 {
1097 file_index i;
1098
1099 for(i= 1;i<no_ch;i++){
1100 if(input_organisation[i]->mode!=ignore){
1101 input_organisation[i]->loc= input_organisation[i]->buffer;
1102 err_print(i,"! Change file entry did not match");
1103
1104 }
1105 }
1106 }
1107
1108
1109 /*:60*/
1110 #line 112 "./ctie.w"
1111
1112 exit(wrap_up());
1113 }
1114
1115 #line 57 "./ctie-k.ch"
1116 /*:3*/
1117 #line 96 "./ctie.w"
1118
1119
1120 /*:2*//*70:*/
1121 #line 1237 "./ctie.w"
1122
1123 #line 399 "./ctie-k.ch"
1124 void usage_help P1H(void)
1125 #line 1239 "./ctie.w"
1126 {
1127 string*message= CTIEHELP;
1128
1129 while(*message){
1130 fputs(*message,stdout);
1131 putchar('\n');
1132 ++message;
1133 }
1134 putchar('\n');
1135 exit(0);
1136 }
1137
1138
1139 /*:70*//*71:*/
1140 #line 1252 "./ctie.w"
1141
1142 #line 416 "./ctie-k.ch"
1143 void print_version_and_exit P2C(string,name,string,version)
1144 {
1145 extern KPSEDLL string kpathsea_version_string;
1146 printf("%s %s\n",name,version);
1147 puts(kpathsea_version_string);
1148
1149 puts("Copyright (C) 2002,2003 Julian Gilbey.");
1150 puts("Kpathsea is copyright (C) 1999 Free Software Foundation, Inc.");
1151
1152 puts("There is NO warranty.  This is free software.");
1153 puts("Redistribution of this software is covered by the terms of");
1154 puts("both the CTIE copyright and the GNU General Public Licence.");
1155 puts("For more information about these matters, see the files");
1156 puts("named COPYING and the CTIE source.");
1157 puts("Primary authors of CTIE: Julian Gilbey.");
1158 puts("Kpathsea written by Karl Berry and others.\n");
1159
1160 exit(0);
1161 }
1162 #line 1265 "./ctie.w"
1163
1164
1165 #line 450 "./ctie-k.ch"
1166 /*:71*/