first working simkit loader

This commit is contained in:
dwarning 2014-09-18 21:05:59 +02:00
parent 1bb1cc1f47
commit 7f748e3b84
3 changed files with 41 additions and 9 deletions

View File

@ -32,9 +32,9 @@ void com_use(wordlist *wl)
#ifdef SIMKIT #ifdef SIMKIT
void com_simkit(wordlist *wl) void com_simkit(wordlist *wl)
{ {
wordlist *ww; NG_IGNORE(wl);
for (ww = wl; ww; ww = ww->wl_next)
if (load_simkit()) if (load_simkit())
fprintf(cp_err, "Error: Simkit %s couldn't be loaded!\n", ww->wl_word); fprintf(cp_err, "Error: Simkit couldn't be loaded!\n");
} }
#endif #endif

View File

@ -256,7 +256,7 @@ struct comm spcp_coms[] = {
"library library ... : Loads the device librarys." } , "library library ... : Loads the device librarys." } ,
#endif #endif
#ifdef SIMKIT #ifdef SIMKIT
{ "simkit", com_simkit, FALSE, TRUE, { "simkit", com_simkit, TRUE, TRUE,
{ 040000, 040000, 040000, 040000 }, E_BEGINNING, 0, LOTS, { 040000, 040000, 040000, 040000 }, E_BEGINNING, 0, LOTS,
NULL, NULL,
"library library ... : Loads the simkit model library." } , "library library ... : Loads the simkit model library." } ,

View File

@ -39,7 +39,17 @@
#ifdef SIMKIT #ifdef SIMKIT
#include "sk.h" #include "sk.h"
#include "simkit_models_loader.h" #include "simkit_models_loader.h"
#include <dlfcn.h> /* to load libraries*/ #ifndef _WIN32
#include <sys/param.h> /* MAXPATHLEN */
#include <dlfcn.h> /* to load libraries */
#else /* _WIN32 */
#include <windows.h>
/* Dynamic library related functions differ between Windows and Unix */
#define dlopen(a, b) LoadLibrary(TEXT(a))
#define dlsym(a, b) GetProcAddress((a), TEXT(b))
#define dlclose(a) FreeLibrary(a)
#define dlerror() printf("dll not found\n")
#endif /* _WIN32 */
#endif #endif
#ifdef XSPICE #ifdef XSPICE
@ -510,16 +520,37 @@ char *dlerror(void)
#endif #endif
/*-------------------- end of XSPICE additions ----------------------*/ /*-------------------- end of XSPICE additions ----------------------*/
#ifdef SIMKIT #ifdef SIMKIT
int load_simkit(void){ int load_simkit(void){
const char *msg; const char *msg;
SK_MODELLIB_DESCRIPTOR (*p_sk_load_models)(void) = NULL; SK_MODELLIB_DESCRIPTOR *(*p_sk_load_models)(void) = NULL;
SK_MODELLIB_DESCRIPTOR *p_sk_modellib_descr = NULL; SK_MODELLIB_DESCRIPTOR *p_sk_modellib_descr = NULL;
void (*p_sk_unload_models)(void) = NULL; void (*p_sk_unload_models)(void) = NULL;
void *p_sk_loader_lib = dlopen("/home/dwarning/local/src/spice/simkit/4.3_pub/source/lib/libsimkit_models_loader", RTLD_LAZY | RTLD_GLOBAL); char library_path[MAXPATHLEN];
char library_name[MAXPATHLEN];
char *p_simkit_ld_libpath;
snprintf(library_name, MAXPATHLEN, "libsimkit_models_loader");
p_simkit_ld_libpath = getenv("SIMKIT_LD_LIBRARY_PATH");
if ( p_simkit_ld_libpath != NULL) {
snprintf(library_path, MAXPATHLEN,
"%s/%s.so",
p_simkit_ld_libpath,
library_name);
} else {
/* If the full path is not specified, dlopen() will look via the
* LD_LIBRARY_PATH to find the shared lib */
snprintf(library_path, MAXPATHLEN,
"%s.so",
library_name);
}
void *p_sk_loader_lib = dlopen(library_path, RTLD_LAZY | RTLD_GLOBAL);
if (p_sk_loader_lib != NULL) if (p_sk_loader_lib != NULL)
{ {
p_sk_load_models = dlsym(p_sk_loader_lib, "SK_load_models"); p_sk_load_models = dlsym(p_sk_loader_lib, "SK_load_models");
@ -536,5 +567,6 @@ int load_simkit(void){
p_sk_modellib_descr = p_sk_load_models(); p_sk_modellib_descr = p_sk_load_models();
} }
return 0;
} }
#endif #endif