diff --git a/src/acconfig.h b/src/acconfig.h
deleted file mode 100644
index bc324d5..0000000
--- a/src/acconfig.h
+++ /dev/null
@@ -1,579 +0,0 @@
-/* Copyright (c) 1993-2000
- *      Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
- *      Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
- * Copyright (c) 1987 Oliver Laumann
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program (see the file COPYING); if not, see
- * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
- *
- ****************************************************************
- * $Id$ FAU
- */
-
-
-
-
-
-/**********************************************************************
- *
- *	User Configuration Section
- */
-
-/*
- * Maximum of simultaneously allowed windows per screen session.
- */
-#ifndef MAXWIN
-# define MAXWIN 40
-#endif
-
-/*
- * Define SOCKDIR to be the directory to contain the named sockets
- * screen creates. This should be in a common subdirectory, such as
- * /usr/local or /tmp. It makes things a little more secure if you
- * choose a directory which is not writable by everyone or where the
- * "sticky" bit is on, but this isn't required.
- * If SOCKDIR is not defined screen will put the named sockets in
- * the user's home directory. Notice that this can cause you problems
- * if some user's HOME directories are AFS- or NFS-mounted. Especially
- * AFS is unlikely to support named sockets.
- *
- * Screen will name the subdirectories "S-$USER" (e.g /tmp/S-davison).
- */
-#undef SOCKDIR
-
-/*
- * Define this if the SOCKDIR is not shared between hosts.
- */
-#define SOCKDIR_IS_LOCAL_TO_HOST
-
-/*
- * Screen can look for the environment variable $SYSSCREENRC and -if it
- * exists- load the file specified in that variable as global screenrc.
- * If you want to enable this feature, define ALLOW_SYSSCREENRC to one (1).
- * Otherwise ETCSCREENRC is always loaded.
- */
-#define ALLOW_SYSSCREENRC 1
-
-/*
- * Define CHECKLOGIN to force Screen users to enter their Unix password
- * in addition to the screen password.
- *
- * Define NOSYSLOG if yo do not have logging facilities. Currently
- * syslog() will be used to trace ``su'' commands only.
- */
-#define CHECKLOGIN 1
-#undef NOSYSLOG
-
-
-/* 
- * define PTYMODE if you do not like the default of 0622, which allows 
- * public write to your pty.
- * define PTYGROUP to some numerical group-id if you do not want the
- * tty to be in "your" group.
- * Note, screen is unable to change mode or group of the pty if it
- * is not installed with sufficient privilege. (e.g. set-uid-root)
- * define PTYROFS if the /dev/pty devices are mounted on a read-only 
- * filesystem so screen should not even attempt to set mode or group  
- * even if running as root (e.g. on TiVo).
- */
-#undef PTYMODE
-#undef PTYGROUP
-#undef PTYROFS
-
-/*
- * If screen is NOT installed set-uid root, screen can provide tty
- * security by exclusively locking the ptys.  While this keeps other
- * users from opening your ptys, it also keeps your own subprocesses
- * from being able to open /dev/tty.  Define LOCKPTY to add this
- * exclusive locking.
- */
-#undef LOCKPTY
-
-/*
- * If you'd rather see the status line on the first line of your
- * terminal rather than the last, define TOPSTAT.
- */
-#undef TOPSTAT
-
-/*
- * define DETACH can detach a session. An absolute 'must'.
- */
-#define DETACH
-
-/*
- * here come the erlangen extensions to screen:
- * define LOCK if you want to use a lock program for a screenlock.
- * define PASSWORD for secure reattach of your screen.
- * define COPY_PASTE to use the famous hacker's treasure zoo.
- * define POW_DETACH to have a detach_and_logout key (requires DETACH).
- * define REMOTE_DETACH (-d option) to move screen between terminals.
- * define AUTO_NUKE to enable Tim MacKenzies clear screen nuking
- * define PSEUDOS to allow window input/output filtering
- * define MULTI to allow multiple attaches.
- * define MULTIUSER to allow other users attach to your session
- *                  (if they are in the acl, of course)
- * define MAPKEYS to include input keyboard translation.
- * define FONT to support ISO2022/alternet charset support
- * define COLOR to include ansi color support. This may expose
- *        a bug in x11r6-color-xterm.
- * define DW_CHARS to include support for double-width character
- *        sets.
- * define ENCODINGS to include support for encodings like euc or big5.
- *        Needs FONT to work.
- * define UTF8 if you want support for UTF-8 encoding.
- *        Needs FONT and ENCODINGS to work.
- * define COLORS16 if you want 16 colors.
- *        Needs COLOR to work.
- * define BUILTIN_TELNET to add telnet support to screen.
- *        Syntax: screen //telnet host [port]
- * define RXVT_OSC if you want support for rxvts special
- *        change fgcolor/bgcolor/bgpicture sequences
- */
-#undef SIMPLESCREEN
-#ifndef SIMPLESCREEN
-# define LOCK
-# define PASSWORD
-# define COPY_PASTE
-# define REMOTE_DETACH
-# define POW_DETACH
-# define AUTO_NUKE
-# define PSEUDOS
-# define MULTI
-# define MULTIUSER
-# define MAPKEYS
-# define COLOR
-# define FONT
-# define DW_CHARS
-# define ENCODINGS
-# define UTF8
-# define COLORS16
-# define ZMODEM
-# define BLANKER_PRG
-#endif /* SIMPLESCREEN */
-
-#undef BUILTIN_TELNET
-#undef RXVT_OSC
-#undef COLORS256
-
-
-/*
- * If you have a braille display you should define HAVE_BRAILLE.
- * The code inside #ifdef HAVE_BRAILLE was contributed by Hadi Bargi
- * Rangin (bargi@dots.physics.orst.edu).
- * WARNING: this is more or less unsupported code, it may be full of
- * bugs leading to security holes, enable at your own risk!
- */
-#undef HAVE_BRAILLE
-
-
-/*
- * As error messages are mostly meaningless to the user, we
- * try to throw out phrases that are somewhat more familiar
- * to ...well, at least familiar to us NetHack players.
- */
-#ifndef NONETHACK
-# define NETHACK
-#endif /* NONETHACK */
-
-/*
- * If screen is installed with permissions to update /etc/utmp (such
- * as if it is installed set-uid root), define UTMPOK.
- */
-#define UTMPOK
-
-/* Set LOGINDEFAULT to one (1)
- * if you want entries added to /etc/utmp by default, else set it to
- * zero (0).
- * LOGINDEFAULT will be one (1) whenever LOGOUTOK is undefined!
- */
-#define LOGINDEFAULT	1
-
-/* Set LOGOUTOK to one (1)
- * if you want the user to be able to log her/his windows out.
- * (Meaning: They are there, but not visible in /etc/utmp).
- * Disabling this feature only makes sense if you have a secure /etc/utmp
- * database. 
- * Negative examples: suns usually have a world writable utmp file, 
- * xterm will run perfectly without s-bit.
- *
- * If LOGOUTOK is undefined and UTMPOK is defined, all windows are
- * initially and permanently logged in.
- *
- * Set CAREFULUTMP to one (1) if you want that users have at least one
- * window per screen session logged in.
- */
-#define LOGOUTOK 1
-#undef CAREFULUTMP
-
-
-/*
- * If UTMPOK is defined and your system (incorrectly) counts logins by
- * counting non-null entries in /etc/utmp (instead of counting non-null
- * entries with no hostname that are not on a pseudo tty), define USRLIMIT
- * to have screen put an upper-limit on the number of entries to write
- * into /etc/utmp.  This helps to keep you from exceeding a limited-user
- * license.
- */
-#undef USRLIMIT
-
-/*
- * both must be defined if you want to favor tcsendbreak over
- * other calls to generate a break condition on serial lines.
- * (Do not bother, if you are not using plain tty windows.)
- */
-#define POSIX_HAS_A_GOOD_TCSENDBREAK
-#define SUNOS4_AND_WE_TRUST_TCSENDBREAK
-
-/*
- * to lower the interrupt load on the host machine, you may want to
- * adjust the VMIN and VTIME settings used for plain tty windows.
- * See the termio(4) manual page (Non-Canonical Mode Input Processing)
- * for details.
- * if undefined, VMIN=1, VTIME=0 is used as a default - this gives you
- * best user responsiveness, but highest interrupt frequency.
- * (Do not bother, if you are not using plain tty windows.)
- */
-#define TTYVMIN 100
-#define TTYVTIME 2
-
-/*
- * looks like the above values are ignored by setting FNDELAY.
- * This is default for all pty/ttys, you may disable it for
- * ttys here. After playing with it for a while, one may find out
- * that this feature may cause screen to lock up.
- */
-#ifdef bsdi
-# define TTY_DISABLE_FNBLOCK /* select barfs without it ... */
-#endif
-
-
-/*
- * Some terminals, e.g. Wyse 120, use a bitfield to select attributes.
- * This doesn't work with the standard so/ul/m? terminal entries,
- * because they will cancel each other out. 
- * On TERMINFO machines, "sa" (sgr) may work. If you want screen
- * to switch attributes only with sgr, define USE_SGR.
- * This is *not* recomended, do this only if you must.
- */
-#undef USE_SGR
-
-
-/*
- * Define USE_LOCALE if you want screen to use the locale names
- * for the name of the month and day of the week.
- */
-#define USE_LOCALE
-
-/*
- * Define USE_PAM if your system supports PAM (Pluggable Authentication
- * Modules) and you want screen to use it instead of calling crypt().
- * (You may also need to add -lpam to LIBS in the Makefile.)
- */
-#undef USE_PAM
-
-/*
- * Define CHECK_SCREEN_W if you want screen to set TERM to screen-w
- * if the terminal width is greater than 131 columns. No longer needed
- * on modern systems which use $COLUMNS or the tty settings instead.
- */
-#undef CHECK_SCREEN_W
-
-/**********************************************************************
- *
- *	End of User Configuration Section
- *
- *      Rest of this file is modified by 'configure'
- *      Change at your own risk!
- *
- */
-
-/*
- * Some defines to identify special unix variants
- */
-#ifndef SVR4
-#undef SVR4
-#endif
-
-/* #ifndef __osf__ */
-#ifndef MIPS
-#undef MIPS
-#endif
-/* #endif */
-
-#ifndef OSX
-#undef OSX
-#endif
-
-#ifndef ISC
-#undef ISC
-#endif
-
-#ifndef sysV68
-#undef sysV68
-#endif
-
-#ifndef _POSIX_SOURCE
-#undef _POSIX_SOURCE
-#endif
-
-/*
- * Define POSIX if your system supports IEEE Std 1003.1-1988 (POSIX).
- */
-#undef POSIX
-
-/*
- * Define BSDJOBS if you have BSD-style job control (both process
- * groups and a tty that deals correctly with them).
- */
-#undef BSDJOBS
-
-/*
- * Define TERMIO if you have struct termio instead of struct sgttyb.
- * This is usually the case for SVID systems, where BSD uses sgttyb.
- * POSIX systems should define this anyway, even though they use
- * struct termios.
- */
-#undef TERMIO
-
-/*
- * Define CYTERMIO if you have cyrillic termio modes.
- */
-#undef CYTERMIO
-
-/*
- * Define TERMINFO if your machine emulates the termcap routines
- * with the terminfo database.
- * Thus the .screenrc file is parsed for
- * the command 'terminfo' and not 'termcap'.
- */
-#undef TERMINFO
-
-/*
- * If your library does not define ospeed, define this.
- */
-#undef NEED_OSPEED
-
-/*
- * Define SYSV if your machine is SYSV complient (Sys V, HPUX, A/UX)
- */
-#ifndef SYSV
-#undef SYSV
-#endif
-
-/*
- * Define SIGVOID if your signal handlers return void.  On older
- * systems, signal returns int, but on newer ones, it returns void.
- */
-#undef SIGVOID 
-
-/*
- * Define USESIGSET if you have sigset for BSD 4.1 reliable signals.
- */
-#undef USESIGSET
-
-/*
- * Define SYSVSIGS if signal handlers must be reinstalled after
- * they have been called.
- */
-#undef SYSVSIGS
-
-/*
- * Define BSDWAIT if your system defines a 'union wait' in <sys/wait.h>
- *
- * Only allow BSDWAIT i.e. wait3 on nonposix systems, since
- * posix implies wait(3) and waitpid(3). vdlinden@fwi.uva.nl
- * 
- */
-#ifndef POSIX
-#undef BSDWAIT
-#endif
-
-/*
- * On RISCOS we prefer wait2() over wait3(). rouilj@sni-usa.com 
- */
-#ifdef BSDWAIT
-#undef USE_WAIT2
-#endif
-
-/*
- * If your system has getutent(), pututline(), etc. to write to the
- * utmp file, define GETUTENT.
- */
-#undef GETUTENT
-
-/*
- * Define UTHOST if the utmp file has a host field.
- */
-#undef UTHOST
-
-/*
- * Define if you have the utempter utmp helper program
- */
-#undef HAVE_UTEMPTER
-
-/*
- * If ttyslot() breaks getlogin() by returning indexes to utmp entries
- * of type DEAD_PROCESS, then our getlogin() replacement should be
- * selected by defining BUGGYGETLOGIN.
- */
-#undef BUGGYGETLOGIN
-
-/*
- * If your system has the calls setreuid() and setregid(),
- * define HAVE_SETREUID. Otherwise screen will use a forked process to
- * safely create output files without retaining any special privileges.
- */
-#undef HAVE_SETRESUID
-#undef HAVE_SETREUID
-
-/*
- * If your system supports BSD4.4's seteuid() and setegid(), define
- * HAVE_SETEUID.
- */
-#undef HAVE_SETEUID
-
-/*
- * If you want the "time" command to display the current load average
- * define LOADAV. Maybe you must install screen with the needed
- * privileges to read /dev/kmem.
- * Note that NLIST_ stuff is only checked, when getloadavg() is not available.
- */
-#undef LOADAV
-
-#undef LOADAV_NUM
-#undef LOADAV_TYPE
-#undef LOADAV_SCALE
-#undef LOADAV_GETLOADAVG
-#undef LOADAV_UNIX
-#undef LOADAV_AVENRUN
-#undef LOADAV_USE_NLIST64
-
-#undef NLIST_DECLARED
-#undef NLIST_STRUCT
-#undef NLIST_NAME_UNION
-
-/*
- * If your system has the new format /etc/ttys (like 4.3 BSD) and the
- * getttyent(3) library functions, define GETTTYENT.
- */
-#undef GETTTYENT
-
-/*
- * Define USEBCOPY if the bcopy/memcpy from your system's C library
- * supports the overlapping of source and destination blocks.  When
- * undefined, screen uses its own (probably slower) version of bcopy().
- * 
- * SYSV machines may have a working memcpy() -- Oh, this is 
- * quite unlikely. Tell me if you see one.
- * "But then, memmove() should work, if at all available" he thought...
- * Boing, never say "works everywhere" unless you checked SCO UNIX.
- * Their memove fails the test in the configure script. Sigh. (Juergen)
- */
-#undef USEBCOPY
-#undef USEMEMCPY
-#undef USEMEMMOVE
-
-/*
- * If your system has vsprintf() and requires the use of the macros in
- * "varargs.h" to use functions with variable arguments,
- * define USEVARARGS.
- */
-#undef USEVARARGS
-
-/*
- * If the select return value doesn't treat a descriptor that is
- * usable for reading and writing as two hits, define SELECT_BROKEN.
- */
-#undef SELECT_BROKEN
-
-/*
- * Define this if your system supports named pipes.
- */
-#undef NAMEDPIPE
-
-/*
- * Define this if your system exits select() immediatly if a pipe is
- * opened read-only and no writer has opened it.
- */
-#undef BROKEN_PIPE
-
-/*
- * Define this if the unix-domain socket implementation doesn't
- * create a socket in the filesystem.
- */
-#undef SOCK_NOT_IN_FS
-
-/*
- * If your system has setenv() and unsetenv() define USESETENV
- */
-#undef USESETENV
-
-/*
- * If setenv() takes 3 arguments sefine HAVE_SETENV_3
- */
-#undef HAVE_SETENV_3
-
-/*
- * If setenv() takes 2 arguments sefine HAVE_SETENV_2
- */
-#undef HAVE_SETENV_2
-
-/*
- * If your system does not come with a setenv()/putenv()/getenv()
- * functions, you may bring in our own code by defining NEEDPUTENV.
- */
-#undef NEEDPUTENV
-
-/*
- * If the passwords are stored in a shadow file and you want the
- * builtin lock to work properly, define SHADOWPW.
- */
-#undef SHADOWPW
-
-/*
- * define HAVE_NL_LANGINFO if your system has the nl_langinfo() call
- * and <langinfo.h> defines CODESET.
- */
-#undef HAVE_NL_LANGINFO
-
-/*
- * Newer versions of Solaris include fdwalk, which can greatly improve
- * the startup time of screen; otherwise screen spends a lot of time
- * closing file descriptors.
- */
-#undef HAVE_FDWALK
-
-/*
- * define HAVE_DEV_PTC if you have a /dev/ptc character special
- * device.
- */
-#undef HAVE_DEV_PTC
-
-/*
- * define HAVE_SVR4_PTYS if you have a /dev/ptmx character special
- * device and support the ptsname(), grantpt(), unlockpt() functions.
- */
-#undef HAVE_SVR4_PTYS
-
-/* 
- * define PTYRANGE0 and or PTYRANGE1 if you want to adapt screen
- * to unusual environments. E.g. For SunOs the defaults are "qpr" and 
- * "0123456789abcdef". For SunOs 4.1.2 
- * #define PTYRANGE0 "pqrstuvwxyzPQRST" 
- * is recommended by Dan Jacobson.
- */
-#undef PTYRANGE0
-#undef PTYRANGE1
-
diff --git a/src/attacher.c b/src/attacher.c
index a416ec1..0712858 100644
--- a/src/attacher.c
+++ b/src/attacher.c
@@ -709,7 +709,7 @@ LockTerminal()
         Msg(errno, "Cannot lock terminal - fork failed");
       else
         {
-#ifdef BSDWAIT
+#ifndef HAVE_SYS_WAIT_H
           union wait wstat;
 #else
           int wstat;
diff --git a/src/configure.ac b/src/configure.ac
new file mode 100644
index 0000000..cfaf5de
--- /dev/null
+++ b/src/configure.ac
@@ -0,0 +1,1663 @@
+# Process this file with autoconf to produce a configure script.
+AC_INIT
+AC_PREREQ([2.64])dnl
+AC_REVISION($Revision$)dnl
+AC_USE_SYSTEM_EXTENSIONS
+AC_CONFIG_SRCDIR([screen.c])
+AC_CONFIG_HEADER(config.h)
+
+AC_DEFINE(MAXWIN, 40, [Maximum of simultaneously allowed windows per screen session.])
+AC_DEFINE(SOCKDIR_IS_LOCAL_TO_HOST,,[Define this if the SOCKDIR is not shared between hosts.])
+AC_DEFINE(ALLOW_SYSSCREENRC,1,[
+Screen can look for the environment variable $SYSSCREENRC and -if it
+exists- load the file specified in that variable as global screenrc.
+If you want to enable this feature, define ALLOW_SYSSCREENRC to one (1).
+Otherwise ETCSCREENRC is always loaded.
+])
+AC_DEFINE(CHECKLOGIN,1,[
+Define CHECKLOGIN to force Screen users to enter their Unix password
+in addition to the screen password.
+])
+AH_TEMPLATE([NOSYSLOG],[
+	Define NOSYSLOG if yo do not have logging facilities. Currently
+	syslog() will be used to trace ``su'' commands only.
+	])
+AH_TEMPLATE([PTYMODE],[
+	 define PTYMODE if you do not like the default of 0622, which allows 
+	 public write to your pty.
+	 ])
+AH_TEMPLATE([PTYGROUP],[
+	 define PTYGROUP to some numerical group-id if you do not want the
+	 tty to be in "your" group.
+	 Note, screen is unable to change mode or group of the pty if it
+	 is not installed with sufficient privilege. (e.g. set-uid-root)
+	 ])
+
+AC_DEFINE([DETACH],,[
+	define DETACH can detach a session. An absolute 'must'.
+	])
+
+AC_DEFINE([UTMPOK],,[
+	If screen is installed with permissions to update /etc/utmp (such
+	as if it is installed set-uid root), define UTMPOK.
+	])
+
+AH_TEMPLATE([NETHACK],[
+	As error messages are mostly meaningless to the user, we
+	try to throw out phrases that are somewhat more familiar
+	to ...well, at least familiar to us NetHack players.
+	])
+
+AH_TEMPLATE([CAREFULUTMP],[
+	Set CAREFULUTMP to one (1) if you want that users have at least one
+	window per screen session logged in.
+	])
+
+AC_DEFINE([LOGINDEFAULT],[1],[
+	Set LOGINDEFAULT to one (1)
+	if you want entries added to /etc/utmp by default, else set it to
+	zero (0).
+	LOGINDEFAULT will be one (1) whenever LOGOUTOK is undefined!
+	])
+
+AC_DEFINE([LOGOUTOK],[1],[
+	Set LOGOUTOK to one (1)
+	if you want the user to be able to log her/his windows out.
+	(Meaning: They are there, but not visible in /etc/utmp).
+	Disabling this feature only makes sense if you have a secure /etc/utmp
+	database. 
+	Negative examples: suns usually have a world writable utmp file, 
+	xterm will run perfectly without s-bit.
+
+	If LOGOUTOK is undefined and UTMPOK is defined, all windows are
+	initially and permanently logged in.
+	])
+
+AC_DEFINE([USE_LOCALE],,[
+	Define USE_LOCALE if you want screen to use the locale names
+	for the name of the month and day of the week.
+	])
+ 
+AH_TEMPLATE([USE_PAM],[
+	Define USE_PAM if your system supports PAM (Pluggable Authentication
+	Modules) and you want screen to use it instead of calling crypt().
+	(You may also need to add -lpam to LIBS in the Makefile.)
+	])
+
+
+AH_TEMPLATE([POSIX],[
+	Define POSIX if your system supports IEEE Std 1003.1-1988 (POSIX).
+	])
+
+AH_TEMPLATE([BSDJOBS],[
+	Define BSDJOBS if you have BSD-style job control (both process
+	groups and a tty that deals correctly with them).
+	])
+
+AH_TEMPLATE([TERMIO],[
+	Define TERMIO if you have struct termio instead of struct sgttyb.
+	This is usually the case for SVID systems, where BSD uses sgttyb.
+	POSIX systems should define this anyway, even though they use
+	struct termios.
+	])
+
+AH_TEMPLATE([CYTERMIO],[
+	Define CYTERMIO if you have cyrillic termio modes.
+	])
+
+AH_TEMPLATE([TERMINFO],[
+	Define TERMINFO if your machine emulates the termcap routines
+	with the terminfo database.
+	Thus the .screenrc file is parsed for
+	the command 'terminfo' and not 'termcap'.
+	])
+
+AH_TEMPLATE([NEED_OSPEED],[
+	If your library does not define ospeed, define this.
+	])
+
+AH_TEMPLATE([USESIGSET],[
+	Define USESIGSET if you have sigset for BSD 4.1 reliable signals.
+	])
+
+AH_TEMPLATE([SYSVSIGS],[
+	Define SYSVSIGS if signal handlers must be reinstalled after
+	they have been called.
+	])
+
+AH_TEMPLATE([HAVE_GETUTENT],[
+	If your system has getutent(), pututline(), etc. to write to the
+	utmp file, define HAVE_GETUTENT.
+	])
+
+AH_TEMPLATE([HAVE_STRUCT_UTMP_UT_HOST],[
+	Define HAVE_STRUCT_UTMP_UT_HOST if the utmp file has a host field.
+	])
+
+AH_TEMPLATE([HAVE_UTEMPTER],[
+	Define if you have the utempter utmp helper program
+	])
+
+AH_TEMPLATE([SVR4],[
+	If ttyslot() breaks getlogin() by returning indexes to utmp entries
+	of type DEAD_PROCESS, as it does on SVR4, then our getlogin() 
+	replacement is used.
+	])
+
+AH_TEMPLATE([HAVE_SETEUID],[
+	If your system supports BSD4.4's seteuid() and setegid(), define
+	HAVE_SETEUID.
+	])
+
+AH_TEMPLATE([GETTTYENT],[
+	If your system has the new format /etc/ttys (like 4.3 BSD) and the
+	getttyent(3) library functions, define GETTTYENT.
+	])
+
+AH_TEMPLATE([USEVARARGS],[
+	If your system has vsprintf() and requires the use of the macros in
+	"varargs.h" to use functions with variable arguments,
+	define USEVARARGS.
+	])
+
+AH_TEMPLATE([SELECT_BROKEN],[
+	If the select return value doesn't treat a descriptor that is
+	usable for reading and writing as two hits, define SELECT_BROKEN.
+	])
+
+AH_TEMPLATE([NAMEDPIPE],[
+	Define this if your system supports named pipes.
+	])
+
+AH_TEMPLATE([BROKEN_PIPE],[
+	Define this if your system exits select() immediatly if a pipe is
+	opened read-only and no writer has opened it.
+	])
+
+AH_TEMPLATE([SOCK_NOT_IN_FS],[
+	Define this if the unix-domain socket implementation doesn't
+	create a socket in the filesystem.
+	])
+
+AH_TEMPLATE([USESETENV],[
+	If your system has setenv() and unsetenv() define USESETENV
+	])
+
+AH_TEMPLATE([HAVE_SETENV_3],[
+	If setenv() takes 3 arguments sefine HAVE_SETENV_3
+	])
+
+AH_TEMPLATE([HAVE_SETENV_2],[
+	If setenv() takes 2 arguments sefine HAVE_SETENV_2
+	])
+
+AH_TEMPLATE([NEEDPUTENV],[
+	If your system does not come with a setenv()/putenv()/getenv()
+	functions, you may bring in our own code by defining NEEDPUTENV.
+	])
+
+AH_TEMPLATE([SHADOWPW],[
+	If the passwords are stored in a shadow file and you want the
+	builtin lock to work properly, define SHADOWPW.
+	])
+
+AH_TEMPLATE([HAVE_NL_LANGINFO],[
+	define HAVE_NL_LANGINFO if your system has the nl_langinfo() call
+	and <langinfo.h> defines CODESET.
+	])
+
+AH_TEMPLATE([HAVE_FDWALK],[
+	Newer versions of Solaris include fdwalk, which can greatly improve
+	the startup time of screen; otherwise screen spends a lot of time
+	closing file descriptors.
+	])
+
+AH_TEMPLATE([HAVE_DEV_PTC],[
+	define HAVE_DEV_PTC if you have a /dev/ptc character special
+	device.
+	])
+
+AH_TEMPLATE([HAVE_SVR4_PTYS],[
+	define HAVE_SVR4_PTYS if you have a /dev/ptmx character special
+	device and support the ptsname(), grantpt(), unlockpt() functions.
+	])
+
+AH_TEMPLATE([USEBCOPY],[
+	Define USEBCOPY if the bcopy/memcpy from your system's C library
+	supports the overlapping of source and destination blocks.  When
+	undefined, screen uses its own (probably slower) version of bcopy().
+	])
+AH_TEMPLATE([USEMEMCPY],[
+	SYSV machines may have a working memcpy() -- Oh, this is 
+	quite unlikely. Tell me if you see one.
+	])
+AH_TEMPLATE([USEMEMMOVE],[
+	"But then, memmove() should work, if at all available" he thought...
+	Boing, never say "works everywhere" unless you checked SCO UNIX.
+
+	Their memove fails the test in the configure script. Sigh. (Juergen)
+	])
+
+AH_TEMPLATE([PTYRANGE0],[
+	define PTYRANGE0 and or PTYRANGE1 if you want to adapt screen
+	to unusual environments. E.g. For SunOs the defaults are "qpr" and 
+	"0123456789abcdef". For SunOs 4.1.2 
+	#define PTYRANGE0 "pqrstuvwxyzPQRST" 
+	is recommended by Dan Jacobson.
+	])
+AH_TEMPLATE([PTYRANGE1])
+
+AH_TEMPLATE([HAVE_SETRESUID],[[
+	If your system has the calls setreuid() and setregid(),
+	define HAVE_SETREUID. Otherwise screen will use a forked process to
+	safely create output files without retaining any special privileges.
+	]])
+AH_TEMPLATE([HAVE_SETREUID])
+
+AH_TEMPLATE([POSIX_HAS_A_GOOD_TCSENDBREAK],[
+	Both
+	POSIX_HAS_A_GOOD_TCSENDBREAK and
+	SUNOS4_AND_WE_TRUST_TCSENDBREAK
+	must be defined if you want to favor tcsendbreak over
+	other calls to generate a break condition on serial lines.
+	(Don't bother, if you are not using plain tty windows.)
+	])
+AH_TEMPLATE([SUNOS4_AND_WE_TRUST_TCSENDBREAK],[
+	Both
+	POSIX_HAS_A_GOOD_TCSENDBREAK and
+	SUNOS4_AND_WE_TRUST_TCSENDBREAK
+	must be defined if you want to favor tcsendbreak over
+	other calls to generate a break condition on serial lines.
+	(Don't bother, if you are not using plain tty windows.)
+	])
+AC_DEFINE([POSIX_HAS_A_GOOD_TCSENDBREAK])
+AC_DEFINE([SUNOS4_AND_WE_TRUST_TCSENDBREAK])
+
+
+AC_DEFINE([TTYVMIN], [100],[
+	to lower the interrupt load on the host machine, you may want to
+	adjust the VMIN and VTIME settings used for plain tty windows.
+	See the termio(4) manual page (Non-Canonical Mode Input Processing)
+	for details.
+	if undefined, VMIN=1, VTIME=0 is used as a default - this gives you
+	best user responsiveness, but highest interrupt frequency.
+	(Do not bother, if you are not using plain tty windows.)
+	])
+AC_DEFINE([TTYVTIME],[2],[
+	to lower the interrupt load on the host machine, you may want to
+	adjust the VMIN and VTIME settings used for plain tty windows.
+	See the termio(4) manual page (Non-Canonical Mode Input Processing)
+	for details.
+	if undefined, VMIN=1, VTIME=0 is used as a default - this gives you
+	best user responsiveness, but highest interrupt frequency.
+	(Do not bother, if you are not using plain tty windows.)
+	])
+
+AH_TEMPLATE([LOADAV],[
+	If you want the "time" command to display the current load average
+	define LOADAV. Maybe you must install screen with the needed
+	privileges to read /dev/kmem.
+	])
+AH_TEMPLATE([LOADAV_NUM],[
+	If you want the "time" command to display the current load average
+	define LOADAV. Maybe you must install screen with the needed
+	privileges to read /dev/kmem.
+	])
+AH_TEMPLATE([LOADAV_TYPE],[
+	If you want the "time" command to display the current load average
+	define LOADAV. Maybe you must install screen with the needed
+	privileges to read /dev/kmem.
+	])
+AH_TEMPLATE([LOADAV_SCALE],[
+	If you want the "time" command to display the current load average
+	define LOADAV. Maybe you must install screen with the needed
+	privileges to read /dev/kmem.
+	])
+AH_TEMPLATE([LOADAV_GETLOADAVG],[
+	If you want the "time" command to display the current load average
+	define LOADAV. Maybe you must install screen with the needed
+	privileges to read /dev/kmem.
+	])
+AH_TEMPLATE([LOADAV_UNIX],[
+	If you want the "time" command to display the current load average
+	define LOADAV. Maybe you must install screen with the needed
+	privileges to read /dev/kmem.
+	])
+AH_TEMPLATE([LOADAV_AVENRUN],[
+	If you want the "time" command to display the current load average
+	define LOADAV. Maybe you must install screen with the needed
+	privileges to read /dev/kmem.
+	])
+AH_TEMPLATE([LOADAV_USE_NLIST64],[
+	If you want the "time" command to display the current load average
+	define LOADAV. Maybe you must install screen with the needed
+	privileges to read /dev/kmem.
+	])
+
+AH_TEMPLATE([NLIST_DECLARED],[
+	Note that NLIST_ stuff is only checked, when getloadavg() is not available.
+	])
+AH_TEMPLATE([NLIST_STRUCT])
+AH_TEMPLATE([NLIST_NAME_UNION])
+
+AH_TEMPLATE([USE_WAIT2],[
+	On RISCOS we prefer wait2() over wait3(). rouilj@sni-usa.com 
+])
+
+AH_TEMPLATE([SYSV],[
+	Define SYSV if your machine is SYSV complient (Sys V, HPUX, A/UX)
+])
+
+AH_TEMPLATE([_POSIX_SOURCE],[
+	A define to identify a special unix variant
+])
+AH_TEMPLATE([SVR4],[
+	A define to identify a special unix variant
+])
+AH_TEMPLATE([MIPS],[
+	A define to identify a special unix variant
+])
+AH_TEMPLATE([OSX],[
+	A define to identify a special unix variant
+])
+AH_TEMPLATE([ISC],[
+	A define to identify a special unix variant
+])
+AH_TEMPLATE([sysV68],[
+	A define to identify a special unix variant
+])
+# 
+# Define some useful macros
+# 
+AC_DEFUN([AC_PROGRAM_SOURCE],
+[AC_REQUIRE([AC_PROG_CPP])AC_PROVIDE([$0])cat > conftest.c <<EOF
+#include "confdefs.h"
+[$1]
+_CUT_HERE_
+[$2]
+EOF
+eval "$ac_cpp conftest.c 2>&5 | sed -e '1,/_CUT_HERE_/d' -e 's/ //g' > conftest.out"
+. ./conftest.out
+rm -f conftest*
+])dnl
+# 
+define(AC_NOTE,
+[echo "$1" 1>&AS_MESSAGE_FD
+])dnl
+
+# 
+# Extract version from patchlevel.h
+# 
+rev=`sed < ${srcdir}/patchlevel.h -n -e '/#define REV/s/#define REV  *//p'`
+vers=`sed < ${srcdir}/patchlevel.h -n -e '/#define VERS/s/#define VERS  *//p'`
+pat=`sed < ${srcdir}/patchlevel.h -n -e '/#define PATCHLEVEL/s/#define PATCHLEVEL  *//p'`
+VERSION="$rev.$vers.$pat"
+AC_NOTE(this is screen version $VERSION)
+AC_SUBST(VERSION)
+AC_PREFIX_PROGRAM(screen)
+AC_PREFIX_PROGRAM(gzip)
+
+old_CFLAGS="$CFLAGS"
+AC_PROG_CC
+AC_PROG_CPP
+AC_PROG_GCC_TRADITIONAL
+AC_SEARCH_LIBS([strerror],[cposix])
+
+AC_RUN_IFELSE([AC_LANG_SOURCE([[main(){return(0);}]])],,[
+if test $CC != cc ; then
+AC_NOTE(Your $CC failed - restarting with CC=cc)
+AC_NOTE()
+CC=cc
+export CC
+exec $0 $configure_args
+fi
+])
+
+AC_RUN_IFELSE([AC_LANG_SOURCE([[main(){return(0);}]])],,[exec 5>&2
+eval $ac_link
+AC_NOTE(CC=$CC; CFLAGS=$CFLAGS; LIBS=$LIBS;)
+AC_NOTE($ac_compile)
+AC_MSG_ERROR(cannot run the compiler - sorry)])
+
+AC_RUN_IFELSE([AC_LANG_SOURCE([[
+main()
+{
+  int __something_strange_();
+  __something_strange_(0);
+}
+]])],[AC_MSG_ERROR(Your compiler does not set the exit status - sorry)])
+
+AC_PROG_AWK
+
+AC_PROG_INSTALL
+
+if test -f etc/toolcheck; then
+AC_MSG_NOTICE([checking for buggy tools...])
+sh etc/toolcheck 1>&AS_MESSAGE_FD
+fi
+
+
+
+# SOCKDIR
+AH_TEMPLATE([SOCKDIR],[
+Define SOCKDIR to be the directory to contain the named sockets
+screen creates. This should be in a common subdirectory, such as
+/usr/local or /tmp. It makes things a little more secure if you
+choose a directory which is not writable by everyone or where the
+"sticky" bit is on, but this isn't required.
+If SOCKDIR is not defined screen will put the named sockets in
+the user's home directory. Notice that this can cause you problems
+if some user's HOME directories are AFS- or NFS-mounted. Especially
+AFS is unlikely to support named sockets.
+
+Screen will name the subdirectories "S-$USER" (e.g /tmp/S-davison).
+])
+AC_MSG_CHECKING(if a system-wide socket dir should be used) 
+AC_ARG_ENABLE(socket-dir,
+AS_HELP_STRING([--enable-socket-dir=path],[where to put the per-user sockets])
+AS_HELP_STRING([--disable-socket-dir],[disable system wide socket-dir and use ~/.screen instead]),[sockdir="${enableval}"],[sockdir=yes])
+AS_IF([test x"$sockdir" = xno],[
+	AC_MSG_RESULT(no.  ~/.screen will be used instead.)]
+,
+	AS_IF([test x"$sockdir" = xyes],
+		AC_DEFINE_UNQUOTED(SOCKDIR,
+			[(eff_uid ? "/tmp/uscreens" : "/tmp/screens")])
+		,
+		AC_DEFINE_UNQUOTED(SOCKDIR, 
+			[${sockdir}]))
+	AC_MSG_RESULT(["${sockdir}"]))
+
+# 
+#    ****  special unix variants  ****
+# 
+AC_CHECK_DECL([bsdi],
+AC_DEFINE(TTY_DISABLE_FNBLOCK,,[select barfs without it ...]))
+
+if test -n "$ISC"; then
+  AC_DEFINE(ISC) LIBS="$LIBS -linet"
+fi
+
+if test -f /sysV68 ; then
+AC_DEFINE(sysV68)
+fi
+
+AC_MSG_NOTICE([checking for MIPS...])
+if test -f /lib/libmld.a || test -f /usr/lib/libmld.a || test -f /usr/lib/cmplrs/cc/libmld.a; then
+oldlibs="$LIBS"
+test -f /bin/mx || LIBS="$LIBS -lmld" # for nlist. But not on alpha.
+# djm@eng.umd.edu: "... for one thing, it doubles the size of the executable"
+AC_MSG_NOTICE([checking mld library...])
+AC_LINK_IFELSE([AC_LANG_PROGRAM(, )],,[LIBS="$oldlibs"])
+# 
+# 
+if test -r /dev/ptc; then
+AC_DEFINE(MIPS)
+AC_MSG_NOTICE([checking wait3...])
+AC_LINK_IFELSE([AC_LANG_PROGRAM(,[[wait3();]])],[ ],[
+AC_MSG_NOTICE([checking wait2...])
+AC_LINK_IFELSE([AC_LANG_PROGRAM(,[[wait2();]])],
+# John Rouillard (rouilj@sni-usa.com):
+# need -I/usr/include/bsd in RISCOS otherwise sockets are broken, no
+# job control etc.
+# Detect RISCOS if wait2 is present, but not wait3.
+AC_DEFINE(USE_WAIT2) LIBS="$LIBS -lbsd" ; CC="$CC -I/usr/include/bsd"
+)])
+fi
+fi
+
+if test -f /usr/lib/libpyr.a ; then
+oldlibs="$LIBS"
+LIBS="$LIBS -lpyr"
+AC_MSG_NOTICE([checking Pyramid OSX...])
+AC_LINK_IFELSE([AC_LANG_PROGRAM(, [[open_controlling_pty("")]])],[AC_DEFINE(OSX)],[LIBS="$oldlibs"])
+fi
+
+AC_MSG_NOTICE([checking for POSIX.1...])
+AC_CHECK_DECL([_POSIX_VERSION],
+	AC_NOTE(- you have a POSIX system) AC_DEFINE(POSIX) posix=1)
+
+AC_MSG_CHECKING([for System V])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+#include <signal.h>
+#include <fcntl.h>]], [[int x = SIGCHLD | FNDELAY;]])],
+[AC_MSG_RESULT(no)],
+[AC_DEFINE(SYSV) AC_MSG_RESULT(yes)])
+
+AC_MSG_NOTICE([checking for sequent/ptx...])
+AC_CHECK_DECL([_SEQUENT_],
+	LIBS="$LIBS -lsocket -linet";seqptx=1)
+
+oldlibs="$LIBS"
+LIBS="$LIBS -lelf"
+
+AC_MSG_CHECKING([SVR4])
+AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <utmpx.h>]])],[
+	AC_CHECK_HEADER(dwarf.h, AC_DEFINE(SVR4) AC_MSG_RESULT(yes),[
+	 AC_CHECK_HEADER(elf.h, AC_DEFINE(SVR4) AC_MSG_RESULT(yes))])
+	],[LIBS="$oldlibs"; AC_MSG_RESULT(no) ])
+
+AC_CHECK_HEADERS([stropts.h string.h strings.h])
+
+AC_MSG_CHECKING([for Solaris 2.x])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
+     [[#if !defined(SVR4) || !defined(sun)
+      error: This is not Solaris 2.x
+     #endif
+     ]])],
+     [AC_MSG_RESULT(yes); LIBS="$LIBS -lsocket -lnsl -lkstat"],
+     [AC_MSG_RESULT(no)])
+
+# 
+#   ****     Job control     ****
+# 
+AC_CHECK_FUNC(setpgrp)
+
+AC_MSG_CHECKING([BSD job jontrol])
+AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+#include <sys/ioctl.h>
+]], [[
+#ifdef POSIX
+tcsetpgrp(0, 0);
+#else
+int x = TIOCSPGRP;
+#ifdef SYSV
+setpgrp();
+#else
+int y = TIOCNOTTY;
+#endif
+#endif
+]])],[AC_MSG_RESULT(you have jobcontrol); AC_DEFINE(BSDJOBS)],[AC_MSG_RESULT(you don't have jobcontrol)])
+
+# 
+#    ****  setresuid(), setreuid(), seteuid()  ****
+# 
+AC_CHECK_FUNCS(setresuid setreuid)
+# 
+# seteuid() check:
+#   linux seteuid was broken before V1.1.11
+#   NeXT, AUX, ISC, and ultrix are still broken (no saved uid support)
+#   Solaris seteuid doesn't change the saved uid, bad for
+#     multiuser screen sessions
+AC_MSG_CHECKING([seteuid])
+AC_LINK_IFELSE([AC_LANG_PROGRAM(, [[
+#if defined(linux) || defined(NeXT) || defined(_AUX_SOURCE) || defined(AUX) || defined(ultrix) || (defined(sun) && defined(SVR4)) || defined(ISC) || defined(sony_news)
+seteuid_is_broken(0);
+#else
+seteuid(0);
+#endif
+]])],
+[AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SETEUID)],
+[AC_MSG_RESULT(no)])
+
+# 
+#    ****  select()  ****
+# 
+AC_MSG_CHECKING([select])
+AC_LINK_IFELSE([AC_LANG_PROGRAM(,[[select(0, 0, 0, 0, 0);]])],
+[AC_MSG_RESULT(yes)],
+[AC_MSG_RESULT(maybe); LIBS="$LIBS -lnet -lnsl"
+AC_MSG_CHECKING([select with $LIBS])
+AC_LINK_IFELSE([AC_LANG_PROGRAM(, [[select(0, 0, 0, 0, 0);]])],
+[AC_MSG_RESULT(yes)],[AC_MSG_ERROR(!!! no select - no screen)])
+])
+
+# 
+#    ****  FIFO tests  ****
+# 
+AC_MSG_CHECKING([fifos])
+AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#ifdef POSIX
+/* For select - According to POSIX 1003.1-2001 */
+#include <sys/select.h>
+#else
+/* For select - According to earlier standards */
+#include <sys/time.h>
+#endif
+
+#ifndef O_NONBLOCK
+#define O_NONBLOCK O_NDELAY
+#endif
+#ifndef S_IFIFO
+#define S_IFIFO 0010000
+#endif
+
+char *fin = "/tmp/conftest$$";
+
+main()
+{
+  struct stat stb;
+  fd_set f;
+
+  (void)alarm(5);
+  unlink(fin);
+#ifdef POSIX
+  if (mkfifo(fin, 0777))
+#else
+  if (mknod(fin, S_IFIFO|0777, 0))
+#endif
+    return(1);
+  if (stat(fin, &stb) || (stb.st_mode & S_IFIFO) != S_IFIFO)
+    return(1);
+  close(0);
+#ifdef __386BSD__
+  /*
+   * The next test fails under 386BSD, but screen works using fifos.
+   * Fifos in O_RDWR mode are only used for the BROKEN_PIPE case and for
+   * the select() configuration test.
+   */
+  return(0);
+#endif
+  if (open(fin, O_RDONLY | O_NONBLOCK))
+    return(1);
+  if (fork() == 0)
+    {
+      close(0);
+      if (open(fin, O_WRONLY | O_NONBLOCK))
+	return(1);
+      close(0);
+      if (open(fin, O_WRONLY | O_NONBLOCK))
+	return(1);
+      if (write(0, "TEST", 4) == -1)
+	return(1);
+      return(0);
+    }
+  FD_SET(0, &f);
+  if (select(1, &f, 0, 0, 0) == -1)
+    return(1);
+  return(0);
+}
+]])],[AC_MSG_RESULT(your fifos are usable); fifo=1],[AC_MSG_RESULT(your fifos are not usable)])
+rm -f /tmp/conftest*
+
+if test -n "$fifo"; then
+AC_MSG_CHECKING([for broken fifo implementation])
+AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#ifdef POSIX
+/* For select - According to POSIX 1003.1-2001 */
+#include <sys/select.h>
+#else
+/* For select - According to earlier standards */
+#include <sys/time.h>
+#endif
+
+#ifndef O_NONBLOCK
+#define O_NONBLOCK O_NDELAY
+#endif
+#ifndef S_IFIFO
+#define S_IFIFO 0010000
+#endif
+
+char *fin = "/tmp/conftest$$";
+
+main()
+{
+  struct timeval tv;
+  fd_set f;
+
+#ifdef POSIX
+  if (mkfifo(fin, 0600))
+#else
+  if (mknod(fin, S_IFIFO|0600, 0))
+#endif
+    return(1);
+  close(0);
+  if (open(fin, O_RDONLY|O_NONBLOCK))
+    return(1);
+  FD_SET(0, &f);
+  tv.tv_sec = 1;
+  tv.tv_usec = 0;
+  if (select(1, &f, 0, 0, &tv))
+    return(1);
+  return(0);
+}
+]])],[AC_MSG_RESULT(your implementation is ok)],[AC_MSG_RESULT(you have a broken implementation); AC_DEFINE(BROKEN_PIPE) fifobr=1])
+rm -f /tmp/conftest*
+fi
+
+# 
+#    ****  SOCKET tests  ****
+# 
+# 	may need  	LIBS="$LIBS -lsocket" 	here
+# 
+AC_CHECK_HEADERS([sys/uio.h])
+
+AC_MSG_CHECKING([sockets])
+AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#include <sys/types.h>
+/* For select - According to POSIX 1003.1-2001 */
+#include <sys/select.h>
+/* For select - According to earlier standards */
+#include <sys/time.h>
+#include <unistd.h>
+
+#include <sys/stat.h>
+#include <fcntl.h>
+
+
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include <sys/socket.h>
+#include <sys/un.h>
+char *son = "/tmp/conftest$$";
+
+main()
+{
+  int s1, s2, l;
+  struct sockaddr_un a;
+  fd_set f;
+
+  (void)alarm(5);
+  if ((s1 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+    return(1);
+  a.sun_family = AF_UNIX;
+  strcpy(a.sun_path, son);
+  (void) unlink(son);
+  if (bind(s1, (struct sockaddr *) &a, strlen(son)+2) == -1)
+    return(1);
+  if (listen(s1, 2))
+    return(1);
+  if (fork() == 0)
+    {
+      if ((s2 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+	kill(getppid(), 3);
+      (void)connect(s2, (struct sockaddr *)&a, strlen(son) + 2);
+      if (write(s2, "HELLO", 5) == -1)
+	kill(getppid(), 3);
+      return(0);
+    }
+  l = sizeof(a);
+  close(0);
+  if (accept(s1, &a, &l))
+    return(1);
+  FD_SET(0, &f);
+  if (select(1, &f, 0, 0, 0) == -1)
+    return(1);
+  return(0);
+}
+]])],
+[AC_MSG_RESULT(your sockets are usable); sock=1],
+[AC_MSG_RESULT(your sockets are not usable)])
+rm -f /tmp/conftest*
+
+if test -n "$sock"; then
+AC_MSG_CHECKING([socket implementation])
+AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#include <sys/types.h>
+/* For select - According to POSIX 1003.1-2001 */
+#include <sys/select.h>
+/* For select - According to earlier standards */
+#include <sys/time.h>
+#include <unistd.h>
+
+#include <sys/stat.h>
+#include <fcntl.h>
+
+
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include <sys/socket.h>
+#include <sys/un.h>
+
+char *son = "/tmp/conftest$$";
+
+main()
+{
+  int s;
+  struct stat stb;
+  struct sockaddr_un a;
+  if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+    return(0);
+  a.sun_family = AF_UNIX;
+  strcpy(a.sun_path, son);
+  (void) unlink(son);
+  if (bind(s, (struct sockaddr *) &a, strlen(son)+2) == -1)
+    return(0);
+  if (stat(son, &stb))
+    return(1);
+  close(s);
+  return(0);
+}
+]])],[AC_MSG_RESULT(you are normal)],[AC_MSG_RESULT(unix domain sockets are not kept in the filesystem)
+AC_DEFINE(SOCK_NOT_IN_FS) socknofs=1])
+rm -f /tmp/conftest*
+fi
+
+
+# 
+#    ****  choose sockets or fifos  ****
+# 
+if test -n "$fifo"; then
+  if test -n "$sock"; then
+    if test -n "$nore"; then
+      AC_NOTE(- hmmm... better take the fifos)
+      AC_DEFINE(NAMEDPIPE)
+    elif test -n "$fifobr"; then
+      AC_NOTE(- as your fifos are broken lets use the sockets.)
+    else
+      AC_NOTE(- both sockets and fifos usable. let's take sockets.)
+    fi
+  else
+    AC_NOTE(- using named pipes, of course)
+    AC_DEFINE(NAMEDPIPE)
+  fi
+elif test -n "$sock"; then
+  AC_NOTE(- using unix-domain sockets, of course)
+else
+  AC_MSG_ERROR(you have neither usable sockets nor usable pipes -> no screen)
+fi
+
+# 
+#    ****  check the select implementation ****
+# 
+AC_MSG_CHECKING([select return value])
+AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#include <sys/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+char *nam = "/tmp/conftest$$";
+
+#ifdef NAMEDPIPE
+
+#ifndef O_NONBLOCK
+#define O_NONBLOCK O_NDELAY
+#endif
+#ifndef S_IFIFO
+#define S_IFIFO 0010000
+#endif
+
+
+main()
+{
+  fd_set f;
+
+#ifdef __FreeBSD__
+/* From Andrew A. Chernov (ache@astral.msk.su):
+ * opening RDWR fifo fails in BSD 4.4, but select return values are
+ * right.
+ */
+  return(0);
+#endif
+  (void)alarm(5);
+#ifdef POSIX
+  if (mkfifo(nam, 0777))
+#else
+  if (mknod(nam, S_IFIFO|0777, 0))
+#endif
+    return(1);
+  close(0);
+  if (open(nam, O_RDWR | O_NONBLOCK))
+    return(1);
+  if (write(0, "TEST", 4) == -1)
+    return(1);
+
+#else
+
+#include <sys/socket.h>
+#include <sys/un.h>
+
+main()
+{
+  int s1, s2, l;
+  struct sockaddr_un a;
+  fd_set f;
+
+  (void)alarm(5);
+  if ((s1 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+    return(1);
+  a.sun_family = AF_UNIX;
+  strcpy(a.sun_path, nam);
+  (void) unlink(nam);
+  if (bind(s1, (struct sockaddr *) &a, strlen(nam)+2) == -1)
+    return(1);
+  if (listen(s1, 2))
+    return(1);
+  if (fork() == 0)
+    {
+      if ((s2 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+	kill(getppid(), 3);
+      (void)connect(s2, (struct sockaddr *)&a, strlen(nam) + 2);
+      if (write(s2, "HELLO", 5) == -1)
+	kill(getppid(), 3);
+      return(0);
+    }
+  l = sizeof(a);
+  close(0);
+  if (accept(s1, (struct sockaddr *)&a, &l))
+    return(1);
+#endif
+
+
+  FD_SET(0, &f);
+  if (select(1, &f, 0, 0, 0) == -1)
+    return(1);
+  if (select(1, &f, &f, 0, 0) != 2)
+    return(1);
+  return(0);
+}
+/* } to confort emacs paren matching */
+]])],[AC_MSG_RESULT(select is ok)],[AC_MSG_RESULT(select cannot count); AC_DEFINE(SELECT_BROKEN)])
+
+# 
+#    ****  termcap or terminfo  ****
+# 
+AC_MSG_NOTICE([checking for tgetent...])
+AC_LINK_IFELSE([AC_LANG_PROGRAM(,[[tgetent((char *)0, (char *)0);]])],,[
+olibs="$LIBS"
+LIBS="-lcurses $olibs"
+AC_MSG_NOTICE([checking libcurses...])
+AC_LINK_IFELSE([AC_LANG_PROGRAM(,[[
+#ifdef __hpux
+__sorry_hpux_libcurses_is_totally_broken_in_10_10();
+#else
+tgetent((char *)0, (char *)0);
+#endif
+]])],,[
+LIBS="-ltermcap $olibs"
+AC_MSG_NOTICE([checking libtermcap...])
+AC_LINK_IFELSE([AC_LANG_PROGRAM(,[[tgetent((char *)0, (char *)0);]])],,[
+LIBS="-ltermlib $olibs"
+AC_MSG_NOTICE([checking libtermlib...])
+AC_LINK_IFELSE([AC_LANG_PROGRAM(,[[tgetent((char *)0, (char *)0);]])],,[
+LIBS="-lncursesw $olibs"
+AC_MSG_NOTICE([checking libncursesw...])
+AC_LINK_IFELSE([AC_LANG_PROGRAM(,[[tgetent((char *)0, (char *)0);]])],,[
+LIBS="-lncurses $olibs"
+AC_MSG_NOTICE([checking libncurses...])
+AC_LINK_IFELSE([AC_LANG_PROGRAM(,[[tgetent((char *)0, (char *)0);]])],,[
+AC_MSG_ERROR(!!! no tgetent - no screen)])])])])])])
+
+AC_RUN_IFELSE([AC_LANG_SOURCE([[
+main()
+{
+ char *tgoto(const char *, int, int);
+ return(strcmp(tgoto("%p1%d", 0, 1), "1") ? 0 : 1);
+}]])],[AC_NOTE(- you use the termcap database)],[AC_NOTE(- you use the terminfo database) AC_DEFINE(TERMINFO)])
+AC_MSG_NOTICE([checking ospeed...])
+AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern short ospeed;]], [[ospeed=5;]])],,[AC_DEFINE(NEED_OSPEED)])
+
+# 
+#    ****  PTY specific things  ****
+# 
+AC_MSG_NOTICE([checking for /dev/ptc...])
+if test -r /dev/ptc; then
+AC_DEFINE(HAVE_DEV_PTC)
+fi
+
+AC_MSG_NOTICE([checking for SVR4 ptys...])
+sysvr4ptys=
+if test -c /dev/ptmx ; then
+AC_LINK_IFELSE([AC_LANG_PROGRAM(, [[ptsname(0);grantpt(0);unlockpt(0);]])],[AC_DEFINE(HAVE_SVR4_PTYS)
+sysvr4ptys=1])
+fi
+
+AC_CHECK_FUNCS(getpt)
+
+# check for openpty()
+if test -z "$sysvr4ptys"; then
+AC_CHECK_FUNCS(openpty,,
+[AC_CHECK_LIB(util,openpty, [AC_DEFINE(HAVE_OPENPTY)] [LIBS="$LIBS -lutil"])])
+fi
+
+AC_MSG_NOTICE([checking for ptyranges...])
+if test -d /dev/ptym ; then
+pdir='/dev/ptym'
+else
+pdir='/dev'
+fi
+# SCO uses ptyp%d
+AC_EGREP_CPP(yes,
+[#ifdef M_UNIX
+   yes;
+#endif
+], ptys=`echo /dev/ptyp??`, ptys=`echo $pdir/pty??`)
+if test "$ptys" != "$pdir/pty??" ; then
+p0=`echo $ptys | tr ' ' '\012' | sed -e 's/^.*\(.\).$/\1/g' | sort -u | tr -d '\012'`
+p1=`echo $ptys | tr ' ' '\012' | sed -e 's/^.*\(.\)$/\1/g'  | sort -u | tr -d '\012'`
+AC_DEFINE_UNQUOTED(PTYRANGE0,"$p0")
+AC_DEFINE_UNQUOTED(PTYRANGE1,"$p1")
+fi
+
+#    ****  pty mode/group handling ****
+# 
+# support provided by Luke Mewburn <lm@rmit.edu.au>, 931222
+AC_ARG_WITH(pty-mode, [  --with-pty-mode=mode    default mode for ptys], [ ptymode="${withval}" ])
+AC_ARG_WITH(pty-group, [  --with-pty-group=group  default group for ptys], [ ptygrp="${withval}" ])
+test -n "$ptymode" || ptymode=0620
+if test -n "$ptygrp" ; then
+AC_DEFINE_UNQUOTED(PTYMODE, $ptymode)
+AC_DEFINE_UNQUOTED(PTYGROUP,$ptygrp)
+else
+
+AC_MSG_NOTICE([checking default tty permissions/group...])
+rm -f conftest_grp
+AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#include <stdio.h>
+main()
+{
+  struct stat sb;
+  char *x,*ttyname();
+  int om, m;
+  FILE *fp;
+
+  if (!(x = ttyname(0))) return(1);
+  if (stat(x, &sb)) return(1);
+  om = sb.st_mode;
+  if (om & 002) return(0);
+  m = system("mesg y");
+  if (m == -1 || m == 127) return(1);
+  if (stat(x, &sb)) return(1);
+  m = sb.st_mode;
+  if (chmod(x, om)) return(1);
+  if (m & 002) return(0);
+  if (sb.st_gid == getgid()) return(1);
+  if (!(fp=fopen("conftest_grp", "w")))
+    return(1);
+  fprintf(fp, "%d\n", sb.st_gid);
+  fclose(fp);
+  return(0);
+}
+]])],[
+    if test -f conftest_grp; then
+	ptygrp=`cat conftest_grp`
+	AC_NOTE([- pty mode: $ptymode, group: $ptygrp])
+	AC_DEFINE_UNQUOTED(PTYMODE, $ptymode)
+	AC_DEFINE_UNQUOTED(PTYGROUP,$ptygrp)
+    else
+	AC_NOTE(- ptys are world accessable)
+    fi
+],[
+    WRITEPATH=''
+    XTERMPATH=''
+    AC_PATH_PROG(WRITEPATH, write)
+    AC_PATH_PROG(XTERMPATH, xterm)
+    found=
+    if test -n "$WRITEPATH$XTERMPATH"; then
+      findfollow=
+      lsfollow=
+      found=`find $WRITEPATH $XTERMPATH -follow -print 2>/dev/null`
+      if test -n "$found"; then
+	findfollow=-follow
+	lsfollow=L
+      fi
+      if test -n "$XTERMPATH"; then
+	ptygrpn=`ls -l$lsfollow $XTERMPATH | sed -n -e 1p | $AWK '{print $4}'`
+	if test tty != "$ptygrpn"; then
+	  XTERMPATH=
+	fi
+      fi
+    fi
+    if test -n "$WRITEPATH$XTERMPATH"; then
+      found=`find $WRITEPATH $XTERMPATH $findfollow -perm -2000 -print` 
+      if test -n "$found"; then
+	ptygrp=`ls -ln$lsfollow $found | sed -n -e 1p | $AWK '{print $4}'`
+	AC_NOTE([- pty mode: $ptymode, group: $ptygrp])
+	AC_DEFINE_UNQUOTED(PTYMODE, $ptymode)
+	AC_DEFINE_UNQUOTED(PTYGROUP,$ptygrp)
+      else
+	AC_NOTE(- ptys are world accessable)
+      fi
+    else
+      AC_NOTE(- cannot determine - assume ptys are world accessable)
+    fi
+  
+])
+rm -f conftest_grp
+fi
+
+# 
+#    ****  utmp handling  ****
+# 
+
+AC_CHECK_DECL([__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__],[
+# Mac OS X 10.5 still has utmp.h, but they warn it's deprecated
+	AC_DEFINE(_UTMPX_COMPAT,,[Turn on Mac OS X 10.5 UTMP compatibility])
+	AC_CHECK_HEADERS(utmpx.h)
+],[
+	AC_CHECK_HEADERS(utmp.h utmpx.h)
+])
+
+AC_CHECK_DECL([HAVE_UTMP_H],[
+	AC_SEARCH_LIBS(getutent,[gen])
+	AC_CHECK_FUNCS(getutent)
+],[
+	AC_CHECK_DECL([HAVE_UTMPX_H],[
+		AC_CHECK_FUNCS(getutxent,[AC_DEFINE([HAVE_GETUTENT])])
+	])
+])
+
+
+AC_CHECK_MEMBERS([struct utmp.ut_host])
+
+AC_CHECK_HEADER(utempter.h, have_utempter=yes, have_utempter=no)
+if test "$have_utempter" = yes; then
+  AC_DEFINE(HAVE_UTEMPTER)
+  LIBS="$LIBS -lutempter"
+fi
+
+# 
+#    ****  loadav  ****
+# 
+AC_MSG_NOTICE([checking for libutil(s)...])
+test -f /usr/lib/libutils.a && LIBS="$LIBS -lutils"
+test -f /usr/lib/libutil.a && LIBS="$LIBS -lutil"
+
+AC_MSG_NOTICE([checking getloadavg...])
+AC_LINK_IFELSE([AC_LANG_PROGRAM(AC_INCLUDES_DEFAULT,[[getloadavg((double *)0, 0);]])],[
+AC_DEFINE(LOADAV_GETLOADAVG) load=1,
+if test -f /usr/lib/libkvm.a ; then
+olibs="$LIBS"
+LIBS="$LIBS -lkvm"
+AC_MSG_NOTICE([checking getloadavg with -lkvm...])
+AC_LINK_IFELSE([AC_LANG_PROGRAM(AC_INCLUDES_DEFAULT, [[getloadavg((double *)0, 0);]])],[AC_DEFINE(LOADAV_GETLOADAVG) load=1],[LIBS="$olibs"])
+fi
+])
+
+if test -z "$load" ; then
+AC_EGREP_CPP(yes,
+[#if defined(NeXT) || defined(apollo) || defined(linux)
+  yes;
+#endif
+], load=1)
+fi
+if test -z "$load" ; then
+AC_MSG_NOTICE([checking for kernelfile...])
+for core in /unix /vmunix /dynix /hp-ux /xelos /dev/ksyms /kernel/unix /kernel/genunix /unicos /mach /netbsd /386bsd /dgux /bsd /stand/vmunix; do
+  if test -f $core || test -c $core; then
+    break
+  fi
+done
+if test ! -f $core && test ! -c $core ; then
+  AC_NOTE(- no kernelfile found)
+else
+  AC_NOTE(- using kernelfile '$core')
+  if test -r $core ; then
+  AC_DEFINE_UNQUOTED(LOADAV_UNIX,"$core")
+  AC_CHECK_HEADER(nlist.h,
+    [AC_DEFINE(NLIST_STRUCT)
+     AC_MSG_NOTICE([checking n_un in struct nlist...])
+     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <nlist.h>]], [[struct nlist n; n.n_un.n_name = 0;]])],[AC_DEFINE(NLIST_NAME_UNION)])])
+
+  AC_MSG_NOTICE([checking for nlist declaration...])
+  AC_EGREP_CPP([nlist(( |	)( |	)*.*\(|\()],[
+#ifdef NLIST_STRUCT
+# include <nlist.h>
+#else
+# include <a.out.h>
+#endif
+],AC_DEFINE(NLIST_DECLARED))
+
+  AC_MSG_NOTICE([checking for avenrun symbol...])
+  nlist64=
+  for av in avenrun _avenrun _Loadavg avenrun _avenrun _Loadavg; do
+  AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#ifdef NLIST_STRUCT
+#include <nlist.h>
+#else
+#include <a.out.h>
+#endif
+
+$nlist64
+
+struct nlist nl[2];
+
+main()
+{
+#if !defined(_AUX_SOURCE) && !defined(AUX)
+# ifdef NLIST_NAME_UNION
+  nl[0].n_un.n_name = "$av";
+# else
+  nl[0].n_name = "$av";
+# endif
+#else
+  strncpy(nl[0].n_name, "$av", sizeof(nl[0].n_name));
+#endif
+  nlist(LOADAV_UNIX, nl);
+  if (nl[0].n_value == 0)
+    return(1);
+  return(0);
+}
+  ]])],[avensym=$av;break])
+  if test "$av" = _Loadavg; then
+    nlist64='#define nlist nlist64'
+  fi
+  done
+  if test -z "$avensym" ; then
+    AC_NOTE(- no avenrun symbol found)
+  else
+    AC_NOTE(- using avenrun symbol '$avensym')
+    AC_DEFINE_UNQUOTED(LOADAV_AVENRUN,"$avensym")
+    if test -n "$nlist64"; then
+      AC_NOTE(- used nlist64 to find it)
+      AC_DEFINE(LOADAV_USE_NLIST64)
+    fi
+    load=1
+  fi
+  else
+    AC_NOTE(  cannot configure the load average display feature)
+    AC_NOTE(  because $core is not readable by you.)
+    AC_NOTE(  To configure the load average display feature)
+    AC_NOTE(  re-run configure as root if possible.)
+    AC_NOTE(  If you are not the system administrator then disregard)
+    AC_NOTE(  this warning.  You can still use screen without)
+    AC_NOTE(  the load average display feature.)
+  fi
+fi
+fi
+
+AC_PROGRAM_SOURCE([
+#include <sys/param.h>
+],[
+#if !defined(LOADAV_GETLOADAVG) && ((defined(hp300) && !defined(__hpux)) || defined(sun) || (defined(ultrix) && defined(mips)) || defined(_SEQUENT_) || defined(sgi) || (defined(SVR4) && !defined(__hpux)) || defined(sony_news) || (!defined(__osf__) && defined(__alpha)) || defined(_IBMR2) || defined(_AUX_SOURCE) || defined(AUX) || defined(m88k))
+loadtype=long
+# if defined(apollo) || defined(_IBMR2) || defined(_AUX_SOURCE) || defined(AUX)
+loadscale=65536
+# else
+#  if defined(FSCALE) && !defined(__osf__)
+#   undef FSCALE
+loadscale=FSCALE
+#  else
+#   ifdef sgi
+loadtype=int
+loadscale=1024
+#   else
+#    if defined(MIPS) || defined(SVR4) || defined(m88k)
+loadscale=256
+#    else /* not MIPS */
+loadscale=1000 	/* our default value */
+#    endif /* MIPS */
+#   endif /* sgi */
+#  endif /* not FSCALE */
+# endif /* not apollo */
+#else
+loadtype=double
+loadscale=1
+#endif
+#ifdef alliant
+loadnum=4
+#else
+loadnum=3
+#endif
+])
+
+if test -n "$load" ; then AC_DEFINE(LOADAV) fi
+if test -n "$loadtype" ; then AC_DEFINE_UNQUOTED(LOADAV_TYPE,$loadtype) fi
+if test -n "$loadnum" ; then AC_DEFINE_UNQUOTED(LOADAV_NUM,$loadnum) fi
+if test -n "$loadscale" ; then AC_DEFINE_UNQUOTED(LOADAV_SCALE,$loadscale) fi
+
+# 
+#    ****  signal handling  ****
+# 
+AC_TYPE_SIGNAL
+if test -n "$posix" ; then
+
+# POSIX has reliable signals with void return type.
+AC_NOTE(assuming posix signal definition)
+
+else
+
+AC_MSG_NOTICE([checking sigset...])
+AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+#include <signal.h>
+]], [[
+sigset(0, (RETSIGTYPE (*)())0);
+]])],[AC_DEFINE(USESIGSET)])
+AC_MSG_NOTICE([checking signal implementation...])
+AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#include <signal.h>
+
+#ifndef SIGCLD
+#define SIGCLD SIGCHLD
+#endif
+#ifdef USESIGSET
+#define signal sigset
+#endif
+
+int got;
+
+RETSIGTYPE
+hand()
+{
+  got++;
+}
+
+main()
+{
+  /* on hpux we use sigvec to get bsd signals */
+#ifdef __hpux
+  (void)signal(SIGCLD, hand);
+  kill(getpid(), SIGCLD);
+  kill(getpid(), SIGCLD);
+  if (got < 2)
+    return(1);
+#endif
+  return(0);
+}
+]])],,[AC_DEFINE(SYSVSIGS)])
+
+fi
+
+# 
+#    ****  libraries  ****
+# 
+
+AC_MSG_NOTICE([checking for crypt and sec libraries...])
+test -f /lib/libcrypt_d.a || test -f /usr/lib/libcrypt_d.a && LIBS="$LIBS -lcrypt_d"
+oldlibs="$LIBS"
+LIBS="$LIBS -lcrypt"
+AC_MSG_NOTICE([checking crypt...])
+AC_LINK_IFELSE([AC_LANG_PROGRAM(, )],,[LIBS="$oldlibs"])
+test -f /lib/libsec.a || test -f /usr/lib/libsec.a && LIBS="$LIBS -lsec"
+test -f /lib/libshadow.a || test -f /usr/lib/libshadow.a && LIBS="$LIBS -lshadow"
+oldlibs="$LIBS"
+LIBS="$LIBS -lsun"
+AC_MSG_NOTICE([checking IRIX sun library...])
+AC_LINK_IFELSE([AC_LANG_PROGRAM(, )],,[LIBS="$oldlibs"])
+
+AC_MSG_NOTICE([checking syslog...])
+AC_LINK_IFELSE([AC_LANG_PROGRAM(,[[closelog();]])], , [oldlibs="$LIBS"
+LIBS="$LIBS -lbsd"
+AC_MSG_NOTICE([checking syslog in libbsd.a...])
+AC_LINK_IFELSE([AC_LANG_PROGRAM(, [[closelog();]])],[AC_NOTE(- found.)],[LIBS="$oldlibs"
+AC_NOTE(- bad news: syslog missing.) AC_DEFINE(NOSYSLOG)])])
+
+AC_EGREP_CPP(yes,
+[#ifdef M_UNIX
+   yes;
+#endif
+], LIBS="$LIBS -lsocket -lcrypt_i")
+
+# 
+#    ****  misc things  ****
+# 
+AC_HEADER_SYS_WAIT
+
+AC_MSG_NOTICE([checking for termio or termios...])
+AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <termio.h>]])],[AC_DEFINE(TERMIO)],[
+if test -n "$posix"; then
+AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <termios.h>]])],[AC_DEFINE(TERMIO)])
+fi
+])
+
+# AC_CHECK_HEADER(shadow.h, AC_DEFINE(SHADOWPW))
+AC_MSG_NOTICE([checking getspnam...])
+AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <shadow.h>]], [[getspnam("x");]])],[AC_DEFINE(SHADOWPW)])
+
+AC_MSG_NOTICE([checking getttyent...])
+AC_LINK_IFELSE([AC_LANG_PROGRAM(, [[getttyent();]])],[AC_DEFINE(GETTTYENT)])
+
+AC_MSG_NOTICE([checking fdwalk...])
+AC_LINK_IFELSE([AC_LANG_PROGRAM(, [[fdwalk(NULL, NULL);]])],[AC_DEFINE(HAVE_FDWALK)])
+
+AC_MSG_NOTICE([checking whether memcpy/memmove/bcopy handles overlapping arguments...])
+AC_RUN_IFELSE([AC_LANG_SOURCE([[
+main() {
+  char buf[10];
+  strcpy(buf, "abcdefghi");
+  bcopy(buf, buf + 2, 3);
+  if (strncmp(buf, "ababcf", 6))
+    return(1);
+  strcpy(buf, "abcdefghi");
+  bcopy(buf + 2, buf, 3);
+  if (strncmp(buf, "cdedef", 6))
+    return(1);
+  return(0); /* libc version works properly.  */
+}]])],[AC_DEFINE(USEBCOPY)])
+
+AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#define bcopy(s,d,l) memmove(d,s,l)
+main() {
+  char buf[10];
+  strcpy(buf, "abcdefghi");
+  bcopy(buf, buf + 2, 3);
+  if (strncmp(buf, "ababcf", 6))
+    return(1);
+  strcpy(buf, "abcdefghi");
+  bcopy(buf + 2, buf, 3);
+  if (strncmp(buf, "cdedef", 6))
+    return(1);
+  return(0); /* libc version works properly.  */
+}]])],[AC_DEFINE(USEMEMMOVE)])
+
+
+AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#define bcopy(s,d,l) memcpy(d,s,l)
+main() {
+  char buf[10];
+  strcpy(buf, "abcdefghi");
+  bcopy(buf, buf + 2, 3);
+  if (strncmp(buf, "ababcf", 6))
+    return(1);
+  strcpy(buf, "abcdefghi");
+  bcopy(buf + 2, buf, 3);
+  if (strncmp(buf, "cdedef", 6))
+    return(1);
+  return(0); /* libc version works properly.  */
+}]])],[AC_DEFINE(USEMEMCPY)])
+
+AC_SYS_LONG_FILE_NAMES
+
+AC_MSG_CHECKING(for vsprintf)
+AC_LINK_IFELSE([AC_LANG_PROGRAM(, [[vsprintf(0,0,0);]])],[AC_MSG_RESULT(yes);AC_DEFINE(USEVARARGS)],[AC_MSG_RESULT(no)])
+
+AC_HEADER_DIRENT
+
+AC_MSG_CHECKING(for setenv)
+if test -z "$ac_setenv_args"; then
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [[
+        setenv((char *) 0, (char *) 0, 0);
+    ]])],[ac_setenv_args=3])
+fi
+if test -z "$ac_setenv_args"; then
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [[
+        setenv((char *) 0, (char *) 0);
+    ]])],[ac_setenv_args=2])
+fi
+if test -n "$ac_setenv_args"; then
+    AC_DEFINE(USESETENV)
+    if test "$ac_setenv_args" = 3; then
+        AC_DEFINE(HAVE_SETENV_3)
+    elif test "$ac_setenv_args" = 2; then
+        AC_DEFINE(HAVE_SETENV_2)
+    fi
+else
+    AC_MSG_RESULT(no)
+    AC_MSG_CHECKING(for putenv)
+    AC_LINK_IFELSE([AC_LANG_PROGRAM(, [[putenv((char *)0);unsetenv((char *)0);]])],[AC_MSG_RESULT(yes) ],[AC_MSG_RESULT(no);AC_DEFINE(NEEDPUTENV)])
+fi
+
+AC_MSG_CHECKING([for nl_langinfo(CODESET)])
+AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+#include <langinfo.h>
+]], [[nl_langinfo(CODESET);]])],
+[AC_MSG_RESULT(yes);AC_DEFINE(HAVE_NL_LANGINFO)],
+[AC_MSG_RESULT(no)])
+
+AC_SEARCH_LIBS(gethostname, nsl)
+
+AC_CHECK_FUNCS(rename fchmod fchown strerror lstat _exit utimes vsnprintf getcwd setlocale strftime)
+
+AC_ARG_ENABLE(pam,AS_HELP_STRING([--enable-pam],[enable PAM support]))
+if test "$enable_pam" = "yes"; then
+    AC_MSG_CHECKING(for PAM support)
+    oldlibs="$LIBS"
+    LIBS="$LIBS -lpam"
+    AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <security/pam_appl.h>]], [[
+	pam_start(0, 0, 0, 0);
+	pam_authenticate(0, 0);
+	pam_end(0,0);
+    ]])],[AC_MSG_RESULT(yes);AC_DEFINE(USE_PAM)],[AC_MSG_RESULT(no);LIBS="$oldlibs"])
+fi
+
+AC_ARG_ENABLE(use_locale, [  --enable-locale         use localized month/day names])
+if test "$enable_use_locale" = "yes"; then
+  AC_DEFINE(USE_LOCALE)
+fi
+
+AC_DEFUN([MY_ARG_ENABLE],
+            [AH_TEMPLATE([$1],[define $1 $2])
+	     AC_ARG_ENABLE(m4_translit([[$1]], [_A-Z], [-a-z]),
+               [AS_HELP_STRING([--enable-m4_translit([$1], [_A-Z], [-a-z])],
+                               [enable $2])],
+	       AS_IF([test x"${enableval}" != xno ],[AC_DEFINE($1)]))])
+
+MY_ARG_ENABLE([BUILTIN_TELNET],[
+	to add builtin telnet support to screen.
+	Syntax: screen //telnet host [port]
+	])
+MY_ARG_ENABLE([RXVT_OSC],[
+	if you want support for rxvt's special
+	       change fgcolor/bgcolor/bgpicture sequences
+	       (OSC codes)
+	])
+MY_ARG_ENABLE([COLORS256],[for support for 256 colors])
+MY_ARG_ENABLE([MULTI],[to allow multiple attaches.])
+MY_ARG_ENABLE([PTYROFS],[
+	 if the /dev/pty devices are mounted on a read-only 
+	 filesystem so screen should not even attempt to set mode or group  
+	 even if running as root (e.g. on TiVo).
+	 ],)
+MY_ARG_ENABLE([LOCKPTY],[
+	to add this exclusive locking:
+	If screen is NOT installed set-uid root, screen can provide tty
+	security by exclusively locking the ptys.  While this keeps other
+	users from opening your ptys, it also keeps your own subprocesses
+	from being able to open /dev/tty.
+	])
+MY_ARG_ENABLE([TOPSTAT],[
+	if you'd rather see the status line on the first line of your
+	terminal rather than the last.
+	])
+MY_ARG_ENABLE([LOCK],[
+	if you want to use a lock program for a screenlock.
+	])
+MY_ARG_ENABLE([PASSWORD],[
+	for secure reattach of your screen.
+	])
+MY_ARG_ENABLE([COPY_PASTE],[
+	to use the famous hacker's treasure zoo.
+	])
+MY_ARG_ENABLE([REMOTE_DETACH],[
+	(-d option) to move screen between terminals.
+	])
+MY_ARG_ENABLE([POW_DETACH],[
+	to have a detach_and_logout key (requires DETACH).
+	])
+MY_ARG_ENABLE([AUTO_NUKE],[
+	to enable Tim MacKenzies clear screen nuking
+	])
+MY_ARG_ENABLE([PSEUDOS],[
+	to allow window input/output filtering
+	])
+MY_ARG_ENABLE([MULTIUSER],[
+	to allow other users attach to your session
+	(if they are in the acl, of course)
+	])
+MY_ARG_ENABLE([MAPKEYS],[
+	to include input keyboard translation.
+	])
+MY_ARG_ENABLE([FONT],[
+	to support ISO2022/alternet charset support
+	])
+MY_ARG_ENABLE([COLOR],[
+	to include ansi color support. This may expose
+	a bug in x11r6-color-xterm.
+	])
+MY_ARG_ENABLE([DW_CHARS],[
+	to include support for double-width character
+	sets.
+	])
+MY_ARG_ENABLE([ENCODINGS],[
+	to include support for encodings like euc or big5.
+	Needs FONT to work.
+	])
+MY_ARG_ENABLE([UTF8],[
+	if you want support for UTF-8 encoding.
+	Needs FONT and ENCODINGS to work.
+	])
+MY_ARG_ENABLE([COLORS16],[
+	if you want 16 colors.
+	Needs COLOR to work.
+	])
+MY_ARG_ENABLE([ZMODEM],[for built-in ZMODEM support])
+MY_ARG_ENABLE([BLANKER_PRG],[for external screen blanking support])
+MY_ARG_ENABLE([HAVE_BRAILLE],[
+	if you have a braille display.
+	The code inside #ifdef HAVE_BRAILLE was contributed by Hadi Bargi
+	Rangin (bargi@dots.physics.orst.edu).
+	WARNING: this is more or less unsupported code, it may be full of
+	bugs leading to security holes, enable at your own risk!
+	])
+MY_ARG_ENABLE([USRLIMIT],[
+	if UTMPOK is defined and your system (incorrectly) counts logins by
+	counting non-null entries in /etc/utmp (instead of counting non-null
+	entries with no hostname that are not on a pseudo tty), so as
+	to have screen put an upper-limit on the number of entries to write
+	into /etc/utmp.  This helps to keep you from exceeding a limited-user
+	license.
+	])
+MY_ARG_ENABLE([USE_SGR],[
+	if you want screen
+	to switch attributes only with sgr.
+	Some terminals, e.g. Wyse 120, use a bitfield to select attributes.
+	This doesn't work with the standard so/ul/m? terminal entries,
+	because they will cancel each other out. 
+	On TERMINFO machines, "sa" (sgr) may work. 
+	This is *not* recomended, do this only if you must.
+	])
+MY_ARG_ENABLE([CHECK_SCREEN_W],[
+	if you want screen to set TERM to screen-w
+	if the terminal width is greater than 131 columns. No longer needed
+	on modern systems which use $COLUMNS or the tty settings instead.
+	])
+
+
+
+# 
+#    ****  the end  ****
+# 
+if test -z "$old_CFLAGS"; then
+  if test "x$CFLAGS" = "x-g"; then
+    CFLAGS="-O"
+  fi
+fi
+# Ptx bug workaround -- insert -lc after -ltermcap
+test -n "$seqptx" && LIBS="-ltermcap -lc -lsocket -linet -lnsl -lsec -lseq"
+
+AC_RUN_IFELSE([AC_LANG_SOURCE([[main(){return(0);}]])],,[AC_MSG_ERROR(cannot run the compiler - internal error. Sorry.)])
+
+AC_CONFIG_FILES([Makefile doc/Makefile])
+AC_CONFIG_COMMANDS([default],[[
+# a hook for preserving undef directive in config.h
+mv config.h conftest
+sed -e 's@^\(.*\)defin.\( .*\) .*/\*\(.*KEEP_UNDEF_HERE\)@\1undef\2	/\*\3@' < conftest > config.h
+rm -f conftest
+]])
+AC_OUTPUT
+
+echo ""
+if test -z "$AWK"; then
+echo "!!! Since you have no awk you must copy the files 'comm.h.dist'"
+echo "!!! and 'term.h.dist' to 'comm.h' and 'term.h'."
+echo "!!! Do _not_ change the user configuration section in config.h!"
+echo "Please check the pathnames in the Makefile."
+else
+echo "Now please check the pathnames in the Makefile and in the user"
+echo "configuration section in config.h."
+fi
+echo "Then type 'make' to make screen. Good luck."
+echo ""
diff --git a/src/configure.in b/src/configure.in
deleted file mode 100644
index 9db3dd6..0000000
--- a/src/configure.in
+++ /dev/null
@@ -1,1309 +0,0 @@
-dnl Process this file with autoconf to produce a configure script.
-dnl
-dnl $Id$ FAU
-dnl
-dnl Many thanks to David MacKenzie for writing autoconf and
-dnl providing a sample configure.in file for screen.
-dnl
-AC_REVISION($Revision$)dnl
-AC_INIT(screen.c)
-AC_CONFIG_HEADER(config.h)
-
-dnl
-dnl Define some useful macros
-dnl
-AC_DEFUN([AC_PROGRAM_SOURCE],
-[AC_REQUIRE([AC_PROG_CPP])AC_PROVIDE([$0])cat > conftest.c <<EOF
-#include "confdefs.h"
-[$1]
-_CUT_HERE_
-[$2]
-EOF
-eval "$ac_cpp conftest.c 2>&5 | sed -e '1,/_CUT_HERE_/d' -e 's/ //g' > conftest.out"
-. ./conftest.out
-rm -f conftest*
-])dnl
-dnl
-define(AC_NOTE,
-[echo "$1" 1>&AC_FD_MSG
-])dnl
-
-dnl
-dnl Extract version from patchlevel.h
-dnl
-rev=`sed < ${srcdir}/patchlevel.h -n -e '/#define REV/s/#define REV  *//p'`
-vers=`sed < ${srcdir}/patchlevel.h -n -e '/#define VERS/s/#define VERS  *//p'`
-pat=`sed < ${srcdir}/patchlevel.h -n -e '/#define PATCHLEVEL/s/#define PATCHLEVEL  *//p'`
-VERSION="$rev.$vers.$pat"
-AC_NOTE(this is screen version $VERSION)
-AC_SUBST(VERSION)
-AC_PREFIX_PROGRAM(screen)
-AC_PREFIX_PROGRAM(gzip)
-
-old_CFLAGS="$CFLAGS"
-AC_PROG_CC
-AC_PROG_CPP
-AC_PROG_GCC_TRADITIONAL
-AC_ISC_POSIX
-AC_USE_SYSTEM_EXTENSIONS
-
-AC_TRY_RUN(main(){exit(0);},,[
-if test $CC != cc ; then
-AC_NOTE(Your $CC failed - restarting with CC=cc)
-AC_NOTE()
-CC=cc
-export CC
-exec $0 $configure_args
-fi
-])
-
-AC_TRY_RUN(main(){exit(0);},,
-exec 5>&2
-eval $ac_link
-AC_NOTE(CC=$CC; CFLAGS=$CFLAGS; LIBS=$LIBS;)
-AC_NOTE($ac_compile)
-AC_MSG_ERROR(Can't run the compiler - sorry))
-
-AC_TRY_RUN([
-main()
-{
-  int __something_strange_();
-  __something_strange_(0);
-}
-],AC_MSG_ERROR(Your compiler does not set the exit status - sorry))
-
-AC_PROG_AWK
-
-AC_PROG_INSTALL
-
-if test -f etc/toolcheck; then
-AC_CHECKING(for buggy tools)
-sh etc/toolcheck 1>&AC_FD_MSG
-fi
-
-
-
-dnl SOCKDIR
-AC_MSG_CHECKING(if a system-wide socket dir should be used) 
-AC_ARG_ENABLE(socket-dir,
-    [  --disable-socket-dir    disable system wide socket-dir and use ~/.screen instead],
-    [
-	AC_MSG_RESULT(no.  ~/.screen will be used instead.)
-    ],
-    [
-	AC_MSG_RESULT(yes)
-	AC_MSG_CHECKING(for the socket dir)
-	SOCKDIR="(eff_uid ? \"/tmp/uscreens\" : \"/tmp/screens\")"
-	AC_ARG_WITH(socket-dir, [  --with-socket-dir=path  where to put the per-user sockets], [ 
-	  case "${withval}" in
-	    *\"*) SOCKDIR="${withval}" ;;
-	    *) SOCKDIR="\"${withval}\"" ;;
-	  esac
-        ])
-	AC_MSG_RESULT(${SOCKDIR})
-	AC_DEFINE_UNQUOTED(SOCKDIR, $SOCKDIR)
-    ]
-)
-
-
-dnl
-dnl    ****  special unix variants  ****
-dnl
-if test -n "$ISC"; then
-  AC_DEFINE(ISC) LIBS="$LIBS -linet"
-fi
-
-dnl AC_CHECKING(for OSF1)
-dnl if test -f /bin/uname ; then
-dnl if test `/bin/uname` = OSF1 || test -f /osf_boot; then
-dnl AC_DEFINE(OSF1)	# this disables MIPS again....
-dnl fi
-dnl fi
-
-if test -f /sysV68 ; then
-AC_DEFINE(sysV68)
-fi
-
-AC_CHECKING(for MIPS)
-if test -f /lib/libmld.a || test -f /usr/lib/libmld.a || test -f /usr/lib/cmplrs/cc/libmld.a; then
-oldlibs="$LIBS"
-test -f /bin/mx || LIBS="$LIBS -lmld" # for nlist. But not on alpha.
-dnl djm@eng.umd.edu: "... for one thing, it doubles the size of the executable"
-AC_CHECKING(mld library)
-AC_TRY_LINK(,,,LIBS="$oldlibs")
-dnl
-dnl
-if test -r /dev/ptc; then
-AC_DEFINE(MIPS)
-AC_CHECKING(wait3)
-AC_TRY_LINK(,[wait3();], ,
-AC_CHECKING(wait2)
-AC_TRY_LINK(,[wait2();],
-dnl John Rouillard (rouilj@sni-usa.com):
-dnl need -I/usr/include/bsd in RISCOS otherwise sockets are broken, no
-dnl job control etc.
-dnl Detect RISCOS if wait2 is present, but not wait3.
-AC_DEFINE(USE_WAIT2) LIBS="$LIBS -lbsd" ; CC="$CC -I/usr/include/bsd"
-))
-fi
-fi
-
-
-AC_CHECKING(for Ultrix)
-AC_EGREP_CPP(yes,
-[#if defined(ultrix) || defined(__ultrix)
-   yes;
-#endif
-], ULTRIX=1)
-
-if test -f /usr/lib/libpyr.a ; then
-oldlibs="$LIBS"
-LIBS="$LIBS -lpyr"
-AC_CHECKING(Pyramid OSX)
-AC_TRY_LINK(,[open_controlling_pty("")], AC_DEFINE(OSX), LIBS="$oldlibs")
-fi
-
-dnl ghazi@caip.rutgers.edu (Kaveh R. Ghazi):
-dnl BBN butterfly is not POSIX, but a MACH BSD system.
-dnl Do not define POSIX and TERMIO.
-AC_CHECKING(for butterfly)
-AC_EGREP_CPP(yes,
-[#if defined(butterfly)
-  yes;
-#endif
-], butterfly=1)
-
-if test -z "$butterfly"; then
-if test -n "$ULTRIX"; then
-  test -z "$GCC" && CC="$CC -YBSD"
-fi
-AC_CHECKING(for POSIX.1)
-AC_EGREP_CPP(yes,
-[#include <sys/types.h>
-#include <unistd.h>
-main () {
-#ifdef _POSIX_VERSION
-  yes;
-#endif
-], AC_NOTE(- you have a POSIX system) AC_DEFINE(POSIX) posix=1)
-fi
-
-AC_CHECKING(for System V)
-AC_TRY_COMPILE(
-[#include <sys/types.h>
-#include <signal.h>
-#include <fcntl.h>], [int x = SIGCHLD | FNDELAY;], , AC_DEFINE(SYSV))
-
-AC_CHECKING(for sequent/ptx)
-AC_EGREP_CPP(yes,
-[#ifdef _SEQUENT_
-  yes;
-#endif
-], LIBS="$LIBS -lsocket -linet";seqptx=1)
-
-oldlibs="$LIBS"
-LIBS="$LIBS -lelf"
-AC_CHECKING(SVR4)
-AC_TRY_LINK([#include <utmpx.h>
-],,
-[AC_CHECK_HEADER(dwarf.h, AC_DEFINE(SVR4) AC_DEFINE(BUGGYGETLOGIN),
-[AC_CHECK_HEADER(elf.h, AC_DEFINE(SVR4) AC_DEFINE(BUGGYGETLOGIN))])]
-,LIBS="$oldlibs")
-AC_CHECK_HEADERS([stropts.h string.h strings.h])
-
-AC_CHECKING(for Solaris 2.x)
-AC_EGREP_CPP(yes,
-[#if defined(SVR4) && defined(sun)
-  yes
-#endif
-], LIBS="$LIBS -lsocket -lnsl -lkstat")
-
-dnl
-dnl    ****  typedefs ****
-dnl
-dnl (currently not used)
-dnl
-dnl AC_CHECKING(for pid_t)
-dnl AC_EGREP_CPP(pid_t,[#include <sys/types.h>
-dnl ],AC_DEFINE(PID_T_DEFINED))
-dnl
-dnl AC_CHECKING(for sig_t)
-dnl AC_EGREP_CPP(sig_t,[#include <sys/types.h>
-dnl #include <signal.h>
-dnl ],AC_DEFINE(SIG_T_DEFINED))
-dnl
-dnl AC_CHECKING(for uid_t)
-dnl AC_EGREP_CPP(uid_t,[#include <sys/types.h>
-dnl ],AC_DEFINE(UID_T_DEFINED))
-dnl
-
-dnl
-dnl   ****     Job control     ****
-dnl
-
-AC_CHECKING(BSD job jontrol)
-AC_TRY_LINK(
-[#include <sys/types.h>
-#include <sys/ioctl.h>
-], [
-#ifdef POSIX
-tcsetpgrp(0, 0);
-#else
-int x = TIOCSPGRP;
-#ifdef SYSV
-setpgrp();
-#else
-int y = TIOCNOTTY;
-#endif
-#endif
-], AC_NOTE(- you have jobcontrol) AC_DEFINE(BSDJOBS), AC_NOTE(- you don't have jobcontrol))
-
-dnl
-dnl    ****  setresuid(), setreuid(), seteuid()  ****
-dnl
-AC_CHECKING(setresuid)
-AC_TRY_LINK(,[
-setresuid(0, 0, 0);
-], AC_DEFINE(HAVE_SETRESUID))
-AC_CHECKING(setreuid)
-AC_TRY_LINK(,[
-setreuid(0, 0);
-], AC_DEFINE(HAVE_SETREUID))
-dnl
-dnl seteuid() check:
-dnl   linux seteuid was broken before V1.1.11
-dnl   NeXT, AUX, ISC, and ultrix are still broken (no saved uid support)
-dnl   Solaris seteuid doesn't change the saved uid, bad for
-dnl     multiuser screen sessions
-AC_CHECKING(seteuid)
-AC_TRY_LINK(,[
-#if defined(linux) || defined(NeXT) || defined(_AUX_SOURCE) || defined(AUX) || defined(ultrix) || (defined(sun) && defined(SVR4)) || defined(ISC) || defined(sony_news)
-seteuid_is_broken(0);
-#else
-seteuid(0);
-#endif
-], AC_DEFINE(HAVE_SETEUID))
-
-dnl
-dnl    ****  select()  ****
-dnl
-
-AC_CHECKING(select)
-AC_TRY_LINK(,[select(0, 0, 0, 0, 0);],, 
-LIBS="$LIBS -lnet -lnsl"
-AC_CHECKING(select with $LIBS)
-AC_TRY_LINK(,[select(0, 0, 0, 0, 0);],, 
-AC_MSG_ERROR(!!! no select - no screen))
-)
-dnl
-dnl    ****  FIFO tests  ****
-dnl
-
-AC_CHECKING(fifos)
-AC_TRY_RUN([
-/* For select - According to POSIX 1003.1-2001 */
-#include <sys/select.h>
-
-/* For select - According to earlier standards */
-#include <sys/time.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <sys/stat.h>
-#include <fcntl.h>
-
-#ifndef O_NONBLOCK
-#define O_NONBLOCK O_NDELAY
-#endif
-#ifndef S_IFIFO
-#define S_IFIFO 0010000
-#endif
-
-char *fin = "/tmp/conftest$$";
-
-main()
-{
-  struct stat stb;
-  fd_set f;
-
-  (void)alarm(5);
-  unlink(fin);
-#ifdef POSIX
-  if (mkfifo(fin, 0777))
-#else
-  if (mknod(fin, S_IFIFO|0777, 0))
-#endif
-    exit(1);
-  if (stat(fin, &stb) || (stb.st_mode & S_IFIFO) != S_IFIFO)
-    exit(1);
-  close(0);
-#ifdef __386BSD__
-  /*
-   * The next test fails under 386BSD, but screen works using fifos.
-   * Fifos in O_RDWR mode are only used for the BROKEN_PIPE case and for
-   * the select() configuration test.
-   */
-  exit(0);
-#endif
-  if (open(fin, O_RDONLY | O_NONBLOCK))
-    exit(1);
-  if (fork() == 0)
-    {
-      close(0);
-      if (open(fin, O_WRONLY | O_NONBLOCK))
-	exit(1);
-      close(0);
-      if (open(fin, O_WRONLY | O_NONBLOCK))
-	exit(1);
-      if (write(0, "TEST", 4) == -1)
-	exit(1);
-      exit(0);
-    }
-  FD_SET(0, &f);
-  if (select(1, &f, 0, 0, 0) == -1)
-    exit(1);
-  exit(0);
-}
-], AC_NOTE(- your fifos are usable) fifo=1,
-AC_NOTE(- your fifos are not usable))
-rm -f /tmp/conftest*
-
-if test -n "$fifo"; then
-AC_CHECKING(for broken fifo implementation)
-AC_TRY_RUN([
-/* For select - According to POSIX 1003.1-2001 */
-#include <sys/select.h>
-
-/* For select - According to earlier standards */
-#include <sys/time.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <sys/stat.h>
-#include <fcntl.h>
-
-#ifndef O_NONBLOCK
-#define O_NONBLOCK O_NDELAY
-#endif
-#ifndef S_IFIFO
-#define S_IFIFO 0010000
-#endif
-
-char *fin = "/tmp/conftest$$";
-
-main()
-{
-  struct timeval tv;
-  fd_set f;
-
-#ifdef POSIX
-  if (mkfifo(fin, 0600))
-#else
-  if (mknod(fin, S_IFIFO|0600, 0))
-#endif
-    exit(1);
-  close(0);
-  if (open(fin, O_RDONLY|O_NONBLOCK))
-    exit(1);
-  FD_SET(0, &f);
-  tv.tv_sec = 1;
-  tv.tv_usec = 0;
-  if (select(1, &f, 0, 0, &tv))
-    exit(1);
-  exit(0);
-}
-], AC_NOTE(- your implementation is ok), 
-AC_NOTE(- you have a broken implementation) AC_DEFINE(BROKEN_PIPE) fifobr=1)
-rm -f /tmp/conftest*
-fi
-
-dnl
-dnl    ****  SOCKET tests  ****
-dnl 
-dnl 	may need  	LIBS="$LIBS -lsocket" 	here
-dnl
-
-AC_CHECKING(sockets)
-AC_TRY_RUN([
-/* For select - According to POSIX 1003.1-2001 */
-#include <sys/select.h>
-
-/* For select - According to earlier standards */
-#include <sys/time.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-
-char *son = "/tmp/conftest$$";
-
-main()
-{
-  int s1, s2, l;
-  struct sockaddr_un a;
-  fd_set f;
-
-  (void)alarm(5);
-  if ((s1 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
-    exit(1);
-  a.sun_family = AF_UNIX;
-  strcpy(a.sun_path, son);
-  (void) unlink(son);
-  if (bind(s1, (struct sockaddr *) &a, strlen(son)+2) == -1)
-    exit(1);
-  if (listen(s1, 2))
-    exit(1);
-  if (fork() == 0)
-    {
-      if ((s2 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
-	kill(getppid(), 3);
-      (void)connect(s2, (struct sockaddr *)&a, strlen(son) + 2);
-      if (write(s2, "HELLO", 5) == -1)
-	kill(getppid(), 3);
-      exit(0);
-    }
-  l = sizeof(a);
-  close(0);
-  if (accept(s1, &a, &l))
-    exit(1);
-  FD_SET(0, &f);
-  if (select(1, &f, 0, 0, 0) == -1)
-    exit(1);
-  exit(0);
-}
-], AC_NOTE(- your sockets are usable) sock=1,
-AC_NOTE(- your sockets are not usable))
-rm -f /tmp/conftest*
-
-if test -n "$sock"; then
-AC_CHECKING(socket implementation)
-AC_TRY_RUN([
-/* For select - According to POSIX 1003.1-2001 */
-#include <sys/select.h>
-
-/* For select - According to earlier standards */
-#include <sys/time.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <sys/stat.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-
-char *son = "/tmp/conftest$$";
-
-main()
-{
-  int s;
-  struct stat stb;
-  struct sockaddr_un a;
-  if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
-    exit(0);
-  a.sun_family = AF_UNIX;
-  strcpy(a.sun_path, son);
-  (void) unlink(son);
-  if (bind(s, (struct sockaddr *) &a, strlen(son)+2) == -1)
-    exit(0);
-  if (stat(son, &stb))
-    exit(1);
-  close(s);
-  exit(0);
-}
-],AC_NOTE(- you are normal),
-AC_NOTE(- unix domain sockets are not kept in the filesystem)
-AC_DEFINE(SOCK_NOT_IN_FS) socknofs=1)
-rm -f /tmp/conftest*
-fi
-
-
-dnl
-dnl    ****  choose sockets or fifos  ****
-dnl
-if test -n "$fifo"; then
-  if test -n "$sock"; then
-    if test -n "$nore"; then
-      AC_NOTE(- hmmm... better take the fifos)
-      AC_DEFINE(NAMEDPIPE)
-    elif test -n "$fifobr"; then
-      AC_NOTE(- as your fifos are broken lets use the sockets.)
-    else
-      AC_NOTE(- both sockets and fifos usable. let's take sockets.)
-    fi
-  else
-    AC_NOTE(- using named pipes, of course)
-    AC_DEFINE(NAMEDPIPE)
-  fi
-elif test -n "$sock"; then
-  AC_NOTE(- using unix-domain sockets, of course)
-else
-  AC_MSG_ERROR(you have neither usable sockets nor usable pipes -> no screen)
-fi
-
-dnl
-dnl    ****  check the select implementation ****
-dnl
-
-AC_CHECKING(select return value)
-AC_TRY_RUN([
-/* For select - According to POSIX 1003.1-2001 */
-#include <sys/select.h>
-
-/* For select - According to earlier standards */
-#include <sys/time.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <sys/stat.h>
-#include <fcntl.h>
-
-char *nam = "/tmp/conftest$$";
-
-#ifdef NAMEDPIPE
-
-#ifndef O_NONBLOCK
-#define O_NONBLOCK O_NDELAY
-#endif
-#ifndef S_IFIFO
-#define S_IFIFO 0010000
-#endif
-
-
-main()
-{
-  fd_set f;
-
-#ifdef __FreeBSD__
-/* From Andrew A. Chernov (ache@astral.msk.su):
- * opening RDWR fifo fails in BSD 4.4, but select return values are
- * right.
- */
-  exit(0);
-#endif
-  (void)alarm(5);
-#ifdef POSIX
-  if (mkfifo(nam, 0777))
-#else
-  if (mknod(nam, S_IFIFO|0777, 0))
-#endif
-    exit(1);
-  close(0);
-  if (open(nam, O_RDWR | O_NONBLOCK))
-    exit(1);
-  if (write(0, "TEST", 4) == -1)
-    exit(1);
-
-#else
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-
-main()
-{
-  int s1, s2, l;
-  struct sockaddr_un a;
-  fd_set f;
-
-  (void)alarm(5);
-  if ((s1 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
-    exit(1);
-  a.sun_family = AF_UNIX;
-  strcpy(a.sun_path, nam);
-  (void) unlink(nam);
-  if (bind(s1, (struct sockaddr *) &a, strlen(nam)+2) == -1)
-    exit(1);
-  if (listen(s1, 2))
-    exit(1);
-  if (fork() == 0)
-    {
-      if ((s2 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
-	kill(getppid(), 3);
-      (void)connect(s2, (struct sockaddr *)&a, strlen(nam) + 2);
-      if (write(s2, "HELLO", 5) == -1)
-	kill(getppid(), 3);
-      exit(0);
-    }
-  l = sizeof(a);
-  close(0);
-  if (accept(s1, (struct sockaddr *)&a, &l))
-    exit(1);
-#endif
-
-
-  FD_SET(0, &f);
-  if (select(1, &f, 0, 0, 0) == -1)
-    exit(1);
-  if (select(1, &f, &f, 0, 0) != 2)
-    exit(1);
-  exit(0);
-}
-],AC_NOTE(- select is ok),
-AC_NOTE(- select can't count) AC_DEFINE(SELECT_BROKEN))
-
-dnl
-dnl    ****  termcap or terminfo  ****
-dnl
-AC_CHECKING(for tgetent)
-AC_TRY_LINK(,tgetent((char *)0, (char *)0);,,
-olibs="$LIBS"
-LIBS="-lcurses $olibs"
-AC_CHECKING(libcurses)
-AC_TRY_LINK(,[
-#ifdef __hpux
-__sorry_hpux_libcurses_is_totally_broken_in_10_10();
-#else
-tgetent((char *)0, (char *)0);
-#endif
-],,
-LIBS="-ltermcap $olibs"
-AC_CHECKING(libtermcap)
-AC_TRY_LINK(,tgetent((char *)0, (char *)0);,,
-LIBS="-ltermlib $olibs"
-AC_CHECKING(libtermlib)
-AC_TRY_LINK(,tgetent((char *)0, (char *)0);,,
-LIBS="-lncursesw $olibs"
-AC_CHECKING(libncursesw)
-AC_TRY_LINK(,tgetent((char *)0, (char *)0);,,
-LIBS="-lncurses $olibs"
-AC_CHECKING(libncurses)
-AC_TRY_LINK(,tgetent((char *)0, (char *)0);,,
-AC_MSG_ERROR(!!! no tgetent - no screen)))))))
-
-AC_TRY_RUN([
-main()
-{
- exit(strcmp(tgoto("%p1%d", 0, 1), "1") ? 0 : 1);
-}], AC_NOTE(- you use the termcap database),
-AC_NOTE(- you use the terminfo database) AC_DEFINE(TERMINFO))
-AC_CHECKING(ospeed)
-AC_TRY_LINK(extern short ospeed;,ospeed=5;,,AC_DEFINE(NEED_OSPEED))
-
-dnl
-dnl    ****  PTY specific things  ****
-dnl
-AC_CHECKING(for /dev/ptc)
-if test -r /dev/ptc; then
-AC_DEFINE(HAVE_DEV_PTC)
-fi
-
-AC_CHECKING(for SVR4 ptys)
-sysvr4ptys=
-if test -c /dev/ptmx ; then
-AC_TRY_LINK([],[ptsname(0);grantpt(0);unlockpt(0);],[AC_DEFINE(HAVE_SVR4_PTYS)
-sysvr4ptys=1])
-fi
-
-AC_CHECK_FUNCS(getpt)
-
-dnl check for openpty()
-if test -z "$sysvr4ptys"; then
-AC_CHECK_FUNCS(openpty,,
-[AC_CHECK_LIB(util,openpty, [AC_DEFINE(HAVE_OPENPTY)] [LIBS="$LIBS -lutil"])])
-fi
-
-AC_CHECKING(for ptyranges)
-if test -d /dev/ptym ; then
-pdir='/dev/ptym'
-else
-pdir='/dev'
-fi
-dnl SCO uses ptyp%d
-AC_EGREP_CPP(yes,
-[#ifdef M_UNIX
-   yes;
-#endif
-], ptys=`echo /dev/ptyp??`, ptys=`echo $pdir/pty??`)
-dnl if test -c /dev/ptyp19; then
-dnl ptys=`echo /dev/ptyp??`
-dnl else
-dnl ptys=`echo $pdir/pty??`
-dnl fi
-if test "$ptys" != "$pdir/pty??" ; then
-p0=`echo $ptys | tr ' ' '\012' | sed -e 's/^.*\(.\).$/\1/g' | sort -u | tr -d '\012'`
-p1=`echo $ptys | tr ' ' '\012' | sed -e 's/^.*\(.\)$/\1/g'  | sort -u | tr -d '\012'`
-AC_DEFINE_UNQUOTED(PTYRANGE0,"$p0")
-AC_DEFINE_UNQUOTED(PTYRANGE1,"$p1")
-fi
-
-dnl    ****  pty mode/group handling ****
-dnl
-dnl support provided by Luke Mewburn <lm@rmit.edu.au>, 931222
-AC_ARG_WITH(pty-mode, [  --with-pty-mode=mode    default mode for ptys], [ ptymode="${withval}" ])
-AC_ARG_WITH(pty-group, [  --with-pty-group=group  default group for ptys], [ ptygrp="${withval}" ])
-test -n "$ptymode" || ptymode=0620
-if test -n "$ptygrp" ; then
-AC_DEFINE_UNQUOTED(PTYMODE, $ptymode)
-AC_DEFINE_UNQUOTED(PTYGROUP,$ptygrp)
-else
-
-AC_CHECKING(default tty permissions/group)
-rm -f conftest_grp
-AC_TRY_RUN([
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
-main()
-{
-  struct stat sb;
-  char *x,*ttyname();
-  int om, m;
-  FILE *fp;
-
-  if (!(x = ttyname(0))) exit(1);
-  if (stat(x, &sb)) exit(1);
-  om = sb.st_mode;
-  if (om & 002) exit(0);
-  m = system("mesg y");
-  if (m == -1 || m == 127) exit(1);
-  if (stat(x, &sb)) exit(1);
-  m = sb.st_mode;
-  if (chmod(x, om)) exit(1);
-  if (m & 002) exit(0);
-  if (sb.st_gid == getgid()) exit(1);
-  if (!(fp=fopen("conftest_grp", "w")))
-    exit(1);
-  fprintf(fp, "%d\n", sb.st_gid);
-  fclose(fp);
-  exit(0);
-}
-],[
-    if test -f conftest_grp; then
-	ptygrp=`cat conftest_grp`
-	AC_NOTE([- pty mode: $ptymode, group: $ptygrp])
-	AC_DEFINE_UNQUOTED(PTYMODE, $ptymode)
-	AC_DEFINE_UNQUOTED(PTYGROUP,$ptygrp)
-    else
-	AC_NOTE(- ptys are world accessable)
-    fi
-],[
-    WRITEPATH=''
-    XTERMPATH=''
-    AC_PATH_PROG(WRITEPATH, write)
-    AC_PATH_PROG(XTERMPATH, xterm)
-    found=
-    if test -n "$WRITEPATH$XTERMPATH"; then
-      findfollow=
-      lsfollow=
-      found=`find $WRITEPATH $XTERMPATH -follow -print 2>/dev/null`
-      if test -n "$found"; then
-	findfollow=-follow
-	lsfollow=L
-      fi
-      if test -n "$XTERMPATH"; then
-	ptygrpn=`ls -l$lsfollow $XTERMPATH | sed -n -e 1p | $AWK '{print $4}'`
-	if test tty != "$ptygrpn"; then
-	  XTERMPATH=
-	fi
-      fi
-    fi
-    if test -n "$WRITEPATH$XTERMPATH"; then
-      found=`find $WRITEPATH $XTERMPATH $findfollow -perm -2000 -print` 
-      if test -n "$found"; then
-	ptygrp=`ls -ln$lsfollow $found | sed -n -e 1p | $AWK '{print $4}'`
-	AC_NOTE([- pty mode: $ptymode, group: $ptygrp])
-	AC_DEFINE_UNQUOTED(PTYMODE, $ptymode)
-	AC_DEFINE_UNQUOTED(PTYGROUP,$ptygrp)
-      else
-	AC_NOTE(- ptys are world accessable)
-      fi
-    else
-      AC_NOTE(- can't determine - assume ptys are world accessable)
-    fi
-  ]
-)
-rm -f conftest_grp
-fi
-
-dnl
-dnl    ****  utmp handling  ****
-dnl
-AC_CHECKING(getutent)
-AC_TRY_LINK([
-#include <time.h> /* to get time_t on SCO */
-#include <sys/types.h>
-#if defined(SVR4) && !defined(DGUX)
-#include <utmpx.h>
-#define utmp utmpx
-#else
-#include <utmp.h>
-#endif
-#ifdef __hpux
-#define pututline _pututline
-#endif
-],
-[int x = DEAD_PROCESS; pututline((struct utmp *)0); getutent();], AC_DEFINE(GETUTENT),
-olibs="$LIBS"
-LIBS="$LIBS -lgen"
-AC_CHECKING(getutent with -lgen)
-AC_TRY_LINK([
-#include <time.h>
-#include <sys/types.h>
-#if defined(SVR4) && !defined(DGUX)
-#include <utmpx.h>
-#define utmp utmpx
-#else
-#include <utmp.h>
-#endif
-#ifdef __hpux
-#define pututline _pututline
-#endif
-],
-[int x = DEAD_PROCESS; pututline((struct utmp *)0); getutent();], AC_DEFINE(GETUTENT), LIBS="$olibs")
-)
-AC_CHECKING(ut_host)
-AC_TRY_COMPILE([
-#include <time.h>
-#include <sys/types.h>
-#if defined(SVR4) && !defined(DGUX)
-#include <utmpx.h>
-#define utmp utmpx
-#else
-#include <utmp.h>
-#endif
-],[struct utmp u; u.ut_host[0] = 0;], AC_DEFINE(UTHOST))
-AC_CHECK_HEADER(utempter.h, have_utempter=yes, have_utempter=no)
-if test "$have_utempter" = yes; then
-  AC_DEFINE(HAVE_UTEMPTER)
-  LIBS="$LIBS -lutempter"
-fi
-
-dnl
-dnl    ****  loadav  ****
-dnl
-AC_CHECKING(for libutil(s))
-test -f /usr/lib/libutils.a && LIBS="$LIBS -lutils"
-test -f /usr/lib/libutil.a && LIBS="$LIBS -lutil"
-
-AC_CHECKING(getloadavg)
-AC_TRY_LINK(,[getloadavg((double *)0, 0);],
-AC_DEFINE(LOADAV_GETLOADAVG) load=1,
-if test -f /usr/lib/libkvm.a ; then
-olibs="$LIBS"
-LIBS="$LIBS -lkvm"
-AC_CHECKING(getloadavg with -lkvm)
-AC_TRY_LINK(,[getloadavg((double *)0, 0);],
-AC_DEFINE(LOADAV_GETLOADAVG) load=1, LIBS="$olibs")
-fi
-)
-
-if test -z "$load" ; then
-AC_EGREP_CPP(yes,
-[#if defined(NeXT) || defined(apollo) || defined(linux)
-  yes;
-#endif
-], load=1)
-fi
-if test -z "$load" ; then
-AC_CHECKING(for kernelfile)
-for core in /unix /vmunix /dynix /hp-ux /xelos /dev/ksyms /kernel/unix /kernel/genunix /unicos /mach /netbsd /386bsd /dgux /bsd /stand/vmunix; do
-  if test -f $core || test -c $core; then
-    break
-  fi
-done
-if test ! -f $core && test ! -c $core ; then
-  AC_NOTE(- no kernelfile found)
-else
-  AC_NOTE(- using kernelfile '$core')
-  if test -r $core ; then
-  AC_DEFINE_UNQUOTED(LOADAV_UNIX,"$core")
-  AC_CHECK_HEADER(nlist.h,
-    [AC_DEFINE(NLIST_STRUCT)
-     AC_CHECKING(n_un in struct nlist)
-     AC_TRY_COMPILE([#include <nlist.h>],
-       [struct nlist n; n.n_un.n_name = 0;],
-        AC_DEFINE(NLIST_NAME_UNION))])
-
-  AC_CHECKING(for nlist declaration)
-  AC_EGREP_CPP([nlist(( |	)( |	)*.*\(|\()],[
-#ifdef NLIST_STRUCT
-# include <nlist.h>
-#else
-# include <a.out.h>
-#endif
-],AC_DEFINE(NLIST_DECLARED))
-
-  AC_CHECKING(for avenrun symbol)
-  nlist64=
-  for av in avenrun _avenrun _Loadavg avenrun _avenrun _Loadavg; do
-  AC_TRY_RUN([
-#include <sys/types.h>
-#ifdef NLIST_STRUCT
-#include <nlist.h>
-#else
-#include <a.out.h>
-#endif
-
-$nlist64
-
-struct nlist nl[2];
-
-main()
-{
-#if !defined(_AUX_SOURCE) && !defined(AUX)
-# ifdef NLIST_NAME_UNION
-  nl[0].n_un.n_name = "$av";
-# else
-  nl[0].n_name = "$av";
-# endif
-#else
-  strncpy(nl[0].n_name, "$av", sizeof(nl[0].n_name));
-#endif
-  nlist(LOADAV_UNIX, nl);
-  if (nl[0].n_value == 0)
-    exit(1);
-  exit(0);
-}
-  ],avensym=$av;break)
-  if test "$av" = _Loadavg; then
-    nlist64='#define nlist nlist64'
-  fi
-  done
-  if test -z "$avensym" ; then
-    AC_NOTE(- no avenrun symbol found)
-  else
-    AC_NOTE(- using avenrun symbol '$avensym')
-    AC_DEFINE_UNQUOTED(LOADAV_AVENRUN,"$avensym")
-    if test -n "$nlist64"; then
-      AC_NOTE(- used nlist64 to find it)
-      AC_DEFINE(LOADAV_USE_NLIST64)
-    fi
-    load=1
-  fi
-  else
-    AC_NOTE(  Can't configure the load average display feature)
-    AC_NOTE(  because $core is not readable by you.)
-    AC_NOTE(  To configure the load average display feature,)
-    AC_NOTE(  re-run configure as root if possible.)
-    AC_NOTE(  If you are not the system administrator then disregard)
-    AC_NOTE(  this warning.  You can still use screen without)
-    AC_NOTE(  the load average display feature.)
-  fi
-fi
-fi
-
-AC_PROGRAM_SOURCE([
-#include <sys/types.h>
-#include <sys/param.h>
-],[
-#if !defined(LOADAV_GETLOADAVG) && ((defined(hp300) && !defined(__hpux)) || defined(sun) || (defined(ultrix) && defined(mips)) || defined(_SEQUENT_) || defined(sgi) || (defined(SVR4) && !defined(__hpux)) || defined(sony_news) || (!defined(__osf__) && defined(__alpha)) || defined(_IBMR2) || defined(_AUX_SOURCE) || defined(AUX) || defined(m88k))
-loadtype=long
-# if defined(apollo) || defined(_IBMR2) || defined(_AUX_SOURCE) || defined(AUX)
-loadscale=65536
-# else
-#  if defined(FSCALE) && !defined(__osf__)
-#   undef FSCALE
-loadscale=FSCALE
-#  else
-#   ifdef sgi
-loadtype=int
-loadscale=1024
-#   else
-#    if defined(MIPS) || defined(SVR4) || defined(m88k)
-loadscale=256
-#    else /* not MIPS */
-loadscale=1000 	/* our default value */
-#    endif /* MIPS */
-#   endif /* sgi */
-#  endif /* not FSCALE */
-# endif /* not apollo */
-#else
-loadtype=double
-loadscale=1
-#endif
-#ifdef alliant
-loadnum=4
-#else
-loadnum=3
-#endif
-])
-
-if test -n "$load" ; then AC_DEFINE(LOADAV) fi
-if test -n "$loadtype" ; then AC_DEFINE_UNQUOTED(LOADAV_TYPE,$loadtype) fi
-if test -n "$loadnum" ; then AC_DEFINE_UNQUOTED(LOADAV_NUM,$loadnum) fi
-if test -n "$loadscale" ; then AC_DEFINE_UNQUOTED(LOADAV_SCALE,$loadscale) fi
-
-dnl
-dnl    ****  signal handling  ****
-dnl
-if test -n "$posix" ; then
-
-dnl POSIX has reliable signals with void return type.
-AC_NOTE(assuming posix signal definition)
-AC_DEFINE(SIGVOID)
-
-else
-
-AC_CHECKING(return type of signal handlers)
-AC_TRY_COMPILE(
-[#include <sys/types.h>
-#include <signal.h>
-#ifdef signal
-#undef signal
-#endif
-extern void (*signal ()) ();], [int i;], AC_DEFINE(SIGVOID))
-AC_CHECKING(sigset)
-AC_TRY_LINK([
-#include <sys/types.h>
-#include <signal.h>
-],[
-#ifdef SIGVOID
-sigset(0, (void (*)())0);
-#else
-sigset(0, (int (*)())0);
-#endif
-], AC_DEFINE(USESIGSET))
-AC_CHECKING(signal implementation)
-AC_TRY_RUN([
-#include <sys/types.h>
-#include <signal.h>
-
-#ifndef SIGCLD
-#define SIGCLD SIGCHLD
-#endif
-#ifdef USESIGSET
-#define signal sigset
-#endif
-
-int got;
-
-#ifdef SIGVOID
-void
-#endif
-hand()
-{
-  got++;
-}
-
-main()
-{
-  /* on hpux we use sigvec to get bsd signals */
-#ifdef __hpux
-  (void)signal(SIGCLD, hand);
-  kill(getpid(), SIGCLD);
-  kill(getpid(), SIGCLD);
-  if (got < 2)
-    exit(1);
-#endif
-  exit(0);
-}
-],,AC_DEFINE(SYSVSIGS))
-
-fi
-
-dnl
-dnl    ****  libraries  ****
-dnl
-
-AC_CHECKING(for crypt and sec libraries)
-test -f /lib/libcrypt_d.a || test -f /usr/lib/libcrypt_d.a && LIBS="$LIBS -lcrypt_d"
-oldlibs="$LIBS"
-LIBS="$LIBS -lcrypt"
-AC_CHECKING(crypt)
-AC_TRY_LINK(,,,LIBS="$oldlibs")
-test -f /lib/libsec.a || test -f /usr/lib/libsec.a && LIBS="$LIBS -lsec"
-test -f /lib/libshadow.a || test -f /usr/lib/libshadow.a && LIBS="$LIBS -lshadow"
-oldlibs="$LIBS"
-LIBS="$LIBS -lsun"
-AC_CHECKING(IRIX sun library)
-AC_TRY_LINK(,,,LIBS="$oldlibs")
-
-AC_CHECKING(syslog)
-AC_TRY_LINK(,[closelog();], , [oldlibs="$LIBS"
-LIBS="$LIBS -lbsd"
-AC_CHECKING(syslog in libbsd.a)
-AC_TRY_LINK(, [closelog();], AC_NOTE(- found.), [LIBS="$oldlibs"
-AC_NOTE(- bad news: syslog missing.) AC_DEFINE(NOSYSLOG)])])
-
-AC_EGREP_CPP(yes,
-[#ifdef M_UNIX
-   yes;
-#endif
-], LIBS="$LIBS -lsocket -lcrypt_i")
-
-dnl
-dnl    ****  misc things  ****
-dnl
-AC_CHECKING(wait union)
-AC_TRY_COMPILE([#include <sys/types.h>
-#include <sys/wait.h>
-],[
-  union wait x;
-  int y;
-#ifdef WEXITSTATUS
-  y = WEXITSTATUS(x);
-#endif
-],AC_DEFINE(BSDWAIT))
-
-if test -z "$butterfly"; then
-AC_CHECKING(for termio or termios)
-AC_TRY_CPP([#include <termio.h>], AC_DEFINE(TERMIO),
-if test -n "$posix"; then
-AC_TRY_CPP([#include <termios.h>], AC_DEFINE(TERMIO))
-fi
-)
-fi
-
-dnl AC_CHECK_HEADER(shadow.h, AC_DEFINE(SHADOWPW))
-AC_CHECKING(getspnam)
-AC_TRY_LINK([#include <shadow.h>], [getspnam("x");],AC_DEFINE(SHADOWPW))
-
-AC_CHECKING(getttyent)
-AC_TRY_LINK(,[getttyent();], AC_DEFINE(GETTTYENT))
-
-AC_CHECKING(fdwalk)
-AC_TRY_LINK([#include <stdlib.h>], [fdwalk(NULL, NULL);],AC_DEFINE(HAVE_FDWALK))
-
-AC_CHECKING(whether memcpy/memmove/bcopy handles overlapping arguments)
-AC_TRY_RUN([
-main() {
-  char buf[10];
-  strcpy(buf, "abcdefghi");
-  bcopy(buf, buf + 2, 3);
-  if (strncmp(buf, "ababcf", 6))
-    exit(1);
-  strcpy(buf, "abcdefghi");
-  bcopy(buf + 2, buf, 3);
-  if (strncmp(buf, "cdedef", 6))
-    exit(1);
-  exit(0); /* libc version works properly.  */
-}], AC_DEFINE(USEBCOPY))
-
-AC_TRY_RUN([
-#define bcopy(s,d,l) memmove(d,s,l)
-main() {
-  char buf[10];
-  strcpy(buf, "abcdefghi");
-  bcopy(buf, buf + 2, 3);
-  if (strncmp(buf, "ababcf", 6))
-    exit(1);
-  strcpy(buf, "abcdefghi");
-  bcopy(buf + 2, buf, 3);
-  if (strncmp(buf, "cdedef", 6))
-    exit(1);
-  exit(0); /* libc version works properly.  */
-}], AC_DEFINE(USEMEMMOVE))
-
-
-AC_TRY_RUN([
-#define bcopy(s,d,l) memcpy(d,s,l)
-main() {
-  char buf[10];
-  strcpy(buf, "abcdefghi");
-  bcopy(buf, buf + 2, 3);
-  if (strncmp(buf, "ababcf", 6))
-    exit(1);
-  strcpy(buf, "abcdefghi");
-  bcopy(buf + 2, buf, 3);
-  if (strncmp(buf, "cdedef", 6))
-    exit(1);
-  exit(0); /* libc version works properly.  */
-}], AC_DEFINE(USEMEMCPY))
-
-AC_SYS_LONG_FILE_NAMES
-
-AC_MSG_CHECKING(for vsprintf)
-AC_TRY_LINK(,[vsprintf(0,0,0);], AC_MSG_RESULT(yes);AC_DEFINE(USEVARARGS), AC_MSG_RESULT(no))
-
-AC_HEADER_DIRENT
-
-AC_MSG_CHECKING(for setenv)
-if test -z "$ac_setenv_args"; then
-    AC_TRY_COMPILE(
-    [#include <stdlib.h>],
-    [
-        setenv((char *) 0, (char *) 0, 0);
-    ], ac_setenv_args=3)
-fi
-if test -z "$ac_setenv_args"; then
-    AC_TRY_COMPILE(
-    [#include <stdlib.h>],
-    [
-        setenv((char *) 0, (char *) 0);
-    ], ac_setenv_args=2)
-fi
-if test -n "$ac_setenv_args"; then
-    AC_DEFINE(USESETENV)
-    if test "$ac_setenv_args" = 3; then
-        AC_DEFINE(HAVE_SETENV_3)
-    elif test "$ac_setenv_args" = 2; then
-        AC_DEFINE(HAVE_SETENV_2)
-    fi
-else
-    AC_MSG_RESULT(no)
-    AC_MSG_CHECKING(for putenv)
-    AC_TRY_LINK(,[putenv((char *)0);unsetenv((char *)0);], AC_MSG_RESULT(yes) ,  AC_MSG_RESULT(no);AC_DEFINE(NEEDPUTENV))
-fi
-AC_MSG_CHECKING([for nl_langinfo(CODESET)])
-AC_TRY_LINK([
-#include <langinfo.h>
-],[nl_langinfo(CODESET);], AC_MSG_RESULT(yes);AC_DEFINE(HAVE_NL_LANGINFO), AC_MSG_RESULT(no))
-
-AC_SEARCH_LIBS(gethostname, nsl)
-
-AC_CHECK_FUNCS(rename fchmod fchown strerror lstat _exit utimes vsnprintf getcwd setlocale strftime)
-
-AC_ARG_ENABLE(pam, [  --enable-pam            enable PAM support])
-if test "$enable_pam" = "yes"; then
-    AC_MSG_CHECKING(for PAM support)
-    oldlibs="$LIBS"
-    LIBS="$LIBS -lpam"
-    AC_TRY_LINK([#include <security/pam_appl.h>], [
-	pam_start(0, 0, 0, 0);
-	pam_authenticate(0, 0);
-	pam_end(0,0);
-    ], AC_MSG_RESULT(yes);AC_DEFINE(USE_PAM),
-       AC_MSG_RESULT(no);LIBS="$oldlibs")
-fi
-
-AC_ARG_ENABLE(use_locale, [  --enable-locale         use localized month/day names])
-if test "$enable_use_locale" = "yes"; then
-  AC_DEFINE(USE_LOCALE)
-fi
-AC_ARG_ENABLE(telnet, [  --enable-telnet         enable builtin telnet])
-if test "$enable_telnet" = "yes"; then
-  AC_DEFINE(BUILTIN_TELNET)
-fi
-AC_ARG_ENABLE(colors256, [  --enable-colors256      enable support for 256 colors])
-if test "$enable_colors256" = "yes"; then
-  AC_DEFINE(COLORS256)
-fi
-AC_ARG_ENABLE(rxvt_osc, [  --enable-rxvt_osc       enable support for rxvt OSC codes])
-if test "$enable_rxvt_osc" = "yes"; then
-  AC_DEFINE(RXVT_OSC)
-fi
-
-dnl
-dnl    ****  the end  ****
-dnl
-if test -z "$old_CFLAGS"; then
-  if test "x$CFLAGS" = "x-g"; then
-    CFLAGS="-O"
-  fi
-fi
-dnl Ptx bug workaround -- insert -lc after -ltermcap
-test -n "$seqptx" && LIBS="-ltermcap -lc -lsocket -linet -lnsl -lsec -lseq"
-
-AC_TRY_RUN(main(){exit(0);},,AC_MSG_ERROR(Can't run the compiler - internal error. Sorry.))
-
-AC_OUTPUT(Makefile doc/Makefile, [[
-# a hook for preserving undef directive in config.h
-mv config.h conftest
-sed -e 's@^\(.*\)defin.\( .*\) .*/\*\(.*KEEP_UNDEF_HERE\)@\1undef\2	/\*\3@' < conftest > config.h
-rm -f conftest
-]])
-
-echo ""
-if test -z "$AWK"; then
-echo "!!! Since you have no awk you must copy the files 'comm.h.dist'"
-echo "!!! and 'term.h.dist' to 'comm.h' and 'term.h'."
-echo "!!! Do _not_ change the user configuration section in config.h!"
-echo "Please check the pathnames in the Makefile."
-else
-echo "Now please check the pathnames in the Makefile and in the user"
-echo "configuration section in config.h."
-fi
-echo "Then type 'make' to make screen. Good luck."
-echo ""
diff --git a/src/display.c b/src/display.c
index e5954ec..fe3c2f3 100644
--- a/src/display.c
+++ b/src/display.c
@@ -3620,9 +3620,9 @@ int progress;
       if (progress)
 	{
 	  fd_set w;
+	  struct timeval t;
 	  FD_ZERO(&w);
 	  FD_SET(D_userfd, &w);
-	  struct timeval t;
 	  t.tv_sec = progress;
 	  t.tv_usec = 0;
 	  wr = select(FD_SETSIZE, (fd_set *)0, &w, (fd_set *)0, &t);
diff --git a/src/extern.h b/src/extern.h
index 4e44024..4332078 100644
--- a/src/extern.h
+++ b/src/extern.h
@@ -52,7 +52,7 @@ extern char *MakeWinMsg __P((char *, struct win *, int));
 extern char *MakeWinMsgEv __P((char *, struct win *, int, int, struct event *, int));
 extern int   AddWinMsgRend __P((const char *, int));
 extern void  PutWinMsg __P((char *, int, int));
-#ifdef BSDWAIT
+#ifndef HAVE_SYS_WAIT_H
 extern void  WindowDied __P((struct win *, union wait, int));
 #else
 extern void  WindowDied __P((struct win *, int, int));
diff --git a/src/misc.c b/src/misc.c
index c56d87a..4105e2d 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -455,7 +455,7 @@ UserStatus()
 {
 #ifndef USE_SETEUID
   int i;
-# ifdef BSDWAIT
+# ifndef HAVE_SYS_WAIT_H
   union wait wstat;
 # else
   int wstat;
diff --git a/src/os.h b/src/os.h
index b56b660..4e2d0c3 100644
--- a/src/os.h
+++ b/src/os.h
@@ -60,6 +60,7 @@
 # define getpgrp __getpgrp
 # define exit __exit
 #endif
+
 #ifdef POSIX
 # include <unistd.h>
 # if defined(__STDC__)
@@ -248,14 +249,14 @@ extern int errno;
  *   utmp handling
  */
 
-#ifdef GETUTENT
+#ifdef HAVE_GETUTENT
   typedef char *slot_t;
 #else
   typedef int slot_t;
 #endif
 
-#if defined(UTMPOK) || defined(BUGGYGETLOGIN)
-# if defined(SVR4) && !defined(DGUX) && !defined(__hpux) && !defined(linux)
+#if defined(UTMPOK) || defined(SVR4)
+# if (defined(HAVE_UTMPX_H) && !defined(HAVE_UTMP_H)) || defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
 #  include <utmpx.h>
 #  define UTMPFILE	UTMPX_FILE
 #  define utmp		utmpx
@@ -266,12 +267,12 @@ extern int errno;
 #  define setutent	setutxent
 #  define endutent	endutxent
 #  define ut_time	ut_xtime
-# else /* SVR4 */
+# else
 #  include <utmp.h>
-# endif /* SVR4 */
+# endif
 # ifdef apollo
    /* 
-    * We don't have GETUTENT, so we dig into utmp ourselves.
+    * We don't HAVE_GETUTENT, so we dig into utmp ourselves.
     * But we save the permanent filedescriptor and
     * open utmp just when we need to. 
     * This code supports an unsorted utmp. jw.
@@ -291,7 +292,7 @@ extern int errno;
 #  endif
 # endif
 
-#endif /* UTMPOK || BUGGYGETLOGIN */
+#endif /* UTMPOK || SVR4 */
 
 #if !defined(UTMPOK) && defined(USRLIMIT)
 # undef USRLIMIT
@@ -397,13 +398,8 @@ extern int errno;
  *    signal handling
  */
 
-#ifdef SIGVOID
 # define SIGRETURN
-# define sigret_t void
-#else
-# define SIGRETURN return 0;
-# define sigret_t int
-#endif
+#define sigret_t RETSIGTYPE
 
 /* Geeeee, reverse it? */
 #if defined(SVR4) || (defined(SYSV) && defined(ISC)) || defined(_AIX) || defined(linux) || defined(ultrix) || defined(__386BSD__) || defined(__bsdi__) || defined(POSIX) || defined(NeXT)
@@ -447,7 +443,7 @@ extern int errno;
 #endif
 
 #ifndef WTERMSIG
-# ifndef BSDWAIT /* if wait is NOT a union: */
+# ifdef HAVE_SYS_WAIT_H /* if wait is NOT a union: */
 #  define WTERMSIG(status) (status & 0177)
 # else
 #  define WTERMSIG(status) status.w_T.w_Termsig 
@@ -455,7 +451,7 @@ extern int errno;
 #endif
 
 #ifndef WSTOPSIG
-# ifndef BSDWAIT /* if wait is NOT a union: */
+# ifdef HAVE_SYS_WAIT_H /* if wait is NOT a union: */
 #  define WSTOPSIG(status) ((status >> 8) & 0377)
 # else
 #  define WSTOPSIG(status) status.w_S.w_Stopsig 
@@ -468,7 +464,7 @@ extern int errno;
 #endif
 
 #ifndef WIFCORESIG
-# ifndef BSDWAIT /* if wait is NOT a union: */
+# ifdef HAVE_SYS_WAIT_H /* if wait is NOT a union: */
 #  define WIFCORESIG(status) (status & 0200)
 # else
 #  define WIFCORESIG(status) status.w_T.w_Coredump
@@ -476,7 +472,7 @@ extern int errno;
 #endif
 
 #ifndef WEXITSTATUS
-# ifndef BSDWAIT /* if wait is NOT a union: */
+# ifdef HAVE_SYS_WAIT_H /* if wait is NOT a union: */
 #  define WEXITSTATUS(status) ((status >> 8) & 0377)
 # else
 #  define WEXITSTATUS(status) status.w_T.w_Retcode
diff --git a/src/osdef.h.in b/src/osdef.h.in
index 36964fb..82e4427 100644
--- a/src/osdef.h.in
+++ b/src/osdef.h.in
@@ -72,7 +72,7 @@ extern void  bcopy __P((char *, char *, int));
 extern void  bcopy __P((char *, char *, int));
 #endif
 
-#ifdef BSDWAIT
+#ifndef HAVE_SYS_WAIT_H
 struct rusage;		/* for wait3 __P */
 union wait;		/* for wait3 __P */
 extern int   wait3 __P((union wait *, int, struct rusage *));
@@ -157,7 +157,7 @@ extern int   listen __P((int, int));
 extern int   accept __P((int, struct sockaddr *, int *));
 #endif
 
-#if defined(UTMPOK) && defined(GETUTENT)
+#if defined(UTMPOK) && defined(HAVE_GETUTENT)
 extern void  setutent __P((void));
 #endif
 
@@ -176,7 +176,7 @@ extern int   utimes __P((char *, struct timeval *));
 
 extern void  unsetenv __P((char *));
 
-# if defined(GETTTYENT) && !defined(GETUTENT) && !defined(UTNOKEEP)
+# if defined(GETTTYENT) && !defined(HAVE_GETUTENT) && !defined(UTNOKEEP)
 struct ttyent;		/* for getttyent __P */
 extern void  setttyent __P((void));
 extern struct ttyent *getttyent __P((void));
diff --git a/src/osdef.sh b/src/osdef.sh
index b281175..725e004 100644
--- a/src/osdef.sh
+++ b/src/osdef.sh
@@ -35,7 +35,7 @@ cat << EOF > osdef0.c
 #include <syslog.h>
 #endif
 #include "os.h"
-#if defined(UTMPOK) && defined (GETTTYENT) && !defined(GETUTENT)
+#if defined(UTMPOK) && defined (GETTTYENT) && !defined(HAVE_GETUTENT)
 #include <ttyent.h>
 #endif
 #ifdef SVR4
diff --git a/src/screen.c b/src/screen.c
index 7d1865e..107c947 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -1464,7 +1464,7 @@ char **av;
 void
 WindowDied(p, wstat, wstat_valid)
 struct win *p;
-#ifdef BSDWAIT
+#ifndef HAVE_SYS_WAIT_H
   union wait wstat;
 #else
   int wstat;
@@ -1473,7 +1473,7 @@ int wstat_valid;
 {
   int killit = 0;
 
-#if defined(BSDJOBS) && !defined(BSDWAIT)
+#if defined(BSDJOBS) && defined(HAVE_SYS_WAIT_H)
   if (!wstat_valid && p->w_pid > 0)
     {
       /* EOF on file descriptor. The process is probably also dead.
@@ -1662,14 +1662,14 @@ DoWait()
 {
   register int pid;
   struct win *p, *next;
-#ifdef BSDWAIT
+#ifndef HAVE_SYS_WAIT_H
   union wait wstat;
 #else
   int wstat;
 #endif
 
 #ifdef BSDJOBS
-# ifndef BSDWAIT
+# ifdef HAVE_SYS_WAIT_H
   while ((pid = waitpid(-1, &wstat, WNOHANG | WUNTRACED)) > 0)
 # else
 # ifdef USE_WAIT2
diff --git a/src/socket.c b/src/socket.c
index 7832832..8aae00d 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -31,6 +31,9 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #if !defined(NAMEDPIPE)
+#ifdef HAVE_SYS_UIO_H
+# include <sys/uio.h>
+#endif
 #include <sys/socket.h>
 #include <sys/un.h>
 #endif
diff --git a/src/termcap.c b/src/termcap.c
index 2b63a24..87083f0 100644
--- a/src/termcap.c
+++ b/src/termcap.c
@@ -361,7 +361,7 @@ int he;
   if (D_CG0)
     {
       if (D_CS0 == 0)
-#ifdef TERMINFO
+#if defined(TERMINFO) || defined(__FreeBSD__)
         D_CS0 = "\033(%p1%c";
 #else
         D_CS0 = "\033(%.";
diff --git a/src/terminfo/checktc.c b/src/terminfo/checktc.c
index ccc9485..acba34e 100644
--- a/src/terminfo/checktc.c
+++ b/src/terminfo/checktc.c
@@ -171,6 +171,7 @@ char *s;
   fflush(stdout);
 }
 
+#ifndef __FreeBSD__
 void CPutStr(s, c)
 char *s;
 int c;
@@ -186,6 +187,7 @@ int x, y;
   tputs(tgoto(s, y, x), 1, putcha);
   fflush(stdout);
 }
+#endif /* __FreeBSD__ */
 
 void GotoPos(x,y)
 int x,y;
diff --git a/src/utmp.c b/src/utmp.c
index 20f3c3c..8771730 100644
--- a/src/utmp.c
+++ b/src/utmp.c
@@ -74,7 +74,7 @@ extern int real_uid, eff_uid;
  *  we have a suid-root helper app that changes the utmp for us
  *  (won't work for login-slots)
  */
-#if (defined(sun) && defined(SVR4) && defined(GETUTENT)) || defined(HAVE_UTEMPTER)
+#if (defined(sun) && defined(SVR4) && defined(HAVE_GETUTENT)) || defined(HAVE_UTEMPTER)
 # define UTMP_HELPER
 #endif
 
@@ -88,13 +88,13 @@ static void makeuser __P((struct utmp *, char *, char *, int));
 static void makedead __P((struct utmp *));
 static int  pututslot __P((slot_t, struct utmp *, char *, struct win *));
 static struct utmp *getutslot __P((slot_t));
-#ifndef GETUTENT
+#ifndef HAVE_GETUTENT
 static struct utmp *getutent __P((void));
 static void endutent __P((void));
 static int  initutmp __P((void));
 static void setutent __P((void));
 #endif
-#if defined(linux) && defined(GETUTENT)
+#if defined(linux) && defined(HAVE_GETUTENT)
 static struct utmp *xpututline __P((struct utmp *utmp));
 # define pututline xpututline
 #endif
@@ -107,21 +107,21 @@ static int utmpfd = -1;
 #endif
 
 
-# if defined(GETUTENT) && (!defined(SVR4) || defined(__hpux)) && ! defined(__CYGWIN__)
-#  if defined(hpux) /* cruel hpux release 8.0 */
+# if defined(HAVE_GETUTENT) && (!defined(SVR4) || defined(__hpux)) && ! defined(__CYGWIN__)
+#  if defined(HAVE__PUTUTLINE) /* cruel hpux release 8.0 */
 #   define pututline _pututline
-#  endif /* hpux */
+#  endif /* HAVE__PUTUTLINE */
 extern struct utmp *getutline(), *pututline();
 #  if defined(_SEQUENT_)
 extern struct utmp *ut_add_user(), *ut_delete_user();
 extern char *ut_find_host();
-#   ifndef UTHOST
-#    define UTHOST		/* _SEQUENT_ has ut_find_host() */
+#   ifndef HAVE_STRUCT_UTMP_UT_HOST
+#    define HAVE_STRUCT_UTMP_UT_HOST		/* _SEQUENT_ has ut_find_host() */
 #   endif
 #  endif /* _SEQUENT_ */
-# endif /* GETUTENT && !SVR4 */
+# endif /* HAVE_GETUTENT && !SVR4 */
 
-# if !defined(GETUTENT) && !defined(UT_UNSORTED)
+# if !defined(HAVE_GETUTENT) && !defined(UT_UNSORTED)
 #  ifdef GETTTYENT
 #   include <ttyent.h>
 #  else
@@ -129,13 +129,13 @@ struct ttyent { char *ty_name; };
 static void           setttyent __P((void));
 static struct ttyent *getttyent __P((void));
 #  endif
-# endif /* !GETUTENT && !UT_UNSORTED */
+# endif /* !HAVE_GETUTENT && !UT_UNSORTED */
 
 #ifndef _SEQUENT_
 # undef  D_loginhost
 # define D_loginhost D_utmp_logintty.ut_host
 #endif
-#ifndef UTHOST
+#ifndef HAVE_STRUCT_UTMP_UT_HOST
 # undef  D_loginhost
 # define D_loginhost ((char *)0)
 #endif
@@ -273,10 +273,10 @@ InitUtmp()
       utmpok = 0;
       return;
     }
-# ifdef GETUTENT
+# ifdef HAVE_GETUTENT
   close(utmpfd);	/* it was just a test */
   utmpfd = -1;
-# endif /* GETUTENT */
+# endif /* HAVE_GETUTENT */
 #endif	/* UTMP_HELPER */
   utmpok = 1;
 }
@@ -409,12 +409,12 @@ struct win *wi;
   register slot_t slot;
   struct utmp u;
   int saved_ut;
-#ifdef UTHOST
+#ifdef HAVE_STRUCT_UTMP_UT_HOST
   char *p;
   char host[sizeof(D_loginhost) + 15];
 #else
   char *host = 0;
-#endif /* UTHOST */
+#endif /* HAVE_STRUCT_UTMP_UT_HOST */
 
   wi->w_slot = (slot_t)0;
   if (!utmpok || wi->w_type != W_TYPE_PTY)
@@ -434,7 +434,7 @@ struct win *wi;
   if (!saved_ut)
     makeuser(&u, stripdev(wi->w_tty), LoginName, wi->w_pid);
 
-#ifdef UTHOST
+#ifdef HAVE_STRUCT_UTMP_UT_HOST
   host[sizeof(host) - 15] = '\0';
   if (display)
     {
@@ -477,7 +477,7 @@ struct win *wi;
 # if !defined(_SEQUENT_) && !defined(sequent)
   strncpy(u.ut_host, host, sizeof(u.ut_host));
 # endif
-#endif /* UTHOST */
+#endif /* HAVE_STRUCT_UTMP_UT_HOST */
 
   if (pututslot(slot, &u, host, wi) == 0)
     {
@@ -546,7 +546,7 @@ struct win *wi;
  *  routines using the getut* api
  */
 
-#ifdef GETUTENT
+#ifdef HAVE_GETUTENT
 
 #define SLOT_USED(u) (u->ut_type == USER_PROCESS)
 
@@ -598,7 +598,7 @@ makedead(u)
 struct utmp *u;
 {
   u->ut_type = DEAD_PROCESS;
-#if (!defined(linux) || defined(EMPTY)) && !defined(__CYGWIN__)
+#if (!defined(linux) || defined(EMPTY)) && !defined(__CYGWIN__) && !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
   u->ut_exit.e_termination = 0;
   u->ut_exit.e_exit = 0;
 #endif
@@ -642,7 +642,7 @@ char *nam;
 }
 
 
-#else /* GETUTENT */
+#else /* HAVE_GETUTENT */
 
 /*********************************************************************
  *
@@ -724,7 +724,7 @@ struct utmp *u;
 {
 #ifdef UT_UNSORTED
   bzero(u->ut_name, sizeof(u->ut_name));
-# ifdef UTHOST
+# ifdef HAVE_STRUCT_UTMP_UT_HOST
   bzero(u->ut_host, sizeof(u->ut_host));
 # endif
 #else
@@ -774,7 +774,7 @@ char *nam;
   return slot;
 }
 
-#endif	/* GETUTENT */
+#endif	/* HAVE_GETUTENT */
 
 
 
@@ -783,7 +783,7 @@ char *nam;
  *  Cheap plastic imitation of ttyent routines.
  */
 
-#if !defined(GETTTYENT) && !defined(GETUTENT) && !defined(UT_UNSORTED)
+#if !defined(GETTTYENT) && !defined(HAVE_GETUTENT) && !defined(UT_UNSORTED)
 
 
 static char *tt, *ttnext;
@@ -825,7 +825,7 @@ getttyent()
   return &t;
 }
 
-#endif	/* !GETTTYENT && !GETUTENT && !UT_UNSORTED*/
+#endif	/* !GETTTYENT && !HAVE_GETUTENT && !UT_UNSORTED*/
 
 
 
@@ -839,7 +839,7 @@ getttyent()
  *  getlogin() replacement (for SVR4 machines)
  */
 
-# if defined(BUGGYGETLOGIN) && defined(UTMP_FILE)
+# if defined(SVR4) && defined(UTMP_FILE)
 char *
 getlogin()
 {
@@ -871,9 +871,9 @@ getlogin()
 
   return *retbuf ? retbuf : NULL;
 }
-# endif /* BUGGYGETLOGIN */
+# endif /* SVR4 */
 
-#if defined(linux) && defined(GETUTENT)
+#if defined(linux) && defined(HAVE_GETUTENT)
 # undef pututline
 
 /* aargh, linux' pututline returns void! */
diff --git a/src/window.c b/src/window.c
index fb271d2..4426f0f 100644
--- a/src/window.c
+++ b/src/window.c
@@ -1855,7 +1855,7 @@ char *data;
 	return;
 #endif
       debug2("Window %d: read error (errno %d) - killing window\n", p->w_number, errno);
-#ifdef BSDWAIT
+#ifndef HAVE_SYS_WAIT_H
       WindowDied(p, (union wait)0, 0);
 #else
       WindowDied(p, 0, 0);
@@ -1865,7 +1865,7 @@ char *data;
   if (len == 0)
     {
       debug1("Window %d: EOF - killing window\n", p->w_number);
-#ifdef BSDWAIT
+#ifndef HAVE_SYS_WAIT_H
       WindowDied(p, (union wait)0, 0);
 #else
       WindowDied(p, 0, 0);
