home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume10 / cbw / part01 / keylib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-06-16  |  1.9 KB  |  108 lines

  1. /*
  2.  * Library of keystroke handling routines.
  3.  *
  4.  * Robert W. Baldwin,  December 1984.
  5.  */
  6.  
  7. #include    <stdio.h>
  8. #include    "window.h"
  9. #include    "terminal.h"
  10. #include    "specs.h"
  11.  
  12.  
  13. /* Keystroke table for default arrow key functionality.
  14.  * Used by the windows that don't accept keystroke commands.
  15.  */
  16. keyer    arwktab[]    =    {
  17.         {CGO_UP, jogup},
  18.         {CGO_DOWN, jogdown},
  19.         {CGO_LEFT, jogleft},
  20.         {CGO_RIGHT, jogright},
  21.         {0, NULL},
  22. };
  23.  
  24.  
  25.  
  26. /* The following routines move the cursor.
  27.  * If the cursor is still in the window, they update the
  28.  * cursor location in the window's data structure.
  29.  */
  30. jogup(w,k)
  31. gwindow    *w;
  32. key        k;
  33. {
  34.     if (w->wcur_row > 1) {
  35.         w->wcur_row--;
  36.         }
  37.     jogcursor(1);
  38. }
  39.  
  40. jogdown(w,k)
  41. gwindow    *w;
  42. key        k;
  43. {
  44.     if (w->wcur_row < w->wheight) {
  45.         w->wcur_row++;
  46.         }
  47.     jogcursor(2);
  48. }
  49.  
  50. jogleft(w,k)
  51. gwindow    *w;
  52. key        k;
  53. {
  54.     if (w->wcur_col > 1) {
  55.         w->wcur_col--;
  56.         }
  57.     jogcursor(3);
  58. }
  59.  
  60. jogright(w,k)
  61. gwindow    *w;
  62. key        k;
  63. {
  64.     if (w->wcur_col < w->wwidth) {
  65.         w->wcur_col++;
  66.         }
  67.     jogcursor(4);
  68. }
  69.  
  70.  
  71.  
  72. /* ddokey is the lookup routine for interpreting keys.
  73.  * It searches a table of keyer entries for one that matches the
  74.  * given key.  If a match is found, it calls the corresponding
  75.  * routine and returns TRUE.  Otherwise returns FALSE.
  76.  * The end of the table is marked by an entry with a keychar = 0 or -1.
  77.  * If it is -1, the proc in that entry will be called with the key,
  78.  * and TRUE is returned.  If it is 0, the no-match status is returned.
  79.  */
  80. int ddokey(w, k, ktab)
  81. gwindow    *w;        /* Window */
  82. key    k;        /* Key to handle */
  83. keyer    *ktab;        /* Table of handling procedures */
  84. {
  85.     int    cmd;
  86.  
  87.     cmd = (k >> CMDSHIFT) & CMDMASK;
  88.     for ( ; ktab->keychar != 0 ; ktab++ )  {
  89.         if (ktab->keychar == cmd  ||  ktab->keychar == -1)  {
  90.             (*(ktab->keyproc))(w, (k & CHARM));
  91.             return(TRUE);
  92.             }
  93.         }
  94.  
  95.     return(FALSE);
  96. }
  97.  
  98.  
  99.  
  100. /* Lookup and call a keyproc in the window's key handling table.
  101.  */
  102. dokey(w, k)
  103. gwindow        *w;
  104. key            k;
  105. {
  106.     return(ddokey(w, k, w->wkeyprocs));
  107. }
  108.