Back to index

tetex-bin  3.0
cwebboot.c
Go to the documentation of this file.
00001 /*1:*/
00002 #line 58 "./cwebdir/common.w"
00003 
00004 /*5:*/
00005 #line 102 "./cwebdir/common.w"
00006 
00007 #include <ctype.h> 
00008 
00009 /*:5*//*8:*/
00010 #line 165 "./cwebdir/common.w"
00011 
00012 #include <stdio.h> 
00013 
00014 /*:8*//*22:*/
00015 #line 471 "./cwebdir/common.w"
00016 
00017 #line 151 "./cwebdir/comm-w2c.ch"
00018 #include <stdlib.h>  
00019 #define CWEB
00020 #include "cpascal.h"
00021 #include <kpathsea/kpathsea.h>  
00022 #include "help.h"
00023 
00024 /*:22*/
00025 #line 59 "./cwebdir/common.w"
00026 
00027 #define ctangle 0
00028 #define cweave 1 \
00029 
00030 #define and_and 04
00031 #define lt_lt 020
00032 #define gt_gt 021
00033 #define plus_plus 013
00034 #define minus_minus 01
00035 #define minus_gt 031
00036 #define not_eq 032
00037 #define lt_eq 034
00038 #define gt_eq 035
00039 #define eq_eq 036
00040 #define or_or 037
00041 #define dot_dot_dot 016
00042 #define colon_colon 06
00043 #define period_ast 026
00044 #define minus_gt_ast 027 \
00045 
00046 #define buf_size 100
00047 #define longest_name 1000
00048 #define long_buf_size (buf_size+longest_name) 
00049 #define xisspace(c) (isspace(c) &&((unsigned char) c<0200) ) 
00050 #define xisupper(c) (isupper(c) &&((unsigned char) c<0200) )  \
00051 
00052 #define max_include_depth 10 \
00053 
00054 #define max_file_name_length 1024
00055 #define cur_file file[include_depth]
00056 #define cur_file_name file_name[include_depth]
00057 #define cur_line line[include_depth]
00058 #define web_file file[0]
00059 #define web_file_name file_name[0] \
00060 
00061 #define lines_dont_match (change_limit-change_buffer!=limit-buffer|| \
00062 strncmp(buffer,change_buffer,limit-buffer) )  \
00063 
00064 #define if_section_start_make_pending(b) {*limit= '!'; \
00065 for(loc= buffer;xisspace(*loc) ;loc++) ; \
00066 *limit= ' '; \
00067 if(*loc=='@'&&(xisspace(*(loc+1) ) ||*(loc+1) =='*') ) change_pending= b; \
00068 } \
00069 
00070 #define max_sections 2000 \
00071  \
00072 
00073 #define too_long() {include_depth--; \
00074 err_print("! Include file name too long") ;goto restart;} \
00075 
00076 #define kpse_find_cweb(name) kpse_find_file(name,kpse_cweb_format,true)  \
00077 
00078 #define max_bytes 90000 \
00079 
00080 #define max_names 4000 \
00081  \
00082 
00083 #define length(c) (c+1) ->byte_start-(c) ->byte_start
00084 #define print_id(c) term_write((c) ->byte_start,length((c) ) )  \
00085 
00086 #define hash_size 353 \
00087 
00088 #define llink link
00089 #define rlink dummy.Rlink
00090 #define root name_dir->rlink \
00091  \
00092 
00093 #define first_chunk(p) ((p) ->byte_start+2) 
00094 #define prefix_length(p) (int) ((unsigned char) *((p) ->byte_start) *256+ \
00095 (unsigned char) *((p) ->byte_start+1) ) 
00096 #define set_prefix_length(p,m) (*((p) ->byte_start) = (m) /256, \
00097 *((p) ->byte_start+1) = (m) %256)  \
00098 
00099 #define less 0
00100 #define equal 1
00101 #define greater 2
00102 #define prefix 3
00103 #define extension 4 \
00104 
00105 #define bad_extension 5 \
00106 
00107 #define spotless 0
00108 #define harmless_message 1
00109 #define error_message 2
00110 #define fatal_message 3
00111 #define mark_harmless {if(history==spotless) history= harmless_message;}
00112 #define mark_error history= error_message \
00113 
00114 #define confusion(s) fatal("! This can't happen: ",s)  \
00115  \
00116 
00117 #define show_banner flags['b']
00118 #define show_progress flags['p']
00119 #define show_stats flags['s']
00120 #define show_happiness flags['h']
00121 #define show_kpathsea_debug flags['d'] \
00122  \
00123 
00124 #define update_terminal fflush(stdout)  \
00125 
00126 #define new_line putchar('\n') 
00127 #define putxchar putchar
00128 #define term_write(a,b) fflush(stdout) ,fwrite(a,sizeof(char) ,b,stdout) 
00129 #define C_printf(c,a) fprintf(C_file,c,a) 
00130 #define C_putc(c) putc(c,C_file)  \
00131  \
00132 
00133 #define ctangle_banner "This is CTANGLE, Version 3.64"
00134 #define cweave_banner "This is CWEAVE, Version 3.64" \
00135 
00136 
00137 #line 60 "./cwebdir/common.w"
00138 
00139 /*2:*/
00140 #line 73 "./cwebdir/common.w"
00141 
00142 #line 75 "./cwebdir/common.w"
00143 boolean program;
00144 
00145 /*:2*//*7:*/
00146 #line 159 "./cwebdir/common.w"
00147 
00148 char buffer[long_buf_size];
00149 char*buffer_end= buffer+buf_size-2;
00150 char*limit= buffer;
00151 char*loc= buffer;
00152 
00153 /*:7*//*10:*/
00154 #line 214 "./cwebdir/common.w"
00155 
00156 int include_depth;
00157 FILE*file[max_include_depth];
00158 FILE*change_file;
00159 char file_name[max_include_depth][max_file_name_length];
00160 
00161 char change_file_name[max_file_name_length];
00162 #line 222 "./cwebdir/common.w"
00163 int line[max_include_depth];
00164 int change_line;
00165 int change_depth;
00166 boolean input_has_ended;
00167 boolean changing;
00168 boolean web_file_open= 0;
00169 
00170 /*:10*//*20:*/
00171 #line 418 "./cwebdir/common.w"
00172 
00173 typedef unsigned short sixteen_bits;
00174 sixteen_bits section_count;
00175 boolean changed_section[max_sections];
00176 boolean change_pending;
00177 
00178 boolean print_where= 0;
00179 
00180 /*:20*//*29:*/
00181 #line 594 "./cwebdir/common.w"
00182 
00183 typedef struct name_info{
00184 char*byte_start;
00185 /*33:*/
00186 #line 631 "./cwebdir/common.w"
00187 
00188 struct name_info*link;
00189 
00190 /*:33*//*42:*/
00191 #line 730 "./cwebdir/common.w"
00192 
00193 union{
00194 struct name_info*Rlink;
00195 
00196 char Ilk;
00197 }dummy;
00198 
00199 /*:42*//*57:*/
00200 #line 1062 "./cwebdir/common.w"
00201 
00202 char*equiv_or_xref;
00203 
00204 /*:57*/
00205 #line 597 "./cwebdir/common.w"
00206 
00207 }name_info;
00208 typedef name_info*name_pointer;
00209 char byte_mem[max_bytes];
00210 char*byte_mem_end= byte_mem+max_bytes-1;
00211 name_info name_dir[max_names];
00212 name_pointer name_dir_end= name_dir+max_names-1;
00213 
00214 /*:29*//*31:*/
00215 #line 617 "./cwebdir/common.w"
00216 
00217 name_pointer name_ptr;
00218 char*byte_ptr;
00219 
00220 /*:31*//*34:*/
00221 #line 644 "./cwebdir/common.w"
00222 
00223 typedef name_pointer*hash_pointer;
00224 name_pointer hash[hash_size];
00225 hash_pointer hash_end= hash+hash_size-1;
00226 hash_pointer h;
00227 
00228 /*:34*//*58:*/
00229 #line 1082 "./cwebdir/common.w"
00230 
00231 int history= spotless;
00232 
00233 /*:58*//*69:*/
00234 #line 1220 "./cwebdir/common.w"
00235 
00236 int argc;
00237 char**argv;
00238 char C_file_name[max_file_name_length];
00239 char tex_file_name[max_file_name_length];
00240 char idx_file_name[max_file_name_length];
00241 char scn_file_name[max_file_name_length];
00242 boolean flags[128];
00243 
00244 /*:69*//*79:*/
00245 #line 1370 "./cwebdir/common.w"
00246 
00247 FILE*C_file;
00248 FILE*tex_file;
00249 FILE*idx_file;
00250 FILE*scn_file;
00251 #line 576 "./cwebdir/comm-w2c.ch"
00252 FILE*active_file;
00253 char*found_filename;
00254 #line 1376 "./cwebdir/common.w"
00255 
00256 /*:79*/
00257 #line 61 "./cwebdir/common.w"
00258 
00259 /*3:*/
00260 #line 83 "./cwebdir/common.w"
00261 int phase;
00262 
00263 /*:3*//*11:*/
00264 #line 240 "./cwebdir/common.w"
00265 
00266 char change_buffer[buf_size];
00267 char*change_limit;
00268 
00269 /*:11*/
00270 #line 62 "./cwebdir/common.w"
00271 
00272 /*35:*/
00273 #line 650 "./cwebdir/common.w"
00274 
00275 #line 260 "./cwebdir/comm-w2c.ch"
00276 extern int names_match P4H(name_pointer,char*,int,char);
00277 #line 652 "./cwebdir/common.w"
00278 
00279 /*:35*//*40:*/
00280 #line 703 "./cwebdir/common.w"
00281 
00282 #line 280 "./cwebdir/comm-w2c.ch"
00283 extern void init_p P2C(name_pointer,p,char,t);
00284 #line 705 "./cwebdir/common.w"
00285 
00286 /*:40*//*48:*/
00287 #line 852 "./cwebdir/common.w"
00288 
00289 #line 327 "./cwebdir/comm-w2c.ch"
00290 extern void init_node P1C(name_pointer,node);
00291 #line 854 "./cwebdir/common.w"
00292 
00293 /*:48*//*55:*/
00294 #line 1017 "./cwebdir/common.w"
00295 
00296 #line 373 "./cwebdir/comm-w2c.ch"
00297 int section_name_cmp P3H(char**,int,name_pointer);
00298 #line 1019 "./cwebdir/common.w"
00299 
00300 /*:55*//*59:*/
00301 #line 1092 "./cwebdir/common.w"
00302 
00303 #line 392 "./cwebdir/comm-w2c.ch"
00304 void err_print P1H(char*);
00305 #line 1094 "./cwebdir/common.w"
00306 
00307 /*:59*//*62:*/
00308 #line 1140 "./cwebdir/common.w"
00309 
00310 #line 410 "./cwebdir/comm-w2c.ch"
00311 int wrap_up P1H(void);
00312 extern void print_stats P1H(void);
00313 #line 1143 "./cwebdir/common.w"
00314 
00315 /*:62*//*65:*/
00316 #line 1173 "./cwebdir/common.w"
00317 
00318 #line 427 "./cwebdir/comm-w2c.ch"
00319 void fatal P2H(char*,char*);
00320 void overflow(char*);
00321 #line 1175 "./cwebdir/common.w"
00322 
00323 /*:65*//*71:*/
00324 #line 1251 "./cwebdir/common.w"
00325 
00326 #line 495 "./cwebdir/comm-w2c.ch"
00327 void scan_args P1H(void);
00328 #line 1253 "./cwebdir/common.w"
00329 
00330 /*:71*/
00331 #line 63 "./cwebdir/common.w"
00332 
00333 
00334 /*:1*//*4:*/
00335 #line 89 "./cwebdir/common.w"
00336 
00337 void
00338 #line 51 "./cwebdir/comm-w2c.ch"
00339  common_init P1H(void)
00340 #line 92 "./cwebdir/common.w"
00341 {
00342 #line 57 "./cwebdir/comm-w2c.ch"
00343 /*32:*/
00344 #line 621 "./cwebdir/common.w"
00345 
00346 name_dir->byte_start= byte_ptr= byte_mem;
00347 name_ptr= name_dir+1;
00348 name_ptr->byte_start= byte_mem;
00349 
00350 /*:32*//*36:*/
00351 #line 655 "./cwebdir/common.w"
00352 
00353 for(h= hash;h<=hash_end;*h++= NULL);
00354 
00355 /*:36*//*43:*/
00356 #line 737 "./cwebdir/common.w"
00357 
00358 root= NULL;
00359 
00360 /*:43*/
00361 #line 57 "./cwebdir/comm-w2c.ch"
00362 ;
00363 /*24:*/
00364 #line 188 "./cwebdir/comm-w2c.ch"
00365 
00366 kpse_set_program_name(argv[0],"cweb");
00367 #line 473 "./cwebdir/common.w"
00368 
00369 /*:24*/
00370 #line 58 "./cwebdir/comm-w2c.ch"
00371 ;
00372 #line 94 "./cwebdir/common.w"
00373 /*70:*/
00374 #line 1233 "./cwebdir/common.w"
00375 
00376 #line 487 "./cwebdir/comm-w2c.ch"
00377 show_banner= show_happiness= show_progress= 1;
00378 #line 1235 "./cwebdir/common.w"
00379 
00380 /*:70*/
00381 #line 94 "./cwebdir/common.w"
00382 ;
00383 /*80:*/
00384 #line 1377 "./cwebdir/common.w"
00385 
00386 scan_args();
00387 if(program==ctangle){
00388 if((C_file= fopen(C_file_name,"w"))==NULL)
00389 fatal("! Cannot open output file ",C_file_name);
00390 
00391 }
00392 else{
00393 if((tex_file= fopen(tex_file_name,"w"))==NULL)
00394 fatal("! Cannot open output file ",tex_file_name);
00395 }
00396 
00397 /*:80*/
00398 #line 95 "./cwebdir/common.w"
00399 ;
00400 }
00401 
00402 /*:4*//*9:*/
00403 #line 172 "./cwebdir/common.w"
00404 
00405 #line 67 "./cwebdir/comm-w2c.ch"
00406 int input_ln P1C(FILE*,fp)
00407 #line 175 "./cwebdir/common.w"
00408 {
00409 register int c= EOF;
00410 register char*k;
00411 if(feof(fp))return(0);
00412 limit= k= buffer;
00413 while(k<=buffer_end&&(c= getc(fp))!=EOF&&c!='\n')
00414 if((*(k++)= c)!=' ')limit= k;
00415 if(k> buffer_end)
00416 if((c= getc(fp))!=EOF&&c!='\n'){
00417 ungetc(c,fp);loc= buffer;err_print("! Input line too long");
00418 
00419 }
00420 if(c==EOF&&limit==buffer)return(0);
00421 
00422 return(1);
00423 }
00424 
00425 /*:9*//*12:*/
00426 #line 251 "./cwebdir/common.w"
00427 
00428 void
00429 #line 88 "./cwebdir/comm-w2c.ch"
00430  prime_the_change_buffer P1H(void)
00431 #line 254 "./cwebdir/common.w"
00432 {
00433 change_limit= change_buffer;
00434 /*13:*/
00435 #line 265 "./cwebdir/common.w"
00436 
00437 while(1){
00438 change_line++;
00439 if(!input_ln(change_file))return;
00440 if(limit<buffer+2)continue;
00441 if(buffer[0]!='@')continue;
00442 if(xisupper(buffer[1]))buffer[1]= tolower(buffer[1]);
00443 if(buffer[1]=='x')break;
00444 if(buffer[1]=='y'||buffer[1]=='z'||buffer[1]=='i'){
00445 loc= buffer+2;
00446 err_print("! Missing @x in change file");
00447 
00448 }
00449 }
00450 
00451 /*:13*/
00452 #line 256 "./cwebdir/common.w"
00453 ;
00454 /*14:*/
00455 #line 282 "./cwebdir/common.w"
00456 
00457 do{
00458 change_line++;
00459 if(!input_ln(change_file)){
00460 err_print("! Change file ended after @x");
00461 
00462 return;
00463 }
00464 }while(limit==buffer);
00465 
00466 /*:14*/
00467 #line 257 "./cwebdir/common.w"
00468 ;
00469 /*15:*/
00470 #line 292 "./cwebdir/common.w"
00471 
00472 {
00473 change_limit= change_buffer+(limit-buffer);
00474 strncpy(change_buffer,buffer,limit-buffer+1);
00475 }
00476 
00477 /*:15*/
00478 #line 258 "./cwebdir/common.w"
00479 ;
00480 }
00481 
00482 /*:12*//*16:*/
00483 #line 320 "./cwebdir/common.w"
00484 
00485 void
00486 #line 96 "./cwebdir/comm-w2c.ch"
00487  check_change P1H(void)
00488 #line 323 "./cwebdir/common.w"
00489 {
00490 int n= 0;
00491 if(lines_dont_match)return;
00492 change_pending= 0;
00493 if(!changed_section[section_count]){
00494 if_section_start_make_pending(1);
00495 if(!change_pending)changed_section[section_count]= 1;
00496 }
00497 while(1){
00498 changing= 1;print_where= 1;change_line++;
00499 if(!input_ln(change_file)){
00500 err_print("! Change file ended before @y");
00501 
00502 change_limit= change_buffer;changing= 0;
00503 return;
00504 }
00505 if(limit> buffer+1&&buffer[0]=='@'){
00506 char xyz_code= xisupper(buffer[1])?tolower(buffer[1]):buffer[1];
00507 /*17:*/
00508 #line 358 "./cwebdir/common.w"
00509 
00510 if(xyz_code=='x'||xyz_code=='z'){
00511 loc= buffer+2;err_print("! Where is the matching @y?");
00512 
00513 }
00514 else if(xyz_code=='y'){
00515 if(n> 0){
00516 loc= buffer+2;
00517 printf("\n! Hmm... %d ",n);
00518 err_print("of the preceding lines failed to match");
00519 
00520 }
00521 change_depth= include_depth;
00522 return;
00523 }
00524 
00525 /*:17*/
00526 #line 342 "./cwebdir/common.w"
00527 ;
00528 }
00529 /*15:*/
00530 #line 292 "./cwebdir/common.w"
00531 
00532 {
00533 change_limit= change_buffer+(limit-buffer);
00534 strncpy(change_buffer,buffer,limit-buffer+1);
00535 }
00536 
00537 /*:15*/
00538 #line 344 "./cwebdir/common.w"
00539 ;
00540 changing= 0;cur_line++;
00541 while(!input_ln(cur_file)){
00542 if(include_depth==0){
00543 err_print("! CWEB file ended during a change");
00544 
00545 input_has_ended= 1;return;
00546 }
00547 include_depth--;cur_line++;
00548 }
00549 if(lines_dont_match)n++;
00550 }
00551 }
00552 
00553 /*:16*//*18:*/
00554 #line 378 "./cwebdir/common.w"
00555 
00556 void
00557 #line 104 "./cwebdir/comm-w2c.ch"
00558  reset_input P1H(void)
00559 #line 381 "./cwebdir/common.w"
00560 {
00561 limit= buffer;loc= buffer+1;buffer[0]= ' ';
00562 /*19:*/
00563 #line 393 "./cwebdir/common.w"
00564 
00565 #line 116 "./cwebdir/comm-w2c.ch"
00566 if((found_filename= kpse_find_cweb(web_file_name))==NULL||
00567 (web_file= fopen(found_filename,"r"))==NULL){
00568 fatal("! Cannot open input file ",web_file_name);
00569 }else if(strlen(found_filename)<max_file_name_length){
00570 strcpy(web_file_name,found_filename);
00571 free(found_filename);
00572 }
00573 #line 399 "./cwebdir/common.w"
00574 
00575 
00576 web_file_open= 1;
00577 #line 129 "./cwebdir/comm-w2c.ch"
00578 if((found_filename= kpse_find_cweb(change_file_name))==NULL||
00579 (change_file= fopen(found_filename,"r"))==NULL){
00580 fatal("! Cannot open change file ",change_file_name);
00581 }else if(strlen(found_filename)<max_file_name_length){
00582 strcpy(change_file_name,found_filename);
00583 free(found_filename);
00584 }
00585 #line 404 "./cwebdir/common.w"
00586 
00587 /*:19*/
00588 #line 383 "./cwebdir/common.w"
00589 ;
00590 include_depth= 0;cur_line= 0;change_line= 0;
00591 change_depth= include_depth;
00592 changing= 1;prime_the_change_buffer();changing= !changing;
00593 limit= buffer;loc= buffer+1;buffer[0]= ' ';input_has_ended= 0;
00594 }
00595 
00596 /*:18*//*21:*/
00597 #line 426 "./cwebdir/common.w"
00598 
00599 #line 143 "./cwebdir/comm-w2c.ch"
00600 int get_line P1H(void)
00601 #line 428 "./cwebdir/common.w"
00602 {
00603 restart:
00604 if(changing&&include_depth==change_depth)
00605 /*27:*/
00606 #line 537 "./cwebdir/common.w"
00607 {
00608 change_line++;
00609 if(!input_ln(change_file)){
00610 err_print("! Change file ended without @z");
00611 
00612 buffer[0]= '@';buffer[1]= 'z';limit= buffer+2;
00613 }
00614 if(limit> buffer){
00615 if(change_pending){
00616 if_section_start_make_pending(0);
00617 if(change_pending){
00618 changed_section[section_count]= 1;change_pending= 0;
00619 }
00620 }
00621 *limit= ' ';
00622 if(buffer[0]=='@'){
00623 if(xisupper(buffer[1]))buffer[1]= tolower(buffer[1]);
00624 if(buffer[1]=='x'||buffer[1]=='y'){
00625 loc= buffer+2;
00626 err_print("! Where is the matching @z?");
00627 
00628 }
00629 else if(buffer[1]=='z'){
00630 prime_the_change_buffer();changing= !changing;print_where= 1;
00631 }
00632 }
00633 }
00634 }
00635 
00636 /*:27*/
00637 #line 431 "./cwebdir/common.w"
00638 ;
00639 if(!changing||include_depth> change_depth){
00640 /*26:*/
00641 #line 520 "./cwebdir/common.w"
00642 {
00643 cur_line++;
00644 while(!input_ln(cur_file)){
00645 print_where= 1;
00646 if(include_depth==0){input_has_ended= 1;break;}
00647 else{
00648 fclose(cur_file);include_depth--;
00649 if(changing&&include_depth==change_depth)break;
00650 cur_line++;
00651 }
00652 }
00653 if(!changing&&!input_has_ended)
00654 if(limit-buffer==change_limit-change_buffer)
00655 if(buffer[0]==change_buffer[0])
00656 if(change_limit> change_buffer)check_change();
00657 }
00658 
00659 /*:26*/
00660 #line 433 "./cwebdir/common.w"
00661 ;
00662 if(changing&&include_depth==change_depth)goto restart;
00663 }
00664 if(input_has_ended)return 0;
00665 loc= buffer;*limit= ' ';
00666 if(buffer[0]=='@'&&(buffer[1]=='i'||buffer[1]=='I')){
00667 loc= buffer+2;*limit= '"';
00668 while(*loc==' '||*loc=='\t')loc++;
00669 if(loc>=limit){
00670 err_print("! Include file name not given");
00671 
00672 goto restart;
00673 }
00674 if(include_depth>=max_include_depth-1){
00675 err_print("! Too many nested includes");
00676 
00677 goto restart;
00678 }
00679 include_depth++;
00680 /*25:*/
00681 #line 474 "./cwebdir/common.w"
00682 {
00683 #line 201 "./cwebdir/comm-w2c.ch"
00684 char*cur_file_name_end= cur_file_name+max_file_name_length-1;
00685 char*k= cur_file_name;
00686 #line 479 "./cwebdir/common.w"
00687 
00688 if(*loc=='"'){
00689 loc++;
00690 while(*loc!='"'&&k<=cur_file_name_end)*k++= *loc++;
00691 if(loc==limit)k= cur_file_name_end+1;
00692 }else
00693 while(*loc!=' '&&*loc!='\t'&&*loc!='"'&&k<=cur_file_name_end)*k++= *loc++;
00694 if(k> cur_file_name_end)too_long();
00695 
00696 *k= '\0';
00697 #line 208 "./cwebdir/comm-w2c.ch"
00698 if((found_filename= kpse_find_cweb(cur_file_name))!=NULL&&
00699 (cur_file= fopen(found_filename,"r"))!=NULL){
00700 
00701 if(strlen(found_filename)<max_file_name_length){
00702 strcpy(cur_file_name,found_filename);
00703 free(found_filename);
00704 }
00705 #line 490 "./cwebdir/common.w"
00706 cur_line= 0;print_where= 1;
00707 goto restart;
00708 }
00709 #line 517 "./cwebdir/common.w"
00710 include_depth--;err_print("! Cannot open include file");goto restart;
00711 }
00712 
00713 /*:25*/
00714 #line 452 "./cwebdir/common.w"
00715 ;
00716 }
00717 return 1;
00718 }
00719 
00720 /*:21*//*28:*/
00721 #line 569 "./cwebdir/common.w"
00722 
00723 void
00724 #line 252 "./cwebdir/comm-w2c.ch"
00725  check_complete P1H(void){
00726 #line 572 "./cwebdir/common.w"
00727 if(change_limit!=change_buffer){
00728 strncpy(buffer,change_buffer,change_limit-change_buffer+1);
00729 limit= buffer+(int)(change_limit-change_buffer);
00730 changing= 1;change_depth= include_depth;loc= buffer;
00731 err_print("! Change file entry did not match");
00732 
00733 }
00734 }
00735 
00736 /*:28*//*37:*/
00737 #line 660 "./cwebdir/common.w"
00738 
00739 name_pointer
00740 #line 271 "./cwebdir/comm-w2c.ch"
00741 
00742 id_lookup P3C(char*,first,char*,last,char,t)
00743 #line 666 "./cwebdir/common.w"
00744 {
00745 char*i= first;
00746 int h;
00747 int l;
00748 name_pointer p;
00749 if(last==NULL)for(last= first;*last!='\0';last++);
00750 l= last-first;
00751 /*38:*/
00752 #line 683 "./cwebdir/common.w"
00753 
00754 h= (unsigned char)*i;
00755 while(++i<last)h= (h+h+(int)((unsigned char)*i))%hash_size;
00756 
00757 
00758 /*:38*/
00759 #line 673 "./cwebdir/common.w"
00760 ;
00761 /*39:*/
00762 #line 691 "./cwebdir/common.w"
00763 
00764 p= hash[h];
00765 while(p&&!names_match(p,first,l,t))p= p->link;
00766 if(p==NULL){
00767 p= name_ptr;
00768 p->link= hash[h];hash[h]= p;
00769 }
00770 
00771 /*:39*/
00772 #line 674 "./cwebdir/common.w"
00773 ;
00774 if(p==name_ptr)/*41:*/
00775 #line 706 "./cwebdir/common.w"
00776 {
00777 if(byte_ptr+l> byte_mem_end)overflow("byte memory");
00778 if(name_ptr>=name_dir_end)overflow("name");
00779 strncpy(byte_ptr,first,l);
00780 (++name_ptr)->byte_start= byte_ptr+= l;
00781 if(program==cweave)init_p(p,t);
00782 }
00783 
00784 /*:41*/
00785 #line 675 "./cwebdir/common.w"
00786 ;
00787 return(p);
00788 }
00789 
00790 /*:37*//*44:*/
00791 #line 764 "./cwebdir/common.w"
00792 
00793 void
00794 #line 289 "./cwebdir/comm-w2c.ch"
00795  print_section_name P1C(name_pointer,p)
00796 #line 768 "./cwebdir/common.w"
00797 {
00798 char*ss,*s= first_chunk(p);
00799 name_pointer q= p+1;
00800 while(p!=name_dir){
00801 ss= (p+1)->byte_start-1;
00802 if(*ss==' '&&ss>=s){
00803 term_write(s,ss-s);p= q->link;q= p;
00804 }else{
00805 term_write(s,ss+1-s);p= name_dir;q= NULL;
00806 }
00807 s= p->byte_start;
00808 }
00809 if(q)term_write("...",3);
00810 }
00811 
00812 /*:44*//*45:*/
00813 #line 783 "./cwebdir/common.w"
00814 
00815 void
00816 #line 299 "./cwebdir/comm-w2c.ch"
00817  sprint_section_name P2C(char*,dest,name_pointer,p)
00818 #line 788 "./cwebdir/common.w"
00819 {
00820 char*ss,*s= first_chunk(p);
00821 name_pointer q= p+1;
00822 while(p!=name_dir){
00823 ss= (p+1)->byte_start-1;
00824 if(*ss==' '&&ss>=s){
00825 p= q->link;q= p;
00826 }else{
00827 ss++;p= name_dir;
00828 }
00829 strncpy(dest,s,ss-s),dest+= ss-s;
00830 s= p->byte_start;
00831 }
00832 *dest= '\0';
00833 }
00834 
00835 /*:45*//*46:*/
00836 #line 804 "./cwebdir/common.w"
00837 
00838 void
00839 #line 308 "./cwebdir/comm-w2c.ch"
00840  print_prefix_name P1C(name_pointer,p)
00841 #line 808 "./cwebdir/common.w"
00842 {
00843 char*s= first_chunk(p);
00844 int l= prefix_length(p);
00845 term_write(s,l);
00846 if(s+l<(p+1)->byte_start)term_write("...",3);
00847 }
00848 
00849 /*:46*//*47:*/
00850 #line 825 "./cwebdir/common.w"
00851 
00852 #line 318 "./cwebdir/comm-w2c.ch"
00853 
00854 int web_strcmp P4C(char*,j,int,j_len,char*,k,int,k_len)
00855 #line 829 "./cwebdir/common.w"
00856 {
00857 char*j1= j+j_len,*k1= k+k_len;
00858 while(k<k1&&j<j1&&*j==*k)k++,j++;
00859 if(k==k1)if(j==j1)return equal;
00860 else return extension;
00861 else if(j==j1)return prefix;
00862 else if(*j<*k)return less;
00863 else return greater;
00864 }
00865 
00866 /*:47*//*49:*/
00867 #line 855 "./cwebdir/common.w"
00868 
00869 name_pointer
00870 #line 340 "./cwebdir/comm-w2c.ch"
00871 
00872 add_section_name P5C(name_pointer,par,int,c,char*,first,char*,last,
00873 int,ispref)
00874 #line 863 "./cwebdir/common.w"
00875 {
00876 name_pointer p= name_ptr;
00877 char*s= first_chunk(p);
00878 int name_len= last-first+ispref;
00879 if(s+name_len> byte_mem_end)overflow("byte memory");
00880 if(name_ptr+1>=name_dir_end)overflow("name");
00881 (++name_ptr)->byte_start= byte_ptr= s+name_len;
00882 if(ispref){
00883 *(byte_ptr-1)= ' ';
00884 name_len--;
00885 name_ptr->link= name_dir;
00886 (++name_ptr)->byte_start= byte_ptr;
00887 }
00888 set_prefix_length(p,name_len);
00889 strncpy(s,first,name_len);
00890 p->llink= NULL;
00891 p->rlink= NULL;
00892 init_node(p);
00893 return par==NULL?(root= p):c==less?(par->llink= p):(par->rlink= p);
00894 }
00895 
00896 /*:49*//*50:*/
00897 #line 884 "./cwebdir/common.w"
00898 
00899 void
00900 #line 354 "./cwebdir/comm-w2c.ch"
00901  extend_section_name P4C(name_pointer,p,char*,first,char*,last,int,ispref)
00902 #line 891 "./cwebdir/common.w"
00903 {
00904 char*s;
00905 name_pointer q= p+1;
00906 int name_len= last-first+ispref;
00907 if(name_ptr>=name_dir_end)overflow("name");
00908 while(q->link!=name_dir)q= q->link;
00909 q->link= name_ptr;
00910 s= name_ptr->byte_start;
00911 name_ptr->link= name_dir;
00912 if(s+name_len> byte_mem_end)overflow("byte memory");
00913 (++name_ptr)->byte_start= byte_ptr= s+name_len;
00914 strncpy(s,first,name_len);
00915 if(ispref)*(byte_ptr-1)= ' ';
00916 }
00917 
00918 /*:50*//*51:*/
00919 #line 912 "./cwebdir/common.w"
00920 
00921 name_pointer
00922 #line 364 "./cwebdir/comm-w2c.ch"
00923 
00924 section_lookup P3C(char*,first,char*,last,int,ispref)
00925 #line 917 "./cwebdir/common.w"
00926 {
00927 int c= 0;
00928 name_pointer p= root;
00929 name_pointer q= NULL;
00930 name_pointer r= NULL;
00931 name_pointer par= NULL;
00932 
00933 int name_len= last-first+1;
00934 /*52:*/
00935 #line 936 "./cwebdir/common.w"
00936 
00937 while(p){
00938 c= web_strcmp(first,name_len,first_chunk(p),prefix_length(p));
00939 if(c==less||c==greater){
00940 if(r==NULL)
00941 par= p;
00942 p= (c==less?p->llink:p->rlink);
00943 }else{
00944 if(r!=NULL){
00945 printf("\n! Ambiguous prefix: matches <");
00946 
00947 print_prefix_name(p);
00948 printf(">\n and <");
00949 print_prefix_name(r);
00950 err_print(">");
00951 return name_dir;
00952 }
00953 r= p;
00954 p= p->llink;
00955 q= r->rlink;
00956 }
00957 if(p==NULL)
00958 p= q,q= NULL;
00959 }
00960 
00961 /*:52*/
00962 #line 926 "./cwebdir/common.w"
00963 ;
00964 /*53:*/
00965 #line 961 "./cwebdir/common.w"
00966 
00967 if(r==NULL)
00968 return add_section_name(par,c,first,last+1,ispref);
00969 
00970 /*:53*/
00971 #line 927 "./cwebdir/common.w"
00972 ;
00973 /*54:*/
00974 #line 969 "./cwebdir/common.w"
00975 
00976 switch(section_name_cmp(&first,name_len,r)){
00977 
00978 case prefix:
00979 if(!ispref){
00980 printf("\n! New name is a prefix of <");
00981 
00982 print_section_name(r);
00983 err_print(">");
00984 }
00985 else if(name_len<prefix_length(r))set_prefix_length(r,name_len);
00986 
00987 case equal:return r;
00988 case extension:if(!ispref||first<=last)
00989 extend_section_name(r,first,last+1,ispref);
00990 return r;
00991 case bad_extension:
00992 printf("\n! New name extends <");
00993 
00994 print_section_name(r);
00995 err_print(">");
00996 return r;
00997 default:
00998 printf("\n! Section name incompatible with <");
00999 
01000 print_prefix_name(r);
01001 printf(">,\n which abbreviates <");
01002 print_section_name(r);
01003 err_print(">");
01004 return r;
01005 }
01006 
01007 /*:54*/
01008 #line 928 "./cwebdir/common.w"
01009 ;
01010 }
01011 
01012 /*:51*//*56:*/
01013 #line 1020 "./cwebdir/common.w"
01014 
01015 #line 384 "./cwebdir/comm-w2c.ch"
01016 int section_name_cmp P3C(char**,pfirst,int,len,name_pointer,r)
01017 #line 1025 "./cwebdir/common.w"
01018 {
01019 char*first= *pfirst;
01020 name_pointer q= r+1;
01021 char*ss,*s= first_chunk(r);
01022 int c;
01023 int ispref;
01024 while(1){
01025 ss= (r+1)->byte_start-1;
01026 if(*ss==' '&&ss>=r->byte_start)ispref= 1,q= q->link;
01027 else ispref= 0,ss++,q= name_dir;
01028 switch(c= web_strcmp(first,len,s,ss-s)){
01029 case equal:if(q==name_dir)
01030 if(ispref){
01031 *pfirst= first+(ss-s);
01032 return extension;
01033 }else return equal;
01034 else return(q->byte_start==(q+1)->byte_start)?equal:prefix;
01035 case extension:
01036 if(!ispref)return bad_extension;
01037 first+= ss-s;
01038 if(q!=name_dir){len-= ss-s;s= q->byte_start;r= q;continue;}
01039 *pfirst= first;return extension;
01040 default:return c;
01041 }
01042 }
01043 }
01044 
01045 /*:56*//*60:*/
01046 #line 1095 "./cwebdir/common.w"
01047 
01048 void
01049 #line 401 "./cwebdir/comm-w2c.ch"
01050  err_print P1C(char*,s)
01051 #line 1099 "./cwebdir/common.w"
01052 {
01053 char*k,*l;
01054 printf(*s=='!'?"\n%s":"%s",s);
01055 if(web_file_open)/*61:*/
01056 #line 1115 "./cwebdir/common.w"
01057 
01058 {if(changing&&include_depth==change_depth)
01059 printf(". (l. %d of change file)\n",change_line);
01060 else if(include_depth==0)printf(". (l. %d)\n",cur_line);
01061 else printf(". (l. %d of include file %s)\n",cur_line,cur_file_name);
01062 l= (loc>=limit?limit:loc);
01063 if(l> buffer){
01064 for(k= buffer;k<l;k++)
01065 if(*k=='\t')putchar(' ');
01066 else putchar(*k);
01067 putchar('\n');
01068 for(k= buffer;k<l;k++)putchar(' ');
01069 }
01070 for(k= l;k<limit;k++)putchar(*k);
01071 if(*limit=='|')putchar('|');
01072 putchar(' ');
01073 }
01074 
01075 /*:61*/
01076 #line 1102 "./cwebdir/common.w"
01077 ;
01078 update_terminal;mark_error;
01079 }
01080 
01081 /*:60*//*63:*/
01082 #line 1150 "./cwebdir/common.w"
01083 
01084 #line 419 "./cwebdir/comm-w2c.ch"
01085 int wrap_up P1H(void){
01086 #line 1152 "./cwebdir/common.w"
01087 putchar('\n');
01088 if(show_stats)
01089 print_stats();
01090 /*64:*/
01091 #line 1160 "./cwebdir/common.w"
01092 
01093 switch(history){
01094 case spotless:if(show_happiness)printf("(No errors were found.)\n");break;
01095 case harmless_message:
01096 printf("(Did you see the warning message above?)\n");break;
01097 case error_message:
01098 printf("(Pardon me, but I think I spotted something wrong.)\n");break;
01099 case fatal_message:printf("(That was a fatal error, my friend.)\n");
01100 }
01101 
01102 /*:64*/
01103 #line 1155 "./cwebdir/common.w"
01104 ;
01105 if(history> harmless_message)return(1);
01106 else return(0);
01107 }
01108 
01109 /*:63*//*66:*/
01110 #line 1179 "./cwebdir/common.w"
01111 void
01112 #line 437 "./cwebdir/comm-w2c.ch"
01113  fatal P2C(char*,s,char*,t)
01114 #line 1182 "./cwebdir/common.w"
01115 {
01116 if(*s)printf(s);
01117 err_print(t);
01118 history= fatal_message;exit(wrap_up());
01119 }
01120 
01121 /*:66*//*67:*/
01122 #line 1190 "./cwebdir/common.w"
01123 void
01124 #line 446 "./cwebdir/comm-w2c.ch"
01125  overflow P1C(char*,t)
01126 #line 1193 "./cwebdir/common.w"
01127 {
01128 printf("\n! Sorry, %s capacity exceeded",t);fatal("","");
01129 }
01130 
01131 
01132 /*:67*//*72:*/
01133 #line 1254 "./cwebdir/common.w"
01134 
01135 void
01136 #line 504 "./cwebdir/comm-w2c.ch"
01137  scan_args P1H(void)
01138 #line 1257 "./cwebdir/common.w"
01139 {
01140 char*dot_pos;
01141 char*name_pos;
01142 register char*s;
01143 boolean found_web= 0,found_change= 0,found_out= 0;
01144 
01145 boolean flag_change;
01146 
01147 while(--argc> 0){
01148 if((**(++argv)=='-'||**argv=='+')&&*(*argv+1))/*76:*/
01149 #line 528 "./cwebdir/comm-w2c.ch"
01150 
01151 {
01152 if(strcmp("-help",*argv)==0||strcmp("--help",*argv)==0)
01153 /*84:*/
01154 #line 605 "./cwebdir/comm-w2c.ch"
01155 
01156 usagehelp(program==ctangle?CTANGLEHELP:CWEAVEHELP,NULL);
01157 
01158 
01159 /*:84*/
01160 #line 531 "./cwebdir/comm-w2c.ch"
01161 ;
01162 if(strcmp("-version",*argv)==0||strcmp("--version",*argv)==0)
01163 /*85:*/
01164 #line 614 "./cwebdir/comm-w2c.ch"
01165 
01166 printversionandexit((program==ctangle?ctangle_banner:cweave_banner),
01167 "Silvio Levy and Donald E. Knuth",NULL);
01168 
01169 
01170 /*:85*/
01171 #line 533 "./cwebdir/comm-w2c.ch"
01172 ;
01173 #line 1346 "./cwebdir/common.w"
01174 if(**argv=='-')flag_change= 0;
01175 #line 539 "./cwebdir/comm-w2c.ch"
01176 else flag_change= 1;
01177 if(*(*argv+1)=='d')
01178 if(sscanf(*argv+2,"%u",&kpathsea_debug)!=1)/*77:*/
01179 #line 1352 "./cwebdir/common.w"
01180 
01181 {
01182 #line 562 "./cwebdir/comm-w2c.ch"
01183 if(program==ctangle){
01184 fprintf(stderr,"ctangle: Need one to three file arguments.\n");
01185 usage("ctangle");
01186 }else{
01187 fprintf(stderr,"cweave: Need one to three file arguments.\n");
01188 usage("cweave");
01189 }
01190 #line 1362 "./cwebdir/common.w"
01191 }
01192 
01193 /*:77*/
01194 #line 541 "./cwebdir/comm-w2c.ch"
01195 ;
01196 #line 1348 "./cwebdir/common.w"
01197 for(dot_pos= *argv+1;*dot_pos> '\0';dot_pos++)
01198 #line 547 "./cwebdir/comm-w2c.ch"
01199 flags[(unsigned char)*dot_pos]= flag_change;
01200 #line 1350 "./cwebdir/common.w"
01201 }
01202 
01203 /*:76*/
01204 #line 1266 "./cwebdir/common.w"
01205 
01206 else{
01207 s= name_pos= *argv;dot_pos= NULL;
01208 while(*s){
01209 if(*s=='.')dot_pos= s++;
01210 else if(*s=='/')dot_pos= NULL,name_pos= ++s;
01211 else s++;
01212 }
01213 if(!found_web)/*73:*/
01214 #line 1292 "./cwebdir/common.w"
01215 
01216 {
01217 if(s-*argv> max_file_name_length-5)
01218 /*78:*/
01219 #line 1364 "./cwebdir/common.w"
01220 fatal("! Filename too long\n",*argv);
01221 
01222 
01223 /*:78*/
01224 #line 1295 "./cwebdir/common.w"
01225 ;
01226 if(dot_pos==NULL)
01227 sprintf(web_file_name,"%s.w",*argv);
01228 else{
01229 strcpy(web_file_name,*argv);
01230 *dot_pos= 0;
01231 }
01232 #line 1303 "./cwebdir/common.w"
01233 sprintf(tex_file_name,"%s.tex",name_pos);
01234 sprintf(idx_file_name,"%s.idx",name_pos);
01235 sprintf(scn_file_name,"%s.scn",name_pos);
01236 sprintf(C_file_name,"%s.c",name_pos);
01237 found_web= 1;
01238 }
01239 
01240 /*:73*/
01241 #line 1275 "./cwebdir/common.w"
01242 
01243 else if(!found_change)/*74:*/
01244 #line 1310 "./cwebdir/common.w"
01245 
01246 {
01247 if(strcmp(*argv,"-")==0)found_change= -1;
01248 else{
01249 if(s-*argv> max_file_name_length-4)
01250 /*78:*/
01251 #line 1364 "./cwebdir/common.w"
01252 fatal("! Filename too long\n",*argv);
01253 
01254 
01255 /*:78*/
01256 #line 1315 "./cwebdir/common.w"
01257 ;
01258 if(dot_pos==NULL)
01259 sprintf(change_file_name,"%s.ch",*argv);
01260 else strcpy(change_file_name,*argv);
01261 found_change= 1;
01262 }
01263 }
01264 
01265 /*:74*/
01266 #line 1276 "./cwebdir/common.w"
01267 
01268 else if(!found_out)/*75:*/
01269 #line 1323 "./cwebdir/common.w"
01270 
01271 {
01272 if(s-*argv> max_file_name_length-5)
01273 /*78:*/
01274 #line 1364 "./cwebdir/common.w"
01275 fatal("! Filename too long\n",*argv);
01276 
01277 
01278 /*:78*/
01279 #line 1326 "./cwebdir/common.w"
01280 ;
01281 if(dot_pos==NULL){
01282 sprintf(tex_file_name,"%s.tex",*argv);
01283 sprintf(idx_file_name,"%s.idx",*argv);
01284 sprintf(scn_file_name,"%s.scn",*argv);
01285 sprintf(C_file_name,"%s.c",*argv);
01286 }else{
01287 strcpy(tex_file_name,*argv);
01288 strcpy(C_file_name,*argv);
01289 if(flags['x']){
01290 *dot_pos= 0;
01291 sprintf(idx_file_name,"%s.idx",*argv);
01292 sprintf(scn_file_name,"%s.scn",*argv);
01293 }
01294 }
01295 found_out= 1;
01296 }
01297 
01298 #line 528 "./cwebdir/comm-w2c.ch"
01299 /*:75*/
01300 #line 1277 "./cwebdir/common.w"
01301 
01302 else/*77:*/
01303 #line 1352 "./cwebdir/common.w"
01304 
01305 {
01306 #line 562 "./cwebdir/comm-w2c.ch"
01307 if(program==ctangle){
01308 fprintf(stderr,"ctangle: Need one to three file arguments.\n");
01309 usage("ctangle");
01310 }else{
01311 fprintf(stderr,"cweave: Need one to three file arguments.\n");
01312 usage("cweave");
01313 }
01314 #line 1362 "./cwebdir/common.w"
01315 }
01316 
01317 /*:77*/
01318 #line 1278 "./cwebdir/common.w"
01319 ;
01320 }
01321 }
01322 if(!found_web)/*77:*/
01323 #line 1352 "./cwebdir/common.w"
01324 
01325 {
01326 #line 562 "./cwebdir/comm-w2c.ch"
01327 if(program==ctangle){
01328 fprintf(stderr,"ctangle: Need one to three file arguments.\n");
01329 usage("ctangle");
01330 }else{
01331 fprintf(stderr,"cweave: Need one to three file arguments.\n");
01332 usage("cweave");
01333 }
01334 #line 1362 "./cwebdir/common.w"
01335 }
01336 
01337 /*:77*/
01338 #line 1281 "./cwebdir/common.w"
01339 ;
01340 #line 513 "./cwebdir/comm-w2c.ch"
01341 if(found_change<=0)strcpy(change_file_name,DEV_NULL);
01342 #line 1283 "./cwebdir/common.w"
01343 }
01344 
01345 /*:72*/