home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / x / xvisrc.zoo / events.c < prev    next >
C/C++ Source or Header  |  1992-07-28  |  4KB  |  203 lines

  1. /* Copyright (c) 1990,1991,1992 Chris and John Downey */
  2. #ifndef lint
  3. static char *sccsid = "@(#)events.c    1.1 (Chris & John Downey) 7/31/92";
  4. #endif
  5.  
  6. /***
  7.  
  8. * program name:
  9.     xvi
  10. * function:
  11.     PD version of UNIX "vi" editor, with extensions.
  12. * module name:
  13.     events.c
  14. * module function:
  15.     Deals with incoming events.
  16.     The main entry point for input to the editor.
  17. * history:
  18.     STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  19.     Originally by Tim Thompson (twitch!tjt)
  20.     Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  21.     Heavily modified by Chris & John Downey
  22.  
  23. ***/
  24.  
  25. #include "xvi.h"
  26.  
  27. static    bool_t    n_proc P((int));
  28. static    bool_t    c_proc P((int));
  29. static    bool_t    d_proc P((int));
  30.  
  31. volatile int    keystrokes;
  32.  
  33. long
  34. xvi_handle_event(ev)
  35. xvEvent    *ev;
  36. {
  37.     bool_t        do_update;
  38.     int        c;
  39.  
  40.     switch (ev->ev_type) {
  41.     case Ev_char:
  42.     keystrokes++;
  43.     map_char(ev->ev_inchar);
  44.     break;
  45.  
  46.     case Ev_timeout:
  47.     if (map_waiting()) {
  48.         map_timeout();
  49.     } else if (keystrokes >= PSVKEYS) {
  50.         do_preserve();
  51.         keystrokes = 0;
  52.     }
  53.     break;
  54.     }
  55.  
  56.     /*
  57.      * Look to see if the event produced any input characters
  58.      * which we can feed into the editor. Call the appropriate
  59.      * function for each one, according to the current State.
  60.      */
  61.     do_update = FALSE;
  62.     while ((c = map_getc()) != EOF) {
  63.     bool_t    (*func)P((int));
  64.  
  65.     switch (State) {
  66.     case NORMAL:
  67.         func = n_proc;
  68.         break;
  69.  
  70.     case CMDLINE:
  71.         func = c_proc;
  72.         break;
  73.  
  74.     case DISPLAY:
  75.         func = d_proc;
  76.         break;
  77.  
  78.     case INSERT:
  79.         func = i_proc;
  80.         break;
  81.  
  82.     case REPLACE:
  83.         func = r_proc;
  84.         break;
  85.     }
  86.     if ((*func)(c)) {
  87.         do_update = TRUE;
  88.     }
  89.  
  90.     /*
  91.      * Look at the resultant state, and the
  92.      * result of the proc() routine, to see
  93.      * whether to update the display.
  94.      */
  95.     switch (State) {
  96.     case CMDLINE:
  97.     case DISPLAY:
  98.         break;
  99.  
  100.     case NORMAL:
  101.     case INSERT:
  102.     case REPLACE:
  103.         if (do_update) {
  104.         move_window_to_cursor(curwin);
  105.         cursupdate(curwin);
  106.         wind_goto(curwin);
  107.         }
  108.     }
  109.     }
  110.  
  111.     if (kbdintr) {
  112.     if (imessage) {
  113.         show_message(curwin, "Interrupted");
  114.         wind_goto(curwin);    /* put cursor back */
  115.     }
  116.     imessage = (kbdintr = 0);
  117.     }
  118.  
  119.     if (map_waiting()) {
  120.     return((long) Pn(P_timeout));
  121.     } else if (keystrokes >= PSVKEYS) {
  122.     return((long) Pn(P_preservetime) * 1000);
  123.     } else {
  124.     return(0);
  125.     }
  126. }
  127.  
  128. /*
  129.  * Process the given character in command mode.
  130.  */
  131. static bool_t
  132. n_proc(c)
  133. int    c;
  134. {
  135.     unsigned    savecho;
  136.     bool_t    result;
  137.  
  138.     savecho = echo;
  139.     result = normal(c);
  140.     echo = savecho;
  141.     return(result);
  142. }
  143.  
  144. /*
  145.  * Returns TRUE if screen wants updating, FALSE otherwise.
  146.  */
  147. static bool_t
  148. c_proc(c)
  149. int    c;
  150. {
  151.     char    *cmdline;
  152.  
  153.     switch (cmd_input(curwin, c)) {
  154.     case cmd_CANCEL:
  155.     /*
  156.      * Put the status line back as it should be.
  157.      */
  158.     show_file_info(curwin);
  159.     update_window(curwin);
  160.     return(FALSE);
  161.  
  162.     case cmd_INCOMPLETE:
  163.     return(FALSE);
  164.  
  165.     case cmd_COMPLETE:
  166.     cmdline = get_cmd(curwin);
  167.     (void) yank_str(cmdline[0], cmdline, TRUE);
  168.     switch (cmdline[0]) {
  169.     case '/':
  170.     case '?':
  171.         (void) dosearch(curwin, cmdline + 1, cmdline[0]);
  172.         move_window_to_cursor(curwin);
  173.         break;
  174.  
  175.     case '!':
  176.         do_pipe(curwin, cmdline + 1);
  177.         break;
  178.  
  179.     case ':':
  180.         do_colon(cmdline + 1, TRUE);
  181.     }
  182.     return(TRUE);
  183.     }
  184.     /*NOTREACHED*/
  185. }
  186.  
  187. /*ARGSUSED*/
  188. static bool_t
  189. d_proc(c)
  190. int    c;
  191. {
  192.     if (c == CTRL('C')) {
  193.     /*
  194.      * In some environments it's possible to type
  195.      * control-C without actually generating an interrupt,
  196.      * but if they do, in this context, they probably want
  197.      * the semantics of an interrupt anyway.
  198.      */
  199.     imessage = (kbdintr = 1);
  200.     }
  201.     return(disp_screen(curwin));
  202. }
  203.