home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume13 / vn.jan.88 / part03 / getch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-01-30  |  1.9 KB  |  85 lines

  1. /*
  2. ** vn news reader.
  3. **
  4. ** getch.c - character i/o routines
  5. **
  6. ** see copyright disclaimer / history in vn.c source file
  7. */
  8. #include <stdio.h>
  9. #include <setjmp.h>
  10. #include "config.h"
  11. #include "vn.h"
  12.  
  13. extern char Cxitop[];
  14. extern char *Ku, *Kd, *Kr, *Kl;
  15.  
  16. /*
  17.     getkey obtains user keystroke with count from leading
  18.     numerics, if any.  Picks up arrow key sequences and maps
  19.     them to other keys.  Also translates character through
  20.     Cxitop array since this routine is only used in session
  21.     loop.  Saves untranslating arrow keys.
  22. */
  23. getkey (c)
  24. char *c;
  25. {
  26.     int i, j;
  27.     static char    ckseq[32];
  28.  
  29.     /* Check for leading count */
  30.     for (i = 0; (*c = getchar() & 0x7f) >= '0' && *c <= '9'; i = i * 10 + *c - '0')
  31.         ;
  32.  
  33.     /* @#$!!! flakey front ends that won't map newlines in raw mode */
  34.     if (*c == '\012' || *c == '\015')
  35.         *c = '\n';
  36.  
  37.     /* @#$!!! flakey terminals which send control sequences for cursors! */
  38.     if( *c == '\033' )
  39.     {
  40.         /*
  41.         ** Check if part of cursor key input sequence
  42.         ** (pitch unknown escape sequences)
  43.         */
  44.         j = 0;
  45.         ckseq[j] = *c; ckseq[j+1] = '\0';
  46.         while(*c == Ku[j] || *c == Kd[j] || *c == Kl[j] || *c == Kr[j])
  47.         {
  48.             if( strcmp(ckseq, Ku) == 0 ) { *c = UP; break; }
  49.             if( strcmp(ckseq, Kd) == 0 ) { *c = DOWN; break; }
  50. #ifdef PAGEARROW
  51.             if( strcmp(ckseq, Kl) == 0 ) { *c = BACK; break; }
  52.             if( strcmp(ckseq, Kr) == 0 ) { *c = FORWARD; break; }
  53. #else
  54.             if( strcmp(ckseq, Kl) == 0 ) { *c = UP; break; }
  55.             if( strcmp(ckseq, Kr) == 0 ) { *c = DOWN; break; }
  56. #endif
  57.             *c = (getchar() & 0x7f);
  58.             ckseq[++j] = *c; ckseq[j+1] = '\0';
  59.         }
  60.     }
  61.     else
  62.         *c = Cxitop[*c];
  63.  
  64.     if (i <= 0)
  65.         i = 1;
  66.     return (i);
  67. }
  68.  
  69. /*
  70.     get user key ignoring most controls.  Used from reader and other
  71.     non-screen interactions.
  72. */
  73. getnoctl ()
  74. {
  75.     char c;
  76.     while ((c = getchar() & 0x7f) < ' ' || c == '\177')
  77.     {
  78.         if (c == '\015' || c == '\012')
  79.             c = '\n';
  80.         if (c == '\n' || c == '\b' || c == '\t')
  81.             return (c);
  82.     }
  83.     return ((int) c);
  84. }
  85.