2000-05-10 20:33:16 +00:00
|
|
|
/*
|
2000-05-11 16:03:29 +00:00
|
|
|
sys_unix.c
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
(description)
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
2000-05-20 02:00:28 +00:00
|
|
|
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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$
|
2000-05-10 20:33:16 +00:00
|
|
|
*/
|
2000-05-11 16:03:29 +00:00
|
|
|
|
2000-05-17 10:03:19 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
2000-05-21 08:24:45 +00:00
|
|
|
#include "sys.h"
|
|
|
|
#include "qargs.h"
|
|
|
|
#include "cvar.h"
|
|
|
|
#include "server.h"
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-05-20 02:00:28 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2000-05-14 18:39:37 +00:00
|
|
|
#include <errno.h>
|
2000-05-10 11:29:38 +00:00
|
|
|
#include <unistd.h>
|
2000-05-14 18:39:37 +00:00
|
|
|
#include <sys/stat.h>
|
2000-05-10 11:29:38 +00:00
|
|
|
#include <sys/time.h>
|
2000-05-14 18:39:37 +00:00
|
|
|
|
2000-05-20 02:00:28 +00:00
|
|
|
#include "sys.h"
|
|
|
|
#include "quakedef.h"
|
|
|
|
|
2000-05-21 19:59:44 +00:00
|
|
|
/* This is unused in the client, but we need the symbol there too. */
|
|
|
|
server_static_t svs;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-05-16 04:47:41 +00:00
|
|
|
cvar_t *sys_nostdout;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-05-20 02:00:28 +00:00
|
|
|
/* 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', '{', '|', '}', '~', '<'
|
|
|
|
};
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-05-20 02:00:28 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
Sys_Printf
|
|
|
|
================
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-05-20 02:00:28 +00:00
|
|
|
void Sys_Printf (char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
char text[2048];
|
|
|
|
unsigned char *p;
|
|
|
|
|
|
|
|
if (sys_nostdout->value) return;
|
|
|
|
|
|
|
|
va_start(argptr,fmt);
|
|
|
|
vsnprintf(text, sizeof(text), fmt, argptr);
|
|
|
|
va_end(argptr);
|
|
|
|
|
|
|
|
/* translate to ASCII instead of printing [xx] --KB */
|
|
|
|
for (p = (unsigned char *)text; *p; p++)
|
|
|
|
putc(qfont_table[*p], stdout);
|
2000-07-19 07:25:03 +00:00
|
|
|
|
|
|
|
fflush (stdout);
|
2000-05-20 02:00:28 +00:00
|
|
|
}
|
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
Sys_FileTime
|
|
|
|
|
|
|
|
returns -1 if not present
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
int Sys_FileTime (char *path)
|
|
|
|
{
|
2000-05-20 02:00:28 +00:00
|
|
|
struct stat buf;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-05-20 02:00:28 +00:00
|
|
|
if (stat(path,&buf) == -1) return -1;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
return buf.st_mtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
Sys_mkdir
|
|
|
|
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
void Sys_mkdir (char *path)
|
|
|
|
{
|
2000-05-20 02:00:28 +00:00
|
|
|
if (mkdir(path, 0777) == 0) return;
|
|
|
|
if (errno != EEXIST) Sys_Error("mkdir %s: %s",path, strerror(errno));
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
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;
|
|
|
|
}
|