Exemplo n.º 1
0
Arquivo: libfunc.c Projeto: vidarh/ACE
void declare()
{
/* - declare a library function -- NOT optional. 
   - declare an external function -- NOT optional.
   - declare a forward reference to a SUB. 
   - declare an instance of a structure. 
*/

char funcname[MAXIDSIZE],ut_funcname[MAXIDSIZE];
char libname[MAXIDSIZE],ut_libname[MAXIDSIZE];
char extfuncname[MAXIDSIZE+1];
int  oldlevel,cc;
int  functype=undefined;
SYM  *declared_func;
BOOL found;

 /* all functions and structures must be declared at level ZERO */

 oldlevel=lev;
 lev=ZERO;

 insymbol();

 if (sym == subsym) { lev=oldlevel; forward_ref(); return; }

 if (sym == structsym) { lev=oldlevel; declare_structure(); return; }

 if (sym != functionsym) _error(47);
 else
 {
  insymbol();

  /* type identifiers */
  functype = sym_to_opt_type();

  if (sym != ident) _error(7);
  else {
   /* get the function's name */
   strcpy(funcname,id);
   strcpy(ut_funcname,ut_id);  /* case sensitive version for search! */
   remove_qualifier(funcname);
   remove_qualifier(ut_funcname);
   if (functype == undefined) functype = typ;

   /* get the LIBRARY symbol and/or parameter list */ 
   insymbol();

   /* parse parameter list? */
   if (sym == lparen)
   {    
    do
    {   
        insymbol();

	if (sym == rparen && lastsym == lparen) break;  /* FuncName() */

	/* type indentifier? */
        if (sym == shortintsym || sym == longintsym || sym == addresssym ||
      	    sym == singlesym || sym == stringsym) 
	insymbol();

	/* parameter */
	if (sym != ident) _error(7);
	else insymbol();
    } while (sym == comma);

    if (sym != rparen) _error(9);
    else insymbol();
   }
   
   /* EXTERNAL or LIBRARY function? */
   if (sym == externalsym) {
	 if (ut_funcname[0] != '_')
	{
	   	strcpy(extfuncname,"_\0");
		strcat(extfuncname,ut_funcname);
	}
	else
		strcpy(extfuncname,ut_funcname);

	enter(extfuncname,functype,extfunc,0);
	enter_XREF(extfuncname);	

	insymbol();
   }
   else
   if (sym != librarysym) _error(48);
   else
   {
    enter(funcname,functype,function,0); /* enter into symbol table */ 
    declared_func=curr_item;

    insymbol();

    if (sym != ident && sym != stringconst)
    {
	/* 
	** Search all bmap files found in acelib and otherlib arrays 
	** for function since no library was specified.
  	*/

	found=FALSE;

	/* acelib array */
	cc=0;
	while (!found && acelib[cc].name[0] != '\0' &&
	       strcmp(acelib[cc].name,"SENTINEL") != 0)
	{
	  found = found_func(acelib[cc].name,ut_funcname,declared_func);
	  cc++;
	}

	if (found) { lev=oldlevel; return; }

	/* otherlib array */
	cc=0;
	while (!found && otherlib[cc].name[0] != '\0' &&
	       strcmp(otherlib[cc].name,"SENTINEL") != 0)
	{
	  found = found_func(otherlib[cc].name,ut_funcname,declared_func);
	  cc++;
	}	

	if (!found) _error(49);
    }
    else
    {
     	/* 
	** Search specified library (bmap file) for the declared function.
	*/
     	get_libname(libname,ut_libname);  /* without extension! */

	if (!found_func(libname,ut_funcname,declared_func)) 
	  _error(49); 

        insymbol();
    }
   }  
  }    
 }
 lev=oldlevel;
}
Exemplo n.º 2
0
void forward_test()
{
    printf("forward:\n");
    forward_ref();
    forward_ref();
}