home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / me34src.zip / me3 / ed / getkey.c < prev    next >
C/C++ Source or Header  |  1995-01-14  |  1KB  |  49 lines

  1. /* getkey.c : get a keycode from the <key device>
  2.  * C Durland
  3.  */
  4.  
  5. /* Copyright 1990, 1991 Craig Durland
  6.  *   Distributed under the terms of the GNU General Public License.
  7.  *   Distributed "as is", without warranties of any kind, but comments,
  8.  *     suggestions and bug reports are welcome.
  9.  */
  10.  
  11. #include <const.h>
  12. #include <char.h>
  13. #include "ed.h"
  14.  
  15. EKeyCode Eprefixes[] = { META, PFIX1, PFIX2, PFIX3 };
  16.  
  17.     /* Ectok(kc,part2) : character to keycode
  18.      *   kc : keycode to convert
  19.      *   part2: TRUE if kc might be part2 of prefixed ME key
  20.      *     (eg in "ESC a" => ctok(a,TRUE) because second part of prefixed
  21.      *     keys are always uppercase.  "SOFKEY a" => ktoc(a,FALSE) because
  22.      *     softkeys get the whole keymap.  Prefix keys are listed in table
  23.      *     above.)
  24.      */
  25. EKeyCode Ectok(kc,part2) register EKeyCode kc; register int part2;
  26. {
  27.   if ((kc & 0xFF00) == 0)    /* Only munge it if its not already a EKeyCode */
  28.   {
  29.     if (part2) kc = toupper(kc);        /* Force to uppercase */
  30.     if (iscntrl(kc)) kc = CTRL | (kc ^ 0x40);    /* control a -> C-A */
  31.   }
  32.   return kc;
  33. }
  34.  
  35. /* Read in a key.
  36.  * Do the standard keyboard preprocessing.
  37.  * Convert the keys to the internal character set.
  38.  */
  39. EKeyCode Eget_key(pkeys) PKey *pkeys;
  40. {
  41.   register EKeyCode kc;
  42.   register int j;
  43.  
  44.   kc = Ectok(t_getchar(),FALSE);
  45.   for (j = PKEYS; j--; )    /* check for prefix keys */
  46.     if (kc == pkeys[j]) return Eprefixes[j] | Ectok(t_getchar(),TRUE);
  47.   return kc;
  48. }
  49.