X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=sys_shared.c;h=9b4aea623989069b6ad652e912625c7ef3609052;hp=11f160402fd6a2f10098f04d42b74c8ae94d12e0;hb=36d38ac2f10b1f0d4006694075e06ad284204ffe;hpb=e9c7b3e739719a2f84c2d583b6a6faf3661dbad0 diff --git a/sys_shared.c b/sys_shared.c index 11f16040..9b4aea62 100644 --- a/sys_shared.c +++ b/sys_shared.c @@ -1,257 +1,145 @@ #include "quakedef.h" -#include +# include #ifndef WIN32 -#include -#include -#include +# include +# include +# include #endif -#include -extern cvar_t timestamps; -extern cvar_t timeformat; +qboolean sys_nostdout = false; -static int sys_nostdout = false; +static char sys_timestring[128]; +char *Sys_TimeString(const char *timeformat) +{ + time_t mytime = time(NULL); + strftime(sys_timestring, sizeof(sys_timestring), timeformat, localtime(&mytime)); + return sys_timestring; +} -/* The translation table between the graphical font and plain ASCII --KB */ -static char qfont_table[256] = { - '\0', '#', '#', '#', '#', '.', '#', '#', - '#', 9, 10, '#', ' ', 13, '.', '.', - '[', ']', '0', '1', '2', '3', '4', '5', - '6', '7', '8', '9', '.', '<', '=', '>', - ' ', '!', '"', '#', '$', '%', '&', '\'', - '(', ')', '*', '+', ',', '-', '.', '/', - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', ':', ';', '<', '=', '>', '?', - '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', - 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', - 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', - 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', - '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', - 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', - 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', - 'x', 'y', 'z', '{', '|', '}', '~', '<', - '<', '=', '>', '#', '#', '.', '#', '#', - '#', '#', ' ', '#', ' ', '>', '.', '.', - '[', ']', '0', '1', '2', '3', '4', '5', - '6', '7', '8', '9', '.', '<', '=', '>', - ' ', '!', '"', '#', '$', '%', '&', '\'', - '(', ')', '*', '+', ',', '-', '.', '/', - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', ':', ';', '<', '=', '>', '?', - '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', - 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', - 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', - 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', - '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', - 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', - 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', - 'x', 'y', 'z', '{', '|', '}', '~', '<' -}; +extern qboolean host_shuttingdown; +void Sys_Quit (void) +{ + host_shuttingdown = true; + Host_Shutdown(); + exit(0); +} -#ifdef WIN32 -extern HANDLE hinput, houtput; -#endif +char engineversion[128]; -#define MAX_PRINT_MSG 16384 -void Sys_Printf (const char *fmt, ...) +void Sys_Shared_EarlyInit(void) { - va_list argptr; - char start[MAX_PRINT_MSG]; // String we started with - char stamp[MAX_PRINT_MSG]; // Time stamp - char final[MAX_PRINT_MSG]; // String we print + const char* os; - time_t mytime = 0; - struct tm *local = NULL; + Memory_Init (); + Log_Init (); - unsigned char *p; -#ifdef WIN32 - DWORD dummy; -#endif + COM_InitArgv(); + COM_InitGameType(); - va_start (argptr, fmt); -#ifdef HAVE_VSNPRINTF - vsnprintf (start, sizeof(start), fmt, argptr); +#if defined(__linux__) + os = "Linux"; +#elif defined(WIN32) + os = "Windows"; +#elif defined(__FreeBSD__) + os = "FreeBSD"; +#elif defined(__NetBSD__) + os = "NetBSD"; +#elif defined(__OpenBSD__) + os = "OpenBSD"; +#elif defined(MACOSX) + os = "Mac OS X"; #else - vsprintf (start, fmt, argptr); + os = "Unknown"; #endif - va_end (argptr); - - if (sys_nostdout) - return; + dpsnprintf (engineversion, sizeof (engineversion), "%s %s %s", gamename, os, buildstring); - if (timestamps.integer) - { - mytime = time (NULL); - local = localtime (&mytime); - strftime (stamp, sizeof (stamp), timeformat.string, local); - - snprintf (final, sizeof (final), "%s%s", stamp, start); - } +// COMMANDLINEOPTION: Console: -nostdout disables text output to the terminal the game was launched from + if (COM_CheckParm("-nostdout")) + sys_nostdout = 1; else - snprintf (final, sizeof (final), "%s", start); - - // LordHavoc: make sure the string is terminated - final[MAX_PRINT_MSG - 1] = 0; - for (p = (unsigned char *) final;*p; p++) - *p = qfont_table[*p]; -#ifdef WIN32 - if (cls.state == ca_dedicated) - WriteFile(houtput, final, strlen (final), &dummy, NULL); -#else - printf("%s", final); -#endif + Con_Printf("%s\n", engineversion); } -// LordHavoc: 256 pak files (was 10) -#define MAX_HANDLES 256 -QFile *sys_handles[MAX_HANDLES]; - -int findhandle (void) +void Sys_Shared_LateInit(void) { - int i; - - for (i = 1;i < MAX_HANDLES;i++) - if (!sys_handles[i]) - return i; - Sys_Error ("out of handles"); - return -1; } /* -================ -Sys_FileLength -================ -*/ -int Sys_FileLength (QFile *f) -{ - int pos, end; +=============================================================================== - pos = Qtell (f); - Qseek (f, 0, SEEK_END); - end = Qtell (f); - Qseek (f, pos, SEEK_SET); +DLL MANAGEMENT - return end; -} +=============================================================================== +*/ -int Sys_FileOpenRead (const char *path, int *handle) +qboolean Sys_LoadLibrary (const char** dllnames, dllhandle_t* handle, const dllfunction_t *fcts) { - QFile *f; - int i, retval; + const dllfunction_t *func; + dllhandle_t dllhandle = 0; + unsigned int i; - i = findhandle (); + if (handle == NULL) + return false; - f = Qopen(path, "rbz"); + // Initializations + for (func = fcts; func && func->name != NULL; func++) + *func->funcvariable = NULL; - if (!f) + // Try every possible name + for (i = 0; dllnames[i] != NULL; i++) { - *handle = -1; - retval = -1; - } - else - { - sys_handles[i] = f; - *handle = i; - retval = Sys_FileLength(f); - } - - return retval; -} - -int Sys_FileOpenWrite (const char *path) -{ - QFile *f; - int i; - - i = findhandle (); +#ifdef WIN32 + dllhandle = LoadLibrary (dllnames[i]); +#else + dllhandle = dlopen (dllnames[i], RTLD_LAZY); +#endif + if (dllhandle) + break; - f = Qopen(path, "wb"); - if (!f) - { - Con_Printf("Sys_FileOpenWrite: Error opening %s: %s", path, strerror(errno)); - return 0; + Con_Printf ("Can't load \"%s\".\n", dllnames[i]); } - sys_handles[i] = f; - - return i; -} -void Sys_FileClose (int handle) -{ - Qclose (sys_handles[handle]); - sys_handles[handle] = NULL; -} + // No DLL found + if (! dllhandle) + return false; -void Sys_FileSeek (int handle, int position) -{ - Qseek (sys_handles[handle], position, SEEK_SET); -} + Con_Printf("\"%s\" loaded.\n", dllnames[i]); -int Sys_FileRead (int handle, void *dest, int count) -{ - return Qread (sys_handles[handle], dest, count); -} + // Get the function adresses + for (func = fcts; func && func->name != NULL; func++) + if (!(*func->funcvariable = (void *) Sys_GetProcAddress (dllhandle, func->name))) + { + Con_Printf ("Missing function \"%s\" - broken library!\n", func->name); + Sys_UnloadLibrary (&dllhandle); + return false; + } -int Sys_FileWrite (int handle, void *data, int count) -{ - return Qwrite (sys_handles[handle], data, count); + *handle = dllhandle; + return true; } -int Sys_FileTime (const char *path) +void Sys_UnloadLibrary (dllhandle_t* handle) { -#if WIN32 - QFile *f; - - f = Qopen(path, "rb"); - if (f) - { - Qclose(f); - return 1; - } + if (handle == NULL || *handle == NULL) + return; - return -1; +#ifdef WIN32 + FreeLibrary (*handle); #else - struct stat buf; - - if (stat (path,&buf) == -1) - return -1; - - return buf.st_mtime; + dlclose (*handle); #endif -} -void Sys_mkdir (const char *path) -{ -#if WIN32 - _mkdir (path); -#else - mkdir (path, 0777); -#endif + *handle = NULL; } -char engineversion[128]; - -void Sys_Shared_EarlyInit(void) +void* Sys_GetProcAddress (dllhandle_t handle, const char* name) { - Memory_Init (); - -#if defined(__linux__) - sprintf (engineversion, "%s Linux %s", gamename, buildstring); -#elif defined(WIN32) - sprintf (engineversion, "%s Windows %s", gamename, buildstring); +#ifdef WIN32 + return (void *)GetProcAddress (handle, name); #else - sprintf (engineversion, "%s Unknown %s", gamename, buildstring); + return (void *)dlsym (handle, name); #endif - - if (COM_CheckParm("-nostdout")) - sys_nostdout = 1; - else - printf("%s\n", engineversion); -} - -void Sys_Shared_LateInit(void) -{ }