[comp.binaries.apple2] Unix-Apple text converter

erast1@unix.cis.pitt.edu (Evan R Aussenberg) (12/18/90)

For unix users:
===============
Here is a shell script to convert text files from Unix-to-Apple and
Apple-to-Unix.  I realize some of you use the t/csh alias command, but
this script is a little friendlier.  It will also handle file
not found errors by skipping the alleged file.

Follow the notes at the beginning of the script.  It's easy.  It's fun.
Also, makek sure that the first line of the shell script is the
colon (:) that you see below.

This is shareware:  That is- feel *free* to share it. :-)

Evan Ron Aussenberg
erast1@unix.cis.pitt.edu
IN%"erast1@pittunix"

---------------------- CUT HERE ------  cut here --------------------------
:
###########################################################################
# atou / utoa  (AppleToUnix & UnixToApple)
# December 15, 1990 - Evan Ron Aussenberg
#                     erast1@unix.cis.pitt.edu
#                     IN%"erast1@pittunix"
#
# Discription:
#   An Apple-to-Unix and Unix-to-Apple text file converter.  This is
#   a Unix shell script.  If you don't use Unix then you don't need
#   this (Well... maybe you do, but you can't use it).
#
# Disclaimer:
#   You're mileage may differ.  Also, this is just a little
#   nicer than making a t/csh alias... and it'll run from any shell
#   as long as you leave the ':' in the 1st line.  Okay?  Okay.
#
# To run this shell script you need :
#   1:  The unix command "basename"     | Just make sure these programs can
#   2:  The unix command "tr"           | be found in your $PATH environ.
#   3:  Save this program as "utoa"
#   4:  Type "chmod a+x utoa"
#   5:  Type "ln utoa atou"             | If you don't have the command
#                                       | "ln" or "link" then use "cp"
#
# Syntax:
#   atou [-v | V] file1 files2...
#   utoa [-v | V] file1 files2...
#
# Options (specifiy only one):
#   -v  Give terse output.  Normally no output is given.
#   -V  Give verbose output
#
###########################################################################
command=`basename $0`       # What command has called us here?
verbose='0'

case $command in
    utoa)  oct1="'\012'"    # This is control-j octal
           oct2="'\015'";;  # This is control-m octal

    atou)  oct1="'\015'"    # This is control-m octal
           oct2="'\012'";;  # This is control-j octal

       *)  echo "Hey, please name this program utoa and/or atou"
           exit 1;
esac

# Check any options.  If you're file is actually named "-v or -V" 
# and you're a unix neophyte... hee hee.
case $1 in
    -v ) verbose=1 ; shift ;;
    -V ) verbose=2 ; shift ;;
     * ) ;;
esac


# Check to make sure some files were specified
if [ $# -gt 0 ] 
then

for file in $* ; do
    if [ -f $file ] ; then
            [ $verbose = 1 ] && echo -n $command': '$file'... '
            [ $verbose = 2 ] &&
                       echo -n $command': Saving '$file' to '$command.$$'... '
        cat $file | tr $oct1 $oct2 > $command.$$
            [ $verbose -gt 0 ] && echo 'done.'
            [ $verbose = 2 ] && echo $command': Moving '$command.$$' to '$file
        mv $command.$$ $file
            [ $verbose = 2 ] && echo
    else
        echo $command": Can't find file "$file"... skipping"
    fi
done
                
else
    echo -n '
'$command':  No file names specified!
Syntax:
   atou [-v | V] file1 files2...
   utoa [-v | V] file1 files2...

'
    exit 1
fi

echo
exit 0
-- 
Evan Ron Aussenberg
erast1@unix.cis.pitt.edu
IN%"erast1@pittunix"