reactos/lib/sdk/crt/conio/cgets.c
Cameron Gutman 29fa274d6d - Create another branch for networking fixes
- TSVN choked repeatedly when attempting to merge ~9000 revs into the branch (tried 3 times on 2 different computers)
 - If someone wants to delete aicom-network-fixes, they are welcome to
 - Lesson learned: Letting a branch get thousands of revs out of date is a horrible idea

svn path=/branches/aicom-network-branch/; revision=44353
2009-12-02 03:23:19 +00:00

73 lines
1.5 KiB
C

/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: msvcrt/conio/cgets.c
* PURPOSE: C Runtime
* PROGRAMMER: Eric Kohl (Imported from DJGPP)
*/
#include <precomp.h>
/*
* @implemented
*/
char *_cgets(char *string)
{
unsigned len = 0;
unsigned int maxlen_wanted;
char *sp;
int c;
/*
* Be smart and check for NULL pointer.
* Don't know wether TURBOC does this.
*/
if (!string)
return(NULL);
maxlen_wanted = (unsigned int)((unsigned char)string[0]);
sp = &(string[2]);
/*
* Should the string be shorter maxlen_wanted including or excluding
* the trailing '\0' ? We don't take any risk.
*/
while(len < maxlen_wanted-1)
{
c=_getch();
/*
* shold we check for backspace here?
* TURBOC does (just checked) but doesn't in cscanf (thats harder
* or even impossible). We do the same.
*/
if (c == '\b')
{
if (len > 0)
{
_cputs("\b \b"); /* go back, clear char on screen with space
and go back again */
len--;
sp[len] = '\0'; /* clear the character in the string */
}
}
else if (c == '\r')
{
sp[len] = '\0';
break;
}
else if (c == 0)
{
/* special character ends input */
sp[len] = '\0';
_ungetch(c); /* keep the char for later processing */
break;
}
else
{
sp[len] = _putch(c);
len++;
}
}
sp[maxlen_wanted-1] = '\0';
string[1] = (char)((unsigned char)len);
return(sp);
}