#!/bin/sh
# @(#) $RCSfile: MAKE_HELP,v $: $Revision: #26 $, $Date: 2008/01/15 $ 
# @(#) Copyright (c), 1987, 2006 Insightful Corp.  All rights reserved.

# Create the PRINT shell script and the help.tr troff command list.

FILE="$SHOME"/cmd/PRINT

# Source the environment variables used by the program
. "$SHOME"/splus/lib/install/USER.env

if touch "$FILE" > /dev/null 2>&1
then
    :
else
    echo
    echo "*** ERROR: unable to create \"$FILE\" ***"
    echo
    exit 1
fi

# Put the introductory information in the file
cat << EOF > "$FILE" || exit 1
#!/bin/sh
# This script is created by the CONFIGURE shell script.
# You should call it from the \$SHOME/cmd/sgml_help script
# or from the Unix prompt like this:  Splus PRINT <HTML file>
# If the -o option is supplied then the help information is put
# into a file instead of going to the printer.
# This script is used by the help() function if the arg offline=T.

usage (){
echo "Usage: \$0 [-o out-file] help-file"
echo "  -o out-file  Instead of printing the help file, write it to <out-file>"
echo "  help-file    The HTML file to be printed"
exit 1
}

if [ \$# = 0 ]; then usage; fi

while [ \$# -ge 0 ]
do
	case \$1 in
		-o)  outname=\$2; print=no; shift; shift;;
		"-h" | "--help" | "-help") usage;;
		-*)  echo "Unknown option \$1"; usage;;
		*)   helpfile=\$1; break;;
	esac
done
if [ "X\$helpfile" = "X" ]; then usage; fi
if [ ! -f "\$helpfile" ]
then 
	echo "The help file \"\$helpfile\" does not exist"
	exit 1
fi

if [ "X\$outname" = "X" ] 
then
	outname="\$S_TMPDIR/PRINT.\$\$.out"
        print=yes
fi
"\$SHOME"/cmd/slynx -cfg="\$SHOME/cmd/lynx.cfg" -dump -nolist "\$helpfile" > "\$outname" || exit 1
if [ \$print = yes ]
then
	$PRINT "\$outname"
	echo "Sent \$helpfile to the printer."
	rm "\$outname"
fi

EOF
# Make it executable
chmod +x "$FILE"

exit 0
