local void prime_the_change_buffer (void) { change_limit=change_buffer; /* this value is used if the change file ends */ do { if (++change_line,!input_ln(change_file)) return; if (limit>&buffer[1] && buffer[0]=='@') if (buffer[1]=='x') break; else if (buffer[1]=='y' || buffer[1]=='z') { loc=&buffer[2]; /* point out error after \:y or \:z */ err_print ("! Where is the matching @x?"); } else { if (buffer[1]=='i' && !compatibility_mode) { loc=&buffer[2]; err_print ("! No includes allowed in change file"); } } } while (true); do if (++change_line,!input_ln(change_file)) { loc=&buffer[0]; err_print("! Change file ended after @x"); return; } while (limit==buffer); { int n=(int)(limit-buffer); change_limit=change_buffer+n; strncpy(change_buffer,buffer,n); } }
void #line 87 "./cwebdir/comm-w2c.ch" prime_the_change_buffer P1H(void) #line 254 "./cwebdir/common.w" { change_limit= change_buffer; /*13:*/ #line 265 "./cwebdir/common.w" while(1){ 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(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 256 "./cwebdir/common.w" ; /*14:*/ #line 282 "./cwebdir/common.w" do{ change_line++; if(!input_ln(change_file)){ err_print("! Change file ended after @x"); return; } }while(limit==buffer); /*:14*/ #line 257 "./cwebdir/common.w" ; /*15:*/ #line 292 "./cwebdir/common.w" { change_limit= change_buffer+(limit-buffer); strncpy(change_buffer,buffer,limit-buffer+1); } /*:15*/ #line 258 "./cwebdir/common.w" ; }
local void check_change (void) /* switches to |change_file| if the buffers match */ { int n=0; /* the number of discrepancies found */ if (!lines_match()) return; print_where=true; /* indicate interrupted line sequencing */ do { changing=true; { if (++change_line,!input_ln(change_file)) { loc=&buffer[0]; err_print("! Change file ended before @y"); change_limit=change_buffer; changing=false; return; } if (limit>&buffer[1] && buffer[0]=='@') if (buffer[1]=='y') break; else if (buffer[1]=='x' || buffer[1]=='z') { loc=&buffer[2]; err_print("! Where is the matching @y?"); } else { if (buffer[1]=='i' && !compatibility_mode) { loc=&buffer[2]; err_print ("! No includes allowed in change file"); } } { int n=(int)(limit-buffer); change_limit=change_buffer+n; strncpy(change_buffer,buffer,n); } } changing=false; if (!get_web_line()) { loc=&buffer[0]; err_print("! CWEB file ended during a change"); return; } if (!lines_match()) ++n; } while (true); if (n>0) { loc=&buffer[2]; print("\n! Hmm... %d of the preceding lines failed to match",n); err_print(""); } }
local boolean get_web_line(void) { do if (++cur_line,input_ln(cur_file)) /* then a line has been found */ if (!compatibility_mode && limit>&buffer[1] && buffer[0]=='@' && buffer[1]=='i') { loc=&buffer[2]; print_where=true; if (locate_file_name()) /* expand \:i */ push_input_file(false,false); } else return true; /* return the line without further action */ else if (include_depth==0) /* then end of input has been reached */ { input_has_ended=true; web_file_open=false; return false; } else { fclose(cur_file); print_where=true; if (include_depth--==saved_include_depth) /* then restore |changing| */ { changing=saved_changing; change_limit=saved_change_limit; saved_include_depth=0; including_header_file=false; if (changing) return false; /* fall back into change file */ } } while (true); }
int get_line P1H(void) #line 428 "./cwebdir/common.w" { restart: if(changing&&include_depth==change_depth) /*27:*/ #line 537 "./cwebdir/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(xisupper(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; } } } } /*:27*/ #line 431 "./cwebdir/common.w" ; if(!changing||include_depth> change_depth){ /*26:*/ #line 520 "./cwebdir/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--; if(changing&&include_depth==change_depth)break; cur_line++; } } if(!changing&&!input_has_ended) if(limit-buffer==change_limit-change_buffer) if(buffer[0]==change_buffer[0]) if(change_limit> change_buffer)check_change(); } /*:26*/ #line 433 "./cwebdir/common.w" ; if(changing&&include_depth==change_depth)goto restart; } if(input_has_ended)return 0; loc= buffer;*limit= ' '; if(buffer[0]=='@'&&(buffer[1]=='i'||buffer[1]=='I')){ loc= buffer+2;*limit= '"'; while(*loc==' '||*loc=='\t')loc++; if(loc>=limit){ err_print("! Include file name not given"); goto restart; } if(include_depth>=max_include_depth-1){ err_print("! Too many nested includes"); goto restart; } include_depth++; /*25:*/ #line 474 "./cwebdir/common.w" { #line 200 "./cwebdir/comm-w2c.ch" char*cur_file_name_end= cur_file_name+max_file_name_length-1; char*k= cur_file_name; #line 479 "./cwebdir/common.w" if(*loc=='"'){ loc++; while(*loc!='"'&&k<=cur_file_name_end)*k++= *loc++; if(loc==limit)k= cur_file_name_end+1; }else while(*loc!=' '&&*loc!='\t'&&*loc!='"'&&k<=cur_file_name_end)*k++= *loc++; if(k> cur_file_name_end)too_long(); *k= '\0'; #line 207 "./cwebdir/comm-w2c.ch" if((found_filename= kpse_find_cweb(cur_file_name))!=NULL&& (cur_file= fopen(found_filename,"r"))!=NULL){ if(strlen(found_filename)<max_file_name_length){ strcpy(cur_file_name,found_filename); free(found_filename); } #line 490 "./cwebdir/common.w" cur_line= 0;print_where= 1; goto restart; } #line 517 "./cwebdir/common.w" include_depth--;err_print("! Cannot open include file");goto restart; } /*:25*/ #line 452 "./cwebdir/common.w" ; } return 1; }
void #line 95 "./cwebdir/comm-w2c.ch" check_change P1H(void) #line 323 "./cwebdir/common.w" { 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]=='@'){ char xyz_code= xisupper(buffer[1])?tolower(buffer[1]):buffer[1]; /*17:*/ #line 358 "./cwebdir/common.w" if(xyz_code=='x'||xyz_code=='z'){ loc= buffer+2;err_print("! Where is the matching @y?"); } else if(xyz_code=='y'){ if(n> 0){ loc= buffer+2; printf("\n! Hmm... %d ",n); err_print("of the preceding lines failed to match"); } change_depth= include_depth; return; } /*:17*/ #line 342 "./cwebdir/common.w" ; } /*15:*/ #line 292 "./cwebdir/common.w" { change_limit= change_buffer+(limit-buffer); strncpy(change_buffer,buffer,limit-buffer+1); } /*:15*/ #line 344 "./cwebdir/common.w" ; changing= 0;cur_line++; while(!input_ln(cur_file)){ if(include_depth==0){ err_print("! CWEB file ended during a change"); input_has_ended= 1;return; } include_depth--;cur_line++; } if(lines_dont_match)n++; } }
boolean get_line (void) /* inputs the next line */ { restart: if (changing) mark_section_as_changed(section_count); else { if (get_web_line() && change_limit>change_buffer && limit-buffer==change_limit-change_buffer && buffer[0]==change_buffer[0] ) check_change(); } if (changing) { { if (++change_line,!input_ln (change_file)) { err_print("! Change file ended without @z"); buffer[0]='@'; buffer[1]='z'; limit=&buffer[2]; } if (limit>&buffer[1] && buffer[0]=='@') /* check if the change has ended */ if (buffer[1]=='z') { prime_the_change_buffer(); changing=false; print_where=true; } else if (buffer[1]=='x' || buffer[1]=='y') { loc=&buffer[2]; err_print("! Where is the matching @z?"); } else { if (buffer[1]=='i' && !compatibility_mode) { loc=&buffer[2]; err_print ("! No includes allowed in change file"); } } } if (!changing) { mark_section_as_changed(section_count); goto restart; } } loc=&buffer[0]; *limit= ' '; /* place sentinel space */ if (compatibility_mode && buffer[0]=='@' && buffer[1]=='i') { loc+=2; print_where=true; if (locate_file_name()) push_input_file(false,changing); goto restart; } if (limit-buffer>5 && strncmp(buffer,"#line",5)==0 && isspace((eight_bits)buffer[5])) { sixteen_bits line=0; print_where=true; /* output a \&{\#line} directive soon */ loc=&buffer[6]; while (loc<limit && isspace((eight_bits)*loc)) ++loc; if (isdigit((eight_bits)*loc)) { do line=10*line + *loc++ -'0'; while (isdigit((eight_bits)*loc)); while (loc<limit && isspace((eight_bits)*loc)) ++loc; if (*loc++=='"') { int i=0; while (&loc[i]<limit && loc[i]!='"') ++i; if (loc[i]=='"' && i<max_file_name_length) { struct f* cur_f= changing ? &change : &file[include_depth]; cur_f->line=line-1; /* directive applies to next line, not this one */ strncpy(cur_f->name,loc,i); cur_f->name[i]='\0'; goto restart; } } } err_print("! Improper #line directive"); goto restart; } return !input_has_ended; }