#ifndef DRS_UTILS_H
#define DRS_UTILS_H

#include <windows.h>

#include <stdlib.h>
#include <ctype.h>
#undef isspace

#include <string.h>

#include "base/at_defs.h"

int32 UTL_GetPrivateProfileInt( byte *section, byte *key, int32 lInitVal, byte *fp)
{
  //This routine emulates windows' GetPrivateProfileInt() for Long values.
  byte buf[64];
  GetPrivateProfileStringA( (LPCSTR) section, (LPCSTR) key, "", (LPSTR) buf, 64, (LPCSTR) fp);
  return( buf[0] == 0 ? lInitVal : strtol( (const char*) buf, NULL, 10));
}
uint32 UTL_GetPrivateProfileInt( byte *section, byte *key, uint32 lInitVal, byte *fp)
{
  //This routine emulates windows' GetPrivateProfileInt() for Unsigned Long values.
  byte buf[64];
  GetPrivateProfileStringA( (LPCSTR) section, (LPCSTR) key, "", (LPSTR) buf, 64, (LPCSTR) fp);
  return( buf[0] == 0 ? lInitVal : strtoul( (const char*) buf, NULL, 10));
}
void UTL_WritePrivateProfileInt( byte *section, byte *key, uint32 lInitVal, byte *fp)
{
  byte sBuf[32];
  ultoa( lInitVal, (char*) sBuf, 10);
  WritePrivateProfileStringA( (LPCSTR) section, (LPCSTR) key, (LPCSTR) sBuf, (LPCSTR) fp);
}
void UTL_WritePrivateProfileInt( byte *section, byte *key, int32 lInitVal, byte *fp)
{
  byte sBuf[32];
  ltoa( lInitVal, (char*) sBuf, 10);
  WritePrivateProfileStringA( (LPCSTR) section, (LPCSTR) key, (LPCSTR) sBuf, (LPCSTR) fp);
}
void UTL_WritePrivateProfileInt( byte *section, byte *key, int16 lInitVal, byte *fp)
{
  byte sBuf[32];
  itoa( lInitVal, (char*) sBuf, 10);
  WritePrivateProfileStringA( (LPCSTR) section, (LPCSTR) key, (LPCSTR) sBuf, (LPCSTR) fp);
}
void UTL_WritePrivateProfileInt( byte *section, byte *key, uint16 lInitVal, byte *fp)
{
  byte sBuf[32];
  itoa( lInitVal, (char*) sBuf, 10);
  WritePrivateProfileStringA( (LPCSTR) section, (LPCSTR) key, (LPCSTR) sBuf, (LPCSTR) fp);
}


byte * UTL_StringClean( byte *s)
{
  for( uint i = strlen((const char*)s); i > 0; i--)
    if( isspace((int) s[i-1])) 
      s[i-1] = 0;
    else break;
  return(s);
}

#endif
