From fsosi@j51.com Tue Mar  7 17:10:06 MET 1995
Article: 26995 of comp.os.linux.development
Path: news.coli.uni-sb.de!news.dfn.de!prise.nz.dlr.de!zib-berlin.de!news.mathworks.com!solaris.cc.vt.edu!spcuna!tzlink.j51.com!fsosi
From: fsosi@j51.com (NightHawk)
Newsgroups: comp.os.linux.development,comp.text.tex
Subject: POSIX patch for ispell 3.1.18
Date: 6 Mar 1995 06:00:06 GMT
Organization: TZ-Link, a public-access online community in Nyack, NY.
Lines: 860
Message-ID: <3je8d6$i8@tzlink.j51.com>
NNTP-Posting-Host: j51.com
Summary: Compile ispell on a POSIX system
Keywords: ispell, POSIX
X-Newsreader: TIN [version 1.2 PL2]
Xref: news.coli.uni-sb.de comp.os.linux.development:26995 comp.text.tex:54414

This is the patch for ispell 3.1.18 to get it compile under
POSIX. You can just put

#define POSIX

in your local.h.

I have tested it under Linux with libc 4.6.30. It should compile
older libc. It works ok for my limited tests. Please try it
under Linux and other POSIX systems. I will submit it to the author 
if I do not hear anything in 1 week.

You can get ispell from ftp.cs.ucla.edu under pub/ispell.

fsosi@j51.com
03/05/1995
------
diff -c misc/ispell/Makefile:1.1.1.1 misc/ispell/Makefile:1.2
*** misc/ispell/Makefile:1.1.1.1	Mon Mar  6 00:05:26 1995
--- misc/ispell/Makefile	Mon Mar  6 00:05:26 1995
***************
*** 1,5 ****
  #
! # $Id: Makefile,v 1.1.1.1 1995/03/05 18:33:05 hjl Exp $
  #
  # Copyright 1992, 1993, Geoff Kuenning, Granada Hills, CA
  # All rights reserved.
--- 1,5 ----
  #
! # $Id: Makefile,v 1.2 1995/03/06 05:02:37 hjl Exp $
  #
  # Copyright 1992, 1993, Geoff Kuenning, Granada Hills, CA
  # All rights reserved.
***************
*** 47,52 ****
--- 47,55 ----
  #   buildhash <dictfile> <affix-file> <outfile>
  
  # $Log: Makefile,v $
+ # Revision 1.2  1995/03/06  05:02:37  hjl
+ # Port ispell 3.1.18 to POSIX.
+ #
  # Revision 1.1.1.1  1995/03/05  18:33:05  hjl
  # Import ispell 3.1.18.
  #
***************
*** 240,246 ****
  	    set -ex; \
  	    rm -f $$ELISPDIR/ispell.el; \
  	    $$INSTALL ispell.el $$ELISPDIR; \
! 	    if iwhich $$EMACS >/dev/null; then \
  		echo '(byte-compile-file "'"$$ELISPDIR/ispell.el"'")' \
  		  > /tmp/emi$$$$; \
  		$$EMACS -nw -batch -l /tmp/emi$$$$; \
--- 243,249 ----
  	    set -ex; \
  	    rm -f $$ELISPDIR/ispell.el; \
  	    $$INSTALL ispell.el $$ELISPDIR; \
! 	    if ./iwhich $$EMACS >/dev/null; then \
  		echo '(byte-compile-file "'"$$ELISPDIR/ispell.el"'")' \
  		  > /tmp/emi$$$$; \
  		$$EMACS -nw -batch -l /tmp/emi$$$$; \
***************
*** 308,317 ****
  	  . ./config.sh; \
  	  set $(SHELLDEBUG); \
  	  if [ -d $$TEXINFODIR ]; then \
! 	    if iwhich makeinfo >/dev/null \
  	      &&  makeinfo ispell.texinfo 2>/dev/null; then \
  		:; \
! 	    elif iwhich $$EMACS >/dev/null; then \
  		set -e; \
  		$$EMACS -batch dummy -i ispell.texinfo \
  		  -f texinfo-format-buffer -f save-buffer; \
--- 311,320 ----
  	  . ./config.sh; \
  	  set $(SHELLDEBUG); \
  	  if [ -d $$TEXINFODIR ]; then \
! 	    if ./iwhich makeinfo >/dev/null \
  	      &&  makeinfo ispell.texinfo 2>/dev/null; then \
  		:; \
! 	    elif ./iwhich $$EMACS >/dev/null; then \
  		set -e; \
  		$$EMACS -batch dummy -i ispell.texinfo \
  		  -f texinfo-format-buffer -f save-buffer; \
diff -c misc/ispell/config.X:1.1.1.1 misc/ispell/config.X:1.2
*** misc/ispell/config.X:1.1.1.1	Mon Mar  6 00:05:27 1995
--- misc/ispell/config.X	Mon Mar  6 00:05:27 1995
***************
*** 52,60 ****
   */
  
  /*
!  * $Id: config.X,v 1.1.1.1 1995/03/05 18:33:05 hjl Exp $
   *
   * $Log: config.X,v $
  # Revision 1.1.1.1  1995/03/05  18:33:05  hjl
  # Import ispell 3.1.18.
  #
--- 52,63 ----
   */
  
  /*
!  * $Id: config.X,v 1.2 1995/03/06 05:02:37 hjl Exp $
   *
   * $Log: config.X,v $
+ # Revision 1.2  1995/03/06  05:02:37  hjl
+ # Port ispell 3.1.18 to POSIX.
+ #
  # Revision 1.1.1.1  1995/03/05  18:33:05  hjl
  # Import ispell 3.1.18.
  #
***************
*** 108,116 ****
  #undef USG		/* Define this in local.h for System V machines */
  #endif /* USG */
  
  #include <sys/param.h>
  #include <sys/types.h>
! #ifndef USG
  #include <sys/dir.h>
  #endif /* USG */
  
--- 111,125 ----
  #undef USG		/* Define this in local.h for System V machines */
  #endif /* USG */
  
+ #ifndef POSIX
+ /* Define this in local.h for POSIX System machines. Most of modern
+    Unix systems can use this. H.J. */
+ #undef POSIX
+ #endif /* USG */
+ 
  #include <sys/param.h>
  #include <sys/types.h>
! #if !defined (USG) && !defined(POSIX)
  #include <sys/dir.h>
  #endif /* USG */
  
***************
*** 586,593 ****
--- 595,606 ----
  ** the terminal mode for ispell, set to CBREAK or RAW
  **
  */
+ #ifdef POSIX
+ #define TERM_MODE	~ICANON
+ #else
  #ifndef TERM_MODE
  #define TERM_MODE	CBREAK
+ #endif
  #endif
  
  /*
diff -c misc/ispell/ispell.c:1.1.1.1 misc/ispell/ispell.c:1.2
*** misc/ispell/ispell.c:1.1.1.1	Mon Mar  6 00:05:28 1995
--- misc/ispell/ispell.c	Mon Mar  6 00:05:28 1995
***************
*** 1,6 ****
  #ifndef lint
  static char Rcs_Id[] =
!     "$Id: ispell.c,v 1.1.1.1 1995/03/05 18:33:06 hjl Exp $";
  #endif
  
  #define MAIN
--- 1,6 ----
  #ifndef lint
  static char Rcs_Id[] =
!     "$Id: ispell.c,v 1.2 1995/03/06 05:02:38 hjl Exp $";
  #endif
  
  #define MAIN
***************
*** 49,54 ****
--- 49,57 ----
  
  /*
   * $Log: ispell.c,v $
+  * Revision 1.2  1995/03/06  05:02:38  hjl
+  * Port ispell 3.1.18 to POSIX.
+  *
   * Revision 1.1.1.1  1995/03/05  18:33:06  hjl
   * Import ispell 3.1.18.
   *
***************
*** 317,322 ****
--- 320,329 ----
  #endif /* BOTTOMCONTEXT */
  #if TERM_MODE == CBREAK
  		    (void) printf ("\tCBREAK\n");
+ #else
+ #if TERM_MODE == ~ICANON
+ 		    (void) printf ("\t~ICANON\n");
+ #endif
  #endif /* TERM_MODE */
  		    (void) printf ("\tCC = \"%s\"\n", CC);
  		    (void) printf ("\tCFLAGS = \"%s\"\n", CFLAGS);
diff -c misc/ispell/local.h.samp:1.1.1.1 misc/ispell/local.h.samp:1.2
*** misc/ispell/local.h.samp:1.1.1.1	Mon Mar  6 00:05:29 1995
--- misc/ispell/local.h.samp	Mon Mar  6 00:05:29 1995
***************
*** 1,5 ****
  /*
!  * $Id: local.h.samp,v 1.1.1.1 1995/03/05 18:33:06 hjl Exp $
   */
  
  /*
--- 1,5 ----
  /*
!  * $Id: local.h.samp,v 1.2 1995/03/06 05:02:39 hjl Exp $
   */
  
  /*
***************
*** 49,54 ****
--- 49,57 ----
  
  /*
   * $Log: local.h.samp,v $
+ # Revision 1.2  1995/03/06  05:02:39  hjl
+ # Port ispell 3.1.18 to POSIX.
+ #
  # Revision 1.1.1.1  1995/03/05  18:33:06  hjl
  # Import ispell 3.1.18.
  #
***************
*** 84,89 ****
--- 87,93 ----
  
  #define MINIMENU	/* Display a mini-menu at the bottom of the screen */
  #define NO8BIT		/* Remove this if you use ISO character sets */
+ #define POSIX		/* Define this on POSIX systems */
  #undef USG		/* Define this on System V */
  
  /*
diff -c misc/ispell/term.c:1.1.1.1 misc/ispell/term.c:1.2
*** misc/ispell/term.c:1.1.1.1	Mon Mar  6 00:05:30 1995
--- misc/ispell/term.c	Mon Mar  6 00:05:30 1995
***************
*** 1,6 ****
  #ifndef lint
  static char Rcs_Id[] =
!     "$Id: term.c,v 1.1.1.1 1995/03/05 18:33:05 hjl Exp $";
  #endif
  
  /*
--- 1,6 ----
  #ifndef lint
  static char Rcs_Id[] =
!     "$Id: term.c,v 1.2 1995/03/06 05:02:40 hjl Exp $";
  #endif
  
  /*
***************
*** 47,52 ****
--- 47,55 ----
  
  /*
   * $Log: term.c,v $
+  * Revision 1.2  1995/03/06  05:02:40  hjl
+  * Port ispell 3.1.18 to POSIX.
+  *
   * Revision 1.1.1.1  1995/03/05  18:33:05  hjl
   * Import ispell 3.1.18.
   *
***************
*** 67,77 ****
--- 70,84 ----
  #include "ispell.h"
  #include "proto.h"
  #include "msgs.h"
+ #ifdef POSIX
+ #include <termios.h>
+ #else
  #ifdef USG
  #include <termio.h>
  #else
  #include <sgtty.h>
  #endif
+ #endif
  #include <signal.h>
  
  void		erase P ((void));
***************
*** 138,143 ****
--- 145,154 ----
      return putchar (c);
      }
  
+ #ifdef POSIX
+ static struct termios	sbuf;
+ static struct termios	osbuf;
+ #else
  #ifdef USG
  static struct termio	sbuf;
  static struct termio	osbuf;
***************
*** 149,154 ****
--- 160,166 ----
  static struct ltchars	oltc;
  #endif
  #endif
+ #endif
  static int		termchanged = 0;
  static SIGNAL_TYPE	(*oldint) ();
  static SIGNAL_TYPE	(*oldterm) ();
***************
*** 244,256 ****
  #endif /* SIGTSTP */
  #endif /* TIOCPGRP */
  
! #ifdef USG
      if (!isatty (0))
  	{
  	(void) fprintf (stderr, TERM_C_NO_BATCH);
  	exit (1);
  	}
      (void) ioctl (0, TCGETA, (char *) &osbuf);
      termchanged = 1;
  
      sbuf = osbuf;
--- 256,272 ----
  #endif /* SIGTSTP */
  #endif /* TIOCPGRP */
  
! #if defined(USG) || defined (POSIX)
      if (!isatty (0))
  	{
  	(void) fprintf (stderr, TERM_C_NO_BATCH);
  	exit (1);
  	}
+ #ifdef POSIX
+     tcgetattr (0, &osbuf);
+ #else
      (void) ioctl (0, TCGETA, (char *) &osbuf);
+ #endif
      termchanged = 1;
  
      sbuf = osbuf;
***************
*** 259,265 ****
--- 275,285 ----
      sbuf.c_iflag &= ~(INLCR | IGNCR | ICRNL);
      sbuf.c_cc[VMIN] = 1;
      sbuf.c_cc[VTIME] = 1;
+ #ifdef POSIX
+     tcsetattr (0, TCSADRAIN, &sbuf);
+ #else
      (void) ioctl (0, TCSETAW, (char *) &sbuf);
+ #endif
  
      uerasechar = osbuf.c_cc[VERASE];
      ukillchar = osbuf.c_cc[VKILL];
***************
*** 267,276 ****
--- 287,307 ----
  #endif
  
  #ifdef SIGTSTP
+ #ifdef POSIX
+     {
+       sigset_t set;
+       sigemptyset(&set);
+       sigaddset(&set, SIGTSTP); 
+       sigaddset(&set, SIGTTIN); 
+       sigaddset(&set, SIGTTOU); 
+       sigprocmask(SIG_SETMASK, &set, NULL);
+     }
+ #else
  #ifndef USG
      (void) sigsetmask (1<<(SIGTSTP-1) | 1<<(SIGTTIN-1) | 1<<(SIGTTOU-1));
  #endif
  #endif
+ #endif
  #ifdef TIOCGPGRP
      if (ioctl (0, TIOCGPGRP, (char *) &tpgrp) != 0)
  	{
***************
*** 282,290 ****
--- 313,331 ----
  #ifdef TIOCPGRP
      if (tpgrp != getpgrp(0)) /* not in foreground */
  	{
+ #ifdef POSIX
+ 	  {
+ 	    sigset_t set;
+ 	    sigemptyset(&set);
+ 	    sigaddset(&set, SIGTSTP); 
+ 	    sigaddset(&set, SIGTTIN); 
+ 	    sigprocmask(SIG_SETMASK, &set, NULL);
+ 	  }
+ #else
  #ifndef USG
  	(void) sigsetmask (1 << (SIGTSTP - 1) | 1 << (SIGTTIN - 1));
  #endif
+ #endif
  	(void) signal (SIGTTOU, SIG_DFL);
  	(void) kill (0, SIGTTOU);
  	/* job stops here waiting for SIGCONT */
***************
*** 293,298 ****
--- 334,352 ----
  #endif
  #endif
  
+ #ifdef POSIX
+     tcgetattr (0, &sbuf);
+     termchanged = 1;
+ 
+     sbuf.c_lflag &= ~ECHO;
+     sbuf.c_lflag |= TERM_MODE;
+     /* A better one? */
+     sbuf.c_cc[VSUSP] = -1;
+ 
+     tcsetattr (0, TCSANOW, &sbuf);
+     uerasechar = sbuf.c_cc[VERASE];
+     ukillchar = sbuf.c_cc[VKILL];
+ #else
  #ifndef USG
      (void) ioctl (0, TIOCGETP, (char *) &osbuf);
  #ifdef TIOCGLTC
***************
*** 314,327 ****
      (void) ioctl (0, TIOCSLTC, (char *) &ltc);
  #endif
  
! #endif /* USG */
  
      if ((oldint = signal (SIGINT, SIG_IGN)) != SIG_IGN)
  	(void) signal (SIGINT, done);
      if ((oldterm = signal (SIGTERM, SIG_IGN)) != SIG_IGN)
  	(void) signal (SIGTERM, done);
  
  #ifdef SIGTSTP
  #ifndef USG
      (void) sigsetmask (0);
  #endif
--- 368,452 ----
      (void) ioctl (0, TIOCSLTC, (char *) &ltc);
  #endif
  
! #endif /* !USG */
  
+ #endif /* POSIX */
+ 
+ #ifdef POSIX
+     {
+       struct sigaction action, oldaction;
+       action.sa_handler = SIG_IGN;
+       action.sa_flags = 0;
+       sigemptyset (&action.sa_mask);
+       sigaction (SIGTTIN, &action, &oldaction);
+       if ((oldint = oldaction.sa_handler) != SIG_IGN)
+       {
+ 	action.sa_handler = done;
+ 	action.sa_flags = 0;
+ 	sigemptyset (&action.sa_mask);
+ 	sigaction (SIGTTIN, &action, NULL);
+       }
+       action.sa_handler = SIG_IGN;
+       action.sa_flags = 0;
+       sigemptyset (&action.sa_mask);
+       sigaction (SIGTERM, &action, &oldaction);
+       if ((oldterm = oldaction.sa_handler) != SIG_IGN)
+       {
+ 	action.sa_handler = done;
+ 	sigemptyset (&action.sa_mask);
+ 	action.sa_flags = 0;
+ 	sigaction (SIGTERM, &action, NULL);
+       }
+     }
+ #else
      if ((oldint = signal (SIGINT, SIG_IGN)) != SIG_IGN)
  	(void) signal (SIGINT, done);
      if ((oldterm = signal (SIGTERM, SIG_IGN)) != SIG_IGN)
  	(void) signal (SIGTERM, done);
+ #endif
  
  #ifdef SIGTSTP
+ #ifdef POSIX
+     {
+       sigset_t set;
+       struct sigaction action, oldaction;
+       sigemptyset(&set);
+       sigprocmask(SIG_SETMASK, &set, NULL);
+       action.sa_handler = SIG_IGN;
+       action.sa_flags = 0;
+       sigemptyset (&action.sa_mask);
+       sigaction (SIGTTIN, &action, &oldaction);
+       if ((oldttin = oldaction.sa_handler) != SIG_IGN)
+       {
+ 	action.sa_handler = onstop;
+         action.sa_flags = 0;
+ 	sigemptyset (&action.sa_mask);
+ 	sigaction (SIGTTIN, &action, NULL);
+       }
+       action.sa_handler = SIG_IGN;
+       action.sa_flags = 0;
+       sigemptyset (&action.sa_mask);
+       sigaction (SIGTTOU, &action, &oldaction);
+       if ((oldttou = oldaction.sa_handler) != SIG_IGN)
+       {
+ 	action.sa_handler = onstop;
+         action.sa_flags = 0;
+ 	sigemptyset (&action.sa_mask);
+ 	sigaction (SIGTTOU, &action, NULL);
+       }
+       action.sa_handler = SIG_IGN;
+       action.sa_flags = 0;
+       sigemptyset (&action.sa_mask);
+       sigaction (SIGTSTP, &action, &oldaction);
+       if ((oldtstp = oldaction.sa_handler) != SIG_IGN)
+       {
+ 	action.sa_handler = onstop;
+         action.sa_flags = 0;
+ 	sigemptyset (&action.sa_mask);
+ 	sigaction (SIGTSTP, &action, NULL);
+       }
+     }
+ #else
  #ifndef USG
      (void) sigsetmask (0);
  #endif
***************
*** 332,337 ****
--- 457,463 ----
      if ((oldtstp = signal (SIGTSTP, SIG_IGN)) != SIG_IGN)
  	(void) signal (SIGTSTP, onstop);
  #endif
+ #endif
      if (ti)
  	tputs (ti, 1, putch);
      }
***************
*** 346,351 ****
--- 472,480 ----
  	{
  	if (te)
  	    tputs (te, 1, putch);
+ #ifdef POSIX
+ 	tcsetattr (0, TCSADRAIN, &osbuf);
+ #else
  #ifdef USG
  	(void) ioctl (0, TCSETAW, (char *) &osbuf);
  #else
***************
*** 354,359 ****
--- 483,489 ----
  	(void) ioctl (0, TIOCSLTC, (char *) &oltc);
  #endif
  #endif
+ #endif
  	}
      exit (0);
      }
***************
*** 362,367 ****
--- 492,500 ----
  static SIGNAL_TYPE onstop (signo)
      int		signo;
      {
+ #ifdef POSIX
+     tcsetattr (0, TCSADRAIN, &osbuf);
+ #else
  #ifdef USG
      (void) ioctl (0, TCSETAW, (char *) &osbuf);
  #else
***************
*** 370,382 ****
--- 503,538 ----
      (void) ioctl (0, TIOCSLTC, (char *) &oltc);
  #endif
  #endif
+ #endif
      (void) signal (signo, SIG_DFL);
+ #ifdef POSIX
+     {
+       sigset_t set;
+       sigemptyset(&set);
+       sigaddset(&set, signo); 
+       sigprocmask(SIG_UNBLOCK, &set, NULL);
+     }
+ #else
  #ifndef USG
      (void) sigsetmask (sigblock (0) & ~(1 << (signo - 1)));
  #endif
+ #endif
      (void) kill (0, signo);
      /* stop here until continued */
+ #ifdef POSIX
+     {
+       struct sigaction action;
+       action.sa_handler = onstop;
+       action.sa_flags = 0;
+       sigemptyset (&action.sa_mask);
+       sigaction (signo, &action, NULL);
+     }
+ #else
      (void) signal (signo, onstop);
+ #endif
+ #ifdef POSIX
+     tcsetattr (0, TCSADRAIN, &sbuf);
+ #else
  #ifdef USG
      (void) ioctl (0, TCSETAW, (char *) &sbuf);
  #else
***************
*** 385,390 ****
--- 541,547 ----
      (void) ioctl (0, TIOCSLTC, (char *) &ltc);
  #endif
  #endif
+ #endif
      }
  #endif
  
***************
*** 437,442 ****
--- 594,602 ----
  	}
      argv[i] = NULL;
  
+ #ifdef POSIX
+     tcsetattr (0, TCSADRAIN, &osbuf);
+ #else
  #ifdef USG
      (void) ioctl (0, TCSETAW, (char *) &osbuf);
  #else
***************
*** 445,450 ****
--- 605,638 ----
      (void) ioctl (0, TIOCSLTC, (char *) &oltc);
  #endif /* TIOCSLTC */
  #endif
+ #endif
+ #ifdef POSIX
+     {
+       struct sigaction action;
+       action.sa_handler = oldint;
+       action.sa_flags = 0;
+       sigemptyset (&action.sa_mask);
+       sigaction (SIGINT, &action, NULL);
+       action.sa_handler = oldterm;
+       action.sa_flags = 0;
+       sigemptyset (&action.sa_mask);
+       sigaction (SIGTERM, &action, NULL);
+ #ifdef SIGTSTP
+       action.sa_handler = oldttin;
+       action.sa_flags = 0;
+       sigemptyset (&action.sa_mask);
+       sigaction (SIGTTIN, &action, NULL);
+       action.sa_handler = oldttou;
+       action.sa_flags = 0;
+       sigemptyset (&action.sa_mask);
+       sigaction (SIGTTOU, &action, NULL);
+       action.sa_handler = oldtstp;
+       action.sa_flags = 0;
+       sigemptyset (&action.sa_mask);
+       sigaction (SIGTSTP, &action, NULL);
+ #endif
+     }
+ #else
      (void) signal (SIGINT, oldint);
      (void) signal (SIGTERM, oldterm);
  #ifdef SIGTSTP
***************
*** 452,457 ****
--- 640,646 ----
      (void) signal (SIGTTOU, oldttou);
      (void) signal (SIGTSTP, oldtstp);
  #endif
+ #endif
      if ((i = fork ()) == 0)
  	{
  	(void) execvp (argv[0], (char **) argv);
***************
*** 469,474 ****
--- 658,705 ----
  	termstat = -1;		/* Couldn't fork */
  	}
  
+ #ifdef POSIX
+     {
+       struct sigaction action;
+       if (oldint != SIG_IGN)
+       {
+ 	action.sa_handler = done;
+ 	action.sa_flags = 0;
+ 	sigemptyset (&action.sa_mask);
+ 	sigaction (SIGINT, &action, NULL);
+       }
+       if (oldterm != SIG_IGN)
+       {
+ 	action.sa_handler = done;
+ 	sigemptyset (&action.sa_mask);
+ 	action.sa_flags = 0;
+ 	sigaction (SIGTERM, &action, NULL);
+       }
+ #ifdef SIGTSTP
+       if (oldttin != SIG_IGN)
+       {
+ 	action.sa_handler = onstop;
+ 	sigemptyset (&action.sa_mask);
+ 	action.sa_flags = 0;
+ 	sigaction (SIGTTIN, &action, NULL);
+       }
+       if (oldttou != SIG_IGN)
+       {
+ 	action.sa_handler = onstop;
+ 	sigemptyset (&action.sa_mask);
+ 	action.sa_flags = 0;
+ 	sigaction (SIGTTOU, &action, NULL);
+       }
+       if (oldtstp != SIG_IGN)
+       {
+ 	action.sa_handler = onstop;
+ 	sigemptyset (&action.sa_mask);
+ 	action.sa_flags = 0;
+ 	sigaction (SIGTSTP, &action, NULL);
+       }
+ #endif
+     }
+ #else
      if (oldint != SIG_IGN)
  	(void) signal (SIGINT, done);
      if (oldterm != SIG_IGN)
***************
*** 482,488 ****
--- 713,723 ----
      if (oldtstp != SIG_IGN)
  	(void) signal (SIGTSTP, onstop);
  #endif
+ #endif
  
+ #ifdef POSIX
+     tcsetattr (0, TCSADRAIN, &sbuf);
+ #else
  #ifdef USG
      (void) ioctl (0, TCSETAW, (char *) &sbuf);
  #else
***************
*** 491,496 ****
--- 726,732 ----
      (void) ioctl (0, TIOCSLTC, (char *) &ltc);
  #endif /* TIOCSLTC */
  #endif
+ #endif
      if (termstat)
  	{
  	(void) printf (TERM_C_TYPE_SPACE);
***************
*** 516,521 ****
--- 752,760 ----
      int		ch;
  #endif
  
+ #ifdef POSIX
+     tcsetattr (0, TCSADRAIN, &osbuf);
+ #else
  #ifdef USG
      (void) ioctl (0, TCSETAW, (char *) &osbuf);
  #else
***************
*** 524,529 ****
--- 763,836 ----
      (void) ioctl (0, TIOCSLTC, (char *) &oltc);
  #endif
  #endif
+ #endif
+ #ifdef POSIX
+     {
+       struct sigaction action;
+       action.sa_handler = oldint;
+       action.sa_flags = 0;
+       sigemptyset (&action.sa_mask);
+       sigaction (SIGINT, &action, NULL);
+       action.sa_handler = oldterm;
+       action.sa_flags = 0;
+       sigemptyset (&action.sa_mask);
+       sigaction (SIGTERM, &action, NULL);
+ #ifdef SIGTSTP
+       action.sa_handler = oldttin;
+       action.sa_flags = 0;
+       sigemptyset (&action.sa_mask);
+       sigaction (SIGTIN, &action, NULL);
+       action.sa_handler = oldttou;
+       action.sa_flags = 0;
+       sigemptyset (&action.sa_mask);
+       sigaction (SIGTOU, &action, NULL);
+       action.sa_handler = oldtstp;
+       action.sa_flags = 0;
+       sigemptyset (&action.sa_mask);
+       sigaction (SIGTSTP, &action, NULL);
+ #endif
+ 
+       (void) system (buf);
+ 
+       if (oldint != SIG_IGN)
+       {
+ 	action.sa_handler = done;
+ 	action.sa_flags = 0;
+ 	sigemptyset (&action.sa_mask);
+ 	sigaction (SIGINT, &action, NULL);
+       }
+       if (oldterm != SIG_IGN)
+       {
+ 	action.sa_handler = done;
+ 	sigemptyset (&action.sa_mask);
+ 	action.sa_flags = 0;
+ 	sigaction (SIGTERM, &action, NULL);
+       }
+ #ifdef SIGTSTP
+       if (oldttin != SIG_IGN)
+       {
+ 	action.sa_handler = onstop;
+ 	sigemptyset (&action.sa_mask);
+ 	action.sa_flags = 0;
+ 	sigaction (SIGTIN, &action, NULL);
+       }
+       if (oldttou != SIG_IGN)
+       {
+ 	action.sa_handler = onstop;
+ 	sigemptyset (&action.sa_mask);
+ 	action.sa_flags = 0;
+ 	sigaction (SIGTOU, &action, NULL);
+       }
+       if (oldtstp != SIG_IGN)
+       {
+ 	action.sa_handler = onstop;
+ 	sigemptyset (&action.sa_mask);
+ 	action.sa_flags = 0;
+ 	sigaction (SIGTSTP, &action, NULL);
+       }
+ #endif
+     }
+ #else
      (void) signal (SIGINT, oldint);
      (void) signal (SIGTERM, oldterm);
  #ifdef SIGTSTP
***************
*** 547,559 ****
--- 854,871 ----
      if (oldtstp != SIG_IGN)
  	(void) signal (SIGTSTP, onstop);
  #endif
+ #endif
  
+ #ifdef POSIX
+     tcsetattr (0, TCSADRAIN, &sbuf);
+ #else
  #ifdef USG
      (void) ioctl (0, TCSETAW, (char *) &sbuf);
  #else
      (void) ioctl (0, TIOCSETP, (char *) &sbuf);
  #ifdef TIOCSLTC
      (void) ioctl (0, TIOCSLTC, (char *) &ltc);
+ #endif
  #endif
  #endif
      (void) printf (TERM_C_TYPE_SPACE);


