#!/bin/sh
# Shell script to find a help reader for Ergo
# This tries emacs19 (via gnudoit)
#    then (for X windows) xdvi on the .dvi file,
#    then (for X windows) info in a separate xterm,
#    then info as a subprocess.
#
# To port this script to a new site, you may need to change
# the assignments to PATH, XTERM, DVIVIEWER, ERGOINFO and SYSINFO below.
#
# NB. 'gnudoit' is a client-server program that communicates with
#     an already-running emacs process.  It is part of the 'gnuserv'
#     program that is available via anonymous ftp from most major
#     ftp sites that support GNU software (eg. prep.ai.mit.edu)
#
#     The use of gnudoit is recommended, because it means that the Ergo manual
#     can be read within emacs19, which allows browsing and navigation
#     via mouse clicks (eg. middle mouse button follows any menu entry or
#     hypertext link) and uses fonts to distinguish buttons from text etc.
#
# NB. 'info' is the standard GNU ASCII reader program for info files.
#     It is distributed as part of the texinfo package, available from
#     ftp sites that support GNU software (eg. prep.ai.mit.edu)

# Set path to ensure that it includes the 'info' and/or 'gnudoit' programs.
PATH=$PATH:/homes/emacs/binBAD

# XTERM determines which X windows terminal emulator to run 'info' in.
XTERM=xterm

# DVIVIEWER determines which viewer to use for .dvi files.
DVIVIEWER=xdvi

# ERGOINFO is the default directory containing Ergo .info files.
if [ "$#" -eq 1 -a -d "$1" ]
then
	ERGOINFO=$1
else
	ERGOINFO=/homes/itp/ver4/userman
fi

# SYSINFO is the default path of directories that contain GNU info files.
# This will be different for each system, but should at least include
# the info subdirectory of the standard GNU emacs19 distribution.
SYSINFO=/homes/emacs/info:/usr/local/emacs-19/info

if [ "$INFOPATH" = "" ]
then
	INFOPATH=$ERGOINFO:$SYSINFO
else
	INFOPATH=$ERGOINFO:$INFOPATH
fi
export PATH INFOPATH

GNUDOIT=`gnudoit "(Info-goto-node \"(ergo)Top\")" 2>/dev/null`
if [ "$?" -eq 0 -a "$GNUDOIT" -ge 0 ]
		  # GNUDOIT can be any number, but not an error message.
then
    echo "Using emacs to read the Ergo user manual"
else
    if [ "$DISPLAY" = "" ]
    then
	# not running X windows.
	info -f ergo
    else
        $DVIVIEWER $ERGOINFO/ergo.dvi \
	|| $XTERM -title "Ergo Help" -e info -f ergo &
    fi
fi
