]> icculus.org git repositories - divverent/darkplaces.git/blob - sys_shared.c
added an extern for cmdline cvar
[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
52 #define MAXPRINTMSG 16384
53
54 void Sys_Print(const char *msg)
55 {
56         unsigned char *p;
57         // Time stamp
58         char stamp[128];
59         // String we print
60         char final[MAXPRINTMSG];
61
62         if (sys_nostdout)
63                 return;
64
65         if (timestamps.integer)
66         {
67                 time_t mytime = time(NULL);
68                 strftime(stamp, sizeof(stamp), timeformat.string, localtime(&mytime));
69                 snprintf(final, sizeof(final), "%s%s", stamp, msg);
70         }
71         else
72                 strncpy(final, msg, sizeof(final));
73
74         // LordHavoc: make sure the string is terminated
75         final[MAXPRINTMSG-1] = 0;
76         for (p = (unsigned char *) final;*p; p++)
77                 *p = qfont_table[*p];
78         Sys_PrintToTerminal(final);
79 }
80
81 void Sys_Printf(const char *fmt, ...)
82 {
83         va_list argptr;
84         char msg[MAXPRINTMSG];  // String we started with
85
86         va_start(argptr,fmt);
87         vsnprintf(msg,sizeof(msg),fmt,argptr);
88         va_end(argptr);
89
90         Sys_Print(msg);
91 }
92
93
94 char engineversion[128];
95
96 void Sys_Shared_EarlyInit(void)
97 {
98         const char* os;
99
100         Memory_Init ();
101
102         COM_InitArgv();
103         COM_InitGameType();
104
105 #if defined(__linux__)
106         os = "Linux";
107 #elif defined(WIN32)
108         os = "Windows";
109 #elif defined(__NetBSD__)
110         os = "NetBSD";
111 #elif defined(__OpenBSD__)
112         os = "OpenBSD";
113 #else
114         os = "Unknown";
115 #endif
116         snprintf (engineversion, sizeof (engineversion), "%s %s %s", gamename, os, buildstring);
117
118         if (COM_CheckParm("-nostdout"))
119                 sys_nostdout = 1;
120         else
121                 Con_Printf("%s\n", engineversion);
122 }
123
124 void Sys_Shared_LateInit(void)
125 {
126 }
127
128 /*
129 ===============================================================================
130
131 DLL MANAGEMENT
132
133 ===============================================================================
134 */
135
136 #ifndef WIN32
137 #include <dlfcn.h>
138 #endif
139
140 dllhandle_t Sys_LoadLibrary (const char* name)
141 {
142 #ifdef WIN32
143         return LoadLibrary (name);
144 #else
145         return dlopen (name, RTLD_LAZY);
146 #endif
147 }
148
149 void Sys_UnloadLibrary (dllhandle_t handle)
150 {
151 #ifdef WIN32
152         FreeLibrary (handle);
153 #else
154         dlclose (handle);
155 #endif
156 }
157
158 void* Sys_GetProcAddress (dllhandle_t handle, const char* name)
159 {
160 #ifdef WIN32
161         return (void *)GetProcAddress (handle, name);
162 #else
163         return (void *)dlsym (handle, name);
164 #endif
165 }
166