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);
91 curtime += newtime - oldtime;
97 char *Sys_ConsoleInput(void)
99 if (cls.state == ca_dedicated)
101 static char text[MAX_INPUTLINE];
132 if (len == sizeof (text))
137 struct timeval timeout;
139 FD_SET(0, &fdset); // stdin
142 if (select (1, &fdset, NULL, NULL, &timeout) != -1 && FD_ISSET(0, &fdset))
144 len = read (0, text, sizeof(text));
147 // rip off the \n and terminate
157 void Sys_Sleep(int microseconds)
159 SDL_Delay(microseconds / 1000);
162 char *Sys_GetClipboardData (void)
168 if (OpenClipboard (NULL) != 0)
170 HANDLE hClipboardData;
172 if ((hClipboardData = GetClipboardData (CF_TEXT)) != 0)
174 if ((cliptext = GlobalLock (hClipboardData)) != 0)
177 allocsize = GlobalSize (hClipboardData) + 1;
178 data = Z_Malloc (allocsize);
179 strlcpy (data, cliptext, allocsize);
180 GlobalUnlock (hClipboardData);
191 void Sys_InitConsole (void)
195 void Sys_Init_Commands (void)
199 int main (int argc, char *argv[])
201 signal(SIGFPE, SIG_IGN);
204 com_argv = (const char **)argv;
207 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
210 // we don't know which systems we'll want to init, yet...