#!/bin/sh
#
# This software is Copyright 1991 by Stan Barber. 
#
# Permission is hereby granted to copy, reproduce, redistribute or otherwise
# use this software as long as: there is no monetary profit gained
# specifically from the use or reproduction of this software, it is not
# sold, rented, traded or otherwise marketed, and this copyright notice is
# included prominently in any copy made. 
#
# The author make no claims as to the fitness or correctness of this software
# for any use whatsoever, and it is provided as is. Any use of this software
# is at the user's own risk. 
#
# If these # comments don't work, trim them.  Don't worry about the other
# shell scripts, Configure will trim # comments from them for you.
#
# $Id: Configure,v 4.4.3.1 1991/11/22 04:11:10 davison Trn $
#
# $Log: Configure,v $
# Revision 4.4.3.1  1991/11/22  04:11:10  davison
# Trn Release 2.0
# 
# Revision 4.4.2.1  1991/12/01  18:05:42  sob
# Patchlevel 2 changes
#
# Revision 4.4.1.1  1991/09/25  19:38:08  sob
# various fixed
#
# Revision 4.4  1991/09/09  20:18:23  sob
# release 4.4
#
#

# Yes, you may rip this off to use in other distribution packages.

CTRLA=`echo a | tr a '\001'`

bopt=''
n=''
c=''
libc=''
sharedclib=''
eunicefix=''
eunice=''
cpp=''
shsharp=''
spitshell=''
startsh=''
test=''
expr=''
sed=''
echo=''
cat=''
rm=''
mv=''
cp=''
tail=''
tr=''
mkdir=''
sort=''
uniq=''
inews=''
grep=''
egrep=''
nidump=''
ypmatch=''
contains=''
lib=''
nametype=''
cc=''
cflags=''
iandd=''
rrninclude=''
termlib=''
jobslib=''
ndirlib=''
socketlib=''
dirtype=''
dirinc=''
libndir=''
usendir=''
ndirc=''
ndiro=''
posix=''
pager=''
mailer=''
internet=''
rnbin=''
filexp=''
distlist=''
Log=''
Id=''
sitename=''
hostfile=''
domain=''
orgname=''
isadmin=''
newsadmin=''
rnlib=''
mtlib=''
mansrc=''
manext=''
mtmansrc=''
mtmanext=''
maildir=''
spool=''
serverspool=''
active=''
myactive=''
activetimes=''
mininact=''
pref=''
defeditor=''
rootid=''
mboxchar=''
locpref=''
orgpref=''
citypref=''
statepref=''
cntrypref=''
contpref=''
strchr=''
memcpy=''
rename=''
ftruncate=''
usleep=''
uselect=''
strftime=''
foundsizet=''
xnxlib=''
chsize=''
tzset=''
threaddef=''
selectdef=''
threaddir=''
syslog=''
novoid=''
novfork=''
sunos4=''
portable=''
passnam=''
berknam=''
usgnam=''
whoami=''
termio=''
termios=''
fcntl=''
ioctl=''
ptem=''
normsig=''
sigblock=''
sigret=''
sighold=''
getuidgid=''
setvbuf=''
setbuffer=''
getcwd=''
getwd=''
havetlib=''
getpwent=''
gethostname=''
douname=''
phostname=''
hostcmd=''
norelay=''
isrrn=''
xthread=''
rdchk=''
serverfile=''
ignoreorg=''
NNTPSRC=''
CONFIG=''

echo "Beginning of configuration questions for trn."
: Eunice requires " " instead of "", can you believe it
echo " "

: sanity checks
PATH=".:$PATH:/bin:/usr/bin:/usr/local/bin:/usr/ucb:/usr/local:/usr/lbin:/etc:/usr/new:/usr/new/bin:/usr/nbin:/usr/bsd"
export PATH || (echo "OOPS, this isn't sh.  Desperation time.  I will feed myself to sh."; sh $0; kill $$)

if test ! -t 0; then
    echo "Type 'sh Configure', not 'sh <Configure'"
    exit 1
fi

(alias) >/dev/null 2>&1 && \
    echo "(I see you are using the Korn shell.  Some ksh's blow up on Configure," && \
    echo "especially on exotic machines.  If yours does, try the Bourne shell instead.)"


: some greps do not return status, grrr.
echo "grimblepritz" >grimble
if grep blurfldyick grimble >/dev/null 2>&1 ; then
    contains=contains
else
    if grep grimblepritz grimble >/dev/null 2>&1 ; then
	contains=grep
    else
	contains=contains
    fi
fi

: the following should work in any shell
case $contains in
contains*)
    echo " "
    echo "AGH!  Grep doesn't return a status.  Attempting remedial action."
    cat >contains <<'EOSS'
grep "$1" "$2" >.greptmp && cat .greptmp && test -s .greptmp
EOSS
chmod +x contains
esac

: first determine how to suppress newline on echo command
echo "Checking echo to see how to suppress newlines..."
(echo "hi there\c" ; echo " ") >.echotmp
if $contains c .echotmp >/dev/null 2>&1 ; then
    echo "...using -n."
    n='-n'
    c=''
else
    cat <<'EOM'
...using \c
EOM
    n=''
    c='\c'
fi
echo $n "Type carriage return to continue.  Your cursor should be here-->$c"
read ans
rm .echotmp

: now set up to do reads with possible shell escape
: if this does not work on your machine, 1,$s/. myread/read ans/
cat <<EOSC >myread
ans='!'
while expr "X\$ans" : "X!" >/dev/null; do
    read ans
    case "\$ans" in
    !)
	sh
	echo " "
	echo $n "Your answer: $c"
	;;
    !*)
	set \`expr "X\$ans" : "X!\(.*\)\$"\`
	sh -c "\$*"
	echo " "
	echo $n "Your answer: $c"
	;;
    esac
done
EOSC

: general instructions
cat <<'EOH'
 
This installation shell script will examine your system and ask you questions
to determine how trn and its auxiliary files should be installed.  If you
get stuck on a question, you may use a ! shell escape to start a subshell or
execute a command.  Many of the questions will have default answers in
square brackets--typing carriage return will give you the default.

On some of the questions which ask for file or directory names you are
allowed to use the ~name construct to specify the login directory belonging
to "name", even if you don't have a shell which knows about that.  Questions
where this is allowed will be marked "(~name ok)".

Much effort has been expended to ensure that this shell script will run
on any Unix system.  If despite that it blows up on you, your best bet is to
edit Configure and run it again.  (Trying to install trn without having run
Configure is well nigh impossible.)  Also, tell Wayne Davison how he blew it
(davison@borland.com).

This installation script affects things by doing direct variable substitutions
on some of the files included in this kit. You may edit any of these files as
the need arises after running this script.

EOH
echo $n "[Type carriage return to continue] $c"
. myread
Xn=$n
Xc=$c
: get old answers, if there is a config file out there
if test -f ./config.sh; then
    echo " "
    dflt=y
    rp="I see a config.sh file.  Do you want to use it to set the defaults? [$dflt]"
    echo $n "$rp $c"
    . myread
    case "$ans" in
    n*) echo "OK, I'll ignore it.";;
    *)  echo "Fetching default answers from your old config.sh file..."
	tmp="$n"
	ans="$c"
        . ./config.sh
	n="$tmp"
	c="$ans"
	;;
    esac
fi

n=$Xn
c=$Xc

: get list of predefined functions in a handy place
echo " "
if test -f /lib/libc.a; then
    if test -f /usr/lib/libc.a ; then
	echo "Found two C libraries:  /lib/libc.a and /usr/lib/libc.a"
	if test -d /usr/convex ; then
	    echo "Ah!  This is ConvexOS!  We'll use the one in /usr/lib."
	    libc=/usr/lib/libc.a
	else
	    echo "Hmmm...we'll use the more normal of the two:  /lib/libc.a"
	    libc=/lib/libc.a
	fi
    else
	echo "Your C library is in /lib/libc.a.  You're normal."
	if test -f /lib/libc_s.a; then
	    echo "You also have AT&T shared libraries, we'll use those."
	    sharedclib=-lc_s
	fi
	libc=/lib/libc.a
    fi
else
  if test -f /lib/clib; then
    echo "Your C library is in /lib/clib.  How nonstandard, must be Apollo."
    libc=/lib/clib
  else
    if test -f /lib/libc; then
	echo "Your C library is in /lib/libc.  This might be Domain/OS."
	libc=/lib/libc
    else
	if test -f /lib/386/Slibc.a; then
	    echo "Your C library is in /lib/386/Slibc.a.  I smell Xenix 386!"
	    libc=/lib/386/Slibc.a
	else
	  if test -f /lib/Llibc.a; then
	    echo "Your C library is in /lib/Llibc.a.  I smell Xenix!"
	    libc=/lib/Llibc.a
	  else
	    if test -f /usr/lib/libc.a; then
		echo "Your C library is in /usr/lib/libc.a, of all places."
		libc=/usr/lib/libc.a
		if test -f /usr/lib/libc_s.a; then
		    echo "You also have AT&T shared libraries, we'll use those."
		    sharedclib=-lc_s
		fi
	    else
		if test -f "$libc"; then
		    echo "Your C library is in $libc, like you said before."
		else
		    cat <<'EOM'
 
I can't seem to find your C library.  I've looked for /lib/libc.a and
/usr/lib/libc.a, but neither of those are there. Perhaps you can find
out by reading `man 3 intro' if you have the 'man' facility installed.

EOM
		    echo $n "What is the full name of your C library? $c"
		    . myread
		    libc="$ans"
		fi
	    fi
	  fi
	fi
    fi
  fi
fi

if test -d /usr/bsd43 -o -d /usr/bsd ; then
    echo " "
    echo "It appears that you might be running on a RISC/os box."
    echo $n "Should I pass the -B option to nm [y]? $c"
    . myread
    case $ans in
	n*|f*) bopt=''   ;;
	*)     bopt='-B' ;;
    esac
fi
if test -f /bin/smit ; then
    echo " "
    echo "It appears that you might be running on an IBM RS/6000 box."
    echo "We'll be using 'nm -B' to get the symbol lists."
    bopt='-B'
fi

echo " "
echo $n "Extracting names from $libc for later perusal...$c"
nm $bopt $libc > nm.list 2>/dev/null
sed -n -e 's/^.* T _//p' -e 's/^.* T //p' < nm.list > libc.list
if $contains '^printf$' libc.list >/dev/null 2>&1; then
    echo "done"
else
    sed -n -e 's/^.* [AD] _//p' -e 's/^.* [AD] //p' < nm.list > libc.list
    if $contains '^printf$' libc.list >/dev/null 2>&1; then
	echo "done"
    else
	 $contains .text nm.list | grep -v static | awk '{ print $1 }' > libc.list
    	if $contains '^printf$' libc.list >/dev/null 2>&1; then
		echo "done"
    	else
	     echo " "
	     echo "nm didn't seem to work right."
	     echo "Trying ar instead..."
	     if ar t $libc | sed -e 's/\.o$//' > libc.list; then
		echo "Ok."
	     else
		echo "That didn't work either.  Giving up."
		exit 1
	     fi
	 fi
    fi
fi
rm nm.list
: make some quick guesses about what we are up against
echo " "
echo $n "Hmm...  $c"
if $contains '^sigvec$' libc.list >/dev/null 2>&1 ; then
    echo "Looks kind of like a BSD system, but we'll see..."
    echo exit 0 >bsd
    echo exit 1 >usg
    echo exit 1 >v7
else
    if $contains '^dup2$' libc.list >/dev/null 2>&1 ; then
	echo "Looks sort of like a V7 system, but we'll see..."
	echo exit 1 >bsd
	echo exit 1 >usg
	echo exit 0 >v7
    else
	    echo "Looks kind of like a USG system, but we'll see..."
	    echo exit 1 >bsd
	    echo exit 0 >usg
	    echo exit 1 >v7
    fi
fi
:
if test -f /etc/inittab; then
    echo "You have an inittab file. You must be a USG system!"
    echo exit 1 >bsd
    echo exit 0 >usg
    echo exit 1 >v7
fi
if $contains '^vmssystem$' libc.list >/dev/null 2>&1 ; then
    cat <<'EOI'
There is, however, a strange, musty smell in the air that reminds me of
something...hmm...yes...I've got it...there's a VMS nearby, or I'm a Blit.
EOI
    echo "exit 0" >eunice
    eunicefix=unixtovms
    eunice=define
: it so happens the Eunice I know will not run shell scripts in Unix format
else
    echo " "
    echo "Congratulations.  You aren't running Eunice."
    eunicefix=':'
    eunice=undef
    echo "exit 1" >eunice
fi
chmod +x bsd usg v7 eunice
$eunicefix bsd usg v7 eunice
: see how we invoke the C preprocessor
echo " "
echo "Checking to see how your C preprocessor is invoked..."
cat <<'EOT' >testcpp.c
#define ABC abc
#define XYZ xyz
ABC+XYZ
EOT
echo 'Maybe "cc -E" will work...'
cc -E testcpp.c >testcpp.out 2>&1
if $contains 'abc+xyz' testcpp.out >/dev/null 2>&1 ; then
    echo "Yup, it does."
    cpp='cc -E'
else
    echo 'Nope...maybe "cc -P" will work...'
    cc -P testcpp.c >testcpp.out 2>&1
    if $contains 'abc+xyz' testcpp.out >/dev/null 2>&1 ; then
	echo "Yup, that does."
	cpp='cc -P'
    else
	echo 'Nixed again...maybe "/lib/cpp" will work...'
	/lib/cpp testcpp.c >testcpp.out 2>&1
	if $contains 'abc+xyz' testcpp.out >/dev/null 2>&1 ; then
	    echo "Hooray, it works!  I was beginning to wonder."
	    cpp='/lib/cpp'
	else
	    if $contains 'abc +xyz' testcpp.out >/dev/null 2>&1 ; then
		echo "Found it!  You're on a NeXT, aren't you?"
		cpp='/lib/cpp'
	    else
		echo 'Hmm...maybe you already told me...'
		case "$cpp" in
		'') ;;
		*) $cpp testcpp.c >testcpp.out 2>&1;;
		esac
		if $contains 'abc+xyz' testcpp.out >/dev/null 2>&1 ; then
		    echo "Hooray, you did!  I was beginning to wonder."
		else
		    echo "Nope. I can't find a C preprocessor.  Name one: $c"
		    . myread
		    cpp="$ans"
		    $cpp testcpp.c >testcpp.out 2>&1
		    if $contains 'abc+xyz' testcpp.out >/dev/null 2>&1 ; then
			echo "OK, that will do."
		    else
			echo "Sorry, I can't get that to work.  Go find one."
		#	exit 1
		    fi
		fi
	    fi
	fi
    fi
fi
rm -f testcpp.c testcpp.out
: check for pdp11
echo " "
cat <<'EOT' >pdp11.c
#ifdef pdp11
exit 0
#else
exit 1
#endif
EOT
$cpp pdp11.c | grep exit >pdp11
chmod +x pdp11
$eunicefix pdp11
rm pdp11.c
if pdp11; then
    echo "This looks like a pdp11 to me."
fi
: check for ultrix
cat <<'EOT' >ultrix.c
#ifdef ultrix
exit 0
#else
exit 1
#endif
EOT
$cpp ultrix.c | grep exit >ultrix
chmod +x ultrix
$eunicefix ultrix
rm ultrix.c
if ultrix; then
    echo "Running ultrix, eh?"
fi

: check for uts
cat <<'EOT' >uts.c
#ifdef uts
exit 0
#else
exit 1
#endif
EOT
$cpp uts.c | grep exit >uts
chmod +x uts
$eunicefix uts
rm uts.c
if uts; then
    echo "This appears to be some kind of System370-type system running UTS."
    socketlib=-lsocket
fi

: check for sun 4.0
sunos4=undef
cat <<'EOT' >sun.c
#ifdef sun
exit 0
#else
exit 1
#endif
EOT
$cpp sun.c | grep exit >sun
chmod +x sun
$eunicefix sun
rm sun.c
if sun; then
    echo "This looks like a sun to me."
    if test -f /etc/ld.so.cache ; then
	echo "And it appears you are running SunOS 4.0 or greater."
        sunos4=define
	socketlib=
	rrninclude=
     fi
fi
: check for hp-ux
cat <<'EOT' >hp-ux.c
#ifdef hpux
exit 0
#else
exit 1
#endif
EOT
$cpp hp-ux.c | grep exit >hp-ux
chmod +x hp-ux
$eunicefix hp-ux
rm hp-ux.c
if hp-ux; then
    echo "Hewlett-Packard must have built this..."
    socketlib=-lbsdipc
fi

: check for mips
cat <<'EOT' >mips.c
#if defined(mips) && !defined(ultrix)
exit 0
#else
exit 1
#endif
EOT
$cpp mips.c | grep exit >mips
chmod +x mips
$eunicefix mips
rm mips.c
if mips; then
    echo "Looks like mips RISC/os..."
	rrninclude="-DUSG -I/usr/include/bsd"
	socketlib=-lbsd
fi
: check for stardent
cat <<'EOT' >stardent.c
#if defined(stardent) || defined(ardent) || defined (steller)
exit 0
#else
exit 1
#endif
EOT
$cpp stardent.c | grep exit >stardent
chmod +x stardent
$eunicefix stardent
rm stardent.c
if stardent; then
    echo "This appears to be a Stardent/Steller/Ardent..."
	rrninclude="-DUSG"
	socketlib=
fi
: check for sgi
cat <<'EOT' >sgi.c
#ifdef sgi
exit 0
#else
exit 1
#endif
EOT
$cpp sgi.c | grep exit >sgi
chmod +x sgi
$eunicefix sgi
rm sgi.c
if sgi; then
    echo "Silicon Graphics must have built this..."
	if test -f /usr/lib/libsun.a ; then
		socketlib=-lsun
	fi
fi

: check for XENIX
cat <<'EOT' >xenix
test -f /xenix; exit $?
EOT
chmod +x xenix
$eunicefix xenix
if xenix; then
    echo "Kinda looks like XENIX....hmmm"
	rrninclude="-DUSG -DLAI_TCP"
	socketlib=-lsocket
	rdchk=define
	dirtype=dirent
	dirinc="<dirent.h>"
else
	rdchk=undef
fi

: check for Pyramid OSx
cat <<'EOT' >pyr.c
#ifdef pyr
exit 0
#else
exit 1
#endif
EOT
$cpp pyr.c | grep exit >pyr
chmod +x pyr
$eunicefix pyr
rm pyr.c
if pyr; then
    echo "This looks like a Pyramid to me."
fi

: check for NeXT
cat <<'EOT' >next.c
#ifdef NeXT
exit 0
#else
exit 1
#endif
EOT
$cpp next.c | grep exit >next
chmod +x next
$eunicefix next
rm next.c
if next; then
    echo "My, you really ARE on a NeXT."
    addcflags=' -bsd'
    test=test
else
    addcflags=''
fi

if bsd; then
    getuidgid=define
else
    getuidgid=undef
fi

cat <<'EOT' > s5uniq
if test -f /bin/uname
then
    case `uname -r -m` in
	"5.3 vax-"*)
		if [ -f /usr/lib/libnet.a \
		  -a -f /usr/lib/libhdb.a \
		  -a -f /usr/lib/libbbn.a \
		  -a -f /usr/lib/libstr.a ]
		then
			exit 0
		fi;;
    esac
fi
exit 1
EOT
chmod +x s5uniq
if s5uniq; then
    echo "This looks like Uniq.  What a pity."
    socketlib="-lnet -lhdb -lbbn -lstr"
    rrninclude="-DR_UNIQ -DUSG"
    # -DR_UNIQ and -DUSG are needed for ~nntp/common/clientlib.c
fi
: check for posix
posix=''
if usg; then
    if test -f /lib/libcposix.a; then
    echo "Your version of System V supports POSIX compatibility."
    echo "We'll make use of it!"
    posix=' -Xp'
    fi
fi


: see if sh knows # comments
echo " "
echo "Checking your sh to see if it knows about # comments..."
if sh -c '#' >/dev/null 2>&1 ; then
    echo "Your sh handles # comments correctly."
    shsharp=true
    spitshell=cat
    echo " "
    echo "Okay, let's see if #! works on this system..."
    echo "#!/bin/echo hi" > try
    $eunicefix try
    chmod +x try
    try > today
    if test -s today; then
	echo "It does."
	sharpbang='#!'
    else
	echo "#! /bin/echo hi" > try
	$eunicefix try
	chmod +x try
	try > today
	if test -s today; then
	    echo "It does."
	    sharpbang='#! '
	else
	    echo "It doesn't."
	    sharpbang=': use '
	fi
    fi
else
    echo "Your sh doesn't grok # comments--I will strip them later on."
    shsharp=false
    echo "exec grep -v '^#'" >spitshell
    chmod +x spitshell
    $eunicefix spitshell
    spitshell=`pwd`/spitshell
    echo "I presume that if # doesn't work, #! won't work either!"
    sharpbang=': use '
fi

: figure out how to guarantee sh startup
echo " "
echo "Checking out how to guarantee sh startup..."
startsh=$sharpbang'/bin/sh'
echo "Let's see if '$startsh' works..."
cat >try <<EOSS
$startsh
set abc
test "$?abc" != 1
EOSS

chmod +x try
$eunicefix try
if try; then
    echo "Yup, it does."
else
    echo "Nope.  You may have to fix up the shell scripts to make sure sh runs them."
fi
rm -f try today

: find out where common programs are
echo " "
echo "Locating common programs..."
pth="/usr/ucb /bin /usr/bin /usr/local /usr/local/bin /usr/lbin /etc /usr/lib /usr/etc /usr/5bin /usr/bsd /usr/bsd43"
cat <<EOSC >loc
$startsh
thing=\$1
shift
dflt=\$1
shift
for dir in \$*; do
    case "\$thing" in
    .)
	if test -d \$dir/\$thing; then
	    echo \$dir
	    exit 0
	fi
	;;
    *)
	if test -f \$dir/\$thing; then
	    echo \$dir/\$thing
	    exit 0
	fi
	;;
    esac
done
echo \$dflt
exit 1
EOSC
chmod +x loc
$eunicefix loc
loclist="expr sed echo cat rm mv cp tail tr mkdir sort uniq grep"
trylist="test inews egrep more pg Mcc nidump ypmatch"
for file in $loclist; do
    xxx=`loc $file $file $pth`
    eval $file=$xxx
    case "$xxx" in
    /*)
	echo $file is in $xxx.
	;;
    *)
	echo "I don't know where $file is.  I hope it's in everyone's PATH."
	;;
    esac
done
echo " "
echo "Don't worry if any of the following aren't found..."
for file in $trylist; do
    xxx=`loc $file $file $pth`
    eval $file=$xxx
    case "$xxx" in
    /*)
	echo $file is in $xxx.
	;;
    *)
	echo "I don't see $file out there, offhand."
	;;
    esac
done
case $egrep in
egrep)
    echo "Substituting grep for egrep."
    egrep=$grep
    ;;
esac
case $test in
test)
    echo "Hopefully test is built into your sh."
    ;;
/bin/test)
    echo " "
    echo $n 'Is your "test" built into sh? [n] (OK to guess) '"$c"
    . myread
    case $ans in
    y*) test=test ;;
    esac
    ;;
*)
    test=test
    ;;
esac
case $echo in
echo)
    echo "Hopefully echo is built into your sh."
    ;;
/bin/echo)
    echo " "
    echo "Checking compatibility between /bin/echo and builtin echo (if any)..."
    $echo $n "hi there$c" >foo1
    echo $n "hi there$c" >foo2
    if cmp foo1 foo2 >/dev/null 2>&1; then
	echo "They are compatible.  In fact, they may be identical."
    else
	echo "They are not compatible--the echo builtin will be used."
	echo=echo
    fi
    $rm -f foo1 foo2
    ;;
*)
    echo=echo
    ;;
esac
$echo " "
: test yp
case $ypmatch in
ypmatch)
    $echo "I don't see ypmatch out there, so YP is not available. We'll search the"
    $echo "passwd file the old fashioned way!"
    ;;
*)
    $ypmatch 513/tcp services > /dev/null 2>/dev/null
    status=$?
    if $test $status  -ne 0 ; then
	$echo "YP installed, but not operational. We won't use it."
	ypmatch=""
    else
    	$echo "YP installed and operational."
    fi
    
    ;;
esac
if $test "$nidump" = "nidump"; then
    nidump=""
fi
if $test "$ypmatch" = "ypmatch"; then
    ypmatch=""
fi
 
: decide how portable to be
case "$portable" in
define) dflt=y;;
*)	dflt=n;;
esac
$cat <<'EOH'
 
I can set things up so that your shell scripts and binaries are more portable,
at what may be a noticeable cost in performance.  In particular, if you
ask to be portable, the following happens:

     1) shell scripts will rely on the PATH variable rather than using
	the paths derived above.
     2) ~username interpretations will be done at run time rather than
	by Configure.
     3) the system name will be determined at run time, if at all possible.

EOH
$echo $n "Do you expect to run these scripts and binaries on multiple machines? [$dflt] $c"
. myread
case $ans in
'') ans=$dflt;;
esac
case $ans in
    y*) portable=define
	for file in $loclist; do
	    eval $file=$file
	done
	;;
    *)  portable=undef ;;
esac

: set up shell script to do ~ expansion
cat >filexp <<EOSS
$startsh
: expand filename
case \$1 in
~/*|~)
    $echo \$1 | $sed "s|~|\${HOME-\$LOGDIR}|"
    ;;
~*)
    if $test -f /bin/csh; then
	/bin/csh -f -c "glob \$1"
	$echo ""
    else
	name=\`$expr x\$1 : '..\([^/]*\)'\`
	if $test "$ypmatch" != ""; then
 		dir=\`$ypmatch \$name passwd 2>/dev/null | $sed "s/^[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:\([^:]*\).*"'\$'"/\1/"'\`
	elif $test "$nidump" != ""; then
	    dir=\`$nidump passwd / | $sed -n -e "/^\${name}:/{s/^[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:\([^:]*\).*"'\$'"/\1/" -e p -e q -e '}'\`
	fi
	if $test "\$dir" = ""; then
	    dir=\`$sed </etc/passwd -n -e "/^\${name}:/{s/^[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:\([^:]*\).*"'\$'"/\1/" -e p -e q -e '}'\`
	fi
	if $test ! -d "\$dir"; then
	    me=\`basename \$0\`
	    $echo "\$me: can't locate home directory for: \$name" >&2
	    exit 1
	fi
	case \$1 in
	*/*)
	    $echo \$dir/\`$expr x\$1 : '..[^/]*/\(.*\)'\`
	    ;;
	*)
	    $echo \$dir
	    ;;
	esac
    fi
    ;;
*)
    $echo \$1
    ;;
esac
EOSS
chmod +x filexp
$eunicefix filexp

: try to deal with domains
$cat << 'EOH'

Please enter your domain name.  This will be used in conjunction with the
site name for return addresses on news articles and mail.  If you use the
4.3ism of having your domain in your hostname, all the posting programs
will figure this out on the fly, so don't worry.

Examples of some valid domains:
	berkeley.edu
	nasa.gov
Example of an invalid domain in common use:
	uucp
EOH

case "$domain" in
'') dflt="uucp";;
*)  dflt="$domain" ;;
esac
$echo $n "Your domain: [$dflt] $c"
. myread
case "$ans" in
'') domain="$dflt";;
*)  domain="$ans" ;;
esac

: now get the site name
$echo " "
$echo "Figuring out site name..."
$echo 'Maybe "hostname" will work...'
if ans=`sh -c hostname 2>&1` ; then
    thissite=$ans
    hostcmd=hostname
else
    $echo 'No, maybe "uuname -l" will work...'
    if ans=`sh -c 'uuname -l' 2>&1` ; then
	thissite=$ans
	hostcmd='uuname -l'
    else
	$echo 'Strange.  Maybe "uname -n" will work...'
	if ans=`sh -c 'uname -n' 2>&1` ; then
	    thissite=$ans
	    hostcmd='uname -n'
	else
	    $echo 'Oh well, maybe I can mine it out of whoami.h...'
	    if ans=`sh -c $contains' sysname /usr/include/whoami.h' 2>&1` ; then
		thissite=`$echo "$ans" | $sed 's/^.*"\(.*\)"/\1/'`
		hostcmd="sed -n -e '"'/sysname/s/^.*\"\\(.*\\)\"/\1/{'"' -e p -e q -e '}' </usr/include/whoami.h"
	    else
		case "$sitename" in
		'') $echo "Does this machine have an identity crisis or something?"
		    hostcmd=''
		    ;;
		*)  $echo "Well, you said $sitename before..."
		    thissite="$sitename"
		    ;;
		esac
	    fi
	fi
    fi
fi
: you do not want to know about this
set $thissite
thissite=$1

: translate upper to lower case. This is mostly to help UUCP work right.
case $thissite in
    *[A-Z]*)
	thissite=`$echo $thissite | tr '[A-Z]' '[a-z]'`
	$echo "(Normalizing case in your site name)"
	;;
esac

: verify site name and allow them to override it
if $test "$thissite" ; then
    $echo 'Your site name appears to be "'$thissite'".'
else
    thissite='unknown'
fi
case "$hostfile" in
/*) dflt="$hostfile" ;;
*)  case "$sitename" in
    '') dflt="$thissite" ;;
    *)  dflt="$sitename" ;;
    esac
esac
$cat <<'EOM'

In some cases it is not desirable to use the actual site name in your return
addresses (if, for example, all mail gets routed first to one site).  In this
case trn allows you to either hard-wire a site name or read the site name from
a file.  To indicate a file, start the name with a slash (e.g. /etc/sitename).
To use just your domain name, re-enter it here.  A period-less site name will
automatically get your domain name added to it.

EOM
while $test $dflt ; do
    $echo $n "What site name goes in return addresses? [$dflt] $c"
    . myread 
    case $ans in
    '') ans=$dflt;;
    esac
    case $ans in
    /*)
	if $test -f $ans ; then
	    hostfile="$ans"
	    hostcmd="$cat $ans"
	    sitename=`$hostcmd`
	    $echo "Trn will read the site name from $ans:  $sitename."
	    dflt=''
	else
	    $echo "Unable to locate $ans."
	fi
	;;
    *)  hostfile=''
	if $test "X$thissite" = "X$ans" ; then
	    sitename="$thissite"
	    $echo "Using the site name derived by $hostcmd:  $sitename."
	else
	    hostcmd=''
	    sitename="$ans"
	    $echo "Using a hard-wired site name:  $sitename."
	fi
	dflt=''
	;;
    esac
done

if $test $portable = "undef" ; then
	case $sitename in
	*.*)	;;
	*)	sitename=$sitename.$domain
		;;
	esac
fi

: get organization name
longshots='/usr/src/new /usr/src/local /usr/local/src'
case "$orgname" in
'') if xxx=`loc news/src/defs.h x $longshots`; then
	dflt=`$sed -n 's/^.*MYORG[ 	]*"\(.*\)".*$/\1/p' $xxx`
    else
	dflt='no default'
    fi
    ;;
*)  dflt="$orgname";;
esac
$cat << 'EOH'
 
Please type the name of your organization as you want it to appear on the
Organization line of outgoing articles.  (It's nice if this also specifies
your location.  Your city name is probably sufficient if well known.)
For example:

	University of Southern North Dakota, Hoople

You may also put the name of a file, as long as it begins with a slash.
For example:

	/etc/organization

EOH
orgname="no default"
while test "X$orgname" = "Xno default"; do
    $echo $n "Organization: [$dflt] $c"
    . myread
    case "$ans" in
    '') orgname="$dflt";;
    *)  orgname="$ans" ;;
    esac
done

: Decide whether to ignore the ORGANIZATION environment variable
cat <<'EOM'

Trn normally looks in the environment variables NEWSORG and ORGANIZATION
for an overriding organization name.  However, if your operating system
reserves the environment variable ORGANIZATION for non-News purposes,
you will want to ignore it and only have trn check for NEWSORG.

EOM

case "$ignoreorg" in
define) dflt=y ;;
*)      dflt=n ;;
esac
$echo $n "Should we ignore ORGANIZATION? [$dflt] $c"
. myread
case "$ans" in
'') ans="$dflt";;
esac
case "$ans" in
y*) ignoreorg=define ;;
*)  ignoreorg=undef ;;
esac

: get news administrator name
case "$newsadmin" in
'')
    if $contains "^news:" /etc/passwd >/dev/null 2>&1 ; then
	dflt=news
    else
	if $contains "^usenet:" /etc/passwd >/dev/null 2>&1 ; then
	    dflt=usenet
	else
	    if eunice; then
		dflt=system
	    else
		dflt=root
	    fi
	fi
    fi
    ;;
*)  dflt="$newsadmin"
    ;;
esac
cat <<'EOM'
 
Many systems keep their news in a private directory, or have a non-superuser
in charge of administering news.  (If you don't have such a user, take the
default answer.)  What is the login name (not directory) that is used for news
EOM
$echo $n "administration? [$dflt] $c"
. myread
newsadmin="$ans"
case $newsadmin in
'') newsadmin=$dflt ;;
esac
case $newsadmin in
root) isadmin=undef ;;
*)    isadmin=define ;;
esac

: figure out news library
case "$lib" in
'')
    dflt=/usr/lib/news
    ;;
*)  dflt=$lib ;;
esac
libexp=$lib
libexp='blurfl/dyick'
while $test ! -d "$libexp"; do
    $echo " "
    case "$libexp" in
    blurfl*) ;;
    *) $echo "Directory $libexp not found";;
    esac
    $echo $n "Where is your news library (~name okay)? [$dflt] $c"
    . myread
    case "$ans" in
    '') ans="$dflt";;
    esac
    lib="$ans"
    case $lib in
    ~*)
	libexp=`filexp $lib`
	$echo "(That is $libexp on this particular system.)"
	case $portable in
	  undef) lib=$libexp ;;
	esac
	;;
    *)
	libexp=$lib
	;;
    esac
done

: locate the inews program
ans='no default'
while $test ! -f "$ans" ; do
	case $ans in
	  'no default') ;;
	  *) $echo "$ans does not appear to exist." ;;
	esac
	case "$inews" in
	  ''|inews) 
	    if $test -f $libexp/inews; then
	 	 dflt=$libexp/inews
	    else
	    	dflt='no default'
	    fi
	  ;;
	  *)  dflt="$inews" ;;
	esac
	$echo " "
	$echo $n "Where is the inews program located on your system? [$dflt] $c"
	. myread
	case $ans in
	  '') ans=$dflt ;;
	esac
done
inews=$ans

: determine where manual pages go
case "$mansrc" in
'')
    dflt=`loc . /usr/man/man1 /usr/man/mann /usr/man/local/man1 /usr/man/u_man/man1 /usr/man/man1`
    ;;
*)  dflt="$mansrc"
    ;;
esac
mansrc='blurfl/dyick'
while $test ! -d "$mansrc" ; do
    case $mansrc in
      blurfl*) ;;
      *) $echo "$mansrc does not appear to exist." ;;
    esac
    $echo " "
    $echo $n "Where do user manual pages (source) go? [$dflt] $c"
    . myread
    mansrc=`filexp "$ans"`
    case $mansrc in
      '') mansrc=$dflt ;;
    esac
done
case "$mansrc" in
*l) manext=l ;;
*L) manext=L ;;
*n) manext=n ;;
*)  manext=1 ;;
esac
case "$mtmansrc" in
'') case "$manext" in
    '1') dflt="`dirname $mansrc`/`basename $mansrc 1`8" ;;
    *)   dflt="$mansrc"
    esac
    ;;
*)  dflt="$mtmansrc"
    ;;
esac
mtmansrc='blurfl/dyick'
while $test ! -d "$mtmansrc" ; do
    case $mtmansrc in
    blurfl*) ;;
    *) $echo "$mtmansrc does not appear to exist." ;;
    esac
    $echo " "
    $echo $n "Where should the mthreads.8 manpage (source) go? [$dflt] $c"
    . myread
    mtmansrc=`filexp "$ans"`
    case $mtmansrc in
    '') mtmansrc=$dflt ;;
    esac
done
case "$mtmansrc" in
*l) mtmanext=l ;;
*L) mtmanext=L ;;
*n) mtmanext=n ;;
*)  mtmanext=8 ;;
esac

: determine where mail is spooled
case "$maildir" in
'')
    dflt=`loc . /usr/spool/mail /usr/spool/mail /usr/mail`
    ;;
*)  dflt="$maildir"
    ;;
esac
case "$dflt" in
*%L*|*%~*) ;;

*)    dflt="$dflt/%L"
esac
$cat <<'EOM'

Trn needs to know where to find yet-to-be-read mail.  Sendmail sites
use /usr/spool/mail/%L (where '%L' is the user's login name).  Some
MMDF sites use /usr/%L/.mail instead.

EOM
$echo $n "Where is yet-to-be-read mail spooled? [$dflt] $c"
. myread
maildir="$ans"
case $maildir in
'') maildir=$dflt ;;
esac

: find out how to find out full name
$echo " "
case "$berknam" in
define)
    dflt=y;;
undef)
    dflt=n;;
*)
    if bsd || xenix; then
	dflt=y
    else
	dflt=n
    fi
    ;;
esac
$echo "Does your /etc/passwd file keep full names in Berkeley/V7 format (name first"
$echo $n "thing after ':' in GCOS field)? [$dflt] $c"
. myread
case $ans in
  '') ans=$dflt ;;
esac
case $ans in
  y*)
    passnam=define
    berknam=define
    usgnam=undef
    nametype=bsd
    ;;
  *)
    $echo " "
    case "$usgnam" in
    define)
	dflt=y;;
    undef)
	dflt=n;;
    *)
	if usg; then
	    dflt=y
	else
	    dflt=n
	fi
	;;
    esac
    $echo "Does your passwd file keep full names in USG format (name sandwiched"
    $echo $n "between a '-' and a '(')? [$dflt] $c"
    . myread
    case $ans in
      '') ans=$dflt ;;
    esac
    case $ans in
      n*)
	$echo "Full name will be taken from ~/.fullname"
	passnam=undef
	berknam=undef
	usgnam=undef
	nametype=other
	;;
      *)
	passnam=define
	berknam=undef
	usgnam=define
	nametype=usg
	;;
    esac
    ;;
esac

: see if we should throw a -i into the Makefile
$echo " "
if pdp11; then
    if $contains '\-i' $mansrc/cc.1 >/dev/null 2>&1 ; then
	$echo $n "Your system appears to have separate I and D space.  Is this true? [y] $c"
	. myread
	case $ans in
	    n*|f*) iandd='' ;;
	    *)     iandd=' -i' ;;
	esac
    else
	$echo "Your system appears to NOT have separate I and D space."
	$echo $n "Is this correct? [y] $c"
	. myread
	case $ans in
	    n*|f*) iandd=' -i' ;;
	    *)     iandd='' ;;
	esac
    fi
else
    $echo "Not a pdp11--assuming no separate I and D."
    iandd=''
fi

: set the right options for cc and include the x library for XENIX
if xenix; then
    if $test -d /lib/386 ; then
	iandd=" -M3e"
    else
:	iandd=" -M2let8 -LARGE -F 3000"
	iandd=" -Ml2et32 -LARGE -F B000"
    fi
    xnxlib=-lx
    chsize=define
else
if $test -r /lib/libx.a -a -f /xenix ; then
    $echo "Found Xenix library; using chsize()"
    xnxlib=-lx
    chsize=define
else
    xnxlib=''
    chsize=undef
fi
fi

: see if we need a special compiler
if usg; then
    case "$cc" in
    '')
	case "$Mcc" in
	/*) dflt='Mcc'
	    ;;
	*)
	    if $contains '\-M' $mansrc/cc.1 >/dev/null 2>&1 ; then
		dflt='cc -M'
	    else
		dflt='cc'
	    fi
	    ;;
	esac
	;;
    *)  dflt="$cc";;
    esac
    $cat <<'EOM'
 
On some systems the default C compiler will not resolve multiple global
references that happen to have the same name.  On some such systems the
"Mcc" command may be used to force these to be resolved.  On other systems
a "cc -M" command is required.  If gcc is available you might want to use
EOM
    $echo $n "that.  What command will force resolution on this system? [$dflt] $c"
    . myread
    cc="$ans"
    case "$cc" in
    '') cc="$dflt";;
    *)  cflags='';;
    esac
else
    case "$cc" in
    '') dflt="cc";;
    *)  dflt="$cc";;
    esac
    cat <<'EOM'

We need a C compiler that can resolve multiple global references, and since
this isn't a USG system, cc should work just fine.  However, you may want to
EOM
    $echo $n "use gcc or something else.  What C compiler should we use? [$dflt] $c"
    . myread
    case "$ans" in
    '') ans="$dflt";;
    *)  cflags='';;
    esac
    cc="$ans"
fi

: see about the C options
case "$cflags" in
'') dflt="-O$posix$iandd$addcflags";;
*)  dflt="$cflags";;
esac
cat <<EOM

The following C flags should do the job on your system.  However, if you need
to omit a -O, add a -traditional or whatever, here's your chance.  What flags
EOM
$echo $n "does $cc need? [$dflt] $c"
. myread
case "$ans" in
'') ans="$dflt";;
esac
cflags="$ans"

: index or strcpy
$echo " "
if $contains '^index$' libc.list >/dev/null 2>&1 ; then
    $echo "Your system appears to use index() and rindex() rather than strchr()"
    $echo $n "and strrchr().  Is this correct? [y] $c"
    . myread
    case $ans in
	n*|f*) strchr='define' ;;
	*)     strchr='undef' ;;
    esac
else
    $echo "Your system appears to use strchr() and strrchr() rather than index()"
    $echo $n "and rindex().  Is this correct? [y] $c"
    . myread
    case $ans in
	n*|f*) strchr=undef ;;
	*)     strchr=define ;;
    esac
fi

: bcopy/bzero or memcpy/memset
$echo " "
if $contains '^bcopy$' libc.list >/dev/null 2>&1 ; then
    $echo "Your system appears to use bcopy() and bzero() rather than memcpy()"
    $echo $n "and memset().  Is this correct? [y] $c"
    . myread
    case $ans in
	n*|f*) memcpy='define' ;;
	*)     memcpy='undef' ;;
    esac
else
    $echo "Your system appears to use memcpy() and memset() rather than bcopy()"
    $echo $n "and bzero().  Is this correct? [y] $c"
    . myread
    case $ans in
	n*|f*) memcpy='undef' ;;
	*)     memcpy='define' ;;
    esac
fi

: check for S5-style timezone handling - current offset from GMT in
: external variable "timezone" rather than gotten with "ftime".
$echo " "
if $contains tzname /usr/include/time.h >/dev/null 2>&1 ; then
    $echo "Your system appears to get the current timezone's offset from GMT by using the"
    $echo "external variable timezone rather than by calling ftime() or gettimeofday()."
    $echo $n "Is this correct? [y] $c"
    . myread
    case $ans in
	n*|f*) tzset='undef' ;;
	*)     tzset='define' ;;
    esac
else
    $echo "Your system appears to get the current timezone's offset from GMT by calling"
    $echo "ftime() or gettimeofday() rather than from the external variable timezone."
    $echo $n "Is this correct? [y] $c"
    . myread
    case $ans in
	n*|f*) tzset='define' ;;
	*)     tzset='undef' ;;
    esac
fi

: determine how to determine when a file is a mailbox
case "$mboxchar" in
'') dflt=F;;
*)  dflt="$mboxchar";;
esac
$cat <<'EOM'
 
In saving articles, trn wants to differentiate between saving to mailbox
format files and normal files.  It does this by examining the first character
of the file in question.  On most systems the first line starts "From...",
so the first character is F.  On other systems there are magic cookies like
control codes between articles, so one of those would be first.  For example,
MMDF messages are separated with lines of 4 control-A's.  On your system, if a
EOM
$echo $n "file is in mailbox format, what is the first character of that file? [$dflt] $c"
. myread
mboxchar="$ans"
case $mboxchar in
'') mboxchar="$dflt" ;;
esac
case $mboxchar in
'F') ;;
"$CTRLA") ;;
*)  cat <<'EOM'
You will need to edit the shell script mbox.saver to properly append an
article to a mailbox.  The arguments to the script are documented in
EOM
    case $shsharp in
    false)
	$echo "comments in mbox.saver.std."
	;;
    true)
	$echo "comments in the shell script itself."
	;;
    esac
esac
$rm -f grimble
: where do we get termlib routines from
$echo " "
ans=`loc libcurses.a x /usr/lib /usr/local/lib /lib`
case "$ans" in
/*)
    if test -f /bin/smit; then
	termlib='-lcurses'
	havetlib=define
	$echo "Using -lcurses and assuming terminfo, since this looks like AIX."
    else
	ar t $ans >grimble
	if $contains tputs grimble >/dev/null 2>&1; then
	    termlib='-lcurses'
	    havetlib=define
	    $echo "Terminfo library found."
	else
	    ans=x
	fi
    fi
    ;;
esac
case "$ans" in
x)
    ans=`loc libtermlib.a x /usr/lib /usr/local/lib /lib`
    case "$ans" in
    /usr/lib*|/lib*)
	termlib='-ltermlib'
	havetlib=define
	$echo "Termlib library found."
	;;
    /*)
	termlib="$ans"
	havetlib=define
	$echo "Termlib library found."
	;;
    *)
	if xenix; then
	    ans=/lib/Llibtermcap.a
	else
	    ans=`loc libtermcap.a x /usr/lib /usr/local/lib /lib`
	fi
	case "$ans" in
	/usr/lib*|/lib*)
	    termlib='-ltermcap'
	    havetlib=define
	    $echo "Termcap library found."
	    ;;
	/*)
	    termlib="$ans"
	    havetlib=define
	    $echo "Termcap library found."
	    ;;
	*)
	    case "$termlib" in
	    '')
		$echo $n "Your system appears to NOT have termlib-style routines.  Is this true? [y] $c"
		. myread
		case $ans in
		    n*|f*) havetlib=define
			  $echo "Then where are the termlib-style routines kept (specify either -llibname"
			  $echo $n " or full pathname (~name ok))? $c"
			  . myread
			  termlib=`filexp $ans`
			  ;;
		    *)    havetlib=undef
			  termlib=''
			  $echo "You will have to play around with term.c then."
			  ;;
		esac
		$echo " "
		;;
	    *)  $echo "You said termlib was $termlib before."
		;;
	    esac
	    ;;
	esac
	;;
    esac
    ;;
esac
: see if there is a whoami file
if $test -r /usr/include/whoami.h ; then
    whoami=define
    $echo "whoami.h found."
else
    whoami=undef
fi

: see if this is a termio/termios/sgtty system
if ultrix || sun || pyr ; then
    termio=undef
    termios=undef
    $echo "Using sgtty.h"
else
if $test -r /usr/include/termio.h ; then
    termio=define
    termios=undef
    $echo "termio.h found."
else
if test -d /usr/convex ; then
    termio=undef
    termios=define
    $echo "termios.h found."
else
if $test -r /usr/include/sgtty.h ; then
    termio=undef
    termios=undef
    $echo "sgtty.h found."
else
    termio=undef
    termios=undef
    $echo "Neither termio.h nor sgtty.h found--you could have problems."
fi
fi
fi
fi

: see if this system has fcntl
if $test -r /usr/include/fcntl.h ; then
    fcntl=define
    $echo "fcntl.h found."
else
    fcntl=undef
    $echo "No fcntl.h found, but that's ok."
fi

: see if ioctl defs are in sgtty/termio or sys/ioctl
if $test -r /usr/include/sys/ioctl.h ; then
    ioctl=define
    $echo "sys/ioctl.h found."
else
    ioctl=undef
    $echo "sys/ioctl.h not found, assuming ioctl args are defined in sgtty.h."
fi

: see if ptem.h exists
if $test -r /usr/include/sys/ptem.h ; then
    ptem=define
    $echo "sys/ptem.h found."
else
    ptem=undef
fi

: see if the system has sigblock
if $contains '^sigblock$' libc.list >/dev/null 2>&1 ; then
    if sgi; then
	$echo "sigblock() found and ignored on this Silicon Graphics box"
	sigblock=undef
    else
	$echo "sigblock() found."
	sigblock=define
    fi
else
    sigblock=undef
fi

: see if the system has setbuffer
if $contains '^setbuffer$' libc.list >/dev/null 2>&1 ; then
    $echo "setbuffer() found."
    setvbuf=undef
    setbuffer=define
else
: see if the system has setvbuf
if $contains '^setvbuf$' libc.list >/dev/null 2>&1 ; then
    $echo "setvbuf() found."
    setvbuf=define
    setbuffer=undef
else
    $echo "neither setbuffer() or setvbuf() found, punting to standard buffers."
    setvbuf=undef
    setbuffer=undef
fi
fi

: see if the system has getwd
if $contains '^getwd$' libc.list >/dev/null 2>&1 ; then
    $echo "getwd() found."
    getcwd=undef
    getwd=define
else
: see if the system has getcwd
if $contains '^getcwd$' libc.list >/dev/null 2>&1 ; then
    $echo "getcwd() found."
    getcwd=define
    getwd=undef
else
    getcwd=undef
    getwd=undef
fi
fi

: see if there is a vfork
if $contains '^vfork$' libc.list >/dev/null 2>&1 ; then
    $echo "vfork() found."
    novfork='undef'
    if sgi; then
        $echo "However, IRIX vfork() is buggy. We'll use fork() instead."
        novfork='define'
    fi
else
    if next; then
	$echo "I know NeXTs have vfork()!"
	novfork='undef'
    else
	$echo "No vfork() found--will use fork() instead."
	novfork='define'
    fi
fi

: check for rename
if $contains '^rename$' libc.list >/dev/null 2>&1 ; then
    $echo "rename() found."
    rename='define'
else
    $echo "No rename() found -- we'll emulate it."
    rename='undef'
fi

: check for ftruncate
if $contains '^ftruncate$' libc.list >/dev/null 2>&1 ; then
    $echo "ftruncate() found."
    ftruncate='define'
else
    $echo "No ftruncate() found -- we'll try to fake it."
    ftruncate='undef'
fi

: check for usleep or select
if $contains '^usleep$' libc.list >/dev/null 2>&1 ; then
    $echo "usleep() found."
    usleep='define'
    uselect='undef'
else
    usleep='undef'
    if $contains '^select$' libc.list >/dev/null 2>&1 ; then
	$echo "No usleep() found -- we'll use select to emulate it."
	uselect='define'
    else
	$echo "No usleep() found -- we'll use sleep() instead."
	uselect='undef'
    fi
fi

: check for strftime
if $contains '^strftime$' libc.list >/dev/null 2>&1 ; then
    $echo "strftime() found."
    strftime='define'
else
    $echo "No strftime() found -- we'll emulate it."
    strftime='undef'
fi
if $contains 'size_t' /usr/include/string*.h >/dev/null 2>&1 ; then
    foundsizet='define'
else
    foundsizet='undef'
fi

: see if YP could be running here
if $contains 'yp_master$' libc.list >/dev/null 2>&1 ; then
    $echo "YP may be running -- will use getpwent(), just in case."
    getpwent='define'
else
: see if there is a getpwent
if $contains '^getpwent$' libc.list >/dev/null 2>&1 ; then
    $echo "getpwent() found."
    getpwent='define'
else
    $echo "No getpwent() found--will use getpw() instead."
    getpwent='undef'
fi
fi

: default
sigret=void
: determine type of signal function
if next; then
	sigret=int
else
if stardent || sgi ; then
	sigret=void
else
if test -f /usr/include/signal.h ; then
	$cpp /usr/include/signal.h >sigtest
else
if test -f /usr/include/sys/signal.h ; then
	$cpp /usr/include/sys/signal.h >sigtest
fi
fi
if $contains 'int[^A-Za-z]*signal' sigtest >/dev/null 2>&1 ; then
	sigret=int
fi
fi
fi
$echo "signal() returns $sigret on this system."
: see how we will look up site name
douname=undef
gethostname=undef
phostname=undef
if $test ! "X$hostfile" = X ; then
    gethostname=define
else
if $test "X$hostcmd" = X ; then
    : it is already compiled in
else
if $contains '^gethostnam' libc.list >/dev/null 2>&1 ; then
    $echo "gethostname() found."
    gethostname=define
else
    if $contains '^uname$' libc.list >/dev/null 2>&1 ; then
	$echo "uname() found."
	douname=define
    else
	case $hostcmd in
	  '') ;;
	  *)
	    $cat <<EOT
 
There is no gethostname() or uname() on this system.  You have two
possibilites at this point:

1)  You can have your site name ($sitename) compiled into trn, which lets
    trn start up faster, but makes your binaries non-portable, or
2)  you can have trn use a
	
	popen("$hostcmd","r")

    which will start slower but be more portable.

Option 1 will use whoami.h if you have one.  If you want option 2 but with
a different command, you can edit config.h after this shell script is done.

EOT
	    case "$phostname" in
	    define) dflt=n;;
	    undef)  dflt=y;;
	    '')
		case $portable in
		define) dflt=n ;;
		*)      dflt=y ;;
		esac
		;;
	    esac
	    $echo $n "Do you want your site name compiled in? [$dflt] $c"
	    . myread
	    case $ans in
	    '') ans=$dflt;;
	    esac
	    case $ans in
	      n*) phostname=define ;;
	      *)  hostcmd='' phostname=undef;;
	    esac
	    ;;
	esac
	case $hostcmd in
	  '')
	    case $whoami in
	      define)
		$echo 'No hostname function--using whoami.h.'
		;;
	      undef)
		$echo 'No hostname function--hardwiring "'$sitename'".'
		;;
	    esac
	    ;;
	esac
    fi
fi
fi
fi

: see if we need -ljobs and if we have sigset, etc.
if $test -r /usr/lib/libjobs.a -o -r /usr/local/lib/libjobs.a ; then
    $echo "Jobs library found."
    normsig=undef
    jobslib='-ljobs'
else
    if bsd; then
	$echo "No jobs library found.  (I suppose this is at least 4.2...)"
    else
	$echo "No jobs library found.  (That's okay, we all have our faults.)"
    fi
    if $contains '^sigset$' libc.list >/dev/null 2>&1 ; then
	$echo "However, sigset() does exist, so we'll make use of it."
	normsig=undef
    else
    	normsig=define
    fi
    jobslib=''
fi
: use sighold and sigrelse?
if $contains '^sighold$' libc.list >/dev/null 2>&1 ; then
	$echo "sighold() found"
	sighold=define
    else
    	sighold=undef
fi
: No Steve jokes...
if next; then
    jobslib='-lsys_s'
fi
: see if there are directory access routines out there
    ndirlib=''
    libndir=undef
    if $contains '^readdir$' libc.list >/dev/null 2>&1 ; then
	$echo "readdir() found."
	usendir=undef
	ndirc=''
	ndiro=''
	if sgi ; then
	    dirtype=direct
	    dirinc="<sys/dir.h>"
	    $echo "Using direct directory structure."
	else 
		if $test -r /usr/include/dirent.h ; then
			$echo "Using dirent directory structure."
	    		dirtype=dirent
			dirinc="<dirent.h>"
		else
			$echo "Using direct directory structure."
	    		dirtype=direct
			dirinc="<sys/dir.h>"
		fi
	fi
     else
	if xenix; then
	    $echo "Using Xenix readdir() from -lx."
	    usendir=undef
	    ndirc=''
	    ndiro=''
	    dirtype=direct
	    dirinc="<sys/ndir.h>"
	    $echo "Using direct directory structure."
	else
		if $test -r /usr/lib/libndir.a -o -r /usr/local/lib/libndir.a ; then
    		$echo "ndir library found."
    			if $test -r /usr/lib/libndir.a; then
				ndirlib='-lndir'
    			else
				ndirlib="/usr/local/lib/libndir.a"
    			fi
    		libndir=define
    		usendir=undef
    		ndirc=''
    		ndiro=''
    		dirtype=direct
    		dirinc="<ndir.h>"
		else
	    		$echo "No ndir library and no readdir()--using ./ndir.c."
	    		usendir=define
	    		ndirc='ndir.c'
	    		ndiro='ndir.o'
	    		dirtype=direct
	fi
    fi
fi

: check if they want threads by default
case "$threaddef" in
    F*) dflt="n";;
    *)  dflt="y";;
esac
$cat <<'EOM'

Trn has two distinct operating modes (selected by the -x option):
traditional rn and threaded rn.  If you like, trn will check the first
letter of the command name and default to threaded mode (-x) if it is
a 't', or run as traditional rn (+x) if it isn't (this lets you install
as both trn and rn, linked together).  Otherwise, you can install trn
to default to threaded rn (-x) no matter what its name is.  Would you
EOM
$echo $n "prefer the latter? (defaults to -x, regardless of name)? [$dflt] $c"
. myread
case "$ans" in
'') ans="$dflt";;
esac
case "$ans" in
    n*|f*) threaddef='FALSE'
	   ans=' when -x is specified';;
    *)     threaddef='TRUE'
	   ans='';;
esac
: check if they want the thread selector used by default
case "$selectdef" in
    F*) dflt="n";;
    *)  dflt="y";;
esac
$cat <<'EOM'

When the -X option is specified, trn will set the default command
for starting a newsgroup to be the thread selector.  Should the -X
EOM
$echo $n "option be on by default$ans? [$dflt] $c"
. myread
case "$ans" in
'') ans="$dflt";;
esac
case "$ans" in
    n*|f*) selectdef='FALSE';;
    *)     selectdef='TRUE';;
esac
: check if they have and want to use syslog for the log file in mthreads
if $contains '^syslog$' libc.list >/dev/null 2>&1 ; then
	case $syslog in
	'') dflt=n ;;
	*)  dflt=y ;;
	esac
	$echo " "
	$echo "Mthreads can either use a custom log file or the syslog functions for"
	$echo $n "maintaining its log messages.  Would you prefer to use syslog? [$dflt] $c"
	. myread
	case "$ans" in
	'') ans="$dflt";;
	esac
	case $ans in
	n*) syslog='' ;;
	*)  case $syslog in
	    LOG_*) dflt="$dflt" ;;
	    *)     dflt=LOG_NEWS ;;
	    esac
	    $cat <<'EOM'

If your syslog has LOG_NEWS or LOG_DAEMON, you'll probably want to use
one of these for your logging.  If it doesn't, accept the default and
EOM
	    $echo $n "we'll figure that out later.  Your choice? [$dflt] $c"
	    . myread
	    case "$ans" in
	    '') ans="$dflt";;
	    esac
	    syslog="$ans"
	    ;;
	esac
else
    	syslog=''
fi

: locate spool directory and check if rrn
case "$isrrn" in
define)
    dflt="y";;
*)
    dflt="n";;
esac
isrrn=''
while $test -z "$isrrn" ; do
    $echo " "
    $echo $n "Do you want to build the NNTP version of trn? [$dflt] $c"
    . myread
    case "$ans" in
    '') ans="$dflt";;
    esac
    case "$ans" in
    n*)
	isrrn=undef
	xthread=undef
	serverspool=''
	;;
    y*)
	isrrn=define
	case "$xthread" in
	define)
	    dflt="y";;
	*)
	    dflt="n";;
	esac
	$echo " "
	$echo "Do you want to use the (unofficial) XTHREAD command to grab the thread files"
	$echo $n "via NNTP instead of using a local database?  (Requires a modified NNTP!) [$dflt] $c"
	. myread
	case "$ans" in
	'') ans="$dflt";;
	esac
	case "$ans" in
	y*) xthread=define
	    case "$serverspool" in
	    '') dflt="n";;
	    *)  dflt="y";;
	    esac
	    $cat <<'EOM'

The client machines won't need to run mthreads at all then.  As such, you
have the option of creating the server version of mthreads, or nothing at
EOM
	    $echo $n "all.  Do you want to create mthreads for the server? [$dflt] $c"
	    . myread
	    case "$ans" in
	    '') ans="$dflt";;
	    esac
	    case "$ans" in
	    y*) case "$serverspool" in
		'') dflt="/usr/spool/news";;
		*)  dflt="$serverspool";;
		esac
		$echo " "
		$echo $n "What directory does the SERVER spool news into? [$dflt] $c"
		. myread
		case "$ans" in
		'') ans="$dflt";;
		esac
		serverspool="$ans"
		;;
	    *)  serverspool=''
		;;
	    esac
	    ;;
	*)  xthread=undef
	    serverspool=''
	    $echo "Ok, mthreads will also be an NNTP client."
	    ;;
	esac
	spool=/tmp
	$echo "net.foobar 00001 00001 y" > .falseactive

	case "$serverfile" in
	'')  dflt="no default" ;;
	*)   dflt="$serverfile";;
	esac

	$cat <<'EOM'

Trrn determines the machine to use as a news server by two means:

First:	It examines the environment variable NNTPSERVER for a machine name.
	If present, this name is used in preference to the default.

Else:	It uses the default machine name, which is either read from a file
	or compiled into trn.

It is your choice whether you wish the default machine name to be read
from a file or specified directly.  To distinguish the two, a filename
must start with a slash or a tilde, and it must already exist with the
server name in it (it can contains comments (#) and blank lines also).
Any other answer is assumed to be a machine name.  If you use an alias
(such as "news-server") you can use your nameserver to map the name to
the actual machine.

EOM

	while : ; do
	    $echo $n "Enter the file name (~name ok) or machine name: [$dflt] $c"
	    . myread
	    case "$ans" in
	    '') ans="$dflt";;
	    esac
	    ans=`filexp "$ans"`
	    case "$ans" in
	    /*)	$test -r $ans && break
		$echo "File $ans does not exist."
		;;
	    *)	break
		;;
	    esac
	done
	serverfile="$ans"

	case "$NNTPSRC" in
	'') dflt="no default";;
	*)  dflt="$NNTPSRC";;
	esac

	ans='blurfl/dyick'
	while $test ! -d "$ans"; do
	    $echo " "
	    $echo $n "Enter the pathname of the NNTP source directory: [$dflt] $c"
	    . myread
	    case "$ans" in
	    '') ans="$dflt";;
	    esac
	    ans=`filexp "$ans"`
	    if $test ! -r $ans/common/nntp.h ; then
		$echo "Can't find $ans/common/nntp.h!"
		ans='blurfl/dyick'
	    fi
	done
	NNTPSRC="$ans"
    esac

done
: hack for Unisys NET-5000 and Interactive V/386
case "$isrrn" in
define) 
: NET-5000
    if $test -d /usr/include/NET-5000 ; then
	$echo "I sense you are on a Unisys 5000 computer...poor soul."
	rrninclude="-I/usr/include/NET-5000 -DEXCELAN -DUSG"
	socketlib=-lsocket
    fi
: Interactive Unix
    if $test -f /usr/lib/libinet.a ; then
	rrninclude="-DUSG"
	socketlib=-linet
    fi
    ;;
*) ;;
esac


case "$spool" in
'')
    dflt=/usr/spool/news
    ;;
*)  dflt="$spool";;
esac
case "$isrrn" in
define)  ans=/tmp;;
*) ans='blurfl/dyick';;
esac
while $test ! -d $ans; do
    $echo " "
    case "$ans" in
    blurfl*);;
    *) $echo "Directory $ans not found.";;
    esac
    $echo $n "Where is news spooled (~name ok)? [$dflt] $c"
    . myread
    case "$ans" in
    '') ans="$dflt";;
    esac
    spool="$ans"
    case $spool in
    ~*)
	ans=`filexp $spool`
	$echo "(That is $ans on this particular system.)"
	case $portable in
	  undef) spool=$ans ;;
	esac
	;;
    *)
	ans=$spool
	;;
    esac
done

: check on .thread file placement
if $test "$isrrn " = "define " -a "$serverspool " = " " ; then
  case "$xthread" in
  define)
    ans="/tmp";;
  *)
    case "$threaddir" in
    ''|'.')	dflt="/usr/spool/threads";;
    *)		dflt="$threaddir";;
    esac
    $echo " "
    $echo "Pick a directory where you would like the thread files to"
    $echo $n "be placed: [$dflt] $c"
    . myread
    case "$ans" in
    ''|'.') ans="$dflt";;
    esac
    ;;
  esac
else
    case "$threaddir" in
    ''|'.')	dflt=".";;
    *)		dflt="$threaddir";;
    esac
    $cat <<'EOM'

By default we place each group's .thread file in the same spool
directory as the article files.  Alternately, you can place the
data files in a separate directory if space is tight on the news
EOM
    case "$serverspool" in
    '') $echo "drive.  Where would you like them put?  (use '.' to specify the"
	$echo $n "spool dir): [$dflt] $c"
	;;
    *)  $echo "drive.  Where would you like them put on the SERVER?  (use '.'"
	$echo $n "to specify the spool dir): [$dflt] $c"
	;;
    esac
    . myread
    case "$ans" in
    '') ans="$dflt";;
    esac
fi
threaddir="$ans"

: locate active file
case "$active" in
'')
    dflt=$lib/active
    ;;
*)  dflt="$active";;
esac
case "$isrrn" in
define) myactive=.falseactive
    case "$serverspool" in
    '') ;;
    *)  $echo " "
	$echo "What is the name of your SERVER's active file (~name ok)?"
	$echo $n "[$dflt] $c"
	. myread
	case "$ans" in
	'') ans="$dflt";;
	esac
	active="$ans"
	;;
    esac
    : check for active.times
    case "$activetimes" in
    ''|none|nntp) dflt="n";;
    *)		  dflt="y";;
    esac
    cat <<'EOM'

If your server maintains an accurate "active.times" file (as C news does), trn
can make use of the much better NEWGROUPS call in NNTP to find new groups.  If
they are running B news, talk them into running acttimes (included) or mthreads
with the -t option to maintain a fake active.times file.  Otherwise, the old
report-everything-that's-not-in-the-.newsrc method will suffice.

EOM
    $echo $n "Will your server support a reliable NEWGROUPS call? [$dflt] $c"
    . myread
    case "$ans" in
    '') ans="$dflt";;
    esac
    case "$ans" in
    y*) case "$serverspool" in
	'') activetimes="nntp";;
	*)  case "$activetimes" in
	    '') dflt="${active}.times";;
	    *)  dflt="$activetimes";;
	    esac
	    $echo " "
	    $echo "What is the name of your SERVER's active.times file?"
	    $echo $n "[$dflt] $c"
	    . myread
	    case "$ans" in
	    '') ans="$dflt";;
	    esac
	    activetimes="$ans"
	esac
	;;
    *)  activetimes='none';;
    esac
    ;;
*) myactive='blurfl/dyick'
esac
while $test ! -f "$myactive"; do
    $echo " "
    case "$myactive" in
    blurfl*);;
    *) "File $myactive not found.";;
    esac
    $echo $n "Where is the active file (~name ok)? [$dflt] $c"
    . myread
    case "$ans" in
    '') ans="$dflt";;
    esac
    active="$ans"
    case $active in
    ~*)
	myactive=`filexp $active`
	$echo "(That is $myactive on this particular system.)"
	case $portable in
	  undef) active=$myactive ;;
	esac
	;;
    *)
	myactive=$active
	;;
    esac
    if $test -d $myactive ; then
	myactive=$myactive/active
	active=$active/active
    fi

    : check for active.times
    case "$activetimes" in
    ''|none|nntp) dflt="${active}.times";;
    *)		  dflt="$activetimes";;
    esac
    if $test "$dflt " = "none " -o ! -f $dflt ; then
	$cat <<'EOM'

If trn can use a file called active.times it can greatly speed up the
newgroup-checking code.  If you have access to a file maintained by C news,
use that.  Or, if you want to have mthreads maintain it, pick a spot for
the file and execute mthreads with the -t option.  Otherwise, specify "none"
for the good ol' slow approach.

EOM
    else
	$cat <<EOM

-- Found $dflt --
If this file is being maintained by C news, mthreads -t, or some other means,
you'll probably want to use it to greatly speed up the newgroup code.  If not
use "none" to indicate the good ol' slow approach.

EOM
    fi
    $echo $n "Active.times file to use or 'none'? [$dflt] $c"
    . myread
    case "$ans" in
    '') ans="$dflt";;
    esac
    activetimes="$ans"
done

: check for 2.10.2 and above
$echo " "
if $contains ' [0-9][0-9]* [0-9]' "$myactive" >/dev/null 2>&1; then
    case "$norelay" in
    undef) dflt="y";;
    *)     dflt="n";;
    esac
    case "$isrrn" in
    define) 
       $echo "Is your NNTP server running an old version of news software," ;;
    *) $echo "Is your system running an old version of news software," ;;
    esac
    $echo $n "predating B News 2.10.3? [${dflt}] $c" 
    . myread
    case "$ans" in
    '') ans=$dflt;;
    esac
    case "$ans" in
    y*)
      norelay='undef'
    $echo "Looks like you are running at least 2.10.2 news."
      ;;
    *)  norelay='define' ;;
    esac
    mininact=define
else
    $echo "It doesn't look like you are running 2.10.2 news yet.  Are you planning"
    $echo $n "to install it in the near future? [y] $c"
    . myread
    case $ans in
    n*) mininact=undef ;;
    *)  mininact=define ;;
    esac
    norelay='undef'
fi


: check for void type
$echo " "
$echo "Checking to see if your C compiler groks the void type..."
$cat >try.c <<'EOCP'
void main();
EOCP
if cc -c try.c >/dev/null 2>&1 ; then
    novoid='undef'
    $echo "Yup, it does."
else
    novoid='define'
    $echo "Nope, it doesn't (boo hiss).  I will substitute int."
fi
$rm try.*

: find out which shell people like to use most
ans='blurfl/dyick'
while $test ! -f "$ans" ; do
    case $ans in
      blurfl*) ;;
      *) $echo "$ans does not appear to exist." ;;
    esac
    case "$pref" in
    '')
	if $test -f /bin/ksh; then
	    dflt='/bin/ksh'
	else
	    if $test -f /bin/csh; then
		dflt='/bin/csh'
	    else
		dflt='/bin/sh'
	    fi
	fi
	;;
    *)  dflt="$pref";;
    esac
    $echo " "
    $echo "Give the full path name of the shell most people like to use on your"
    $echo $n "system: [$dflt] $c"
    . myread
    case $ans in
      '') ans=$dflt ;;
    esac
done
pref=$ans

: locate the preferred pager for this system
case "$pager" in
'')
    case $pg in
    /*) dflt=$pg
	;;
    esac
    case $more in
    /*) dflt=$more
	;;
    esac
    case $dflt in
    '') dflt=/usr/ucb/more
	;;
    esac
    ;;
*)  dflt="$pager";;
esac
pager='blurfl/dyick'
while $test ! -f "$pager" ; do
    case $pager in
      blurfl*)
	$echo " "
	$echo "(If your kernel does terminal paging then you may answer this with '/bin/cat'.)"
	;;
      /*) $echo "$pager does not appear to exist."
	$echo " "
        ;;
      *) $echo "Please give the full path name."
	$echo " "
        ;;
    esac
    $echo $n "What pager is used on your system? [$dflt] $c"
    . myread
    pager="$ans"
    case $pager in
      '') pager="$dflt" ;;
    esac
done

: determine default editor
case "$defeditor" in
'')
    dflt=`loc vi /usr/ucb $pth`
    ;;
*)  dflt="$defeditor"
    ;;
esac
defeditor='blurfl/dyick'
while $test ! -f "$defeditor" ; do
    case $defeditor in
      blurfl*) ;;
      *) $echo "$defeditor does not appear to exist." ;;
    esac
    $echo " "
    $echo $n "What is the default editor on your system? [$dflt] $c"
    . myread
    defeditor="$ans"
    case $defeditor in
      '') defeditor=$dflt ;;
    esac
done

: determine default mailer for Rnmail to use
$echo " "
if $test -f /usr/lib/sendmail; then
    dflt=/usr/lib/sendmail
else
    if usg && $test -f $libexp/recmail; then
        dflt=$libexp/recmail
    else
        dflt=/bin/mail
    fi
fi
$echo " "
if $test "$dflt" = "$libexp/recmail"; then
    $echo "($libexp/recmail is a part of the news package,and can"
    $echo "be safely used as the default mailer for the rrn package."
    $echo "You can also use the standard /bin/mail program if you choose.)"
    $echo " "
fi
$echo $n "What is the default mailer on your system? [$dflt] $c"
. ./myread                      
mailer="$ans"
case $mailer in
    '') mailer=$dflt ;;
esac
$echo "Mail sender is $mailer"

: check for internet mailer
case "$internet" in
define) dflt=y;;
undef)	dflt=n;;
*)
    case "$isrrn" in
	define) dflt=y ;;
	*) dflt=n ;;
    esac
    ;;
esac
cat <<EOM
 
Some newer mailers can deliver mail to addresses of the INTERNET persuasion,
such as user@host.UUCP.  Other older mailers require the complete path to
the destination to be specified in the address.  Does your mailer understand
EOM
$echo $n "INTERNET addresses? [$dflt] $c"
. myread
case "$ans" in
'') ans=$dflt;;
esac
case "$ans" in
y*) internet=define;;
*)  internet=undef;;
esac

: determine where public executables go
case "$rnbin" in
'')
    dflt=`loc . /bin /usr/local/bin /usr/lbin /usr/local /usr/bin`
    ;;
*)  dflt="$rnbin"
    ;;
esac
rnbin='blurfl/dyick'
while $test ! -d "$rnbin" ; do
    case $rnbin in
      blurfl*) ;;
      *) $echo "$rnbin does not appear to exist." ;;
    esac
    $echo " "
    $echo $n "Where do you want to put the public executables? [$dflt] $c"
    . myread
    rnbin="$ans"
    rnbin=`filexp $rnbin`
    case $rnbin in
      '') rnbin=$dflt ;;
    esac
done

: determine where private executables go
case "$rnlib" in
'')
    case "$isrrn" in
	define) dflt=/usr/local/lib/trn ;;
	*) dflt=$lib/trn ;;
    esac
    ;;
*)  dflt="$rnlib"
    ;;
esac
$echo " "
$echo "Trn has a number of auxiliary programs that need not be visible to the"
$echo "whole world.  Where do you want to put these private executables?"
$echo $n "[$dflt] $c"
. myread
rnlib="$ans"
case $rnlib in
  '') rnlib=$dflt ;;
esac
case $portable in
undef)
    rnlib=`filexp $rnlib`
    ;;
esac
: must not allow self reference
case $rnlib in
  /*)
    filexp=$rnlib/filexp
    ;;
  *)
    filexp=`pwd`/filexp
    ;;
esac

: find where to put private files for mthreads
case "$mtlib" in
'') dflt="$rnlib" ;;
*)  dflt="$mtlib" ;;
esac
cat <<'EOM'

Mthreads needs to create some private files (like active2, and maybe active1
and mt.log, depending on your setup).  These can go in the same directory as
the private executables, as long as it is writable by whoever runs mthreads.
Otherwise, a good place to put them is in your thread file directory.  Where
EOM
$echo $n "should these files be kept? [$dflt] $c"
. myread
mtlib="$ans"
case "$mtlib" in
'') mtlib=$dflt ;;
esac

: get the local distribution prefixes
if $test -f $libexp/sys ; then
    $sed <$libexp/sys -n -e "s/^$sitename://p" | \
    $sed -e "s/:.*//" -e "s/,/ /g" | tr ' ' '\012' | \
    $sed -e "/^to./d" -e "/^net$/d" -e "/^fa$/d" -e "/^mod$/d" > .distlist
fi

$cat <<'EOH'
 
Distribution groups are the things you use on the Distribution line to limit
where an article will go to.  You are likely to be a member of several
distribution groups, such as organization, city, state, province, country,
continent, etc.  For example, Los Angeles has the distribution prefix "la",
New Jersey has the prefix "nj", and Europe has the prefix "eunet".

The categories you will be asked are: 

local organization	(Could be just one machine or a cluster or an office)
organization		att, dec, kgb, ...
city			la, ny, mosc, ...
state/province		ca, nj, bc, ...
country			usa, can, rok, whatever
continent		na (North America, not "Not Applicable"), asia, etc.

(If you don't have a distribution prefix in any of these categories then
just hit return.)

EOH
if $test -f .distlist; then
    distlist=`tr '\012' ' ' <.distlist`
    if $test "$distlist" ; then
	$echo "(These are the distributions in your sys file: $distlist)"
	$echo " "
    fi
fi
case "$locpref" in
'') dflt="";;
*)  dflt="[$locpref] ";;
esac
$echo $n "What is the distribution prefix for your local organization? $dflt$c"
. myread
case "$ans" in
'') ;;
*)  locpref="$ans";;
esac
case $locpref in
  '') locpref=none ;;
esac
case "$orgpref" in
'') dflt="";;
*)  dflt="[$orgpref] ";;
esac
$echo $n "What is the distribution prefix for your organization? $dflt$c"
. myread
case "$ans" in
'') ;;
*)  orgpref="$ans";;
esac
case $orgpref in
  '') orgpref=none ;;
esac
case "$citypref" in
'') dflt="";;
*)  dflt="[$citypref] ";;
esac
$echo $n "What is the distribution prefix for your city? $dflt$c"
. myread
case "$ans" in
'') ;;
*)  citypref="$ans";;
esac
case $citypref in
  '') citypref=none ;;
esac
case "$statepref" in
'') dflt="";;
*)  dflt="[$statepref] ";;
esac
$echo $n "What is the distribution prefix for your state/province? $dflt$c"
. myread
case "$ans" in
'') ;;
*)  statepref="$ans";;
esac
case $statepref in
  '') statepref=none ;;
esac
case "$cntrypref" in
'') dflt="";;
*)  dflt="[$cntrypref] ";;
esac
$echo $n "What is the distribution prefix for your country? $dflt$c"
. myread
case "$ans" in
'') ;;
*)  cntrypref="$ans";;
esac
case $cntrypref in
  '') cntrypref=none ;;
esac
case "$contpref" in
'') dflt="";;
*)  dflt="[$contpref] ";;
esac
$echo $n "What is the distribution prefix for your continent? $dflt$c"
. myread
case "$ans" in
'') ;;
*)  contpref="$ans";;
esac
case $contpref in
  '') contpref=none ;;
esac

$echo " "
$echo "If you have any other distribution groups you will need to edit Pnews"
$echo "and newsetup to add them."
$echo " "

: determine root id
rootid=`$sed </etc/passwd -e "/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*"'$'"/\1/" -e "q" -e "}" -e "d"`
case $rootid in
  '') rootid=0 ;;
  *)  $echo "Root uid = $rootid" ;;
esac

: weed out incompatibilities
case $douname in
  define) whoami=undef ;;
esac

: preserve RCS keywords in files with variable substitution, grrr
Log='$Log'
Id='$Id'

: Warnings
if v7; then
    cat <<'EOM'
 
NOTE: the V7 compiler may ignore some #undefs that trn uses.  If so, you will
get messages about redefining EXT.  Some V7 compilers also have difficulties
with #defines near buffer boundaries, so beware.  You may have to play with
the spacing in common.h.
EOM
fi

if pdp11; then
    cat <<'EOM'
 
NOTE: the PDP-11 does not have enough data space to do subject caching
reliably.  That feature will be disabled automatically.  Subject searching
will tend to be slow.
EOM
fi
case "$isrrn" in
	define) ;;
	*) socketlib=""
	   rrninclude=""
	 ;;
esac

$echo " "
$echo "End of configuration questions."
$echo " "

: create config.sh file
$echo " "
$echo "Creating config.sh..."
$spitshell <<EOT >config.sh
$startsh
# config.sh
# This file was produced by running the Configure script.

n='$n'
c='$c'
libc='$libc'
sharedclib='$sharedclib'
eunicefix='$eunicefix'
eunice='$eunice'
cpp='$cpp'
shsharp='$shsharp'
startsh='$startsh'
spitshell='$spitshell'
test='$test'
expr='$expr'
sed='$sed'
echo='$echo'
cat='$cat'
rm='$rm'
mv='$mv'
cp='$cp'
tail='$tail'
tr='$tr'
mkdir='$mkdir'
sort='$sort'
uniq='$uniq'
inews='$inews'
grep='$grep'
egrep='$egrep'
nidump='$nidump'
ypmatch='$ypmatch'
contains='$contains'
lib='$lib'
libexp='$libexp'
nametype='$nametype'
cc='$cc'
cflags='$cflags'
iandd='$iandd'
rrninclude='$rrninclude'
termlib='$termlib'
jobslib='$jobslib'
socketlib='$socketlib'
getcwd='$getcwd'
getwd='$getwd'
setbuffer='$setbuffer'
setvbuf='$setvbuf'
dirtype='$dirtype'
dirinc='$dirinc'
ndirlib='$ndirlib'
libndir='$libndir'
usendir='$usendir'
ndirc='$ndirc'
ndiro='$ndiro'
posix='$posix'
pager='$pager'
mailer='$mailer'
internet='$internet'
rnbin='$rnbin'
filexp='$filexp'
distlist='$distlist'
Log='$Log'
Id='$Id'
sitename='$sitename'
hostfile='$hostfile'
domain='$domain'
orgname="$orgname"
isadmin='$isadmin'
newsadmin='$newsadmin'
rnlib='$rnlib'
mtlib='$mtlib'
mansrc='$mansrc'
manext='$manext'
mtmansrc='$mtmansrc'
mtmanext='$mtmanext'
maildir='$maildir'
spool='$spool'
serverspool='$serverspool'
active='$active'
myactive='$myactive'
activetimes='$activetimes'
mininact='$mininact'
pref='$pref'
defeditor='$defeditor'
rootid='$rootid'
mboxchar='$mboxchar'
locpref='$locpref'
orgpref='$orgpref'
citypref='$citypref'
statepref='$statepref'
cntrypref='$cntrypref'
contpref='$contpref'
strchr='$strchr'
memcpy='$memcpy'
rename='$rename'
ftruncate='$ftruncate'
usleep='$usleep'
uselect='$uselect'
strftime='$strftime'
foundsizet='$foundsizet'
xnxlib='$xnxlib'
chsize='$chsize'
tzset='$tzset'
threaddef='$threaddef'
selectdef='$selectdef'
threaddir='$threaddir'
syslog='$syslog'
novoid='$novoid'
novfork='$novfork'
sunos4='$sunos4'
portable='$portable'
passnam='$passnam'
berknam='$berknam'
usgnam='$usgnam'
whoami='$whoami'
termio='$termio'
termios='$termios'
fcntl='$fcntl'
ioctl='$ioctl'
ptem='$ptem'
normsig='$normsig'
sigblock='$sigblock'
sigret='$sigret'
sighold='$sighold'
getuidgid='$getuidgid'
havetlib='$havetlib'
getpwent='$getpwent'
gethostname='$gethostname'
douname='$douname'
phostname='$phostname'
hostcmd='$hostcmd'
norelay='$norelay'
rdchk='$rdchk'
isrrn='$isrrn'
xthread='$xthread'
serverfile='$serverfile'
ignoreorg='$ignoreorg'
NNTPSRC='$NNTPSRC'
CONFIG=true
EOT
CONFIG=true
$rm -f libc.list .distlist kit*isdone 

$echo "If you didn't make any mistakes, then just type a carriage return here."
$echo $n "If you need to edit config.sh, do it as a shell escape here: $c"
. myread
case "$ans" in
'') ;;
*) : in case they cannot read
    eval $ans;;
esac
. ./config.sh

$echo " "
$echo "Doing variable substitutions on various files..."
$echo " "
set `$grep <MANIFEST '\.SH' | awk '{print $1}'`
for file in $*; do
    . $file
done

$echo " "
$echo 'Now you need to generate make dependencies by running "makedepend".'
$echo 'You might prefer to run it in background: "makedepend > makedepend.out &"'
$echo $n "Would you like me to run it for you (it takes quite a while)? [n] $c" 
. myread
case "$ans" in
y*) ./makedepend;;
esac
$rm -f myread
: end of Configure
