#define NOCCARGC #include stdio.h #include clib.def /* ** Gets an entire string (including its newline ** terminator) or size-1 characters, whichever comes ** first. The input is terminated by a null character. ** Entry: str = Pointer to the destination buffer. ** size = Size of the destination buffer. ** fd = File descriptor of pertinent file. ** Returns str on success, else NULL. */ fgets(str, size, fd) char *str; int size, fd; { return (_gets(str, size, fd, 1)); } /* ** Gets an entire string fron stdin (excluding its newline ** terminator) or size - 1 characters, whichever comes ** first. The input is terminated by a null character. ** The user buffer must be large enough to hold the data. ** Entry: str = Pointer to destination buffer. ** Returns str on success, else NULL. */ gets(str) char *str; { return (_gets(str, 32767, stdin, 0)); } _gets(str, size, fd, nl) char *str; int size, fd, nl; { int backup; char *next; next = str; while(--size > 0) { switch (*next = fgetc(fd)) { case EOF: *next = NULL; if (next == str) return (NULL); return (str); case '\n': *(next + nl) = NULL; return (str); case RUB: if(next > str) backup = 1; else backup = 0; goto backout; case WIPE: backup = next - str; backout: if(iscons(fd)) { fputs("\b \b\b \b", stderr); ++size; while(backup--) { fputs("\b \b", stderr); if(*--next < 32) fputs("\b \b", stderr); ++size; } continue: } default: ++next; } } *next = NULL; return (str); }