2010-02-15 23:26:55 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-2001 Id Software, Inc.
|
|
|
|
Copyright (C) 2002-2005 John Fitzgibbons and others
|
|
|
|
Copyright (C) 2007-2008 Kristian Duske
|
2014-09-22 08:55:46 +00:00
|
|
|
Copyright (C) 2010-2014 QuakeSpasm developers
|
2010-02-15 23:26:55 +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.
|
|
|
|
|
|
|
|
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 the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2014-09-10 09:47:34 +00:00
|
|
|
#include "arch_def.h"
|
2010-06-19 16:50:15 +00:00
|
|
|
#include "quakedef.h"
|
|
|
|
|
2010-02-27 07:47:16 +00:00
|
|
|
#include <sys/types.h>
|
2010-06-19 16:50:15 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
2014-09-10 09:51:35 +00:00
|
|
|
#ifdef PLATFORM_OSX
|
|
|
|
#include <libgen.h> /* dirname() and basename() */
|
|
|
|
#endif
|
2010-02-27 07:47:16 +00:00
|
|
|
#include <sys/stat.h>
|
2010-06-19 16:50:15 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <time.h>
|
2014-09-10 07:28:28 +00:00
|
|
|
#ifdef DO_USERDIRS
|
|
|
|
#include <pwd.h>
|
|
|
|
#endif
|
2010-02-27 07:47:16 +00:00
|
|
|
|
2012-08-16 04:51:41 +00:00
|
|
|
#if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG)
|
2014-09-05 19:34:43 +00:00
|
|
|
#if defined(USE_SDL2)
|
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
#else
|
2012-08-16 04:51:41 +00:00
|
|
|
#include <SDL/SDL.h>
|
2014-09-05 19:34:43 +00:00
|
|
|
#endif
|
2012-08-16 04:51:41 +00:00
|
|
|
#else
|
2010-06-19 22:50:48 +00:00
|
|
|
#include "SDL.h"
|
2012-08-16 04:51:41 +00:00
|
|
|
#endif
|
2010-06-19 22:50:48 +00:00
|
|
|
|
2010-06-22 11:01:24 +00:00
|
|
|
|
2010-02-17 23:32:04 +00:00
|
|
|
qboolean isDedicated;
|
2011-12-28 22:01:33 +00:00
|
|
|
cvar_t sys_throttle = {"sys_throttle", "0.02", CVAR_ARCHIVE};
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2019-10-04 21:19:49 +00:00
|
|
|
static size_t sys_handles_max; /* spike -- removed limit, was 32 (johnfitz -- was 10) */
|
|
|
|
static FILE **sys_handles;
|
2010-06-22 11:01:24 +00:00
|
|
|
static int findhandle (void)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2019-10-04 21:19:49 +00:00
|
|
|
size_t i, n;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2019-10-04 21:19:49 +00:00
|
|
|
for (i = 1; i < sys_handles_max; i++)
|
2010-06-22 11:01:24 +00:00
|
|
|
{
|
2010-02-17 23:32:04 +00:00
|
|
|
if (!sys_handles[i])
|
|
|
|
return i;
|
2010-06-22 11:01:24 +00:00
|
|
|
}
|
2019-10-04 21:19:49 +00:00
|
|
|
n = sys_handles_max+10;
|
|
|
|
sys_handles = realloc(sys_handles, sizeof(*sys_handles)*n);
|
|
|
|
if (!sys_handles)
|
|
|
|
Sys_Error ("out of handles");
|
|
|
|
while (sys_handles_max < n)
|
|
|
|
sys_handles[sys_handles_max++] = NULL;
|
|
|
|
return i;
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
2011-02-10 17:25:43 +00:00
|
|
|
long Sys_filelength (FILE *f)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2011-02-10 17:25:43 +00:00
|
|
|
long pos, end;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2010-02-17 23:32:04 +00:00
|
|
|
pos = ftell (f);
|
|
|
|
fseek (f, 0, SEEK_END);
|
|
|
|
end = ftell (f);
|
|
|
|
fseek (f, pos, SEEK_SET);
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2010-02-17 23:32:04 +00:00
|
|
|
return end;
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
2010-08-29 02:22:55 +00:00
|
|
|
int Sys_FileOpenRead (const char *path, int *hndl)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
FILE *f;
|
2010-06-22 11:01:24 +00:00
|
|
|
int i, retval;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
i = findhandle ();
|
|
|
|
f = fopen(path, "rb");
|
|
|
|
|
|
|
|
if (!f)
|
|
|
|
{
|
|
|
|
*hndl = -1;
|
|
|
|
retval = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sys_handles[i] = f;
|
|
|
|
*hndl = i;
|
2010-02-27 07:45:12 +00:00
|
|
|
retval = Sys_filelength(f);
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-08-29 02:22:55 +00:00
|
|
|
int Sys_FileOpenWrite (const char *path)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = findhandle ();
|
|
|
|
f = fopen(path, "wb");
|
|
|
|
|
|
|
|
if (!f)
|
|
|
|
Sys_Error ("Error opening %s: %s", path, strerror(errno));
|
2010-02-17 23:32:04 +00:00
|
|
|
|
|
|
|
sys_handles[i] = f;
|
2010-02-15 23:26:55 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2017-09-17 02:12:53 +00:00
|
|
|
int Sys_FileOpenStdio (FILE *file)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
i = findhandle ();
|
|
|
|
sys_handles[i] = file;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2010-02-15 23:26:55 +00:00
|
|
|
void Sys_FileClose (int handle)
|
|
|
|
{
|
|
|
|
fclose (sys_handles[handle]);
|
|
|
|
sys_handles[handle] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sys_FileSeek (int handle, int position)
|
|
|
|
{
|
|
|
|
fseek (sys_handles[handle], position, SEEK_SET);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Sys_FileRead (int handle, void *dest, int count)
|
|
|
|
{
|
|
|
|
return fread (dest, 1, count, sys_handles[handle]);
|
|
|
|
}
|
|
|
|
|
2010-08-29 02:22:55 +00:00
|
|
|
int Sys_FileWrite (int handle, const void *data, int count)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
return fwrite (data, 1, count, sys_handles[handle]);
|
|
|
|
}
|
|
|
|
|
2010-08-29 02:22:55 +00:00
|
|
|
int Sys_FileTime (const char *path)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2010-02-17 23:32:04 +00:00
|
|
|
FILE *f;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2010-02-17 23:32:04 +00:00
|
|
|
f = fopen(path, "rb");
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2010-02-17 23:32:04 +00:00
|
|
|
if (f)
|
|
|
|
{
|
|
|
|
fclose(f);
|
|
|
|
return 1;
|
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2010-02-17 23:32:04 +00:00
|
|
|
return -1;
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
2014-11-03 09:10:18 +00:00
|
|
|
|
|
|
|
#if defined(__linux__) || defined(__sun) || defined(sun) || defined(_AIX)
|
|
|
|
static int Sys_NumCPUs (void)
|
|
|
|
{
|
|
|
|
int numcpus = sysconf(_SC_NPROCESSORS_ONLN);
|
|
|
|
return (numcpus < 1) ? 1 : numcpus;
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(PLATFORM_OSX)
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#if !defined(HW_AVAILCPU) /* using an ancient SDK? */
|
|
|
|
#define HW_AVAILCPU 25 /* needs >= 10.2 */
|
|
|
|
#endif
|
|
|
|
static int Sys_NumCPUs (void)
|
|
|
|
{
|
|
|
|
int numcpus;
|
|
|
|
int mib[2];
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
#if defined(_SC_NPROCESSORS_ONLN) /* needs >= 10.5 */
|
|
|
|
numcpus = sysconf(_SC_NPROCESSORS_ONLN);
|
|
|
|
if (numcpus != -1)
|
|
|
|
return (numcpus < 1) ? 1 : numcpus;
|
|
|
|
#endif
|
|
|
|
len = sizeof(numcpus);
|
|
|
|
mib[0] = CTL_HW;
|
|
|
|
mib[1] = HW_AVAILCPU;
|
|
|
|
sysctl(mib, 2, &numcpus, &len, NULL, 0);
|
|
|
|
if (sysctl(mib, 2, &numcpus, &len, NULL, 0) == -1)
|
|
|
|
{
|
|
|
|
mib[1] = HW_NCPU;
|
|
|
|
if (sysctl(mib, 2, &numcpus, &len, NULL, 0) == -1)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return (numcpus < 1) ? 1 : numcpus;
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(__sgi) || defined(sgi) || defined(__sgi__) /* IRIX */
|
|
|
|
static int Sys_NumCPUs (void)
|
|
|
|
{
|
|
|
|
int numcpus = sysconf(_SC_NPROC_ONLN);
|
|
|
|
if (numcpus < 1)
|
|
|
|
numcpus = 1;
|
|
|
|
return numcpus;
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(PLATFORM_BSD)
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
static int Sys_NumCPUs (void)
|
|
|
|
{
|
|
|
|
int numcpus;
|
|
|
|
int mib[2];
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
#if defined(_SC_NPROCESSORS_ONLN)
|
|
|
|
numcpus = sysconf(_SC_NPROCESSORS_ONLN);
|
|
|
|
if (numcpus != -1)
|
|
|
|
return (numcpus < 1) ? 1 : numcpus;
|
|
|
|
#endif
|
|
|
|
len = sizeof(numcpus);
|
|
|
|
mib[0] = CTL_HW;
|
|
|
|
mib[1] = HW_NCPU;
|
|
|
|
if (sysctl(mib, 2, &numcpus, &len, NULL, 0) == -1)
|
|
|
|
return 1;
|
|
|
|
return (numcpus < 1) ? 1 : numcpus;
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(__hpux) || defined(__hpux__) || defined(_hpux)
|
|
|
|
#include <sys/mpctl.h>
|
|
|
|
static int Sys_NumCPUs (void)
|
|
|
|
{
|
|
|
|
int numcpus = mpctl(MPC_GETNUMSPUS, NULL, NULL);
|
|
|
|
return numcpus;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* unknown OS */
|
|
|
|
static int Sys_NumCPUs (void)
|
|
|
|
{
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-09-10 09:51:35 +00:00
|
|
|
static char cwd[MAX_OSPATH];
|
2014-09-10 07:28:28 +00:00
|
|
|
#ifdef DO_USERDIRS
|
|
|
|
static char userdir[MAX_OSPATH];
|
|
|
|
#ifdef PLATFORM_OSX
|
|
|
|
#define SYS_USERDIR "Library/Application Support/QuakeSpasm"
|
|
|
|
#else
|
|
|
|
#define SYS_USERDIR ".quakespasm"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void Sys_GetUserdir (char *dst, size_t dstsize)
|
|
|
|
{
|
|
|
|
size_t n;
|
|
|
|
const char *home_dir = NULL;
|
|
|
|
struct passwd *pwent;
|
|
|
|
|
|
|
|
pwent = getpwuid( getuid() );
|
|
|
|
if (pwent == NULL)
|
|
|
|
perror("getpwuid");
|
|
|
|
else
|
|
|
|
home_dir = pwent->pw_dir;
|
|
|
|
if (home_dir == NULL)
|
|
|
|
home_dir = getenv("HOME");
|
|
|
|
if (home_dir == NULL)
|
|
|
|
Sys_Error ("Couldn't determine userspace directory");
|
|
|
|
|
|
|
|
/* what would be a maximum path for a file in the user's directory...
|
|
|
|
* $HOME/SYS_USERDIR/game_dir/dirname1/dirname2/dirname3/filename.ext
|
|
|
|
* still fits in the MAX_OSPATH == 256 definition, but just in case :
|
|
|
|
*/
|
|
|
|
n = strlen(home_dir) + strlen(SYS_USERDIR) + 50;
|
|
|
|
if (n >= dstsize)
|
|
|
|
Sys_Error ("Insufficient array size for userspace directory");
|
|
|
|
|
|
|
|
q_snprintf (dst, dstsize, "%s/%s", home_dir, SYS_USERDIR);
|
|
|
|
}
|
|
|
|
#endif /* DO_USERDIRS */
|
|
|
|
|
2014-09-10 09:51:35 +00:00
|
|
|
#ifdef PLATFORM_OSX
|
|
|
|
static char *OSX_StripAppBundle (char *dir)
|
|
|
|
{ /* based on the ioquake3 project at icculus.org. */
|
|
|
|
static char osx_path[MAX_OSPATH];
|
|
|
|
|
|
|
|
q_strlcpy (osx_path, dir, sizeof(osx_path));
|
|
|
|
if (strcmp(basename(osx_path), "MacOS"))
|
|
|
|
return dir;
|
|
|
|
q_strlcpy (osx_path, dirname(osx_path), sizeof(osx_path));
|
|
|
|
if (strcmp(basename(osx_path), "Contents"))
|
|
|
|
return dir;
|
|
|
|
q_strlcpy (osx_path, dirname(osx_path), sizeof(osx_path));
|
|
|
|
if (!strstr(basename(osx_path), ".app"))
|
|
|
|
return dir;
|
|
|
|
q_strlcpy (osx_path, dirname(osx_path), sizeof(osx_path));
|
|
|
|
return osx_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Sys_GetBasedir (char *argv0, char *dst, size_t dstsize)
|
|
|
|
{
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
if (realpath(argv0, dst) == NULL)
|
|
|
|
{
|
|
|
|
perror("realpath");
|
|
|
|
if (getcwd(dst, dstsize - 1) == NULL)
|
|
|
|
_fail: Sys_Error ("Couldn't determine current directory");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* strip off the binary name */
|
|
|
|
if (! (tmp = strdup (dst))) goto _fail;
|
|
|
|
q_strlcpy (dst, dirname(tmp), dstsize);
|
|
|
|
free (tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = OSX_StripAppBundle(dst);
|
|
|
|
if (tmp != dst)
|
|
|
|
q_strlcpy (dst, tmp, dstsize);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void Sys_GetBasedir (char *argv0, char *dst, size_t dstsize)
|
|
|
|
{
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
if (getcwd(dst, dstsize - 1) == NULL)
|
|
|
|
Sys_Error ("Couldn't determine current directory");
|
|
|
|
|
|
|
|
tmp = dst;
|
|
|
|
while (*tmp != 0)
|
|
|
|
tmp++;
|
|
|
|
while (*tmp == 0 && tmp != dst)
|
|
|
|
{
|
|
|
|
--tmp;
|
|
|
|
if (tmp != dst && *tmp == '/')
|
|
|
|
*tmp = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-06-22 11:01:24 +00:00
|
|
|
void Sys_Init (void)
|
|
|
|
{
|
2014-09-10 09:51:35 +00:00
|
|
|
memset (cwd, 0, sizeof(cwd));
|
|
|
|
Sys_GetBasedir(host_parms->argv[0], cwd, sizeof(cwd));
|
|
|
|
host_parms->basedir = cwd;
|
2014-09-10 07:28:28 +00:00
|
|
|
#ifndef DO_USERDIRS
|
|
|
|
host_parms->userdir = host_parms->basedir; /* code elsewhere relies on this ! */
|
|
|
|
#else
|
2014-09-10 09:51:35 +00:00
|
|
|
memset (userdir, 0, sizeof(userdir));
|
2014-09-10 07:28:28 +00:00
|
|
|
Sys_GetUserdir(userdir, sizeof(userdir));
|
|
|
|
Sys_mkdir (userdir);
|
|
|
|
host_parms->userdir = userdir;
|
|
|
|
#endif
|
2014-11-03 09:10:18 +00:00
|
|
|
host_parms->numcpus = Sys_NumCPUs ();
|
|
|
|
Sys_Printf("Detected %d CPUs.\n", host_parms->numcpus);
|
2010-06-22 11:01:24 +00:00
|
|
|
}
|
|
|
|
|
2010-08-29 02:22:55 +00:00
|
|
|
void Sys_mkdir (const char *path)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2010-02-27 07:47:16 +00:00
|
|
|
int rc = mkdir (path, 0777);
|
2011-12-12 10:50:26 +00:00
|
|
|
if (rc != 0 && errno == EEXIST)
|
2014-04-24 08:10:15 +00:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
if (stat(path, &st) == 0 && S_ISDIR(st.st_mode))
|
|
|
|
rc = 0;
|
|
|
|
}
|
2011-12-12 10:50:26 +00:00
|
|
|
if (rc != 0)
|
|
|
|
{
|
|
|
|
rc = errno;
|
|
|
|
Sys_Error("Unable to create directory %s: %s", path, strerror(rc));
|
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
2010-06-22 11:01:24 +00:00
|
|
|
static const char errortxt1[] = "\nERROR-OUT BEGIN\n\n";
|
|
|
|
static const char errortxt2[] = "\nQUAKE ERROR: ";
|
2010-02-15 23:26:55 +00:00
|
|
|
|
Constified Con_DebugLog, Con_Print, Con_Printf, Con_Warning, Con_DPrintf,
Con_DPrintf2, Con_SafePrintf, Con_CenterPrintf, Con_LogCenterPrint,
Con_NotifyBox, PL_ErrorDialog, PR_RunError, Host_EndGame, Host_Error,
SV_ClientPrintf, SV_BroadcastPrintf, Host_ClientCommands, Sys_DebugLog,
Sys_Error, Sys_Printf, BOPS_Error and va. Added noreturn attribute to
Sys_Error, Sys_Quit, BOPS_Error, PR_RunError, Host_EndGame and Host_Error.
Added format printf attribute to Con_DebugLog, Con_Printf, Con_Warning,
Con_DPrintf, Con_DPrintf2, Con_SafePrintf, Con_CenterPrintf, PL_ErrorDialog,
PR_RunError, Host_EndGame, Host_Error, SV_ClientPrintf, SV_BroadcastPrintf,
Host_ClientCommands, Sys_DebugLog, Sys_Error, Sys_Printf and va. Adjusted
Host_Status_f and NET_Ban_f for the new attributes. Fixed broken format
strings in Con_Dump_f, Mod_LoadTexinfo, PR_AllocStringSlots and FloorDivMod.
Defined __attribute__ macros in quakedef.h so that we don't break non-gcc
compilers.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@154 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-04-26 16:30:40 +00:00
|
|
|
void Sys_Error (const char *error, ...)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2010-02-17 23:32:04 +00:00
|
|
|
va_list argptr;
|
2010-06-22 11:01:24 +00:00
|
|
|
char text[1024];
|
2010-02-17 23:32:04 +00:00
|
|
|
|
2018-02-21 07:33:07 +00:00
|
|
|
host_parms->errstate++;
|
2010-02-17 23:32:04 +00:00
|
|
|
|
|
|
|
va_start (argptr, error);
|
2010-08-31 16:57:12 +00:00
|
|
|
q_vsnprintf (text, sizeof(text), error, argptr);
|
2010-02-17 23:32:04 +00:00
|
|
|
va_end (argptr);
|
|
|
|
|
2018-02-21 07:33:07 +00:00
|
|
|
fputs (errortxt1, stderr);
|
2017-09-17 02:12:53 +00:00
|
|
|
Con_Redirect(NULL);
|
2018-05-01 00:35:14 +00:00
|
|
|
PR_SwitchQCVM(NULL);
|
2018-02-21 07:33:07 +00:00
|
|
|
Host_Shutdown ();
|
2010-06-22 11:01:24 +00:00
|
|
|
fputs (errortxt2, stderr);
|
|
|
|
fputs (text, stderr);
|
|
|
|
fputs ("\n\n", stderr);
|
|
|
|
if (!isDedicated)
|
2010-02-17 23:32:04 +00:00
|
|
|
PL_ErrorDialog(text);
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
Constified Con_DebugLog, Con_Print, Con_Printf, Con_Warning, Con_DPrintf,
Con_DPrintf2, Con_SafePrintf, Con_CenterPrintf, Con_LogCenterPrint,
Con_NotifyBox, PL_ErrorDialog, PR_RunError, Host_EndGame, Host_Error,
SV_ClientPrintf, SV_BroadcastPrintf, Host_ClientCommands, Sys_DebugLog,
Sys_Error, Sys_Printf, BOPS_Error and va. Added noreturn attribute to
Sys_Error, Sys_Quit, BOPS_Error, PR_RunError, Host_EndGame and Host_Error.
Added format printf attribute to Con_DebugLog, Con_Printf, Con_Warning,
Con_DPrintf, Con_DPrintf2, Con_SafePrintf, Con_CenterPrintf, PL_ErrorDialog,
PR_RunError, Host_EndGame, Host_Error, SV_ClientPrintf, SV_BroadcastPrintf,
Host_ClientCommands, Sys_DebugLog, Sys_Error, Sys_Printf and va. Adjusted
Host_Status_f and NET_Ban_f for the new attributes. Fixed broken format
strings in Con_Dump_f, Mod_LoadTexinfo, PR_AllocStringSlots and FloorDivMod.
Defined __attribute__ macros in quakedef.h so that we don't break non-gcc
compilers.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@154 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-04-26 16:30:40 +00:00
|
|
|
void Sys_Printf (const char *fmt, ...)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2010-02-17 23:32:04 +00:00
|
|
|
va_list argptr;
|
|
|
|
|
2010-06-22 11:01:24 +00:00
|
|
|
va_start(argptr, fmt);
|
|
|
|
vprintf(fmt, argptr);
|
|
|
|
va_end(argptr);
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sys_Quit (void)
|
|
|
|
{
|
|
|
|
Host_Shutdown();
|
|
|
|
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
2011-12-12 16:01:01 +00:00
|
|
|
double Sys_DoubleTime (void)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2010-02-17 23:32:04 +00:00
|
|
|
return SDL_GetTicks() / 1000.0;
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
2011-12-12 12:02:37 +00:00
|
|
|
const char *Sys_ConsoleInput (void)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2010-06-19 16:50:15 +00:00
|
|
|
static char con_text[256];
|
|
|
|
static int textlen;
|
|
|
|
char c;
|
|
|
|
fd_set set;
|
|
|
|
struct timeval timeout;
|
|
|
|
|
|
|
|
FD_ZERO (&set);
|
|
|
|
FD_SET (0, &set); // stdin
|
|
|
|
timeout.tv_sec = 0;
|
|
|
|
timeout.tv_usec = 0;
|
|
|
|
|
|
|
|
while (select (1, &set, NULL, NULL, &timeout))
|
|
|
|
{
|
|
|
|
read (0, &c, 1);
|
|
|
|
if (c == '\n' || c == '\r')
|
|
|
|
{
|
|
|
|
con_text[textlen] = '\0';
|
|
|
|
textlen = 0;
|
|
|
|
return con_text;
|
|
|
|
}
|
|
|
|
else if (c == 8)
|
|
|
|
{
|
|
|
|
if (textlen)
|
|
|
|
{
|
|
|
|
textlen--;
|
|
|
|
con_text[textlen] = '\0';
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
con_text[textlen] = c;
|
|
|
|
textlen++;
|
2011-12-29 19:06:08 +00:00
|
|
|
if (textlen < (int) sizeof(con_text))
|
2010-06-19 16:50:15 +00:00
|
|
|
con_text[textlen] = '\0';
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// buffer is full
|
|
|
|
textlen = 0;
|
|
|
|
con_text[0] = '\0';
|
|
|
|
Sys_Printf("\nConsole input too long!\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
2011-12-12 16:01:01 +00:00
|
|
|
void Sys_Sleep (unsigned long msecs)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2011-12-21 10:40:18 +00:00
|
|
|
/* usleep (msecs * 1000);*/
|
|
|
|
SDL_Delay (msecs);
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sys_SendKeyEvents (void)
|
|
|
|
{
|
2016-03-01 21:58:08 +00:00
|
|
|
IN_Commands(); //ericw -- allow joysticks to add keys so they can be used to confirm SCR_ModalMessage
|
2011-12-16 14:11:37 +00:00
|
|
|
IN_SendKeyEvents();
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|