home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume7 / rvi / part2 / rv_getline.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  1.8 KB  |  106 lines

  1. #include "rv.h"
  2. #include <ctype.h>
  3.  
  4. extern boolean did_botprint;  /* Used by hitcr_continue() */
  5. extern boolean scrolled;      /* Used by hitcr_continue() */
  6. extern boolean superquote;    /* Set by rv_getchar() */
  7.  
  8. static char buf[256];
  9.  
  10. char *
  11. rv_getline()
  12. /*
  13.  * Read input line
  14.  * Returns a static buffer, else NULL
  15.  */
  16. {
  17.     char *s, ch;
  18.     INT savecol, saverow;
  19.  
  20.     s = buf;
  21.     strncpy(buf, "", 256);  /* Zero out buf */
  22.     savecol = CURCOLUMN;
  23.     saverow = CURLINE;
  24.     hitcr_continue();
  25.     clrtobot();
  26.     move(saverow, savecol);  /* Because clrtobot homes the cursor in 4bsd */
  27.     did_botprint = TRUE;
  28.  
  29.     for (;;) {
  30.         ch = rv_getchar();
  31.         if (!superquote) {
  32.             if (ch == erasechar())
  33.                 ch = '\b';
  34.             if (ch == killchar())
  35.                 ch = CTRL(X);
  36.             switch (ch) {
  37. case '\b':
  38.         /*
  39.          * Backspace
  40.          */
  41.         if (s-- <= buf) {
  42.             if (screen_column(buf, strlen(buf)) >= COLS-1)
  43.                 scrolled = TRUE;
  44.             hitcr_continue();
  45.             move_cursor(screen.sc_lineno, screen.sc_column);
  46.             return NULL;
  47.         }
  48.         move(CURLINE, CURCOLUMN-1);
  49.         if (*s < ' ' || *s > '~')
  50.             move(CURLINE, CURCOLUMN-1);
  51.         clrtoeol();
  52.         break;
  53.  
  54. case CTRL(X):
  55.         /*
  56.          * Line kill
  57.          */
  58.         s = buf;
  59.         move(saverow, savecol);
  60.         clrtobot();
  61.         move(saverow, savecol);
  62.         break;
  63.  
  64. case '\t':
  65.         /*
  66.          * Tab
  67.          */
  68.         addch('^');
  69.         addch('I');
  70.         *s++ = ch;
  71.         break;
  72.  
  73. case '\r':
  74. case '\n':
  75. case CTRL([):
  76.         /*
  77.          * End of line 
  78.          */
  79.         if (screen_column(buf, strlen(buf)) >= COLS-1)
  80.             scrolled = TRUE;
  81.         *s = '\0';
  82.         hitcr_continue();
  83.         move_cursor(screen.sc_lineno, screen.sc_column);
  84.         return buf;
  85.  
  86. default:
  87.         addch(ch);
  88.         *s++ = ch;
  89.         break;
  90.  
  91.             } /* End switch */
  92.         } else {
  93.             addch(ch);
  94.             *s++ = ch;
  95.         }
  96.  
  97.         if (buf-s >= 250) { /* If end of buffer */
  98.             scrolled = TRUE;
  99.             *s = '\0';
  100.             hitcr_continue();
  101.             move_cursor(screen.sc_lineno, screen.sc_column);
  102.             return buf;
  103.         }
  104.     }
  105. }
  106.