home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / sun / volume1 / tooltool2.1c / part02 / func_fix.c next >
Encoding:
C/C++ Source or Header  |  1989-06-06  |  5.7 KB  |  183 lines

  1. /************************************************************************/
  2. /*    Copyright 1988 by Chuck Musciano and Harris Corporation        */
  3. /*                                    */
  4. /*    Permission to use, copy, modify, and distribute this software    */
  5. /*    and its documentation for any purpose and without fee is    */
  6. /*    hereby granted, provided that the above copyright notice    */
  7. /*    appear in all copies and that both that copyright notice and    */
  8. /*    this permission notice appear in supporting documentation, and    */
  9. /*    that the name of Chuck Musciano and Harris Corporation not be    */
  10. /*    used in advertising or publicity pertaining to distribution    */
  11. /*    of the software without specific, written prior permission.    */
  12. /*    Chuck Musciano and Harris Corporation make no representations    */
  13. /*    about the suitability of this software for any purpose.  It is    */
  14. /*    provided "as is" without express or implied warranty.        */
  15. /*                                    */
  16. /*    The sale of any product based wholely or in part upon the     */
  17. /*    technology provided by tooltool is strictly forbidden without    */
  18. /*    specific, prior written permission from Harris Corporation.    */
  19. /*    Tooltool technology includes, but is not limited to, the source    */
  20. /*    code, executable binary files, specification language, and    */
  21. /*    sample specification files.                    */
  22. /************************************************************************/
  23.  
  24. #include    <stdio.h>
  25.  
  26. #include    "tooltool.h"
  27.  
  28. #define        advance_queue_ptr(q)    ((q) = ((q) + 1) % MAX_EVENTS)
  29.  
  30. #define        MAX_EVENTS        16
  31.  
  32. typedef    struct    fk_data    fk_rec, *fk_ptr;
  33.  
  34. struct    fk_data    {int    candidate;
  35.          int    true_event;
  36.          char    *expansion;
  37.         };
  38.  
  39. PRIVATE    Event    event_queue[MAX_EVENTS];
  40. PRIVATE    Event    saved_event[MAX_EVENTS];
  41. PRIVATE    int    queue_head = 0;
  42. PRIVATE    int    queue_tail = 0;
  43. PRIVATE    int    state = 0;
  44.  
  45. PRIVATE    fk_rec    func_key[] = {{TRUE, KEY_LEFT(2),   "\033[193z"},
  46.                   {TRUE, KEY_LEFT(3),   "\033[194z"},
  47.                   {TRUE, KEY_LEFT(4),   "\033[195z"},
  48.                   {TRUE, KEY_LEFT(5),   "\033[196z"},
  49.                   {TRUE, KEY_LEFT(6),   "\033[197z"},
  50.                   {TRUE, KEY_LEFT(7),   "\033[198z"},
  51.                   {TRUE, KEY_LEFT(8),   "\033[199z"},
  52.                   {TRUE, KEY_LEFT(9),   "\033[200z"},
  53.                   {TRUE, KEY_LEFT(10),  "\033[201z"},
  54.                   {TRUE, KEY_TOP(1),    "\033[224z"},
  55.                   {TRUE, KEY_TOP(2),    "\033[225z"},
  56.                   {TRUE, KEY_TOP(3),    "\033[226z"},
  57.                   {TRUE, KEY_TOP(4),    "\033[227z"},
  58.                   {TRUE, KEY_TOP(5),    "\033[228z"},
  59.                   {TRUE, KEY_TOP(6),    "\033[229z"},
  60.                   {TRUE, KEY_TOP(7),    "\033[230z"},
  61.                   {TRUE, KEY_TOP(8),    "\033[231z"},
  62.                   {TRUE, KEY_TOP(9),    "\033[232z"},
  63.                   {TRUE, KEY_RIGHT(1),  "\033[208z"},
  64.                   {TRUE, KEY_RIGHT(2),  "\033[209z"},
  65.                   {TRUE, KEY_RIGHT(3),  "\033[210z"},
  66.                   {TRUE, KEY_RIGHT(4),  "\033[211z"},
  67.                   {TRUE, KEY_RIGHT(5),  "\033[212z"},
  68.                   {TRUE, KEY_RIGHT(6),  "\033[213z"},
  69.                   {TRUE, KEY_RIGHT(7),  "\033[214z"},
  70.                   {TRUE, KEY_RIGHT(8),  "\033[215z"},
  71.                   {TRUE, KEY_RIGHT(9),  "\033[216z"},
  72.                   {TRUE, KEY_RIGHT(10), "\033[217z"},
  73.                   {TRUE, KEY_RIGHT(11), "\033[218z"},
  74.                   {TRUE, KEY_RIGHT(12), "\033[219z"},
  75.                   {TRUE, KEY_RIGHT(13), "\033[220z"},
  76.                   {TRUE, KEY_RIGHT(14), "\033[221z"},
  77.                   {TRUE, KEY_RIGHT(15), "\033[222z"},
  78.                   {NULL, NULL,          NULL}};
  79.  
  80. /************************************************************************/
  81. PRIVATE    enqueue_event(event)
  82.  
  83. Event    *event;
  84.  
  85. {
  86.     event_queue[queue_head] = *event;
  87.     if (advance_queue_ptr(queue_head) == queue_tail)
  88.        abend("internal event queue overflow");
  89. }
  90.  
  91. /************************************************************************/
  92. PRIVATE    Event    *dequeue_event()
  93.  
  94. {    Event    *result;
  95.  
  96.     if (queue_tail == queue_head)
  97.        return(NULL);
  98.     result = &(event_queue[queue_tail]);
  99.     advance_queue_ptr(queue_tail);
  100.     return(result);
  101. }
  102.  
  103. /************************************************************************/
  104. PRIVATE    reset_state_machine(enqueue_events)
  105.  
  106. int    enqueue_events;
  107.  
  108. {    int    i;
  109.  
  110.     if (enqueue_events)
  111.        for (i = 0; i < state; i++)
  112.           enqueue_event(&(saved_event[i]));
  113.     for (i = 0; func_key[i].expansion; i++)
  114.        func_key[i].candidate = TRUE;
  115.     state = 0;
  116. }
  117.  
  118. /************************************************************************/
  119. PRIVATE    advance_state_machine(event)
  120.  
  121. register    Event    *event;
  122.  
  123. {    register    int    candidates;
  124.     register    fk_ptr    last_match, key;
  125.  
  126.     for (key = func_key, candidates = 0; key->expansion; key++)
  127.        if (key->candidate && key->expansion[state] == event_id(event)) {
  128.           candidates++;
  129.           last_match = key;
  130.           }
  131.        else
  132.           key->candidate = FALSE;
  133.     if (candidates == 0) {
  134.        reset_state_machine(TRUE);
  135.        enqueue_event(event);
  136.        }
  137.     else if (candidates == 1 && last_match->expansion[state + 1] == '\0') {
  138.        event_set_id(event, last_match->true_event);
  139.        reset_state_machine(FALSE);
  140.        enqueue_event(event);
  141.        }
  142.     else {
  143.        saved_event[state] = *event;
  144.        if (++state >= MAX_EVENTS)
  145.           abend("oveflowed internal event buffer");
  146.        }
  147. }
  148.  
  149. /************************************************************************/
  150. PRIVATE    Notify_value    function_check(win, event, arg, type)
  151.  
  152. Window    win;
  153. Event    *event;
  154. Notify_arg    arg;
  155. Notify_event_type    type;
  156.  
  157. {    Notify_value    result;
  158.  
  159.     if (event_is_ascii(event) || event_is_meta(event))
  160.        if (event_is_down(event))
  161.           advance_state_machine(event);
  162.        else
  163.           reset_state_machine(TRUE);
  164.     else {
  165.        reset_state_machine(TRUE);
  166.        enqueue_event(event);
  167.        }
  168.     while (event = dequeue_event())
  169.        if ((result = notify_next_event_func(win, event, arg, type)) != NOTIFY_DONE)
  170.           return(result);
  171.     return(NOTIFY_DONE);
  172. }
  173.  
  174. /************************************************************************/
  175. EXPORT    init_function_fix(win)
  176.  
  177. Window    win;
  178.  
  179. {
  180.     window_set(win, WIN_CONSUME_KBD_EVENT,  WIN_UP_ASCII_EVENTS, 0);
  181.     notify_interpose_event_func(win, function_check, NOTIFY_SAFE);
  182. }
  183.