/*
 *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 *  SCR_Pars.h
 *  Scripts, Beaudet Christophe
 *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 */
 
#ifndef __SCR_Pars_h__Types
#define __SCR_Pars_h__Types
 
#ifndef __Only_Types__
#define __SCR_Pars_h__Undef
#define __Only_Types__
#endif /* !__Only_Types__ */
 
/*
 *=================================================================================================
 *  Includes.
 *=================================================================================================
 */
 
#include "SCR_Cxt.h"
 
#ifdef __SCR_Pars_h__Undef
#undef __Only_Types__
#undef __SCR_Pars_h__Undef
#endif /* __SCR_Pars_h__Undef */
 
/*
 *=================================================================================================
 *  Constants.
 *=================================================================================================
 */
 
/*
 *  To export code.
 */
#undef CPA_EXPORT
#if defined(CPA_WANTS_IMPORT)
#define CPA_EXPORT __declspec(dllimport)
#elif defined(CPA_WANTS_EXPORT)
#define CPA_EXPORT __declspec(dllexport)
#else /* CPA_WANTS_IMPORT */
#define CPA_EXPORT
#endif /* CPA_WANTS_IMPORT */
 
/*
 *=================================================================================================
 *  Types.
 *=================================================================================================
 */
 
/*
 *  Structure that describes file parsing infos.
 */
typedef struct SCR_tdst_Pars_Infos_
{
    struct SCR_tdst_Cxt_Position_   stPosition;         /* Last position of parser */
    unsigned short                  uwDynamicFlags;     /* Flags depending on directives */
} SCR_tdst_Pars_Infos;
 
#endif /* __SCR_Pars_h__Types */
 
/*
 *=================================================================================================
 *  Macros.
 *=================================================================================================
 */
 
/*
 *  To get a character from a file.
 *  _File   :   File to read from.
 *              If d_stCurPage is NULL, then file is a real one (p_xHandle correct).
 *              Else, file is took from memory.
 *  _Read   :   To get read character.
 */
#define SCR_M_Pars_ReadChar(_File, _Read)\
{\
    SCR_M_Dbg_Assert_P((_File) != NULL);\
    /*
     *  Update gs_ui_Pars_NbRead.
     */\
    SCR_g_ui_Pars_NbRead++;\
    /*
     *  Normal read from file if d_stFirstPage is NULL.
     */\
    if((_File)->d_stFirstPage == NULL)\
	{\
		SCR_M_fgetc(_File, _Read);\
	}\
    else\
    {\
        /*
         *  Read from a special save file if not.
         *  Pass to next character.
         */\
        _Read = (_File)->d_stCurPage->d_cBuffer[(_File)->iCurPosInPage];\
        if(_Read == 0)\
            _Read = EOF;\
        fn_v_Page_ToNextChar(_File);\
    }\
}
 
/*
 *  Is a character is a space ?
 *  _Char   :   Character to test.
 */
#define SCR_M_Pars_IsSpace(_iChar) ((_iChar == ' ') || (_iChar == '\t') || (_iChar == '\r'))
 
/*
 *  To obtain next character except blanks.
 *  _File   :   File to read characters
 *  _Read   :   To receive next character
 */
#define SCR_M_Pars_GetNextNonSpaceChar(_File, _Read)\
{\
    SCR_M_Dbg_Assert_P((_File) != NULL);\
    do\
    {\
        SCR_M_Pars_ReadChar(_File, _Read);\
    } while(SCR_M_Pars_IsSpace(_Read));\
}
 
/*
 *  Zap blanks if _Read is a blank character.
 *  _File   :   File to read characters
 *  _Read   :   To receive next character. Must be correct when call.
 */
#define SCR_M_Pars_ZapIfSpace(_File, _Read)\
{\
    SCR_M_Dbg_Assert_P((_File) != NULL);\
    while(SCR_M_Pars_IsSpace(iRead))\
    {\
        SCR_M_Pars_ReadChar(_File, _Read);\
    };\
}
 
/*
 *	A macro to free parameters.
 */
#define SCR_M_Pars_FreeParameters(_ap_szParameters)\
{\
    SCR_M_Dbg_Assert_P(_ap_szParameters != NULL);\
	if(_ap_szParameters[0])\
		gs_p_cNewFreePlace = _ap_szParameters[0];\
}
 
/*
 *	Basic functions.
 */
#define strstri(a, b) SCR_strstri(a, b)
 
/*
 *	Macros to determin if a given character is valid.
 */
#define SCR_M_Pars_CharValidForWord(_Char)\
	(gs_a256_cIsCharValidForWord[_Char])
 
/*
 *=================================================================================================
 *  Global variables.
 *=================================================================================================
 */
 
#if !defined(__SCR_Pars_h__Globals) && !defined(__Only_Types__)
#define __SCR_Pars_h__Globals
 
CPA_EXPORT extern unsigned int	SCR_g_ui_Pars_NbRead;
CPA_EXPORT extern char			gs_a256_cIsCharValidForWord[256];
extern char						*gs_p_cNewFreePlace;
 
#endif /* !__SCR_Pars_h__Globals && !__Only_Types__ */
 
/*
 *=================================================================================================
 *  Protos.
 *=================================================================================================
 */
 
#if !defined(__SCR_Pars_h__Protos) && !defined(__Only_Types__)
#define __SCR_Pars_h__Protos
 
extern int          fn_i_Pars_Word(struct SCR_tdst_File_Description_ *, char *);
extern int          fn_i_Pars_SectionName(struct SCR_tdst_File_Description_ *, char *, char *);
extern int          fn_i_Pars_FormatArray(struct SCR_tdst_File_Description_ *, char **);
extern int          fn_i_Pars_FormatScanf(struct SCR_tdst_File_Description_ *, char **);
extern int          fn_i_Pars_Format(struct SCR_tdst_File_Description_ *, char *);
extern int          fn_i_Pars_Parameters(struct SCR_tdst_File_Description_ *, char *);
extern int          fn_i_Pars_FormatParameters(struct SCR_tdst_File_Description_ *, int, char *, char *);
extern int          fn_i_Pars_Line(struct SCR_tdst_File_Description_ *, char *, char *, char *, char *, SCR_tde_Cxt_ParseType *, unsigned int *);
 
extern void         fn_v_Pars_ConvertNormalParameters(char *, char *[]);
extern void         fn_v_Pars_ConvertReferencesParameters(char *, char *, char *[]);
extern void         fn_v_Pars_ConvertArrayParameters(char *, char *, char *[]);
extern void         fn_v_Pars_ConvertScanfParameters(char *, char *, char *[]);
extern void         fn_v_Pars_ConvertParameters(char *, char *, char *[]);
 
extern char			*SCR_strstri(char *, char *);
extern int			SCR_strcmpi(char *, char *);
 
#endif /* !__SCR_Pars_h__Protos && !__Only_Types__ */
