#pragma warning(disable:4032)   /* formal parameter 1 has different type when promoted */
 
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
 
#include "ConvCst.h"
 
#include "EnumKey.h"
#include "ConvKey.h"
 
#include "EnumCond.h"
#include "ConvCond.h"
 
#include "EnumFunc.h"
#include "ConvFunc.h"
 
#include "EnumOper.h"
#include "ConvOper.h"
 
#include "EnumProc.h"
#include "ConvProc.h"
 
#include "EnumAct.h"
#include "ConvAct.h"
 
#include "EnumFild.h"
#include "ConvFild.h"
 
#include "EnumVar.h"
#include "ConvVar.h"
#include "VarType.h"
 
#include "EnumType.h"
 
/* don't delete this function please !
void display()
{
  #define M_DEFINE_KEYWORD(a,b,c,d,e,f) printf("%s (%s,%s)\n"  "\t\"%s\"\n"  "\t\"%s\"\n",#a,e,f,b,c);
  #include "DefKey.h"
  #undef M_DEFINE_KEYWORD
  getch();
  
  #define M_DEFINE_CONDITION(a,b,c,d,e,f) printf("%s (%s)\n"  "\t\"%s\"\n"  "\t\"%s\"\n",#a,e,b,c);
  #include "DefCond.h"
  #undef M_DEFINE_CONDITION
  getch();
 
  #define M_DEFINE_FUNCTION(a,b,c,d,e,f,g) printf("%s (%s,%s)\n"  "\t\"%s\"\n"  "\t\"%s\"\n",#a,e,f,b,c);
  #include "DefFunc.h"
  #undef M_DEFINE_FUNCTION
  getch();
 
  #define M_DEFINE_OPERATOR(a,b,c,d,e,f) printf("%s (%s,%s)\n"  "\t\"%s\"\n"  "\t\"%s\"\n",#a,e,f,b,c);
  #include "DefOper.h"
  #undef M_DEFINE_OPERATOR
  getch();
 
  #define M_DEFINE_PROCEDURE(a,b,c,d,e,f) printf("%s (%s)\n"  "\t\"%s\"\n"  "\t\"%s\"\n",#a,e,b,c);
  #include "DefProc.h"
  #undef M_DEFINE_PROCEDURE
  getch();
 
  #define M_DEFINE_METAACTION(a,b,c,d,e,f) printf("%s (%s)\n"  "\t\"%s\"\n"  "\t\"%s\"\n",#a,f,b,c);
  #include "DefAct.h"
  #undef M_DEFINE_METAACTION
  getch();
 
  #define M_DEFINE_FIELD(a,b,c,d,e,f) printf("%s (%s)\n"  "\t\"%s\"\n"  "\t\"%s\"\n",#a,#d,b,c);
  #include "DefFild.h"
  #undef M_DEFINE_FIELD
  getch();
 
  #define M_DEFINE_DSGVAR_TYPE(a,b,c,d,e,f,g,h,i,j) printf("%s (%s)\n" "\t\"%s\"\n" "\t\"%s\"\n" "\t\"%s\"\n" "\t\"%s\"\n",#a,#d,b,c,#g,#h);
  #include "DefVar.h"
  #undef M_DEFINE_DSGVAR_TYPE
  getch();
 
  #define M_DEFINE_TYPE_INTERPRET(a,b,c,d) printf("%s\n"  "\t%s\n"  "\t%s\n"  "\t%s\n",#a,#b,#c,#d);
  #include "DefType.h"
  #undef M_DEFINE_TYPE_INTERPRET
  getch();
 
  #define M_DEFINE_NODE(a,b,c) printf("\"%s\"\n"  "\t%s\n"  "\t%s\n",a,#b,#c);
  #include "DefNode.h"
  #undef M_DEFINE_NODE
  getch();
 
  #define M_DEFINE_DSGVAR_SAVE_TYPE(a,b,c) printf("\"%s\"\n"  "\"%s\"\n"  "%s\n\n",a,b,#c);
  #include "DefSAI.h"
  #undef M_DEFINE_DSGVAR_SAVE_TYPE
  getch();
 
  #define M_DEFINE_DSGVAR_INIT_TYPE(a,b,c) printf("\"%s\"\n\"%s\"\n%s\n\n",a,b,#c);
  #include "DefOTI.h"
  #undef M_DEFINE_DSGVAR_INIT_TYPE
  getch();
}
*/
 
/* To generate the multilanguage file very soon used by XB */
#define AI_MULTI_LANGUAGE_SCRIPT "AILANGUE.TXT"
 
#define AI_ALL_METAACTIONS		"CreateAllMetaActions"
#define AI_ONE_METAACTION		"CreateOneMetaAction"
 
#define AI_ALL_PROCEDURES		"CreateAllProcedures"
#define AI_ONE_PROCEDURE		"CreateOneProcedure"
 
#define AI_ALL_FUNCTIONS		"CreateAllFunctions"
#define AI_ONE_FUNCTION			"CreateOneFunction"
 
#define AI_ALL_CONDITIONS		"CreateAllConditions"
#define AI_ONE_CONDITION		"CreateOneCondition"
 
#define AI_ALL_KEYWORDS			"CreateAllKeyWords"
#define AI_ONE_KEYWORD			"CreateOneKeyWord"
 
#define AI_ALL_FIELDS			"CreateAllFields"
#define AI_ONE_FIELD			"CreateOneField"
 
#define AI_ALL_DSGVAR_TYPES		"CreateAllDsgVarTypes"
#define AI_ONE_DSGVAR_TYPE		"CreateOneDsgVarType"
 
#define AI_ALL_DSGVAR_INIT_TYPES "CreateAllDsgVarInitTypes"
#define AI_ONE_DSGVAR_INIT_TYPE	 "CreateOneDsgVarInitType"
 
#define AI_ALL_DSGVAR_SAVE_TYPES "CreateAllDsgVarSaveTypes"
#define AI_ONE_DSGVAR_SAVE_TYPE	 "CreateOneDsgVarSaveType"
 
#define AI_FRENCH				"French"
#define AI_ENGLISH				"English"
 
/* C'est pour virer Proc,Cond,Action etc...*/
char *fn_szConvertString(char *str)
{
  char *ptr;
  if ((ptr=strchr(str,'_'))!=NULL)
  {
	ptr++;
  }
  else
  {
    ptr=str;
  }
  return(ptr);
}
 
/* C'est pour Xavier qui veut que les noms des conditions <> <= >= etc soit les mêmes en anglais et en francais !!!*/
char *fn_szConvertConditionString(char *str1,char *str2)
{
	if (!isalpha(str2[0]))
	{
		return(fn_szConvertString(str2));
	}
	return(fn_szConvertString(str1));
}
 
/* C'est pour Xavier qui veut qu'il y ait bijection entre les mots clés et les types des variables designers*/
/* C'est pour Xavier qui veut que les noms des types des variables commencent par une lettre !!!*/
char TempChar[200];
char *fn_szConvertDsgVarString(char *str1,char *str2)
{
	if (!strnicmp(str2,"Type",4))
	{
		sprintf(&TempChar[0],"%sType",str1);
		return(fn_szConvertString(&TempChar[0]));
	}
	else if ((isdigit(str1[0])) || (str1[0]=='_') )
	{
		sprintf(&TempChar[0],"Integer%s",str1);
		return(&TempChar[0]);	
	}
	return(str1);
}
 
void main()
{
	FILE *fp;
 
    if ((fp=fopen(AI_MULTI_LANGUAGE_SCRIPT,"wt"))!=NULL)
	{
		#define  M_BAR "------------------------------------------------------------------"
 
		#define  M_WRITE_ALL_COMMAND_START(title,nb)	fprintf(fp,";%s\n;%s\n;%s\n{%s:(%d)\n",M_BAR,title,M_BAR,title,nb);
		#define  M_WRITE_ALL_COMMAND_END()  			fprintf(fp,"}\n\n");
 
		#define M_WRITE_ONE_COMMAND(title,key,fr,gb) \
			fprintf(fp,"\t{%s:%s\n",title,key); \
			fprintf(fp,"\t\t%s(%s)\n",AI_FRENCH,fr); \
			fprintf(fp,"\t\t%s(%s)\n",AI_ENGLISH,gb); \
			fprintf(fp,"\t}\n\n");
 
		/* MetaActions*/
		#define M_WRITE_ALL_METAACTIONS(nb)			 M_WRITE_ALL_COMMAND_START(AI_ALL_METAACTIONS,nb)	
		#define M_WRITE_ONE_METAACTION(key,fr,gb)	 M_WRITE_ONE_COMMAND(AI_ONE_METAACTION,key,fr,gb)
		
		M_WRITE_ALL_METAACTIONS(fn_eGetNbMetaAction())
		#define M_DEFINE_METAACTION(a,b,c,d,e,f)	 M_WRITE_ONE_METAACTION(c,b,fn_szConvertString(c))
		#include "DefAct.h"
		#undef M_DEFINE_METAACTION
		M_WRITE_ALL_COMMAND_END()
 
		/* Procedures*/
		#define M_WRITE_ALL_PROCEDURES(nb)			 M_WRITE_ALL_COMMAND_START(AI_ALL_PROCEDURES,nb)	
		#define M_WRITE_ONE_PROCEDURE(key,fr,gb)	 M_WRITE_ONE_COMMAND(AI_ONE_PROCEDURE,key,fr,gb)
 
		M_WRITE_ALL_PROCEDURES(fn_eGetNbProcedure())
		#define M_DEFINE_PROCEDURE(a,b,c,d,e,f)		 M_WRITE_ONE_PROCEDURE(c,b,fn_szConvertString(c))
		#include "DefProc.h"
		#undef M_DEFINE_PROCEDURE
		M_WRITE_ALL_COMMAND_END()
 
		/* Functions*/
		#define M_WRITE_ALL_FUNCTIONS(nb)			 M_WRITE_ALL_COMMAND_START(AI_ALL_FUNCTIONS,nb)	
		#define M_WRITE_ONE_FUNCTION(key,fr,gb)	     M_WRITE_ONE_COMMAND(AI_ONE_FUNCTION,key,fr,gb)
 
		M_WRITE_ALL_FUNCTIONS(fn_eGetNbFunc())
		#define M_DEFINE_FUNCTION(a,b,c,d,e,f,g)	 M_WRITE_ONE_FUNCTION(c,b,fn_szConvertString(c))
		#include "DefFunc.h"
		#undef M_DEFINE_FUNCTION
		M_WRITE_ALL_COMMAND_END()
 
		/* Conditions*/
		#define M_WRITE_ALL_CONDITIONS(nb)			 M_WRITE_ALL_COMMAND_START(AI_ALL_CONDITIONS,nb)	
		#define M_WRITE_ONE_CONDITION(key,fr,gb)	 M_WRITE_ONE_COMMAND(AI_ONE_CONDITION,key,fr,gb)
 
		M_WRITE_ALL_CONDITIONS(fn_eGetNbCond())
		#define M_DEFINE_CONDITION(a,b,c,d,e,f)		 M_WRITE_ONE_CONDITION(c,b,fn_szConvertConditionString(c,b))
		#include "DefCond.h"
		#undef M_DEFINE_CONDITION
		M_WRITE_ALL_COMMAND_END()
 
		/* KeyWords*/
		#define M_WRITE_ALL_KEYWORDS(nb)			 M_WRITE_ALL_COMMAND_START(AI_ALL_KEYWORDS,nb)	
		#define M_WRITE_ONE_KEYWORD(key,fr,gb)	     M_WRITE_ONE_COMMAND(AI_ONE_KEYWORD,key,fr,gb)
 
		M_WRITE_ALL_KEYWORDS(fn_eGetNbKeyWord())
		#define M_DEFINE_KEYWORD(a,b,c,d,e,f)		 M_WRITE_ONE_KEYWORD(c,b,fn_szConvertString(c))
		#include "DefKey.h"
		#undef M_DEFINE_KEYWORD
		M_WRITE_ALL_COMMAND_END()
 
		/* Fields*/
		#define M_WRITE_ALL_FIELDS(nb)				 M_WRITE_ALL_COMMAND_START(AI_ALL_FIELDS,nb)	
		#define M_WRITE_ONE_FIELD(key,fr,gb)		 M_WRITE_ONE_COMMAND(AI_ONE_FIELD,key,fr,gb)
 
		M_WRITE_ALL_FIELDS(fn_eGetNbField())
		#define M_DEFINE_FIELD(a,b,c,d,e,f)			 M_WRITE_ONE_FIELD(c,b,fn_szConvertString(c))
		#include "DefFild.h"
		#undef M_DEFINE_FIELD
		M_WRITE_ALL_COMMAND_END()
 
		/* Designer variables*/
		#define M_WRITE_ALL_DSGVAR_TYPES(nb)         M_WRITE_ALL_COMMAND_START(AI_ALL_DSGVAR_TYPES,nb)	
		#define M_WRITE_ONE_DSGVAR_TYPE(key,fr,gb)	 M_WRITE_ONE_COMMAND(AI_ONE_DSGVAR_TYPE,key,fr,gb)
 
		M_WRITE_ALL_DSGVAR_TYPES(fn_eGetNbDsgVarType())
		#define M_DEFINE_DSGVAR_TYPE(a,b,c,d,e,f,g,h,i,j)    M_WRITE_ONE_DSGVAR_TYPE(c,b,fn_szConvertDsgVarString(c,b))
		#include "DefVar.h"
		#undef M_DEFINE_DSGVAR_TYPE
		M_WRITE_ALL_COMMAND_END()
 
		/* SAI Type*/
		#define M_WRITE_ALL_DSGVAR_SAVE_TYPES(nb)        M_WRITE_ALL_COMMAND_START(AI_ALL_DSGVAR_SAVE_TYPES,nb)	
		#define M_WRITE_ONE_DSGVAR_SAVE_TYPE(key,fr,gb)	 M_WRITE_ONE_COMMAND(AI_ONE_DSGVAR_SAVE_TYPE,key,fr,gb)
 
		M_WRITE_ALL_DSGVAR_SAVE_TYPES(fn_ucGetSaveTypeNumber())
		#define M_DEFINE_DSGVAR_SAVE_TYPE(a,b,c)		 M_WRITE_ONE_DSGVAR_SAVE_TYPE(b,a,b)
		#include "DefSAI.h"
		#undef M_DEFINE_DSGVAR_SAVE_TYPE
		M_WRITE_ALL_COMMAND_END()
 
		/* OTI Type*/
		#define M_WRITE_ALL_DSGVAR_INIT_TYPES(nb)        M_WRITE_ALL_COMMAND_START(AI_ALL_DSGVAR_INIT_TYPES,nb)	
		#define M_WRITE_ONE_DSGVAR_INIT_TYPE(key,fr,gb)	 M_WRITE_ONE_COMMAND(AI_ONE_DSGVAR_INIT_TYPE,key,fr,gb)
 
		M_WRITE_ALL_DSGVAR_INIT_TYPES(fn_ucGetInitTypeNumber())
		#define M_DEFINE_DSGVAR_INIT_TYPE(a,b,c)		 M_WRITE_ONE_DSGVAR_INIT_TYPE(b,a,b)
		#include "DefOTI.h"
		#undef M_DEFINE_DSGVAR_INIT_TYPE
		M_WRITE_ALL_COMMAND_END()
 
		fclose(fp);
	}
}
