#include <bastard.h>

/* API sections:
 *    11. Functions				:: Creating/manipulating FUNCTION objects
 *    12. Inline					:: Creating/manipulating INLINE functions
 * /


/* ---------------------------------------------------------------Functions */
   int DefineFunc( long rva, char * name, int size ){
      struct function f;
   
      f.id = ++seq.func;
      f.rva = rva;
      f.size = size;
   /* add check : if size == NULL, look for next ret */
      if ( d_keyfind(FUNCTION_RVA, &f.rva) != S_OKAY){
         d_fillnew(FUNCTION, &f);
         if (db_status != S_OKAY) { 
            return(SetLastError(dbError()));}
      } 
   /* create name for addr */
      if ( d_keyfind(NAME_RVA, &f.rva) != S_OKAY){
			/* don't overwrite existing names */
         SetName( rva, name, NAME_AUTO); 
      }
      return(1);
   }

   int GetFuncName( long rva, char *buf){
      struct name n;
   
      if ( d_keyfind(NAME_RVA, &rva) == S_OKAY) {
			d_recread(&n);
         strncpy(buf, n.name, 63);
         return(1);
      }
      return(SetLastError(4310));
   }

   int GetFuncStart( long rva){
      struct function f;
   
      if ( d_keyfind(FUNCTION_RVA, &rva) == S_NOTFOUND){
         d_keynext(FUNCTION_RVA);
         d_keyprev(FUNCTION_RVA);
      }
      if ( db_status != S_OKAY)
         return(SetLastError(dbError()));
      d_recread(&f);
      return(f.rva);
   }

   int GetFuncEnd( long rva){
      struct function f;
   
      if ( d_keyfind(FUNCTION_RVA, &rva) == S_NOTFOUND){
         d_keynext(FUNCTION_RVA);
         d_keyprev(FUNCTION_RVA);
      }
      if ( db_status != S_OKAY)
         return(SetLastError(dbError()));
      d_recread(&f);
      return(f.rva + f.size);
   }

   int GetFuncByName( char *name) {
		int rva;
		
		rva = GetAddrByName( name );
		if ( rva && d_keyfind(FUNCTION_RVA, &rva) == S_OKAY){
         return(rva);
      }

      return(SetLastError(4320));
   }

   int SetFuncName( long rva, char *name){
      struct function f;
   
      if ( d_keyfind(FUNCTION_RVA, &rva) != S_OKAY)
      	return(SetLastError(4310));
      return(SetName( rva, name, NAME_AUTO)); 
   }

   int SetFuncSize( long rva, int size){
      struct function f;
   
      if ( d_keyfind(FUNCTION_RVA, &rva) == S_OKAY){
         d_recread(&f);
			f.size = size;
         d_recwrite(&f);
         return(1);
      }
      return(SetLastError(4310));
   }

/* ---------------------------------------------------------------Inline */
/* Flags to add : paginate, hide libs, hide inline */
/* Note : f;ags should be changed in Seer to avoid parsing :) */

