13 #include <android/log.h>
16 #define FNDELAY O_NDELAY
26 #if SDL_MAJOR_VERSION == 1
27 #pragma comment(lib, "sdl.lib")
28 #pragma comment(lib, "sdlmain.lib")
30 #pragma comment(lib, "sdl2.lib")
31 #pragma comment(lib, "sdl2main.lib")
38 // =======================================================================
40 // =======================================================================
42 void Sys_Shutdown (void)
45 Sys_AllowProfiling(false);
48 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
55 void Sys_Error (const char *error, ...)
58 char string[MAX_INPUTLINE];
60 // change stdin to non blocking
62 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
65 va_start (argptr,error);
66 dpvsnprintf (string, sizeof (string), error, argptr);
69 Con_Printf ("Quake Error: %s\n", string);
72 MessageBox(NULL, string, "Quake Error", MB_OK | MB_SETFOREGROUND | MB_ICONSTOP);
80 void Sys_PrintToTerminal(const char *text)
83 if (developer.integer > 0)
85 __android_log_write(ANDROID_LOG_DEBUG, com_argv[0], text);
91 // BUG: for some reason, NDELAY also affects stdout (1) when used on stdin (0).
92 // this is because both go to /dev/tty by default!
94 int origflags = fcntl (outfd, F_GETFL, 0);
95 fcntl (outfd, F_SETFL, origflags & ~FNDELAY);
102 fs_offset_t written = (fs_offset_t)write(outfd, text, (int)strlen(text));
104 break; // sorry, I cannot do anything about this error - without an output
108 fcntl (outfd, F_SETFL, origflags);
111 //fprintf(stdout, "%s", text);
115 char *Sys_ConsoleInput(void)
117 // if (cls.state == ca_dedicated)
119 static char text[MAX_INPUTLINE];
150 if (len == sizeof (text))
155 struct timeval timeout;
157 FD_SET(0, &fdset); // stdin
160 if (select (1, &fdset, NULL, NULL, &timeout) != -1 && FD_ISSET(0, &fdset))
162 len = read (0, text, sizeof(text));
165 // rip off the \n and terminate
175 char *Sys_GetClipboardData (void)
177 #if SDL_MAJOR_VERSION != 1
181 cliptext = SDL_GetClipboardText();
182 if (cliptext != NULL) {
184 allocsize = strlen(cliptext) + 1;
185 data = (char *)Z_Malloc (allocsize);
186 strlcpy (data, cliptext, allocsize);
195 if (OpenClipboard (NULL) != 0)
197 HANDLE hClipboardData;
199 if ((hClipboardData = GetClipboardData (CF_TEXT)) != 0)
201 if ((cliptext = (char *)GlobalLock (hClipboardData)) != 0)
204 allocsize = GlobalSize (hClipboardData) + 1;
205 data = (char *)Z_Malloc (allocsize);
206 strlcpy (data, cliptext, allocsize);
207 GlobalUnlock (hClipboardData);
218 void Sys_InitConsole (void)
222 int main (int argc, char *argv[])
225 setlocale(LC_ALL, "");
228 signal(SIGFPE, SIG_IGN);
231 Sys_AllowProfiling(true);
235 com_argv = (const char **)argv;
238 // COMMANDLINEOPTION: sdl: -noterminal disables console output on stdout
239 if(COM_CheckParm("-noterminal"))
241 // COMMANDLINEOPTION: sdl: -stderr moves console output to stderr
242 else if(COM_CheckParm("-stderr"))
248 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
251 // we don't know which systems we'll want to init, yet...
259 qboolean sys_supportsdlgetticks = true;
260 unsigned int Sys_SDL_GetTicks (void)
262 return SDL_GetTicks();
264 void Sys_SDL_Delay (unsigned int milliseconds)
266 SDL_Delay(milliseconds);