示例#1
0
void reset_input (void) /* initialise to read the web file and change file */
{ boolean use_change_file= change_file_name[0]!='\0';
  
  { if ((web_file=fopen(web_file_name,"r"))!=NULL)
      strcpy(file[0].name,web_file_name);
    else if ((web_file=fopen(alt_web_file_name,"r"))!=NULL)
      strcpy(file[0].name,alt_web_file_name);
    else fatal("! Cannot open \"%s\" as input file", web_file_name);
  	      
    web_file_open=true;
    if (use_change_file)
      if ((change_file=fopen(change_file_name,"r"))!=NULL)
        strcpy(change.name,change_file_name);
      else if (!change_file_explicit)
        use_change_file=false; /* forget about the change file */
      else fatal("! Cannot open \"%s\" as change file", change_file_name);
  		
  }
  cur_line=0; change_line=0; include_depth=0;
  if (use_change_file) { changing=true; prime_the_change_buffer(); }
    /* prepare change file */
  else change_limit=change_buffer;
    /* emulate that change file that has ended */
  limit=buffer; loc=&buffer[1]; /* now |find_char()| will read a line */
  changing=false; input_has_ended=false;
}
示例#2
0
void
#line 103 "./cwebdir/comm-w2c.ch"
 reset_input P1H(void)
#line 381 "./cwebdir/common.w"
{
limit= buffer;loc= buffer+1;buffer[0]= ' ';
/*19:*/
#line 393 "./cwebdir/common.w"

#line 115 "./cwebdir/comm-w2c.ch"
if((found_filename= kpse_find_cweb(web_file_name))==NULL||
(web_file= fopen(found_filename,"r"))==NULL){
fatal("! Cannot open input file ",web_file_name);
}else if(strlen(found_filename)<max_file_name_length){
strcpy(web_file_name,found_filename);
free(found_filename);
}
#line 399 "./cwebdir/common.w"


web_file_open= 1;
#line 128 "./cwebdir/comm-w2c.ch"
if((found_filename= kpse_find_cweb(change_file_name))==NULL||
(change_file= fopen(found_filename,"r"))==NULL){
fatal("! Cannot open change file ",change_file_name);
}else if(strlen(found_filename)<max_file_name_length){
strcpy(change_file_name,found_filename);
free(found_filename);
}
#line 404 "./cwebdir/common.w"

/*:19*/
#line 383 "./cwebdir/common.w"
;
include_depth= 0;cur_line= 0;change_line= 0;
change_depth= include_depth;
changing= 1;prime_the_change_buffer();changing= !changing;
limit= buffer;loc= buffer+1;buffer[0]= ' ';input_has_ended= 0;
}
示例#3
0
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;
}
示例#4
0
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;
}