17 // =======================================================================
19 // =======================================================================
21 void Sys_Shutdown (void)
24 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
31 void Sys_Error (const char *error, ...)
34 char string[MAX_INPUTLINE];
36 // change stdin to non blocking
38 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
41 va_start (argptr,error);
42 dpvsnprintf (string, sizeof (string), error, argptr);
45 Con_Printf ("Quake Error: %s\n", string);
51 void Sys_PrintToTerminal(const char *text)
54 // BUG: for some reason, NDELAY also affects stdout (1) when used on stdin (0).
55 int origflags = fcntl (1, F_GETFL, 0);
56 fcntl (1, F_SETFL, origflags & ~FNDELAY);
60 int written = (int)write(1, text, (int)strlen(text));
62 break; // sorry, I cannot do anything about this error - without an output
66 fcntl (1, F_SETFL, origflags);
68 //fprintf(stdout, "%s", text);
71 double Sys_DoubleTime (void)
73 static int first = true;
74 static double oldtime = 0.0, curtime = 0.0;
76 newtime = (double) SDL_GetTicks() / 1000.0;
85 if (newtime < oldtime)
87 // warn if it's significant
88 if (newtime - oldtime < -0.01)
89 Con_Printf("Sys_DoubleTime: time stepped backwards (went from %f to %f, difference %f)\n", oldtime, newtime, newtime - oldtime);
92 curtime += newtime - oldtime;
98 char *Sys_ConsoleInput(void)
100 if (cls.state == ca_dedicated)
102 static char text[MAX_INPUTLINE];
133 if (len == sizeof (text))
138 struct timeval timeout;
140 FD_SET(0, &fdset); // stdin
143 if (select (1, &fdset, NULL, NULL, &timeout) != -1 && FD_ISSET(0, &fdset))
145 len = read (0, text, sizeof(text));
148 // rip off the \n and terminate
158 void Sys_Sleep(int milliseconds)
160 if (milliseconds < 1)
162 SDL_Delay(milliseconds);
165 char *Sys_GetClipboardData (void)
171 if (OpenClipboard (NULL) != 0)
173 HANDLE hClipboardData;
175 if ((hClipboardData = GetClipboardData (CF_TEXT)) != 0)
177 if ((cliptext = GlobalLock (hClipboardData)) != 0)
179 data = Z_Malloc (GlobalSize(hClipboardData)+1);
180 strcpy (data, cliptext);
181 GlobalUnlock (hClipboardData);
192 void Sys_InitConsole (void)
196 void Sys_Init_Commands (void)
200 int main (int argc, char *argv[])
202 signal(SIGFPE, SIG_IGN);
205 com_argv = (const char **)argv;
208 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
211 // we don't know which systems we'll want to init, yet...