]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
host.c, sys_linux.c: Clear up linefeeds in Sys_Printf() -- we don't need to
authordeek <deek@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 12 Sep 2000 15:12:18 +0000 (15:12 +0000)
committerdeek <deek@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 12 Sep 2000 15:12:18 +0000 (15:12 +0000)
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

host.c
makefile
sys_linux.c

diff --git a/host.c b/host.c
index 72457eee96462ebb69ef4ffde01369e904853f60..08ebecf7d76106bd65a8a67419de410653ca555f 100644 (file)
--- 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 (&timestamps);
+       Cvar_RegisterVariable (&timeformat);
+
        Host_FindMaxClients ();
        
        host_time = 1.0;                // so a think at time 0 won't get called
index 175b2301b00c6a0163f357e2ab0da07b30f0454c..e878223568290ddfe9084a6c5e6787a1058078f3 100644 (file)
--- 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)
index 30fba39b80eae267b1ee5a33e2f12e1061c74b2d..dc19728cefc6e19ee353ec8fe496114d70650ff6 100644 (file)
@@ -1,20 +1,21 @@
-#include <unistd.h>
-#include <signal.h>
 #include <stdlib.h>
-#include <limits.h>
-#include <sys/time.h>
+#include <stdio.h>
+#include <stdarg.h>
+
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <stdarg.h>
-#include <stdio.h>
+
+#include <signal.h>
+#include <limits.h>
 #include <sys/ipc.h>
 #include <sys/shm.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <ctype.h>
+#include <sys/time.h>
 #include <sys/wait.h>
 #include <sys/mman.h>
+#include <string.h>
+#include <ctype.h>
 #include <errno.h>
 
 #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