home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CDPD Public Domain Collection for CDTV 3
/
CDPDIII.bin
/
pd
/
programming
/
utils
/
cweb
/
amiga
/
common.c
next >
Wrap
C/C++ Source or Header
|
1993-01-21
|
19KB
|
1,094 lines
#define tangle 0
#define weave 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 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 if_section_start_make_pending(b){*limit= '!'; \
for(loc= buffer;isspace(*loc);loc++); \
*limit= ' '; \
if(*loc=='@'&&(isspace(*(loc+1))||*(loc+1)=='*'))change_pending= b; \
} \
#define max_sections 2000 \
\
#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 first_chunk(p)((p)->byte_start+2)
#define prefix_length(p)((unsigned char)*((p)->byte_start)*256+ \
(unsigned char)*((p)->byte_start+1))
#define set_prefix_length(p,m)(*((p)->byte_start)= (m)/256, \
*((p)->byte_start+1)= (m)%256) \
#define less 0
#define equal 1
#define greater 2
#define prefix 3
#define extension 4 \
#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 fatal(s,t){ \
printf(s);err_print(t); \
history= fatal_message;wrap_up(); \
} \
#define confusion(s)fatal("! This can't happen: ",s) \
\
#define overflow(t){ \
printf("\n! Sorry, %s capacity exceeded",t);fatal("",""); \
} \
\
#define show_banner flags['b']
#define show_progress flags['p']
#define show_stats flags['s']
#define show_happiness flags['h'] \
#define update_terminal fflush(stdout) \
#define new_line putchar('\n')
#define putxchar putchar
#define term_write(a,b)fflush(stdout),write(1,a,b)
#define C_printf(c,a)fprintf(C_file,c,a)
#define C_putc(c)putc(c,C_file) \
/*1:*/
#line 57 "common.w"
/*5:*/
#line 99 "common.w"
#include <ctype.h>
/*:5*//*8:*/
#line 155 "common.w"
#include <stdio.h>
/*:8*/
#line 58 "common.w"
/*2:*/
#line 71 "common.w"
typedef short boolean;
boolean program;
/*:2*//*7:*/
#line 149 "common.w"
char buffer[long_buf_size];
char*buffer_end= buffer+buf_size-2;
char*limit= buffer;
char*loc= buffer;
/*:7*//*10:*/
#line 204 "common.w"
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];
char alt_web_file_name[max_file_name_length];
int line[max_include_depth];
int change_line;
boolean input_has_ended;
boolean changing;
boolean web_file_open= 0;
/*:10*//*20:*/
#line 402 "common.w"
typedef unsigned short sixteen_bits;
sixteen_bits section_count;
boolean changed_section[max_sections];
boolean change_pending;
boolean print_where= 0;
/*:20*//*26:*/
#line 543 "common.w"
typedef struct name_info{
char*byte_start;
/*30:*/
#line 580 "common.w"
struct name_info*link;
/*:30*//*37:*/
#line 670 "common.w"
union{
struct name_info*Rlink;
char Ilk;
}dummy;
/*:37*//*48:*/
#line 989 "common.w"
char*equiv_or_xref;
/*:48*/
#line 546 "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;
/*:26*//*28:*/
#line 566 "common.w"
name_pointer name_ptr;
char*byte_ptr;
/*:28*//*31:*/
#line 593 "common.w"
typedef name_pointer*hash_pointer;
name_pointer hash[hash_size];
hash_pointer hash_end= hash+hash_size-1;
hash_pointer h;
/*:31*//*49:*/
#line 1009 "common.w"
int history= spotless;
/*:49*//*57:*/
#line 1120 "common.w"
int argc;
char**argv;
char C_file_name[max_file_name_length];
char tex_file_name[max_file_name_length];
boolean flags[128];
/*:57*//*66:*/
#line 1250 "common.w"
FILE*C_file;
FILE*tex_file;
/*:66*/
#line 59 "common.w"
/*3:*/
#line 81 "common.w"
int phase;
/*:3*//*11:*/
#line 229 "common.w"
char change_buffer[buf_size];
char*change_limit;
/*:11*/
#line 60 "common.w"
/*4:*/
#line 87 "common.w"
common_init()
{
/*29:*/
#line 570 "common.w"
name_dir->byte_start= byte_ptr= byte_mem;
name_ptr= name_dir+1;
name_ptr->byte_start= byte_mem;
/*:29*//*32:*/
#line 601 "common.w"
for(h= hash;h<=hash_end;*h++= NULL);
/*:32*//*38:*/
#line 677 "common.w"
root= NULL;
/*:38*/
#line 90 "common.w"
;
/*58:*/
#line 1131 "common.w"
show_banner= show_happiness= show_progress= 1;
/*:58*/
#line 91 "common.w"
;
/*67:*/
#line 1254 "common.w"
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);
}
/*:67*/
#line 92 "common.w"
;
}
/*:4*//*9:*/
#line 162 "common.w"
input_ln(fp)
FILE*fp;
{
register int c;
register char*k;
if(feof(fp))return(0);
limit= k= buffer;
while(k<=buffer_end&&(c= getc(fp))!=EOF&&c!='\n')
if((*(k++)= c)!=' ')limit= k;
if(k>buffer_end)
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);
return(1);
}
/*:9*//*12:*/
#line 240 "common.w"
prime_the_change_buffer()
{
change_limit= change_buffer;
/*13:*/
#line 253 "common.w"
while(1){
change_line++;
if(!input_ln(change_file))return;
if(limit<buffer+2)continue;
if(buffer[0]!='@')continue;
if(isupper(buffer[1]))buffer[1]= tolower(buffer[1]);
if(buffer[1]=='x')break;
if(buffer[1]=='y'||buffer[1]=='z'||buffer[1]=='i'){
loc= buffer+2;
err_print("! Missing @x in change file");
}
}
/*:13*/
#line 244 "common.w"
;
/*14:*/
#line 270 "common.w"
do{
change_line++;
if(!input_ln(change_file)){
err_print("! Change file ended after @x");
return;
}
}while(limit==buffer);
/*:14*/
#line 245 "common.w"
;
/*15:*/
#line 280 "common.w"
{
change_limit= change_buffer-buffer+limit;
strncpy(change_buffer,buffer,limit-buffer+1);
}
/*:15*/
#line 246 "common.w"
;
}
/*:12*//*16:*/
#line 308 "common.w"
check_change()
{
int n= 0;
if(lines_dont_match)return;
change_pending= 0;
if(!changed_section[section_count]){
if_section_start_make_pending(1);
if(!change_pending)changed_section[section_count]= 1;
}
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;
return;
}
if(limit>buffer+1&&buffer[0]=='@'){
if(isupper(buffer[1]))buffer[1]= tolower(buffer[1]);
/*17:*/
#line 345 "common.w"
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;
printf("\n! Hmm... %d ",n);
err_print("of the preceding lines failed to match");
}
return;
}
/*:17*/
#line 329 "common.w"
;
}
/*15:*/
#line 280 "common.w"
{
change_limit= change_buffer-buffer+limit;
strncpy(change_buffer,buffer,limit-buffer+1);
}
/*:15*/
#line 331 "common.w"
;
changing= 0;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--;cur_line++;
}
if(lines_dont_match)n++;
}
}
/*:16*//*18:*/
#line 364 "common.w"
reset_input()
{
limit= buffer;loc= buffer+1;buffer[0]= ' ';
/*19:*/
#line 377 "common.w"
if((web_file= fopen(web_file_name,"r"))==NULL){
strcpy(web_file_name,alt_web_file_name);
if((web_file= fopen(web_file_name,"r"))==NULL)
fatal("! Cannot open input file ",web_file_name);
}
web_file_open= 1;
if((change_file= fopen(change_file_name,"r"))==NULL)
fatal("! Cannot open change file ",change_file_name);
/*:19*/
#line 368 "common.w"
;
include_depth= 0;cur_line= 0;change_line= 0;
changing= 1;prime_the_change_buffer();changing= !changing;
limit= buffer;loc= buffer+1;buffer[0]= ' ';input_has_ended= 0;
}
/*:18*//*21:*/
#line 410 "common.w"
get_line()
{
restart:
if(changing)/*24:*/
#line 487 "common.w"
{
change_line++;
if(!input_ln(change_file)){
err_print("! Change file ended without @z");
buffer[0]= '@';buffer[1]= 'z';limit= buffer+2;
}
if(limit>buffer){
if(change_pending){
if_section_start_make_pending(0);
if(change_pending){
changed_section[section_count]= 1;change_pending= 0;
}
}
*limit= ' ';
if(buffer[0]=='@'){
if(isupper(buffer[1]))buffer[1]= tolower(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;
}
}
}
}
/*:24*/
#line 414 "common.w"
;
if(!changing){
/*23:*/
#line 474 "common.w"
{
cur_line++;
while(!input_ln(cur_file)){
print_where= 1;
if(include_depth==0){input_has_ended= 1;break;}
else{fclose(cur_file);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();
}
/*:23*/
#line 416 "common.w"
;
if(changing)goto restart;
}
loc= buffer;*limit= ' ';
if(*buffer=='@'&&(*(buffer+1)=='i'||*(buffer+1)=='I'))
/*22:*/
#line 436 "common.w"
{
char*k,*j;
loc= buffer+2;
while(loc<=limit&&(*loc==' '||*loc=='\t'||*loc=='"'))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!=' '&&*loc!='\t'&&*loc!='"')*k++= *loc++;
*k= '\0';
if((cur_file= fopen(cur_file_name,"r"))==NULL){
#ifdef INCLUDEDIR
strcpy(cur_file_name,INCLUDEDIR);
k= cur_file_name+strlen(cur_file_name);
while(*j!=' '&&*j!='\t'&&*j!='"')*k++= *j++;
*k= '\0';
if((cur_file= fopen(cur_file_name,"r"))==NULL){
#endif
include_depth--;
err_print("! Cannot open include file");
}
#ifdef INCLUDEDIR
else{cur_line= 0;print_where= 1;}
}
#endif
else{cur_line= 0;print_where= 1;}
}
else{
include_depth--;
err_print("! Too many nested includes");
}
}
goto restart;
}
/*:22*/
#line 421 "common.w"
;
return(!input_has_ended);
}
/*:21*//*25:*/
#line 519 "common.w"
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= buffer;
err_print("! Change file entry did not match");
}
}
/*:25*//*50:*/
#line 1019 "common.w"
err_print(s)
char*s;
{
char*k,*l;
printf(*s=='!'?"\n%s":"%s",s);
if(web_file_open)/*51:*/
#line 1038 "common.w"
{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(*k);
putchar('\n');
for(k= buffer;k<l;k++)putchar(' ');
}
for(k= l;k<limit;k++)putchar(*k);
if(*limit=='|')putchar('|');
putchar(' ');
}
/*:51*/
#line 1025 "common.w"
;
update_terminal;mark_error;
}
/*:50*//*55:*/
#line 1085 "common.w"
wrap_up(){
putchar('\n');
#ifdef STAT
if(show_stats)print_stats();
#endif
/*56:*/
#line 1096 "common.w"
switch(history){
case spotless:if(show_happiness)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");
}
/*:56*/
#line 1091 "common.w"
;
if(history>harmless_message)exit(1);
else exit(0);
}
/*:55*//*59:*/
#line 1149 "common.w"
#line 1150 "common.w"
scan_args()
{
char*dot_pos;
char*name_pos;
register char*s;
boolean found_web= 0,found_change= 0,found_out= 0;
boolean flag_change;
while(--argc>0){
if(**(++argv)=='-'||**argv=='+')/*63:*/
#line 1226 "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;
}
/*:63*/
#line 1160 "common.w"
else{
s= name_pos= *argv;dot_pos= NULL;
while(*s){
if(*s=='.')dot_pos= s++;
else if(*s=='/')dot_pos= NULL,name_pos= ++s;
else s++;
}
if(!found_web)/*60:*/
#line 1186 "common.w"
{
if(s-*argv>max_file_name_length-5)
/*65:*/
#line 1245 "common.w"
fatal("! Filename too long\n",*argv);
/*:65*/
#line 1189 "common.w"
;
if(dot_pos==NULL)
sprintf(web_file_name,"%s.w",*argv);
else{
strcpy(web_file_name,*argv);
*dot_pos= 0;
}
sprintf(alt_web_file_name,"%s.web",*argv);
sprintf(tex_file_name,"%s.tex",name_pos);
sprintf(C_file_name,"%s.c",name_pos);
found_web= 1;
}
/*:60*/
#line 1169 "common.w"
else if(!found_change)/*61:*/
#line 1202 "common.w"
{
if(s-*argv>max_file_name_length-4)
/*65:*/
#line 1245 "common.w"
fatal("! Filename too long\n",*argv);
/*:65*/
#line 1205 "common.w"
;
if(dot_pos==NULL)
sprintf(change_file_name,"%s.ch",*argv);
else strcpy(change_file_name,*argv);
found_change= 1;
}
/*:61*/
#line 1170 "common.w"
else if(!found_out)/*62:*/
#line 1212 "common.w"
{
if(s-*argv>max_file_name_length-5)
/*65:*/
#line 1245 "common.w"
fatal("! Filename too long\n",*argv);
/*:65*/
#line 1215 "common.w"
;
if(dot_pos==NULL){
sprintf(tex_file_name,"%s.tex",*argv);
sprintf(C_file_name,"%s.c",*argv);
}else{
strcpy(tex_file_name,*argv);
strcpy(C_file_name,*argv);
}
found_out= 1;
}
/*:62*/
#line 1171 "common.w"
else/*64:*/
#line 1234 "common.w"
{
if(program==tangle)
fatal(
"! Usage: ctangle [options] webfile[.w] [changefile[.ch] [outfile[.c]]]\n"
,"")
else fatal(
"! Usage: cweave [options] webfile[.w] [changefile[.ch] [outfile[.tex]]]\n"
,"");
}
/*:64*/
#line 1172 "common.w"
;
}
}
if(!found_web)/*64:*/
#line 1234 "common.w"
{
if(program==tangle)
fatal(
"! Usage: ctangle [options] webfile[.w] [changefile[.ch] [outfile[.c]]]\n"
,"")
else fatal(
"! Usage: cweave [options] webfile[.w] [changefile[.ch] [outfile[.tex]]]\n"
,"");
}
/*:64*/
#line 1175 "common.w"
;
#line 15 "common.ch"
if(!found_change)strcpy(change_file_name,"NIL:");
#line 1177 "common.w"
}
/*:59*/
#line 61 "common.w"
/*:1*//*33:*/
#line 606 "common.w"
name_pointer
id_lookup(first,last,t)
char*first;
char*last;
char t;
{
char*i= first;
int h;
int l;
name_pointer p;
if(last==NULL)for(last= first;*last!='\0';last++);
l= last-first;
/*34:*/
#line 628 "common.w"
h= *i;while(++i<last)h= (h+h+*i)%hash_size;
/*:34*/
#line 618 "common.w"
;
/*35:*/
#line 634 "common.w"
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;
}
/*:35*/
#line 619 "common.w"
;
if(p==name_ptr)/*36:*/
#line 646 "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==weave)init_p(p,t);
}
/*:36*/
#line 620 "common.w"
;
return(p);
}
/*:33*//*39:*/
#line 704 "common.w"
print_section_name(p)
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;
}else{
term_write(s,ss+1-s);p= name_dir;q= NULL;
}
s= p->byte_start;
}
if(q)term_write("...",3);
}
sprint_section_name(dest,p)
char*dest;
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){
p= q->link;q= p;
}else{
ss++;p= name_dir;
}
strncpy(dest,s,ss-s),dest+= ss-s;
s= p->byte_start;
}
*dest= '\0';
}
print_prefix_name(p)
name_pointer p;
{
char*s= first_chunk(p);
int l= prefix_length(p);
term_write(s,l);
if(s+l<(p+1)->byte_start)term_write("...",3);
}
/*:39*//*40:*/
#line 760 "common.w"
web_strcmp(j,j_len,k,k_len)
char*j,*k;
int j_len,k_len;
{
char*j1= j+j_len,*k1= k+k_len;
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;
}
/*:40*//*41:*/
#line 786 "common.w"
name_pointer
add_section_name(par,c,first,last,ispref)
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;
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;
if(ispref){
*(byte_ptr-1)= ' ';
name_len--;
name_ptr->link= name_dir;
(++name_ptr)->byte_start= byte_ptr;
}
set_prefix_length(p,name_len);
(void)strncpy(s,first,name_len);
p->llink= NULL;
p->rlink= NULL;
init_node(p);
return par==NULL?(root= p):c==less?(par->llink= p):(par->rlink= p);
}
/*:41*//*42:*/
#line 815 "common.w"
extend_section_name(p,first,last,ispref)
name_pointer p;
char*first;
char*last;
int ispref;
{
char*s;
name_pointer q= p+1;
int name_len= last-first+ispref;
if(name_ptr>=name_dir_end)overflow("name");
while(q->link!=name_dir)q= q->link;
q->link= name_ptr;
s= name_ptr->byte_start;
name_ptr->link= name_dir;
if(s+name_len>byte_mem_end)overflow("byte memory");
(++name_ptr)->byte_start= byte_ptr= s+name_len;
(void)strncpy(s,first,name_len);
if(ispref)*(byte_ptr-1)= ' ';
}
/*:42*//*43:*/
#line 842 "common.w"
name_pointer
section_lookup(first,last,ispref)
char*first,*last;
int ispref;
{
int c;
name_pointer p= root;
name_pointer q= NULL;
name_pointer r= NULL;
name_pointer par= NULL;
int name_len= last-first+1;
/*44:*/
#line 866 "common.w"
while(p){
c= web_strcmp(first,name_len,first_chunk(p),prefix_length(p));
if(c==less||c==greater){
if(r==NULL)
par= p;
p= (c==less?p->llink:p->rlink);
}else{
if(r!=NULL){
printf("\n! Ambiguous prefix: matches <");
print_prefix_name(p);
printf(">\n and <");
print_prefix_name(r);
err_print(">");
return name_dir;
}
r= p;
p= p->llink;
q= r->rlink;
}
if(p==NULL)
p= q,q= NULL;
}
/*:44*/
#line 856 "common.w"
;
/*45:*/
#line 891 "common.w"
if(r==NULL)
return add_section_name(par,c,first,last+1,ispref);
/*:45*/
#line 857 "common.w"
;
/*46:*/
#line 899 "common.w"
switch(section_name_cmp(&first,name_len,r)){
case less:case greater:
printf("\n! Section name incompatible with <");
print_prefix_name(r);
printf(">,\n which abbreviates <");
print_section_name(r);
err_print(">");
return r;
case prefix:
if(!ispref){
printf("\n! New name is a prefix of <");
print_section_name(r);
err_print(">");
}
else if(name_len<prefix_length(r))set_prefix_length(r,name_len);
case equal:return r;
case extension:if(!ispref||first<=last)
extend_section_name(r,first,last+1,ispref);
return r;
case bad_extension:
printf("\n! New name extends <");
print_section_name(r);
err_print(">");
return r;
}
/*:46*/
#line 858 "common.w"
;
}
/*:43*//*47:*/
#line 947 "common.w"
section_name_cmp(pfirst,len,r)
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){
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);
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;}
*pfirst= first;return extension;
default:return c;
}
}
}
/*:47*/