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

  1. /* Copyright (c) 1990,1991,1992 Chris and John Downey */
  2. #ifndef lint
  3. static char *sccsid = "@(#)signal.c    2.1 (Chris & John Downey) 7/29/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.     signal.c
  14. * module function:
  15.     Signal handling routines.
  16.  
  17.     This is all fairly system-dependent, & may be replaced by more
  18.     system-specific routines if required. On MS-DOS, for instance,
  19.     this module isn't used at all: ignore_signals() &
  20.     catch_signals() are defined in msdos_c.c & msdos_a.asm instead.
  21. * history:
  22.     STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  23.     Originally by Tim Thompson (twitch!tjt)
  24.     Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  25.     Heavily modified by Chris & John Downey
  26.  
  27. ***/
  28.  
  29. #include "xvi.h"
  30.  
  31. /*
  32.  * Signal handlers.
  33.  */
  34. #ifdef    SIGINT
  35.     static    void    int_handler P((int));
  36. #endif
  37. #ifdef    SIGTSTP
  38.     static    void    tstp_handler P((int));
  39. #endif
  40. #ifdef    SIGHUP
  41.     static    void    hup_handler P((int));
  42. #endif
  43. #ifdef SIGTERM
  44.     static    void    term_handler P((int));
  45. #endif
  46.  
  47. void
  48. ignore_signals()
  49. {
  50. #ifdef    SIGINT
  51.     (void) signal(SIGINT, SIG_IGN);
  52. #endif
  53. #ifdef SIGBREAK
  54.     /*
  55.      * On OS/2, this is generated by pressing control-break.
  56.      */
  57.     (void) signal(SIGBREAK, SIG_IGN);
  58. #endif
  59. #ifdef    SIGQUIT
  60.     (void) signal(SIGQUIT, SIG_IGN);
  61. #endif
  62. #ifdef    SIGTSTP
  63.     (void) signal(SIGTSTP, SIG_IGN);
  64. #endif
  65.     /*
  66.      * There isn't much point in catching or ignoring SIGHUP
  67.      * signals until we have some modified buffers to preserve.
  68.      */
  69. #ifdef SIGTERM
  70.     (void) signal(SIGTERM, SIG_IGN);
  71. #endif
  72. }
  73.  
  74. void
  75. catch_signals()
  76. {
  77. #ifdef    SIGINT
  78.     (void) signal(SIGINT, int_handler);
  79. #endif
  80. #ifdef SIGBREAK
  81.     /*
  82.      * On OS/2, this is generated by pressing control-break.
  83.      */
  84.     (void) signal(SIGBREAK, int_handler);
  85. #endif
  86. #ifdef    SIGTSTP
  87.     (void) signal(SIGTSTP, tstp_handler);
  88. #endif
  89. #ifdef SIGHUP
  90.     (void) signal(SIGHUP, hup_handler);
  91. #endif
  92. #ifdef SIGTERM
  93.     (void) signal(SIGTERM, term_handler);
  94. #endif
  95. }
  96.  
  97. /*
  98.  * Handler for SIGINT (keyboard interrupt).
  99.  */
  100. #ifdef    SIGINT
  101. static void
  102. int_handler(sig)
  103. int    sig;
  104. {
  105.     signal(SIGINT, int_handler);
  106.     kbdintr = 1;
  107. }
  108. #endif
  109.  
  110. /*
  111.  * This function is used on UNIX as the signal handler
  112.  * for the keyboard-generated TSTP signal.
  113.  */
  114. #ifdef    SIGTSTP
  115. static void
  116. tstp_handler(sig)
  117. int    sig;
  118. {
  119.     do_suspend(curwin);
  120. }
  121. #endif
  122.  
  123. /*
  124.  * This one is used for the hangup signal, which generally means that
  125.  * the terminal line has gone dead. This means sys_exit() doesn't make
  126.  * much sense, so we call exit() instead.
  127.  */
  128. #ifdef    SIGHUP
  129. static void
  130. hup_handler(sig)
  131. int    sig;
  132. {
  133.     signal(SIGHUP, SIG_IGN);
  134.     /*
  135.      * Make backup copies of all modified buffers.
  136.      */
  137.     (void) do_preserve();
  138.     exit(0);
  139. }
  140. #endif
  141.  
  142. /*
  143.  * This one is used for the software-generated terminate signal.
  144.  */
  145. #ifdef SIGTERM
  146. static void
  147. term_handler(sig)
  148. int    sig;
  149. {
  150.     signal(SIGTERM, SIG_IGN);
  151.     /*
  152.      * Make backup copies of all modified buffers.
  153.      */
  154.     (void) do_preserve();
  155.     sys_exit(0);
  156. }
  157. #endif
  158.