示例#1
0
文件: p0io.c 项目: mingpen/OpenNT
/************************************************************************
**  nested_include : searches the parentage list of the currently
**		open files on the stack when a new include file is found.
**		Input : ptr to include file name.
**		Output : TRUE if the file was found, FALSE if not.
*************************************************************************/
int nested_include(void)
{
    PUCHAR	p_tmp1;
    PUCHAR	p_file;
    PUCHAR	p_slash;
    int			tos;

    tos = Findex;
    p_file = Filename;		/* always start with the current file */
    for(;;) {
	p_tmp1 = p_file;
	p_slash = NULL;
	while(*p_tmp1) {	/* pt to end of filename, find trailing slash */
	    if(CHARMAP(*p_tmp1) == LX_LEADBYTE) {
		p_tmp1++;
	    }
	    else if(strchr(Path_chars, *p_tmp1)) {
		p_slash = p_tmp1;
	    }
	    p_tmp1++;
	}
	if(p_slash) {
	    p_tmp1 = Reuse_1;
	    while(p_file <= p_slash) {	/*  we want the trailing '/'  */
		*p_tmp1++ = *p_file++;	/*  copy the parent directory  */
	    }
	    p_file = yylval.yy_string.str_ptr;
	    while((*p_tmp1++ = *p_file++)!=0) {  /*append include file name  */
		;	/*  NULL  */
	    }
	}
	else {
	    SET_MSG(Reuse_1,"%s",yylval.yy_string.str_ptr);
	}
	if(newinput(Reuse_1,MAY_OPEN)) {
	    return(TRUE);
	}
	if(tos <= 0) {
	    break;
	}
	p_file = Fstack[tos--].fl_name;
    }
    return(FALSE);
}
extern input_list* unflatten_area(input_list *entry, int entry_number)
{
   input_list *pred = NULL, *input, *new_input;
   chain_list* abl;
   cell_list* cell;
   note_list* note, *all_note=NULL, *best_note;
   int cell_source_positiv, neg_cell_source_positiv;   /*flag*/

   if (!entry) {
      fprintf(stderr,"unflatten_area: no input\n");
      exit(1);
   }
   
   /*test all the simple logic library*/
   for (cell=getcell_oper_lib(); cell; cell=cell->NEXT) {
      all_note=eval_note(all_note, cell, entry, entry_number);
   }
      
   /*no result pattern, impossible to map, signal it to caller function*/
   if (!all_note) return entry;

   /*take the best for a positiv and negativ results*/
   best_note=all_note;
   best_note->AVERAGE_COST=(best_note->COST+best_note->NEG_COST)/2;
   for (note=all_note->NEXT; note; note=note->NEXT) {
      note->AVERAGE_COST=(note->COST+note->NEG_COST)/2;
      if (note->AVERAGE_COST<best_note->AVERAGE_COST) best_note=note;
      else if (note->AVERAGE_COST==best_note->AVERAGE_COST 
         && note->ARITY>best_note->ARITY) best_note=note;
      else if (note->AVERAGE_COST==best_note->AVERAGE_COST 
         && note->ARITY==best_note->ARITY
         && note->DELAY+note->NEG_DELAY<best_note->DELAY+best_note->NEG_DELAY)
            best_note=note;
   }

   /*one of those cells are missing, impossible to unflat*/
   if (!best_note->CELL || !best_note->NEG_CELL) {
      fprintf(stderr,
      "unflatten_area: opposite cell of %s is missing (%d inputs)\n",
      best_note->CELL?best_note->CELL->NAME:best_note->NEG_CELL->NAME,
      entry_number);
      exit(1);
   }   

   /*build new input*/
   new_input=newinput();
   new_input->DELAY=best_note->DELAY;
   new_input->NEG_DELAY=best_note->NEG_DELAY;
   new_input->R=best_note->R;
   new_input->NEG_R=best_note->NEG_R;
   new_input->ABL=createabloper(ABL_OPER(best_note->CELL->ABL));
   new_input->NEG_ABL=createabloper(ABL_OPER(best_note->NEG_CELL->ABL));
   cell_source_positiv=is_source_positiv(ABL_OPER(best_note->CELL->ABL));
   neg_cell_source_positiv=is_source_positiv(
                                         ABL_OPER(best_note->NEG_CELL->ABL));   /*put operands*/
   for (input=entry; input; input=input->NEXT) {
      if (best_note->ARITY==0) break;
      best_note->ARITY--;
      /*positiv*/
      if (cell_source_positiv) {
         abl=input->ABL;
         input->ABL=NULL; /* protect from freeinput() */
      }
      else {   
         abl=input->NEG_ABL;
         input->NEG_ABL=NULL; /* protect from freeinput() */
      }
      ABL_CDR(new_input->ABL)=addchain(ABL_CDR(new_input->ABL),abl);
      /*opposite*/
      if (neg_cell_source_positiv) {
         if (input->ABL) abl=input->ABL;
         else abl=dupablexpr(abl);     /*already used above*/
         input->ABL=NULL; /* protect from freeinput() */
      }
      else {   
         if (input->NEG_ABL) abl=input->NEG_ABL;
         else abl=dupablexpr(abl);     /*already used above*/
         input->NEG_ABL=NULL; /* protect from freeinput() */
      }
      ABL_CDR(new_input->NEG_ABL)=addchain(ABL_CDR(new_input->NEG_ABL),abl);

      pred=input;
   }
   
   pred->NEXT=NULL;
   freeinput(entry);
   freenote(all_note);
   
   return sort_input(input,new_input);      /*return a sort list*/
}