#!/bin/sh
#	$Header: /usr/people/sam/fax/RCS/configure,v 1.145 1994/04/27 21:55:13 sam Rel $
#
# FlexFAX Facsimile Software
#
# Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994 Sam Leffler
# Copyright (c) 1991, 1992, 1993, 1994 Silicon Graphics, Inc.
# 
# Permission to use, copy, modify, distribute, and sell this software and 
# its documentation for any purpose is hereby granted without fee, provided
# that (i) the above copyright notices and this permission notice appear in
# all copies of the software and related documentation, and (ii) the names of
# Sam Leffler and Silicon Graphics may not be used in any advertising or
# publicity relating to the software without the specific, prior written
# permission of Sam Leffler and Silicon Graphics.
# 
# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
# 
# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
# OF THIS SOFTWARE.
#

# Configuration script for FlexFAX

#
# Shell script to setup machine-dependent files in
# preparation for building flexfax source.
#
RM="rm -f"
CP="cp"

PATH=/bin:/usr/bin:/etc
test -d /usr/ccs/bin && PATH=$PATH:/usr/ccs/bin		# SVR4/Solaris2
test -d /usr/sbin && PATH=$PATH:/usr/sbin		# SGI and others
test -d /usr/bsd && PATH=$PATH:/usr/bsd			# SGI
test -d /usr/ucb && PATH=$PATH:/usr/ucb			# Sun and others
test -d /usr/5bin && PATH=/usr/5bin:$PATH:/usr/etc	# Sun and others

applyEdits()
{
    file=$1; shift
    (for i do
	echo "$i";
     done; echo w; echo q) | ed - $file >/dev/null
}

#
# Apply a set of ed commands to a file.  If the
# file is initially setup read-only, then it is
# made writeable, edited, and then read-only again.
#
editFile()
{
    file=$1;
    if [ ! -w $file ]; then
	chmod +w $file
	applyEdits "$@"
	chmod -w $file
    else
	applyEdits "$@"
    fi
}

#
# Like editFile, but first save the original
# as file.orig, a la the patch program.
#
patchFile()
{
    file=$1;
    $RM $file.orig; $CP $file $file.orig
    if [ ! -w $file ]; then
	chmod +w $file
	applyEdits "$@"
	chmod -w $file
    else
	applyEdits "$@"
    fi
}

identifyTarget()
{
    random=`date | awk '{print $4}' | sed -e 's/.*://'` 2>/dev/null
    case "$random" in
    1*)	echo "Wow, you've got a $1 system!";;
    2*)	echo "Hmm, looks like a $1 system.";;
    3*)	echo "Oh no, not another $1 system...";;
    4*)	echo "Well I'll be, a $1 system.";;
    5*)	echo "Fee, fie, foe, this smells like a $1 system.";;
    *)	echo "Gosh, aren't you lucky to have a $1 system!";;
    esac
}

checkStrings()
{
    f=$1; shift
    strings $f | grep "$@" >/dev/null 2>&1
    return
}

#
# If no target is specified, try to deduce the system.
#
TARGET=$1
if [ -z "$TARGET" ]; then
    SYS=`uname -s` 2>/dev/null
    case @"$SYS" in
    @IRIX)	TARGET=sgi;;
    @UNIX_SV)	TARGET=svr4;;
    @Linux)	TARGET=linux;;
    @SunOS)	if [ -d /etc/saf ]; then
		    TARGET=solaris2 SYS="Solaris 2.x"
		else
		    TARGET=sun4
		fi
		;;
    @BSD/386)	TARGET=bsdi;;
    @4.4BSD)	TARGET=4.4bsd;;
    @386BSD)	TARGET=386bsd;;
    @FreeBSD)	TARGET=freebsd;;
    @HP-UX)	TARGET=hpux;;
    @*-Reno)	TARGET=reno;;
    @AIX)	TARGET=aix32;;
    @ULTRIX)	TARGET=ultrix;;
    @)		echo "Sorry, no target specified and no uname command!";exit 1;;
    *)		if [ -d /etc/saf ]; then
		    TARGET=svr4 SYS=SVR4
		elif checkStrings /unix 'SCO UNIX'; then
		    TARGET=sco SYS="SCO"
		elif checkStrings /unix 'INTERACTIVE UNIX'; then
		    TARGET=isc SYS="ISC"
		else
		    echo "Sorry, I don't grok a $SYS system."
		    exit 1
		fi
		;;
    esac
    identifyTarget $SYS
fi

warnUnfinished()
{
    README=port/$1/README
    if [ -f $README ]; then
	echo "Warning, this port is incomplete; read $README for more information."
    else
	echo "Warning, This port is incomplete and there is no README file."
    fi
}

warnNoMakeDepend()
{
    echo "Warning, no make dependency support for this compilation environment."
}

boom()
{
    echo "$@"
    echo ""
    echo "Unrecoverable error!  Once you've corrected the problem rerun this script."
    exit 1
}

case $TARGET in
sgi|sgi-cc)
    TARGET=sgi COMPILER=cc
    ;;
sun3|sun3-gcc|sun4|sun4-gcc)
    TARGET=sun COMPILER=gcc
    ;;
solaris2-cc)
    TARGET=solaris2 COMPILER=cc
    warnNoMakeDepend
    warnUnfinished $TARGET
    ;;
4.4bsd*|hpux|hpux-gcc|reno*|ultrix*)
    TARGET=`basename $TARGET -gcc` COMPILER=gcc
    warnUnfinished $TARGET
    ;;
hpux-cc)
    TARGET=hpux COMPILER=cc
    warnUnfinished $TARGET
    ;;
*)
    TARGET=`basename $TARGET -gcc` COMPILER=gcc
    if [ ! -d port/$TARGET ]; then
	echo "$TARGET: Unsupported system configuration."
	exit 1
    fi
    ;;
esac

#
# Random system-dependent fixups that have to be
# done before we go too far.
#
case $TARGET in
linux)
    ed()
    {
        sed -e '/^w$/d' -e '/^q$/d' > /tmp/ed.$$
        $CP $2 /tmp/file.$$
        sed -f /tmp/ed.$$ /tmp/file.$$ > $2
        $RM /tmp/ed.$$ /tmp/file.$$
    }
    ;;
ultrix)
    # must use GNU make 'cuz standard make doesn't hack it
    echo "Warning, prepending /usr/local/bin to PATH for GNU make."
    test -d /usr/local/bin && PATH=/usr/local/bin:$PATH
    ;;
esac

#
# Setup make-related files.
#
setupConfig()
{
    if [ -f port/$TARGET/Makefile.flexfax ]; then
	M=port/$TARGET/Makefile.flexfax
    elif [ -f port/$TARGET/Makefile ]; then
	M=port/$TARGET/Makefile
    else
	boom "Help, no \"Makefile\" for building FlexFAX!"
    fi
    if [ -f port/$TARGET/defs.$COMPILER ]; then
	D=port/$TARGET/defs.$COMPILER
    elif [ -f port/$TARGET/defs ]; then
	D=port/$TARGET/defs
    else
	boom "Help, no \"defs\" file for building FlexFAX!"
    fi
    echo "Installing $M as Makefile."
    $RM Makefile; $CP $M Makefile
    echo "Installing $D as defs."
    $RM defs; $CP $D defs
}
getConfigTag()
{
    param=`grep "$1:" $2 | sed -e 's/.*:[ 	]*\([^ 	]*\).*/\1/'`
}

echo "Setting up make-related files."
if [ -f defs -a -f Makefile ]; then
    getConfigTag TARGET defs;	target="$param"
    getConfigTag COMPILER defs;	compiler="$param"
    if [ "$target" != "$TARGET" -o "$compiler" != "$COMPILER" ]; then
	echo "Replacing configuration for \"$target\" & \"$compiler\"."
	setupConfig
    else
	#
	# We should figure out if only localized changes were
	# done to defs and/or Makefile and leave things unchanged;
	# but for now that's too hard so we just cloberr things
	# under the assumption that folks don't configure very
	# often and doing something simpleminded can lead to problems.
	#
	echo "Updating configuration for \"$target\" & \"$compiler\"."
	setupConfig
    fi
else
    setupConfig
fi

#
# Verify that defs has correct C++ and C compiler definitions.
#
(cat defs; echo 'test: ${C++} ${CC}') | make -f - test >/dev/null 2>&1 || {
    echo ""
    echo "Something is wrong in the \"defs\" file, check the definitions of"
    echo "the C++ and CC macros:"
    echo ""
    grep '^C++[ 	]*=' defs; grep '^CC[ 	]*=' defs
    echo ""
    boom "they do not appear to reflect the locations of your compilers."
}

NewFixed=""
if [ $COMPILER = gcc ]; then
    GCCversion=`(cat defs; echo 'version: ${C++}; ${C++} -v') | \
	make -f - version 2>&1 | \
	sed -n -e '/version/s/.* //p'`
    if expr "$GCCversion" \< 2.3.3 >/dev/null 2>&1; then
	echo ""
	echo "You appear to have gcc version $GCCversion; beware that you"
	echo "may need to apply the patch in port/sun/GCC-PATCH before you"
	echo "compile this software."
	echo ""
    else
	# NB: defined in port.h below
	NewFixed="yes"
    fi
    if [ $GCCversion = 2.5.8 -a $TARGET = sgi ]; then
	echo ""
	echo "Beware that you must build this version of gcc according to the"
	echo "information given in port/sgi/README in order to get a working"
	echo "system."
	echo ""
    fi
fi

if [ $TARGET != "sgi" ]; then
    echo "Setting up make dependency files."
    #
    # Setup null make dependency files so that we can include
    # it w/o problem.  Some systems have conditional include
    # support in their make, but others do not, so we use an
    # unconditional include and setup everthing as null here
    #
    DEPEND="Makedepend		\
	fax2ps/Makedepend	\
	faxalter/Makedepend	\
	faxcover/Makedepend	\
	faxd/Makedepend		\
	faxmail/Makedepend	\
	faxrm/Makedepend	\
	faxstat/Makedepend	\
	iv/Makedepend		\
	recvfax/Makedepend	\
	sendfax/Makedepend	\
	sgi2fax/Makedepend	\
	util/Makedepend		\
	man/Makedepend		\
	doc/Makedepend		\
	etc/Makedepend		\
	relnotes/Makedepend	\
	libtiff/Makedepend	\
	port/$TARGET/Makedepend	\
	"
    $RM $DEPEND; tee $DEPEND </dev/null
    editFile rules '/^sinclude/s//include/'
fi

#
# Install appropriate TIFF library Makefile: look first
# in the port area, then for a Makefile that is part of
# the standard TIFF distribution.  The priority is:
#
# port/<target>/Makefile.libtiff.<compiler>
# port/<target>/Makefile.libtiff
# port/generic/Makefile.libtiff.<compiler>
# port/libtiff/Makefile.<target>-<compiler>
# port/libtiff/Makefile.<target>
# port/libtiff/Makefile.<compiler>
#
if [ -f port/$TARGET/Makefile.libtiff.$COMPILER ]; then
    M=port/$TARGET/Makefile.libtiff.$COMPILER
elif [ -f port/$TARGET/Makefile.libtiff ]; then
    M=port/$TARGET/Makefile.libtiff
elif [ -f port/generic/Makefile.libtiff.$COMPILER ]; then
    M=port/generic/Makefile.libtiff.$COMPILER
elif [ -f libtiff/Makefile.$TARGET-$COMPILER ]; then
    M=libtiff/Makefile.$TARGET-$COMPILER
elif [ -f libtiff/Makefile.$TARGET ]; then
    M=libtiff/Makefile.$TARGET
elif [ -f libtiff/Makefile.$COMPILER ]; then
    M=libtiff/Makefile.$COMPILER
else
    boom "Can not locate Makefile for building the TIFF software."
fi
echo "Installing $M as libtiff/Makefile."
$RM libtiff/Makefile; $CP $M libtiff/Makefile

#
# Some makes can not deal with certain types of
# whitespace-filled lines that occasionally creep
# in--so purge anything strange before compiling.
#
badMakefiles=`grep -l '^	$' Makefile */Makefile`
if [ "$badMakefiles" ]; then
    #
    # This bizarre stuff is used instead of just doing
    # editFile $m '^<tab>$/s///' because some shells
    # appear to convert the tab to a blank!
    #
    echo '/^	$/s///' | tr ' ' '\011' >/tmp/$$ed
    echo w >>/tmp/$$ed; echo q >>/tmp/$$ed
    echo "Fixing up bad make files:"
    for m in $badMakefiles; do
	echo "  $m"
	chmod +w $m; cat /tmp/$$ed | ed - $m >/dev/null; chmod -w $m
    done
    $RM /tmp/$$ed
fi

patchForBogusIncludeSyntax()
{
    echo "Warning, patching Makefile stuff to use bogus include syntax."
    for i do
	patchFile $i "g/^include/s/^include[  ]*\(.*\)$/.include <\1>/"
    done
}

patchForBogusSunPro()
{
    echo "Warning, patching $1 to use SunPro file.c++=.C syntax."
    patchFile $1 "$2"
}

patchShellScripts()
{
    shell=$1
    for i in etc/faxaddmodem.sh etc/probemodem.sh util/notify.sh util/*stats.sh
    do
	echo "Warning, patching $i to use $shell"
	patchFile $i "/^#! /s;/bin/sh;$shell;"
    done
}

case "$TARGET-$COMPILER" in
386bsd*|freebsd*|ultrix*|bsdi*)
    patchShellScripts /bin/bash
    ;;
hpux*)
    patchShellScripts /bin/ksh
    ;;
bsdi-gcc)
    $RM port/$TARGET/stdio.h; $CP /usr/include/stdio.h port/$TARGET
    editFile port/$TARGET/stdio.h '/static inline int/s//static int/'
    ;;
reno*|4.4bsd*)
    patchForBogusIncludeSyntax Makefile rules */Makefile
    ;;
solaris2-cc)
    #
    # Yech, the SunPro C++ compiler has no option to force a source
    # file w/ a .c++ suffix to be treated as C++ source code; instead one
    # must specify file.c++=.C.  We patch the Makefiles with explicit
    # construction rules to do this...
    #
    patchForBogusSunPro rules 'g/\\$</s//&=.C/'
    patchForBogusSunPro iv/Makefile 'g/-c.*\\.c++$/s/.c++/&=.C/'
    patchForBogusSunPro faxd/Makefile '/^[ 	]*UUCPLock.c++$/s//&=.C/'
    patchForBogusSunPro util/Makefile '/^[ 	]*textfmt.c++$/s//&=.C/'
    ;;
esac

#
# Figure out if certain system-specific interfaces are
# supported.  We craft a port.h file that has external
# declarations for missing routines that are required by
# the system and modify defs to reflect which optional
# interfaces are supported.
#

EmitCPlusPlusPrologue()
{
    echo '/*'
    echo ' * Warning, this file was automatically created by the configure script'
    echo ' * DATE:	' `date`
    echo ' * TARGET:	' $TARGET
    if [ $COMPILER = gcc ]; then
	echo ' * COMPILER:	' $COMPILER $GCCversion
    else
	echo ' * COMPILER:	' $COMPILER
    fi
    echo ' */'
    echo "#ifndef $1"
    echo '#ifdef __cplusplus'
    echo 'extern "C" {'
    echo '#endif'
}

EmitCPlusPlusEpilogue()
{
    echo '#ifdef __cplusplus'
    echo '}'
    echo '#endif'
    echo '#endif'
}

#
# Look for a function in one of the standard libraries.
#
CheckFunc()
{
    echo "extern int $1(); main(){$1();exit(0);}" >t.c
    (echo DEPTH=.; cat defs; echo 't:; ${CCF} t.c') |\
     make -f - t >/dev/null 2>&1
    return
}

#
# Look for a function declaration in system include files.
#
AddFuncDecl()
{
    (echo "$2"; echo "... add function prototype for $1" 1>&2)
}
CheckForFuncDecl()
{
    f=$1; shift
    (for i do
	echo "#include \"$i\""
     done)>t.c++
    (echo DEPTH=.; cat defs; echo 't:; ${C++F} ${C++FILE} -E t.c++') |\
     make -f - t 2>&1 |\
     awk '{while($0~/[,(][ \t]*$/){printf"%s",$0;getline}print}' |\
     grep "$f[ ]*(.*)" >/dev/null
    return
}
CheckFuncDecl()
{
    f=$1; shift
    decl=$1; shift
    CheckForFuncDecl "$f" "$@" || AddFuncDecl "$f" "$decl"
}

#
# Look for a variable declaration in system include files.
#
CheckVarDecl()
{
    v=$1; shift
    decl=$1; shift
    (for i do
	echo "#include \"$i\""
     done)>t.c++
    (echo DEPTH=.; cat defs; echo 't:; ${C++F} ${C++FILE} -E t.c++') |\
     make -f - t 2>&1 |\
     grep "$v" >/dev/null ||\
    (echo "$decl"; echo "... add declaration $decl" 1>&2)
}

#
# Look for a #define in system include files.
#
AddDefine()
{
   echo '#ifndef' $1
   echo '#define' "$2"
   echo '#endif'
   echo '... add #define for' "$1" 1>&2
}
CheckForDefine()
{
    def=$1; shift
    (for i do
	echo "#include \"$i\""
     done
     for i in "#ifdef $def" "FOUND" "#endif"; do
	echo "$i"
     done
    )>t.c
    (echo DEPTH=.; cat defs; echo 't:; ${CCF} -E t.c') |\
     make -f - t 2>&1 |\
     grep FOUND >/dev/null
    return
}
CheckDefine()
{
    def=$1; shift
    decl=$1; shift
    CheckForDefine "$def" "$@" || AddDefine "$def" "$decl"
}

#
# Look for an include file.
#
CheckForIncludeFile()
{
    (for i do
	echo "#include \"$i\""
     done)>t.c++
    (echo DEPTH=.; cat defs; echo 't:; ${C++F} ${C++FILE} -E t.c++') |\
     make -f - t >/dev/null 2>&1
    return
}

CheckTermioFuncDecls()
{
    CheckFuncDecl cfsetospeed \
	'extern int cfsetospeed(const struct termios*, speed_t);' $@
    CheckFuncDecl cfsetispeed \
	'extern int cfsetispeed(const struct termios*, speed_t);' $@
    CheckFuncDecl tcgetattr 'extern int tcgetattr(int, struct termios*);' $@
    CheckFuncDecl tcsetattr \
	'extern int tcsetattr(int, int, const struct termios*);' $@
    CheckFuncDecl tcsendbreak 'extern int tcsendbreak(int, int);' $@
    CheckFuncDecl tcdrain 'extern int tcdrain(int);' $@
    CheckFuncDecl tcflush 'extern int tcflush(int, int);' $@
    CheckFuncDecl tcflow 'extern int tcflow(int, int);' $@
}

JUNK="xport.h xtermios.h t.c t.c++ a.out"
trap "$RM \$JUNK; exit 1" 1 2 15

$RM xport.h port.h xtermios.h termios.h a.out t t.c t.c++

CheckForIncludeFile termios.h || {
    CheckForIncludeFile sys/termios.h || {
	boom "Cannot locate termios.h or sys/termios.h."
    }
    echo "No termios.h found; creating one with necessary definitions."
    (EmitCPlusPlusPrologue _TERMIOS_
     echo '#include "sys/termios.h"'
     CheckTermioFuncDecls sys/termios.h
     EmitCPlusPlusEpilogue
    )>xtermios.h
    mv xtermios.h termios.h; chmod 444 termios.h
}

echo "Creating port.h with necessary definitions."

(EmitCPlusPlusPrologue _PORT_
test "$NewFixed" = "yes"	&& echo '#define NEW_FIXED'
fifoOpenMode="O_RDONLY"
case $TARGET in
solaris2)
    echo "... enable Solaris 2.x workaround for FIFO select bug" 1>&2
    echo '#define FIFOSELECTBUG'
    ;;
sgi)
    # enable workarounds for IRIX 5.x kernel bugs
    case "`uname -a | cut '-d ' -f3`" in
    5.[012]*)
	echo "... enable IRIX 5.x workarounds for FIFO and select bugs" 1>&2
	echo '#define FIFOSELECTBUG'
	echo '#define SGISELECTBUG'
	;;
    esac
    ;;
sco|isc)
    echo "... enable additional include files for TIOCGWINSZ" 1>&2
    echo "#define CONFIG_WINSZHACK"
    fifoOpenMode="O_RDWR"
    ;;
aix32|ultrix|hpux)
    fifoOpenMode="O_RDWR"
    ;;
esac
if [ "$fifoOpenMode" = "O_RDWR" ]; then
    echo "... open FIFO files read+write to avoid select bug" 1>&2
else
    echo "... open FIFO files read-only" 1>&2
fi
echo "#define CONFIG_OPENFIFO $fifoOpenMode"
CheckFuncDecl mkstemp 'extern int mkstemp(char *);' stdio.h unistd.h
CheckFuncDecl strerror 'extern char* strerror(int);' string.h
CheckFuncDecl strncasecmp \
    'extern int strncasecmp(const char*, const char*, size_t);' string.h
CheckFuncDecl strcasecmp \
    'extern int strcasecmp(const char*, const char*);' string.h
CheckFuncDecl strdup 'extern char* strdup(const char*);' string.h
CheckFuncDecl memset 'extern void* memset(void*, int, size_t);' string.h
CheckFuncDecl random 'extern long random(void);' math.h stdlib.h
CheckFuncDecl floor 'extern double floor(double);' math.h
CheckFuncDecl waitpid 'extern pid_t waitpid(pid_t, int *, int);' sys/wait.h
CheckDefine _POSIX_OPEN_MAX '_POSIX_OPEN_MAX 16' limits.h
CheckDefine howmany 'howmany(x, y)	(((x)+((y)-1))/(y))' sys/types.h
CheckForFuncDecl sigvec signal.h || {
    echo '#ifdef SV_INTERRUPT'
    echo 'struct sigvec;'
    AddFuncDecl sigvec \
	'extern int sigvec(int, const struct sigvec*, struct sigvec*);'
    echo '#endif'
}
CheckForFuncDecl sigaction signal.h || {
    echo '#ifdef SA_NOCLDSTOP'
    echo 'struct sigaction;'
    AddFuncDecl sigaction \
	'extern int sigaction(int, const struct sigaction*, struct sigaction*);'
    echo '#endif'
}
CheckFuncDecl kill 'extern int kill(pid_t, int);' signal.h
CheckFuncDecl close 'extern int close(int);' unistd.h
CheckFuncDecl getuid 'extern uid_t getuid(void);' unistd.h
CheckFuncDecl geteuid 'extern uid_t geteuid(void);' unistd.h
CheckFuncDecl seteuid 'extern int seteuid(uid_t);' unistd.h
CheckFuncDecl setegid 'extern int setegid(gid_t);' unistd.h
CheckFuncDecl ftruncate 'extern int ftruncate(int, off_t);' unistd.h
CheckFuncDecl getdtablesize 'extern int getdtablesize(void);' unistd.h
#
# unistd.h is where many people put it
# sys/select.h is for USL-derived code
# sys/time.h is for HP systems (sigh)
#
CheckForFuncDecl select unistd.h sys/select.h sys/time.h || {
    echo 'struct fd_set;'
    echo 'struct timeval;'
    AddFuncDecl select \
	'extern int select(int,struct fd_set*,struct fd_set*,struct fd_set*,struct timeval*);'
}
CheckFuncDecl unlink 'extern int unlink(const char*);' unistd.h
CheckFuncDecl read 'extern int read(int, const void*, unsigned int);' unistd.h
CheckFuncDecl ioctl 'extern int ioctl(int, int, ...);' unistd.h sys/ioctl.h
CheckFunc fchown && {
    echo '#define HAS_FCHOWN 1'
    echo "... configure use of fchown" 1>&2
    CheckFuncDecl fchown 'extern int fchown(int, uid_t, gid_t);' unistd.h
}
CheckFuncDecl gethostname 'extern int gethostname(char*, int);' unistd.h osfcn.h
CheckFuncDecl malloc 'extern void* malloc(size_t);' stdlib.h
CheckFuncDecl realloc 'extern void* realloc(void*, size_t);' stdlib.h
CheckFuncDecl free 'extern void free(void*);' stdlib.h
CheckFuncDecl strtoul \
    'extern unsigned long strtoul(const char*, char**, int);' stdlib.h
CheckFuncDecl cuserid 'extern char* cuserid(char*);' stdio.h
#
# unistd.h is for sco3.2v4.[0-2]
#
CheckFuncDecl getopt \
    'extern int getopt(int, char* const*, const char*);' stdlib.h unistd.h
CheckFuncDecl isatty 'extern int isatty(int);' stdlib.h unistd.h
CheckVarDecl 'char.*optarg' 'extern char* optarg;' stdlib.h
CheckVarDecl 'int.*opterr' 'extern int opterr;' stdlib.h
CheckVarDecl 'int.*optind' 'extern int optind;' stdlib.h
CheckFuncDecl mktemp 'extern char* mktemp(char*);' stdio.h unistd.h
CheckFuncDecl tempnam 'extern char* tempnam(const char*, const char*);' stdio.h
CheckFuncDecl popen 'extern FILE* popen(const char *, const char *);' stdio.h
CheckFuncDecl pclose 'extern int pclose(FILE*);' stdio.h
CheckFuncDecl fdopen 'extern FILE* fdopen(int, const char*);' stdio.h
CheckForDefine fileno stdio.h || {
    CheckFuncDecl fileno 'extern int fileno(FILE*);' stdio.h
}
CheckFuncDecl opendir 'extern DIR* opendir(const char*);' dirent.h
CheckFuncDecl syslog 'extern void syslog(int, const char*, ...);' syslog.h
CheckForFuncDecl vsyslog syslog.h || {
    echo '#include <stdarg.h>'
    AddFuncDecl vsyslog 'extern void vsyslog(int, const char*, va_list);'
}
CheckFuncDecl closelog 'extern void closelog(void);' syslog.h
CheckFuncDecl openlog 'extern void openlog(const char*, int, int);' syslog.h
CheckFunc fchmod && {
    echo '#define HAS_FCHMOD 1'
    echo "... configure use of fchmod" 1>&2
    CheckFuncDecl fchmod 'extern int fchmod(int, mode_t);' \
	unistd.h libc.h osfcn.h sys/stat.h
}
if [ "$TARGET-$COMPILER" = "solaris2-cc" ]; then
    #
    # SunPro pre-processor leaves comments in!  This messes up
    # the scheme used by CheckFuncDecl 'cuz time.h has a comment
    # in it that includes "gettimeofday(2)".  Sigh...
    #
    AddFuncDecl gettimeofday \
	'extern int gettimeofday(struct timeval*, struct timezone*);'
else
    CheckForFuncDecl gettimeofday sys/time.h || {
	echo 'struct timezone;'
	echo 'struct timeval;'
	AddFuncDecl gettimeofday \
	    'extern int gettimeofday(struct timeval*, struct timezone*);'
    }
fi
CheckForFuncDecl strftime time.h || {
    echo 'struct tm;'
    AddFuncDecl strftime \
	'extern size_t strftime(char*,size_t,const char*,const struct tm*);'
}
CheckForFuncDecl localtime time.h || {
    echo 'struct tm;'
    AddFuncDecl localtime 'struct tm* localtime(const time_t* clock);'
}
CheckForFuncDecl setitimer sys/time.h || {
    echo '#ifdef ITIMER_REAL'
    echo 'struct itimerval;'
    AddFuncDecl setitimer \
	'extern int setitimer(int,struct itimerval*,struct itimerval*);'
    echo '#endif'
}
CheckFuncDecl endpwent 'extern void endpwent(void);' pwd.h
CheckFuncDecl getpwnam 'extern struct passwd* getpwnam(const char*);' pwd.h
if [ "$TARGET" != "reno" ]; then
    CheckFuncDecl toupper 'extern int toupper(int);' ctype.h
    CheckFuncDecl tolower 'extern int tolower(int);' ctype.h
fi
CheckFuncDecl getpeername 'extern int getpeername(int,void*,int*);' sys/socket.h
CheckFuncDecl socket 'extern int socket(int, int, int);' sys/socket.h
CheckFuncDecl connect 'extern int connect(int, const void*, int);' sys/socket.h
CheckForFuncDecl gethostbyname netdb.h || {
    echo 'struct hostent;'
    AddFuncDecl gethostbyname \
	'extern struct hostent* gethostbyname(const char*);'
}
CheckForFuncDecl gethostbyaddr netdb.h || {
    echo 'struct hostent;'
    AddFuncDecl gethostbyaddr \
	'extern struct hostent* gethostbyaddr(const void*, int, int);'
}
CheckForFuncDecl getservbyname netdb.h || {
    echo 'struct servent;'
    AddFuncDecl getservbyname \
	'extern struct servent*	getservbyname(const char*, const char*);'
}
CheckForDefine LOCK_SH sys/file.h || {
    AddDefine LOCK_SH 'LOCK_SH	1	/* shared lock */'
    AddDefine LOCK_EX 'LOCK_EX	2	/* exclusive lock */'
    AddDefine LOCK_NB 'LOCK_NB	4	/* dont block when locking */'
    AddDefine LOCK_UN 'LOCK_UN	8	/* unlock */'
}
CheckFuncDecl flock 'extern int flock(int, int);' sys/file.h
CheckTermioFuncDecls termios.h
EmitCPlusPlusEpilogue
)>xport.h
mv xport.h port.h; chmod 444 port.h
$RM $JUNK

#
# Figure out which brand of echo we have and define
# prompt and print shell functions accordingly.
#
if [ `echo foo\\\c`@ = "foo@" ]; then
    prompt()
    {
       echo "$* \\c"
    }
elif [ "`echo -n foo`@" = "foo@" ]; then
    prompt()
    {
       echo -n "$* "
    }
else
    prompt()
    {
	echo "$*"
    }
fi

#
# Prompt the user for a string that can not be null.
#
promptForNonNullStringParameter()
{
    x=""
    while [ -z "$x" ]; do
	prompt "$2 [$1]?"; read x
	if [ "$x" ]; then
	    # strip leading and trailing white space
	    x=`echo "$x" | sed -e 's/^[ 	]*//' -e 's/[ 	]*$//'`
	else
	    x="$1"
	fi
    done
    param="$x"
}

#
# Prompt the user for a numeric value.
#
promptForNumericParameter()
{
    x=""
    while [ -z "$x" ]; do
	prompt "$2 [$1]?"; read x
	if [ "$x" ]; then
	    # strip leading and trailing white space
	    x=`echo "$x" | sed -e 's/^[ 	]*//' -e 's/[ 	]*$//'`
	    match=`expr "$x" : "\([0-9]*\)"`
	    if [ "$match" != "$x" ]; then
		echo ""
		echo "This must be entirely numeric; please correct it."
		echo ""
		x="";
	    fi
	else
	    x="$1"
	fi
    done
    param="$x"
}

promptForLockType()
{
    x=""
    while [ -z "$x" ]; do
	prompt "Type of uucp lock files [$UUCP_LOCKTYPE]?"; read x
	if [ "$x" ]; then
	    # strip leading and trailing white space
	    x=`echo "$x" | sed -e 's/^[ 	]*//' -e 's/[ 	]*$//'`
	    if [ "$x" != "ascii" -a "$x" != "binary" ]; then
cat <<EOF

"$x" is not a uucp lock type; choose either "ascii"
for System V-style lock files with ascii contents or
"binary" for BSD-style lock files with binary contents.
EOF
		x=""
	    fi
	else
	    x="$UUCP_LOCKTYPE"
	fi
    done
    UUCP_LOCKTYPE="$x"
}

promptForImagerPackage()
{
    x=""
    while [ -z "$x" ]; do
	prompt "PostScript imager package [$PSPACKAGE]?"; read x
	if [ "$x" ]; then
	    # strip leading and trailing white space
	    x=`echo "$x" | sed -e 's/^[ 	]*//' -e 's/[ 	]*$//'`
	    case "$x" in
	    [dD]ps|DPS)			x="dps";;
	    [gG]s|[gG]host[sS]cript)	x="gs";;
	    *)
cat <<EOF

"$x" is not a PostScript imager package; choose either "dps"
for Display PostScript on a Silicon Graphics machine or "gs"
for the freely available Ghostscript package.
EOF
		x="";;
	    esac
	else
	    x="$PSPACKAGE"
	fi
    done
    PSPACKAGE="$x"
}

promptForPageSize()
{
    x=""
    while [ -z "$x" ]; do
	prompt "Default page size [$PAGESIZE]?"; read x
	if [ "$x" ]; then
	    # strip leading and trailing white space
	    x=`echo "$x" | sed -e 's/^[ 	]*//' -e 's/[ 	]*$//'`
	    # search pagesizes file for an entry
	    y=`sed -e '/^#/d' $1 | grep -i "$x" | sed -e 's/	.*//;q'`
	    if [ -z "$y" ]; then
		cat<<EOF

"$x" is not a known page size; the following are known page sizes:

Name			Abbrev	Width	Height	Width	Height	Top	Left
EOF
		sed -e '/^#/d' -e '/^default/d' $1
		echo ""
		x=""
	    else
		x="$y"
	    fi
	else
	    x="$PAGESIZE"
	fi
    done
    PAGESIZE="$x"
}

#
# Prompt the user for a numeric value.
#
promptForVRes()
{
    x=""
    while [ -z "$x" ]; do
	prompt "Default vertical res (lpi) [$FAX_DEFVRES]?"; read x
	if [ "$x" ]; then
	    # strip leading and trailing white space
	    x=`echo "$x" | sed -e 's/^[ 	]*//' -e 's/[ 	]*$//'`
	    case "$x" in
	    98|low|med*)	x="98";;
	    196|high|fine)	x="196";;
	    *)
cat <<EOF

"$x" is not a valid vertical resolution; choose either "98" lines/inch
(low resolution) or "196" lines/inch (often called fine resolution).

EOF
		x="";;
	    esac
	else
	    x="$FAX_DEFVRES"
	fi
    done
    FAX_DEFVRES="$x"
}

getParameter()
{
    param=`grep "^$1[ 	]*=" $2 | \
	sed -e 's/#.*//' -e 's/.*=[ 	]*//' -e 's/[ 	]*$//'`
}
getPageSizeInfo()
{
    pat=`grep '^default' $1 | \
	sed -e 's/default[	 ]*//' -e 's/[ 	][ 	]*/\[ 	\]*/g'`
    param=`grep "$pat" $1 | sed -e 's/	.*//;q'`
}
getUtilParameter()
{
    param=`grep "$1" $2 | sed -e "s/.*$1[ 	]*\([^	 ]*\).*/\1/"`
}

getProtoParameters()
{
    file=$1;
    getParameter BIN $file; 			FAX_BINDIR="$param"
    getParameter LIBDATA $file; 		FAX_LIBDATA="$param"
    getParameter LIBEXEC $file; 		FAX_LIBEXEC="$param"
    getParameter SPOOL $file; 			FAX_SPOOLDIR="$param"
    getParameter USRETC $file;			USRETC="$param"
    getParameter MAN $file; 			MAN="$param"
    getParameter DOC $file; 			DOC="$param"
    getParameter PSPACKAGE $file;		PSPACKAGE="$param"
    getParameter AFMDIR $file;			AFMDIR="$param"
    getParameter UUCP_LOCKTYPE $file;		UUCP_LOCKTYPE="$param"
    getParameter UUCP_LOCKMODE $file;		UUCP_LOCKMODE="$param"
    getParameter UUCP_LOCKDIR $file;		UUCP_LOCKDIR="$param"
    getParameter PSIMAGER $file;		PSIMAGER="$param"
    getParameter SENDMAIL $file;		SENDMAIL="$param"
    getPageSizeInfo util/pagesizes;		PAGESIZE="$param"
    getUtilParameter FAX_DEFVRES util/config.h;	FAX_DEFVRES="$param"
}

saveProtoParameters()
{
    protoFAX_BINDIR="$FAX_BINDIR"
    protoFAX_LIBDATA="$FAX_LIBDATA"
    protoFAX_LIBEXEC="$FAX_LIBEXEC"
    protoFAX_LIBFILTER="$FAX_LIBFILTER"
    protoFAX_SPOOLDIR="$FAX_SPOOLDIR"
    protoUSRETC="$USRETC"
    protoMAN="$MAN"
    protoDOC="$DOC"
    protoPSPACKAGE="$PSPACKAGE"
    protoAFMDIR="$AFMDIR"
    protoUUCP_LOCKTYPE="$UUCP_LOCKTYPE"
    protoUUCP_LOCKMODE="$UUCP_LOCKMODE"
    protoUUCP_LOCKDIR="$UUCP_LOCKDIR"
    protoSENDMAIL="$SENDMAIL"
    protoPAGESIZE="$PAGESIZE"
    protoFAX_DEFVRES="$FAX_DEFVRES"
}

printConfig()
{
    cat<<EOF

FlexFAX configuration parameters are:

Directory for applications:	$FAX_BINDIR
Directory for lib data files:	$FAX_LIBDATA
Directory for lib executables:	$FAX_LIBEXEC
Directory for servers:		$USRETC
Directory for manual pages:	$MAN
Directory for documentation:	$DOC
Directory for spooling:		$FAX_SPOOLDIR
Type of uucp lock files:	$UUCP_LOCKTYPE
Directory for uucp lock files:	$UUCP_LOCKDIR
Mode for uucp lock files:	$UUCP_LOCKMODE
PostScript imager packaage:	$PSPACKAGE
PostScript imager program:	$PSIMAGER
Default page size:		$PAGESIZE
Default vertical res (lpi):	$FAX_DEFVRES
Directory for font metrics:	$AFMDIR
Location of sendmail program:	$SENDMAIL

EOF
}

bitchExecutable()
{
    echo ""
    echo "Warning, $1 does not seem to be an executable program;"
    echo "you'll need to correct this before starting up the fax server."
}

checkForExecutable()
{
    test -x $1 || bitchExecutable $1
}

bitchDirectory()
{
    echo ""
    echo "Warning, $1 does not seem to be a directory;"; shift
    for i do
	echo "$i";
    done
}

checkDirectory()
{
    dir=$1; shift
    test -d $dir || bitchDirectory $dir "$@"
}

checkFont()
{
    test -r $AFMDIR/$1 -o -r $AFMDIR/$1.afm
    return
}

checkAFMSetup()
{
    if [ -d $AFMDIR ]; then
	# check for minimal font metrics required by textfmt
	checkFont Courier || cat<<EOF

Warning, no font metric information was found for the Courier font
in the directory $AFMDIR.  This means that text formatting
will not look right.  You need either to correct the AFMDIR parameter
in the defs file and/or install the font metrics for use with this
software (see the README file).
EOF
	checkFont Courier-Bold || cat<<EOF

Warning, no font metric information was found for the Courier-Bold font
in the directory $AFMDIR.  This means that the default handling
of ASCII text will fail because the typerules file converts text to
PostScript using this font.  You need to either correct the AFMDIR
definition in the defs file, install the font metrics for use with this
software (see the README file), or alter the typerules file to use a font
for which there are font metrics.
EOF
    else
	bitchDirectory $AFMDIR \
"this means that only a crummy builtin font will be available for imaging text."
    fi
}

checkPSImagerSetup()
{
    if test -x $PSIMAGER; then
	if [ "$PSPACKAGE" = "gs" ]; then
	    # verify Ghostscript was linked with the tiffg3 device driver
	    ($PSIMAGER -sDEVICE=tiffg3 </dev/null >/dev/null 2>&1) || cat<<EOF

Warning, the PostScript imaging program $PSIMAGER does not appear to be
to be configured with the tiffg3 device driver.  This is necessary for the
fax software to operate correctly.  See the README file for information
on building Ghostscript with the necessary TIFF driver.
EOF
	fi
    else
	bitchExecutable $PSIMAGER
    fi
}

#
# Setup general configuration parameters.
#
getProtoParameters defs
saveProtoParameters

# convert uucp lock type to something understandable
case "$UUCP_LOCKTYPE" in
1) UUCP_LOCKTYPE="binary";;
*) UUCP_LOCKTYPE="ascii";;	# default
esac

ok=skip
while [ "$ok" != "" -a "$ok" != "y" -a "$ok" != "yes" ]; do
    if [ "$ok" != "skip" ]; then
	promptForNonNullStringParameter "$FAX_BINDIR" \
	    "Directory to install applications";	FAX_BINDIR="$param"
	promptForNonNullStringParameter "$FAX_LIBDATA" \
	    "Directory to install library data files";	FAX_LIBDATA="$param"
	promptForNonNullStringParameter "$FAX_LIBEXEC" \
	    "Directory to install library executables";	FAX_LIBEXEC="$param"
	promptForNonNullStringParameter "$USRETC" \
	    "Directory to install server programs";	USRETC="$param"
	promptForNonNullStringParameter "$MAN" \
	    "Directory to install manual pages";	MAN="$param"
	promptForNonNullStringParameter "$DOC" \
	    "Directory to install documentation";	DOC="$param"
	promptForNonNullStringParameter "$FAX_SPOOLDIR" \
	    "Directory to setup server spooling area";	FAX_SPOOLDIR="$param"
	promptForLockType;
	promptForNonNullStringParameter "$UUCP_LOCKDIR" \
	    "Directory for uucp lock files";		UUCP_LOCKDIR="$param"
	promptForNumericParameter "$UUCP_LOCKMODE" \
	    "Protection mode for uucp lock files";	UUCP_LOCKMODE=$param;
	promptForImagerPackage;
	promptForNonNullStringParameter "$PSIMAGER" \
	    "PostScript imager program";		PSIMAGER="$param"
	promptForPageSize util/pagesizes;
	promptForVRes;
	promptForNonNullStringParameter "$AFMDIR" \
	    "Directory to find Adobe font metrics";	AFMDIR="$param"
	promptForNonNullStringParameter "$SENDMAIL" \
	    "Location of sendmail program";		SENDMAIL="$param"
    fi
    checkDirectory $USRETC \
"this must be fixed before doing a make install of faxd and faxd.recv."
    checkAFMSetup
    checkPSImagerSetup
    checkForExecutable $SENDMAIL
    # make sure UUCP_LOCKMODE is an octal number
    if [ "`expr "$UUCP_LOCKMODE" : '\(.\)'`" != "0" ]; then
	UUCP_LOCKMODE="0${UUCP_LOCKMODE}"
    fi
    printConfig; prompt "Are these ok [yes]?"; read ok
done

# convert uucp lock type back to a #define
case "$UUCP_LOCKTYPE" in
ascii)	UUCP_LOCKTYPE=0;;
binary)	UUCP_LOCKTYPE=1;;
*)	boom "Help, uucp lock type is \"$UUCP_LOCKTYPE\"; shouldn't happen!";;
esac

echo ""

#
# defs include file for all Makefiles
#
if [    "$FAX_BINDIR"	!= "$protoFAX_BINDIR"	\
     -o "$FAX_LIBDATA"	!= "$protoFAX_LIBDATA"	\
     -o "$FAX_LIBEXEC"	!= "$protoFAX_LIBEXEC"	\
     -o "$FAX_SPOOLDIR"	!= "$protoFAX_SPOOLDIR"	\
     -o "$USRETC"	!= "$protoUSRETC"	\
     -o "$MAN"		!= "$protoMAN"		\
     -o "$DOC"		!= "$protoDOC"		\
     -o "$AFMDIR"	!= "$protoAFMDIR"	\
     -o "$UUCP_LOCKTYPE" != "$protoUUCP_LOCKTYPE" \
     -o "$UUCP_LOCKMODE" != "$protoUUCP_LOCKMODE" \
     -o "$UUCP_LOCKDIR"	!= "$protoUUCP_LOCKDIR" \
     -o "$SENDMAIL"	!= "$protoSENDMAIL" \
]; then
    prompt "Set config parameters in the defs file [yes]?"; read x
    if [ -z "$x" -o "$x" = "y" -o "$x" = "yes" ]; then
	editFile defs \
	    "/^BIN[ 	]*=/s;=[^#]*;=${FAX_BINDIR};" \
	    "/^LIBDATA[ 	]*=/s;=[^#]*;=${FAX_LIBDATA};" \
	    "/^LIBEXEC[ 	]*=/s;=[^#]*;=${FAX_LIBEXEC};" \
	    "/^SPOOL[ 	]*=/s;=[^#]*;=${FAX_SPOOLDIR};" \
	    "/^USRETC[ 	]*=/s;=[^#]*;=${USRETC};" \
	    "/^MAN[ 	]*=/s;=[^#]*;=${MAN};" \
	    "/^DOC[ 	]*=/s;=[^#]*;=${DOC};" \
	    "/^AFMDIR[ 	]*=/s;=[^#]*;=${AFMDIR};" \
	    "/^UUCP_LOCKTYPE[ 	]*=/s;=[^#]*;=${UUCP_LOCKTYPE};" \
	    "/^UUCP_LOCKMODE[ 	]*=/s;=[^#]*;=${UUCP_LOCKMODE};" \
	    "/^UUCP_LOCKDIR[ 	]*=/s;=[^#]*;=${UUCP_LOCKDIR};" \
	    "/^SENDMAIL[ 	]*=/s;=[^#]*;=${SENDMAIL};"
    fi
fi

#
# util/config.h has definitions included by all source code.
#
getHParameter()
{
    param=`grep "$1" $2 | sed -e 's/.*"\(.*\)".*/\1/'`
}
f=util/config.h
getHParameter FAX_SPOOLDIR $f;	protoFAX_SPOOLDIR="$param"
getHParameter FAX_LIBDATA $f;	protoFAX_LIBDATA="$param"
getHParameter FAX_LIBEXEC $f;	protoFAX_LIBEXEC="$param"
getUtilParameter FAX_DEFVRES $f; protoFAX_DEFVRES="$param"
if [    "$FAX_LIBDATA"	!= "$protoFAX_LIBDATA"	\
     -o "$FAX_LIBEXEC"	!= "$protoFAX_LIBEXEC"	\
     -o "$FAX_SPOOLDIR"	!= "$protoFAX_SPOOLDIR"	\
     -o "$FAX_DEFVRES"	!= "$protoFAX_DEFVRES"	\
]; then
    prompt "Set config parameters in $f [yes]?"; read x
    if [ -z "$x" -o "$x" = "y" -o "$x" = "yes" ]; then
	editFile $f \
	    "/FAX_LIBDATA/s;${protoFAX_LIBDATA};${FAX_LIBDATA};" \
	    "/FAX_LIBEXEC/s;${protoFAX_LIBEXEC};${FAX_LIBEXEC};" \
	    "/FAX_SPOOLDIR/s;${protoFAX_SPOOLDIR};${FAX_SPOOLDIR};" \
	    "/FAX_DEFVRES/s;${protoFAX_DEFVRES};${FAX_DEFVRES};"
    fi
fi

#
# etc/faxaddmodem.sh is the modem installation and configuration
# script; it has server-related definitions built into it.
#
f=etc/faxaddmodem.sh
quit=$FAX_BINDIR/faxquit
getParameter SPOOL $f;		protoFAX_SPOOLDIR="$param"
getParameter SERVERDIR $f;	protoUSRETC="$param"
getParameter LOCKDIR $f;	protoUUCP_LOCKDIR="$param"
getParameter QUIT $f;		protoQUIT="$param"
    getParameter FAXUSER defs;	PROTOUID="$param"
getParameter PROTOUID $f;	protoPROTOUID="$param"
    getParameter FAXGROUP defs;	PROTOGID="$param"
getParameter PROTOGID $f;	protoPROTOGID="$param"
if [    "$FAX_SPOOLDIR"	!= "$protoFAX_SPOOLDIR" \
     -o "$PROTOUID"	!= "$protoPROTOUID" \
     -o "$PROTOGID"	!= "$protoPROTOGID" \
     -o "$USRETC"	!= "$protoUSRETC" \
     -o "$UUCP_LOCKDIR"	!= "$protoUUCP_LOCKDIR" \
     -o "$quit"		!= "$protoQUIT" \
]; then
    prompt "Set config parameters in $f [yes]?"; read x
    if [ -z "$x" -o "$x" = "y" -o "$x" = "yes" ]; then
	editFile $f \
	    "/^SPOOL=/s;${protoFAX_SPOOLDIR};${FAX_SPOOLDIR};" \
	    "/^PROTOUID=/s;${protoPROTOUID};${PROTOUID};" \
	    "/^PROTOGID=/s;${protoPROTOGID};${PROTOGID};" \
	    "/^SERVERDIR=/s;${protoUSRETC};${USRETC};" \
	    "/^LOCKDIR=/s;${protoUUCP_LOCKDIR};${UUCP_LOCKDIR};" \
	    "/^QUIT=/s;=.*/faxquit;=${FAX_BINDIR}/faxquit;"
    fi
fi

#
# etc/probemodem.sh is a modem debugging script;
# it has server-related definitions built into it.
#
f=etc/probemodem.sh
getParameter SPOOL $f;		protoFAX_SPOOLDIR="$param"
getParameter LOCKDIR $f;	protoUUCP_LOCKDIR="$param"
if [    "$FAX_SPOOLDIR"	!= "$protoFAX_SPOOLDIR" \
     -o "$UUCP_LOCKDIR"	!= "$protoUUCP_LOCKDIR" \
]; then
    prompt "Set config parameters in $f [yes]?"; read x
    if [ -z "$x" -o "$x" = "y" -o "$x" = "yes" ]; then
	editFile $f \
	    "/^SPOOL=/s;${protoFAX_SPOOLDIR};${FAX_SPOOLDIR};" \
	    "/^LOCKDIR=/s;${protoUUCP_LOCKDIR};${UUCP_LOCKDIR};"
    fi
fi

#
# util/ps2fax.*.sh is the shell script that invokes the
# PostScript imager; it has the location of the imager
#
f=util/ps2fax.$PSPACKAGE.sh
getParameter PS $f
if [ "$PSIMAGER" != "$param" ]; then
    prompt "Set config parameters in $f [yes]?"; read x
    if [ -z "$x" -o "$x" = "y" -o "$x" = "yes" ]; then
	editFile $f "/^PS=/s;${param};${PSIMAGER};"
    fi
fi

#
# Several scripts are aware of the location of the spooling
# area and (possibly) of the mailer.
#
# util/faxrcvd.sh	for anonymous received facsimile
# util/pollrcvd.sh	for polled received facsimile
# util/notify.sh	for server notification of events
# util/xferstats.sh	for transmit statistics
# util/recvstats.sh	for receive statistics
# util/faxcron.sh	for cleaning up the spooling area
#
for f in util/faxrcvd.sh util/pollrcvd.sh util/notify.sh
do
    getParameter SPOOL $f;	protoSPOOL="$param"
    getParameter SENDMAIL $f;	protoSENDMAIL="$param"
    if [   "$FAX_SPOOLDIR"	!= "$protoSPOOL" \
	-o "$SENDMAIL"	!= "$protoSENDMAIL" \
    ]; then
	prompt "Set config parameters in $f [yes]? "; read x
	if [ -z "$x" -o "$x" = "y" -o "$x" = "yes" ]; then
	    editFile $f \
		"/^SENDMAIL=/s;${protoSENDMAIL};${SENDMAIL};" \
		"/^SPOOL=/s;${protoFAX_SPOOLDIR};${FAX_SPOOLDIR};"
	fi
    fi
done

for f in util/*stats.sh util/faxcron.sh
do
    getParameter SPOOL $f;	protoSPOOL="$param"
    if [   "$FAX_SPOOLDIR"	!= "$protoSPOOL" ]; then
	prompt "Set config parameters in $f [yes]? "; read x
	if [ -z "$x" -o "$x" = "y" -o "$x" = "yes" ]; then
	    editFile $f \
		"/^SPOOL=/s;${protoFAX_SPOOLDIR};${FAX_SPOOLDIR};"
	fi
    fi
done

f=util/pagesizes
if [ "$PAGESIZE" != "$protoPAGESIZE" ]; then
    prompt "Set config parameter in $f [yes]? "; read x
    if [ -z "$x" -o "$x" = "y" -o "$x" = "yes" ]; then
	newDefault=`grep "$PAGESIZE" $f | sed -e 's/[^	]*/default/;q'`
	editFile $f "/^default/s/.*/$newDefault/"
    fi
fi
echo "Done."
exit 0
