From: deek Date: Tue, 12 Sep 2000 15:12:18 +0000 (+0000) Subject: host.c, sys_linux.c: Clear up linefeeds in Sys_Printf() -- we don't need to X-Git-Tag: RELEASE_0_2_0_RC1~992 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=commitdiff_plain;h=e9e47ab1cc26ca266eb185efdfa2ba919690b0b9 host.c, sys_linux.c: Clear up linefeeds in Sys_Printf() -- we don't need to add them, they should already be in there. Also, add optional timestamping to console - doesn't work well with messages that call Sys_Printf() multiple times, but for the rest it works fine. cvar names: timestamps (int), timeformat (string) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@28 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/host.c b/host.c index 72457eee..08ebecf7 100644 --- a/host.c +++ b/host.c @@ -77,6 +77,8 @@ cvar_t pausable = {"pausable","1"}; cvar_t temp1 = {"temp1","0"}; +cvar_t timestamps = {"timestamps", "0", true}; +cvar_t timeformat = {"timeformat", "[%b %e %X] ", true}; /* ================ @@ -227,6 +229,9 @@ void Host_InitLocal (void) Cvar_RegisterVariable (&temp1); + Cvar_RegisterVariable (×tamps); + Cvar_RegisterVariable (&timeformat); + Host_FindMaxClients (); host_time = 1.0; // so a think at time 0 won't get called diff --git a/makefile b/makefile index 175b2301..e8782235 100644 --- a/makefile +++ b/makefile @@ -1,9 +1,10 @@ -OBJECTS = cd_linux.o chase.o cl_demo.o cl_input.o cl_main.o cl_parse.o cl_tent.o cmd.o common.o console.o cpu_noasm.o crc.o cvar.o fractalnoise.o gl_draw.o gl_poly.o gl_refrag.o gl_rmain.o gl_rmisc.o gl_rsurf.o gl_screen.o gl_warp.o host.o host_cmd.o image.o keys.o mathlib.o menu.o model_alias.o model_brush.o model_shared.o model_sprite.o net_bsd.o net_udp.o net_dgrm.o net_loop.o net_main.o net_vcr.o pr_cmds.o pr_edict.o pr_exec.o r_light.o r_part.o sbar.o snd_dma.o snd_mem.o snd_mix.o snd_linux.o sv_main.o sv_move.o sv_phys.o sv_user.o sys_linux.o transform.o view.o wad.o world.o zone.o vid_shared.o +OBJECTS= cd_linux.o chase.o cl_demo.o cl_input.o cl_main.o cl_parse.o cl_tent.o cmd.o common.o console.o cpu_noasm.o crc.o cvar.o fractalnoise.o gl_draw.o gl_poly.o gl_refrag.o gl_rmain.o gl_rmisc.o gl_rsurf.o gl_screen.o gl_warp.o host.o host_cmd.o image.o keys.o mathlib.o menu.o model_alias.o model_brush.o model_shared.o model_sprite.o net_bsd.o net_udp.o net_dgrm.o net_loop.o net_main.o net_vcr.o pr_cmds.o pr_edict.o pr_exec.o r_light.o r_part.o sbar.o snd_dma.o snd_mem.o snd_mix.o snd_linux.o sv_main.o sv_move.o sv_phys.o sv_user.o sys_linux.o transform.o view.o wad.o world.o zone.o vid_shared.o -OPTIMIZATIONS = -O6 -ffast-math -funroll-loops -fomit-frame-pointer -fexpensive-optimizations -CFLAGS = -Wall -Werror -I/usr/X11R6/include -I/usr/include/glide $(OPTIMIZATIONS) -#CFLAGS = -Wall -Werror -I/usr/X11/include -ggdb $(OPTIMIZATIONS) -LIBS = -L/usr/X11R6/lib -lc -lm -lXext -lXxf86dga -lXxf86vm -lGL -ldl +OPTIMIZATIONS= -O6 -ffast-math -funroll-loops -fomit-frame-pointer -fexpensive-optimizations + +CFLAGS= -Wall -Werror -I/usr/X11R6/include -I/usr/include/glide $(OPTIMIZATIONS) +#CFLAGS= -Wall -Werror -I/usr/X11/include -ggdb $(OPTIMIZATIONS) +LDFLAGS= -L/usr/X11R6/lib -lm -lX11 -lXext -lXIE -lXxf86dga -lXxf86vm -lGL -ldl all: darkplaces-glx darkplaces-3dfx @@ -11,7 +12,7 @@ all: darkplaces-glx darkplaces-3dfx gcc $(CFLAGS) -c $*.c darkplaces-glx: $(OBJECTS) vid_glx.o - gcc -o $@ $^ $(LIBS) + gcc -o $@ $^ $(LDFLAGS) darkplaces-3dfx: $(OBJECTS) in_svgalib.o vid_3dfxsvga.o gcc -o $@ $^ $(LIBS) diff --git a/sys_linux.c b/sys_linux.c index 30fba39b..dc19728c 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -1,20 +1,21 @@ -#include -#include #include -#include -#include +#include +#include + #include +#include #include #include -#include -#include + +#include +#include #include #include -#include -#include -#include +#include #include #include +#include +#include #include #include "quakedef.h" @@ -28,6 +29,46 @@ char *cachedir = "/tmp"; cvar_t sys_linerefresh = {"sys_linerefresh","0"};// set for entity display +extern cvar_t timestamps; +extern cvar_t timeformat; + +/* The translation table between the graphical font and plain ASCII --KB */ +static char qfont_table[256] = { + '\0', '#', '#', '#', '#', '.', '#', '#', + '#', 9, 10, '#', ' ', 13, '.', '.', + '[', ']', '0', '1', '2', '3', '4', '5', + '6', '7', '8', '9', '.', '<', '=', '>', + ' ', '!', '"', '#', '$', '%', '&', '\'', + '(', ')', '*', '+', ',', '-', '.', '/', + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', ':', ';', '<', '=', '>', '?', + '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', + 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', + 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', + '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', + 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', + 'x', 'y', 'z', '{', '|', '}', '~', '<', + + '<', '=', '>', '#', '#', '.', '#', '#', + '#', '#', ' ', '#', ' ', '>', '.', '.', + '[', ']', '0', '1', '2', '3', '4', '5', + '6', '7', '8', '9', '.', '<', '=', '>', + ' ', '!', '"', '#', '$', '%', '&', '\'', + '(', ')', '*', '+', ',', '-', '.', '/', + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', ':', ';', '<', '=', '>', '?', + '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', + 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', + 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', + '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', + 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', + 'x', 'y', 'z', '{', '|', '}', '~', '<' +}; + // ======================================================================= // General routines // ======================================================================= @@ -83,41 +124,40 @@ void Sys_Printf (char *fmt, ...) } */ -char sysprintfbuf1[1024]; -char sysprintfbuf2[4096]; -char sysprintfhextable[] = "0123456789ABCDEF"; +#define MAX_PRINT_MSG 4096 void Sys_Printf (char *fmt, ...) { va_list argptr; - char c, *o; - int i; + char start[MAX_PRINT_MSG]; // String we started with + char stamp[MAX_PRINT_MSG]; // Time stamp + char final[MAX_PRINT_MSG]; // String we print - va_start (argptr,fmt); - vsprintf (sysprintfbuf1,fmt,argptr); - va_end (argptr); + time_t mytime = 0; + struct tm *local = NULL; - if (strlen(sysprintfbuf1) > 1023) - Sys_Error("memory overwrite in Sys_Printf"); + unsigned char *p; + + va_start (argptr, fmt); + vsnprintf (start, sizeof(start), fmt, argptr); + va_end (argptr); if (nostdout) return; - o = sysprintfbuf2; - for (i = 0;i < 1023 && sysprintfbuf1[i];i++) - { - c = sysprintfbuf1[i] & 0x7f; - if (c < 32 && c != 10 && c != 13 && c != 9) - { - *o++ = '['; - *o++ = sysprintfhextable[(c >> 4)]; - *o++ = sysprintfhextable[c & 0x0F]; - *o++ = ']'; - } - else - *o++ = c; + if (timestamps.value) { + mytime = time (NULL); + local = localtime (&mytime); + strftime (stamp, sizeof (stamp), timeformat.string, local); + + snprintf (final, sizeof (final), "%s%s", stamp, start); + } else { + snprintf (final, sizeof (final), "%s", start); + } + + for (p = (unsigned char *) final; *p; p++) { + putc (qfont_table[*p], stdout); } - *o++ = 0; - puts(sysprintfbuf2); + fflush (stdout); } #if 0