00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "gen_base.h"
00043
00044 static const char type_defs[]= "\n\
00045 #ifndef defs_INCLUDED\n\
00046 #define defs_INCLUDED\n\
00047 typedef signed int INT;\n\
00048 typedef signed int INT32;\n\
00049 typedef signed long long INT64;\n\
00050 typedef signed char mINT8;\n\
00051 typedef signed short mINT16;\n\
00052 typedef signed int mINT32;\n\
00053 typedef signed long long mINT64;\n\
00054 typedef unsigned int UINT;\n\
00055 typedef unsigned int UINT32;\n\
00056 typedef unsigned long long UINT64;\n\
00057 typedef unsigned char mUINT8;\n\
00058 typedef unsigned short mUINT16;\n\
00059 typedef unsigned int mUINT32;\n\
00060 typedef unsigned long long mUINT64;\n\
00061 typedef int BOOL;\n\
00062 typedef unsigned char mBOOL;\n\
00063 #ifndef TRUE\n\
00064 #define TRUE ((BOOL) 1)\n\
00065 #endif\n\
00066 #ifndef FALSE\n\
00067 #define FALSE ((BOOL) 0)\n\
00068 #endif\n\
00069 #if (defined(_LANGUAGE_C) || defined(__GNUC__)) && !defined(inline)\n\
00070 #define inline static __inline\n\
00071 #endif\n\
00072 #endif\n\n";
00073
00074
00075 void Emit_Header (FILE *hfile,
00076 const char *name,
00077 const char * const *interface_desc,
00078 bool cplusplus)
00079 {
00080 int i;
00081
00082 for (i=0; interface_desc[i]!=NULL; i++)
00083 {
00084 fprintf(hfile, "%s\n", interface_desc[i]);
00085 }
00086 fprintf(hfile, "\n#ifndef %s_INCLUDED\n", name);
00087 fprintf(hfile, "#define %s_INCLUDED\n", name);
00088
00089 if (cplusplus == false)
00090 fprintf(hfile, "#ifdef __cplusplus\n"
00091 "extern \"C\" {\n"
00092 "#endif\n");
00093 fprintf(hfile, type_defs);
00094 }
00095
00096 void Emit_Tailer(FILE *hfile, bool cplusplus)
00097 {
00098 if (cplusplus == false) {
00099 fprintf(hfile, "\n\
00100 #ifdef __cplusplus\n\
00101 }\n\
00102 #endif\n");
00103 }
00104 fprintf(hfile, "#endif\n");
00105 }
00106
00107 void Init_Module_Files(GEN_MODE mode, const char * module_name,
00108 FILE **c_file, bool cplusplus)
00109 {
00110 if (mode == GEN_MODE_FILE)
00111 {
00112 char * buf_name = (char *)malloc(strlen(module_name)+strlen(".Exported")+1);
00113 FmtAssert(buf_name, ("Unable to alloc memory from system!!\n"));
00114
00115 if (cplusplus){
00116 sprintf(buf_name, "%s.cxx", module_name);
00117 }
00118 else{
00119 sprintf(buf_name, "%s.c", module_name);
00120 }
00121 *c_file = fopen(buf_name, "w");
00122 FmtAssert( *c_file,
00123 ("Creat files: %s failure!!\n", module_name));
00124 free(buf_name);
00125 }
00126 else
00127 {
00128 *c_file = stdout;
00129 }
00130 }
00131
00132
00133 void Init_Module_Files(GEN_MODE mode, const char * module_name,
00134 FILE **c_file, FILE **h_file, FILE **export_file,
00135 bool cplusplus)
00136 {
00137 if (mode == GEN_MODE_FILE)
00138 {
00139 char * buf_name = (char *)malloc(strlen(module_name)+strlen(".Exported")+1);
00140 FmtAssert(buf_name, ("Unable to alloc memory from system!!\n"));
00141
00142 if (cplusplus){
00143 sprintf(buf_name, "%s.cxx", module_name);
00144 }
00145 else{
00146 sprintf(buf_name, "%s.c", module_name);
00147 }
00148 *c_file = fopen(buf_name, "w");
00149 sprintf(buf_name, "%s.h", module_name);
00150 *h_file = fopen(buf_name, "w");
00151 sprintf(buf_name, "%s.Exported", module_name);
00152 *export_file = fopen(buf_name, "w");
00153
00154 FmtAssert( (*c_file)&&(*h_file)&&(*export_file),
00155 ("Creat files: %s failure!!\n", module_name));
00156 free(buf_name);
00157 }
00158 else
00159 {
00160 *c_file = stdout;
00161 *h_file = stdout;
00162 *export_file = stdout;
00163 }
00164
00165 }
00166
00167 void Close_Module_Files(GEN_MODE mode,
00168 FILE **c_file, FILE **h_file, FILE **export_file)
00169 {
00170 if (mode == GEN_MODE_FILE)
00171 {
00172 fclose(*c_file);
00173 fclose(*h_file);
00174 fclose(*export_file);
00175 }
00176
00177 }
00178