shithub: qk1

Download patch

ref: d193ea7221257855663b31a409adbbd77bf86110
parent: b5c21ec18207ea25ca3461e12b78fe82a8e1ed34
author: qwx <qwx@sciops.net>
date: Tue Aug 24 12:04:52 EDT 2021

don't print any debug or console messages to stdin/err by default

--- a/cl_demo.c
+++ b/cl_demo.c
@@ -78,7 +78,7 @@
 		if(r != 1 && r != 2)
 			return r;
 		if(net_message.cursize == 1 && net_message.data[0] == svc_nop)
-			dprint("<-- server to client keepalive");
+			dprint("<-- server to client keepalive\n");
 		else
 			break;
 	}
--- a/cl_main.c
+++ b/cl_main.c
@@ -95,7 +95,7 @@
 		if (cls.demorecording)
 			stopdemo();
 
-		print("CL_Disconnect: sending clc_disconnect...\n");
+		dprint("CL_Disconnect: sending clc_disconnect...\n");
 		SZ_Clear (&cls.message);
 		MSG_WriteByte (&cls.message, clc_disconnect);
 		NET_SendUnreliableMessage (cls.netcon, &cls.message);
@@ -141,7 +141,7 @@
 	cls.netcon = NET_Connect (host);
 	if (!cls.netcon)
 		Host_Error ("CL_Connect: connect failed\n");
-	print("CL_EstablishConnection: connected to %s\n", host);
+	dprint("CL_EstablishConnection: connected to %s\n", host);
 	
 	cls.demonum = -1;			// not in the demo loop now
 	cls.state = ca_connected;
@@ -159,7 +159,7 @@
 {
 	char 	str[8192];
 
-	print("CL_SignonReply: got %d\n", cls.signon);
+	dprint("CL_SignonReply: got %d\n", cls.signon);
 
 	switch (cls.signon)
 	{
--- a/cl_parse.c
+++ b/cl_parse.c
@@ -192,7 +192,7 @@
 	char	model_precache[MAX_MODELS][Npath];
 	char	sound_precache[MAX_SOUNDS][Npath];
 
-	print("CL_ParseServerInfo: parsing serverinfo pkt...\n");
+	dprint("CL_ParseServerInfo: parsing serverinfo pkt...\n");
 //
 // wipe the client_state_t struct
 //
--- a/console.c
+++ b/console.c
@@ -293,6 +293,8 @@
 {
 	char buf[4096], *p, *d;
 
+	if(!debug)
+		return;
 	p = s;
 	d = buf;
 	while(*p)
--- a/d_surf.c
+++ b/d_surf.c
@@ -190,8 +190,8 @@
 
 	for(s = sc_base; s != nil; s = s->next){
 		if(s == sc_rover)
-			print("ROVER:\n");
-		print("%p : %d bytes     %ud width\n", s, s->size, s->width);
+			dprint("ROVER:\n");
+		dprint("%p : %d bytes     %ud width\n", s, s->size, s->width);
 	}
 }
 
--- a/dat.h
+++ b/dat.h
@@ -45,3 +45,4 @@
 #define Spktatt 1.0
 
 extern int dumpwin, scaleon;
+extern int debug;
--- a/fs.c
+++ b/fs.c
@@ -508,12 +508,12 @@
 		strcpy(*s, "--- UNUSED SLOT ---");
 		bf = bopen(va("%s/s%d.sav", fsdir, n), OREAD, 1);
 		if(bf == nil){
-			dprint("savnames: %r");
+			dprint("savnames: %r\n");
 			continue;
 		}
 		if((p = Brdline(bf, '\n'), p == nil)	/* discard version */
 		|| (p = Brdline(bf, '\n'), p == nil)){
-			dprint("savnames: short read: %r");
+			dprint("savnames: short read: %r\n");
 			continue;
 		}
 		strncpy(*s, p, sizeof(*s)-1);
@@ -762,9 +762,9 @@
 	n = Bread(demobf, net_message.data, net_message.cursize);
 	demoofs = Bseek(demobf, 0, 1);
 	if(n < 0)
-		dprint("readdm: bad read: %r");
+		dprint("readdm: bad read: %r\n");
 	if(n != net_message.cursize){
-		dprint("readdm: short read: %r");
+		dprint("readdm: short read: %r\n");
 		n = -1;
 	}
 	return n;
@@ -782,7 +782,7 @@
 	s = Brdline(demobf, '\n');
 	n = Blinelen(demobf) - 1;
 	if(s == nil || n < 0 || n > 11){
-		dprint("loaddm: invalid trk field");
+		dprint("loaddm: invalid trk field\n");
 		closelmp(demobf);
 		return -1;
 	}
@@ -869,7 +869,7 @@
 		snprint(f, sizeof f, "%s/pak%d.pak", d, n);
 		p = pak(f);
 		if(p == nil){
-			dprint("pakdir: %r");
+			dprint("pakdir: %r\n");
 			break;
 		}
 		pl = Hunk_Alloc(sizeof *pl);
@@ -914,7 +914,7 @@
 	Cvar_RegisterVariable(&registered);
 	bf = openlmp("gfx/pop.lmp", nil);
 	if(bf == nil){
-		dprint("chkreg: shareware version");
+		dprint("chkreg: shareware version\n");
 		if(notid1)
 			fatal("chkreg: phase error -- %r");
 		return;
@@ -925,7 +925,7 @@
 			fatal("chkreg: corrupted pop lump");
 	closelmp(bf);
 	setcvar("registered", "1");
-	dprint("chkreg: registered version");
+	dprint("chkreg: registered version\n");
 }
 
 /* TODO: nuke these from orbit */
--- a/host.c
+++ b/host.c
@@ -68,7 +68,7 @@
 	vsnprint(s, sizeof s, fmt, arg);
 	va_end(arg);
 
-	print("Host_EndGame: %s\n", s);
+	dprint("Host_EndGame: %s\n", s);
 
 	if(sv.active)
 		Host_ShutdownServer(false);
@@ -280,7 +280,7 @@
 			pr_global_struct->self = saveSelf;
 		}
 
-		print("client %s removed\n", host_client->name);
+		dprint("client %s removed\n", host_client->name);
 	}
 
 // break the net connection
@@ -391,7 +391,7 @@
 */
 void Host_ClearMemory (void)
 {
-	print("Clearing memory\n");
+	dprint("Clearing memory\n");
 	D_FlushCaches ();
 	Mod_ClearAll ();
 	if (host_hunklevel)
@@ -647,7 +647,7 @@
 	
 	if (isdown)
 	{
-		print ("recursive shutdown\n");
+		fprint(2, "Host_Shutdown: recursive shutdown\n");
 		return;
 	}
 	isdown = true;
--- a/host_cmd.c
+++ b/host_cmd.c
@@ -461,7 +461,7 @@
 	}
 	host_client = save;
 
-	print("%s", &text[1]);
+	dprint("%s", &text[1]);
 }
 
 
@@ -718,7 +718,7 @@
 		PR_ExecuteProgram (pr_global_struct->ClientConnect);
 
 		if ((dtime() - host_client->netconnection->connecttime) <= sv.time)
-			print("%s entered the game\n", host_client->name);
+			dprint("%s entered the game\n", host_client->name);
 
 		PR_ExecuteProgram (pr_global_struct->PutClientInServer);	
 	}
--- a/pr_edict.c
+++ b/pr_edict.c
@@ -882,7 +882,7 @@
 		PR_ExecuteProgram (func - pr_functions);
 	}	
 
-	print("%d entities inhibited\n", inhibit);
+	dprint("%d entities inhibited\n", inhibit);
 }
 
 
@@ -904,7 +904,7 @@
 	progs = loadhunklmp("progs.dat", &n);
 	if(progs == nil)
 		fatal("PR_LoadProgs: %r");
-	print("Programs occupy %dK.\n", n/1024);
+	dprint("Programs occupy %dK.\n", n/1024);
 
 	for (i=0 ; i<n ; i++)
 		crc (((byte *)progs)[i]);
--- a/qk1.c
+++ b/qk1.c
@@ -10,6 +10,7 @@
 uchar *membase;
 int memsize;
 char *game;
+int debug;
 
 enum{
 	KB = 1024*1024,
@@ -16,8 +17,6 @@
 	Nmem = 64 * KB
 };
 
-static int debug;
-
 void
 dprint(char *fmt, ...)
 {
@@ -29,7 +28,7 @@
 	va_start(arg, fmt);
 	vseprint(s, s+sizeof s, fmt, arg);
 	va_end(arg);
-	fprint(2, "%s\n", s);
+	fprint(2, "%s", s);
 }
 
 /* FIXME: merge dprint/fatal? */
@@ -121,6 +120,9 @@
 
 	memsize = Nmem;
 	ARGBEGIN{
+	case 'D':
+		debug = 1;
+		break;
 	case 'd':
 		dedicated = 1;
 		break;
--- a/qw/cl_main.c
+++ b/qw/cl_main.c
@@ -1395,7 +1395,7 @@
 	
 	if (isdown)
 	{
-		printf ("recursive shutdown\n");
+		Sys_Printf ("recursive shutdown\n");
 		return;
 	}
 	isdown = true;
--- a/qw/d_surf.c
+++ b/qw/d_surf.c
@@ -204,7 +204,7 @@
 	{
 		if (test == sc_rover)
 			Sys_Printf ("ROVER:\n");
-		printf ("%p : %d bytes     %d width\n",test, test->size, test->width);
+		Sys_Printf ("%p : %d bytes     %d width\n",test, test->size, test->width);
 	}
 }
 
--- a/qw/sys.c
+++ b/qw/sys.c
@@ -4,7 +4,7 @@
 #include <thread.h>
 #include "quakedef.h"
 
-int svonly;
+int svonly, debug;
 
 void *
 emalloc(ulong n)
@@ -24,16 +24,17 @@
 	char *p;
 	va_list arg;
 
+	if(!svonly && !debug)
+		return;
 	va_start(arg, fmt);
 	vseprint(buf, buf+sizeof(buf), fmt, arg);
 	va_end(arg);
-
 	for(p = buf; *p; p++){
 		*p &= 0x7f;
 		if(*p < 32 && *p != 10 && *p != 13 && *p != 9)
-			print("[%02x]", *p);
+			fprint(2, "[%02x]", *p);
 		else
-			print("%c", *p);
+			fprint(2, "%c", *p);
 	}
 }
 
@@ -115,6 +116,8 @@
 
 	if(i = COM_CheckParm("-mem"))
 		q->memsize = atoi(com_argv[i+1]) * 1024*1024;
+	if(COM_CheckParm("-debug"))
+		debug = 1;
 	if((q->membase = malloc(q->memsize)) == nil)
 		sysfatal("initparm:malloc: %r");
 }
--- a/sv_main.c
+++ b/sv_main.c
@@ -233,7 +233,7 @@
 
 	client = svs.clients + clientnum;
 
-	print("client %s connected\n", client->netconnection->address);
+	dprint("client %s connected\n", client->netconnection->address);
 
 	edictnum = clientnum+1;
 
@@ -1010,7 +1010,7 @@
 		setcvar ("hostname", "UNNAMED");
 	scr_centertime_off = 0;
 
-	print("SV_SpawnServer: %s\n", server);
+	dprint("SV_SpawnServer: %s\n", server);
 	svs.changelevel_issued = false;		// now safe to issue another
 
 //
@@ -1146,6 +1146,6 @@
 			SV_SendServerinfo (host_client);
 
 	IN_Grabm(1);
-	print("server spawned\n");
+	dprint("server spawned\n");
 }
 
--- a/zone.c
+++ b/zone.c
@@ -739,7 +739,7 @@
 void
 Cache_Report(void)
 {
-	print("%4.1f megabyte data cache\n",
+	dprint("%4.1f megabyte data cache\n",
 		(memsize - hunk_high_used - hunk_low_used)
 		/ (float)(1024*1024));
 }