DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: S T

⟦346dc01e7⟧ TextFile

    Length: 16445 (0x403d)
    Types: TextFile
    Names: »SAVEcommon.c«

Derivation

└─⟦52210d11f⟧ Bits:30007239 EUUGD2: TeX 3 1992-12
    └─⟦c319c2751⟧ »unix3.0/TeX3.0.tar.Z« 
        └─⟦036c765ac⟧ 
            └─⟦this⟧ »TeX3.0/CWEB/SAVEcommon.c« 
└─⟦060c9c824⟧ Bits:30007080 DKUUG TeX 2/12/89
    └─⟦this⟧ »./tex82/CWEB/SAVEcommon.c« 

TextFile

#define tangle 0
#define weave 1 \

#define first_text_char 0
#define last_text_char 0177 \

#define and_and 04
#define tab_mark 011
#define line_feed 012
#define form_feed 014
#define carriage_return 015
#define gt_gt 020
#define lt_lt 022
#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 buf_size 100
#define long_buf_size 500 \

#define max_include_depth 10 \

#define max_file_name_length 60
#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 lines_dont_match (change_limit-change_buffer!=limit-buffer|| \
strncmp(buffer,change_buffer,limit-buffer)) \

#define max_modules 2000 \
 \

#define max_bytes 90000 \

#define max_names 4000 \
 \

#define length(c)(c+1)->byte_start-(c)->byte_start
#define print_id(c)ASCII_write((c)->byte_start,length((c))) \
 \

#define hash_size 353 \

#define llink link
#define rlink dummy.Rlink
#define root name_dir->rlink \
 \

#define less 0
#define equal 1
#define greater 2
#define prefix 3
#define extension 4 \

#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 fatal(s1,s2){ \
printf(s1);err_print(s2); \
history= fatal_message;wrap_up(); \
} \

#define confusion(s)fatal("! This can't happen: ",s) \
 \

#define overflow(string){ \
printf("\n! Sorry, %s capacity exceeded",string);fatal("",""); \
} \
 \

#define update_terminal fflush(stdout) \

#define new_line putchar('\n')
#define putxchar putchar
#define ASCII_write(a,b)fflush(stdout),write(1,a,b)
#define line_write(c)write(fileno(C_file),c)
#define C_printf(c,a)fprintf(C_file,c,a)
#define C_putc(c)putc(c,C_file) \

/*1:*/
#line 38 "common.web"

#include <stdio.h>
/*2:*/
#line 52 "common.web"

typedef short boolean;
boolean program;

/*:2*//*4:*/
#line 135 "common.web"

typedef char ASCII;
typedef char outer_char;

/*:4*//*5:*/
#line 143 "common.web"

ASCII xord[last_text_char];
outer_char xchr[0200];

/*:5*//*9:*/
#line 229 "common.web"

ASCII buffer[long_buf_size];
ASCII*buffer_end= buffer+buf_size-2;
ASCII*limit= buffer;
ASCII*loc= buffer;

/*:9*//*11:*/
#line 281 "common.web"

int include_depth;
FILE*file[max_include_depth];
FILE*change_file;
char file_name[max_include_depth][max_file_name_length];

char change_file_name[max_file_name_length];
int line[max_include_depth];
int change_line;
boolean input_has_ended;
boolean changing;

/*:11*//*23:*/
#line 471 "common.web"

typedef unsigned short sixteen_bits;
sixteen_bits module_count;
boolean changed_module[max_modules];
boolean print_where= 0;

/*:23*//*29:*/
#line 598 "common.web"

typedef struct name_info{
ASCII*byte_start;
/*33:*/
#line 636 "common.web"

struct name_info*link;

/*:33*//*40:*/
#line 726 "common.web"

union{
struct name_info*Rlink;

sixteen_bits Ilk;
}dummy;

/*:40*//*47:*/
#line 865 "common.web"

ASCII*equiv_or_xref;

/*:47*/
#line 601 "common.web"

}name_info;
typedef name_info*name_pointer;
ASCII byte_mem[max_bytes];
ASCII*byte_mem_end= byte_mem+max_bytes-1;
name_info name_dir[max_names];
name_pointer name_dir_end= name_dir+max_names-1;

/*:29*//*31:*/
#line 622 "common.web"

name_pointer name_ptr;
ASCII*byte_ptr;

/*:31*//*34:*/
#line 649 "common.web"

typedef name_pointer*hash_pointer;
name_pointer hash[hash_size];
hash_pointer hash_end= hash+hash_size-1;
hash_pointer h;

/*:34*//*48:*/
#line 885 "common.web"

int history= spotless;

/*:48*//*56:*/
#line 997 "common.web"

int argc;
char**argv;
char C_file_name[max_file_name_length];
char tex_file_name[max_file_name_length];
int no_xref;

/*:56*//*65:*/
#line 1100 "common.web"

FILE*C_file;
FILE*tex_file;

/*:65*/
#line 40 "common.web"

/*3:*/
#line 62 "common.web"
int phase;

/*:3*//*12:*/
#line 304 "common.web"

ASCII change_buffer[buf_size];
ASCII*change_limit;

/*:12*//*42:*/
#line 751 "common.web"

name_pointer install_node();

/*:42*/
#line 41 "common.web"

/*6:*/
#line 159 "common.web"

common_init()
{
strcpy(xchr,"                                 !\"#$%&'()*+,-./0123456789\
:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ");
/*8:*/
#line 208 "common.web"


/*:8*/
#line 164 "common.web"
;
/*7:*/
#line 173 "common.web"
{
int i;
for(i= first_text_char;i<=last_text_char;i++)xord[i]= '\040';
for(i= 1;i<0177;i++)xord[xchr[i]]= i;
}

/*:7*/
#line 165 "common.web"
;
/*32:*/
#line 626 "common.web"

name_dir->byte_start= byte_ptr= byte_mem;
name_ptr= name_dir+1;
name_ptr->byte_start= byte_mem;

/*:32*//*35:*/
#line 657 "common.web"

for(h= hash;h<=hash_end;*h++= NULL);

/*:35*//*41:*/
#line 733 "common.web"

root= NULL;

/*:41*/
#line 166 "common.web"
;
/*66:*/
#line 1104 "common.web"

scan_args();
if(program==tangle){
if((C_file= fopen(C_file_name,"w"))==NULL)
fatal("! Cannot open output file ",C_file_name);

}
else{
if((tex_file= fopen(tex_file_name,"w"))==NULL)
fatal("! Cannot open output file ",tex_file_name);
}

/*:66*/
#line 167 "common.web"
;
}

/*:6*//*10:*/
#line 239 "common.web"

input_ln(fp)
FILE*fp;
{
register int c;
register ASCII*k;
if(feof(fp))return(0);
limit= k= buffer;
while(k<=buffer_end&&(c= getc(fp))!=EOF&&c!='\n')
if((*(k++)= xord[c])!=0040)limit= k;
if(k>buffer_end)
if((c= getc(fp))!=EOF&&c!='\n'){
ungetc(c,fp);loc= buffer;err_print("\n! Input line too long");

}
if(c==EOF&&limit==buffer)return(0);

return(1);
}

/*:10*//*13:*/
#line 314 "common.web"

prime_the_change_buffer()
{
change_limit= change_buffer;
/*14:*/
#line 328 "common.web"

while(1){
change_line++;
if(!input_ln(change_file))return;
if(limit<buffer+2)continue;
if(buffer[0]!=0100)continue;
/*15:*/
#line 346 "common.web"

if(buffer[1]>=0130&&buffer[1]<=0132||buffer[1]==0111)buffer[1]+= 0172-0132;

/*:15*/
#line 334 "common.web"
;
/*16:*/
#line 351 "common.web"
{
if(buffer[1]==0151){
loc= buffer+2;
err_print("! No includes allowed in change file");

}
}

/*:16*/
#line 335 "common.web"
;
if(buffer[1]==0170)break;
if(buffer[1]==0171||buffer[1]==0172){
loc= buffer+2;
err_print("! Where is the matching @x?");

}
}

/*:14*/
#line 318 "common.web"
;
/*17:*/
#line 361 "common.web"

do{
change_line++;
if(!input_ln(change_file)){
err_print("! Change file ended after @x");

return;
}
}while(limit==buffer);

/*:17*/
#line 319 "common.web"
;
/*18:*/
#line 371 "common.web"

{
change_limit= change_buffer-buffer+limit;
strncpy(change_buffer,buffer,limit-buffer+1);
}

/*:18*/
#line 320 "common.web"
;
}

/*:13*//*19:*/
#line 386 "common.web"

check_change()
{
int n= 0;
if(lines_dont_match)return;
while(1){
changing= 1;print_where= 1;change_line++;
if(!input_ln(change_file)){
err_print("! Change file ended before @y");

change_limit= change_buffer;changing= 0;print_where= 1;
return;
}
if(limit>buffer+1&&buffer[0]==0100)
/*16:*/
#line 351 "common.web"
{
if(buffer[1]==0151){
loc= buffer+2;
err_print("! No includes allowed in change file");

}
}

/*:16*/
#line 400 "common.web"
;
/*20:*/
#line 417 "common.web"

if(limit>buffer+1&&buffer[0]==0100){
/*15:*/
#line 346 "common.web"

if(buffer[1]>=0130&&buffer[1]<=0132||buffer[1]==0111)buffer[1]+= 0172-0132;

/*:15*/
#line 419 "common.web"
;
if(buffer[1]==0170||buffer[1]==0172){
loc= buffer+2;err_print("! Where is the matching @y?");

}
else if(buffer[1]==0171){
if(n>0){
loc= buffer+2;
err_print("! Hmm... some of the preceding lines failed to match");

}
return;
}
}

/*:20*/
#line 402 "common.web"
;
/*18:*/
#line 371 "common.web"

{
change_limit= change_buffer-buffer+limit;
strncpy(change_buffer,buffer,limit-buffer+1);
}

/*:18*/
#line 403 "common.web"
;
changing= 0;print_where= 1;cur_line++;
while(!input_ln(cur_file)){
if(include_depth==0){
err_print("! WEB file ended during a change");

input_has_ended= 1;return;
}
include_depth--;print_where= 1;cur_line++;
}
if(lines_dont_match)n++;
}
}

/*:19*//*21:*/
#line 437 "common.web"

reset_input()
{
limit= buffer;loc= buffer+1;buffer[0]= 0040;
/*22:*/
#line 450 "common.web"

if((web_file= fopen(web_file_name,"r"))==NULL)
fatal("! Cannot open input file ",web_file_name);


if((change_file= fopen(change_file_name,"r"))==NULL)
fatal("! Cannot open change file ",change_file_name);

/*:22*/
#line 441 "common.web"
;
cur_line= 0;change_line= 0;include_depth= 0;
changing= 1;prime_the_change_buffer();changing= !changing;
limit= buffer;loc= buffer+1;buffer[0]= 0040;input_has_ended= 0;
}

/*:21*//*24:*/
#line 477 "common.web"

get_line()
{
restart:
if(changing)changed_module[module_count]= 1;
else/*26:*/
#line 534 "common.web"
{
cur_line++;
while(!input_ln(cur_file)){
print_where= 1;
if(include_depth==0){input_has_ended= 1;break;}
else{include_depth--;cur_line++;}
}
if(!input_has_ended)
if(limit==change_limit-change_buffer+buffer)
if(buffer[0]==change_buffer[0])
if(change_limit>change_buffer)check_change();
}

/*:26*/
#line 482 "common.web"
;
if(changing){
/*27:*/
#line 547 "common.web"
{
change_line++;
if(!input_ln(change_file)){
err_print("! Change file ended without @z");

buffer[0]= 0100;buffer[1]= 0172;limit= buffer+2;
}
if(limit>buffer+1)
if(buffer[0]==0100){
/*15:*/
#line 346 "common.web"

if(buffer[1]>=0130&&buffer[1]<=0132||buffer[1]==0111)buffer[1]+= 0172-0132;

/*:15*/
#line 556 "common.web"
;
/*16:*/
#line 351 "common.web"
{
if(buffer[1]==0151){
loc= buffer+2;
err_print("! No includes allowed in change file");

}
}

/*:16*/
#line 557 "common.web"
;
if(buffer[1]==0170||buffer[1]==0171){
loc= buffer+2;err_print("! Where is the matching @z?");

}
else if(buffer[1]==0172){
prime_the_change_buffer();changing= !changing;print_where= 1;
}
}
}

/*:27*/
#line 484 "common.web"
;
if(!changing){
changed_module[module_count]= 1;goto restart;
}
}
loc= buffer;*limit= 0040;
if(*buffer==0100&&(*(buffer+1)==0151||*(buffer+1)==0111))
/*25:*/
#line 506 "common.web"
{
ASCII*k,*j;
loc= buffer+2;
while(loc<=limit&&(*loc==0040||*loc==0011||*loc==0042))loc++;
if(loc>=limit)err_print("! Include file name not given");

else{
if(++include_depth<max_include_depth){
k= cur_file_name;j= loc;
while(*loc!=0040&&*loc!=0011&&*loc!=0042)*k++= xchr[*loc++];
*k= '\0';
if((cur_file= fopen(cur_file_name,"r"))==NULL){
loc= j;
include_depth--;
err_print("! Cannot open include file");

}
else{cur_line= 0;print_where= 1;}
}
else{
include_depth--;
err_print("! Too many nested includes");

}
}
goto restart;
}

/*:25*/
#line 491 "common.web"
;
return(!input_has_ended);
}

/*:24*//*28:*/
#line 571 "common.web"

check_complete(){
if(change_limit!=change_buffer){
strncpy(buffer,change_buffer,change_limit-change_buffer+1);
limit= change_limit-change_buffer+buffer;
changing= 1;loc= change_limit;
err_print("! Change file entry did not match");

}
}

/*:28*//*49:*/
#line 899 "common.web"

err_print(s)
char*s;
{
ASCII*k,*l;
printf("\n%s",s);
/*50:*/
#line 918 "common.web"

if(changing)printf(". (l. %d of change file)\n",change_line);
else if(include_depth==0)printf(". (l. %d)\n",cur_line);
else printf(". (l. %d of include file %s)\n",cur_line,cur_file_name);
l= (loc>=limit?limit:loc);
if(l>buffer){
for(k= buffer;k<l;k++)
if(*k=='\t')putchar(' ');
else putchar(xchr[*k]);
putchar('\n');
for(k= buffer;k<l;k++)putchar(' ');
}
for(k= l;k<limit;k++)putchar(xchr[*k]);
if(*limit==0174)putchar('|');
putchar(' ');

/*:50*/
#line 905 "common.web"
;
fflush(stdout);mark_error;
}

/*:49*//*54:*/
#line 964 "common.web"

wrap_up(){
putchar('\n');
#ifdef STAT
print_stats();
#endif
/*55:*/
#line 975 "common.web"

switch(history){
case spotless:printf("(No errors were found.)\n");break;
case harmless_message:
printf("(Did you see the warning message above?)\n");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");
}

/*:55*/
#line 970 "common.web"
;
if(history>harmless_message)exit(1);
else exit(0);
}

/*:54*//*57:*/
#line 1017 "common.web"

char*index(s,c)
char*s;
char c;
{
while(*s!=c&&*s!='\0')
s++;
if(*s=='\0')return NULL;
return s;
}

scan_args()
{
char*dot_pos;
boolean found_web= 0,found_change= 0;
no_xref= 0;
while(--argc>0){
if(**(++argv)!='-'){
if(!found_web)/*58:*/
#line 1051 "common.web"

{
if(strlen(*argv)>max_file_name_length-5)
/*63:*/
#line 1091 "common.web"
fatal("! Filename too long\n",*argv);

/*:63*/
#line 1054 "common.web"
;
if((dot_pos= index(*argv,'.'))==NULL)
sprintf(web_file_name,"%s.web",*argv);
else{
sprintf(web_file_name,"%s",*argv);
*dot_pos= 0;
}
sprintf(tex_file_name,"%s.tex",*argv);
sprintf(C_file_name,"%s.c",*argv);
found_web= 1;
}

/*:58*/
#line 1036 "common.web"

else if(!found_change)/*59:*/
#line 1066 "common.web"

{
if(strlen(*argv)>max_file_name_length-5)
/*63:*/
#line 1091 "common.web"
fatal("! Filename too long\n",*argv);

/*:63*/
#line 1069 "common.web"
;
if((dot_pos= index(*argv,'.'))==NULL)
sprintf(change_file_name,"%s.ch",*argv);
else sprintf(change_file_name,"%s",*argv);
found_change= 1;
}

/*:59*/
#line 1037 "common.web"

else/*62:*/
#line 1084 "common.web"

{
if(program==tangle)
fatal("! Usage: tangle webfile[.web] [changefile[.ch]]\n","")
else fatal("! Usage: weave webfile[.web] [changefile[.ch]] [-x]\n","");
}

/*:62*/
#line 1038 "common.web"
;
}
else/*61:*/
#line 1078 "common.web"

{
if((*argv)[1]=='x')no_xref= 1;
else/*64:*/
#line 1093 "common.web"
{
printf("! Unknown option in argument %s\n",*argv);mark_harmless;
}

/*:64*/
#line 1081 "common.web"
;
}

/*:61*/
#line 1040 "common.web"
;
}
if(!found_web)/*62:*/
#line 1084 "common.web"

{
if(program==tangle)
fatal("! Usage: tangle webfile[.web] [changefile[.ch]]\n","")
else fatal("! Usage: weave webfile[.web] [changefile[.ch]] [-x]\n","");
}

/*:62*/
#line 1042 "common.web"
;
if(!found_change)/*60:*/
#line 1076 "common.web"
strcpy(change_file_name,"/dev/null");

/*:60*/
#line 1043 "common.web"
;
}

/*:57*/
#line 42 "common.web"
;

/*:1*//*36:*/
#line 662 "common.web"
name_pointer
id_lookup(first,last,t)
ASCII*first;
ASCII*last;
sixteen_bits t;
{
ASCII*i= first;
int h;
int l;
name_pointer p;
if(last==NULL)for(last= first;*last!='\0';last++);
l= last-first;
/*37:*/
#line 684 "common.web"

h= *i;while(++i<last)h= (h+h+*i)%hash_size;

/*:37*/
#line 674 "common.web"
;
/*38:*/
#line 690 "common.web"

p= hash[h];
while(p&&!names_match(p,first,l,t))p= p->link;
if(p==NULL){
p= name_ptr;
p->link= hash[h];hash[h]= p;
}

/*:38*/
#line 675 "common.web"
;
if(p==name_ptr)/*39:*/
#line 702 "common.web"
{
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==weave)init_p(p,t);
}

/*:39*/
#line 676 "common.web"
;
return(p);
}

/*:36*//*43:*/
#line 754 "common.web"
name_pointer
mod_lookup(k,l)
ASCII*k;
ASCII*l;
{
short c= greater;
name_pointer p= root;
name_pointer q= name_dir;
while(p){
c= web_strcmp(k,l+1,p->byte_start,(p+1)->byte_start);
q= p;
switch(c){
case less:p= p->llink;continue;
case greater:p= p->rlink;continue;
case equal:return p;
default:err_print("! Incompatible section names");return NULL;

}
}
return(install_node(q,c,k,l-k+1));
}

/*:43*//*44:*/
#line 779 "common.web"

web_strcmp(j,j1,k,k1)
ASCII*j;
ASCII*j1;
ASCII*k;
ASCII*k1;
{
while(k<k1&&j<j1&&*j==*k)k++,j++;
if(k==k1)if(j==j1)return equal;
else return extension;
else if(j==j1)return prefix;
else if(*j<*k)return less;
else return greater;
}

/*:44*//*45:*/
#line 802 "common.web"
name_pointer
install_node(parent,c,j,name_len)
name_pointer parent;
int c;
ASCII*j;
int name_len;
{
name_pointer node= name_ptr;
if(byte_ptr+name_len>byte_mem_end)overflow("byte memory");
if(name_ptr==name_dir_end)overflow("name");
if(c==less)parent->llink= node;else parent->rlink= node;
node->llink= NULL;node->rlink= NULL;
init_node(node);
strncpy(byte_ptr,j,name_len);
(++name_ptr)->byte_start= byte_ptr+= name_len;
return(node);
}

/*:45*//*46:*/
#line 826 "common.web"
name_pointer
prefix_lookup(k,l)
ASCII*k;
ASCII*l;
{
short c= greater;
short count= 0;
name_pointer p= root;
name_pointer q= NULL;

name_pointer r= NULL;
while(p){
c= web_strcmp(k,l+1,p->byte_start,(p+1)->byte_start);
switch(c){
case less:p= p->llink;break;
case greater:p= p->rlink;break;
default:r= p;count++;q= p->rlink;p= p->llink;
}
if(p==NULL){
p= q;q= NULL;
}
}
if(count==0)err_print("! Name does not match");

if(count>1)err_print("! Ambiguous prefix");

return(r);
}

/*:46*/