Commit f9fb40e5 authored by Kevin Koltzau's avatar Kevin Koltzau Committed by Alexandre Julliard

Enable line editing for _cgets.

parent 52c62995
...@@ -156,19 +156,36 @@ int _getche(void) ...@@ -156,19 +156,36 @@ int _getche(void)
char* _cgets(char* str) char* _cgets(char* str)
{ {
char *buf = str + 2; char *buf = str + 2;
int c; DWORD got;
DWORD conmode = 0;
TRACE("(%p)\n", str);
str[1] = 0; /* Length */ str[1] = 0; /* Length */
/* FIXME: No editing of string supported */
LOCK_CONSOLE; LOCK_CONSOLE;
do GetConsoleMode(MSVCRT_console_in, &conmode);
{ SetConsoleMode(MSVCRT_console_in, ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT|ENABLE_PROCESSED_INPUT);
if (str[1] >= str[0] || (str[1]++, c = _getche()) == MSVCRT_EOF || c == '\n')
break; if(ReadConsoleA(MSVCRT_console_in, buf, str[0], &got, NULL)) {
*buf++ = c & 0xff; if(buf[got-2] == '\r') {
} while (1); buf[got-2] = 0;
str[1] = got-2;
}
else if(got == 1 && buf[got-1] == '\n') {
buf[0] = 0;
str[1] = 0;
}
else if(got == str[0] && buf[got-1] == '\r') {
buf[got-1] = 0;
str[1] = got-1;
}
else
str[1] = got;
}
else
buf = NULL;
SetConsoleMode(MSVCRT_console_in, conmode);
UNLOCK_CONSOLE; UNLOCK_CONSOLE;
*buf = '\0'; return buf;
return str + 2;
} }
/********************************************************************* /*********************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment