ReactOS 0.4.15-dev-8135-g1bc6c90
cgets.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: lib/sdk/crt/conio/cgets.c
5 * PURPOSE: C Runtime
6 * PROGRAMMER: Eric Kohl (Imported from DJGPP)
7 */
8
9#include <precomp.h>
10
11/*
12 * @implemented
13 */
14char *_cgets(char *string)
15{
16 unsigned len = 0;
17 unsigned int maxlen_wanted;
18 char *sp;
19 int c;
20 /*
21 * Be smart and check for NULL pointer.
22 * Don't know wether TURBOC does this.
23 */
24 if (!string)
25 return(NULL);
26 maxlen_wanted = (unsigned int)((unsigned char)string[0]);
27 sp = &(string[2]);
28 /*
29 * Should the string be shorter maxlen_wanted including or excluding
30 * the trailing '\0' ? We don't take any risk.
31 */
32 while(len < maxlen_wanted-1)
33 {
34 c=_getch();
35 /*
36 * shold we check for backspace here?
37 * TURBOC does (just checked) but doesn't in cscanf (thats harder
38 * or even impossible). We do the same.
39 */
40 if (c == '\b')
41 {
42 if (len > 0)
43 {
44 _cputs("\b \b"); /* go back, clear char on screen with space
45 and go back again */
46 len--;
47 sp[len] = '\0'; /* clear the character in the string */
48 }
49 }
50 else if (c == '\r')
51 {
52 sp[len] = '\0';
53 break;
54 }
55 else if (c == 0)
56 {
57 /* special character ends input */
58 sp[len] = '\0';
59 _ungetch(c); /* keep the char for later processing */
60 break;
61 }
62 else
63 {
64 sp[len] = _putch(c);
65 len++;
66 }
67 }
68 sp[maxlen_wanted-1] = '\0';
69 string[1] = (char)((unsigned char)len);
70 return(sp);
71}
72
73
char * _cgets(char *string)
Definition: cgets.c:14
#define NULL
Definition: types.h:112
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
unsigned char
Definition: typeof.h:29
const GLubyte * c
Definition: glext.h:8905
GLenum GLsizei len
Definition: glext.h:6722
#define c
Definition: ke_i.h:80
static const WCHAR sp[]
Definition: suminfo.c:287
int __cdecl _ungetch(int)
Definition: ungetch.c:22
int __cdecl _cputs(const char *)
Definition: cputs.c:8
_CRTIMP int __cdecl _putch(_In_ int _Ch)
int _getch()
Definition: getch.c:16