2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
|
|
|
* YAP Prolog *
|
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: load_dl.c *
|
|
|
|
* comments: dl based dynamic loader of external routines *
|
|
|
|
* tested on i486-linuxelf *
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "Yap.h"
|
|
|
|
#include "Yatom.h"
|
|
|
|
#include "Heap.h"
|
|
|
|
#include "yapio.h"
|
|
|
|
#include "Foreign.h"
|
|
|
|
|
|
|
|
#if LOAD_DLL
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
/*
|
2002-09-23 18:06:13 +01:00
|
|
|
* YAP_FindExecutable(argv[0]) should be called on yap initialization to
|
2001-04-09 20:54:03 +01:00
|
|
|
* locate the executable of Yap
|
|
|
|
*/
|
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_FindExecutable(char *name)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LoadForeign(ofiles,libs,proc_name,init_proc) dynamically loads foreign
|
|
|
|
* code files and libraries and locates an initialization routine
|
|
|
|
*/
|
2002-11-11 17:38:10 +00:00
|
|
|
static Int
|
2001-04-09 20:54:03 +01:00
|
|
|
LoadForeign(StringList ofiles, StringList libs,
|
|
|
|
char *proc_name, YapInitProc *init_proc)
|
|
|
|
{
|
|
|
|
|
|
|
|
while (ofiles) {
|
|
|
|
HINSTANCE handle;
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
if (Yap_TrueFileName(ofiles->s, Yap_FileNameBuf, TRUE) &&
|
|
|
|
(handle=LoadLibrary(Yap_FileNameBuf)) != 0)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
if (*init_proc == NULL)
|
|
|
|
*init_proc = (YapInitProc)GetProcAddress((HMODULE)handle, proc_name);
|
|
|
|
}
|
|
|
|
ofiles = ofiles->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* load libraries first so that their symbols are available to
|
|
|
|
other routines */
|
|
|
|
while (libs) {
|
|
|
|
HINSTANCE handle;
|
|
|
|
|
|
|
|
if (libs->s[0] == '-') {
|
2002-11-18 18:18:05 +00:00
|
|
|
strcat(Yap_FileNameBuf,libs->s+2);
|
|
|
|
strcat(Yap_FileNameBuf,".dll");
|
2001-04-09 20:54:03 +01:00
|
|
|
} else {
|
2002-11-18 18:18:05 +00:00
|
|
|
strcpy(Yap_FileNameBuf,libs->s);
|
2001-04-09 20:54:03 +01:00
|
|
|
}
|
|
|
|
|
2002-11-18 18:18:05 +00:00
|
|
|
if((handle=LoadLibrary(Yap_FileNameBuf)) == 0)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
2002-11-18 18:18:05 +00:00
|
|
|
/* strcpy(Yap_ErrorSay,dlerror());*/
|
2001-04-09 20:54:03 +01:00
|
|
|
return LOAD_FAILLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*init_proc == NULL)
|
|
|
|
*init_proc = (YapInitProc)GetProcAddress((HMODULE)handle, proc_name);
|
|
|
|
|
|
|
|
libs = libs->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*init_proc == NULL) {
|
2002-11-18 18:18:05 +00:00
|
|
|
strcpy(Yap_ErrorSay,"Could not locate initialization routine");
|
2001-04-09 20:54:03 +01:00
|
|
|
return LOAD_FAILLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LOAD_SUCCEEDED;
|
|
|
|
}
|
|
|
|
|
2002-11-11 17:38:10 +00:00
|
|
|
Int
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_LoadForeign(StringList ofiles, StringList libs,
|
2002-11-11 17:38:10 +00:00
|
|
|
char *proc_name, YapInitProc *init_proc)
|
|
|
|
{
|
|
|
|
return LoadForeign(ofiles, libs, proc_name, init_proc);
|
|
|
|
}
|
|
|
|
|
2001-04-09 20:54:03 +01:00
|
|
|
void
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_ShutdownLoadForeign(void)
|
2001-04-09 20:54:03 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Int
|
2002-11-18 18:18:05 +00:00
|
|
|
Yap_ReLoadForeign(StringList ofiles, StringList libs,
|
2001-04-09 20:54:03 +01:00
|
|
|
char *proc_name, YapInitProc *init_proc)
|
|
|
|
{
|
|
|
|
return(LoadForeign(ofiles,libs, proc_name, init_proc));
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|