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

  1. /* tokc.c :  Convert a key string to EKeyCode
  2.  * For example:
  3.  *   "A" => A
  4.  *   "^A" => C-A
  5.  *   "C-A" => C-A
  6.  * Input:
  7.  *   key_text : pointer to text to convert.
  8.  *   prefixable : 
  9.  * C Durland
  10.  */
  11.  
  12. /* Copyright 1990, 1991 Craig Durland
  13.  *   Distributed under the terms of the GNU General Public License.
  14.  *   Distributed "as is", without warranties of any kind, but comments,
  15.  *     suggestions and bug reports are welcome.
  16.  */
  17.  
  18. #include <char.h>
  19. #include <const.h>
  20. #include "ed.h"
  21.  
  22. extern EKeyCode Eprefixes[];        /* in getkey.c */
  23.  
  24. EKeyCode Eto_keycode(pkeys,key_text,prefixable)
  25.   PKey *pkeys; unsigned char *key_text;
  26. {
  27.   register EKeyCode keycode = 0;
  28.   register unsigned char c;
  29.   register int j;
  30.  
  31.   for (; c = *key_text; key_text++)
  32.   {
  33.     if (key_text[1] == '-')    /* maybe its something like "C-A" */
  34.     {
  35.       switch (c)
  36.       {
  37.     default: goto next;        /* must be just a dash */
  38.     case 'C' : keycode |= CTRL;   break;
  39.     case 'F' : keycode |= SOFKEY; break;
  40.     case 'M' : keycode |= META;   break;
  41.     case 'S' : keycode |= SHIFT;  break;
  42.       }
  43.       key_text++;
  44.       continue;
  45.     }
  46.   next:
  47.     if (iscntrl(c)) keycode |= CTRL | (c ^ 0x40);
  48.     else
  49.       if ((keycode & (CTRL | META | PFIX1 | PFIX2 | PFIX3)) &&
  50.       (keycode & SOFKEY) == 0) keycode |= TOUPPER(c);
  51.       else keycode |= c;
  52.     if (prefixable)
  53.     {
  54.       for (j = PKEYS; j--; )            /* check for prefix keys */
  55.     if (keycode == pkeys[j]) { keycode = Eprefixes[j]; break; }
  56.       prefixable = FALSE;
  57.     }
  58.   }
  59.   return keycode;
  60. }
  61.