From b4ac2446a1db9d842845a58cbd6891feeb3d0e5e Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 5 Jul 2001 03:28:40 +0000 Subject: [PATCH] Put knghtbrd's sys cleanup changes back in, but with Sys_MakeCodeWriteable in sys/util.c rather than limbo (the crux of the problem that caused the previous reversal). I'll look into his Sys_Printf changes next. --- configure.in | 2 +- libs/util/sys.c | 31 +++++++ nq/source/sys_null.c | 5 -- nq/source/sys_unix.c | 82 +------------------ nq/source/sys_unixd.c | 143 +-------------------------------- nq/source/sys_win.c | 30 ------- nq/source/sys_wind.c | 5 -- qw/source/cl_sys_sdl.c | 29 ------- qw/source/cl_sys_unix.c | 25 +----- qw/source/cl_sys_win.c | 12 --- qw/source/sys_null.c | 173 ---------------------------------------- qw/source/sys_unix.c | 151 ----------------------------------- qw/source/sys_win.c | 139 -------------------------------- 13 files changed, 38 insertions(+), 789 deletions(-) delete mode 100644 qw/source/sys_null.c delete mode 100644 qw/source/sys_unix.c delete mode 100644 qw/source/sys_win.c diff --git a/configure.in b/configure.in index 1de31c5d7..f75aacb77 100644 --- a/configure.in +++ b/configure.in @@ -259,7 +259,7 @@ AC_CHECK_FUNCS( gethostname gethostbyname connect gettimeofday getwd mkdir _mkdir \ ftime _ftime fcntl stat putenv select socket strerror strstr \ snprintf _snprintf vsnprintf _vsnprintf strsep dlopen getaddrinfo \ - getnameinfo + getnameinfo mprotect ) DL_LIBS="" diff --git a/libs/util/sys.c b/libs/util/sys.c index fbdcdbb86..eb2a158a6 100644 --- a/libs/util/sys.c +++ b/libs/util/sys.c @@ -52,6 +52,9 @@ #ifdef HAVE_WINDOWS_H # include #endif +#ifdef HAVE_SYS_MMAN_H +# include +#endif #include "compat.h" #include "QF/cvar.h" @@ -206,3 +209,31 @@ Sys_DoubleTime (void) return now - start_time; #endif } + +void +Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length) +{ +#ifdef HAVE_MPROTECT + int r; + unsigned long addr; + int psize = getpagesize (); + + addr = (startaddr & ~(psize - 1)) - psize; + +// fprintf(stderr, "writable code %lx(%lx)-%lx, length=%lx\n", startaddr, +// addr, startaddr+length, length); + + r = mprotect ((char *) addr, length + startaddr - addr + psize, 7); + + if (r < 0) + Sys_Error ("Protection change failed\n"); +#else +# ifdef HAVE_VIRTUALPROTECT + DWORD flOldProtect; + + if (!VirtualProtect + ((LPVOID) startaddr, length, PAGE_READWRITE, + &flOldProtect)) Sys_Error ("Protection change failed\n"); +# endif +#endif +} diff --git a/nq/source/sys_null.c b/nq/source/sys_null.c index 8ca912138..2c0b48f91 100644 --- a/nq/source/sys_null.c +++ b/nq/source/sys_null.c @@ -162,11 +162,6 @@ SYSTEM IO =============================================================================== */ -void -Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length) -{ -} - void Sys_Error (char *error, ...) diff --git a/nq/source/sys_unix.c b/nq/source/sys_unix.c index 58132950c..6196acc09 100644 --- a/nq/source/sys_unix.c +++ b/nq/source/sys_unix.c @@ -81,54 +81,11 @@ Sys_DebugLog (char *file, char *fmt, ...) close (fd); } -void -Sys_EditFile (char *filename) -{ - char cmd[256]; - char *term; - char *editor; - - term = getenv ("TERM"); - if (term && !strcmp (term, "xterm")) { - editor = getenv ("VISUAL"); - if (!editor) - editor = getenv ("EDITOR"); - if (!editor) - editor = getenv ("EDIT"); - if (!editor) - editor = "vi"; - snprintf (cmd, sizeof (cmd), "xterm -e %s %s", editor, filename); - system (cmd); - } -} /* * System I/O */ -void -Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length) -{ - int r; - unsigned long addr; - int psize = getpagesize (); - - addr = (startaddr & ~(psize - 1)) - psize; - -// fprintf(stderr, "writable code %lx(%lx)-%lx, length=%lx\n", startaddr, -// addr, startaddr+length, length); - - r = mprotect ((char *) addr, length + startaddr - addr + psize, 7); - - if (r < 0) - Sys_Error ("Protection change failed\n"); - -} - -void -Sys_DebugNumber (int y, int val) -{ -} void Sys_Error (const char *error, ...) @@ -166,34 +123,6 @@ Sys_Init (void) #endif } -void -Sys_Warn (char *warning, ...) -{ - va_list argptr; - char string[1024]; - - va_start (argptr, warning); - vsnprintf (string, sizeof (string), warning, argptr); - va_end (argptr); - fprintf (stderr, "Warning: %s", string); -} - -// ======================================================================= -// Sleeps for microseconds -// ======================================================================= - -static volatile int oktogo; - -void -alarm_handler (int x) -{ - oktogo = 1; -} - -void -Sys_LineRefresh (void) -{ -} void floating_point_exception_handler (int whatever) @@ -202,7 +131,7 @@ floating_point_exception_handler (int whatever) signal (SIGFPE, floating_point_exception_handler); } -char * +char * Sys_ConsoleInput (void) { static char text[256]; @@ -242,7 +171,7 @@ Sys_LowFPPrecision (void) #endif int -main (int c, char **v) +main (int c, char *v[]) { double time, oldtime, newtime; @@ -251,9 +180,6 @@ main (int c, char **v) extern int recording; int j; -// static char cwd[1024]; - -// signal(SIGFPE, floating_point_exception_handler); signal (SIGFPE, SIG_IGN); memset (&parms, 0, sizeof (parms)); @@ -310,9 +236,7 @@ main (int c, char **v) Host_Frame (time); -// graphic debugging aids -// if (sys_linerefresh->value) -// Sys_LineRefresh (); } } + diff --git a/nq/source/sys_unixd.c b/nq/source/sys_unixd.c index 5d900a05d..c97f36852 100644 --- a/nq/source/sys_unixd.c +++ b/nq/source/sys_unixd.c @@ -71,75 +71,6 @@ cvar_t *sys_linerefresh; cvar_t *timestamps; cvar_t *timeformat; -/* 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', '{', '|', '}', '~', '<' -}; - - -/* - * File I/O - */ - -/* - Sys_FileTime - - Returns -1 if file not present -*/ -int -Sys_FileTime (char *path) -{ - struct stat buf; - - if (stat (path, &buf) == -1) - return -1; - - return buf.st_mtime; -} - -/* - Sys_mkdir - - Creates a directory -*/ -void -Sys_mkdir (char *path) -{ - mkdir (path, 0777); -} - int Sys_FileOpenRead (char *path, int *handle) { @@ -212,41 +143,6 @@ Sys_DebugLog (char *file, char *fmt, ...) close (fd); } -void -Sys_EditFile (char *filename) -{ - char cmd[256]; - char *term; - char *editor; - - term = getenv ("TERM"); - if (term && !strcmp (term, "xterm")) { - editor = getenv ("VISUAL"); - if (!editor) - editor = getenv ("EDITOR"); - if (!editor) - editor = getenv ("EDIT"); - if (!editor) - editor = "vi"; - snprintf (cmd, sizeof (cmd), "xterm -e %s %s", editor, filename); - system (cmd); - } -} - -/* - * System I/O - */ - -void -Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length) -{ -} - -void -Sys_DebugNumber (int y, int val) -{ -} - #define MAX_PRINT_MSG 4096 void Sys_Printf (char *fmt, ...) @@ -321,18 +217,6 @@ Sys_Init (void) #endif } -void -Sys_Warn (char *warning, ...) -{ - va_list argptr; - char string[1024]; - - va_start (argptr, warning); - vsnprintf (string, sizeof (string), warning, argptr); - va_end (argptr); - fprintf (stderr, "Warning: %s", string); -} - double Sys_DoubleTime (void) { @@ -350,31 +234,8 @@ Sys_DoubleTime (void) return (tp.tv_sec - secbase) + tp.tv_usec / 1000000.0; } -// ======================================================================= -// Sleeps for microseconds -// ======================================================================= -static volatile int oktogo; - -void -alarm_handler (int x) -{ - oktogo = 1; -} - -void -Sys_LineRefresh (void) -{ -} - -void -floating_point_exception_handler (int whatever) -{ -// Sys_Warn("floating point exception\n"); - signal (SIGFPE, floating_point_exception_handler); -} - -char * +char * Sys_ConsoleInput (void) { static char text[256]; @@ -421,7 +282,6 @@ main (int argc, char *argv[]) char *newargv[256]; int j; -// signal (SIGFPE, floating_point_exception_handler); signal (SIGFPE, SIG_IGN); memset (&parms, 0, sizeof (parms)); @@ -469,3 +329,4 @@ main (int argc, char *argv[]) } return true; // return success } + diff --git a/nq/source/sys_win.c b/nq/source/sys_win.c index 2b1690cd6..58d4ce4e7 100644 --- a/nq/source/sys_win.c +++ b/nq/source/sys_win.c @@ -139,21 +139,6 @@ SYSTEM IO =============================================================================== */ -/* -================ -Sys_MakeCodeWriteable -================ -*/ -void -Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length) -{ - DWORD flOldProtect; - - if (!VirtualProtect - ((LPVOID) startaddr, length, PAGE_READWRITE, - &flOldProtect)) Sys_Error ("Protection change failed\n"); -} - #ifndef USE_INTEL_ASM @@ -301,23 +286,8 @@ Sys_Error (const char *error, ...) exit (1); } -/*FIXME? -void -Sys_Printf (const char *fmt, ...) -{ - va_list argptr; - char text[1024]; - DWORD dummy; - if (isDedicated) { - va_start (argptr, fmt); - vsnprintf (text, sizeof (text), fmt, argptr); - va_end (argptr); - WriteFile (houtput, text, strlen (text), &dummy, NULL); - } -} -*/ void Sys_Quit (void) { diff --git a/nq/source/sys_wind.c b/nq/source/sys_wind.c index 986a4d322..5de28c183 100644 --- a/nq/source/sys_wind.c +++ b/nq/source/sys_wind.c @@ -166,11 +166,6 @@ SYSTEM IO =============================================================================== */ -void -Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length) -{ -} - void Sys_DebugLog (char *file, char *fmt, ...) diff --git a/qw/source/cl_sys_sdl.c b/qw/source/cl_sys_sdl.c index 92956fd98..7a96806d5 100644 --- a/qw/source/cl_sys_sdl.c +++ b/qw/source/cl_sys_sdl.c @@ -97,35 +97,6 @@ Sys_DebugLog (char *file, char *fmt, ...) */ -void -Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length) -{ - -#ifdef _WIN32 - DWORD flOldProtect; - - // copy on write or just read-write? - if (!VirtualProtect - ((LPVOID) startaddr, length, PAGE_READWRITE, - &flOldProtect)) Sys_Error ("Protection change failed\n"); -#else - int r; - unsigned long addr; - int psize = getpagesize (); - - addr = (startaddr & ~(psize - 1)) - psize; - -// fprintf(stderr, "writable code %lx(%lx)-%lx, length=%lx\n", startaddr, -// addr, startaddr+length, length); - - r = mprotect ((char *) addr, length + startaddr - addr + psize, 7); - - if (r < 0) - Sys_Error ("Protection change failed\n"); -#endif -} - - void Sys_Init (void) { diff --git a/qw/source/cl_sys_unix.c b/qw/source/cl_sys_unix.c index 099bd1e03..8f300c2e7 100644 --- a/qw/source/cl_sys_unix.c +++ b/qw/source/cl_sys_unix.c @@ -180,12 +180,10 @@ Sys_LowFPPrecision (void) } #endif - int skipframes; - int -main (int c, char **v) +main (int c, char *v[]) { double time, oldtime, newtime; int j; @@ -228,24 +226,3 @@ main (int c, char **v) oldtime = newtime; } } - - -void -Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length) -{ - - int r; - unsigned long addr; - int psize = getpagesize (); - - addr = (startaddr & ~(psize - 1)) - psize; - -// fprintf(stderr, "writable code %lx(%lx)-%lx, length=%lx\n", startaddr, -// addr, startaddr+length, length); - - r = mprotect ((char *) addr, length + startaddr - addr + psize, 7); - - if (r < 0) - Sys_Error ("Protection change failed\n"); - -} diff --git a/qw/source/cl_sys_win.c b/qw/source/cl_sys_win.c index 964c33042..204964e31 100644 --- a/qw/source/cl_sys_win.c +++ b/qw/source/cl_sys_win.c @@ -124,18 +124,6 @@ wfilelength (VFile *f) */ -void -Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length) -{ - DWORD flOldProtect; - -//@@@ copy on write or just read-write? - if (!VirtualProtect - ((LPVOID) startaddr, length, PAGE_READWRITE, - &flOldProtect)) Sys_Error ("Protection change failed\n"); -} - - /* Sys_Init */ diff --git a/qw/source/sys_null.c b/qw/source/sys_null.c deleted file mode 100644 index ca4be0ce2..000000000 --- a/qw/source/sys_null.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - sys_null.c - - null system driver to aid porting efforts - - Copyright (C) 1996-1997 Id Software, Inc. - - 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 - - $Id$ -*/ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include - - -/* - filelength -*/ -int -filelength (VFile *f) -{ - int pos; - int end; - - pos = Qtell (f); - Qseek (f, 0, SEEK_END); - end = Qtell (f); - Qseek (f, pos, SEEK_SET); - - return end; -} - - -int -Sys_FileTime (char *path) -{ - VFile *f; - - f = Qopen (path, "rb"); - if (f) { - Qclose (f); - return 1; - } - - return -1; -} - -void -Sys_mkdir (char *path) -{ -} - - -/* - SYSTEM IO -*/ - -void -Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length) -{ -} - - -void -Sys_DebugLog (char *file, char *fmt, ...) -{ -} - -void -Sys_Error (char *error, ...) -{ - va_list argptr; - - printf ("I_Error: "); - va_start (argptr, error); - vprintf (error, argptr); - va_end (argptr); - printf ("\n"); - - exit (1); -} - -void -Sys_Printf (char *fmt, ...) -{ - va_list argptr; - - va_start (argptr, fmt); - vprintf (fmt, argptr); - va_end (argptr); -} - -void -Sys_Quit (void) -{ - exit (0); -} - -double -Sys_FloatTime (void) -{ - static double t; - - t += 0.1; - - return t; -} - -char * -Sys_ConsoleInput (void) -{ - return NULL; -} - -void -Sys_Sleep (void) -{ -} - -void -IN_SendKeyEvents (void) -{ -} - -void -Sys_HighFPPrecision (void) -{ -} - -void -Sys_LowFPPrecision (void) -{ -} - -//============================================================================= - -void -main (int argc, char **argv) -{ - host_parms.memsize = 5861376; - host_parms.membase = malloc (host_parms.memsize); - - COM_InitArgv (argc, argv); - - host_parms.argc = com_argc; - host_parms.argv = com_argv; - - printf ("Host_Init\n"); - Host_Init (); - while (1) { - Host_Frame (0.1); - } -} diff --git a/qw/source/sys_unix.c b/qw/source/sys_unix.c deleted file mode 100644 index b4ac3c68f..000000000 --- a/qw/source/sys_unix.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - sys_unix.c - - (description) - - Copyright (C) 1996-1997 Id Software, Inc. - Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se] - - 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 - - $Id$ -*/ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_STRINGS_H -#include -#endif - -#include "QF/cvar.h" -#include "host.h" -#include "QF/qargs.h" -#include "server.h" -#include "QF/sys.h" - -cvar_t *sys_nostdout; - -/* 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', '{', '|', '}', '~', '<' -}; - -#define MAXPRINTMSG 4096 -/* - Sys_Printf -*/ -void -Sys_Printf (char *fmt, ...) -{ - va_list argptr; - char msg[MAXPRINTMSG]; - - unsigned char *p; - - if (sys_nostdout && sys_nostdout->int_val) - return; - - va_start (argptr, fmt); - vsnprintf (msg, sizeof (msg), fmt, argptr); - va_end (argptr); - - /* translate to ASCII instead of printing [xx] --KB */ - for (p = (unsigned char *) msg; *p; p++) - putc (qfont_table[*p], stdout); - - fflush (stdout); -} - - -/* - Sys_mkdir -*/ -void -Sys_mkdir (char *path) -{ - if (mkdir (path, 0777) == 0) - return; - if (errno != EEXIST) - Sys_Error ("mkdir %s: %s", path, strerror (errno)); -} - - -/* - Sys_DoubleTime -*/ -double -Sys_DoubleTime (void) -{ - struct timeval tp; - struct timezone tzp; - static int secbase; - - gettimeofday (&tp, &tzp); - - if (!secbase) { - secbase = tp.tv_sec; - return tp.tv_usec / 1000000.0; - } - - return (tp.tv_sec - secbase) + tp.tv_usec / 1000000.0; -} diff --git a/qw/source/sys_win.c b/qw/source/sys_win.c deleted file mode 100644 index d74afba1e..000000000 --- a/qw/source/sys_win.c +++ /dev/null @@ -1,139 +0,0 @@ -/* - sys_win.c - - (description) - - Copyright (C) 1996-1997 Id Software, Inc. - - 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 - - $Id$ -*/ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include - -#include "compat.h" -#include "server.h" - -cvar_t *sys_nostdout; - -/* 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', '{', '|', '}', '~', '<' -}; - -/* - Sys_DoubleTime -*/ -double -Sys_DoubleTime (void) -{ - static DWORD starttime; - static qboolean first = true; - DWORD now; - - now = timeGetTime (); - - if (first) { - first = false; - starttime = now; - return 0.0; - } - - if (now < starttime) // wrapped? - return (now / 1000.0) + (LONG_MAX - starttime / 1000.0); - - if (now - starttime == 0) - return 0.0; - - return (now - starttime) / 1000.0; -} - -#define MAXPRINTMSG 4096 -/* - Sys_Printf -*/ -void -Sys_Printf (char *fmt, ...) -{ - va_list argptr; - char msg[MAXPRINTMSG]; - - unsigned char *p; - - if (sys_nostdout && sys_nostdout->int_val) - return; - - va_start (argptr, fmt); - vsnprintf (msg, sizeof (msg), fmt, argptr); - va_end (argptr); - - /* translate to ASCII instead of printing [xx] --KB */ - for (p = (unsigned char *) msg; *p; p++) - putc (qfont_table[*p], stdout); - - fflush (stdout); -} - -/* - Sys_mkdir -*/ -void -Sys_mkdir (char *path) -{ - _mkdir (path); -}