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