From 7f748e3b846fd10931ca8a9f5a10f3e109e7f574 Mon Sep 17 00:00:00 2001 From: dwarning Date: Thu, 18 Sep 2014 21:05:59 +0200 Subject: [PATCH] first working simkit loader --- src/frontend/com_dl.c | 8 ++++---- src/frontend/commands.c | 2 +- src/spicelib/devices/dev.c | 40 ++++++++++++++++++++++++++++++++++---- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/frontend/com_dl.c b/src/frontend/com_dl.c index 58182e067..eea4bebd2 100644 --- a/src/frontend/com_dl.c +++ b/src/frontend/com_dl.c @@ -32,9 +32,9 @@ void com_use(wordlist *wl) #ifdef SIMKIT void com_simkit(wordlist *wl) { - wordlist *ww; - for (ww = wl; ww; ww = ww->wl_next) - if (load_simkit()) - fprintf(cp_err, "Error: Simkit %s couldn't be loaded!\n", ww->wl_word); + NG_IGNORE(wl); + + if (load_simkit()) + fprintf(cp_err, "Error: Simkit couldn't be loaded!\n"); } #endif diff --git a/src/frontend/commands.c b/src/frontend/commands.c index b9744c030..176b56682 100644 --- a/src/frontend/commands.c +++ b/src/frontend/commands.c @@ -256,7 +256,7 @@ struct comm spcp_coms[] = { "library library ... : Loads the device librarys." } , #endif #ifdef SIMKIT - { "simkit", com_simkit, FALSE, TRUE, + { "simkit", com_simkit, TRUE, TRUE, { 040000, 040000, 040000, 040000 }, E_BEGINNING, 0, LOTS, NULL, "library library ... : Loads the simkit model library." } , diff --git a/src/spicelib/devices/dev.c b/src/spicelib/devices/dev.c index f34567ce8..215e4c475 100644 --- a/src/spicelib/devices/dev.c +++ b/src/spicelib/devices/dev.c @@ -39,7 +39,17 @@ #ifdef SIMKIT #include "sk.h" #include "simkit_models_loader.h" -#include /* to load libraries*/ +#ifndef _WIN32 + #include /* MAXPATHLEN */ + #include /* to load libraries */ +#else /* _WIN32 */ + #include + /* 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 #ifdef XSPICE @@ -510,16 +520,37 @@ char *dlerror(void) #endif /*-------------------- end of XSPICE additions ----------------------*/ - #ifdef SIMKIT int load_simkit(void){ 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; 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) { 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(); } + return 0; } #endif