#!/bin/sh

# This script replaces the old helptomaple executable. Helptomaple is
# really obsolete, and the Maple function makehelp() should be used
# instead, but this script is provided for backwards compatiblity.

# Here is the documentation for the original program:

# Reads standard input and writes to standard output, enclosing each line
# with backquotes.  All characters in each line except backquotes (`) and
# backslashes (\) are printed as is, while backquotes and backslashes are
# simply doubled up (`` and \\).  Resulting lines are separated by commas
# (,) and all enclosed in a TEXT() function.  The program takes a single
# argument which is the Maple name to which the resulting text should be
# assigned.

# Written by Stefan Vorkoetter and Mike Monagan, March 1990
# Modified by Stefan Vorkoetter to extend short lines, April 1990
# Modified by Stefan Vorkoetter to not escape everything, April 1990
# Modified by Mike Monangan to not generate "save" and "quit", September 1992
# Translated into a shell script by Stefan Vorkoetter, September 1992

# WARNING: backslashes are not handled properly by the new script. The
#          makehelp function, when used in Maple, will handle them properly,
#	   but the Maple save statement (used in the script) will not do
#	   the right thing with them when saving as text.

# Create a temporary file name and make sure it does not already exist.
TEMP=/tmp/htom.$$
if [ -f $TEMP ]
then	echo $0: could not create temporary file $TEMP
	exit 1
fi

# Check that there is one argument.
if [ $# != 1 ]
then	echo Usage: $0 name
	exit 1
fi

# Copy the standard input into a temporary file.
cat > $TEMP

# Run Maple to process the file, saving the result in the same file.
maple -q > /dev/null <<EOF
	readlib(makehelp):
	\`$1\` := makehelp(JUNK,\`$TEMP\`):
	save \`$1\`,\`$TEMP\`:
	quit
EOF

# Copy the result to the standard output and erase the temporary file.
cat $TEMP
rm $TEMP
