Back to index

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