2000-02-12 08:08:31 +00:00
|
|
|
/*
|
2000-02-13 11:31:00 +00:00
|
|
|
plugin.c
|
2000-02-12 08:08:31 +00:00
|
|
|
|
2000-02-14 08:50:30 +00:00
|
|
|
Dynamic shared object loader
|
2000-02-12 08:08:31 +00:00
|
|
|
|
2000-02-14 08:50:30 +00:00
|
|
|
Copyright (C) 1999, 2000 contributors of the QuakeForge project
|
2000-02-12 08:08:31 +00:00
|
|
|
Please see the file "AUTHORS" for a list of contributors
|
|
|
|
|
2000-02-14 08:50:30 +00:00
|
|
|
Author: Zephaniah E. Hull <mwarp@whitestar.soark.net>
|
|
|
|
Date: 11 Feb 2000
|
2000-02-12 08:08:31 +00:00
|
|
|
|
|
|
|
This file is part of the QuakeForge Core system.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2000-02-20 21:19:50 +00:00
|
|
|
#ifndef WIN32
|
2000-02-12 08:08:31 +00:00
|
|
|
#include <dlfcn.h>
|
2000-02-14 11:30:37 +00:00
|
|
|
#include <sys/param.h>
|
2000-02-20 21:19:50 +00:00
|
|
|
#else
|
|
|
|
#include "input.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2000-02-12 08:08:31 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <net.h>
|
|
|
|
#include <plugin.h>
|
2000-02-14 04:46:57 +00:00
|
|
|
#include <cvar.h>
|
|
|
|
|
2000-03-06 13:26:42 +00:00
|
|
|
#ifndef LIBDIR
|
|
|
|
#define LIBDIR
|
|
|
|
#endif
|
2000-02-27 07:13:32 +00:00
|
|
|
|
|
|
|
//cvar_t drv_path = {"drv_path", ".:" LIBDIR "/quakeforge"};
|
|
|
|
cvar_t *fs_drvpath;
|
2000-02-12 08:08:31 +00:00
|
|
|
|
2000-02-20 21:19:50 +00:00
|
|
|
input_pi *IN;
|
|
|
|
|
2000-02-27 07:13:32 +00:00
|
|
|
void Plugin_Init ()
|
|
|
|
{
|
|
|
|
fs_drvpath = Cvar_Get ("fs_drvpath",".:" LIBDIR "/quakeforge",0,"None");
|
|
|
|
}
|
|
|
|
|
2000-02-20 21:19:50 +00:00
|
|
|
#ifndef WIN32
|
|
|
|
|
2000-02-14 11:30:37 +00:00
|
|
|
void *_plugin_load(const char *filename)
|
2000-02-12 08:08:31 +00:00
|
|
|
{
|
|
|
|
void *h;
|
2000-02-14 20:28:22 +00:00
|
|
|
char path_buf[MAXPATHLEN*2+1+1];
|
2000-02-14 11:30:37 +00:00
|
|
|
char *path,*end;
|
|
|
|
int len;
|
|
|
|
|
2000-02-27 07:13:32 +00:00
|
|
|
for (path = fs_drvpath->string; *path; path=end) {
|
2000-02-14 11:30:37 +00:00
|
|
|
end = strchr(path,':');
|
|
|
|
if (!end)
|
|
|
|
end = strchr(path,0);
|
|
|
|
len=end-path;
|
|
|
|
if (len>MAXPATHLEN)
|
|
|
|
len=MAXPATHLEN;
|
|
|
|
sprintf(path_buf,"%.*s/%.*s",len,path,MAXPATHLEN,filename);
|
|
|
|
if ((h = dlopen(path_buf, RTLD_LAZY))) {
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
if (*end)
|
|
|
|
end++;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int plugin_load(char *filename)
|
|
|
|
{
|
2000-02-12 08:08:31 +00:00
|
|
|
void *(*gpi) (void);
|
2000-02-14 11:30:37 +00:00
|
|
|
void *h;
|
2000-02-12 08:08:31 +00:00
|
|
|
|
2000-02-14 11:30:37 +00:00
|
|
|
if ((h=_plugin_load(filename))) {
|
2000-02-12 08:08:31 +00:00
|
|
|
if ((gpi = dlsym(h, "get_input_plugin_info"))) {
|
2000-02-19 08:24:15 +00:00
|
|
|
/*
|
2000-02-12 08:08:31 +00:00
|
|
|
input_pi *p;
|
2000-02-14 11:30:37 +00:00
|
|
|
|
2000-02-12 08:08:31 +00:00
|
|
|
p = (input_pi *) gpi();
|
|
|
|
p->handle = h;
|
|
|
|
p->filename = filename;
|
2000-02-14 11:30:37 +00:00
|
|
|
|
2000-02-12 08:08:31 +00:00
|
|
|
IN = p;
|
|
|
|
} else if (gpi = dlsym(h, "get_sound_plugin_info")) {
|
2000-02-14 11:30:37 +00:00
|
|
|
sound_pi *p;
|
2000-02-12 08:08:31 +00:00
|
|
|
|
|
|
|
p = (sound_pi *) gpi();
|
|
|
|
p->handle = h;
|
|
|
|
p->filename = filename;
|
|
|
|
*/
|
|
|
|
} else {
|
|
|
|
dlclose(h);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "%s\n", dlerror());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void plugin_unload(void *handle)
|
|
|
|
{
|
|
|
|
dlclose(handle);
|
|
|
|
}
|
2000-02-13 11:31:00 +00:00
|
|
|
|
2000-02-20 21:19:50 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
input_pi Winput;
|
|
|
|
int IN_Init();
|
|
|
|
void IN_Move(usercmd_t *);
|
|
|
|
void IN_Commands();
|
|
|
|
void Sys_SendKeyEvents();
|
|
|
|
void IN_Shutdown (void);
|
|
|
|
|
|
|
|
int plugin_load(char *filename)
|
|
|
|
{
|
|
|
|
IN = &Winput;
|
|
|
|
Winput.description = "Windows Input";
|
|
|
|
Winput.Init = IN_Init;
|
|
|
|
Winput.Move = IN_Move;
|
|
|
|
Winput.Commands = IN_Frame;
|
|
|
|
Winput.SendKeyEvents = IN_SendKeyEvents;
|
|
|
|
Winput.Shutdown = IN_Shutdown;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void plugin_unload(void *handle)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|