#!/bin/sh
# @(#)MAKE_HELP version 3.18 created 9/24/93
# @(#)Copyright (c), 1987, 1993 StatSci, Inc.  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 file is created by the CONFIGURE shell script.
# You should call it from the \$SHOME/cmd/help script.

case \$# in
1)    
;;
*)    
      echo "Usage: \$0 help_file"
      exit 1
;;
esac

EOF
# Make it executable
chmod +x $FILE

# Create nroff command if no TROFF available
if [ "$TROFF" = "nroff" ]
then
    cat << EOF >> $FILE || exit 1
sed -e "/^\.ul/d
    /\\\`/s/\'//g
    /\\\`/s/\\\`//g" "\$1" |
    nroff -Ttn300 \$SHOME/cmd/help.nr - | $PRINT || exit 1
    echo "Sent \$1 to the printer."
EOF
    echo "Created: $FILE"
    exit 0
fi

# Create a version of $SHOME/cmd/help.tr appropriate for this system.
if [ "$OLD_NEW" = old ]
then
    SED_OLD="s/^.*OLDTROFF //"
else
    SED_OLD="s/^.*NEWTROFF //"
    
fi
if [ "x$EQN" = "x" ]
then
    SED_EQN="s/^.*NOEQN //"
else
    SED_EQN="s/^.*OKEQN //"
fi

sed -e "$SED_OLD" -e "$SED_EQN" $INSTALL_DIR/help.tr.pre > $SHOME/cmd/help.tr || exit 1
echo "Created: $SHOME/cmd/help.tr"

# Convert `' to the appropriate troff commands.
cat << EOF >> $FILE || exit 1

sed -e "/\\\`/s/\'/\\\\\\\\fP\\\\\\\\s+1/g
        /\\\`/s/\\\`/\\\\\\\\f3\\\\\\\\s-1/g" "\$1" |
EOF

if [ "x$EQN" != "x" ]
then
    # put eqn line in $FILE
    echo "    $EQN |" >> $FILE || exit 1
fi

# Create TROFF and printing command last
cat << EOF >> $FILE || exit 1
    $TROFF $TO \$SHOME/cmd/help.tr - 2>/dev/null | $PRINT || exit 1
    echo "Sent \$1 to the printer."
EOF
echo "Created: $FILE"

exit 0
