revert kntbrds recent sys changes as they break sw static builds

This commit is contained in:
Bill Currie 2001-07-05 00:12:43 +00:00
parent ce3eddb89c
commit e659c2a44f
10 changed files with 703 additions and 22 deletions

View File

@ -36,9 +36,7 @@ extern struct cvar_s *sys_nostdout;
int Sys_FileTime (const char *path);
void Sys_mkdir (const char *path);
//void Sys_Printf (const char *fmt, ...) __attribute__((format(printf,1,2)));
extern void (*Sys_Printf) (const char *fmt, ...);
void Sys_StdPrintf (const char *fmt, ...) __attribute__((format(printf,1,2)));
void Sys_Printf (const char *fmt, ...) __attribute__((format(printf,1,2)));
void Sys_Error (const char *error, ...) __attribute__((format(printf,1,2)));
void Sys_Quit (void);
double Sys_DoubleTime (void);

View File

@ -139,10 +139,10 @@ Sys_FileTime (const char *path)
}
/*
Sys_StdPrintf
Sys_Printf
*/
void
Sys_StdPrintf (const char *fmt, ...)
Sys_Printf (const char *fmt, ...)
{
va_list argptr;
char msg[MAXPRINTMSG];

View File

@ -81,11 +81,54 @@ 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, ...)
@ -123,6 +166,34 @@ 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)
@ -131,7 +202,7 @@ floating_point_exception_handler (int whatever)
signal (SIGFPE, floating_point_exception_handler);
}
char *
char *
Sys_ConsoleInput (void)
{
static char text[256];
@ -170,10 +241,8 @@ Sys_LowFPPrecision (void)
#endif
void (*Sys_Printf) (const char *fmt, ...);
int
main (int c, char *v[])
main (int c, char **v)
{
double time, oldtime, newtime;
@ -182,9 +251,10 @@ main (int c, char *v[])
extern int recording;
int j;
signal (SIGFPE, SIG_IGN);
// static char cwd[1024];
Sys_Printf = Sys_StdPrintf;
// signal(SIGFPE, floating_point_exception_handler);
signal (SIGFPE, SIG_IGN);
memset (&parms, 0, sizeof (parms));
@ -240,7 +310,9 @@ main (int c, char *v[])
Host_Frame (time);
// graphic debugging aids
// if (sys_linerefresh->value)
// Sys_LineRefresh ();
}
}

View File

@ -71,6 +71,75 @@ 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)
{
@ -143,6 +212,41 @@ 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, ...)
@ -217,6 +321,18 @@ 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)
{
@ -234,8 +350,31 @@ Sys_DoubleTime (void)
return (tp.tv_sec - secbase) + tp.tv_usec / 1000000.0;
}
// =======================================================================
// Sleeps for microseconds
// =======================================================================
char *
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 *
Sys_ConsoleInput (void)
{
static char text[256];
@ -282,6 +421,7 @@ 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));
@ -329,4 +469,3 @@ main (int argc, char *argv[])
}
return true; // return success
}

View File

@ -301,8 +301,23 @@ 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)
{

View File

@ -180,12 +180,12 @@ Sys_LowFPPrecision (void)
}
#endif
void (*Sys_Printf) (const char *fmt, ...);
int skipframes;
int
main (int c, char *v[])
main (int c, char **v)
{
double time, oldtime, newtime;
int j;
@ -195,8 +195,6 @@ main (int c, char *v[])
// signal(SIGFPE, floating_point_exception_handler);
signal (SIGFPE, SIG_IGN);
Sys_Printf = Sys_StdPrintf;
memset (&host_parms, 0, sizeof (host_parms));
COM_InitArgv (c, v);

View File

@ -155,8 +155,6 @@ Sys_Init (void)
#endif
}
void (*Sys_Printf) (const char *fmt, ...);
/*
main
*/
@ -168,8 +166,6 @@ main (int argc, char *argv[])
extern int net_socket;
int j;
Sys_Printf = Sys_StdPrintf;
memset (&host_parms, 0, sizeof (host_parms));
COM_InitArgv (argc, argv);

173
qw/source/sys_null.c Normal file
View File

@ -0,0 +1,173 @@
/*
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);
}
}

151
qw/source/sys_unix.c Normal file
View File

@ -0,0 +1,151 @@
/*
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;
}

139
qw/source/sys_win.c Normal file
View File

@ -0,0 +1,139 @@
/*
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);
}