home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume16 / less5 / part02 / ttyin.c < prev   
Encoding:
C/C++ Source or Header  |  1988-09-22  |  572 b   |  44 lines

  1. /*
  2.  * Routines dealing with getting input from the keyboard (i.e. from the user).
  3.  */
  4.  
  5. #include "less.h"
  6.  
  7. static int tty;
  8.  
  9. /*
  10.  * Open keyboard for input.
  11.  * (Just use file descriptor 2.)
  12.  */
  13.     public void
  14. open_getchr()
  15. {
  16.     tty = 2;
  17. }
  18.  
  19. /*
  20.  * Get a character from the keyboard.
  21.  */
  22.     public int
  23. getchr()
  24. {
  25.     char c;
  26.     int result;
  27.  
  28.     do
  29.     {
  30.         result = iread(tty, &c, 1);
  31.         if (result == READ_INTR)
  32.             return (READ_INTR);
  33.         if (result < 0)
  34.         {
  35.             /*
  36.              * Don't call error() here,
  37.              * because error calls getchr!
  38.              */
  39.             quit();
  40.         }
  41.     } while (result != 1);
  42.     return (c & 0177);
  43. }
  44.