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);
61 int written = (int)write(1, text, (int)strlen(text));
63 break; // sorry, I cannot do anything about this error - without an output
67 fcntl (1, F_SETFL, origflags);
69 //fprintf(stdout, "%s", text);
72 double Sys_DoubleTime (void)
74 static int first = true;
75 static double oldtime = 0.0, curtime = 0.0;
77 newtime = (double) SDL_GetTicks() / 1000.0;
86 if (newtime < oldtime)
88 // warn if it's significant
89 if (newtime - oldtime < -0.01)
90 Con_Printf("Sys_DoubleTime: time stepped backwards (went from %f to %f, difference %f)\n", oldtime, newtime, newtime - oldtime);
92 else if (newtime > oldtime + 1800)
94 Con_Printf("Sys_DoubleTime: time stepped forward (went from %f to %f, difference %f)\n", oldtime, newtime, newtime - oldtime);
97 curtime += newtime - oldtime;
103 char *Sys_ConsoleInput(void)
105 if (cls.state == ca_dedicated)
107 static char text[MAX_INPUTLINE];
138 if (len == sizeof (text))
143 struct timeval timeout;
145 FD_SET(0, &fdset); // stdin
148 if (select (1, &fdset, NULL, NULL, &timeout) != -1 && FD_ISSET(0, &fdset))
150 len = read (0, text, sizeof(text));
153 // rip off the \n and terminate
163 void Sys_Sleep(int microseconds)
165 SDL_Delay(microseconds / 1000);
168 char *Sys_GetClipboardData (void)
174 if (OpenClipboard (NULL) != 0)
176 HANDLE hClipboardData;
178 if ((hClipboardData = GetClipboardData (CF_TEXT)) != 0)
180 if ((cliptext = (char *)GlobalLock (hClipboardData)) != 0)
183 allocsize = GlobalSize (hClipboardData) + 1;
184 data = (char *)Z_Malloc (allocsize);
185 strlcpy (data, cliptext, allocsize);
186 GlobalUnlock (hClipboardData);
197 void Sys_InitConsole (void)
201 void Sys_Init_Commands (void)
205 int main (int argc, char *argv[])
207 signal(SIGFPE, SIG_IGN);
210 com_argv = (const char **)argv;
213 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
216 // we don't know which systems we'll want to init, yet...