home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume5 / smallc / part3 / lib / gets.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  451 b   |  28 lines

  1. #include <stdio.h>
  2. #define EOL    10
  3. #define    BKSP    8
  4. #define CTRLU    0x15
  5. gets(s) char *s; {
  6.     char c, *ts;
  7.     ts = s;
  8.     while ((c = getchar()) != EOL && (c != EOF)) {
  9.         if (c == BKSP) {
  10.             if (ts > s) {
  11.                 --ts;
  12.                 /* CPM already echoed */
  13.                 putchar(' ');
  14.                 putchar(BKSP);
  15.                 }
  16.             }
  17.         else if (c == CTRLU) {
  18.             ts = s;
  19.             putchar(EOL);
  20.             putchar('#');
  21.             }
  22.         else (*ts++) = c;
  23.         }
  24.     if ((c == EOF) && (ts == s)) return NULL;
  25.     (*ts) = NULL;
  26.     return s;
  27. }
  28.