#if defined(_AI_LIB_)
	#include "AIUseCPA.h"
	
	#include "specif/AIOption.h"
 
	#include "AIMacros.h"	
	#include "AI_Erm.h"
	
	#include "Convert.h"
	#include "EnumKey.h"
 
	#if defined(OPTIMIZED_COMMAND) 
		#include "ProtKey.h"
	#endif
#else
	#include <string.h>
	#include "specif/AIOption.h"
	
	#include "ConvCst.h"
	#include "EnumKey.h"
	#include "ConvKey.h"
#endif /* _AI_LIB_*/
 
 
#define C_MAX_SIZE_KEYWORD_EDITOR_NAME 17
#define C_MAX_SIZE_KEYWORD_SCRIPT_NAME 14
#define C_MAX_KEYWORD_NB_IN_PARAM  3
#define C_MAX_KEYWORD_NB_OUT_PARAM 1
 
typedef struct tdstKeyWordEntry_
{
 
#if defined(ACTIVE_EDITOR)
    /* KeyWord string used in editor*/
    char szKeyWordEditorName[C_MAX_SIZE_KEYWORD_EDITOR_NAME+1]; 
    char szKeyWordEditorName_En[C_MAX_SIZE_KEYWORD_EDITOR_NAME+1]; 
#endif /* ACTIVE_EDITOR*/
#if defined (AI_USE_SCRIPT)
	/* KeyWord string used in script*/
    char szKeyWordScriptName[C_MAX_SIZE_KEYWORD_SCRIPT_NAME+1];
#endif /* AI_USE_SCRIPT */
#if defined(_AI_LIB_)
	/* pointer on KeyWord function*/
    tdp_fn_p_stKeyWordFunctionPtr p_fn_p_stKeyWordFunction;
#endif /* _AI_LIB_*/
#if defined (AI_USE_SCRIPT)
	/* list of KeyWord parameters (taken from szAutorizedTypeParam) in parameter*/
	char szKeyWordTypeInParam[C_MAX_KEYWORD_NB_IN_PARAM+1];
    /* list of KeyWord parameters (taken from szAutorizedTypeParam) out parameter*/
	char szKeyWordTypeOutParam[C_MAX_KEYWORD_NB_OUT_PARAM+1];
#endif /* AI_USE_SCRIPT */
} tdstKeyWordEntry;
 
tdstKeyWordEntry a_stKeyWordTable[eNbKeyWord]
#if defined(OPTIMIZED_COMMAND)
=
{
#if defined (AI_USE_SCRIPT)
/* KeyWords initialisation*/
#if defined(_AI_LIB_)
	#if defined(ACTIVE_EDITOR)
		#define M_DEFINE_KEYWORD(a,b,english,c,d,e,f) { b,english,c,d,e,f },
	#else
		#define M_DEFINE_KEYWORD(a,b,english,c,d,e,f) { c,d,e,f },
    #endif /* ACTIVE_EDITOR*/
#else
	#if defined(ACTIVE_EDITOR)
		#define M_DEFINE_KEYWORD(a,b,english,c,d,e,f) { b,english,c,e,f },
	#else
	    #define M_DEFINE_KEYWORD(a,b,english,c,d,e,f) { c,e,f },
	#endif
#endif /* _AI_LIB_ */
    #include "DefKey.h" 
	#undef M_DEFINE_KEYWORD
}
#else /* AI_USE_SCRIPT */
/* KeyWords initialisation*/
#if defined(_AI_LIB_)
	#if defined(ACTIVE_EDITOR)
		#define M_DEFINE_KEYWORD(a,b,english,c,d,e,f) { b,english,d },
	#else
		#define M_DEFINE_KEYWORD(a,b,english,c,d,e,f) { d },
    #endif /* ACTIVE_EDITOR*/
#else
	#if defined(ACTIVE_EDITOR)
		#define M_DEFINE_KEYWORD(a,b,english,c,d,e,f) { b,english },
	#else
	    #define M_DEFINE_KEYWORD(a,b,english,c,d,e,f) {  },
	#endif
#endif /* _AI_LIB_ */
    #include "DefKey.h" 
	#undef M_DEFINE_KEYWORD
}
#endif /* AI_USE_SCRIPT */
#endif /* OPTIMIZED_COMMAND*/
;
 
#if defined(_AI_LIB_)
tdp_fn_p_stKeyWordFunctionPtr fn_p_fn_pGetKeyWordFunctionPtr(enum tdeKeyWordId_ eKeyWordId)
{
  return(a_stKeyWordTable[eKeyWordId].p_fn_p_stKeyWordFunction);
}
#endif
 
 
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
enum tdeKeyWordId_ fn_eGetNbKeyWord()
{
  return(eNbKeyWord);
}
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
 
 
#if defined(ACTIVE_EDITOR)
char *szGetKeyWordTypeInParamFromId(enum tdeKeyWordId_ eKeyWordId)
{
    return(a_stKeyWordTable[eKeyWordId].szKeyWordTypeInParam);
}
 
char *szGetKeyWordTypeOutParamFromId(enum tdeKeyWordId_ eKeyWordId)
{
    return(a_stKeyWordTable[eKeyWordId].szKeyWordTypeOutParam);
}
 
/* modif : enum tdeKeyWordId_ fn_eFindKeyWordIdFromEditorName(char *szKeyWord, int langage)*/
enum tdeKeyWordId_ fn_eFindKeyWordIdFromEditorName(char *szKeyWord)
{
    short wKeyWordEntry;
    for(wKeyWordEntry=0;wKeyWordEntry<fn_eGetNbKeyWord();wKeyWordEntry++)
    {
        if (!stricmp(a_stKeyWordTable[wKeyWordEntry].szKeyWordEditorName,szKeyWord))
        {
			return((enum tdeKeyWordId_) wKeyWordEntry);
        }
    }
    return(fn_eGetNbKeyWord());
}
 
char *szFindKeyWordScriptNameFromId(enum tdeKeyWordId_ eKeyWordId)
{
    return(a_stKeyWordTable[eKeyWordId].szKeyWordScriptName);
}
/* modif : char *szFindKeyWordEditorNameFromId(enum tdeKeyWordId_ eKeyWordId, int langage)*/
char *szFindKeyWordEditorNameFromId(enum tdeKeyWordId_ eKeyWordId)
{
    return(a_stKeyWordTable[eKeyWordId].szKeyWordEditorName);
}
#endif /* ACTIVE_EDITOR*/
 
#if defined (AI_USE_SCRIPT)
enum tdeKeyWordId_ fn_eFindKeyWordIdFromScriptName(char *szKeyWord)
{
    short wKeyWordEntry;
    for(wKeyWordEntry=0;wKeyWordEntry<fn_eGetNbKeyWord();wKeyWordEntry++)
    {
        if (!stricmp(a_stKeyWordTable[wKeyWordEntry].szKeyWordScriptName,szKeyWord))
        {
			return((enum tdeKeyWordId_) wKeyWordEntry);
        }
    }
    return(fn_eGetNbKeyWord());
}
#endif /* AI_USE_SCRIPT */
 
#if !defined(OPTIMIZED_COMMAND)
#if defined(ACTIVE_EDITOR)
void fn_vDefineKeyWordEntry(enum tdeKeyWordId_ eKeyWordId,char *szKeyWordEditorName,char *szKeyWordEditorName_En,char *szKeyWordScriptName,tdp_fn_p_stKeyWordFunctionPtr p_fn_p_stKeyWordFunction,char *szKeyWordTypeInParam,char *szKeyWordTypeOutParam)				
#else
void fn_vDefineKeyWordEntry(enum tdeKeyWordId_ eKeyWordId,char *szKeyWordScriptName,tdp_fn_p_stKeyWordFunctionPtr p_fn_p_stKeyWordFunction,char *szKeyWordTypeInParam,char *szKeyWordTypeOutParam)				
#endif /* ACTIVE_EDITOR*/
{
    if (
        (eKeyWordId<fn_eGetNbKeyWord())
#if defined(ACTIVE_EDITOR)
        &&(strlen(szKeyWordEditorName)<=C_MAX_SIZE_KEYWORD_EDITOR_NAME)
       /* &&(strlen(szKeyWordEditorName_En)<=C_MAX_SIZE_KEYWORD_EDITOR_NAME)*/
#endif /* ACTIVE_EDITOR*/
        &&(strlen(szKeyWordScriptName)<=C_MAX_SIZE_KEYWORD_SCRIPT_NAME)
		&&(fn_ucCheckTypeParam(szKeyWordTypeInParam))
		&&(strlen(szKeyWordTypeInParam)<=C_MAX_KEYWORD_NB_IN_PARAM)
        &&(fn_ucCheckTypeParam(szKeyWordTypeOutParam))
		&&(strlen(szKeyWordTypeOutParam)<=C_MAX_KEYWORD_NB_OUT_PARAM)
        )
    {
#if defined(ACTIVE_EDITOR)
        strcpy(a_stKeyWordTable[eKeyWordId].szKeyWordEditorName,szKeyWordEditorName);
       /* strcpy(a_stKeyWordTable[eKeyWordId].szKeyWordEditorName_En,szKeyWordEditorName_En);*/
#endif /* ACTIVE_EDITOR*/
        strcpy(a_stKeyWordTable[eKeyWordId].szKeyWordScriptName,szKeyWordScriptName);
        a_stKeyWordTable[eKeyWordId].p_fn_p_stKeyWordFunction=p_fn_p_stKeyWordFunction;
        strcpy(a_stKeyWordTable[eKeyWordId].szKeyWordTypeInParam,szKeyWordTypeInParam);
        strcpy(a_stKeyWordTable[eKeyWordId].szKeyWordTypeOutParam,szKeyWordTypeOutParam);
    }
    else
    {
		char str[C_MAX_LENGTH_STRING];
		sprintf(str,"Error while defining %s keyword in %s\n",szKeyWordScriptName,__FILE__);
        M_AIFatalErrorMsg(E_uwAIFatalUnknownKeyWord,str);
    }
}
#endif /* OPTIMIZED_COMMAND*/
 
#if !defined(OPTIMIZED_COMMAND)
#if defined(__DEBUG_AI__)
void fn_vInitKeyWordTable(tdp_fn_p_stKeyWordFunctionPtr fn_p_stDefaultKeyWordFunctionPointer)
{
  short wKeyWordEntry;
  for(wKeyWordEntry=0;wKeyWordEntry<fn_eGetNbKeyWord();wKeyWordEntry++)
  {
	fn_vDefineKeyWordEntry(M_KEYWORD_ENTRY((enum tdeKeyWordId_) wKeyWordEntry,"","","",fn_p_stDefaultKeyWordFunctionPointer,USE_NO_PARAM,USE_NO_PARAM));
  }
}
 
void fn_vCheckKeyWordTable(tdp_fn_p_stKeyWordFunctionPtr fn_p_stDefaultKeyWordFunctionPointer)
{
  char str[C_MAX_LENGTH_STRING];
  short wKeyWordEntry;
  size_t lLen;
  size_t lMaxLengthScriptName=0;
#if defined(ACTIVE_EDITOR)
  size_t lMaxLengthEditorName=0;
#endif /* ACTIVE_EDITOR*/
  size_t lMaxLengthInParam=0;
  size_t lMaxLengthOutParam=0;
  for(wKeyWordEntry=0;wKeyWordEntry<fn_eGetNbKeyWord();wKeyWordEntry++)
  {
     if (fn_p_fn_pGetKeyWordFunctionPtr((enum tdeKeyWordId_) wKeyWordEntry)==fn_p_stDefaultKeyWordFunctionPointer)
	 {
	   sprintf(str,"Error while defining %s keyword in %s\n",a_stKeyWordTable[wKeyWordEntry].szKeyWordScriptName,__FILE__);
 	   M_AIFatalErrorMsg(E_uwAIFatalUnknownKeyWord,str);
	 }
	 if ((lLen=strlen(a_stKeyWordTable[wKeyWordEntry].szKeyWordScriptName))>lMaxLengthScriptName)
	 {
	   lMaxLengthScriptName=lLen;
	 }
#if defined(ACTIVE_EDITOR)
	 if ((lLen=strlen(a_stKeyWordTable[wKeyWordEntry].szKeyWordEditorName))>lMaxLengthEditorName)
	 {
	   lMaxLengthEditorName=lLen;
	 }
     /*
     if ((lLen=strlen(a_stKeyWordTable[wKeyWordEntry].szKeyWordEditorName_En))>lMaxLengthEditorName)
	 {
	   lMaxLengthEditorName=lLen;
	 }
     */
 
	 if ((lLen=strlen(a_stKeyWordTable[wKeyWordEntry].szKeyWordTypeInParam))>lMaxLengthInParam)
	 {
        lMaxLengthInParam=lLen;
	 }
	 if ((lLen=strlen(a_stKeyWordTable[wKeyWordEntry].szKeyWordTypeOutParam))>lMaxLengthOutParam)
	 {
        lMaxLengthOutParam=lLen;
	 }
#endif /* ACTIVE_EDITOR*/
  }	
#if !defined(U64)
  {
	if (lMaxLengthScriptName<C_MAX_SIZE_KEYWORD_SCRIPT_NAME)
	{
		sprintf(str,"*** AI : You should reduce C_MAX_SIZE_KEYWORD_SCRIPT_NAME in %s to %d\n",__FILE__,lMaxLengthScriptName);
		OutputDebugString(str);
	}
#if defined(ACTIVE_EDITOR)
	if (lMaxLengthEditorName<C_MAX_SIZE_KEYWORD_EDITOR_NAME)
	{
		sprintf(str,"*** AI : You should reduce C_MAX_SIZE_KEYWORD_EDITOR_NAME in %s to %d\n",__FILE__,lMaxLengthEditorName);
		OutputDebugString(str);
	}
	if (lMaxLengthInParam<C_MAX_KEYWORD_NB_IN_PARAM)
	{
		sprintf(str,"*** AI : You should reduce C_MAX_KEYWORD_NB_IN_PARAM in %s to %d\n",__FILE__,lMaxLengthInParam);
		OutputDebugString(str);
	}
	if (lMaxLengthOutParam<C_MAX_KEYWORD_NB_OUT_PARAM)
	{
		sprintf(str,"*** AI : You should reduce C_MAX_KEYWORD_NB_OUT_PARAM in %s to %d\n",__FILE__,lMaxLengthOutParam);
		OutputDebugString(str);
	}
#endif /* ACTIVE_EDITOR*/
  }
#endif /* U64*/
}
#endif /* __DEBUG_AI__*/
 
#endif /* OPTIMIZED_COMMAND*/
 
