16 // =======================================================================
18 // =======================================================================
20 void Sys_Shutdown (void)
23 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
30 void Sys_Error (const char *error, ...)
33 char string[MAX_INPUTLINE];
35 // change stdin to non blocking
37 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
40 va_start (argptr,error);
41 dpvsnprintf (string, sizeof (string), error, argptr);
44 Con_Printf ("Quake Error: %s\n", string);
50 void Sys_PrintToTerminal(const char *text)
53 // BUG: for some reason, NDELAY also affects stdout (1) when used on stdin (0).
54 int origflags = fcntl (1, F_GETFL, 0);
55 fcntl (1, F_SETFL, origflags & ~FNDELAY);
59 int written = (int)write(1, text, (int)strlen(text));
61 break; // sorry, I cannot do anything about this error - without an output
65 fcntl (1, F_SETFL, origflags);
67 //fprintf(stdout, "%s", text);
70 double Sys_DoubleTime (void)
72 static int first = true;
73 static double oldtime = 0.0, curtime = 0.0;
75 newtime = (double) SDL_GetTicks() / 1000.0;
84 if (newtime < oldtime)
86 // warn if it's significant
87 if (newtime - oldtime < -0.01)
88 Con_Printf("Sys_DoubleTime: time stepped backwards (went from %f to %f, difference %f)\n", oldtime, newtime, newtime - oldtime);
90 else if (newtime > oldtime + 1800)
92 Con_Printf("Sys_DoubleTime: time stepped forward (went from %f to %f, difference %f)\n", oldtime, newtime, newtime - oldtime);
95 curtime += newtime - oldtime;
101 char *Sys_ConsoleInput(void)
103 if (cls.state == ca_dedicated)
105 static char text[MAX_INPUTLINE];
136 if (len == sizeof (text))
141 struct timeval timeout;
143 FD_SET(0, &fdset); // stdin
146 if (select (1, &fdset, NULL, NULL, &timeout) != -1 && FD_ISSET(0, &fdset))
148 len = read (0, text, sizeof(text));
151 // rip off the \n and terminate
161 void Sys_Sleep(int microseconds)
163 SDL_Delay(microseconds / 1000);
166 char *Sys_GetClipboardData (void)
172 if (OpenClipboard (NULL) != 0)
174 HANDLE hClipboardData;
176 if ((hClipboardData = GetClipboardData (CF_TEXT)) != 0)
178 if ((cliptext = GlobalLock (hClipboardData)) != 0)
181 allocsize = GlobalSize (hClipboardData) + 1;
182 data = Z_Malloc (allocsize);
183 strlcpy (data, cliptext, allocsize);
184 GlobalUnlock (hClipboardData);
195 void Sys_InitConsole (void)
199 void Sys_Init_Commands (void)
203 int main (int argc, char *argv[])
205 signal(SIGFPE, SIG_IGN);
208 com_argv = (const char **)argv;
211 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
214 // we don't know which systems we'll want to init, yet...