mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-21 18:01:15 +00:00
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.
This commit is contained in:
parent
e659c2a44f
commit
b4ac2446a1
13 changed files with 38 additions and 789 deletions
|
@ -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=""
|
||||
|
|
|
@ -52,6 +52,9 @@
|
|||
#ifdef HAVE_WINDOWS_H
|
||||
# include <windows.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_MMAN_H
|
||||
# include <sys/mman.h>
|
||||
#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
|
||||
}
|
||||
|
|
|
@ -162,11 +162,6 @@ SYSTEM IO
|
|||
===============================================================================
|
||||
*/
|
||||
|
||||
void
|
||||
Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Sys_Error (char *error, ...)
|
||||
|
|
|
@ -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 ();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -166,11 +166,6 @@ SYSTEM IO
|
|||
===============================================================================
|
||||
*/
|
||||
|
||||
void
|
||||
Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Sys_DebugLog (char *file, char *fmt, ...)
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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");
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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 <errno.h>
|
||||
|
||||
|
||||
/*
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -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 <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRINGS_H
|
||||
#include <strings.h>
|
||||
#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;
|
||||
}
|
|
@ -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 <limits.h>
|
||||
#include <direct.h>
|
||||
#include <windows.h>
|
||||
|
||||
#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);
|
||||
}
|
Loading…
Reference in a new issue