home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / utilities / cli / gnuinfo / Source / c / signals < prev    next >
Encoding:
Text File  |  1994-10-01  |  4.9 KB  |  181 lines

  1. #include "defines.h"
  2. /* signals.c -- Install and maintain Info signal handlers. */
  3.  
  4. /* This file is part of GNU Info, a program for reading online documentation
  5.    stored in Info format.
  6.  
  7.    Copyright (C) 1993 Free Software Foundation, Inc.
  8.  
  9.    This program is free software; you can redistribute it and/or modify
  10.    it under the terms of the GNU General Public License as published by
  11.    the Free Software Foundation; either version 2, or (at your option)
  12.    any later version.
  13.  
  14.    This program is distributed in the hope that it will be useful,
  15.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.    GNU General Public License for more details.
  18.  
  19.    You should have received a copy of the GNU General Public License
  20.    along with this program; if not, write to the Free Software
  21.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23.    Written by Brian Fox (bfox@ai.mit.edu). */
  24.  
  25. #include "info.h"
  26. #include "signals.h"
  27.  
  28. /* **************************************************************** */
  29. /*                                    */
  30. /*        Pretending That We Have POSIX Signals            */
  31. /*                                    */
  32. /* **************************************************************** */
  33.  
  34. #undef HAVE_SIGSETMASK
  35.  
  36. #if !defined (_POSIX_VERSION)
  37. /* Perform OPERATION on NEWSET, perhaps leaving information in OLDSET. */
  38. static void
  39. sigprocmask (operation, newset, oldset)
  40.      int operation, *newset, *oldset;
  41. {
  42.   switch (operation)
  43.     {
  44.     case SIG_UNBLOCK:
  45. #if defined (HAVE_SIGSETMASK)
  46.       sigsetmask (sigblock (0) & ~(*newset));
  47. #endif /* HAVE_SIGSETMASK */
  48.       break;
  49.  
  50.     case SIG_BLOCK:
  51.       /* *oldset = sigblock (*newset); */
  52.       break;
  53.  
  54.     case SIG_SETMASK:
  55. #if defined (HAVE_SIGSETMASK)
  56.       sigsetmask (*newset);
  57. #endif /* HAVE_SIGSETMASK */
  58.       break;
  59.  
  60.     default:
  61.       abort ();
  62.     }
  63. }
  64. #endif /* !_POSIX_VERSION */
  65.  
  66. /* **************************************************************** */
  67. /*                                    */
  68. /*            Signal Handling for Info                */
  69. /*                                    */
  70. /* **************************************************************** */
  71.  
  72. typedef void SigHandlerType;
  73. typedef SigHandlerType SigHandler ();
  74.  
  75. static SigHandlerType info_signal_handler ();
  76. static SigHandler *old_TSTP, *old_TTOU, *old_TTIN;
  77. static SigHandler *old_WINCH, *old_INT;
  78.  
  79. void
  80. initialize_info_signal_handler ()
  81. {
  82. #if defined (SIGTSTP)
  83.   old_TSTP = (SigHandler *) signal (SIGTSTP, info_signal_handler);
  84.   old_TTOU = (SigHandler *) signal (SIGTTOU, info_signal_handler);
  85.   old_TTIN = (SigHandler *) signal (SIGTTIN, info_signal_handler);
  86. #endif /* SIGTSTP */
  87.  
  88. #if defined (SIGWINCH)
  89.   old_WINCH = (SigHandler *) signal (SIGWINCH, info_signal_handler);
  90. #endif
  91.  
  92. #if defined (SIGINT)
  93.   old_INT = (SigHandler *) signal (SIGINT, info_signal_handler);
  94. #endif
  95. }
  96.  
  97. static void
  98. redisplay_after_signal ()
  99. {
  100.   terminal_clear_screen ();
  101.   display_clear_display (the_display);
  102.   window_mark_chain (windows, W_UpdateWindow);
  103.   display_update_display (windows);
  104.   display_cursor_at_point (active_window);
  105.   fflush (stdout);
  106. }
  107.  
  108. static SigHandlerType
  109. info_signal_handler (sig)
  110.      int sig;
  111. {
  112.   SigHandler **old_signal_handler;
  113.  
  114.   switch (sig)
  115.     {
  116. #if defined (SIGTSTP)
  117.     case SIGTSTP:
  118.     case SIGTTOU:
  119.     case SIGTTIN:
  120. #endif
  121. #if defined (SIGINT)
  122.     case SIGINT:
  123. #endif
  124.       {
  125. #if defined (SIGTSTP)
  126.     if (sig == SIGTSTP)
  127.       old_signal_handler = &old_TSTP;
  128.     if (sig == SIGTTOU)
  129.       old_signal_handler = &old_TTOU;
  130.     if (sig == SIGTTIN)
  131.       old_signal_handler = &old_TTIN;
  132. #endif /* SIGTSTP */
  133.     if (sig == SIGINT)
  134.       old_signal_handler = &old_INT;
  135.  
  136.     /* For stop signals, restore the terminal IO, leave the cursor
  137.        at the bottom of the window, and stop us. */
  138.     terminal_goto_xy (0, screenheight - 1);
  139.     terminal_clear_to_eol ();
  140.     fflush (stdout);
  141.     terminal_unprep_terminal ();
  142.     signal (sig, *old_signal_handler);
  143.      UNBLOCK_SIGNAL (sig);
  144.     kill (getpid (), sig);
  145.  
  146.     /* The program is returning now.  Restore our signal handler,
  147.        turn on terminal handling, redraw the screen, and place the
  148.        cursor where it belongs. */
  149.     terminal_prep_terminal ();
  150.     *old_signal_handler = (SigHandler *) signal (sig, info_signal_handler);
  151.     redisplay_after_signal ();
  152.     fflush (stdout);
  153.       }
  154.       break;
  155.  
  156. #if defined (SIGWINCH)
  157.     case SIGWINCH:
  158.       {
  159.     /* Turn off terminal IO, tell our parent that the window has changed,
  160.        then reinitialize the terminal and rebuild our windows. */
  161.     old_signal_handler = &old_WINCH;
  162.     terminal_goto_xy (0, 0);
  163.     fflush (stdout);
  164.     terminal_unprep_terminal ();
  165.     signal (sig, *old_signal_handler);
  166.      UNBLOCK_SIGNAL (sig);
  167.     kill (getpid (), sig);
  168.  
  169.     /* After our old signal handler returns... */
  170.     terminal_get_screen_size ();
  171.     terminal_prep_terminal ();
  172.     display_initialize_display (screenwidth, screenheight);
  173.     window_new_screen_size (screenwidth, screenheight, (VFunction *)NULL);
  174.     *old_signal_handler = (SigHandler *) signal (sig, info_signal_handler);
  175.     redisplay_after_signal ();
  176.       }
  177.       break;
  178. #endif /* SIGWINCH */
  179.     }
  180. }
  181.