
#include <bastard.h>

/* API sections:
 *     6. Code						:: Creating/manipulating CODE objects
 * /


/* ---------------------------------------------------------------Code */
/* TODO : rewrite these to use curr_rec like api_search.c does */
   long GetNextCode(long rva){
      struct address a;
   
      d_keyfind(ADDRESS_RVA, &rva);
      while (db_status == S_OKAY){
         d_keynext(ADDRESS_RVA);
         d_recread(&a);
         if (a.flags & ADDR_CODE) 
            return(a.rva);
      }
      return(0);
   }

   long GetNextData(long rva){
      struct address a;
   
      d_keyfind(ADDRESS_RVA, &rva);
      while (db_status == S_OKAY){
         d_keynext(ADDRESS_RVA);
         d_recread(&a);
         if (a.flags & ADDR_DATA) 
            return(a.rva);
      }
      return(0);
   }

   int GetCodeRep(char *buf, char *fmt, long rva) {
      struct address a;
   
      if (d_keyfind(CODE_RVA, &rva) != S_OKAY) 
         return(SetLastError(4110));
      d_recread(&a);
      return(asmsprintf(buf, fmt, &a));
   }

   int GetMnemonic(long rva, char *buf) {
      struct code c;
   
      if (d_keyfind(CODE_RVA, &rva) != S_OKAY) 
         return(SetLastError(4110));
      d_recread(&c);
      strcpy(buf, c.mnemonic);
      return(strlen(buf));
   }

   int GetSrc(long rva, char *buf) {
      struct code c;
   
      if (d_keyfind(CODE_RVA, &rva) != S_OKAY) 
         return(SetLastError(4110));
      d_recread(&c);
      strcpy(buf, c.src);
      return(strlen(buf));
   }

   int GetDest(long rva, char *buf) {
      struct code c;
   
      if (d_keyfind(CODE_RVA, &rva) != S_OKAY) 
         return(SetLastError(4110));
      d_recread(&c);
      strcpy(buf, c.dest);
      return(strlen(buf));
   }

   int GetAux(long rva, char *buf) {
      struct code c;
   
      if (d_keyfind(CODE_RVA, &rva) != S_OKAY) 
         return(SetLastError(4110));
      d_recread(&c);
      strcpy(buf, c.aux);
      return(strlen(buf));
   }

   int GetMnemType(long rva) {
      struct code c;
   
      if (d_keyfind(CODE_RVA, &rva) != S_OKAY) 
         return(SetLastError(4110));
      d_recread(&c);
      return(c.mnemType);
   }

   int GetSrcType(long rva) {
      struct code c;
   
      if (d_keyfind(CODE_RVA, &rva) != S_OKAY) 
         return(SetLastError(4110));
      d_recread(&c);
      return(c.srcType);
   }

   int GetDestType(long rva) {
      struct code c;
   
      if (d_keyfind(CODE_RVA, &rva) != S_OKAY) 
         return(SetLastError(4110));
      d_recread(&c);
      return(c.destType);
   }

   int GetAuxType(long rva) {
      struct code c;
   
      if (d_keyfind(CODE_RVA, &rva) != S_OKAY) 
         return(SetLastError(4110));
      d_recread(&c);
      return(c.auxType);
   }

	int SetMnemonic(long rva, char *mnemonic){
		return(1);
	}
	int SetDest(long rva, char *dest){
		return(1);
	}
	int SetSrc(long rva, char *src){
		return(1);
	}
	int SetAux(long rva, char *aux){
		return(1);
	}