12 #include <android/log.h>
15 #define FNDELAY O_NDELAY
25 #if SDL_MAJOR_VERSION == 1
26 #pragma comment(lib, "sdl.lib")
27 #pragma comment(lib, "sdlmain.lib")
29 #pragma comment(lib, "sdl2.lib")
30 #pragma comment(lib, "sdl2main.lib")
37 // =======================================================================
39 // =======================================================================
41 void Sys_Shutdown (void)
44 Sys_AllowProfiling(false);
47 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
54 void Sys_Error (const char *error, ...)
57 char string[MAX_INPUTLINE];
59 // change stdin to non blocking
61 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
64 va_start (argptr,error);
65 dpvsnprintf (string, sizeof (string), error, argptr);
68 Con_Printf ("Quake Error: %s\n", string);
71 MessageBox(NULL, string, "Quake Error", MB_OK | MB_SETFOREGROUND | MB_ICONSTOP);
79 void Sys_PrintToTerminal(const char *text)
82 if (developer.integer > 0)
84 __android_log_write(ANDROID_LOG_DEBUG, com_argv[0], text);
90 // BUG: for some reason, NDELAY also affects stdout (1) when used on stdin (0).
91 // this is because both go to /dev/tty by default!
93 int origflags = fcntl (outfd, F_GETFL, 0);
94 fcntl (outfd, F_SETFL, origflags & ~FNDELAY);
101 fs_offset_t written = (fs_offset_t)write(outfd, text, (int)strlen(text));
103 break; // sorry, I cannot do anything about this error - without an output
107 fcntl (outfd, F_SETFL, origflags);
110 //fprintf(stdout, "%s", text);
114 char *Sys_ConsoleInput(void)
116 // if (cls.state == ca_dedicated)
118 static char text[MAX_INPUTLINE];
149 if (len == sizeof (text))
154 struct timeval timeout;
156 FD_SET(0, &fdset); // stdin
159 if (select (1, &fdset, NULL, NULL, &timeout) != -1 && FD_ISSET(0, &fdset))
161 len = read (0, text, sizeof(text));
164 // rip off the \n and terminate
174 char *Sys_GetClipboardData (void)
176 #if SDL_MAJOR_VERSION != 1
180 cliptext = SDL_GetClipboardText();
181 if (cliptext != NULL) {
183 allocsize = strlen(cliptext) + 1;
184 data = (char *)Z_Malloc (allocsize);
185 strlcpy (data, cliptext, allocsize);
194 if (OpenClipboard (NULL) != 0)
196 HANDLE hClipboardData;
198 if ((hClipboardData = GetClipboardData (CF_TEXT)) != 0)
200 if ((cliptext = (char *)GlobalLock (hClipboardData)) != 0)
203 allocsize = GlobalSize (hClipboardData) + 1;
204 data = (char *)Z_Malloc (allocsize);
205 strlcpy (data, cliptext, allocsize);
206 GlobalUnlock (hClipboardData);
217 void Sys_InitConsole (void)
221 int main (int argc, char *argv[])
223 signal(SIGFPE, SIG_IGN);
226 Sys_AllowProfiling(true);
230 com_argv = (const char **)argv;
233 // COMMANDLINEOPTION: sdl: -noterminal disables console output on stdout
234 if(COM_CheckParm("-noterminal"))
236 // COMMANDLINEOPTION: sdl: -stderr moves console output to stderr
237 else if(COM_CheckParm("-stderr"))
243 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
246 // we don't know which systems we'll want to init, yet...
254 qboolean sys_supportsdlgetticks = true;
255 unsigned int Sys_SDL_GetTicks (void)
257 return SDL_GetTicks();
259 void Sys_SDL_Delay (unsigned int milliseconds)
261 SDL_Delay(milliseconds);