-#include <time.h>
-#ifndef WIN32
-#include <unistd.h>
-#include <fcntl.h>
-#endif
-
-extern cvar_t timestamps;
-extern cvar_t timeformat;
-
-static int sys_nostdout = false;
-
-/* 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', '{', '|', '}', '~', '<'
-};
+#include "taskqueue.h"
+#include "thread.h"
+
+#define SUPPORTDLL
+
+#ifdef WIN32
+# include <windows.h>
+# include <mmsystem.h> // timeGetTime
+# include <time.h> // localtime
+#ifdef _MSC_VER
+#pragma comment(lib, "winmm.lib")
+#endif
+#else
+# ifdef __FreeBSD__
+# include <sys/sysctl.h>
+# endif
+# include <unistd.h>
+# include <fcntl.h>
+# include <sys/time.h>
+# include <time.h>
+# ifdef SUPPORTDLL
+# include <dlfcn.h>
+# endif
+#endif
+
+static char sys_timestring[128];
+char *Sys_TimeString(const char *timeformat)
+{
+ time_t mytime = time(NULL);
+#if _MSC_VER >= 1400
+ struct tm mytm;
+ localtime_s(&mytm, &mytime);
+ strftime(sys_timestring, sizeof(sys_timestring), timeformat, &mytm);
+#else
+ strftime(sys_timestring, sizeof(sys_timestring), timeformat, localtime(&mytime));
+#endif
+ return sys_timestring;
+}
+
+
+void Sys_Quit (int returnvalue)
+{
+ // Unlock mutexes because the quit command may jump directly here, causing a deadlock
+ if ((cmd_local)->cbuf->lock)
+ Cbuf_Unlock((cmd_local)->cbuf);
+ SV_UnlockThreadMutex();
+ TaskQueue_Frame(true);
+
+ if (Sys_CheckParm("-profilegameonly"))
+ Sys_AllowProfiling(false);
+ host.state = host_shutdown;
+ Host_Shutdown();
+ exit(returnvalue);
+}
+
+#ifdef __cplusplus
+extern "C"
+#endif
+void Sys_AllowProfiling(qbool enable)
+{
+#ifdef __ANDROID__
+#ifdef USE_PROFILER
+ extern void monstartup(const char *libname);
+ extern void moncleanup(void);
+ if (enable)
+ monstartup("libmain.so");
+ else
+ moncleanup();
+#endif
+#elif (defined(__linux__) && (defined(__GLIBC__) || defined(__GNU_LIBRARY__))) || defined(__FreeBSD__)
+ extern int moncontrol(int);
+ moncontrol(enable);
+#endif
+}
+
+
+/*
+===============================================================================