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);
75 void Sys_PrintToTerminal(const char *text)
78 if (developer.integer > 0)
80 __android_log_write(ANDROID_LOG_DEBUG, com_argv[0], text);
86 // BUG: for some reason, NDELAY also affects stdout (1) when used on stdin (0).
87 // this is because both go to /dev/tty by default!
89 int origflags = fcntl (outfd, F_GETFL, 0);
90 fcntl (outfd, F_SETFL, origflags & ~FNDELAY);
97 fs_offset_t written = (fs_offset_t)write(outfd, text, (int)strlen(text));
99 break; // sorry, I cannot do anything about this error - without an output
103 fcntl (outfd, F_SETFL, origflags);
106 //fprintf(stdout, "%s", text);
110 char *Sys_ConsoleInput(void)
112 // if (cls.state == ca_dedicated)
114 static char text[MAX_INPUTLINE];
145 if (len == sizeof (text))
150 struct timeval timeout;
152 FD_SET(0, &fdset); // stdin
155 if (select (1, &fdset, NULL, NULL, &timeout) != -1 && FD_ISSET(0, &fdset))
157 len = read (0, text, sizeof(text));
160 // rip off the \n and terminate
170 char *Sys_GetClipboardData (void)
176 if (OpenClipboard (NULL) != 0)
178 HANDLE hClipboardData;
180 if ((hClipboardData = GetClipboardData (CF_TEXT)) != 0)
182 if ((cliptext = (char *)GlobalLock (hClipboardData)) != 0)
185 allocsize = GlobalSize (hClipboardData) + 1;
186 data = (char *)Z_Malloc (allocsize);
187 strlcpy (data, cliptext, allocsize);
188 GlobalUnlock (hClipboardData);
199 void Sys_InitConsole (void)
203 int main (int argc, char *argv[])
205 signal(SIGFPE, SIG_IGN);
208 Sys_AllowProfiling(true);
212 com_argv = (const char **)argv;
215 // COMMANDLINEOPTION: sdl: -noterminal disables console output on stdout
216 if(COM_CheckParm("-noterminal"))
218 // COMMANDLINEOPTION: sdl: -stderr moves console output to stderr
219 else if(COM_CheckParm("-stderr"))
225 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
228 // we don't know which systems we'll want to init, yet...
236 qboolean sys_supportsdlgetticks = true;
237 unsigned int Sys_SDL_GetTicks (void)
239 return SDL_GetTicks();
241 void Sys_SDL_Delay (unsigned int milliseconds)
243 SDL_Delay(milliseconds);