From 47ec80a33a8f3e4a78deb12b025b9eea431e3003 Mon Sep 17 00:00:00 2001 From: sezero Date: Sat, 19 Jun 2010 16:50:15 +0000 Subject: [PATCH] * sys_sdl.c: Added a Sys_ConsoleInput implementation from uhexen2. Only for unix for the time being. git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@189 af15c1b1-3010-417e-b628-4374ebc0bcbd --- Quake/sys_sdl.c | 61 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/Quake/sys_sdl.c b/Quake/sys_sdl.c index 9e6d56ab..ad38afc0 100644 --- a/Quake/sys_sdl.c +++ b/Quake/sys_sdl.c @@ -20,16 +20,21 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "quakedef.h" + #include #ifdef _WIN32 #include #include +#include #else +#include +#include #include +#include +#include +#include #endif -#include "errno.h" - -#include "quakedef.h" #define CONSOLE_ERROR_TIMEOUT 60.0 /* # of seconds to wait on Sys_Error running */ qboolean isDedicated; @@ -248,7 +253,55 @@ double Sys_FloatTime (void) char *Sys_ConsoleInput (void) { - return 0; +#if !defined(_WIN32) + static char con_text[256]; + static int textlen; + char c; + fd_set set; + struct timeval timeout; + + if (!isDedicated) + return NULL; // no stdin necessary in graphical mode + + FD_ZERO (&set); + FD_SET (0, &set); // stdin + timeout.tv_sec = 0; + timeout.tv_usec = 0; + + while (select (1, &set, NULL, NULL, &timeout)) + { + read (0, &c, 1); + if (c == '\n' || c == '\r') + { + con_text[textlen] = '\0'; + textlen = 0; + return con_text; + } + else if (c == 8) + { + if (textlen) + { + textlen--; + con_text[textlen] = '\0'; + } + continue; + } + con_text[textlen] = c; + textlen++; + if (textlen < sizeof(con_text)) + con_text[textlen] = '\0'; + else + { + // buffer is full + textlen = 0; + con_text[0] = '\0'; + Sys_Printf("\nConsole input too long!\n"); + break; + } + } +#endif /* ! _WIN32 */ + + return NULL; } void Sys_Sleep (void)