]> icculus.org git repositories - divverent/darkplaces.git/blob - sys_shared.c
moved Sys_Printf and related code/data to sys_shared.c (new), removed all uses of...
[divverent/darkplaces.git] / sys_shared.c
1
2 #include "quakedef.h"
3 #include <time.h>
4
5 extern cvar_t   timestamps;
6 extern cvar_t   timeformat;
7
8 static int sys_nostdout = false;
9
10 /* The translation table between the graphical font and plain ASCII  --KB */
11 static char qfont_table[256] = {
12         '\0', '#',  '#',  '#',  '#',  '.',  '#',  '#',
13         '#',  9,    10,   '#',  ' ',  13,   '.',  '.',
14         '[',  ']',  '0',  '1',  '2',  '3',  '4',  '5',
15         '6',  '7',  '8',  '9',  '.',  '<',  '=',  '>',
16         ' ',  '!',  '"',  '#',  '$',  '%',  '&',  '\'',
17         '(',  ')',  '*',  '+',  ',',  '-',  '.',  '/',
18         '0',  '1',  '2',  '3',  '4',  '5',  '6',  '7',
19         '8',  '9',  ':',  ';',  '<',  '=',  '>',  '?',
20         '@',  'A',  'B',  'C',  'D',  'E',  'F',  'G',
21         'H',  'I',  'J',  'K',  'L',  'M',  'N',  'O',
22         'P',  'Q',  'R',  'S',  'T',  'U',  'V',  'W',
23         'X',  'Y',  'Z',  '[',  '\\', ']',  '^',  '_',
24         '`',  'a',  'b',  'c',  'd',  'e',  'f',  'g',
25         'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',
26         'p',  'q',  'r',  's',  't',  'u',  'v',  'w',
27         'x',  'y',  'z',  '{',  '|',  '}',  '~',  '<',
28
29         '<',  '=',  '>',  '#',  '#',  '.',  '#',  '#',
30         '#',  '#',  ' ',  '#',  ' ',  '>',  '.',  '.',
31         '[',  ']',  '0',  '1',  '2',  '3',  '4',  '5',
32         '6',  '7',  '8',  '9',  '.',  '<',  '=',  '>',
33         ' ',  '!',  '"',  '#',  '$',  '%',  '&',  '\'',
34         '(',  ')',  '*',  '+',  ',',  '-',  '.',  '/',
35         '0',  '1',  '2',  '3',  '4',  '5',  '6',  '7',
36         '8',  '9',  ':',  ';',  '<',  '=',  '>',  '?',
37         '@',  'A',  'B',  'C',  'D',  'E',  'F',  'G',
38         'H',  'I',  'J',  'K',  'L',  'M',  'N',  'O',
39         'P',  'Q',  'R',  'S',  'T',  'U',  'V',  'W',
40         'X',  'Y',  'Z',  '[',  '\\', ']',  '^',  '_',
41         '`',  'a',  'b',  'c',  'd',  'e',  'f',  'g',
42         'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o', 
43         'p',  'q',  'r',  's',  't',  'u',  'v',  'w',
44         'x',  'y',  'z',  '{',  '|',  '}',  '~',  '<'
45 };
46
47 #ifdef WIN32
48 extern HANDLE hinput, houtput;
49 #endif
50
51 #define MAX_PRINT_MSG   16384
52 void Sys_Printf (char *fmt, ...)
53 {
54         va_list         argptr;
55         char            start[MAX_PRINT_MSG];   // String we started with
56         char            stamp[MAX_PRINT_MSG];   // Time stamp
57         char            final[MAX_PRINT_MSG];   // String we print
58
59         time_t          mytime = 0;
60         struct tm       *local = NULL;
61
62         unsigned char           *p;
63 #ifdef WIN32
64         DWORD           dummy;
65 #endif
66
67         va_start (argptr, fmt);
68 #ifdef HAVE_VSNPRINTF
69         vsnprintf (start, sizeof(start), fmt, argptr);
70 #else
71         vsprintf (start, fmt, argptr);
72 #endif
73         va_end (argptr);
74
75         if (sys_nostdout)
76                 return;
77
78         if (timestamps.value)
79         {
80                 mytime = time (NULL);
81                 local = localtime (&mytime);
82                 strftime (stamp, sizeof (stamp), timeformat.string, local);
83                 
84                 snprintf (final, sizeof (final), "%s%s", stamp, start);
85         }
86         else
87                 snprintf (final, sizeof (final), "%s", start);
88
89         for (p = (unsigned char *) final; *p; p++)
90                 *p = qfont_table[*p];
91 #ifdef WIN32
92         if (cls.state == ca_dedicated)
93                 WriteFile(houtput, final, strlen (final), &dummy, NULL);        
94 #else
95         puts(final);
96 #endif
97 //      for (p = (unsigned char *) final; *p; p++)
98 //              putc (qfont_table[*p], stdout);
99 #ifndef WIN32
100         fflush (stdout);
101 #endif
102 }
103
104 void Sys_Shared_Init(void)
105 {
106         if (COM_CheckParm("-nostdout"))
107                 sys_nostdout = 1;
108         else
109         {
110 #if defined(__linux__)
111                 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
112                 printf ("DarkPlaces Linux   GL %.2f build %3i", (float) VERSION, buildnumber);
113 #elif defined(WIN32)
114                 printf ("DarkPlaces Windows GL %.2f build %3i", (float) VERSION, buildnumber);
115 #else
116                 printf ("DarkPlaces Unknown GL %.2f build %3i", (float) VERSION, buildnumber);
117 #endif
118         }
119 }