/*
  libx2bc.h
  
  Main header for x2bc library
  
  Author: doubleshadow, based on work of CheckerTwo
  
*/

#ifndef LIB_X2_BC_INCLUDED
#define LIB_X2_BC_INCLUDED

#define X2BC_EXPORT
#define X2BCAPI __stdcall

// input file type (for BOD compilation)
#define X2BC_BOD_CUT 1
#define X2BC_BOD_BOB 2

// options (for SetOption)
#define X2BC_O_FRAME_WARNINGS 1
#define X2BC_O_XTRA_PNT_INFO  2
#define X2BC_O_XTRA_X3_INFO   3
//#define X2BC_O_X3BOB          4

// Error severity
#define X2BC_SEV_SUCCESS                0
#define X2BC_SEV_ERROR                  1
#define X2BC_SEV_WARNING                2

// Error facilities
#define X2BC_FACILITY_SETTINGS          1
#define X2BC_FACILITY_BOBLOADER         2
#define X2BC_FACILITY_STATLOADER        3
#define X2BC_FACILITY_COMPILER          4
#define X2BC_FACILITY_DLL               5

// Error codes
#define X2BC_E_OK                       0
#define X2BC_E_Error                    1
#define X2BC_E_BadConstantDeclaration   2
#define X2BC_E_BadFormatDeclaration     3
#define X2BC_E_SectionEmpty             4
#define X2BC_E_LineIgnored              5
#define X2BC_E_ConstantAlwaysZero       6

#define X2BC_E_BadHeader                7
#define X2BC_E_BadEndHeader             8
#define X2BC_E_MoreData                 9
#define X2BC_E_NotEnoughData           10
#define X2BC_E_ChildrenCountIncorrect  11
#define X2BC_E_NoStatFormat            12
#define X2BC_E_FormatUserWarning       13
#define X2BC_E_UnkPointHeader          14
#define X2BC_E_PointNotFound           15
#define X2BC_E_BadVersion              16

#define X2BC_E_FileCannotOpen          17
#define X2BC_E_BadFlags                18

#define X2BC_SEVERITY(code) (code >> 24)
#define X2BC_FACILITY(code) ((code >> 16) & 0xff)

#define X2BC_FAILED(code) ((X2BC_SEVERITY(code) & X2BC_SEV_ERROR) > 0)
#define X2BC_WARNING(code) ((X2BC_SEVERITY(code) & X2BC_SEV_WARNING) > 0)
#define X2BC_SUCCEEDED(code) ((X2BC_SEVERITY(code) & X2BC_SEV_SUCCESS ) == 0)

struct X2BC_ERROR
{
  int code;
  int line;
  int col;
  char text[255];
};

#ifdef __cplusplus
  extern "C" {
#endif

/************************************************
 * X2BC_LoadSettings
 *
 * Loads ini file with settings
 *
 * in: pszINIFileName - ini file to load
 * ret: zero on failure, nonzero otherwise
 ************************************************/
X2BC_EXPORT int X2BCAPI X2BC_LoadSettings(const char *pszINIFileName);

/************************************************
 * X2BC_BOB2BOD
 *
 * Converts binary BOB file to text BOD file
 *
 * in: pszFileName - input bob file, pszOutFileName - output bod file
 * ret: zero on failure, nonzero otherwise
 ************************************************/
X2BC_EXPORT int X2BCAPI X2BC_BOB2BOD(const char *pszFileName,
const char *pszOutFileName);

/************************************************
 * X2BC_BOD2BOB
 *
 * Converts text BOD file to binary BOB file
 *
 * in: pszBuffer - buffer containning the bod data. It must be zero terminated!,
 *     nSize size of buffer (excluding the terminating zero), pszOutFileName -
 *     output bob file, nBODType - type of input data (X2BC_BOD_CUT,
 *     X2BC_BOD_BOB)
 * ret: zero on failure, nonzero otherwise
 ************************************************/
X2BC_EXPORT int X2BCAPI X2BC_BOD2BOB(char *pszBuffer, int nSize,
const char *pszOutFileName, int nBODType);

/************************************************
 * X2BC_GetError
 *
 * retrieves error from the error stack
 *
 * in: pointer to error structure
 * ret: zero if no error was retrieved, non zero otherwise
 ************************************************/
X2BC_EXPORT int X2BCAPI X2BC_GetError(X2BC_ERROR *pError);

/************************************************
 * X2BC_SetOption
 *
 * set option for compiler/decompiler
 *
 * in: nOption - what to set (use X2BC_O_* settings)
 * ret: zero if no error was retrieved, non zero otherwise
 ************************************************/
X2BC_EXPORT int X2BCAPI X2BC_SetOption(int nOption, const char *pszValue);

/************************************************
 * X2BC_GetVersion
 *
 * returns library version
 *
 * in: nBuffLen - length of in buffer
 * out: pszBuffer - pointer to buffer to recieve the version string
 * ret: number of copied bytes
 ************************************************/
X2BC_EXPORT int X2BCAPI X2BC_GetVersion(char *pszBuffer, int nBuffLen);

#ifdef __cplusplus
  }
#endif

#endif // !defined(LIB_X2_BC_INCLUDED)
