Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygencgets.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS kernel 00004 * FILE: msvcrt/conio/cgets.c 00005 * PURPOSE: C Runtime 00006 * PROGRAMMER: Eric Kohl (Imported from DJGPP) 00007 */ 00008 00009 #include <precomp.h> 00010 00011 /* 00012 * @implemented 00013 */ 00014 char *_cgets(char *string) 00015 { 00016 unsigned len = 0; 00017 unsigned int maxlen_wanted; 00018 char *sp; 00019 int c; 00020 /* 00021 * Be smart and check for NULL pointer. 00022 * Don't know wether TURBOC does this. 00023 */ 00024 if (!string) 00025 return(NULL); 00026 maxlen_wanted = (unsigned int)((unsigned char)string[0]); 00027 sp = &(string[2]); 00028 /* 00029 * Should the string be shorter maxlen_wanted including or excluding 00030 * the trailing '\0' ? We don't take any risk. 00031 */ 00032 while(len < maxlen_wanted-1) 00033 { 00034 c=_getch(); 00035 /* 00036 * shold we check for backspace here? 00037 * TURBOC does (just checked) but doesn't in cscanf (thats harder 00038 * or even impossible). We do the same. 00039 */ 00040 if (c == '\b') 00041 { 00042 if (len > 0) 00043 { 00044 _cputs("\b \b"); /* go back, clear char on screen with space 00045 and go back again */ 00046 len--; 00047 sp[len] = '\0'; /* clear the character in the string */ 00048 } 00049 } 00050 else if (c == '\r') 00051 { 00052 sp[len] = '\0'; 00053 break; 00054 } 00055 else if (c == 0) 00056 { 00057 /* special character ends input */ 00058 sp[len] = '\0'; 00059 _ungetch(c); /* keep the char for later processing */ 00060 break; 00061 } 00062 else 00063 { 00064 sp[len] = _putch(c); 00065 len++; 00066 } 00067 } 00068 sp[maxlen_wanted-1] = '\0'; 00069 string[1] = (char)((unsigned char)len); 00070 return(sp); 00071 } 00072 00073 Generated on Mon May 28 2012 04:36:15 for ReactOS by
1.7.6.1
|