home *** CD-ROM | disk | FTP | other *** search
- #include <stdarg.h>
- #define variant empty
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include <limits.h>
- #include "common.h"
- #define max_bytes 50000L
- #define max_names 3000
- #define max_sections 10000
- #define hash_size 353
- #define buf_size 100
- #define longest_name 400
- #define long_buf_size (buf_size+longest_name)
- #define local static
- #define array_size(a)((int)(sizeof(a)/sizeof(a[0])))
- #define false (boolean)0
- #define true (boolean)1
- #define ctangle 0
- #define cweave 1
- #define and_and 04
- #define lt_lt 020
- #define gt_gt 021
- #define plus_plus 013
- #define minus_minus 01
- #define minus_gt 031
- #define not_eq 032
- #define lt_eq 034
- #define gt_eq 035
- #define eq_eq 036
- #define or_or 037
- #define find_char (loc<=limit||get_line())
- #define including_header_file (saved_include_depth>0)
- #define spotless 0
- #define harmless_message 1
- #define error_message 2
- #define fatal_message 3
- #define mark_harmless if(history==spotless)history=harmless_message;else
- #define mark_error history=error_message
- #define overflow(t)fatal("\n! Sorry, %s capacity exceeded",t)
- #define confusion(s)fatal("\n! This can't happen: %s",s)
- #define show_banner flags['b']
- #define show_progress flags['p']
- #define show_stats flags['s']
- #define show_happiness flags['h']
- #define C_plus_plus flags['+']
- #define update_terminal fflush(stdout)
- #define new_line putchar('\n')
- #define term_write(string,leng)printf("%.*s",(int)(leng),string)
- #define buffer_end (&buffer[buf_size-2])
- #define max_include_depth 10
- #define lines_match \
- (change_limit-change_buffer==limit-buffer \
- &&strncmp(buffer,change_buffer,limit-buffer)==0)
- #define byte_mem_end (&byte_mem[max_bytes])
- #define name_dir_end (&name_dir[max_names])
- #define update_terminal fflush(stdout)
- /*12:*//*8:*/
- #line 122 "common.inc"
- boolean names_match(name_pointer,char*,int,int);
- void init_id_name(name_pointer,int);
- void init_module_name(name_pointer);/*:8*//*16:*/
- #line 102 "w.common"
- int program,phase;/*:16*//*20:*/
- #line 144 "w.common"
- char buffer[long_buf_size];
- char*loc=buffer;
-
- char*limit=buffer;/*:20*//*23:*/
- #line 220 "w.common"
- int include_depth;
- int saved_include_depth=0;
- struct f file[max_include_depth];
- struct f change;
- local char alt_web_file_name[max_file_name_length];
- boolean input_has_ended;
- boolean changing;
- boolean web_file_open=false;
- boolean print_where=false;/*:23*//*26:*/
- #line 295 "w.common"
- local boolean saved_changing;
- local char*saved_change_limit;/*:26*//*29:*/
- #line 348 "w.common"
- local char change_buffer[buf_size];
- local char*change_limit;/*:29*//*41:*/
- #line 532 "w.common"
- sixteen_bits section_count;
- eight_bits changed_section[(max_sections+7)/8];/*:41*//*49:*/
- #line 688 "w.common"
- char byte_mem[max_bytes];
- char*byte_ptr= &byte_mem[0];
- name_info name_dir[max_names];
- name_pointer name_ptr= &name_dir[0];/*:49*//*53:*/
- #line 747 "w.common"
- struct empty{char comforter;};/*:53*//*55:*/
- #line 770 "w.common"
- name_pointer hash[hash_size];/*:55*//*62:*/
- #line 860 "w.common"
- name_pointer root=NULL;/*:62*//*69:*/
- #line 1004 "w.common"
- char mod_text[longest_name+1];
- char*id_first;
- char*id_loc;/*:69*//*75:*/
- #line 1098 "w.common"
- int history=spotless;/*:75*//*82:*/
- #line 1198 "w.common"
- int argc;
- char* *argv;
- boolean flags[UCHAR_MAX+1];
- char C_file_name[max_file_name_length];
- local char tex_file_name[max_file_name_length];
- local boolean change_file_explicit;/*:82*//*93:*/
- #line 1322 "w.common"
- FILE*C_file;
- FILE*tex_file;/*:93*//*97:*/
- #line 1359 "w.common"
- local boolean term_line_empty=true;/*:97*//*63:*/
- #line 868 "w.common"
- local enum mod_comparison
- {less,
-
- equal,
- greater,
-
- prefix,
- extension
- }web_strcmp(char*,char*,char*,char*);
- local name_pointer make_mod_node(char*,int);/*:63*//*85:*/
- #line 1226 "w.common"
- local void scan_args(void);/*:85*//*:12*//*18:*/
- #line 112 "w.common"
- void common_init(void)
- {/*50:*/
- #line 696 "w.common"
- name_begin(name_ptr)=byte_ptr;/*:50*//*56:*/
- #line 778 "w.common"
- {int i=hash_size;do hash[--i]=NULL;while(i>0);}/*:56*//*71:*/
- #line 1033 "w.common"
- mod_text[0]=' ';/*:71*//*83:*/
- #line 1209 "w.common"
- show_banner=show_happiness=show_progress=true;/*:83*/
- #line 115 "w.common"
- scan_args();
- }/*:18*//*21:*/
- #line 157 "w.common"
- local boolean input_ln(FILE*f)
-
- {register int c;
- register char*k=limit=buffer;
- while((c=getc(f))!='\n'&&c!=EOF)
- if(k<=buffer_end){*k++=c;if(!isspace(c))limit=k;}
- if(k>buffer_end)
- {loc=buffer;
- err_print("! Input line too long");
- if(limit>buffer_end)limit=buffer_end;
- }
- return c!=EOF||limit>buffer;
- }/*:21*//*24:*/
- #line 245 "w.common"
- void push_input_file(boolean at_h)
- {char delim=' ';
- while(loc<limit&&(isspace(*loc)))++loc;
- if(*loc!='<')
- {if(*loc=='"')delim= *loc++;
- if(loc>=limit)err_print("! Include file name not given");
-
- else if(++include_depth>=max_include_depth)
- {--include_depth;
- err_print("! Too many nested includes");
- }
- else
- {/*25:*/
- #line 37 "ch.common"
- {
- char*k=cur_file_name,*dot_pos,*colon_pos;
- while(!(*loc==delim||(delim==' '?isspace(*loc):loc==limit)))
- if(k== &cur_file_name[max_file_name_length-1])
- {
- err_print("! Include file name truncated");break;}
-
- else
- *k++= *loc++;
- *k='\0';
-
-
-
-
- dot_pos=strrchr(cur_file_name,'.');
- colon_pos=strrchr(cur_file_name,':');
- if((dot_pos[2]=='\0')||(dot_pos[3]=='\0')){
- char temp[max_file_name_length];
- *dot_pos='\0';
- if(colon_pos==NULL)
- sprintf(temp,"%s.%s",dot_pos+1,cur_file_name);
- else{
- *colon_pos='\0';
- sprintf(temp,"%s:%s.%s",cur_file_name,dot_pos+1,
- colon_pos+1);
- }
- strcpy(cur_file_name,temp);
- }
- }/*:25*/
- #line 8 "ch.common"
- if((cur_file=fopen(cur_file_name,"r"))==NULL)
- {char temp[max_file_name_length+3];
-
-
-
- if(strchr(cur_file_name,':')==NULL){
- sprintf(temp,"C:%s",cur_file_name);
- cur_file=fopen(temp,"r");
- }
- if(cur_file==NULL){
- --include_depth;
- err_print("! Cannot open include file");
-
- }
- }
- #line 263 "w.common"
- else
- {cur_line=0;print_where=true;/*27:*/
- #line 299 "w.common"
- if(at_h)
- {saved_changing=changing;changing=false;
- saved_change_limit=change_limit;change_limit=change_buffer;
- saved_include_depth=include_depth;
- }/*:27*/
- #line 266 "w.common"
- }
- }
- }
- loc= &limit[1];
- }/*:24*//*28:*/
- #line 315 "w.common"
- local boolean get_web_line(void)
- {do
- if(++cur_line,input_ln(cur_file))
- {loc=buffer;*limit=' ';
- if(*buffer!='@'||tolower(buffer[1])!='i')return true;
- loc+=2;print_where=true;push_input_file(false);
- }
- else if(include_depth==0)
- {input_has_ended=true;web_file_open=false;return false;}
- else
- {fclose(cur_file);print_where=true;
- if(include_depth-- ==saved_include_depth)
- {changing=saved_changing;change_limit=saved_change_limit;
- saved_include_depth=0;
- if(changing)return false;
- }
- }
- while(true);
- }/*:28*//*30:*/
- #line 361 "w.common"
- local void prime_the_change_buffer(void)
- {change_limit=change_buffer;/*31:*/
- #line 377 "w.common"
- while(true)
- {if(++change_line,!input_ln(change_file))return;
- if(limit<buffer+2||buffer[0]!='@')continue;
- buffer[1]=tolower(buffer[1]);/*32:*/
- #line 394 "w.common"
- {if(buffer[1]=='i')
- {loc=buffer+2;err_print("! No includes allowed in change file");}
- }/*:32*/
- #line 382 "w.common"
- if(buffer[1]=='x')break;
- if(buffer[1]=='y'||buffer[1]=='z')
- {loc=buffer+2;
- err_print("! Where is the matching @x?");
- }
- }/*:31*//*33:*/
- #line 405 "w.common"
- do
- if(++change_line,!input_ln(change_file))
- {err_print("! Change file ended after @x");return;}
- while(limit==buffer);/*:33*//*34:*/
- #line 411 "w.common"
- {change_limit=change_buffer-buffer+limit;
- strncpy(change_buffer,buffer,limit-buffer);
- }/*:34*/
- #line 367 "w.common"
- }/*:30*//*35:*/
- #line 429 "w.common"
- local void check_change(void)
-
- {int n=0;
- if(!lines_match)return;
- print_where=true;
- do
- {changing=true;
- if(++change_line,!input_ln(change_file))
- {err_print("! Change file ended before @y");
-
- change_limit=change_buffer;changing=false;
- return;
- }
- if(limit>buffer+1&&buffer[0]=='@')
- {buffer[1]=tolower(buffer[1]);/*32:*/
- #line 394 "w.common"
- {if(buffer[1]=='i')
- {loc=buffer+2;err_print("! No includes allowed in change file");}
- }/*:32*//*36:*/
- #line 461 "w.common"
- if(buffer[1]=='x'||buffer[1]=='z')
- {loc=buffer+2;err_print("! Where is the matching @y?");}
-
- else if(buffer[1]=='y')
- {if(n>0)
- {loc=buffer+2;
- print("\n! Hmm... %d of the preceding lines failed to match",n);
-
- err_print("");
- }
- return;
- }/*:36*/
- #line 447 "w.common"
- }/*34:*/
- #line 411 "w.common"
- {change_limit=change_buffer-buffer+limit;
- strncpy(change_buffer,buffer,limit-buffer);
- }/*:34*/
- #line 449 "w.common"
- changing=false;
- if(!get_web_line())
- {err_print("! CWEB file ended during a change");return;}
-
- if(!lines_match)++n;
- }while(true);
- }/*:35*//*38:*/
- #line 487 "w.common"
- void reset_input(void)
- {boolean no_change_file=false;/*39:*/
- #line 504 "w.common"
- if((web_file=fopen(web_file_name,"r"))==NULL)
- {if((web_file=fopen(alt_web_file_name,"r"))==NULL)
- fatal("! Cannot open \"%s\" as input file",web_file_name);
-
- strcpy(web_file_name,alt_web_file_name);
- }
- web_file_open=true;
- if((change_file=fopen(change_file_name,"r"))==NULL)
- {if(change_file_explicit)
- fatal("! Cannot open \"%s\" as change file",change_file_name);
-
- no_change_file=true;
- }/*:39*/
- #line 490 "w.common"
- cur_line=0;change_line=0;include_depth=0;
- if(no_change_file)change_limit=change_buffer;
-
- else{changing=true;prime_the_change_buffer();}
- changing=false;
- limit=buffer;loc=buffer+1;buffer[0]=' ';input_has_ended=false;
- }/*:38*//*42:*/
- #line 549 "w.common"
- boolean get_line(void)
- {
- restart:
- if(changing)mark_section_as_changed(section_count);
- else/*43:*/
- #line 573 "w.common"
- {if(get_web_line()
- &&change_limit>change_buffer
- &&limit-buffer==change_limit-change_buffer
- &&buffer[0]==change_buffer[0]
- )check_change();
- }/*:43*/
- #line 554 "w.common"
- if(changing)
- {/*44:*/
- #line 588 "w.common"
- {if(++change_line,!input_ln(change_file))
- {err_print("! Change file ended without @z");
- buffer[0]='@';buffer[1]='z';limit=buffer+2;
- }
- loc=buffer;*limit=' ';
- if(limit>buffer+1&&buffer[0]=='@')
- {buffer[1]=tolower(buffer[1]);/*32:*/
- #line 394 "w.common"
- {if(buffer[1]=='i')
- {loc=buffer+2;err_print("! No includes allowed in change file");}
- }/*:32*/
- #line 595 "w.common"
- 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=false;print_where=true;}
- }
- }/*:44*/
- #line 556 "w.common"
- if(!changing)
- {mark_section_as_changed(section_count);goto restart;}
- }
- return!input_has_ended;
- }/*:42*//*46:*/
- #line 620 "w.common"
- void check_complete(void)
- {if(change_limit!=change_buffer)
- {int l=(int)(change_limit-change_buffer);
- strncpy(buffer,change_buffer,l);limit= &buffer[l];
- changing=true;loc=buffer;web_file_open=true;
-
- err_print("! Change file entry did not match");
-
- }
- }/*:46*//*57:*/
- #line 791 "w.common"
- name_pointer id_lookup(char*first,char*last,int ilk)
-
- {int h;
- int l;
-
- if(last==NULL)last=first+(l=(int)strlen(first));
- else l=(int)(last-first);/*58:*/
- #line 814 "w.common"
- {char*p=first;
- h= *p;while(++p<last)h=((h<<1)+ *p)%hash_size;
- }/*:58*//*59:*/
- #line 824 "w.common"
- {name_pointer p=hash[h];
- while(p!=NULL&&!names_match(p,first,l,ilk))p=p->link;
- if(p==NULL)
- {p=name_ptr;/*60:*/
- #line 841 "w.common"
- {if(byte_ptr+l>byte_mem_end)overflow("byte memory");
- if(++name_ptr>=name_dir_end)overflow("name");
- strncpy(byte_ptr,first,l);name_bt)
- fchar r*p53:ir[max_fige_fnerchange_buffer(e mcta
- {l1,lowed t_g_f13stdoffer;equ ff;purishashlocal v8:*&&bulocal v8y'):*while;
- bo?3 ;
- boo;chauffer+2;[max_filofht;/*:2ed_cposfile?"r=ruannopre'@*:9 "w.common"
- }xplbylimit=rgs,"rhar*ce,<ster;);
- ele;/*
- in;c mlimit<buffer[0]=xpln
- if(ch[max_bboolean isspn_r=sge_fipeht/*3t_l=true;
- lonclud;píimit==bor_ss=buffer_eª n_file(c!=*:2'psage
- t=cer!inpu*:34}; spdel“““ “;/*:2e;/*:2e;
- #define sh{in{in{=true=true= ={c{c{ { r hile=file=fi
- #define sh
- #define sh
- //*7 r bfer);fer);f f (chan %sE*_po_po_local d iLLsh_sh_s s ']
- #deseseslimit=climit=cl lyte_pcur_filecur_filec c()oryoryostrch)%)%)savenclncln m m
- &
- &
- r*r*r ryte_meyte_meye_lime_lime e armarmaile_nang,ctale le ls",s",s s *:plplpemp)emp)e eelse
- {!:1namenamename)k=8*//[max_filot l#line #line #change_ludiudiuct ect ecy'y'y y alse;alse;a adefinenclnnclnn nflags[flags[f f ,l);,l);,change_change_cegse;
- se;
- s s boz"96change_buffer)change_buffer)c2662662limit=rlimit=rl(char*//*85*//*85* *s 1s 1sempempeanginangina a C:C:C C r fr fr r
- #line 49
- #line 49
- void)void)v+=+=+first, trp<[max_bb5*/5*/5returncw,l);,=truhow``` `t_g_']
- #dfile(;}/À(*l_lim-- fer)fer)f0 "w.ŒŒŒ#l#l#file_nafile_naf f includestr; ÐÐÐgi
- {l gisemp,"emp,"e e' ';' ';' ' #line 6lowed tgegeg g ed_cfafafclu¶¶¶3943943 3
- iffer+2ffer+2ffile_efile_efless)))p_lim-_lim-_<=b_di_di_ _#define#defin#defin# #38:38:3 3 e me met_ººº ºon"
- lon"
- lochanging)ory=alse;
- else
- else
- +(l=(il=(il lif(buffpusiciiciire=trre=trrs_mas_massectio')drn:*/
- #li:*/
- #li:;}
- };}
- };"w.com4114114 4
- in;
- in;
- f(kf(kf fincludname_b“void)
- {void)
- {v v");}");}"yte_pyte_pyt)t)t4
- 4
- 4 ");
- }