mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-02-13 23:40:58 +00:00
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
This commit is contained in:
parent
65a7f903e5
commit
c2c768f028
4 changed files with 75 additions and 53 deletions
|
@ -20,13 +20,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
// console.c
|
// console.c
|
||||||
|
|
||||||
#ifdef NeXT
|
#include <sys/types.h>
|
||||||
#include <libc.h>
|
#include <time.h>
|
||||||
#endif
|
#include <sys/stat.h>
|
||||||
#ifndef _MSC_VER
|
#include <fcntl.h>
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <io.h>
|
||||||
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
#include <fcntl.h>
|
|
||||||
#include "quakedef.h"
|
#include "quakedef.h"
|
||||||
|
|
||||||
int con_linewidth;
|
int con_linewidth;
|
||||||
|
@ -56,7 +58,7 @@ float con_times[NUM_CON_TIMES]; // realtime time the line was generated
|
||||||
|
|
||||||
int con_vislines;
|
int con_vislines;
|
||||||
|
|
||||||
qboolean con_debuglog;
|
qboolean con_debuglog = false;
|
||||||
|
|
||||||
#define MAXCMDLINE 256
|
#define MAXCMDLINE 256
|
||||||
extern char key_lines[32][MAXCMDLINE];
|
extern char key_lines[32][MAXCMDLINE];
|
||||||
|
@ -328,21 +330,6 @@ Con_Init
|
||||||
*/
|
*/
|
||||||
void Con_Init (void)
|
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
|
//johnfitz -- user settable console buffer size
|
||||||
if (COM_CheckParm("-consize"))
|
if (COM_CheckParm("-consize"))
|
||||||
con_buffersize = max(CON_MINSIZE,Q_atoi(com_argv[COM_CheckParm("-consize")+1])*1024);
|
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
|
Con_DebugLog
|
||||||
================
|
================
|
||||||
*/
|
*/
|
||||||
void Con_DebugLog(const char *file, const char *fmt, ...) __attribute__((__format__(__printf__,2,3)));
|
void Con_DebugLog(const char *msg)
|
||||||
void Con_DebugLog(const char *file, const char *fmt, ...)
|
|
||||||
{
|
{
|
||||||
va_list argptr;
|
if (log_fd == -1)
|
||||||
static char data[1024];
|
return;
|
||||||
int fd;
|
|
||||||
|
|
||||||
va_start(argptr, fmt);
|
write(log_fd, msg, strlen(msg));
|
||||||
vsprintf(data, fmt, argptr);
|
|
||||||
va_end(argptr);
|
|
||||||
fd = open(file, O_WRONLY | O_CREAT | O_APPEND, 0666);
|
|
||||||
write(fd, data, strlen(data));
|
|
||||||
close(fd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -529,7 +514,7 @@ void Con_Printf (const char *fmt, ...)
|
||||||
|
|
||||||
// log all messages to file
|
// log all messages to file
|
||||||
if (con_debuglog)
|
if (con_debuglog)
|
||||||
Con_DebugLog(va("%s/qconsole.log",com_gamedir), "%s", msg);
|
Con_DebugLog(msg);
|
||||||
|
|
||||||
if (!con_initialized)
|
if (!con_initialized)
|
||||||
return;
|
return;
|
||||||
|
@ -1252,3 +1237,38 @@ void Con_NotifyBox (const char *text)
|
||||||
realtime = 0; // put the cursor back to invisible
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,5 +59,11 @@ char *Con_Quakebar (int len);
|
||||||
void Con_TabComplete (void);
|
void Con_TabComplete (void);
|
||||||
void Con_LogCenterPrint (const char *str);
|
void Con_LogCenterPrint (const char *str);
|
||||||
|
|
||||||
|
//
|
||||||
|
// debuglog
|
||||||
|
//
|
||||||
|
void LOG_Init (quakeparms_t *parms);
|
||||||
|
void LOG_Close (void);
|
||||||
|
|
||||||
#endif /* __CONSOLE_H */
|
#endif /* __CONSOLE_H */
|
||||||
|
|
||||||
|
|
|
@ -813,6 +813,7 @@ void Host_Init (quakeparms_t *parms)
|
||||||
Memory_Init (parms->membase, parms->memsize);
|
Memory_Init (parms->membase, parms->memsize);
|
||||||
Cbuf_Init ();
|
Cbuf_Init ();
|
||||||
Cmd_Init ();
|
Cmd_Init ();
|
||||||
|
LOG_Init (parms);
|
||||||
Cvar_Init (); //johnfitz
|
Cvar_Init (); //johnfitz
|
||||||
V_Init ();
|
V_Init ();
|
||||||
Chase_Init ();
|
Chase_Init ();
|
||||||
|
@ -898,5 +899,6 @@ void Host_Shutdown(void)
|
||||||
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();
|
VID_Shutdown();
|
||||||
}
|
}
|
||||||
|
LOG_Close ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -223,6 +223,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#define SOUND_CHANNELS 8
|
#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 "common.h"
|
||||||
#include "bspfile.h"
|
#include "bspfile.h"
|
||||||
#include "vid.h"
|
#include "vid.h"
|
||||||
|
@ -283,27 +296,8 @@ typedef struct
|
||||||
// command line parms passed to the program, and the amount of memory
|
// command line parms passed to the program, and the amount of memory
|
||||||
// available for the program to use
|
// 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;
|
extern qboolean noclip_anglehack;
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// host
|
// host
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue