home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 1B
/
DATAFILE_PDCD1B.iso
/
_languages
/
languages
/
cweb
/
c
/
common
next >
Wrap
Text File
|
1994-02-20
|
17KB
|
677 lines
#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-buff