00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <defs.h>
00025 #include <iostream>
00026 #include <fstream>
00027 #include <string.h>
00028 #include <ext/hash_map>
00029 #include <stdlib.h>
00030
00031 #include "mempool.h"
00032 #include "cxx_memory.h"
00033 #include "errors.h"
00034 #include "f2c_abi_utils.h"
00035
00036 extern "C" {
00037 #include "../fe90/printmsg.h"
00038 }
00039
00040 static CALLEE_HTABLE spec_table;
00041 static BOOL script_init = FALSE;
00042 extern MEM_POOL *FE_Mempool;
00043 using namespace std;
00044
00045 static void Make_Mangled_Name(char *dst, const char *src)
00046 {
00047 const char *ptr;
00048 int underscores;
00049
00050 bzero (dst, sizeof(char)*strlen(dst));
00051 underscores = 1;
00052 for (ptr = src; ptr && *ptr && *ptr != ' ' ; ptr++){
00053 *dst++ = towlower(*ptr) ;
00054 if (*ptr == '_')
00055 underscores++;
00056 }
00057 while (underscores--)
00058 *dst ++ = '_';
00059 *dst = '\0';
00060 }
00061
00062
00063
00064
00065
00066
00067
00068 static void Parse_script(const char *script_name)
00069 {
00070
00071 char line_buffer[1024], *line_iterator;
00072 ifstream infile;
00073 char *callee_func;
00074 char callee_key[1024], *key_temp;
00075 static int count = 1;
00076
00077 infile.open(script_name, ifstream::in);
00078
00079 strcpy(callee_key, "");
00080 #ifdef KEY
00081 if (!infile.good()) {
00082 PRINTMSG(0, 1676, Log_Error, 0, script_name, strerror(errno));
00083 return;
00084 }
00085 #else
00086 FmtAssert((infile.good()), ("Ff2c abi script parsing error: can't open the ff2c abi description file"));
00087 #endif
00088
00089
00090
00091 while (infile.good()) {
00092 infile.getline(line_buffer, 1024);
00093 line_iterator = line_buffer;
00094
00095
00096 while (*line_iterator == ' ')
00097 line_iterator++;
00098 callee_func = strtok(line_iterator, " ");
00099 if (!callee_func)
00100 continue;
00101 Make_Mangled_Name(callee_key, callee_func);
00102
00103 key_temp = TYPE_MEM_POOL_ALLOC_N(char, FE_Mempool, sizeof(char)*(strlen(callee_key)+1));
00104 strcpy(key_temp, callee_key);
00105 spec_table[key_temp] = count++;
00106 }
00107 infile.close();
00108 }
00109
00110
00111
00112
00113
00114 extern char *F2C_ABI_filename;
00115 extern "C" int Check_FF2C_Script(const char *callee_key, int mangled)
00116 {
00117 char name_string[1024];
00118 const char *name_ptr;
00119
00120 if (!F2C_ABI_filename)
00121 return FALSE;
00122
00123 if (script_init == FALSE) {
00124 Parse_script (F2C_ABI_filename);
00125 script_init = TRUE;
00126 }
00127
00128 if (!mangled){
00129 Make_Mangled_Name(name_string, callee_key);
00130 name_ptr = name_string;
00131 }
00132 else
00133 name_ptr = callee_key;
00134
00135
00136 if (spec_table.find(name_ptr) == spec_table.end())
00137 return FALSE;
00138 return TRUE;
00139 }