From c2c768f028bb4cafa0eb1e57081d5989336a9782 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Tue, 27 Apr 2010 08:24:13 +0000 Subject: [PATCH] console.c: Added LOG_Init() and LOG_Close() as two new procedures, adapted from uhexen2. Moved debug log initialization from Con_Init() to LOG_Init(). Made Con_DebugLog() to operate without varargs stuff. Log file is written into host_parms->basedir now, not into a gamedir. console.h: Added prototypes for LOG_Init() and LOG_Close(). host.c (Host_Init): Added LOG_Init(). (Host_Shutdown): Added LOG_Close(). quakedef.h (quakeparms_t): Moved the typedef to an earlier place before any of the other quake headers are included. git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@159 af15c1b1-3010-417e-b628-4374ebc0bcbd --- Quake/console.c | 86 +++++++++++++++++++++++++++++------------------- Quake/console.h | 6 ++++ Quake/host.c | 4 ++- Quake/quakedef.h | 32 ++++++++---------- 4 files changed, 75 insertions(+), 53 deletions(-) diff --git a/Quake/console.c b/Quake/console.c index d091be79..a02de6ad 100644 --- a/Quake/console.c +++ b/Quake/console.c @@ -20,13 +20,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // console.c -#ifdef NeXT -#include -#endif -#ifndef _MSC_VER +#include +#include +#include +#include +#ifdef _WIN32 +#include +#else #include #endif -#include #include "quakedef.h" int con_linewidth; @@ -56,7 +58,7 @@ float con_times[NUM_CON_TIMES]; // realtime time the line was generated int con_vislines; -qboolean con_debuglog; +qboolean con_debuglog = false; #define MAXCMDLINE 256 extern char key_lines[32][MAXCMDLINE]; @@ -328,21 +330,6 @@ Con_Init */ void Con_Init (void) { -#define MAXGAMEDIRLEN 1000 - char temp[MAXGAMEDIRLEN+1]; - char *t2 = "/qconsole.log"; - - con_debuglog = COM_CheckParm("-condebug"); - - if (con_debuglog) - { - if (strlen (com_gamedir) < (MAXGAMEDIRLEN - strlen (t2))) - { - sprintf (temp, "%s%s", com_gamedir, t2); - unlink (temp); - } - } - //johnfitz -- user settable console buffer size if (COM_CheckParm("-consize")) con_buffersize = max(CON_MINSIZE,Q_atoi(com_argv[COM_CheckParm("-consize")+1])*1024); @@ -484,24 +471,22 @@ void Con_Print (const char *txt) } +// borrowed from uhexen2 by S.A. for new procs, LOG_Init, LOG_Close + +static char logfilename[MAX_OSPATH]; // current logfile name +static int log_fd = -1; // log file descriptor + /* ================ Con_DebugLog ================ */ -void Con_DebugLog(const char *file, const char *fmt, ...) __attribute__((__format__(__printf__,2,3))); -void Con_DebugLog(const char *file, const char *fmt, ...) +void Con_DebugLog(const char *msg) { - va_list argptr; - static char data[1024]; - int fd; + if (log_fd == -1) + return; - va_start(argptr, fmt); - vsprintf(data, fmt, argptr); - va_end(argptr); - fd = open(file, O_WRONLY | O_CREAT | O_APPEND, 0666); - write(fd, data, strlen(data)); - close(fd); + write(log_fd, msg, strlen(msg)); } @@ -529,7 +514,7 @@ void Con_Printf (const char *fmt, ...) // log all messages to file if (con_debuglog) - Con_DebugLog(va("%s/qconsole.log",com_gamedir), "%s", msg); + Con_DebugLog(msg); if (!con_initialized) return; @@ -1252,3 +1237,38 @@ void Con_NotifyBox (const char *text) realtime = 0; // put the cursor back to invisible } + +void LOG_Init (quakeparms_t *parms) +{ + time_t inittime; + char session[24]; + + if (!COM_CheckParm("-condebug")) + return; + + inittime = time (NULL); + strftime (session, sizeof(session), "%m/%d/%Y %H:%M:%S", localtime(&inittime)); + snprintf (logfilename, sizeof(logfilename), "%s/qconsole.log", parms->basedir); + + unlink (logfilename); + + log_fd = open (logfilename, O_WRONLY | O_CREAT | O_APPEND, 0666); + if (log_fd == -1) + { + fprintf (stderr, "Error: Unable to create log file %s\n", logfilename); + return; + } + + con_debuglog = true; + Con_DebugLog (va("LOG started on: %s \n", session)); + +} + +void LOG_Close (void) +{ + if (log_fd == -1) + return; + close (log_fd); + log_fd = -1; +} + diff --git a/Quake/console.h b/Quake/console.h index 47b8d881..a99fcebf 100644 --- a/Quake/console.h +++ b/Quake/console.h @@ -59,5 +59,11 @@ char *Con_Quakebar (int len); void Con_TabComplete (void); void Con_LogCenterPrint (const char *str); +// +// debuglog +// +void LOG_Init (quakeparms_t *parms); +void LOG_Close (void); + #endif /* __CONSOLE_H */ diff --git a/Quake/host.c b/Quake/host.c index 881dcd1d..f85e39da 100644 --- a/Quake/host.c +++ b/Quake/host.c @@ -813,6 +813,7 @@ void Host_Init (quakeparms_t *parms) Memory_Init (parms->membase, parms->memsize); Cbuf_Init (); Cmd_Init (); + LOG_Init (parms); Cvar_Init (); //johnfitz V_Init (); Chase_Init (); @@ -895,8 +896,9 @@ void Host_Shutdown(void) if (cls.state != ca_dedicated) { - IN_Shutdown (); // input is only initialized in Host_Init if we're not dedicated -- kristian + IN_Shutdown (); // input is only initialized in Host_Init if we're not dedicated -- kristian VID_Shutdown(); } + LOG_Close (); } diff --git a/Quake/quakedef.h b/Quake/quakedef.h index f2138d58..702f9306 100644 --- a/Quake/quakedef.h +++ b/Quake/quakedef.h @@ -223,6 +223,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define SOUND_CHANNELS 8 +typedef struct +{ + char *basedir; + char *userdir; // user's directory on UNIX platforms. + // if user directories are enabled, basedir + // and userdir will point to different + // memory locations, otherwise to the same. + int argc; + char **argv; + void *membase; + int memsize; +} quakeparms_t; + #include "common.h" #include "bspfile.h" #include "vid.h" @@ -283,27 +296,8 @@ typedef struct // command line parms passed to the program, and the amount of memory // available for the program to use -typedef struct -{ - char *basedir; - char *userdir; // user's directory on UNIX platforms. - // if user directories are enabled, basedir - // and userdir will point to different - // memory locations, otherwise to the same. - int argc; - char **argv; - void *membase; - int memsize; -} quakeparms_t; - - -//============================================================================= - - - extern qboolean noclip_anglehack; - // // host //