]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/lib_tstp.c
ncurses 4.2
[ncurses.git] / ncurses / lib_tstp.c
index ee7c2afbe0d97ce96a3b9fe64f32b9ea16066f45..0fb8b848986c3f6b2748d62195fea2e59746e28a 100644 (file)
@@ -1,23 +1,35 @@
+/****************************************************************************
+ * Copyright (c) 1998 Free Software Foundation, Inc.                        *
+ *                                                                          *
+ * Permission is hereby granted, free of charge, to any person obtaining a  *
+ * copy of this software and associated documentation files (the            *
+ * "Software"), to deal in the Software without restriction, including      *
+ * without limitation the rights to use, copy, modify, merge, publish,      *
+ * distribute, distribute with modifications, sublicense, and/or sell       *
+ * copies of the Software, and to permit persons to whom the Software is    *
+ * furnished to do so, subject to the following conditions:                 *
+ *                                                                          *
+ * The above copyright notice and this permission notice shall be included  *
+ * in all copies or substantial portions of the Software.                   *
+ *                                                                          *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
+ *                                                                          *
+ * Except as contained in this notice, the name(s) of the above copyright   *
+ * holders shall not be used in advertising or otherwise to promote the     *
+ * sale, use or other dealings in this Software without prior written       *
+ * authorization.                                                           *
+ ****************************************************************************/
 
-/***************************************************************************
-*                            COPYRIGHT NOTICE                              *
-****************************************************************************
-*                ncurses is copyright (C) 1992-1995                        *
-*                          Zeyd M. Ben-Halim                               *
-*                          zmbenhal@netcom.com                             *
-*                          Eric S. Raymond                                 *
-*                          esr@snark.thyrsus.com                           *
-*                                                                          *
-*        Permission is hereby granted to reproduce and distribute ncurses  *
-*        by any means and for any fee, whether alone or as part of a       *
-*        larger distribution, in source or in binary form, PROVIDED        *
-*        this notice is included with any such distribution, and is not    *
-*        removed from any of its header files. Mention of ncurses in any   *
-*        applications linked with it is highly appreciated.                *
-*                                                                          *
-*        ncurses comes AS IS with no warranty, implied or expressed.       *
-*                                                                          *
-***************************************************************************/
+/****************************************************************************
+ *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
+ *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ ****************************************************************************/
 
 
 /*
 #include <curses.priv.h>
 
 #include <signal.h>
-
-#if HAVE_SIGACTION
-#if !HAVE_TYPE_SIGACTION
-typedef struct sigaction sigaction_t;
-#endif
-#else  /* !HAVE_SIGACTION */
-#if HAVE_SIGVEC
 #include <SigAction.h>
-#endif
-#endif
 
-#ifdef SVR4_ACTION
+#if defined(SVR4_ACTION) && !defined(_POSIX_SOURCE)
 #define _POSIX_SOURCE
 #endif
 
-MODULE_ID("$Id: lib_tstp.c,v 1.8 1996/11/17 00:11:41 tom Exp $")
+MODULE_ID("$Id: lib_tstp.c,v 1.15 1998/02/11 12:13:57 tom Exp $")
 
 /*
  * Note: This code is fragile!  Its problem is that different OSs
@@ -110,7 +113,7 @@ static void tstp(int dummy GCC_UNUSED)
         */
        (void)sigemptyset(&mask);
        (void)sigaddset(&mask, SIGALRM);
-#ifdef SIGWINCH
+#if USE_SIGWINCH
        (void)sigaddset(&mask, SIGWINCH);
 #endif
        (void)sigprocmask(SIG_BLOCK, &mask, &omask);
@@ -173,18 +176,36 @@ static void cleanup(int sig)
                sigemptyset(&act.sa_mask);
                act.sa_flags = 0;
                act.sa_handler = SIG_IGN;
-               if (sigaction(sig, &act, (sigaction_t *)0) == 0) {
-                       endwin();
-               }
+               if (sigaction(sig, &act, (sigaction_t *)0) == 0)
 #else
-               if (signal(sig, SIG_IGN) != SIG_ERR) {
+               if (signal(sig, SIG_IGN) != SIG_ERR)
+#endif
+               {
+                   SCREEN *scan = _nc_screen_chain;
+                   while(scan)
+                   {
+                       set_term(scan);
                        endwin();
+                       SP->_endwin = FALSE; /* in case we have an atexit! */
+                       scan = scan->_next_screen;
+                   }
                }
-#endif
        }
        exit(EXIT_FAILURE);
 }
 
+#if USE_SIGWINCH
+static void sigwinch(int sig GCC_UNUSED)
+{
+    SCREEN *scan = _nc_screen_chain;
+    while(scan)
+    {
+       scan->_sig_winch = TRUE;
+       scan = scan->_next_screen;
+    }
+}
+#endif /* USE_SIGWINCH */
+
 /*
  * If the given signal is still in its default state, set it to the given
  * handler.
@@ -194,11 +215,12 @@ static int CatchIfDefault(int sig, sigaction_t *act)
 {
        sigaction_t old_act;
 
-#ifdef SA_RESTART
-       act->sa_flags |= SA_RESTART;
-#endif /* SA_RESTART */
        if (sigaction(sig, (sigaction_t *)0, &old_act) == 0
-        && old_act.sa_handler == SIG_DFL) {
+        && (old_act.sa_handler == SIG_DFL
+#if USE_SIGWINCH
+           || (sig == SIGWINCH && old_act.sa_handler == SIG_IGN)
+#endif
+           )) {
                (void)sigaction(sig, act, (sigaction_t *)0);
                return TRUE;
        }
@@ -210,7 +232,11 @@ static int CatchIfDefault(int sig, RETSIGTYPE (*handler)())
        void    (*ohandler)();
 
        ohandler = signal(sig, SIG_IGN);
-       if (ohandler == SIG_DFL) {
+       if (ohandler == SIG_DFL
+#if USE_SIGWINCH
+           || (sig == SIGWINCH && ohandler == SIG_IGN)
+#endif
+       ) {
                signal(sig, handler);
                return TRUE;
        } else {
@@ -252,10 +278,14 @@ static int ignore;
                {
                        sigemptyset(&act.sa_mask);
                        act.sa_flags = 0;
+#if USE_SIGWINCH
+                       act.sa_handler = sigwinch;
+                       CatchIfDefault(SIGWINCH, &act);
+#endif
+
 #ifdef SA_RESTART
                        act.sa_flags |= SA_RESTART;
 #endif /* SA_RESTART */
-
                        act.sa_handler = cleanup;
                        CatchIfDefault(SIGINT,  &act);
                        CatchIfDefault(SIGTERM, &act);
@@ -265,18 +295,31 @@ static int ignore;
                                ignore = TRUE;
                }
        }
-#else
+#else /* !SIGTSTP */
        if (enable)
        {
 #if HAVE_SIGACTION || HAVE_SIGVEC
                static sigaction_t act;
+               sigemptyset(&act.sa_mask);
+#if USE_SIGWINCH
+               act.sa_handler = sigwinch;
+               CatchIfDefault(SIGWINCH, &act);
+#endif
+#ifdef SA_RESTART
+               act.sa_flags |= SA_RESTART;
+#endif /* SA_RESTART */
                act.sa_handler = cleanup;
                CatchIfDefault(SIGINT,  &act);
                CatchIfDefault(SIGTERM, &act);
-#else
+
+#else /* !(HAVE_SIGACTION || HAVE_SIGVEC) */
+
                CatchIfDefault(SIGINT,  cleanup);
                CatchIfDefault(SIGTERM, cleanup);
+#if USE_SIGWINCH
+               CatchIfDefault(SIGWINCH, sigwinch);
 #endif
+#endif /* !(HAVE_SIGACTION || HAVE_SIGVEC) */
        }
-#endif
+#endif /* !SIGTSTP */
 }