diff options
Diffstat (limited to 'web/c_cpp/cweb/common.c')
-rw-r--r-- | web/c_cpp/cweb/common.c | 1059 |
1 files changed, 572 insertions, 487 deletions
diff --git a/web/c_cpp/cweb/common.c b/web/c_cpp/cweb/common.c index 2bf7a9d4a8..7dd0f0c083 100644 --- a/web/c_cpp/cweb/common.c +++ b/web/c_cpp/cweb/common.c @@ -1,26 +1,22 @@ /*1:*/ -#line 58 "common.w" +#line 66 "common.w" -/*5:*/ -#line 102 "common.w" - -#include <ctype.h> - -/*:5*//*8:*/ -#line 165 "common.w" - -#include <stdio.h> - -/*:8*//*22:*/ -#line 471 "common.w" +/*3:*/ +#line 46 "common.h" +#include <ctype.h> +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> #include <stdlib.h> +#include <stdio.h> +#include <string.h> -/*:22*/ -#line 59 "common.w" +/*:3*/ +#line 67 "common.w" -#define ctangle 0 -#define cweave 1 \ +#define ctangle false +#define cweave true \ #define and_and 04 #define lt_lt 020 @@ -28,7 +24,7 @@ #define plus_plus 013 #define minus_minus 01 #define minus_gt 031 -#define not_eq 032 +#define non_eq 032 #define lt_eq 034 #define gt_eq 035 #define eq_eq 036 @@ -38,23 +34,65 @@ #define period_ast 026 #define minus_gt_ast 027 \ -#define buf_size 100 -#define longest_name 10000 -#define long_buf_size (buf_size+longest_name) -#define xisspace(c) (isspace(c) &&((unsigned char) c<0200) ) -#define xisupper(c) (isupper(c) &&((unsigned char) c<0200) ) \ +#define xisalpha(c) (isalpha((eight_bits) c) &&((eight_bits) c<0200) ) +#define xisdigit(c) (isdigit((eight_bits) c) &&((eight_bits) c<0200) ) +#define xisspace(c) (isspace((eight_bits) c) &&((eight_bits) c<0200) ) +#define xislower(c) (islower((eight_bits) c) &&((eight_bits) c<0200) ) +#define xisupper(c) (isupper((eight_bits) c) &&((eight_bits) c<0200) ) +#define xisxdigit(c) (isxdigit((eight_bits) c) &&((eight_bits) c<0200) ) \ #define max_include_depth 10 \ -#define max_file_name_length 60 +#define max_file_name_length 1024 #define cur_file file[include_depth] #define cur_file_name file_name[include_depth] #define cur_line line[include_depth] #define web_file file[0] #define web_file_name file_name[0] \ +#define length(c) (size_t) ((c+1) ->byte_start-(c) ->byte_start) +#define print_id(c) term_write((c) ->byte_start,length((c) ) ) +#define llink link +#define rlink dummy.Rlink +#define root name_dir->rlink \ + \ + +#define spotless 0 +#define harmless_message 1 +#define error_message 2 +#define fatal_message 3 +#define mark_harmless {if(history==spotless) history= harmless_message;} +#define mark_error history= error_message +#define confusion(s) fatal("! This can't happen: ",s) \ + \ + +#define show_banner flags['b'] +#define show_progress flags['p'] +#define show_stats flags['s'] +#define show_happiness flags['h'] +#define make_xrefs flags['x'] \ + +#define update_terminal fflush(stdout) +#define new_line putchar('\n') +#define putxchar putchar +#define term_write(a,b) fflush(stdout) ,fwrite(a,sizeof(char) ,b,stdout) +#define C_printf(c,a) fprintf(C_file,c,a) +#define C_putc(c) putc(c,C_file) \ + +#define max_bytes 1000000 \ + +#define max_toks 1000000 +#define max_names 10239 \ + +#define max_sections 4000 +#define max_texts 10239 +#define longest_name 10000 +#define stack_size 500 +#define buf_size 1000 +#define long_buf_size (buf_size+longest_name) \ + #define lines_dont_match (change_limit-change_buffer!=limit-buffer|| \ -strncmp(buffer,change_buffer,limit-buffer) ) \ +strncmp(buffer,change_buffer,(size_t) (limit-buffer) ) ) \ #define if_section_start_make_pending(b) {*limit= '!'; \ for(loc= buffer;xisspace(*loc) ;loc++) ; \ @@ -62,30 +100,14 @@ for(loc= buffer;xisspace(*loc) ;loc++) ; \ if(*loc=='@'&&(xisspace(*(loc+1) ) ||*(loc+1) =='*') ) change_pending= b; \ } \ -#define max_sections 2000 \ - \ - #define too_long() {include_depth--; \ err_print("! Include file name too long") ;goto restart;} \ -#define max_bytes 90000 \ - -#define max_names 4000 \ - \ - -#define length(c) (c+1) ->byte_start-(c) ->byte_start -#define print_id(c) term_write((c) ->byte_start,length((c) ) ) \ - -#define hash_size 353 \ - -#define llink link -#define rlink dummy.Rlink -#define root name_dir->rlink \ - \ +#define hash_size 8501 \ #define first_chunk(p) ((p) ->byte_start+2) -#define prefix_length(p) (int) ((unsigned char) *((p) ->byte_start) *256+ \ -(unsigned char) *((p) ->byte_start+1) ) +#define prefix_length(p) (int) ((eight_bits) *((p) ->byte_start) *256+ \ +(eight_bits) *((p) ->byte_start+1) ) #define set_prefix_length(p,m) (*((p) ->byte_start) = (m) /256, \ *((p) ->byte_start+1) = (m) %256) \ @@ -97,48 +119,140 @@ err_print("! Include file name too long") ;goto restart;} \ #define bad_extension 5 \ -#define spotless 0 -#define harmless_message 1 -#define error_message 2 -#define fatal_message 3 -#define mark_harmless {if(history==spotless) history= harmless_message;} -#define mark_error history= error_message \ +#define flag_change (**argv!='-') -#define confusion(s) fatal("! This can't happen: ",s) \ - \ +#line 68 "common.w" -#define show_banner flags['b'] -#define show_progress flags['p'] -#define show_stats flags['s'] -#define show_happiness flags['h'] \ +/*2:*/ +#line 37 "common.h" -#define update_terminal fflush(stdout) \ +typedef bool boolean; +typedef uint8_t eight_bits; +typedef uint16_t sixteen_bits; +extern boolean program; +extern int phase; -#define new_line putchar('\n') -#define putxchar putchar -#define term_write(a,b) fflush(stdout) ,fwrite(a,sizeof(char) ,b,stdout) -#define C_printf(c,a) fprintf(C_file,c,a) -#define C_putc(c) putc(c,C_file) \ +/*:2*//*4:*/ +#line 74 "common.h" +extern char section_text[]; +extern char*section_text_end; +extern char*id_first; +extern char*id_loc; -#line 60 "common.w" +/*:4*//*5:*/ +#line 88 "common.h" -/*2:*/ -#line 73 "common.w" +extern char buffer[]; +extern char*buffer_end; +extern char*loc; +extern char*limit; + +/*:5*//*6:*/ +#line 105 "common.h" + +extern int include_depth; +extern FILE*file[]; +extern FILE*change_file; +extern char file_name[][max_file_name_length]; + +extern char change_file_name[]; +extern int line[]; +extern int change_line; +extern int change_depth; +extern boolean input_has_ended; +extern boolean changing; +extern boolean web_file_open; + +/*:6*//*8:*/ +#line 125 "common.h" + +extern sixteen_bits section_count; +extern boolean changed_section[]; +extern boolean change_pending; +extern boolean print_where; + +/*:8*//*9:*/ +#line 139 "common.h" + +typedef struct name_info{ +char*byte_start; +struct name_info*link; +union{ +struct name_info*Rlink; + +char Ilk; +}dummy; +void*equiv_or_xref; +}name_info; +typedef name_info*name_pointer; +typedef name_pointer*hash_pointer; +extern char byte_mem[]; +extern char*byte_mem_end; +extern char*byte_ptr; +extern name_info name_dir[]; +extern name_pointer name_dir_end; +extern name_pointer name_ptr; +extern name_pointer hash[]; +extern hash_pointer hash_end; +extern hash_pointer h; + +/*:9*//*11:*/ +#line 183 "common.h" + +extern int history; + +/*:11*//*13:*/ +#line 199 "common.h" + +extern int argc; +extern char**argv; +extern char C_file_name[]; +extern char tex_file_name[]; +extern char idx_file_name[]; +extern char scn_file_name[]; +extern boolean flags[]; + +/*:13*//*14:*/ +#line 215 "common.h" + +extern FILE*C_file; +extern FILE*tex_file; +extern FILE*idx_file; +extern FILE*scn_file; +extern FILE*active_file; + +/*:14*/ +#line 69 "common.w" + +/*18:*/ +#line 83 "common.w" -typedef short boolean; boolean program; -/*:2*//*7:*/ -#line 159 "common.w" +/*:18*//*19:*/ +#line 92 "common.w" + +int phase; + +/*:19*//*21:*/ +#line 130 "common.w" + +char section_text[longest_name+1]; +char*section_text_end= section_text+longest_name; +char*id_first; +char*id_loc; + +/*:21*//*22:*/ +#line 150 "common.w" char buffer[long_buf_size]; char*buffer_end= buffer+buf_size-2; -char*limit= buffer; char*loc= buffer; +char*limit= buffer; -/*:7*//*10:*/ -#line 214 "common.w" +/*:22*//*25:*/ +#line 194 "common.w" int include_depth; FILE*file[max_include_depth]; @@ -146,79 +260,57 @@ FILE*change_file; char file_name[max_include_depth][max_file_name_length]; char change_file_name[max_file_name_length]; -char alt_web_file_name[max_file_name_length]; +static char alt_web_file_name[max_file_name_length]; int line[max_include_depth]; int change_line; int change_depth; boolean input_has_ended; boolean changing; -boolean web_file_open= 0; +boolean web_file_open= false; -/*:10*//*20:*/ -#line 418 "common.w" +/*:25*//*26:*/ +#line 220 "common.w" + +static char change_buffer[buf_size]; +static char*change_limit; + +/*:26*//*37:*/ +#line 399 "common.w" -typedef unsigned short sixteen_bits; sixteen_bits section_count; boolean changed_section[max_sections]; boolean change_pending; -boolean print_where= 0; +boolean print_where= false; -/*:20*//*27:*/ -#line 594 "common.w" +/*:37*//*43:*/ +#line 596 "common.w" -typedef struct name_info{ -char*byte_start; -/*31:*/ -#line 631 "common.w" - -struct name_info*link; - -/*:31*//*40:*/ -#line 730 "common.w" - -union{ -struct name_info*Rlink; - -char Ilk; -}dummy; - -/*:40*//*55:*/ -#line 1062 "common.w" - -char*equiv_or_xref; - -/*:55*/ -#line 597 "common.w" - -}name_info; -typedef name_info*name_pointer; char byte_mem[max_bytes]; char*byte_mem_end= byte_mem+max_bytes-1; name_info name_dir[max_names]; name_pointer name_dir_end= name_dir+max_names-1; -/*:27*//*29:*/ -#line 617 "common.w" +/*:43*//*44:*/ +#line 607 "common.w" -name_pointer name_ptr; char*byte_ptr; +name_pointer name_ptr; -/*:29*//*32:*/ -#line 644 "common.w" +/*:44*//*46:*/ +#line 627 "common.w" -typedef name_pointer*hash_pointer; name_pointer hash[hash_size]; hash_pointer hash_end= hash+hash_size-1; hash_pointer h; -/*:32*//*56:*/ -#line 1082 "common.w" +/*:46*//*65:*/ +#line 1014 "common.w" int history= spotless; -/*:56*//*67:*/ -#line 1220 "common.w" +/*:65*//*73:*/ +#line 1135 "common.w" int argc; char**argv; @@ -228,8 +320,8 @@ char idx_file_name[max_file_name_length]; char scn_file_name[max_file_name_length]; boolean flags[128]; -/*:67*//*77:*/ -#line 1370 "common.w" +/*:73*//*83:*/ +#line 1282 "common.w" FILE*C_file; FILE*tex_file; @@ -237,138 +329,133 @@ FILE*idx_file; FILE*scn_file; FILE*active_file; -/*:77*/ -#line 61 "common.w" - -/*3:*/ -#line 83 "common.w" -int phase; - -/*:3*//*11:*/ -#line 240 "common.w" - -char change_buffer[buf_size]; -char*change_limit; - -/*:11*/ -#line 62 "common.w" - -/*33:*/ -#line 650 "common.w" - -extern int names_match(); +/*:83*/ +#line 70 "common.w" -/*:33*//*38:*/ -#line 703 "common.w" +/*7:*/ +#line 119 "common.h" -void init_p(); +extern boolean get_line(void); +extern void check_complete(void); +extern void reset_input(void); -/*:38*//*46:*/ -#line 852 "common.w" +/*:7*//*10:*/ +#line 162 "common.h" -extern void init_node(); +extern boolean names_match(name_pointer,const char*,size_t,eight_bits); +extern name_pointer id_lookup(const char*,const char*,char); -/*:46*//*53:*/ -#line 1017 "common.w" +extern name_pointer section_lookup(char*,char*,int); +extern void init_node(name_pointer); +extern void init_p(name_pointer,eight_bits); +extern void print_prefix_name(name_pointer); +extern void print_section_name(name_pointer); +extern void sprint_section_name(char*,name_pointer); -int section_name_cmp(); +/*:10*//*12:*/ +#line 186 "common.h" -/*:53*//*57:*/ -#line 1092 "common.w" +extern int wrap_up(void); +extern void err_print(const char*); +extern void fatal(const char*,const char*); +extern void overflow(const char*); -void err_print(); +/*:12*//*15:*/ +#line 223 "common.h" -/*:57*//*60:*/ -#line 1140 "common.w" +extern void common_init(void); +extern void print_stats(void); -int wrap_up(); -extern void print_stats(); +/*:15*//*24:*/ +#line 180 "common.w" +static boolean input_ln(FILE*); -/*:60*//*63:*/ -#line 1173 "common.w" +/*:24*//*28:*/ +#line 241 "common.w" +static void prime_the_change_buffer(void); -void fatal(),overflow(); +/*:28*//*33:*/ +#line 340 "common.w" +static void check_change(void); -/*:63*//*69:*/ -#line 1251 "common.w" +/*:33*//*55:*/ +#line 774 "common.w" -void scan_args(); +static int web_strcmp(char*,int,char*,int); +static name_pointer add_section_name(name_pointer,int,char*,char*,int); +static void extend_section_name(name_pointer,char*,char*,int); -/*:69*//*81:*/ -#line 1411 "common.w" +/*:55*//*64:*/ +#line 1002 "common.w" +static int section_name_cmp(char**,int,name_pointer); -extern int strlen(); -extern int strcmp(); -extern char*strcpy(); -extern int strncmp(); -extern char*strncpy(); +/*:64*//*76:*/ +#line 1197 "common.w" +static void scan_args(void); -/*:81*/ -#line 63 "common.w" +/*:76*/ +#line 71 "common.w" -/*:1*//*4:*/ -#line 89 "common.w" +/*:1*//*20:*/ +#line 99 "common.w" void -common_init() +common_init(void) { -/*30:*/ -#line 621 "common.w" +/*45:*/ +#line 611 "common.w" name_dir->byte_start= byte_ptr= byte_mem; name_ptr= name_dir+1; name_ptr->byte_start= byte_mem; +root= NULL; -/*:30*//*34:*/ -#line 655 "common.w" +/*:45*//*47:*/ +#line 634 "common.w" for(h= hash;h<=hash_end;*h++= NULL); -/*:34*//*41:*/ -#line 737 "common.w" +/*:47*/ +#line 103 "common.w" -root= NULL; +/*74:*/ +#line 1148 "common.w" -/*:41*/ -#line 93 "common.w" -; -/*68:*/ -#line 1233 "common.w" +show_banner= show_happiness= show_progress= make_xrefs= true; +show_stats= false; -show_banner= show_happiness= show_progress= 1; +/*:74*/ +#line 104 "common.w" -/*:68*/ -#line 94 "common.w" -; -/*78:*/ -#line 1377 "common.w" +/*84:*/ +#line 1289 "common.w" scan_args(); if(program==ctangle){ -if((C_file= fopen(C_file_name,"w"))==NULL) +if((C_file= fopen(C_file_name,"wb"))==NULL) fatal("! Cannot open output file ",C_file_name); } else{ -if((tex_file= fopen(tex_file_name,"w"))==NULL) +if((tex_file= fopen(tex_file_name,"wb"))==NULL) fatal("! Cannot open output file ",tex_file_name); } -/*:78*/ -#line 95 "common.w" -; +/*:84*/ +#line 105 "common.w" + } -/*:4*//*9:*/ -#line 172 "common.w" +/*:20*//*23:*/ +#line 160 "common.w" -int input_ln(fp) -FILE*fp; +static boolean input_ln( +FILE*fp) { register int c= EOF; register char*k; -if(feof(fp))return(0); +if(feof(fp))return false; limit= k= buffer; while(k<=buffer_end&&(c= getc(fp))!=EOF&&c!='\n') if((*(k++)= c)!=' ')limit= k; @@ -377,27 +464,27 @@ if((c= getc(fp))!=EOF&&c!='\n'){ ungetc(c,fp);loc= buffer;err_print("! Input line too long"); } -if(c==EOF&&limit==buffer)return(0); +if(c==EOF&&limit==buffer)return false; -return(1); +return true; } -/*:9*//*12:*/ -#line 251 "common.w" +/*:23*//*27:*/ +#line 231 "common.w" -void -prime_the_change_buffer() +static void +prime_the_change_buffer(void) { change_limit= change_buffer; -/*13:*/ -#line 265 "common.w" +/*29:*/ +#line 247 "common.w" -while(1){ +while(true){ change_line++; if(!input_ln(change_file))return; if(limit<buffer+2)continue; if(buffer[0]!='@')continue; -if(xisupper(buffer[1]))buffer[1]= tolower(buffer[1]); +if(xisupper(buffer[1]))buffer[1]= tolower((eight_bits)buffer[1]); if(buffer[1]=='x')break; if(buffer[1]=='y'||buffer[1]=='z'||buffer[1]=='i'){ loc= buffer+2; @@ -406,11 +493,11 @@ err_print("! Missing @x in change file"); } } -/*:13*/ -#line 256 "common.w" -; -/*14:*/ -#line 282 "common.w" +/*:29*/ +#line 236 "common.w" + +/*30:*/ +#line 264 "common.w" do{ change_line++; @@ -421,47 +508,47 @@ return; } }while(limit==buffer); -/*:14*/ -#line 257 "common.w" -; -/*15:*/ -#line 292 "common.w" +/*:30*/ +#line 237 "common.w" + +/*31:*/ +#line 274 "common.w" { -change_limit= change_buffer+(limit-buffer); -strncpy(change_buffer,buffer,limit-buffer+1); +change_limit= change_buffer+(ptrdiff_t)(limit-buffer); +strncpy(change_buffer,buffer,(size_t)(limit-buffer+1)); } -/*:15*/ -#line 258 "common.w" -; +/*:31*/ +#line 238 "common.w" + } -/*:12*//*16:*/ -#line 320 "common.w" +/*:27*//*32:*/ +#line 302 "common.w" -void -check_change() +static void +check_change(void) { int n= 0; if(lines_dont_match)return; -change_pending= 0; +change_pending= false; if(!changed_section[section_count]){ -if_section_start_make_pending(1); -if(!change_pending)changed_section[section_count]= 1; +if_section_start_make_pending(true); +if(!change_pending)changed_section[section_count]= true; } -while(1){ -changing= 1;print_where= 1;change_line++; +while(true){ +changing= true;print_where= true;change_line++; if(!input_ln(change_file)){ err_print("! Change file ended before @y"); -change_limit= change_buffer;changing= 0; +change_limit= change_buffer;changing= false; return; } if(limit> buffer+1&&buffer[0]=='@'){ -char xyz_code= xisupper(buffer[1])?tolower(buffer[1]):buffer[1]; -/*17:*/ -#line 358 "common.w" +char xyz_code= xisupper(buffer[1])?tolower((eight_bits)buffer[1]):buffer[1]; +/*34:*/ +#line 342 "common.w" if(xyz_code=='x'||xyz_code=='z'){ loc= buffer+2;err_print("! Where is the matching @y?"); @@ -478,27 +565,27 @@ change_depth= include_depth; return; } -/*:17*/ -#line 342 "common.w" -; +/*:34*/ +#line 324 "common.w" + } -/*15:*/ -#line 292 "common.w" +/*31:*/ +#line 274 "common.w" { -change_limit= change_buffer+(limit-buffer); -strncpy(change_buffer,buffer,limit-buffer+1); +change_limit= change_buffer+(ptrdiff_t)(limit-buffer); +strncpy(change_buffer,buffer,(size_t)(limit-buffer+1)); } -/*:15*/ -#line 344 "common.w" -; -changing= 0;cur_line++; +/*:31*/ +#line 326 "common.w" + +changing= false;cur_line++; while(!input_ln(cur_file)){ if(include_depth==0){ err_print("! CWEB file ended during a change"); -input_has_ended= 1;return; +input_has_ended= true;return; } include_depth--;cur_line++; } @@ -506,15 +593,15 @@ if(lines_dont_match)n++; } } -/*:16*//*18:*/ -#line 378 "common.w" +/*:32*//*35:*/ +#line 362 "common.w" void -reset_input() +reset_input(void) { limit= buffer;loc= buffer+1;buffer[0]= ' '; -/*19:*/ -#line 393 "common.w" +/*36:*/ +#line 377 "common.w" if((web_file= fopen(web_file_name,"r"))==NULL){ strcpy(web_file_name,alt_web_file_name); @@ -523,28 +610,28 @@ fatal("! Cannot open input file ",web_file_name); } -web_file_open= 1; +web_file_open= true; if((change_file= fopen(change_file_name,"r"))==NULL) fatal("! Cannot open change file ",change_file_name); -/*:19*/ -#line 383 "common.w" -; +/*:36*/ +#line 367 "common.w" + include_depth= 0;cur_line= 0;change_line= 0; change_depth= include_depth; changing= 1;prime_the_change_buffer();changing= !changing; -limit= buffer;loc= buffer+1;buffer[0]= ' ';input_has_ended= 0; +limit= buffer;loc= buffer+1;buffer[0]= ' ';input_has_ended= false; } -/*:18*//*21:*/ -#line 426 "common.w" +/*:35*//*38:*/ +#line 406 "common.w" -int get_line() +boolean get_line(void) { restart: if(changing&&include_depth==change_depth) -/*25:*/ -#line 537 "common.w" +/*41:*/ +#line 514 "common.w" { change_line++; if(!input_ln(change_file)){ @@ -554,37 +641,37 @@ buffer[0]= '@';buffer[1]= 'z';limit= buffer+2; } if(limit> buffer){ if(change_pending){ -if_section_start_make_pending(0); +if_section_start_make_pending(false); if(change_pending){ -changed_section[section_count]= 1;change_pending= 0; +changed_section[section_count]= true;change_pending= false; } } *limit= ' '; if(buffer[0]=='@'){ -if(xisupper(buffer[1]))buffer[1]= tolower(buffer[1]); +if(xisupper(buffer[1]))buffer[1]= tolower((eight_bits)buffer[1]); if(buffer[1]=='x'||buffer[1]=='y'){ loc= buffer+2; err_print("! Where is the matching @z?"); } else if(buffer[1]=='z'){ -prime_the_change_buffer();changing= !changing;print_where= 1; +prime_the_change_buffer();changing= !changing;print_where= true; } } } } -/*:25*/ -#line 431 "common.w" -; +/*:41*/ +#line 411 "common.w" + if(!changing||include_depth> change_depth){ -/*24:*/ -#line 520 "common.w" +/*40:*/ +#line 497 "common.w" { cur_line++; while(!input_ln(cur_file)){ -print_where= 1; -if(include_depth==0){input_has_ended= 1;break;} +print_where= true; +if(include_depth==0){input_has_ended= true;break;} else{ fclose(cur_file);include_depth--; if(changing&&include_depth==change_depth)break; @@ -597,12 +684,12 @@ if(buffer[0]==change_buffer[0]) if(change_limit> change_buffer)check_change(); } -/*:24*/ -#line 433 "common.w" -; +/*:40*/ +#line 413 "common.w" + if(changing&&include_depth==change_depth)goto restart; } -if(input_has_ended)return 0; +if(input_has_ended)return false; loc= buffer;*limit= ' '; if(buffer[0]=='@'&&(buffer[1]=='i'||buffer[1]=='I')){ loc= buffer+2;*limit= '"'; @@ -618,8 +705,8 @@ err_print("! Too many nested includes"); goto restart; } include_depth++; -/*23:*/ -#line 474 "common.w" +/*39:*/ +#line 451 "common.w" { char temp_file_name[max_file_name_length]; char*cur_file_name_end= cur_file_name+max_file_name_length-1; @@ -636,7 +723,7 @@ if(k> cur_file_name_end)too_long(); *k= '\0'; if((cur_file= fopen(cur_file_name,"r"))!=NULL){ -cur_line= 0;print_where= 1; +cur_line= 0;print_where= true; goto restart; } kk= getenv("CWEBINPUTS"); @@ -659,61 +746,61 @@ for(;k>=cur_file_name;k--)*(k+l+1)= *k; strcpy(cur_file_name,temp_file_name); cur_file_name[l]= '/'; if((cur_file= fopen(cur_file_name,"r"))!=NULL){ -cur_line= 0;print_where= 1; +cur_line= 0;print_where= true; goto restart; } } include_depth--;err_print("! Cannot open include file");goto restart; } -/*:23*/ -#line 452 "common.w" -; +/*:39*/ +#line 432 "common.w" + } -return 1; +return true; } -/*:21*//*26:*/ -#line 569 "common.w" +/*:38*//*42:*/ +#line 546 "common.w" void -check_complete(){ +check_complete(void){ if(change_limit!=change_buffer){ -strncpy(buffer,change_buffer,change_limit-change_buffer+1); -limit= buffer+(int)(change_limit-change_buffer); -changing= 1;change_depth= include_depth;loc= buffer; +strncpy(buffer,change_buffer,(size_t)(change_limit-change_buffer+1)); +limit= buffer+(ptrdiff_t)(change_limit-change_buffer); +changing= true;change_depth= include_depth;loc= buffer; err_print("! Change file entry did not match"); } } -/*:26*//*35:*/ -#line 660 "common.w" +/*:42*//*48:*/ +#line 639 "common.w" name_pointer -id_lookup(first,last,t) -char*first; -char*last; -char t; +id_lookup( +const char*first, +const char*last, +char t) { -char*i= first; +const char*i= first; int h; int l; name_pointer p; if(last==NULL)for(last= first;*last!='\0';last++); -l= last-first; -/*36:*/ -#line 683 "common.w" +l= (int)(last-first); +/*49:*/ +#line 662 "common.w" -h= (unsigned char)*i; -while(++i<last)h= (h+h+(int)((unsigned char)*i))%hash_size; +h= (eight_bits)*i; +while(++i<last)h= (h+h+(int)((eight_bits)*i))%hash_size; -/*:36*/ -#line 673 "common.w" -; -/*37:*/ -#line 691 "common.w" +/*:49*/ +#line 652 "common.w" + +/*50:*/ +#line 670 "common.w" p= hash[h]; while(p&&!names_match(p,first,l,t))p= p->link; @@ -722,53 +809,53 @@ p= name_ptr; p->link= hash[h];hash[h]= p; } -/*:37*/ -#line 674 "common.w" -; -if(p==name_ptr)/*39:*/ -#line 706 "common.w" +/*:50*/ +#line 653 "common.w" + +if(p==name_ptr)/*51:*/ +#line 681 "common.w" { if(byte_ptr+l> byte_mem_end)overflow("byte memory"); if(name_ptr>=name_dir_end)overflow("name"); strncpy(byte_ptr,first,l); (++name_ptr)->byte_start= byte_ptr+= l; -if(program==cweave)init_p(p,t); +init_p(p,t); } -/*:39*/ -#line 675 "common.w" -; -return(p); +/*:51*/ +#line 654 "common.w" + +return p; } -/*:35*//*42:*/ -#line 764 "common.w" +/*:48*//*52:*/ +#line 713 "common.w" void -print_section_name(p) -name_pointer p; +print_section_name( +name_pointer p) { char*ss,*s= first_chunk(p); name_pointer q= p+1; while(p!=name_dir){ ss= (p+1)->byte_start-1; if(*ss==' '&&ss>=s){ -term_write(s,ss-s);p= q->link;q= p; +term_write(s,(size_t)(ss-s));p= q->link;q= p; }else{ -term_write(s,ss+1-s);p= name_dir;q= NULL; +term_write(s,(size_t)(ss+1-s));p= name_dir;q= NULL; } s= p->byte_start; } if(q)term_write("...",3); } -/*:42*//*43:*/ -#line 783 "common.w" +/*:52*//*53:*/ +#line 732 "common.w" void -sprint_section_name(dest,p) -char*dest; -name_pointer p; +sprint_section_name( +char*dest, +name_pointer p) { char*ss,*s= first_chunk(p); name_pointer q= p+1; @@ -779,18 +866,18 @@ p= q->link;q= p; }else{ ss++;p= name_dir; } -strncpy(dest,s,ss-s),dest+= ss-s; +strncpy(dest,s,(size_t)(ss-s)),dest+= ss-s; s= p->byte_start; } *dest= '\0'; } -/*:43*//*44:*/ -#line 804 "common.w" +/*:53*//*54:*/ +#line 753 "common.w" void -print_prefix_name(p) -name_pointer p; +print_prefix_name( +name_pointer p) { char*s= first_chunk(p); int l= prefix_length(p); @@ -798,12 +885,14 @@ term_write(s,l); if(s+l<(p+1)->byte_start)term_write("...",3); } -/*:44*//*45:*/ -#line 825 "common.w" +/*:54*//*56:*/ +#line 779 "common.w" -int web_strcmp(j,j_len,k,k_len) -char*j,*k; -int j_len,k_len; +static int web_strcmp( +char*j, +int j_len, +char*k, +int k_len) { char*j1= j+j_len,*k1= k+k_len; while(k<k1&&j<j1&&*j==*k)k++,j++; @@ -814,20 +903,20 @@ else if(*j<*k)return less; else return greater; } -/*:45*//*47:*/ -#line 855 "common.w" +/*:56*//*57:*/ +#line 808 "common.w" -name_pointer -add_section_name(par,c,first,last,ispref) -name_pointer par; -int c; -char*first; -char*last; -int ispref; +static name_pointer +add_section_name( +name_pointer par, +int c, +char*first, +char*last, +int ispref) { name_pointer p= name_ptr; char*s= first_chunk(p); -int name_len= last-first+ispref; +int name_len= (int)(last-first)+ispref; if(s+name_len> byte_mem_end)overflow("byte memory"); if(name_ptr+1>=name_dir_end)overflow("name"); (++name_ptr)->byte_start= byte_ptr= s+name_len; @@ -845,19 +934,19 @@ init_node(p); return par==NULL?(root= p):c==less?(par->llink= p):(par->rlink= p); } -/*:47*//*48:*/ -#line 884 "common.w" +/*:57*//*58:*/ +#line 837 "common.w" -void -extend_section_name(p,first,last,ispref) -name_pointer p; -char*first; -char*last; -int ispref; +static void +extend_section_name( +name_pointer p, +char*first, +char*last, +int ispref) { char*s; name_pointer q= p+1; -int name_len= last-first+ispref; +int name_len= (int)(last-first)+ispref; if(name_ptr>=name_dir_end)overflow("name"); while(q->link!=name_dir)q= q->link; q->link= name_ptr; @@ -869,13 +958,13 @@ strncpy(s,first,name_len); if(ispref)*(byte_ptr-1)= ' '; } -/*:48*//*49:*/ -#line 912 "common.w" +/*:58*//*59:*/ +#line 865 "common.w" name_pointer -section_lookup(first,last,ispref) -char*first,*last; -int ispref; +section_lookup( +char*first,char*last, +int ispref) { int c= 0; name_pointer p= root; @@ -883,9 +972,9 @@ name_pointer q= NULL; name_pointer r= NULL; name_pointer par= NULL; -int name_len= last-first+1; -/*50:*/ -#line 936 "common.w" +int name_len= (int)(last-first)+1; +/*60:*/ +#line 889 "common.w" while(p){ c= web_strcmp(first,name_len,first_chunk(p),prefix_length(p)); @@ -895,10 +984,10 @@ par= p; p= (c==less?p->llink:p->rlink); }else{ if(r!=NULL){ -printf("\n! Ambiguous prefix: matches <"); +fputs("\n! Ambiguous prefix: matches <",stdout); print_prefix_name(p); -printf(">\n and <"); +fputs(">\n and <",stdout); print_prefix_name(r); err_print(">"); return name_dir; @@ -911,26 +1000,26 @@ if(p==NULL) p= q,q= NULL; } -/*:50*/ -#line 926 "common.w" -; -/*51:*/ -#line 961 "common.w" +/*:60*/ +#line 879 "common.w" + +/*61:*/ +#line 914 "common.w" if(r==NULL) return add_section_name(par,c,first,last+1,ispref); -/*:51*/ -#line 927 "common.w" -; -/*52:*/ -#line 969 "common.w" +/*:61*/ +#line 880 "common.w" + +/*62:*/ +#line 922 "common.w" switch(section_name_cmp(&first,name_len,r)){ case prefix: if(!ispref){ -printf("\n! New name is a prefix of <"); +fputs("\n! New name is a prefix of <",stdout); print_section_name(r); err_print(">"); @@ -942,71 +1031,71 @@ case extension:if(!ispref||first<=last) extend_section_name(r,first,last+1,ispref); return r; case bad_extension: -printf("\n! New name extends <"); +fputs("\n! New name extends <",stdout); print_section_name(r); err_print(">"); return r; default: -printf("\n! Section name incompatible with <"); +fputs("\n! Section name incompatible with <",stdout); print_prefix_name(r); -printf(">,\n which abbreviates <"); +fputs(">,\n which abbreviates <",stdout); print_section_name(r); err_print(">"); return r; } -/*:52*/ -#line 928 "common.w" -; +/*:62*/ +#line 881 "common.w" + } -/*:49*//*54:*/ -#line 1020 "common.w" +/*:59*//*63:*/ +#line 970 "common.w" -int section_name_cmp(pfirst,len,r) -char**pfirst; -int len; -name_pointer r; +static int section_name_cmp( +char**pfirst, +int len, +name_pointer r) { char*first= *pfirst; name_pointer q= r+1; char*ss,*s= first_chunk(r); int c; int ispref; -while(1){ +while(true){ ss= (r+1)->byte_start-1; if(*ss==' '&&ss>=r->byte_start)ispref= 1,q= q->link; else ispref= 0,ss++,q= name_dir; switch(c= web_strcmp(first,len,s,ss-s)){ case equal:if(q==name_dir) if(ispref){ -*pfirst= first+(ss-s); +*pfirst= first+(ptrdiff_t)(ss-s); return extension; }else return equal; else return(q->byte_start==(q+1)->byte_start)?equal:prefix; case extension: if(!ispref)return bad_extension; first+= ss-s; -if(q!=name_dir){len-= ss-s;s= q->byte_start;r= q;continue;} +if(q!=name_dir){len-= (int)(ss-s);s= q->byte_start;r= q;continue;} *pfirst= first;return extension; default:return c; } } } -/*:54*//*58:*/ -#line 1095 "common.w" +/*:63*//*66:*/ +#line 1024 "common.w" void -err_print(s) -char*s; +err_print( +const char*s) { char*k,*l; printf(*s=='!'?"\n%s":"%s",s); -if(web_file_open)/*59:*/ -#line 1115 "common.w" +if(web_file_open)/*67:*/ +#line 1044 "common.w" {if(changing&&include_depth==change_depth) printf(". (l. %d of change file)\n",change_line); @@ -1025,85 +1114,83 @@ if(*limit=='|')putchar('|'); putchar(' '); } -/*:59*/ -#line 1102 "common.w" -; +/*:67*/ +#line 1031 "common.w" + update_terminal;mark_error; } -/*:58*//*61:*/ -#line 1150 "common.w" +/*:66*//*68:*/ +#line 1076 "common.w" -int wrap_up(){ -putchar('\n'); +int wrap_up(void){ +if(show_progress)new_line; if(show_stats) print_stats(); -/*62:*/ -#line 1160 "common.w" +/*69:*/ +#line 1086 "common.w" switch(history){ -case spotless:if(show_happiness)printf("(No errors were found.)\n");break; +case spotless:if(show_happiness)puts("(No errors were found.)");break; case harmless_message: -printf("(Did you see the warning message above?)\n");break; +puts("(Did you see the warning message above?)");break; case error_message: -printf("(Pardon me, but I think I spotted something wrong.)\n");break; -case fatal_message:printf("(That was a fatal error, my friend.)\n"); +puts("(Pardon me, but I think I spotted something wrong.)");break; +case fatal_message:puts("(That was a fatal error, my friend.)"); } -/*:62*/ -#line 1155 "common.w" -; -if(history> harmless_message)return(1); -else return(0); +/*:69*/ +#line 1081 "common.w" + +if(history> harmless_message)return EXIT_FAILURE; +else return EXIT_SUCCESS; } -/*:61*//*64:*/ -#line 1179 "common.w" +/*:68*//*70:*/ +#line 1102 "common.w" void -fatal(s,t) -char*s,*t; +fatal( +const char*s,const char*t) { -if(*s)printf(s); +if(*s)err_print(s); err_print(t); history= fatal_message;exit(wrap_up()); } -/*:64*//*65:*/ -#line 1190 "common.w" +/*:70*//*71:*/ +#line 1113 "common.w" void -overflow(t) -char*t; +overflow( +const char*t) { printf("\n! Sorry, %s capacity exceeded",t);fatal("",""); } -/*:65*//*70:*/ -#line 1254 "common.w" +/*:71*//*75:*/ +#line 1167 "common.w" -void -scan_args() +static void +scan_args(void) { char*dot_pos; char*name_pos; register char*s; -boolean found_web= 0,found_change= 0,found_out= 0; +boolean found_web= false,found_change= false,found_out= false; -boolean flag_change; +strcpy(change_file_name,"/dev/null"); while(--argc> 0){ -if((**(++argv)=='-'||**argv=='+')&&*(*argv+1))/*74:*/ -#line 1344 "common.w" +if((**(++argv)=='-'||**argv=='+')&&*(*argv+1))/*80:*/ +#line 1258 "common.w" { -if(**argv=='-')flag_change= 0; -else flag_change= 1; for(dot_pos= *argv+1;*dot_pos> '\0';dot_pos++) -flags[*dot_pos]= flag_change; +flags[(eight_bits)*dot_pos]= flag_change; } -/*:74*/ -#line 1266 "common.w" +/*:80*/ +#line 1179 "common.w" else{ s= name_pos= *argv;dot_pos= NULL; @@ -1112,19 +1199,19 @@ if(*s=='.')dot_pos= s++; else if(*s=='/')dot_pos= NULL,name_pos= ++s; else s++; } -if(!found_web)/*71:*/ -#line 1292 "common.w" +if(!found_web)/*77:*/ +#line 1206 "common.w" { if(s-*argv> max_file_name_length-5) -/*76:*/ -#line 1364 "common.w" +/*82:*/ +#line 1276 "common.w" fatal("! Filename too long\n",*argv); -/*:76*/ -#line 1295 "common.w" -; +/*:82*/ +#line 1209 "common.w" + if(dot_pos==NULL) sprintf(web_file_name,"%s.w",*argv); else{ @@ -1136,50 +1223,49 @@ sprintf(tex_file_name,"%s.tex",name_pos); sprintf(idx_file_name,"%s.idx",name_pos); sprintf(scn_file_name,"%s.scn",name_pos); sprintf(C_file_name,"%s.c",name_pos); -found_web= 1; +found_web= true; } -/*:71*/ -#line 1275 "common.w" +/*:77*/ +#line 1188 "common.w" -else if(!found_change)/*72:*/ -#line 1310 "common.w" +else if(!found_change)/*78:*/ +#line 1224 "common.w" { -if(strcmp(*argv,"-")==0)found_change= -1; -else{ +if(strcmp(*argv,"-")!=0){ if(s-*argv> max_file_name_length-4) -/*76:*/ -#line 1364 "common.w" +/*82:*/ +#line 1276 "common.w" fatal("! Filename too long\n",*argv); -/*:76*/ -#line 1315 "common.w" -; +/*:82*/ +#line 1228 "common.w" + if(dot_pos==NULL) sprintf(change_file_name,"%s.ch",*argv); else strcpy(change_file_name,*argv); -found_change= 1; } +found_change= true; } -/*:72*/ -#line 1276 "common.w" +/*:78*/ +#line 1189 "common.w" -else if(!found_out)/*73:*/ -#line 1323 "common.w" +else if(!found_out)/*79:*/ +#line 1236 "common.w" { if(s-*argv> max_file_name_length-5) -/*76:*/ -#line 1364 "common.w" +/*82:*/ +#line 1276 "common.w" fatal("! Filename too long\n",*argv); -/*:76*/ -#line 1326 "common.w" -; +/*:82*/ +#line 1239 "common.w" + if(dot_pos==NULL){ sprintf(tex_file_name,"%s.tex",*argv); sprintf(idx_file_name,"%s.idx",*argv); @@ -1188,20 +1274,20 @@ sprintf(C_file_name,"%s.c",*argv); }else{ strcpy(tex_file_name,*argv); strcpy(C_file_name,*argv); -if(flags['x']){ +if(make_xrefs){ *dot_pos= 0; sprintf(idx_file_name,"%s.idx",*argv); sprintf(scn_file_name,"%s.scn",*argv); } } -found_out= 1; +found_out= true; } -/*:73*/ -#line 1277 "common.w" +/*:79*/ +#line 1190 "common.w" -else/*75:*/ -#line 1352 "common.w" +else/*81:*/ +#line 1264 "common.w" { if(program==ctangle) @@ -1214,13 +1300,13 @@ else fatal( ,""); } -/*:75*/ -#line 1278 "common.w" -; +/*:81*/ +#line 1191 "common.w" + } } -if(!found_web)/*75:*/ -#line 1352 "common.w" +if(!found_web)/*81:*/ +#line 1264 "common.w" { if(program==ctangle) @@ -1233,10 +1319,9 @@ else fatal( ,""); } -/*:75*/ -#line 1281 "common.w" -; -if(found_change<=0)strcpy(change_file_name,"/dev/null"); +/*:81*/ +#line 1194 "common.w" + } -/*:70*/ +/*:75*/ |