#! /bin/sh -e
#
# convert a DOS ASCII file to a UNIX ASCII file by removing trailing ^M at the
# end of each line and ^Z at the end of the file

TMPFILE=/tmp/to_unix$$

if [ $# != 2 ]
then
	echo "usage: to_unix <dos_file> <unix_file>"
	exit 1
fi

sed -e 's/
$//' -e '/^/d' "$1" > $TMPFILE

# Get the last line if there's no trailing newline.

case `tail -2c "$1" | wc -l` in
    *0)	echo "`echo \"\`tail -0 \\\"$1\\\"\`\" | sed -e 's/$//'`\c" >> $TMPFILE
	;;
esac

mv -f $TMPFILE "$2"
