#!/bin/sh -

binary=$1
shift

if [ `echo $binary | wc -c` -gt 28 ] ; then
    echo "#!/bin/sh -"
    echo exec $binary $* -i '"$0"' '"$@"'

elif [ $# -gt 0 ] ; then
    echo '#!'$binary \\
    echo $* -i

else echo '#!'$binary -i
fi

if [ ! "${OSTYPE}" = "cygwin32" ] ; then
    exec cat
else
    exec /mksnt/cat
fi

# This program reads an S48 image from stdin and turns it into
# an executable by prepending a #! prefix. The vm and its
# args are passed to this program on the command line.
#
# If the vm binary is 27 chars or less, then we can directly
# execute the vm with one of these scripts:
#     No args:
#         image2script /usr/local/bin/svm <image
#     outputs this script:
#	  #!/usr/local/bin/svm -i
#	  ...image bits follow...
#    
#     Args:
#         image2script /usr/bin/svm -h 4000000 -o /usr/bin/svm <image
#     outputs this script:
#	  #!/usr/bin/svm \
#	  -h 4000000 -o /usr/bin/svm -i
#	  ...image bits follow...
#
# The exec system call won't handle the #! line if it contains more than
# 32 chars, so if the vm binary is over 28 chars, we have to use a /bin/sh
# trampoline.
#     image2script /user1/lecturer/shivers/vc/scsh/s48/lib/svm -h 4000000 < ...
# outputs this script:
#     #!/bin/sh -
#     exec /user1/lecturer/shivers/vc/scsh/s48/lib/svm -h 4000000 -i $0 $*
#     ...image bits follow...
#
# 	-Olin
