#if defined(_AI_LIB_)
	#include "AIUseCPA.h"
	
	#include "specif/AIOption.h"
	#include "AIMacros.h"	
	#include "AI_Erm.h"
	
	#include "Convert.h"
	#include "EnumAct.h"
 
	#if defined(OPTIMIZED_COMMAND) 
		#include "ProtAct.h"
	#endif
#else
	#include <string.h>
	#include "specif/AIOption.h"
	
	#include "ConvCst.h"
	#include "EnumAct.h"
	#include "ConvAct.h"
#endif /* _AI_LIB_							*/
 
#define C_MAX_SIZE_META_ACTION_SCRIPT_NAME 37
#define C_MAX_SIZE_META_ACTION_EDITOR_NAME 80
#define C_MAX_NB_META_ACTION_PARAM		   C_MAX_NB_PARAM
 
typedef struct tdstMetaActionEntry_
{
#if defined(ACTIVE_EDITOR)
    /* metaaction string used in editor*/
    char szMetaActionEditorName[C_MAX_SIZE_META_ACTION_EDITOR_NAME+1]; 
    char szMetaActionEditorName_En[C_MAX_SIZE_META_ACTION_EDITOR_NAME+1]; 
#endif /* ACTIVE_EDITOR*/
#if defined (AI_USE_SCRIPT)
    /* metaaction string used in script*/
    char szMetaActionScriptName[C_MAX_SIZE_META_ACTION_SCRIPT_NAME+1];
#endif /* AI_USE_SCRIPT */
#if defined(_AI_LIB_)
	/* pointer on metaaction INIT function*/
    tdp_fn_p_stMetaActionInitFunctionPtr p_fn_p_stMetaActionInitFunction;
    /* pointer on metaaction NEXT function*/
    tdp_fn_ucMetaActionFunctionPtr p_fn_ucMetaActionFunction;
#endif /* _AI_LIB_*/
 
    /* list of metaaction parameters (taken from szAutorizedTypeParam)*/
    char szMetaActionTypeParam[C_MAX_NB_META_ACTION_PARAM+1];
} tdstMetaActionEntry;
 
tdstMetaActionEntry a_stMetaActionTable[eNbMetaAction]
#if defined(OPTIMIZED_COMMAND)
=
{
/* Procedure initialisation*/
#if defined (AI_USE_SCRIPT)
#if defined(_AI_LIB_)
	#if defined(ACTIVE_EDITOR)
		#define M_DEFINE_METAACTION(a,b,english,c,d,e,f) { b,english,c,d,e,f },
	#else
		#define M_DEFINE_METAACTION(a,b,english,c,d,e,f) { c,d,e,f },
	#endif /* ACTIVE_EDITOR*/
#else
	#if defined(ACTIVE_EDITOR)
		#define M_DEFINE_METAACTION(a,b,english,c,d,e,f) { b,english,c,f },
	#else
		#define M_DEFINE_METAACTION(a,b,english,c,d,e,f) { c,f },
	#endif /* ACTIVE_EDITOR*/
#endif /* _AI_LIB_*/
#else  /* AI_USE_SCRIPT */
#if defined(_AI_LIB_)
	#if defined(ACTIVE_EDITOR)
		#define M_DEFINE_METAACTION(a,b,english,c,d,e,f) { b,english,d,e,f },
	#else
		#define M_DEFINE_METAACTION(a,b,english,c,d,e,f) { d,e,f },
	#endif /* ACTIVE_EDITOR*/
#else
	#if defined(ACTIVE_EDITOR)
		#define M_DEFINE_METAACTION(a,b,english,c,d,e,f) { b,english,f },
	#else
		#define M_DEFINE_METAACTION(a,b,english,c,d,e,f) { f },
	#endif /* ACTIVE_EDITOR*/
#endif /* _AI_LIB_*/
#endif /* AI_USE_SCRIPT */
	#include "DefAct.h" 
	#undef M_DEFINE_METAACTION
}
#endif /* OPTIMIZED_COMMAND*/
;
 
 
#ifndef _FIRE_DEADCODE_U64_ /* Added by RUC */
enum tdeMetaActionId_ fn_eGetNbMetaAction()
{
  return(eNbMetaAction);
}
#endif /* _FIRE_DEADCODE_U64_ */ /* Added by RUC */
 
 
char *szGetMetaActionTypeInParamFromId(enum tdeMetaActionId_ eMetaActionId)
{
    return( a_stMetaActionTable[eMetaActionId].szMetaActionTypeParam);
}
 
#if defined(ACTIVE_EDITOR)
char *szGetMetaActionTypeOutParamFromId(enum tdeMetaActionId_ eMetaActionId)
{
    eMetaActionId=eMetaActionId; /* for lint*/
    return(USE_NO_PARAM);
}
 
char *szGetMetaActionTypeParamFromId(enum tdeMetaActionId_ eMetaActionId)
{
    return( a_stMetaActionTable[eMetaActionId].szMetaActionTypeParam);
}
 
enum tdeMetaActionId_ fn_eFindMetaActionIdFromEditorName(char *szMetaAction)
{
    short wActionEntry;
    for(wActionEntry=0;wActionEntry<fn_eGetNbMetaAction();wActionEntry++)
    {
        if (!stricmp(a_stMetaActionTable[wActionEntry].szMetaActionEditorName,szMetaAction))
        {
            return((enum tdeMetaActionId_) wActionEntry);
        }
    }
    return(fn_eGetNbMetaAction());
}
 
char *szFindMetaActionEditorNameFromId(enum tdeMetaActionId_ eMetaActionId)
{
    return( a_stMetaActionTable[eMetaActionId].szMetaActionEditorName);
}
#endif /* ACTIVE_EDITOR*/
 
 
 
#if defined (AI_USE_SCRIPT)
char *szFindMetaActionScriptNameFromId(enum tdeMetaActionId_ eMetaActionId)
{
    return( a_stMetaActionTable[eMetaActionId].szMetaActionScriptName);
}
 
enum tdeMetaActionId_ fn_eFindMetaActionIdFromScriptName(char *szMetaAction)
{
    short wActionEntry;
    for(wActionEntry=0;wActionEntry<fn_eGetNbMetaAction();wActionEntry++)
    {
        if (!stricmp(a_stMetaActionTable[wActionEntry].szMetaActionScriptName,szMetaAction))
        {
            return((enum tdeMetaActionId_) wActionEntry);
        }
    }
    return(fn_eGetNbMetaAction());
}
#endif /* AI_USE_SCRIPT */
 
 
 
 
#if defined(_AI_LIB_)
tdp_fn_p_stMetaActionInitFunctionPtr fn_p_fn_pGetMetaActionInitFunctionPtr(enum tdeMetaActionId_ eMetaActionId)
{
  return(a_stMetaActionTable[eMetaActionId].p_fn_p_stMetaActionInitFunction);
}
 
tdp_fn_ucMetaActionFunctionPtr fn_p_fn_pGetMetaActionFunctionPtr(enum tdeMetaActionId_ eMetaActionId)
{
  return(a_stMetaActionTable[eMetaActionId].p_fn_ucMetaActionFunction);
}
#endif /* _AI_LIB_*/
 
/***************************************************************************************/
/* -------------------------*/
/* fn_vDefineMetaActionEntry*/
/* -------------------------*/
/* eMetaActionId : MetaAction identifier*/
/* szMetaActionEditorName : MetaAction string in Editor*/
/* szMetaActionScriptName : MetaAction string in Script*/
/* p_fn_p_stMetaActionInitFunction : function pointer on your INIT function*/
/* p_fn_ucMetaActionFunction : function pointer on your NEXT function*/
/* szMetaActionTypeParam : string of MetaActionParameters (cf szAutorizedTypeParam)*/
/***************************************************************************************/
#if !defined(OPTIMIZED_COMMAND)
#if defined(ACTIVE_EDITOR)
void fn_vDefineMetaActionEntry(enum tdeMetaActionId_ eMetaActionId,char *szMetaActionEditorName,char *szMetaActionEditorName_En,char *szMetaActionScriptName,tdp_fn_p_stMetaActionInitFunctionPtr p_fn_p_stMetaActionInitFunction,tdp_fn_ucMetaActionFunctionPtr p_fn_ucMetaActionFunction,char *szMetaActionTypeParam)				
#else
void fn_vDefineMetaActionEntry(enum tdeMetaActionId_ eMetaActionId,char *szMetaActionScriptName,tdp_fn_p_stMetaActionInitFunctionPtr p_fn_p_stMetaActionInitFunction,tdp_fn_ucMetaActionFunctionPtr p_fn_ucMetaActionFunction,char *szMetaActionTypeParam)				
#endif /* ACTIVE_EDITOR*/
{
    if (
        (eMetaActionId<fn_eGetNbMetaAction())
#if defined(ACTIVE_EDITOR)
        &&(strlen(szMetaActionEditorName)<=C_MAX_SIZE_META_ACTION_EDITOR_NAME)
#endif /* ACTIVE_EDITOR*/
        &&(strlen(szMetaActionScriptName)<=C_MAX_SIZE_META_ACTION_SCRIPT_NAME)
		&&(strlen(szMetaActionTypeParam)<=C_MAX_NB_META_ACTION_PARAM)
        &&(fn_ucCheckTypeParam(szMetaActionTypeParam))
        )
    {
#if defined(ACTIVE_EDITOR)
        strcpy(a_stMetaActionTable[eMetaActionId].szMetaActionEditorName,szMetaActionEditorName);
#endif /* ACTIVE_EDITOR*/
        strcpy(a_stMetaActionTable[eMetaActionId].szMetaActionScriptName,szMetaActionScriptName);
        a_stMetaActionTable[eMetaActionId].p_fn_p_stMetaActionInitFunction=p_fn_p_stMetaActionInitFunction;
        a_stMetaActionTable[eMetaActionId].p_fn_ucMetaActionFunction=p_fn_ucMetaActionFunction;
        strcpy(a_stMetaActionTable[eMetaActionId].szMetaActionTypeParam,szMetaActionTypeParam);
    }
    else
    {
	   char str[C_MAX_LENGTH_STRING];
  	   sprintf(str,"Error while defining %s metaaction in %s\n",a_stMetaActionTable[eMetaActionId].szMetaActionScriptName,__FILE__);
	   M_AIFatalErrorMsg(E_uwAIFatalInvalidAction,str);
    }
}
#endif /* OPTIMIZED_COMMAND*/
 
#if !defined(OPTIMIZED_COMMAND)
#if defined(__DEBUG_AI__)
void fn_vInitMetaActionTable(tdp_fn_p_stMetaActionInitFunctionPtr fn_p_stDefaultActionInitFunctionPointer,tdp_fn_ucMetaActionFunctionPtr fn_ucDefaultActionFunctionPointer)
{
   short wActionEntry;
   for(wActionEntry=0;wActionEntry<fn_eGetNbMetaAction();wActionEntry++)
   {
       fn_vDefineMetaActionEntry(M_METAACTION_ENTRY((enum tdeMetaActionId_) wActionEntry,"","","",fn_p_stDefaultActionInitFunctionPointer,fn_ucDefaultActionFunctionPointer,USE_NO_PARAM));
   }
}
 
void fn_vCheckMetaActionTable(tdp_fn_p_stMetaActionInitFunctionPtr fn_p_stDefaultActionInitFunctionPointer,tdp_fn_ucMetaActionFunctionPtr fn_ucDefaultActionFunctionPointer)
{
  short wActionEntry;
  char str[C_MAX_LENGTH_STRING];
  size_t lLen;
  size_t lMaxLengthScriptName=0;
#if defined(ACTIVE_EDITOR)
  size_t lMaxLengthEditorName=0;
#endif /* ACTIVE_EDITOR*/
  size_t lMaxLengthParam=0;
   for(wActionEntry=0;wActionEntry<fn_eGetNbMetaAction();wActionEntry++)
  {
	 fn_p_stDefaultActionInitFunctionPointer=fn_p_stDefaultActionInitFunctionPointer;
     if (  /*(fn_p_fn_pGetMetaActionInitFunctionPtr((enum tdeMetaActionId_) wActionEntry)==fn_p_stDefaultActionInitFunctionPointer) ||*/
		   (fn_p_fn_pGetMetaActionFunctionPtr((enum tdeMetaActionId_) wActionEntry)==fn_ucDefaultActionFunctionPointer)
		)
	 {
  	   sprintf(str,"Error while defining %s metaaction in %s\n",a_stMetaActionTable[wActionEntry].szMetaActionScriptName,__FILE__);
	   M_AIFatalErrorMsg(E_uwAIFatalInvalidAction,str);
	 }
	 if ((lLen=strlen(a_stMetaActionTable[wActionEntry].szMetaActionScriptName))>lMaxLengthScriptName)
	 {
	   lMaxLengthScriptName=lLen;
	 }
#if defined(ACTIVE_EDITOR)
	 if ((lLen=strlen(a_stMetaActionTable[wActionEntry].szMetaActionEditorName))>lMaxLengthEditorName)
	 {
	   lMaxLengthEditorName=lLen;
	 }
#endif /* ACTIVE_EDITOR*/
	 if ((lLen=strlen(a_stMetaActionTable[wActionEntry].szMetaActionTypeParam))>lMaxLengthParam)
	 {
        lMaxLengthParam=lLen;
	 }
  }	
#if !defined(U64)
  {
	if (lMaxLengthScriptName<C_MAX_SIZE_META_ACTION_SCRIPT_NAME)
	{
		sprintf(str,"*** AI : You should reduce C_MAX_SIZE_META_ACTION_SCRIPT_NAME in %s to %d\n",__FILE__,lMaxLengthScriptName);
		OutputDebugString(str);
	}
#if defined(ACTIVE_EDITOR)
	if (lMaxLengthEditorName<C_MAX_SIZE_META_ACTION_EDITOR_NAME)
	{
		sprintf(str,"*** AI : You should reduce C_MAX_SIZE_META_ACTION_EDITOR_NAME in %s to %d\n",__FILE__,lMaxLengthEditorName);
		OutputDebugString(str);
	}
#endif /* ACTIVE_EDITOR*/
	if (lMaxLengthParam<C_MAX_NB_META_ACTION_PARAM)
	{
		sprintf(str,"*** AI : You should reduce C_MAX_NB_META_ACTION_PARAM in %s to %d\n",__FILE__,lMaxLengthParam);
		OutputDebugString(str);
	}
  }
#endif /* U64*/
}
#endif /* __DEBUG_AI__*/
#endif /* OPTIMIZED_COMMAND*/
