redo Sys_Error so it's more usable throughout quake

This commit is contained in:
Bill Currie 2002-02-20 19:22:52 +00:00
parent ea79349c2d
commit 8ee5acb208
17 changed files with 83 additions and 75 deletions

View file

@ -29,6 +29,7 @@
#ifndef __sys_h
#define __sys_h
#include <stdio.h>
#include <stdarg.h>
#include "QF/gcc_attr.h"
@ -48,8 +49,10 @@ void Sys_mkdir (const char *path);
typedef void (*sys_printf_t) (const char *fmt, va_list args);
void Sys_SetPrintf (sys_printf_t func);
void Sys_SetStdPrintf (sys_printf_t func);
void Sys_SetErrPrintf (sys_printf_t func);
void Sys_Print (FILE *stream, const char *fmt, va_list args);
void Sys_Printf (const char *fmt, ...) __attribute__((format(printf,1,2)));
void Sys_DPrintf (const char *fmt, ...) __attribute__((format(printf,1,2)));
void Sys_Error (const char *error, ...) __attribute__((format(printf,1,2), noreturn));

View file

@ -58,7 +58,7 @@ Con_Init (const char *plugin_name)
con_module = PI_LoadPlugin ("console", plugin_name);
if (con_module) {
con_module->functions->general->p_Init ();
Sys_SetPrintf (con_module->functions->console->pC_Print);
Sys_SetStdPrintf (con_module->functions->console->pC_Print);
} else {
setvbuf (stdout, 0, _IOLBF, BUFSIZ);
}

View file

@ -65,6 +65,7 @@ static const char rcsid[] =
#include "compat.h"
static void Sys_StdPrintf (const char *fmt, va_list args);
static void Sys_ErrPrintf (const char *fmt, va_list args);
cvar_t *sys_nostdout;
cvar_t *sys_extrasleep;
@ -73,7 +74,8 @@ cvar_t *sys_sleep;
int sys_checksum;
static sys_printf_t sys_printf_function = Sys_StdPrintf;
static sys_printf_t sys_std_printf_function = Sys_StdPrintf;
static sys_printf_t sys_err_printf_function = Sys_ErrPrintf;
typedef struct shutdown_list_s {
struct shutdown_list_s *next;
@ -169,28 +171,50 @@ Sys_FileTime (const char *path)
actual implementation of Sys_Printf.
*/
void
Sys_SetPrintf (sys_printf_t func)
Sys_SetStdPrintf (sys_printf_t func)
{
sys_printf_function = func;
sys_std_printf_function = func;
}
void
Sys_SetErrPrintf (sys_printf_t func)
{
sys_err_printf_function = func;
}
void
Sys_Print (FILE *stream, const char *fmt, va_list args)
{
char msg[MAXPRINTMSG];
unsigned char *p;
vsnprintf (msg, sizeof (msg), fmt, args);
#ifdef WIN32
if (stream == stderr)
MessageBox (NULL, string, "Error", 0 /* MB_OK */ );
#endif
/* translate to ASCII instead of printing [xx] --KB */
for (p = (unsigned char *) msg; *p; p++)
putc (sys_char_map[*p], stream);
fflush (stream);
}
static void
Sys_StdPrintf (const char *fmt, va_list args)
{
char msg[MAXPRINTMSG];
unsigned char *p;
if (sys_nostdout && sys_nostdout->int_val)
return;
Sys_Print (stdout, fmt, args);
}
vsnprintf (msg, sizeof (msg), fmt, args);
/* translate to ASCII instead of printing [xx] --KB */
for (p = (unsigned char *) msg; *p; p++)
putc (sys_char_map[*p], stdout);
fflush (stdout);
static void
Sys_ErrPrintf (const char *fmt, va_list args)
{
fprintf (stderr, "Fatal Error: ");
Sys_Print (stderr, fmt, args);
}
void
@ -198,7 +222,7 @@ Sys_Printf (const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
sys_printf_function (fmt, args);
sys_std_printf_function (fmt, args);
va_end (args);
}
@ -210,7 +234,7 @@ Sys_DPrintf (const char *fmt, ...)
if (!developer || !developer->int_val)
return;
va_start (args, fmt);
sys_printf_function (fmt, args);
sys_std_printf_function (fmt, args);
va_end (args);
}
@ -326,17 +350,11 @@ void
Sys_Error (const char *error, ...)
{
va_list argptr;
char string[1024];
va_start (argptr, error);
vsnprintf (string, sizeof (string), error, argptr);
sys_err_printf_function (error, argptr);
va_end (argptr);
#ifdef WIN32
MessageBox (NULL, string, "Error", 0 /* MB_OK */ );
#endif
fprintf (stderr, "Fatal error: %s\n", string);
run_shutdown_list ();
exit (1);

View file

@ -267,8 +267,6 @@ void SV_RunClients (void);
void SV_SaveSpawnparms ();
void SV_SpawnServer (const char *server);
void SV_Error (const char *error, ...) __attribute__((format(printf,1,2)));
void SV_LoadProgs (void);
void SV_Progs_Init (void);
void SV_Progs_Init_Cvars (void);

View file

@ -170,7 +170,6 @@ Host_Error (const char *error, ...)
va_start (argptr, error);
vsnprintf (string, sizeof (string), error, argptr);
va_end (argptr);
Con_Printf ("Host_Error: %s\n", string);
if (sv.active)
Host_ShutdownServer (false);
@ -178,6 +177,8 @@ Host_Error (const char *error, ...)
if (cls.state == ca_dedicated)
Sys_Error ("Host_Error: %s\n", string); // dedicated servers exit
Con_Printf ("Host_Error: %s\n", string);
CL_Disconnect ();
cls.demonum = -1;

View file

@ -1040,16 +1040,3 @@ SV_SpawnServer (const char *server)
Con_DPrintf ("Server spawned.\n");
}
void
SV_Error (const char *error, ...)
{
va_list argptr;
static char string[1024];
va_start (argptr, error);
vsnprintf (string, sizeof (string), error, argptr);
va_end (argptr);
Host_Error ("%s", string);
}

View file

@ -42,6 +42,7 @@ static const char rcsid[] =
#include "QF/clip_hull.h"
#include "QF/console.h"
#include "QF/crc.h"
#include "QF/sys.h"
#include "compat.h"
#include "server.h"
@ -166,12 +167,12 @@ SV_HullForEntity (edict_t *ent, const vec3_t mins, const vec3_t maxs,
} if (SVfloat (ent, solid) == SOLID_BSP) {
// explicit hulls in the BSP model
if (SVfloat (ent, movetype) != MOVETYPE_PUSH)
SV_Error ("SOLID_BSP without MOVETYPE_PUSH");
Sys_Error ("SOLID_BSP without MOVETYPE_PUSH");
model = sv.models[(int) SVfloat (ent, modelindex)];
if (!model || model->type != mod_brush)
SV_Error ("SOLID_BSP with a non bsp model");
Sys_Error ("SOLID_BSP with a non bsp model");
hull = &model->hulls[hull_index];
}
@ -419,7 +420,7 @@ SV_HullPointContents (hull_t *hull, int num, const vec3_t p)
while (num >= 0) {
if (num < hull->firstclipnode || num > hull->lastclipnode)
SV_Error ("SV_HullPointContents: bad node number");
Sys_Error ("SV_HullPointContents: bad node number");
node = hull->clipnodes + num;
plane = hull->planes + node->planenum;
@ -641,7 +642,7 @@ SV_ClipToLinks (areanode_t *node, moveclip_t * clip)
if (touch == clip->passedict)
continue;
if (SVfloat (touch, solid) == SOLID_TRIGGER)
SV_Error ("Trigger in clipping list");
Sys_Error ("Trigger in clipping list");
if (clip->type == MOVE_NOMONSTERS && SVfloat (touch, solid)
!= SOLID_BSP)

View file

@ -422,7 +422,6 @@ extern const char *client_info_filters[];
//===========================================================
// FIXME: declare exported functions in their own relevant .h
void SV_Error (const char *error, ...) __attribute__((format(printf,1,2)));
void SV_Init (void);
void SV_Progs_Init (void);
void SV_Progs_Init_Cvars (void);

View file

@ -394,7 +394,7 @@ SV_Map_f (void)
SV_Printf ("Can't find %s\n", expanded);
// If curlevel == level, something is SCREWED! --KB
if (strcaseequal (level, curlevel))
SV_Error ("map: cannot restart level\n");
Sys_Error ("map: cannot restart level\n");
else
Cbuf_AddText (va ("map %s", curlevel));
return;

View file

@ -234,9 +234,9 @@ SV_WriteDelta (entity_state_t *from, entity_state_t *to, sizebuf_t *msg,
// write the message
if (!to->number)
SV_Error ("Unset entity number");
Sys_Error ("Unset entity number");
if (to->number >= 512)
SV_Error ("Entity number >= 512");
Sys_Error ("Entity number >= 512");
if (!bits && !force)
return; // nothing to send!

View file

@ -41,6 +41,7 @@ static const char rcsid[] =
#include "QF/cvar.h"
#include "QF/info.h"
#include "QF/msg.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "QF/vfs.h"
@ -70,7 +71,7 @@ SV_ModelIndex (const char *name)
if (!strcmp (sv.model_precache[i], name))
return i;
if (i == MAX_MODELS || !sv.model_precache[i])
SV_Error ("SV_ModelIndex: model %s not precached", name);
Sys_Error ("SV_ModelIndex: model %s not precached", name);
return i;
}
@ -86,7 +87,7 @@ SV_FlushSignon (void)
return;
if (sv.num_signon_buffers == MAX_SIGNON_BUFFERS - 1)
SV_Error ("sv.num_signon_buffers == MAX_SIGNON_BUFFERS-1");
Sys_Error ("sv.num_signon_buffers == MAX_SIGNON_BUFFERS-1");
sv.signon_buffer_size[sv.num_signon_buffers - 1] = sv.signon.cursize;
sv.signon.data = sv.signon_buffers[sv.num_signon_buffers];

View file

@ -232,26 +232,21 @@ SV_Shutdown (void)
then exits
*/
void
SV_Error (const char *error, ...)
SV_Error (const char *error, va_list argptr)
{
va_list argptr;
static char string[1024];
static qboolean inerror = false;
if (inerror)
Sys_Error ("SV_Error: recursively entered (%s)", string);
return;
inerror = true;
va_start (argptr, error);
vsnprintf (string, sizeof (string), error, argptr);
va_end (argptr);
SV_Printf ("SV_Error: %s\n", string);
SV_FinalMessage (va ("server crashed: %s\n", string));
Sys_Error ("SV_Error: %s\n", string);
Sys_Print (stderr, error, argptr);
}
/*
@ -2422,7 +2417,8 @@ SV_Init (void)
CVAR_ROM, 0, "Plugin used for the console");
PI_RegisterPlugins (server_plugin_list);
Con_Init (sv_console_plugin->string);
Sys_SetPrintf (SV_Print);
Sys_SetStdPrintf (SV_Print);
Sys_SetErrPrintf (SV_Error);
COM_Filesystem_Init_Cvars ();
Game_Init_Cvars ();
@ -2476,5 +2472,5 @@ SV_Init (void)
if (sv.state == ss_dead)
Cmd_ExecuteString ("map start", src_command);
if (sv.state == ss_dead)
SV_Error ("Could not initialize server");
Sys_Error ("Could not initialize server");
}

View file

@ -32,6 +32,7 @@ static const char rcsid[] =
#endif
#include "QF/cvar.h"
#include "QF/sys.h"
#include "pmove.h"
#include "server.h"
@ -274,7 +275,7 @@ SV_FlyMove (edict_t *ent, float time, trace_t *steptrace)
break; // moved the entire distance
if (!trace.ent)
SV_Error ("SV_FlyMove: !trace.ent");
Sys_Error ("SV_FlyMove: !trace.ent");
if (trace.plane.normal[2] > 0.7) {
blocked |= 1; // floor
@ -870,7 +871,7 @@ SV_RunEntity (edict_t *ent)
SV_Physics_Toss (ent);
break;
default:
SV_Error ("SV_Physics: bad movetype %i", (int) SVfloat (ent,
Sys_Error ("SV_Physics: bad movetype %i", (int) SVfloat (ent,
movetype));
}
}

View file

@ -41,6 +41,7 @@ static const char rcsid[] =
#include "QF/cmd.h"
#include "QF/cvar.h"
#include "QF/msg.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "compat.h"
@ -76,7 +77,7 @@ PF_error (progs_t *pr)
ed = PROG_TO_EDICT (pr, *sv_globals.self);
ED_Print (pr, ed);
SV_Error ("Program error");
Sys_Error ("Program error");
}
/*
@ -100,7 +101,7 @@ PF_objerror (progs_t *pr)
ED_Print (pr, ed);
ED_Free (pr, ed);
SV_Error ("Program error");
Sys_Error ("Program error");
}
/*
@ -999,7 +1000,7 @@ WriteDest (progs_t *pr)
return &sv.datagram;
case MSG_ONE:
SV_Error ("Shouldn't be at MSG_ONE");
Sys_Error ("Shouldn't be at MSG_ONE");
#if 0
ent = PROG_TO_EDICT (pr, *sv_globals.msg_entity);
entnum = NUM_FOR_EDICT (pr, ent);

View file

@ -40,6 +40,7 @@ static const char rcsid[] =
#include "QF/cmd.h"
#include "QF/cvar.h"
#include "QF/sys.h"
#include "compat.h"
#include "server.h"
@ -178,7 +179,7 @@ SV_LoadProgs (void)
PR_LoadProgs (&sv_pr_state, sv_progs->string, MAX_EDICTS, 0);
if (!sv_pr_state.progs)
SV_Error ("SV_LoadProgs: couldn't load %s", sv_progs->string);
Sys_Error ("SV_LoadProgs: couldn't load %s", sv_progs->string);
// progs engine needs these globals anyway
sv_globals.self = sv_pr_state.globals.self;
sv_globals.time = sv_pr_state.globals.time;

View file

@ -363,7 +363,7 @@ SV_Multicast (const vec3_t origin, int to)
default:
mask = NULL;
SV_Error ("SV_Multicast: bad to:%i", to);
Sys_Error ("SV_Multicast: bad to:%i", to);
}
// send the data to all relevent clients
@ -425,13 +425,13 @@ SV_StartSound (edict_t *entity, int channel, const char *sample, int volume,
vec3_t origin;
if (volume < 0 || volume > 255)
SV_Error ("SV_StartSound: volume = %i", volume);
Sys_Error ("SV_StartSound: volume = %i", volume);
if (attenuation < 0 || attenuation > 4)
SV_Error ("SV_StartSound: attenuation = %f", attenuation);
Sys_Error ("SV_StartSound: attenuation = %f", attenuation);
if (channel < 0 || channel > 15)
SV_Error ("SV_StartSound: channel = %i", channel);
Sys_Error ("SV_StartSound: channel = %i", channel);
// find precache number for sound
for (sound_num = 1; sound_num < MAX_SOUNDS

View file

@ -42,6 +42,7 @@ static const char rcsid[] =
#include "QF/clip_hull.h"
#include "QF/console.h"
#include "QF/crc.h"
#include "QF/sys.h"
#include "compat.h"
#include "server.h"
@ -166,12 +167,12 @@ SV_HullForEntity (edict_t *ent, const vec3_t mins, const vec3_t maxs,
} if (SVfloat (ent, solid) == SOLID_BSP) {
// explicit hulls in the BSP model
if (SVfloat (ent, movetype) != MOVETYPE_PUSH)
SV_Error ("SOLID_BSP without MOVETYPE_PUSH");
Sys_Error ("SOLID_BSP without MOVETYPE_PUSH");
model = sv.models[(int) SVfloat (ent, modelindex)];
if (!model || model->type != mod_brush)
SV_Error ("SOLID_BSP with a non bsp model");
Sys_Error ("SOLID_BSP with a non bsp model");
hull = &model->hulls[hull_index];
}
@ -419,7 +420,7 @@ SV_HullPointContents (hull_t *hull, int num, const vec3_t p)
while (num >= 0) {
if (num < hull->firstclipnode || num > hull->lastclipnode)
SV_Error ("SV_HullPointContents: bad node number");
Sys_Error ("SV_HullPointContents: bad node number");
node = hull->clipnodes + num;
plane = hull->planes + node->planenum;
@ -641,7 +642,7 @@ SV_ClipToLinks (areanode_t *node, moveclip_t * clip)
if (touch == clip->passedict)
continue;
if (SVfloat (touch, solid) == SOLID_TRIGGER)
SV_Error ("Trigger in clipping list");
Sys_Error ("Trigger in clipping list");
if (clip->type == MOVE_NOMONSTERS && SVfloat (touch, solid)
!= SOLID_BSP)