#include "quakedef.h"
#include <time.h>
-#ifdef WIN32
-#include <direct.h>
-#else
-#include <sys/stat.h>
+#ifndef WIN32
#include <unistd.h>
#include <fcntl.h>
#endif
-#include <errno.h>
extern cvar_t timestamps;
extern cvar_t timeformat;
'x', 'y', 'z', '{', '|', '}', '~', '<'
};
-#ifdef WIN32
-extern HANDLE hinput, houtput;
-#endif
-
-#define MAX_PRINT_MSG 16384
-void Sys_Printf (const char *fmt, ...)
+static char sys_timestring[128];
+char *Sys_TimeString(const char *timeformat)
{
- 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
+ time_t mytime = time(NULL);
+ strftime(sys_timestring, sizeof(sys_timestring), timeformat, localtime(&mytime));
+ return sys_timestring;
+}
- time_t mytime = 0;
- struct tm *local = NULL;
- unsigned char *p;
-#ifdef WIN32
- DWORD dummy;
-#endif
+#define MAXPRINTMSG 16384
- va_start (argptr, fmt);
-#ifdef HAVE_VSNPRINTF
- vsnprintf (start, sizeof(start), fmt, argptr);
-#else
- vsprintf (start, fmt, argptr);
-#endif
- va_end (argptr);
+void Sys_Print(const char *msg)
+{
+ unsigned char *p;
+ // String we print
+ char final[MAXPRINTMSG];
if (sys_nostdout)
return;
if (timestamps.integer)
- {
- mytime = time (NULL);
- local = localtime (&mytime);
- strftime (stamp, sizeof (stamp), timeformat.string, local);
-
- snprintf (final, sizeof (final), "%s%s", stamp, start);
- }
+ snprintf(final, sizeof(final), "%s%s", Sys_TimeString(timeformat.string), msg);
else
- snprintf (final, sizeof (final), "%s", start);
+ strncpy(final, msg, sizeof(final));
// LordHavoc: make sure the string is terminated
- final[MAX_PRINT_MSG - 1] = 0;
+ final[MAXPRINTMSG-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
-}
-
-// LordHavoc: 256 pak files (was 10)
-#define MAX_HANDLES 256
-QFile *sys_handles[MAX_HANDLES];
-
-int findhandle (void)
-{
- int i;
-
- for (i = 1;i < MAX_HANDLES;i++)
- if (!sys_handles[i])
- return i;
- Sys_Error ("out of handles");
- return -1;
+ Sys_PrintToTerminal(final);
}
-/*
-================
-Sys_FileLength
-================
-*/
-int Sys_FileLength (QFile *f)
+void Sys_Printf(const char *fmt, ...)
{
- int pos, end;
+ va_list argptr;
+ char msg[MAXPRINTMSG]; // String we started with
- pos = Qtell (f);
- Qseek (f, 0, SEEK_END);
- end = Qtell (f);
- Qseek (f, pos, SEEK_SET);
+ va_start(argptr,fmt);
+ vsnprintf(msg,sizeof(msg),fmt,argptr);
+ va_end(argptr);
- return end;
+ Sys_Print(msg);
}
-int Sys_FileOpenRead (const char *path, int *handle)
-{
- QFile *f;
- int i, retval;
-
- i = findhandle ();
- f = Qopen(path, "rbz");
-
- if (!f)
- {
- *handle = -1;
- retval = -1;
- }
- else
- {
- sys_handles[i] = f;
- *handle = i;
- retval = Sys_FileLength(f);
- }
-
- return retval;
-}
+char engineversion[128];
-int Sys_FileOpenWrite (const char *path)
+void Sys_Shared_EarlyInit(void)
{
- QFile *f;
- int i;
-
- i = findhandle ();
-
- f = Qopen(path, "wb");
- if (!f)
- {
- Con_Printf("Sys_FileOpenWrite: Error opening %s: %s", path, strerror(errno));
- return 0;
- }
- sys_handles[i] = f;
+ const char* os;
- return i;
-}
+ Memory_Init ();
-void Sys_FileClose (int handle)
-{
- Qclose (sys_handles[handle]);
- sys_handles[handle] = NULL;
-}
+ COM_InitArgv();
+ COM_InitGameType();
-void Sys_FileSeek (int handle, int position)
-{
- Qseek (sys_handles[handle], position, SEEK_SET);
-}
+#if defined(__linux__)
+ os = "Linux";
+#elif defined(WIN32)
+ os = "Windows";
+#elif defined(__NetBSD__)
+ os = "NetBSD";
+#elif defined(__OpenBSD__)
+ os = "OpenBSD";
+#else
+ os = "Unknown";
+#endif
+ snprintf (engineversion, sizeof (engineversion), "%s %s %s", gamename, os, buildstring);
-int Sys_FileRead (int handle, void *dest, int count)
-{
- return Qread (sys_handles[handle], dest, count);
+ if (COM_CheckParm("-nostdout"))
+ sys_nostdout = 1;
+ else
+ Con_Printf("%s\n", engineversion);
}
-int Sys_FileWrite (int handle, void *data, int count)
+void Sys_Shared_LateInit(void)
{
- return Qwrite (sys_handles[handle], data, count);
}
-int Sys_FileTime (const char *path)
-{
-#if WIN32
- QFile *f;
-
- f = Qopen(path, "rb");
- if (f)
- {
- Qclose(f);
- return 1;
- }
+/*
+===============================================================================
- return -1;
-#else
- struct stat buf;
+DLL MANAGEMENT
- if (stat (path,&buf) == -1)
- return -1;
+===============================================================================
+*/
- return buf.st_mtime;
+#ifndef WIN32
+#include <dlfcn.h>
#endif
-}
-void Sys_mkdir (const char *path)
+dllhandle_t Sys_LoadLibrary (const char* name)
{
-#if WIN32
- _mkdir (path);
+#ifdef WIN32
+ return LoadLibrary (name);
#else
- mkdir (path, 0777);
+ return dlopen (name, RTLD_LAZY);
#endif
}
-char engineversion[128];
-
-void Sys_Shared_EarlyInit(void)
+void Sys_UnloadLibrary (dllhandle_t handle)
{
- Memory_Init ();
-
- COM_InitArgv();
- COM_InitGameType();
-
-#if defined(__linux__)
- sprintf (engineversion, "%s Linux %s", gamename, buildstring);
-#elif defined(WIN32)
- sprintf (engineversion, "%s Windows %s", gamename, buildstring);
+#ifdef WIN32
+ FreeLibrary (handle);
#else
- sprintf (engineversion, "%s Unknown %s", gamename, buildstring);
+ dlclose (handle);
#endif
-
- if (COM_CheckParm("-nostdout"))
- sys_nostdout = 1;
- else
- printf("%s\n", engineversion);
}
-void Sys_Shared_LateInit(void)
+void* Sys_GetProcAddress (dllhandle_t handle, const char* name)
{
+#ifdef WIN32
+ return (void *)GetProcAddress (handle, name);
+#else
+ return (void *)dlsym (handle, name);
+#endif
}