- (bal) Changed from GNU rx to PCRE on suggestion from djm.
 - (bal) Integrated Sony NEWS-OS patches from NAKAJI Hirouyuki
   <nakaji@tutrp.tut.ac.jp>
diff --git a/ChangeLog b/ChangeLog
index 2070718..3d3a04a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,9 @@
  - (djm) Don't rely on atomicio's retval to determine length of askpass
    supplied passphrase. Problem report from Lutz Jaenicke
    <Lutz.Jaenicke@aet.TU-Cottbus.DE>
+ - (bal) Changed from GNU rx to PCRE on suggestion from djm.
+ - (bal) Integrated Sony NEWS-OS patches from NAKAJI Hirouyuki 
+   <nakaji@tutrp.tut.ac.jp>
 
 20001016
  - (djm) Sync with OpenBSD:
diff --git a/INSTALL b/INSTALL
index b201ecc..9112b92 100644
--- a/INSTALL
+++ b/INSTALL
@@ -40,8 +40,8 @@
 OpenSSH has only been tested with GNU make. It may work with other
 'make' programs, but you are on your own.
 
-GNU rx:
-ftp:://ftp.gnu.org/gnu/rx/
+pcre (POSIX Regular Expression library):
+ftp://ftp.cus.cam.ac.uk/pub/software/programs/pcre/
 
 Most platforms do not required this.  However older 4.3 BSD do not
 have a posix regex library. 
diff --git a/acconfig.h b/acconfig.h
index d212b90..0837eb3 100644
--- a/acconfig.h
+++ b/acconfig.h
@@ -52,8 +52,8 @@
 /* Define if you are on Cygwin */
 #undef HAVE_CYGWIN
 
-/* Define if you lack native POSIX regex and you are using GNU rx library */
-#undef HAVE_LIBRX
+/* Define if you lack native POSIX regex and you are using PCRE */
+#undef HAVE_LIBPCRE
 
 /* Define if you have a broken realpath. */
 #undef BROKEN_REALPATH
@@ -61,6 +61,9 @@
 /* Define if you are on NeXT */
 #undef HAVE_NEXT
 
+/* Define if you are on NEWS-OS */
+#undef HAVE_NEWS4
+
 /* Define if you want to disable PAM support */
 #undef DISABLE_PAM
 
@@ -254,6 +257,9 @@
 /* Use IPv4 for connection by default, IPv6 can still if explicity asked */
 #undef IPV4_DEFAULT
 
+/* If you have no atexit() but xatexit(), and want to use xatexit() */
+#undef HAVE_XATEXIT
+
 /* getaddrinfo is broken (if present) */
 #undef BROKEN_GETADDRINFO
 
diff --git a/compat.c b/compat.c
index 0e12b77..49bc051 100644
--- a/compat.c
+++ b/compat.c
@@ -29,8 +29,8 @@
 #include "packet.h"
 #include "xmalloc.h"
 #include "compat.h"
-#ifdef HAVE_LIBRX
-#  include <rxposix.h>
+#ifdef HAVE_LIBPCRE
+#  include <pcreposix.h>
 #else /* Use native regex libraries */
 #  include <regex.h>
 #endif /* HAVE_LIBRX */
diff --git a/configure.in b/configure.in
index c859b66..1a57583 100644
--- a/configure.in
+++ b/configure.in
@@ -119,6 +119,13 @@
 	AC_DEFINE(PAM_TTY_KLUDGE)
 	inet6_default_4in6=yes
 	;;
+mips-sony-bsd|mips-sony-newsos4)
+	AC_DEFINE(HAVE_NEWS4)
+	SONY=1
+	AC_CHECK_LIB(iberty, xatexit, AC_DEFINE(HAVE_XATEXIT),
+		AC_MSG_ERROR([*** libiberty missing - please install first ***])
+        )
+	;;
 *-*-netbsd*)
 	need_dash_r=1
 	;;
@@ -257,7 +264,8 @@
 # Checks for libraries.
 AC_CHECK_LIB(z, deflate, ,AC_MSG_ERROR([*** zlib missing - please install first ***]))
 AC_CHECK_LIB(util, login, AC_DEFINE(HAVE_LIBUTIL_LOGIN) LIBS="$LIBS -lutil")
-AC_CHECK_LIB(rx, regcomp, AC_DEFINE(HAVE_LIBRX) LIBS="$LIBS -lrx")
+AC_CHECK_LIB(pcre, pcre_info, 
+	AC_DEFINE(HAVE_LIBPCRE) LIBS="$LIBS -lpcreposix -lpcre")
 
 if test -z "$no_libsocket" ; then
 	AC_CHECK_LIB(nsl, yp_match, , )
@@ -490,6 +498,11 @@
 	fi
 fi
 
+# Cheap hack to ensure NEWS-OS libraries are arranged right.
+if test ! -z "$SONY" ; then
+  LIBS="$LIBS -liberty";
+fi
+
 # Checks for data types
 AC_CHECK_SIZEOF(char, 1)
 AC_CHECK_SIZEOF(short int, 2)
diff --git a/defines.h b/defines.h
index 323ff29..79d98e2 100644
--- a/defines.h
+++ b/defines.h
@@ -354,6 +354,10 @@
 
 #if !defined(HAVE_ATEXIT) && defined(HAVE_ON_EXIT)
 # define atexit(a) on_exit(a)
+#else
+# if defined(HAVE_XATEXIT)
+#  define atexit(a) xatexit(a)
+# endif /* defined(HAVE_XATEXIT) */
 #endif /* !defined(HAVE_ATEXIT) && defined(HAVE_ON_EXIT) */
 
 #if defined(HAVE_VHANGUP) && !defined(BROKEN_VHANGUP)
diff --git a/includes.h b/includes.h
index 797c5e8..9160663 100644
--- a/includes.h
+++ b/includes.h
@@ -20,6 +20,7 @@
 #include "config.h"
 
 #include "next-posix.h"
+#include "news4-posix.h"
 
 #include <sys/types.h>
 #include <sys/socket.h>
diff --git a/news4-posix.c b/news4-posix.c
new file mode 100644
index 0000000..b1a289f
--- /dev/null
+++ b/news4-posix.c
@@ -0,0 +1,39 @@
+#include "config.h"
+
+#ifdef HAVE_NEWS4
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <sys/fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+#include <sys/file.h>
+#include <errno.h>
+#include <termios.h>
+#include <sys/wait.h>
+
+#include "xmalloc.h"
+#include "ssh.h"
+#include "news4-posix.h"
+
+int
+waitpid(int	pid, int	*stat_loc, int	options)
+{
+	if (pid <= 0) {
+		if (pid != -1) {
+			errno = EINVAL;
+			return -1;
+		}
+		pid = 0;	/* wait4() expects pid=0 for indiscriminate wait. */
+	}
+	return wait4(pid, (union wait *)stat_loc, options, NULL);
+}
+
+#endif /* HAVE_NEWS4 */
diff --git a/news4-posix.h b/news4-posix.h
new file mode 100644
index 0000000..8740679
--- /dev/null
+++ b/news4-posix.h
@@ -0,0 +1,35 @@
+/*
+ * Defines and prototypes specific to News4 system
+ */
+
+#ifndef _NEWS4_POSIX_H
+#define _NEWS4_POSIX_H
+
+#ifdef HAVE_NEWS4
+
+#include <sys/wait.h>
+
+typedef long	clock_t;
+
+/* FILE */
+#define O_NONBLOCK      00004   /* non-blocking open */
+
+/* WAITPID */
+#undef WIFEXITED
+#undef WIFSTOPPED
+#undef WIFSIGNALED
+
+#define _W_INT(w)	(*(int*)&(w))	/* convert union wait to int */
+#define WIFEXITED(w)	(!((_W_INT(w)) & 0377))
+#define WIFSTOPPED(w)	((_W_INT(w)) & 0100)
+#define WIFSIGNALED(w)	(!WIFEXITED(w) && !WIFSTOPPED(w))
+#define WEXITSTATUS(w)	(int)(WIFEXITED(w) ? ((_W_INT(w) >> 8) & 0377) : -1)
+#define WTERMSIG(w)	(int)(WIFSIGNALED(w) ? (_W_INT(w) & 0177) : -1)
+#define WCOREFLAG	0x80
+#define WCOREDUMP(w) 	((_W_INT(w)) & WCOREFLAG)
+
+int waitpid(int pid,int *stat_loc,int options);
+#define setsid() setpgrp(0, getpid())
+
+#endif /* HAVE_NEWS4 */
+#endif /* _NEWS4_POSIX_H */
diff --git a/pty.c b/pty.c
index cbbe584..04004d2 100644
--- a/pty.c
+++ b/pty.c
@@ -242,6 +242,10 @@
 	 */
 	ioctl(*ttyfd, TIOCSCTTY, NULL);
 #endif /* TIOCSCTTY */
+#ifdef HAVE_NEWS4
+	if (setpgrp(0,0) < 0)
+		error("SETPGRP %s",strerror(errno));
+#endif /* HAVE_NEWS4 */
 #ifdef USE_VHANGUP
 	old = signal(SIGHUP, SIG_IGN);
 	vhangup();