home *** CD-ROM | disk | FTP | other *** search
/ ftp.freefriends.org / ftp.freefriends.org.tar / ftp.freefriends.org / arnold / Source / mush.rstevens.tar.gz / mush.tar / fkeys.c < prev    next >
C/C++ Source or Header  |  1990-05-03  |  2KB  |  66 lines

  1. /* @(#)fkeys.c        (c) copyright 10/18/86 (Dan Heller) */
  2.  
  3. #include "mush.h"
  4.  
  5. #define L(n)        KEY_LEFTFIRST+(n)-1
  6. #define R(n)        KEY_RIGHTFIRST+(n)-1
  7. #define F(n)        KEY_TOPFIRST+(n)-1
  8. #define BREAK_KEY    KEY_TOPLAST
  9.  
  10. static int func_key();
  11.  
  12. Notify_value
  13. fkey_interposer(client, event, arg, type)
  14. Frame client;
  15. Event *event;
  16. Notify_arg arg;
  17. Notify_event_type type;
  18. {
  19.     if ((event_is_key_left(event) || event_is_key_right(event) ||
  20.     event_is_key_top(event)) &&
  21.     event_is_down(event) && func_key(event_id(event)))
  22.         return NOTIFY_DONE;
  23.  
  24.     return notify_next_event_func(client, event, arg, type);
  25. }
  26.  
  27. /*
  28.  * Execute commands defined by a function key.
  29.  * Left keys:
  30.  * L1 = (null)  can't be set
  31.  * L2 ... L10
  32.  * Top function keys
  33.  * F1 ... F9, BREAK/backspace (key not definable)
  34.  * Right function keys
  35.  * R1 ... R15
  36.  * Usually, the last Function key displays the others' settings.
  37.  */
  38. static int
  39. func_key(key)
  40. register int key;
  41. {
  42.     register char **argv, *p;
  43.     char buf[256];
  44.     int n;
  45.  
  46.     if (key >= KEY_LEFTFIRST && key <= KEY_LEFTLAST)
  47.     buf[0] = 'L', n = key - KEY_LEFTFIRST;
  48.     else if (key >= KEY_TOPFIRST && key <= KEY_TOPLAST)
  49.     buf[0] = 'F', n = key - KEY_TOPFIRST;
  50.     else if (key >= KEY_RIGHTFIRST && key <= KEY_RIGHTLAST)
  51.     buf[0] = 'R', n = key - KEY_RIGHTFIRST;
  52.     (void) sprintf(buf+1, "%d", n+1);
  53.  
  54.     if (!(p = do_set(fkeys, buf))) {
  55.     if (!chk_option("quiet", "fkey"))
  56.         wprint("Function key \"%s\" not set.\n", buf);
  57.     return FALSE;
  58.     }
  59.     /* make_command will screw up "p", so copy it first */
  60.     (void) strcpy(buf, p);
  61.     Debug("(%s) \"%s\": ", key, p), turnon(glob_flags, CONT_PRNT);
  62.     if (argv = make_command(buf, TRPL_NULL, &n))
  63.     (void) do_command(n, argv, msg_list);
  64.     return TRUE;
  65. }
  66.