1 |
/* printf */ |
/* printf, sscanf, fgets, fprintf */ |
2 |
#include <stdio.h> |
#include <stdio.h> |
3 |
/* EXIT_SUCCESS */ |
/* exit, EXIT_SUCCESS, malloc, free */ |
4 |
#include <stdlib.h> |
#include <stdlib.h> |
5 |
/* NULL */ |
/* NULL */ |
6 |
#include <stddef.h> |
#include <stddef.h> |
7 |
/* dlopen, dlsym, dlerror */ |
/* dlopen, dlsym, dlerror */ |
8 |
#include <dlfcn.h> |
#include <dlfcn.h> |
9 |
/* assert */ |
/* strcmp, strcpy, strlen, strcat, strdup */ |
|
#include <assert.h> |
|
|
/* strcat */ |
|
10 |
#include <string.h> |
#include <string.h> |
11 |
|
|
12 |
#define HASHTBLSIZE 65536 |
#define HASHTBLSIZE 65536 |
99 |
} |
} |
100 |
free(val); /* Free the actual list value */ |
free(val); /* Free the actual list value */ |
101 |
break; |
break; |
102 |
default: |
case integer: |
103 |
|
case func: |
104 |
|
case symb: |
105 |
break; |
break; |
106 |
} |
} |
107 |
} |
} |
198 |
} |
} |
199 |
|
|
200 |
/* Mangle a symbol name to a valid C identifier name */ |
/* Mangle a symbol name to a valid C identifier name */ |
201 |
char *mangle_(const char *old_string){ |
char *mangle_str(const char *old_string){ |
202 |
char validchars[] |
char validchars[] |
203 |
="0123456789abcdef"; |
="0123456789abcdef"; |
204 |
char *new_string, *current; |
char *new_string, *current; |
205 |
|
|
206 |
new_string=malloc(strlen(old_string)+4); |
new_string=malloc((strlen(old_string)*2)+4); |
207 |
strcpy(new_string, "sx_"); /* Stack eXternal */ |
strcpy(new_string, "sx_"); /* Stack eXternal */ |
208 |
current=new_string+3; |
current=new_string+3; |
209 |
while(old_string[0] != '\0'){ |
while(old_string[0] != '\0'){ |
210 |
current[0]=validchars[old_string[0]/16]; |
current[0]=validchars[(unsigned char)(old_string[0])/16]; |
211 |
current[1]=validchars[old_string[0]%16]; |
current[1]=validchars[(unsigned char)(old_string[0])%16]; |
212 |
current+=2; |
current+=2; |
213 |
old_string++; |
old_string++; |
214 |
} |
} |
233 |
return; |
return; |
234 |
} |
} |
235 |
|
|
236 |
new_string= mangle_((const char *)(env->head->item->content.ptr)); |
new_string= mangle_str((const char *)(env->head->item->content.ptr)); |
237 |
|
|
238 |
toss(env); |
toss(env); |
239 |
if(env->err) return; |
if(env->err) return; |
296 |
funcptr= dlsym(handle, in_string); /* Get function pointer */ |
funcptr= dlsym(handle, in_string); /* Get function pointer */ |
297 |
dlerr=dlerror(); |
dlerr=dlerror(); |
298 |
if(dlerr != NULL) { /* If no function was found */ |
if(dlerr != NULL) { /* If no function was found */ |
299 |
mangled=mangle_(in_string); |
mangled=mangle_str(in_string); |
300 |
funcptr= dlsym(handle, mangled); /* try mangling it */ |
funcptr= dlsym(handle, mangled); /* try mangling it */ |
301 |
free(mangled); |
free(mangled); |
302 |
dlerr=dlerror(); |
dlerr=dlerror(); |
541 |
free(temp_string); |
free(temp_string); |
542 |
break; |
break; |
543 |
|
|
544 |
default: |
case integer: |
545 |
|
break; |
546 |
} |
} |
547 |
} |
} |
548 |
|
|