forked from slotzero/manquake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsole.c
185 lines (153 loc) · 4.14 KB
/
console.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
Copyright (C) 1996-1997 Id Software, Inc.
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.
*/
// console.c
#ifdef NeXT
#include <libc.h>
#endif
#ifndef _MSC_VER
#include <unistd.h>
#endif
#include <fcntl.h>
#include "quakedef.h"
// JPG - needed for console log
#include <time.h>
// JPG - upped CON_TEXTSIZE from 16384 to 65536
#define CON_TEXTSIZE 65536
char *con_text=0;
char logfilename[128];
qboolean con_debuglog;
/*
================
Con_Clear_f
================
*/
void Con_Clear_f (void)
{
if (con_text)
memset (con_text, ' ', CON_TEXTSIZE);
}
/*
================
Con_Init
================
*/
void Con_Init (void)
{
#define MAXGAMEDIRLEN 1000
char temp[MAXGAMEDIRLEN+1];
char *ch; // JPG - added this
int fd, n; // JPG - added these
time_t ltime; // JPG - for console log file
con_debuglog = COM_CheckParm("-condebug");
if (con_debuglog)
{
// JPG - check for different file name
if ((con_debuglog < com_argc - 1) && (*com_argv[con_debuglog+1] != '-') && (*com_argv[con_debuglog+1] != '+'))
{
if ((ch = strchr(com_argv[con_debuglog+1], '%')) && (ch[1] == 'd'))
{
n = 0;
do
{
n = n + 1;
dpsnprintf(logfilename, sizeof(logfilename), com_argv[con_debuglog+1], n);
strcat(logfilename, ".log");
dpsnprintf(temp, sizeof(temp), "%s/%s", com_gamedir, logfilename);
fd = open(temp, O_CREAT | O_EXCL | O_WRONLY, 0666);
}
while (fd == -1);
close(fd);
}
else
dpsnprintf(logfilename, sizeof(logfilename), "%s.log", com_argv[con_debuglog+1]);
}
else
strcpy(logfilename, "qconsole.log");
// JPG - changed t2 to logfilename
if (strlen (com_gamedir) < (MAXGAMEDIRLEN - strlen (logfilename)))
{
dpsnprintf (temp, sizeof(temp), "%s/%s", com_gamedir, logfilename); // JPG - added the '/'
unlink (temp);
}
// JPG - print initial message
Con_Printf("Log file initialized.\n");
Con_Printf("%s/%s\n", com_gamedir, logfilename);
time( <ime );
Con_Printf( "%s\n", ctime( <ime ) );
}
// used by some mods
con_text = Hunk_AllocName (CON_TEXTSIZE, "context");
memset (con_text, ' ', CON_TEXTSIZE);
Con_Printf ("Console initialized.\n");
// register our commands
Cmd_AddCommand ("clear", Con_Clear_f);
}
// JPG - increased this from 4096 to 16384 and moved it up here
// See http://www.inside3d.com/qip/q1/bugs.htm, NVidia 5.16 drivers can cause crash
#define MAXPRINTMSG 16384
/*
================
Con_DebugLog
================
*/
void Con_DebugLog (char *fmt, ...)
{
va_list argptr;
static char data[MAXPRINTMSG];
int fd;
va_start(argptr, fmt);
dpvsnprintf (data, sizeof(data), fmt, argptr);
va_end(argptr);
fd = open(va("%s/%s", com_gamedir, logfilename), O_WRONLY | O_CREAT | O_APPEND, 0666);
write(fd, data, strlen(data));
close(fd);
}
/*
================
Con_Printf
Handles cursor positioning, line wrapping, etc
================
*/
void Con_Printf (char *fmt, ...)
{
va_list argptr;
char msg[MAXPRINTMSG];
va_start (argptr,fmt);
dpvsnprintf (msg, sizeof(msg), fmt, argptr);
va_end (argptr);
// also echo to debugging console
Sys_Printf ("%s", msg);
// log all messages to file
if (con_debuglog)
Con_DebugLog("%s", msg);
}
/*
================
Con_DPrintf
A Con_Printf that only shows up if the "developer" cvar is set
================
*/
void Con_DPrintf (char *fmt, ...)
{
va_list argptr;
char msg[MAXPRINTMSG];
// don't confuse non-developers with techie stuff...
if (!developer.value)
return;
va_start (argptr,fmt);
dpvsnprintf (msg, sizeof(msg), fmt, argptr);
va_end (argptr);
Con_Printf ("%s", msg);
}