Back to index

tetex-bin  3.0
ctie.c
Go to the documentation of this file.
00001 #define version_number "1.1"
00002 #define banner "This is CTIE, Version 1.1"
00003 #define copyright  \
00004 "Copyright 2002,2003 Julian Gilbey.  All rights reserved.  There is no warranty.\n\
00005 Run with the --version option for other important information." \
00006  \
00007 
00008 #define false 0
00009 #define true 1 \
00010 
00011 #define buf_size 1024
00012 #define max_file_index 32 \
00013 
00014 #define xisupper(c) (isupper(c) &&((unsigned char) c<0200) )  \
00015  \
00016 
00017 #define spotless 0
00018 #define troublesome 1
00019 #define fatal 2 \
00020 
00021 #define max_include_files 20 \
00022 
00023 #define max_file_name_length 60 \
00024 
00025 #define too_long() {total_include_files--;free(new_inc) ; \
00026 err_print(i,"! Include file name too long") ;goto restart;} \
00027 
00028 #define fatal_error(i,s,t) { \
00029 fprintf(stderr,"\n%s",s) ; \
00030 err_print(i,t) ; \
00031 history= fatal; \
00032 exit(wrap_up() ) ; \
00033 } \
00034  \
00035 
00036 #define none (-1)  \
00037 
00038 /*2:*/
00039 #line 89 "./ctie.w"
00040 
00041 /*8:*/
00042 #line 172 "./ctie.w"
00043 
00044 #include <stdio.h> 
00045 
00046 
00047 /*:8*//*9:*/
00048 #line 180 "./ctie.w"
00049 
00050 #ifdef __STDC__
00051 #include <stdlib.h> 
00052 #else
00053 #include <malloc.h> 
00054 #endif
00055 
00056 
00057 /*:9*//*37:*/
00058 #line 715 "./ctie.w"
00059 
00060 #include <errno.h> 
00061 
00062 
00063 /*:37*/
00064 #line 90 "./ctie.w"
00065 
00066 /*4:*/
00067 #line 124 "./ctie.w"
00068 
00069 typedef int boolean;
00070 typedef char*string;
00071 
00072 
00073 /*:4*//*10:*/
00074 #line 211 "./ctie.w"
00075 
00076 #define search 0
00077 #define test 1
00078 #define reading 2
00079 #define ignore 3
00080 typedef int in_file_modes;
00081 #define unknown 0
00082 #define master 1
00083 #define chf 2
00084 typedef int file_types;
00085 
00086 
00087 /*:10*//*11:*/
00088 #line 229 "./ctie.w"
00089 
00090 #define normal 0
00091 #define pre 1
00092 #define post 2
00093 typedef int out_md_type;
00094 
00095 
00096 /*:11*//*12:*/
00097 #line 239 "./ctie.w"
00098 
00099 typedef int file_index;
00100 
00101 
00102 /*:12*//*13:*/
00103 #line 246 "./ctie.w"
00104 
00105 typedef struct _indsc{
00106 char file_name[max_file_name_length];
00107 long line;
00108 FILE*the_file;
00109 struct _indsc*parent;
00110 }include_description;
00111 
00112 
00113 /*:13*//*14:*/
00114 #line 259 "./ctie.w"
00115 
00116 typedef struct _idsc{
00117 string file_name;
00118 char buffer[buf_size];
00119 in_file_modes mode;
00120 long line;
00121 file_types type_of_file;
00122 include_description*current_include;
00123 char*buffer_end;
00124 char*limit;
00125 char*loc;
00126 FILE*the_file;
00127 int dont_match;
00128 }input_description;
00129 
00130 
00131 /*:14*/
00132 #line 91 "./ctie.w"
00133 
00134 /*5:*/
00135 #line 134 "./ctie.w"
00136 
00137 extern int strlen();
00138 extern char*strcpy();
00139 extern int strncmp();
00140 extern char*strncpy();
00141 extern char*strerror();
00142 
00143 
00144 /*:5*//*28:*/
00145 #line 584 "./ctie.w"
00146 
00147 void err_print();
00148 
00149 /*:28*//*33:*/
00150 #line 673 "./ctie.w"
00151 
00152 int wrap_up();
00153 
00154 /*:33*//*35:*/
00155 #line 696 "./ctie.w"
00156 
00157 void pfatal_error();
00158 
00159 /*:35*//*67:*/
00160 #line 1232 "./ctie.w"
00161 
00162 void usage_help();
00163 void print_version_and_exit();
00164 
00165 
00166 /*:67*/
00167 #line 92 "./ctie.w"
00168 
00169 /*7:*/
00170 #line 162 "./ctie.w"
00171 
00172 int history= spotless;
00173 
00174 
00175 /*:7*//*15:*/
00176 #line 286 "./ctie.w"
00177 
00178 int total_include_files= 0;
00179 
00180 /*:15*//*16:*/
00181 #line 292 "./ctie.w"
00182 
00183 file_index actual_input,test_input,no_ch;
00184 file_types prod_chf= unknown;
00185 out_md_type out_mode;
00186 
00187 /*:16*//*18:*/
00188 #line 309 "./ctie.w"
00189 
00190 input_description*input_organisation[max_file_index+1];
00191 
00192 
00193 /*:18*//*22:*/
00194 #line 406 "./ctie.w"
00195 
00196 boolean input_has_ended= false;
00197 
00198 
00199 /*:22*//*39:*/
00200 #line 742 "./ctie.w"
00201 
00202 FILE*out_file;
00203 string out_name;
00204 
00205 
00206 /*:39*//*66:*/
00207 #line 1217 "./ctie.w"
00208 
00209 string CTIEHELP[]= {
00210 "Usage: ctie -[mc] outfile master changefile(s)",
00211 "  Create a new master file or change file from the given",
00212 "  master (C)WEB file and changefiles.",
00213 "  All filenames are taken literally; no suffixes are added.",
00214 "",
00215 "-m  create a new master file from original (C)WEB and change file(s)",
00216 "-c  create a master change file for original (C)WEB file from changefile(s)",
00217 "--help      display this help and exit",
00218 "--version   display version information and exit",
00219 NULL
00220 };
00221 
00222 
00223 /*:66*/
00224 #line 93 "./ctie.w"
00225 
00226 /*29:*/
00227 #line 589 "./ctie.w"
00228 
00229 void err_print(i,s)
00230 file_index i;char*s;
00231 {
00232 char*k,*l;
00233 fprintf(stderr,*s=='!'?"\n%s":"%s",s);
00234 if(i>=0)/*30:*/
00235 #line 611 "./ctie.w"
00236 
00237 {
00238 register input_description*inp_desc= input_organisation[i];
00239 register include_description*inc_desc= inp_desc->current_include;
00240 
00241 if(inc_desc!=NULL){
00242 fprintf(stderr,". (l. %ld of include file %s",inc_desc->line,
00243 inc_desc->file_name);
00244 fprintf(stderr," included from l. %ld of %s file %s)\n",
00245 inp_desc->line,
00246 inp_desc->type_of_file==master?"master":"change",
00247 inp_desc->file_name);
00248 }
00249 else
00250 fprintf(stderr,". (l. %ld of %s file %s)\n",inp_desc->line,
00251 inp_desc->type_of_file==master?"master":"change",
00252 inp_desc->file_name);
00253 l= (inp_desc->loc>=inp_desc->limit?inp_desc->limit:inp_desc->loc);
00254 if(l> inp_desc->buffer){
00255 for(k= inp_desc->buffer;k<l;k++)
00256 if(*k=='\t')putc(' ',stderr);
00257 else putc(*k,stderr);
00258 putc('\n',stderr);
00259 for(k= inp_desc->buffer;k<l;k++)
00260 putc(' ',stderr);
00261 }
00262 for(k= l;k<inp_desc->limit;k++)
00263 putc(*k,stderr);
00264 putc('\n',stderr);
00265 }
00266 
00267 
00268 /*:30*/
00269 #line 595 "./ctie.w"
00270 
00271 else putc('\n',stderr);
00272 fflush(stderr);
00273 history= troublesome;
00274 }
00275 
00276 /*:29*//*36:*/
00277 #line 699 "./ctie.w"
00278 
00279 void pfatal_error(s,t)
00280 char*s,*t;
00281 {
00282 char*strerr= strerror(errno);
00283 
00284 fprintf(stderr,"\n%s%s",s,t);
00285 if(strerr)fprintf(stderr," (%s)\n",strerr);
00286 else fprintf(stderr,"\n");
00287 history= fatal;
00288 exit(wrap_up());
00289 }
00290 
00291 
00292 /*:36*/
00293 #line 94 "./ctie.w"
00294 
00295 /*19:*/
00296 #line 328 "./ctie.w"
00297 
00298 boolean get_line(i,do_includes)
00299 file_index i;boolean do_includes;
00300 {
00301 register input_description*inp_desc= input_organisation[i];
00302 register FILE*fp;
00303 
00304 if(inp_desc->mode==ignore)return false;
00305 
00306 restart:
00307 if(inp_desc->current_include!=NULL){
00308 register include_description*inc_desc= inp_desc->current_include;
00309 
00310 fp= inc_desc->the_file;
00311 /*24:*/
00312 #line 426 "./ctie.w"
00313 
00314 {
00315 register int c;
00316 register char*k;
00317 
00318 if(feof(fp))
00319 /*25:*/
00320 #line 452 "./ctie.w"
00321 
00322 {
00323 include_description*temp= inc_desc->parent;
00324 
00325 fclose(fp);
00326 free(inc_desc);
00327 total_include_files--;
00328 inp_desc->current_include= temp;
00329 goto restart;
00330 }
00331 
00332 
00333 /*:25*/
00334 #line 432 "./ctie.w"
00335 
00336 
00337 inp_desc->limit= k= inp_desc->buffer;
00338 while(k<=inp_desc->buffer_end&&(c= getc(fp))!=EOF&&c!='\n')
00339 if((*(k++)= c)!=' ')inp_desc->limit= k;
00340 if(k> inp_desc->buffer_end)
00341 if((c= getc(fp))!=EOF&&c!='\n'){
00342 ungetc(c,fp);inp_desc->loc= inp_desc->buffer;
00343 err_print(i,"! Input line too long");
00344 
00345 }
00346 if(c==EOF&&inp_desc->limit==inp_desc->buffer)
00347 /*25:*/
00348 #line 452 "./ctie.w"
00349 
00350 {
00351 include_description*temp= inc_desc->parent;
00352 
00353 fclose(fp);
00354 free(inc_desc);
00355 total_include_files--;
00356 inp_desc->current_include= temp;
00357 goto restart;
00358 }
00359 
00360 
00361 /*:25*/
00362 #line 444 "./ctie.w"
00363 
00364 
00365 inc_desc->line++;
00366 }
00367 
00368 /*:24*/
00369 #line 342 "./ctie.w"
00370 
00371 }
00372 else{
00373 fp= inp_desc->the_file;
00374 /*20:*/
00375 #line 366 "./ctie.w"
00376 
00377 {
00378 register int c;
00379 register char*k;
00380 
00381 if(feof(fp))
00382 /*21:*/
00383 #line 394 "./ctie.w"
00384 
00385 {
00386 inp_desc->mode= ignore;
00387 inp_desc->limit= NULL;
00388 if(inp_desc->type_of_file==master)input_has_ended= true;
00389 fclose(fp);
00390 return false;
00391 }
00392 
00393 
00394 /*:21*/
00395 #line 372 "./ctie.w"
00396 
00397 
00398 inp_desc->limit= k= inp_desc->buffer;
00399 while(k<=inp_desc->buffer_end&&(c= getc(fp))!=EOF&&c!='\n')
00400 if((*(k++)= c)!=' ')inp_desc->limit= k;
00401 if(k> inp_desc->buffer_end)
00402 if((c= getc(fp))!=EOF&&c!='\n'){
00403 ungetc(c,fp);inp_desc->loc= inp_desc->buffer;
00404 err_print(i,"! Input line too long");
00405 
00406 }
00407 if(c==EOF&&inp_desc->limit==inp_desc->buffer)
00408 /*21:*/
00409 #line 394 "./ctie.w"
00410 
00411 {
00412 inp_desc->mode= ignore;
00413 inp_desc->limit= NULL;
00414 if(inp_desc->type_of_file==master)input_has_ended= true;
00415 fclose(fp);
00416 return false;
00417 }
00418 
00419 
00420 /*:21*/
00421 #line 384 "./ctie.w"
00422 
00423 
00424 /*23:*/
00425 #line 414 "./ctie.w"
00426 
00427 inp_desc->line++;
00428 if(inp_desc->type_of_file==master&&inp_desc->line%100==0){
00429 if(inp_desc->line%500==0)printf("%ld",inp_desc->line);
00430 else putchar('.');
00431 fflush(stdout);
00432 }
00433 
00434 
00435 /*:23*/
00436 #line 387 "./ctie.w"
00437 
00438 }
00439 
00440 
00441 /*:20*/
00442 #line 346 "./ctie.w"
00443 
00444 }
00445 
00446 if(do_includes)
00447 /*26:*/
00448 #line 467 "./ctie.w"
00449 
00450 {
00451 inp_desc->loc= inp_desc->buffer;
00452 *inp_desc->limit= ' ';
00453 if(*inp_desc->buffer=='@'&&
00454 (inp_desc->buffer[1]=='i'||inp_desc->buffer[1]=='I')){
00455 inp_desc->loc= inp_desc->buffer+2;
00456 *inp_desc->limit= '"';
00457 while(*inp_desc->loc==' '||*inp_desc->loc=='\t')
00458 inp_desc->loc++;
00459 if(inp_desc->loc>=inp_desc->limit){
00460 err_print(i,"! Include file name not given");
00461 
00462 goto restart;
00463 }
00464 if(total_include_files>=max_include_files){
00465 err_print(i,"! Too many nested includes");
00466 
00467 goto restart;
00468 }
00469 total_include_files++;
00470 /*27:*/
00471 #line 507 "./ctie.w"
00472 
00473 {
00474 include_description*new_inc;
00475 char temp_file_name[max_file_name_length];
00476 char*file_name_end;
00477 char*k,*kk;
00478 int l;
00479 
00480 new_inc= (include_description*)malloc(sizeof(include_description));
00481 if(new_inc==NULL)
00482 fatal_error(i,"! No memory for new include descriptor","");
00483 new_inc->line= 0;
00484 k= new_inc->file_name;
00485 file_name_end= k+max_file_name_length-1;
00486 
00487 if(*inp_desc->loc=='"'){
00488 inp_desc->loc++;
00489 while(*inp_desc->loc!='"'&&k<=file_name_end)
00490 *k++= *inp_desc->loc++;
00491 if(inp_desc->loc==inp_desc->limit)
00492 k= file_name_end+1;
00493 }else
00494 while(*inp_desc->loc!=' '&&*inp_desc->loc!='\t'&&
00495 *inp_desc->loc!='"'&&k<=file_name_end)*k++= *inp_desc->loc++;
00496 if(k> file_name_end)too_long();
00497 
00498 *k= '\0';
00499 if((new_inc->the_file= fopen(new_inc->file_name,"r"))!=NULL){
00500 new_inc->parent= inp_desc->current_include;
00501 inp_desc->current_include= new_inc;
00502 goto restart;
00503 }
00504 kk= getenv("CWEBINPUTS");
00505 if(kk!=NULL){
00506 if((l= strlen(kk))> max_file_name_length-2)too_long();
00507 strcpy(temp_file_name,kk);
00508 }
00509 else{
00510 #ifdef CWEBINPUTS
00511 if((l= strlen(CWEBINPUTS))> max_file_name_length-2)too_long();
00512 strcpy(temp_file_name,CWEBINPUTS);
00513 #else
00514 l= 0;
00515 #endif 
00516 }
00517 if(l> 0){
00518 if(k+l+2>=file_name_end)too_long();
00519 for(;k>=new_inc->file_name;k--)*(k+l+1)= *k;
00520 strcpy(new_inc->file_name,temp_file_name);
00521 new_inc->file_name[l]= '/';
00522 if((new_inc->the_file= fopen(new_inc->file_name,"r"))!=NULL){
00523 new_inc->parent= inp_desc->current_include;
00524 inp_desc->current_include= new_inc;
00525 goto restart;
00526 }
00527 }
00528 total_include_files--;
00529 free(new_inc);
00530 err_print(i,"! Cannot open include file");
00531 
00532 goto restart;
00533 }
00534 
00535 
00536 
00537 /*:27*/
00538 #line 488 "./ctie.w"
00539 ;
00540 }
00541 }
00542 
00543 
00544 /*:26*/
00545 #line 351 "./ctie.w"
00546 
00547 return true;
00548 }
00549 
00550 
00551 /*:19*//*32:*/
00552 #line 663 "./ctie.w"
00553 
00554 int wrap_up()
00555 {
00556 /*34:*/
00557 #line 682 "./ctie.w"
00558 
00559 switch(history){
00560 case spotless:
00561 printf("\n(No errors were found.)\n");break;
00562 case troublesome:
00563 printf("\n(Pardon me, but I think I spotted something wrong.)\n");break;
00564 case fatal:printf("(That was a fatal error, my friend.)\n");
00565 }
00566 
00567 
00568 /*:34*/
00569 #line 666 "./ctie.w"
00570 ;
00571 if(history> spotless)return 1;
00572 else return 0;
00573 }
00574 
00575 /*:32*//*42:*/
00576 #line 791 "./ctie.w"
00577 
00578 boolean lines_dont_match(i,j)
00579 file_index i,j;
00580 {
00581 register input_description*iptr= input_organisation[i],
00582 *jptr= input_organisation[j];
00583 
00584 if(iptr->limit-iptr->buffer!=jptr->limit-jptr->buffer)
00585 return true;
00586 return strncmp(iptr->buffer,jptr->buffer,iptr->limit-iptr->buffer);
00587 }
00588 
00589 
00590 /*:42*//*43:*/
00591 #line 808 "./ctie.w"
00592 
00593 void init_change_file(i)
00594 file_index i;
00595 {
00596 register input_description*inp_desc= input_organisation[i];
00597 char ccode;
00598 
00599 inp_desc->limit= inp_desc->buffer;
00600 /*44:*/
00601 #line 827 "./ctie.w"
00602 
00603 while(1){
00604 if(!get_line(i,false))return;
00605 if(inp_desc->limit<inp_desc->buffer+2)continue;
00606 if(inp_desc->buffer[0]!='@')continue;
00607 ccode= inp_desc->buffer[1];
00608 if(xisupper(ccode))ccode= tolower(ccode);
00609 if(ccode=='x')break;
00610 if(ccode=='y'||ccode=='z'||ccode=='i'){
00611 inp_desc->loc= inp_desc->buffer+2;
00612 err_print(i,"! Missing @x in change file");
00613 
00614 }
00615 }
00616 
00617 /*:44*/
00618 #line 816 "./ctie.w"
00619 
00620 /*45:*/
00621 #line 844 "./ctie.w"
00622 
00623 do{
00624 if(!get_line(i,true)){
00625 err_print(i,"! Change file ended after @x");
00626 
00627 return;
00628 }
00629 }while(inp_desc->limit==inp_desc->buffer);
00630 
00631 
00632 /*:45*/
00633 #line 817 "./ctie.w"
00634 
00635 inp_desc->dont_match= 0;
00636 }
00637 
00638 
00639 /*:43*//*46:*/
00640 #line 857 "./ctie.w"
00641 
00642 void put_line(j)
00643 file_index j;
00644 {
00645 char*ptr= input_organisation[j]->buffer;
00646 char*lmt= input_organisation[j]->limit;
00647 
00648 while(ptr<lmt)putc(*ptr++,out_file);
00649 putc('\n',out_file);
00650 }
00651 
00652 
00653 /*:46*//*47:*/
00654 #line 872 "./ctie.w"
00655 
00656 boolean e_of_ch_module(i)
00657 file_index i;
00658 {
00659 register input_description*inp_desc= input_organisation[i];
00660 
00661 if(inp_desc->limit==NULL){
00662 err_print(i,"! Change file ended without @z");
00663 
00664 return true;
00665 }else if(inp_desc->limit>=inp_desc->buffer+2)
00666 if(inp_desc->buffer[0]=='@'&&
00667 (inp_desc->buffer[1]=='Z'||inp_desc->buffer[1]=='z'))
00668 return true;
00669 return false;
00670 }
00671 
00672 
00673 /*:47*//*48:*/
00674 #line 893 "./ctie.w"
00675 
00676 boolean e_of_ch_preamble(i)
00677 file_index i;
00678 {
00679 register input_description*inp_desc= input_organisation[i];
00680 
00681 if(inp_desc->limit>=inp_desc->buffer+2&&inp_desc->buffer[0]=='@')
00682 if(inp_desc->buffer[1]=='Y'||inp_desc->buffer[1]=='y'){
00683 if(inp_desc->dont_match> 0){
00684 inp_desc->loc= inp_desc->buffer+2;
00685 fprintf(stderr,"\n! Hmm... %d ",inp_desc->dont_match);
00686 err_print(i,"of the preceding lines failed to match");
00687 }
00688 return true;
00689 }
00690 return false;
00691 }
00692 
00693 
00694 
00695 /*:48*//*59:*/
00696 #line 1105 "./ctie.w"
00697 
00698 void usage_error()
00699 {
00700 /*60:*/
00701 #line 1118 "./ctie.w"
00702 
00703 printf("%s\n",banner);
00704 printf("%s\n",copyright);
00705 
00706 
00707 /*:60*/
00708 #line 1108 "./ctie.w"
00709 ;
00710 fprintf(stderr,"Usage: ctie -[mc] outfile master changefile(s)\n");
00711 fprintf(stderr,"Type ctie --help for more information\n");
00712 exit(1);
00713 }
00714 
00715 
00716 /*:59*/
00717 #line 95 "./ctie.w"
00718 
00719 /*3:*/
00720 #line 101 "./ctie.w"
00721 
00722 main(argc,argv)
00723 int argc;string*argv;
00724 {
00725 /*17:*/
00726 #line 300 "./ctie.w"
00727 
00728 actual_input= 0;
00729 out_mode= normal;
00730 
00731 /*:17*/
00732 #line 105 "./ctie.w"
00733 ;
00734 /*61:*/
00735 #line 1135 "./ctie.w"
00736 
00737 {
00738 if(argc> max_file_index+5-1)usage_error();
00739 no_ch= -1;
00740 while(--argc> 0){
00741 argv++;
00742 if(strcmp("-help",*argv)==0||strcmp("--help",*argv)==0)
00743 /*64:*/
00744 #line 1202 "./ctie.w"
00745 
00746 usage_help();
00747 
00748 
00749 
00750 /*:64*/
00751 #line 1142 "./ctie.w"
00752 ;
00753 if(strcmp("-version",*argv)==0||strcmp("--version",*argv)==0)
00754 /*65:*/
00755 #line 1208 "./ctie.w"
00756 
00757 {
00758 print_version_and_exit("CTIE",version_number);
00759 
00760 }
00761 
00762 
00763 /*:65*/
00764 #line 1144 "./ctie.w"
00765 ;
00766 if(**argv=='-')/*62:*/
00767 #line 1158 "./ctie.w"
00768 
00769 if(prod_chf!=unknown)usage_error();
00770 else
00771 switch(*(*argv+1)){
00772 case'c':case'C':prod_chf= chf;break;
00773 case'm':case'M':prod_chf= master;break;
00774 default:usage_error();
00775 }
00776 
00777 
00778 /*:62*/
00779 #line 1145 "./ctie.w"
00780 
00781 else/*63:*/
00782 #line 1172 "./ctie.w"
00783 
00784 {
00785 if(no_ch==(-1)){
00786 out_name= *argv;
00787 }else{
00788 register input_description*inp_desc;
00789 
00790 inp_desc= (input_description*)malloc(sizeof(input_description));
00791 if(inp_desc==NULL)
00792 fatal_error(-1,"! No memory for input descriptor","");
00793 
00794 inp_desc->mode= search;
00795 inp_desc->line= 0;
00796 inp_desc->type_of_file= chf;
00797 inp_desc->limit= inp_desc->buffer;
00798 inp_desc->buffer[0]= ' ';
00799 inp_desc->loc= inp_desc->buffer+1;
00800 inp_desc->buffer_end= inp_desc->buffer+buf_size-2;
00801 inp_desc->file_name= *argv;
00802 inp_desc->current_include= NULL;
00803 input_organisation[no_ch]= inp_desc;
00804 }
00805 no_ch++;
00806 }
00807 
00808 
00809 /*:63*/
00810 #line 1146 "./ctie.w"
00811 
00812 }
00813 if(no_ch<=0||prod_chf==unknown)usage_error();
00814 }
00815 
00816 
00817 /*:61*/
00818 #line 106 "./ctie.w"
00819 
00820 /*60:*/
00821 #line 1118 "./ctie.w"
00822 
00823 printf("%s\n",banner);
00824 printf("%s\n",copyright);
00825 
00826 
00827 /*:60*/
00828 #line 107 "./ctie.w"
00829 ;
00830 /*40:*/
00831 #line 750 "./ctie.w"
00832 
00833 {
00834 input_organisation[0]->the_file= 
00835 fopen(input_organisation[0]->file_name,"r");
00836 
00837 if(input_organisation[0]->the_file==NULL)
00838 pfatal_error("! Cannot open master file ",
00839 input_organisation[0]->file_name);
00840 
00841 printf("(%s)\n",input_organisation[0]->file_name);
00842 input_organisation[0]->type_of_file= master;
00843 get_line(0,true);
00844 }
00845 
00846 
00847 /*:40*/
00848 #line 108 "./ctie.w"
00849 
00850 /*41:*/
00851 #line 768 "./ctie.w"
00852 
00853 {
00854 file_index i;
00855 
00856 i= 1;
00857 while(i<no_ch){
00858 input_organisation[i]->the_file= 
00859 fopen(input_organisation[i]->file_name,"r");
00860 if(input_organisation[i]->the_file==NULL)
00861 pfatal_error("! Cannot open change file ",
00862 input_organisation[i]->file_name);
00863 
00864 printf("(%s)\n",input_organisation[i]->file_name);
00865 init_change_file(i);
00866 i++;
00867 }
00868 }
00869 
00870 
00871 /*:41*/
00872 #line 109 "./ctie.w"
00873 
00874 /*38:*/
00875 #line 729 "./ctie.w"
00876 
00877 {
00878 out_file= fopen(out_name,"w");
00879 if(out_file==NULL){
00880 pfatal_error("! Cannot open/create output file","");
00881 
00882 }
00883 }
00884 
00885 
00886 /*:38*/
00887 #line 110 "./ctie.w"
00888 
00889 /*57:*/
00890 #line 1074 "./ctie.w"
00891 
00892 actual_input= 0;
00893 input_has_ended= false;
00894 while(input_has_ended==false||actual_input!=0)
00895 /*49:*/
00896 #line 917 "./ctie.w"
00897 
00898 {
00899 file_index test_file;
00900 
00901 /*50:*/
00902 #line 934 "./ctie.w"
00903 
00904 {
00905 register input_description*inp_desc;
00906 while(actual_input> 0&&e_of_ch_module(actual_input)){
00907 inp_desc= input_organisation[actual_input];
00908 if(inp_desc->type_of_file==master){
00909 
00910 fatal_error(-1,"! This can't happen: change file is master file","");
00911 
00912 }
00913 inp_desc->mode= search;
00914 init_change_file(actual_input);
00915 while((input_organisation[actual_input]->mode!=reading
00916 &&actual_input> 0))
00917 actual_input--;
00918 }
00919 }
00920 
00921 
00922 /*:50*/
00923 #line 921 "./ctie.w"
00924 
00925 if(input_has_ended&&actual_input==0)break;
00926 /*51:*/
00927 #line 960 "./ctie.w"
00928 
00929 test_input= none;
00930 test_file= actual_input;
00931 while(test_input==none&&test_file<no_ch-1){
00932 test_file++;
00933 switch(input_organisation[test_file]->mode){
00934 case search:
00935 if(lines_dont_match(actual_input,test_file)==false){
00936 input_organisation[test_file]->mode= test;
00937 test_input= test_file;
00938 }
00939 break;
00940 case test:
00941 if(lines_dont_match(actual_input,test_file)){
00942 
00943 input_organisation[test_file]->dont_match++;
00944 }
00945 test_input= test_file;
00946 break;
00947 case reading:
00948 break;
00949 case ignore:
00950 break;
00951 }
00952 }
00953 
00954 
00955 /*:51*/
00956 #line 923 "./ctie.w"
00957 
00958 /*52:*/
00959 #line 993 "./ctie.w"
00960 
00961 if(prod_chf==chf){
00962 while(1){
00963 /*53:*/
00964 #line 1007 "./ctie.w"
00965 
00966 if(out_mode==normal){
00967 if(test_input!=none){
00968 fprintf(out_file,"@x\n");
00969 out_mode= pre;
00970 }else break;
00971 }
00972 
00973 
00974 /*:53*/
00975 #line 996 "./ctie.w"
00976 
00977 /*54:*/
00978 #line 1021 "./ctie.w"
00979 
00980 if(out_mode==pre){
00981 if(test_input==none){
00982 fprintf(out_file,"@y\n");
00983 out_mode= post;
00984 }else{
00985 if(input_organisation[actual_input]->type_of_file==master)
00986 put_line(actual_input);
00987 break;
00988 }
00989 }
00990 
00991 
00992 /*:54*/
00993 #line 997 "./ctie.w"
00994 
00995 /*55:*/
00996 #line 1040 "./ctie.w"
00997 
00998 if(out_mode==post){
00999 if(input_organisation[actual_input]->type_of_file==chf){
01000 if(test_input==none)put_line(actual_input);
01001 break;
01002 }else{
01003 fprintf(out_file,"@z\n\n");
01004 out_mode= normal;
01005 }
01006 }
01007 
01008 
01009 /*:55*/
01010 #line 998 "./ctie.w"
01011 
01012 }
01013 }else
01014 if(test_input==none)put_line(actual_input);
01015 
01016 
01017 /*:52*/
01018 #line 924 "./ctie.w"
01019 
01020 /*56:*/
01021 #line 1055 "./ctie.w"
01022 
01023 get_line(actual_input,true);
01024 if(test_input!=none){
01025 get_line(test_input,true);
01026 if(e_of_ch_preamble(test_input)==true){
01027 get_line(test_input,true);
01028 input_organisation[test_input]->mode= reading;
01029 actual_input= test_input;
01030 test_input= none;
01031 }
01032 }
01033 
01034 
01035 /*:56*/
01036 #line 925 "./ctie.w"
01037 
01038 }
01039 
01040 
01041 /*:49*/
01042 #line 1078 "./ctie.w"
01043 
01044 if(out_mode==post)
01045 fprintf(out_file,"@z\n");
01046 
01047 
01048 /*:57*/
01049 #line 111 "./ctie.w"
01050 
01051 /*58:*/
01052 #line 1087 "./ctie.w"
01053 
01054 {
01055 file_index i;
01056 
01057 for(i= 1;i<no_ch;i++){
01058 if(input_organisation[i]->mode!=ignore){
01059 input_organisation[i]->loc= input_organisation[i]->buffer;
01060 err_print(i,"! Change file entry did not match");
01061 
01062 }
01063 }
01064 }
01065 
01066 
01067 /*:58*/
01068 #line 112 "./ctie.w"
01069 
01070 exit(wrap_up());
01071 }
01072 
01073 /*:3*/
01074 #line 96 "./ctie.w"
01075 
01076 
01077 /*:2*//*68:*/
01078 #line 1237 "./ctie.w"
01079 
01080 void usage_help()
01081 {
01082 string*message= CTIEHELP;
01083 
01084 while(*message){
01085 fputs(*message,stdout);
01086 putchar('\n');
01087 ++message;
01088 }
01089 putchar('\n');
01090 exit(0);
01091 }
01092 
01093 
01094 /*:68*//*69:*/
01095 #line 1252 "./ctie.w"
01096 
01097 void print_version_and_exit(name,version)
01098 string name,version;
01099 {
01100 printf("%s %s\n",name,version);
01101 
01102 puts("Copyright (C) 2002,2003 Julian Gilbey.");
01103 
01104 puts("There is NO warranty.  This is free software.  See the source");
01105 puts("code of CTIE for redistribution conditions.");
01106 
01107 exit(0);
01108 }
01109 
01110 
01111 /*:69*/