]> icculus.org git repositories - divverent/darkplaces.git/blob - sys_shared.c
fixed a bug with Host_Startdemos_f that caused it to never shorten the list of demos...
[divverent/darkplaces.git] / sys_shared.c
1
2 #include "quakedef.h"
3 #include <time.h>
4 #ifndef WIN32
5 #include <unistd.h>
6 #include <fcntl.h>
7 #endif
8
9 extern cvar_t   timestamps;
10 extern cvar_t   timeformat;
11
12 static int sys_nostdout = false;
13
14 /* The translation table between the graphical font and plain ASCII  --KB */
15 static char qfont_table[256] = {
16         '\0', '#',  '#',  '#',  '#',  '.',  '#',  '#',
17         '#',  9,    10,   '#',  ' ',  13,   '.',  '.',
18         '[',  ']',  '0',  '1',  '2',  '3',  '4',  '5',
19         '6',  '7',  '8',  '9',  '.',  '<',  '=',  '>',
20         ' ',  '!',  '"',  '#',  '$',  '%',  '&',  '\'',
21         '(',  ')',  '*',  '+',  ',',  '-',  '.',  '/',
22         '0',  '1',  '2',  '3',  '4',  '5',  '6',  '7',
23         '8',  '9',  ':',  ';',  '<',  '=',  '>',  '?',
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         '`',  'a',  'b',  'c',  'd',  'e',  'f',  'g',
29         'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',
30         'p',  'q',  'r',  's',  't',  'u',  'v',  'w',
31         'x',  'y',  'z',  '{',  '|',  '}',  '~',  '<',
32
33         '<',  '=',  '>',  '#',  '#',  '.',  '#',  '#',
34         '#',  '#',  ' ',  '#',  ' ',  '>',  '.',  '.',
35         '[',  ']',  '0',  '1',  '2',  '3',  '4',  '5',
36         '6',  '7',  '8',  '9',  '.',  '<',  '=',  '>',
37         ' ',  '!',  '"',  '#',  '$',  '%',  '&',  '\'',
38         '(',  ')',  '*',  '+',  ',',  '-',  '.',  '/',
39         '0',  '1',  '2',  '3',  '4',  '5',  '6',  '7',
40         '8',  '9',  ':',  ';',  '<',  '=',  '>',  '?',
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         '`',  'a',  'b',  'c',  'd',  'e',  'f',  'g',
46         'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',
47         'p',  'q',  'r',  's',  't',  'u',  'v',  'w',
48         'x',  'y',  'z',  '{',  '|',  '}',  '~',  '<'
49 };
50
51 #ifdef WIN32
52 extern HANDLE hinput, houtput;
53 #endif
54
55 #define MAX_PRINT_MSG   16384
56 void Sys_Printf (const char *fmt, ...)
57 {
58         va_list         argptr;
59         char            start[MAX_PRINT_MSG];   // String we started with
60         char            stamp[MAX_PRINT_MSG];   // Time stamp
61         char            final[MAX_PRINT_MSG];   // String we print
62
63         time_t          mytime = 0;
64         struct tm       *local = NULL;
65
66         unsigned char           *p;
67 #ifdef WIN32
68         DWORD           dummy;
69 #endif
70
71         va_start (argptr, fmt);
72         vsnprintf (start, sizeof(start), fmt, argptr);
73         va_end (argptr);
74
75         if (sys_nostdout)
76                 return;
77
78         if (timestamps.integer)
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         // LordHavoc: make sure the string is terminated
90         final[MAX_PRINT_MSG - 1] = 0;
91         for (p = (unsigned char *) final;*p; p++)
92                 *p = qfont_table[*p];
93 #ifdef WIN32
94         if (cls.state == ca_dedicated)
95                 WriteFile(houtput, final, strlen (final), &dummy, NULL);
96 #else
97         printf("%s", final);
98 #endif
99 }
100
101
102 char engineversion[128];
103
104 void Sys_Shared_EarlyInit(void)
105 {
106         const char* os;
107
108         Memory_Init ();
109
110         COM_InitArgv();
111         COM_InitGameType();
112
113 #if defined(__linux__)
114         os = "Linux";
115 #elif defined(WIN32)
116         os = "Windows";
117 #else
118         os = "Unknown";
119 #endif
120         snprintf (engineversion, sizeof (engineversion), "%s %s %s", gamename, os, buildstring);
121
122         if (COM_CheckParm("-nostdout"))
123                 sys_nostdout = 1;
124         else
125                 Con_Printf("%s\n", engineversion);
126 }
127
128 void Sys_Shared_LateInit(void)
129 {
130 }
131