diff --git a/nq/source/sys_sdl.c b/nq/source/sys_sdl.c index 0edf36823..d986e404f 100644 --- a/nq/source/sys_sdl.c +++ b/nq/source/sys_sdl.c @@ -1,5 +1,5 @@ /* - cl_sys_sdl.c + sys_sdl.c (description) @@ -26,15 +26,12 @@ $Id$ */ - - #ifdef HAVE_CONFIG_H # include "config.h" #endif #include #include - #include #include #include @@ -84,26 +81,20 @@ void MaskExceptions (void); #endif -void -Sys_DebugLog (const char *file, const char *fmt, ...) -{ - int fd; - static char data[1024]; // why static ? - va_list argptr; - - va_start (argptr, fmt); - vsnprintf (data, sizeof (data), fmt, argptr); - va_end (argptr); - fd = open (file, O_WRONLY | O_CREAT | O_APPEND, 0666); - write (fd, data, strlen (data)); - close (fd); -}; - - /* - SYSTEM IO -*/ + Sys_Init_Cvars + Quake calls this so the system can register variables before host_hunklevel + is marked +*/ +void +Sys_Init_Cvars (void) +{ + sys_nostdout = Cvar_Get ("sys_nostdout", "0", CVAR_NONE, NULL, + "Set to disable std out"); + if (COM_CheckParm ("-nostdout")) + Cvar_Set (sys_nostdout, "1"); +} void Sys_Init (void) @@ -136,7 +127,19 @@ Sys_Init (void) #endif } +/* + Sys_Quit +*/ +void +Sys_Quit (void) +{ + Host_Shutdown (); + exit (0); +} +/* + Sys_Error +*/ void Sys_Error (const char *error, ...) { @@ -159,37 +162,38 @@ Sys_Error (const char *error, ...) exit (1); } - void -Sys_Quit (void) +Sys_DebugLog (const char *file, const char *fmt, ...) { - Host_Shutdown (); - exit (0); -} + int fd; + static char data[1024]; // why static ? + va_list argptr; + va_start (argptr, fmt); + vsnprintf (data, sizeof (data), fmt, argptr); + va_end (argptr); + fd = open (file, O_WRONLY | O_CREAT | O_APPEND, 0666); + write (fd, data, strlen (data)); + close (fd); +}; +/* + Sys_ConsoleInput + + Checks for a complete line of text typed in at the console, then forwards + it to the host command processor +*/ const char * Sys_ConsoleInput (void) { return NULL; } - void Sys_Sleep (void) { } - -void -Sys_Init_Cvars (void) -{ - sys_nostdout = Cvar_Get ("sys_nostdout", "0", CVAR_NONE, NULL, - "Set to disable std out"); - if (COM_CheckParm ("-nostdout")) - Cvar_Set (sys_nostdout, "1"); -} - #ifndef SDL_main # define SDL_main main #endif diff --git a/nq/source/sys_unix.c b/nq/source/sys_unix.c index 1730a5e78..5bce6cc98 100644 --- a/nq/source/sys_unix.c +++ b/nq/source/sys_unix.c @@ -54,8 +54,6 @@ #include "server.h" #include "host.h" - - qboolean isDedicated; char *basedir = "."; @@ -65,28 +63,30 @@ cvar_t *sys_linerefresh; cvar_t *timestamps; cvar_t *timeformat; + void -Sys_DebugLog (const char *file, const char *fmt, ...) +Sys_Init (void) { - va_list argptr; - static char data[1024]; - int fd; - - va_start (argptr, fmt); - vsnprintf (data, sizeof (data), fmt, argptr); - va_end (argptr); - - fd = open (file, O_WRONLY | O_CREAT | O_APPEND, 0666); - write (fd, data, strlen (data)); - close (fd); +#ifdef USE_INTEL_ASM + Sys_SetFPCW (); +#endif } +/* + Sys_Quit +*/ +void +Sys_Quit (void) +{ + Host_Shutdown (); + fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY); + fflush (stdout); + exit (0); +} /* - * System I/O - */ - - + Sys_Error +*/ void Sys_Error (const char *error, ...) { @@ -107,22 +107,20 @@ Sys_Error (const char *error, ...) } void -Sys_Quit (void) +Sys_DebugLog (const char *file, const char *fmt, ...) { - Host_Shutdown (); - fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY); - fflush (stdout); - exit (0); -} + va_list argptr; + static char data[1024]; + int fd; -void -Sys_Init (void) -{ -#ifdef USE_INTEL_ASM - Sys_SetFPCW (); -#endif -} + va_start (argptr, fmt); + vsnprintf (data, sizeof (data), fmt, argptr); + va_end (argptr); + fd = open (file, O_WRONLY | O_CREAT | O_APPEND, 0666); + write (fd, data, strlen (data)); + close (fd); +} void floating_point_exception_handler (int whatever) @@ -131,6 +129,12 @@ floating_point_exception_handler (int whatever) signal (SIGFPE, floating_point_exception_handler); } +/* + Sys_ConsoleInput + + Checks for a complete line of text typed in at the console, then forwards + it to the host command processor +*/ const char * Sys_ConsoleInput (void) { diff --git a/qw/source/cl_sys_sdl.c b/qw/source/cl_sys_sdl.c index f58e49376..c90f48936 100644 --- a/qw/source/cl_sys_sdl.c +++ b/qw/source/cl_sys_sdl.c @@ -26,15 +26,12 @@ $Id$ */ - - #ifdef HAVE_CONFIG_H # include "config.h" #endif #include #include - #include #include #include @@ -84,26 +81,20 @@ void MaskExceptions (void); #endif -void -Sys_DebugLog (const char *file, const char *fmt, ...) -{ - int fd; - static char data[1024]; // why static ? - va_list argptr; - - va_start (argptr, fmt); - vsnprintf (data, sizeof (data), fmt, argptr); - va_end (argptr); - fd = open (file, O_WRONLY | O_CREAT | O_APPEND, 0666); - write (fd, data, strlen (data)); - close (fd); -}; - - /* - SYSTEM IO -*/ + Sys_Init_Cvars + Quake calls this so the system can register variables before host_hunklevel + is marked +*/ +void +Sys_Init_Cvars (void) +{ + sys_nostdout = Cvar_Get ("sys_nostdout", "0", CVAR_NONE, NULL, + "set to disable std out"); + if (COM_CheckParm ("-nostdout")) + Cvar_Set (sys_nostdout, "1"); +} void Sys_Init (void) @@ -136,7 +127,20 @@ Sys_Init (void) #endif } +/* + Sys_Quit +*/ +void +Sys_Quit (void) +{ + Host_Shutdown (); + exit (0); +} + +/* + Sys_Error +*/ void Sys_Error (const char *error, ...) { @@ -160,14 +164,29 @@ Sys_Error (const char *error, ...) } + void -Sys_Quit (void) +Sys_DebugLog (const char *file, const char *fmt, ...) { - Host_Shutdown (); - exit (0); -} + int fd; + static char data[1024]; // why static ? + va_list argptr; + + va_start (argptr, fmt); + vsnprintf (data, sizeof (data), fmt, argptr); + va_end (argptr); + fd = open (file, O_WRONLY | O_CREAT | O_APPEND, 0666); + write (fd, data, strlen (data)); + close (fd); +}; +/* + Sys_ConsoleInput + + Checks for a complete line of text typed in at the console, then forwards + it to the host command processor +*/ const char * Sys_ConsoleInput (void) { @@ -181,19 +200,13 @@ Sys_Sleep (void) } -void -Sys_Init_Cvars (void) -{ - sys_nostdout = Cvar_Get ("sys_nostdout", "0", CVAR_NONE, NULL, - "Set to disable std out"); - if (COM_CheckParm ("-nostdout")) - Cvar_Set (sys_nostdout, "1"); -} - #ifndef SDL_main # define SDL_main main #endif +/* + main +*/ int SDL_main (int c, char **v) { @@ -210,7 +223,7 @@ SDL_main (int c, char **v) host_parms.argc = com_argc; host_parms.argv = com_argv; - host_parms.memsize = 16 * 1024 * 1024; + host_parms.memsize = 16 * 1024 * 1024; // 16MB default heap j = COM_CheckParm ("-mem"); if (j) @@ -221,6 +234,7 @@ SDL_main (int c, char **v) printf ("Can't allocate memory for zone.\n"); return 1; } + #ifndef WIN32 noconinput = COM_CheckParm ("-noconinput"); if (!noconinput) @@ -231,7 +245,7 @@ SDL_main (int c, char **v) oldtime = Sys_DoubleTime (); while (1) { -// find time spent rendering last frame + // find time spent rendering last frame newtime = Sys_DoubleTime (); time = newtime - oldtime; diff --git a/qw/source/cl_sys_unix.c b/qw/source/cl_sys_unix.c index 1860400e0..0c39b64ed 100644 --- a/qw/source/cl_sys_unix.c +++ b/qw/source/cl_sys_unix.c @@ -55,9 +55,33 @@ int noconinput = 0; qboolean is_server = false; char *svs_info; -// General routines ====================================================== +/* + Sys_Init_Cvars + Quake calls this so the system can register variables before host_hunklevel + is marked +*/ +void +Sys_Init_Cvars (void) +{ + sys_nostdout = Cvar_Get ("sys_nostdout", "0", CVAR_NONE, NULL, + "set to disable std out"); + if (COM_CheckParm ("-nostdout")) + Cvar_Set (sys_nostdout, "1"); +} + +void +Sys_Init (void) +{ +#ifdef USE_INTEL_ASM + Sys_SetFPCW (); +#endif +} + +/* + Sys_Quit +*/ void Sys_Quit (void) { @@ -69,26 +93,9 @@ Sys_Quit (void) exit (0); } - -void -Sys_Init_Cvars (void) -{ - sys_nostdout = Cvar_Get ("sys_nostdout", "0", CVAR_NONE, NULL, - "set to disable std out"); - if (COM_CheckParm ("-nostdout")) - Cvar_Set (sys_nostdout, "1"); -} - - -void -Sys_Init (void) -{ -#ifdef USE_INTEL_ASM - Sys_SetFPCW (); -#endif -} - - +/* + Sys_Error +*/ void Sys_Error (const char *error, ...) { @@ -107,7 +114,6 @@ Sys_Error (const char *error, ...) exit (1); } - void Sys_Warn (char *warning, ...) { @@ -120,7 +126,6 @@ Sys_Warn (char *warning, ...) fprintf (stderr, "Warning: %s", string); } - void Sys_DebugLog (const char *file, const char *fmt, ...) { @@ -146,6 +151,12 @@ floating_point_exception_handler (int whatever) } +/* + Sys_ConsoleInput + + Checks for a complete line of text typed in at the console, then forwards + it to the host command processor +*/ const char * Sys_ConsoleInput (void) { @@ -181,6 +192,9 @@ Sys_LowFPPrecision (void) int skipframes; +/* + main +*/ int main (int c, const char *v[]) { @@ -204,6 +218,7 @@ main (int c, const char *v[]) if (j) host_parms.memsize = (int) (atof (com_argv[j + 1]) * 1024 * 1024); host_parms.membase = malloc (host_parms.memsize); + if (!host_parms.membase) { printf ("Can't allocate memory for zone.\n"); return 1; diff --git a/qw/source/cl_sys_win.c b/qw/source/cl_sys_win.c index 168910874..e536d1edb 100644 --- a/qw/source/cl_sys_win.c +++ b/qw/source/cl_sys_win.c @@ -83,60 +83,19 @@ void Sys_PopFPCW (void); void Sys_PushFPCW_SetHigh (void); -void -Sys_DebugLog (const char *file, const char *fmt, ...) -{ - va_list argptr; - static char data[1024]; - int fd; - - va_start (argptr, fmt); - vsnprintf (data, sizeof (data), fmt, argptr); - va_end (argptr); - fd = open (file, O_WRONLY | O_CREAT | O_APPEND, 0666); - write (fd, data, strlen (data)); - close (fd); -}; - - /* - FILE IO + Sys_Init_Cvars + + Quake calls this so the system can register variables before host_hunklevel + is marked */ - - -int -wfilelength (VFile *f) -{ - int pos; - int end; - - pos = Qtell (f); - Qseek (f, 0, SEEK_END); - end = Qtell (f); - Qseek (f, pos, SEEK_SET); - - return end; -} - - -/* - SYSTEM IO -*/ - - -/* - Sys_Init -*/ - - void Sys_Init_Cvars (void) { sys_nostdout = Cvar_Get ("sys_nostdout", "1", CVAR_NONE, NULL, - "unset to enable std out - windows does NOT support this"); + "unset to enable std out - windows does NOT support this"); } - void Sys_Init (void) { @@ -184,7 +143,30 @@ Sys_Init (void) WinNT = false; } +/* + Sys_Quit +*/ +void +Sys_Quit (void) +{ + VID_ForceUnlockedAndReturnState (); + Host_Shutdown (); + + if (tevent) + CloseHandle (tevent); + + if (qwclsemaphore) + CloseHandle (qwclsemaphore); + + Net_LogStop(); + + exit (0); +} + +/* + Sys_Error +*/ void Sys_Error (const char *error, ...) { @@ -206,26 +188,42 @@ Sys_Error (const char *error, ...) exit (1); } - void -Sys_Quit (void) +Sys_DebugLog (const char *file, const char *fmt, ...) { - VID_ForceUnlockedAndReturnState (); + va_list argptr; + static char data[1024]; + int fd; - Host_Shutdown (); + va_start (argptr, fmt); + vsnprintf (data, sizeof (data), fmt, argptr); + va_end (argptr); + fd = open (file, O_WRONLY | O_CREAT | O_APPEND, 0666); + write (fd, data, strlen (data)); + close (fd); +}; - if (tevent) - CloseHandle (tevent); - if (qwclsemaphore) - CloseHandle (qwclsemaphore); +int +wfilelength (VFile *f) +{ + int pos; + int end; - Net_LogStop(); + pos = Qtell (f); + Qseek (f, 0, SEEK_END); + end = Qtell (f); + Qseek (f, pos, SEEK_SET); - exit (0); + return end; } +/* + Sys_ConsoleInput + Checks for a complete line of text typed in at the console, then forwards + it to the host command processor +*/ const char * Sys_ConsoleInput (void) { @@ -334,18 +332,11 @@ Sys_ConsoleInput (void) return NULL; } - void Sys_Sleep (void) { } - -/* - WINDOWS CRAP -*/ - - void SleepUntilInput (int time) { @@ -360,6 +351,9 @@ char *argv[MAX_NUM_ARGVS]; static char *empty_string = ""; +/* + main +*/ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) diff --git a/qw/source/sv_sys_unix.c b/qw/source/sv_sys_unix.c index ed1e3546b..8a231bf99 100644 --- a/qw/source/sv_sys_unix.c +++ b/qw/source/sv_sys_unix.c @@ -65,72 +65,7 @@ char *svs_info = svs.info; /* - REQUIRED SYS FUNCTIONS -*/ - -/* - Sys_Error -*/ -void -Sys_Error (const char *error, ...) -{ - va_list argptr; - char string[1024]; - - va_start (argptr, error); - vsnprintf (string, sizeof (string), error, argptr); - va_end (argptr); - printf ("Fatal error: %s\n", string); - - exit (1); -} - - -/* - Sys_Quit -*/ -void -Sys_Quit (void) -{ - - Net_LogStop(); - - exit (0); // appkit isn't running -} - -static int do_stdin = 1; - -/* - Sys_ConsoleInput - - Checks for a complete line of text typed in at the console, then forwards - it to the host command processor -*/ -const char * -Sys_ConsoleInput (void) -{ - static char text[256]; - int len; - - if (!stdin_ready || !do_stdin) - return NULL; // the select didn't say it was ready - stdin_ready = false; - - len = read (0, text, sizeof (text)); - if (len == 0) { - // end of file - do_stdin = 0; - return NULL; - } - if (len < 1) - return NULL; - text[len - 1] = 0; // rip off the /n and terminate - - return text; -} - -/* - Sys_Init + Sys_Init_Cvars Quake calls this so the system can register variables before host_hunklevel is marked @@ -156,6 +91,67 @@ Sys_Init (void) #endif } +/* + Sys_Quit +*/ +void +Sys_Quit (void) +{ + + Net_LogStop(); + + exit (0); +} + +/* + Sys_Error +*/ +void +Sys_Error (const char *error, ...) +{ + va_list argptr; + char string[1024]; + + va_start (argptr, error); + vsnprintf (string, sizeof (string), error, argptr); + va_end (argptr); + printf ("Fatal error: %s\n", string); + + exit (1); +} + + +static int do_stdin = 1; + +/* + Sys_ConsoleInput + + Checks for a complete line of text typed in at the console, then forwards + it to the host command processor +*/ +const char * +Sys_ConsoleInput (void) +{ + static char text[256]; + int len; + + if (!stdin_ready || !do_stdin) + return NULL; // the select didn't say it was ready + stdin_ready = false; + + len = read (0, text, sizeof (text)); + if (len == 0) { + // end of file + do_stdin = 0; + return NULL; + } + if (len < 1) + return NULL; + text[len - 1] = 0; // rip off the /n and terminate + + return text; +} + /* main */ diff --git a/qw/source/sv_sys_win.c b/qw/source/sv_sys_win.c index 510e33744..d54d799f5 100644 --- a/qw/source/sv_sys_win.c +++ b/qw/source/sv_sys_win.c @@ -1,5 +1,5 @@ /* - sys_win.c + sv_sys_win.c (description) @@ -52,81 +52,11 @@ cvar_t *sys_sleep; /* - Sys_Error -*/ -void -Sys_Error (const char *error, ...) -{ - va_list argptr; - char text[1024]; - - va_start (argptr, error); - vsnprintf (text, sizeof (text), error, argptr); - va_end (argptr); - -// MessageBox(NULL, text, "Error", 0 /* MB_OK */ ); - printf ("ERROR: %s\n", text); - - exit (1); -} - - -/* - Sys_ConsoleInput -*/ -const char * -Sys_ConsoleInput (void) -{ - static char text[256]; - static int len; - int c; - - // read a line out - while (kbhit ()) { - c = _getch (); - putch (c); - if (c == '\r') { - text[len] = 0; - putch ('\n'); - len = 0; - return text; - } - if (c == 8) { - if (len) { - putch (' '); - putch (c); - len--; - text[len] = 0; - } - continue; - } - text[len] = c; - len++; - text[len] = 0; - if (len == sizeof (text)) - len = 0; - } - - return NULL; -} - -/* - Sys_Quit -*/ -void -Sys_Quit (void) -{ - Net_LogStop(); - exit (0); -} - -/* - Sys_Init + Sys_Init_Cvars Quake calls this so the system can register variables before host_hunklevel is marked */ - void Sys_Init_Cvars (void) { @@ -164,6 +94,78 @@ Sys_Init (void) WinNT = false; } +/* + Sys_Quit +*/ +void +Sys_Quit (void) +{ + Net_LogStop(); + exit (0); +} + +/* + Sys_Error +*/ +void +Sys_Error (const char *error, ...) +{ + va_list argptr; + char text[1024]; + + va_start (argptr, error); + vsnprintf (text, sizeof (text), error, argptr); + va_end (argptr); + +// MessageBox(NULL, text, "Error", 0 /* MB_OK */ ); + printf ("ERROR: %s\n", text); + + exit (1); +} + + +/* + Sys_ConsoleInput + + Checks for a complete line of text typed in at the console, then forwards + it to the host command processor +*/ +const char * +Sys_ConsoleInput (void) +{ + static char text[256]; + static int len; + int c; + + // read a line out + while (kbhit ()) { + c = _getch (); + putch (c); + if (c == '\r') { + text[len] = 0; + putch ('\n'); + len = 0; + return text; + } + if (c == 8) { + if (len) { + putch (' '); + putch (c); + len--; + text[len] = 0; + } + continue; + } + text[len] = c; + len++; + text[len] = 0; + if (len == sizeof (text)) + len = 0; + } + + return NULL; +} + /* main */