[comp.binaries.apple2] atou/utoa

erast1@unix.cis.pitt.edu (Evan R Aussenberg) (02/13/91)

Below is a *unix* shell script to convert *text* files
from Apple to Unix format (and vice versa).

It's somewhat nicer that using a t/csh alias, and it
accepts multiple file names.

This is a small update at the request of several users
for standard output support.  That is- the shell script
will optionally output the conversion to your screen
instead of altering the file.

It is not a complex shell script, thus the few important
notes about installing/using the program are contained
below in the script itself.

Enjoy,
    Evan

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

------------------------- CUT HERE --- CUT HERE -------------------------------
:
###########################################################################
# atou / utoa  (AppleToUnix & UnixToApple)
#
# Author:  Evan Ron Aussenberg
#          erast1@unix.cis.pitt.edu
#          IN%"erast1@pittunix"
#
# Version 1.1
# February 13, 1991
#   - Added standard output support
#
# December 15, 1990 - Evan Ron Aussenberg
#   - Initial release
#
# Description:
#   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:
#   Your mileage may differ.  Also, this is just a little nicer
#   than making a t/csh alias... and it should 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 ] [ -c ] file1 files2...
#   utoa [ -v | V ] [ -c ] file1 files2...
#
# Options (specifiy only one):
#   -c  Standard output is used instead of saving the converted file.
#   -v  Give terse output.  Normally no output is given.
#   -V  Give verbose output
#
# Note: Both "-v" and "-V" are ignored if "-c" is specified.
#
###########################################################################
version=1.1
command=`basename $0`       # What command has called us here?
verbose='0'                 # Verbose off
std='0'                     # Standard output off

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.
# I don't use "getopt[s]"
#######################
case $1 in
    -v ) verbose=1 ; shift ;;
    -V ) verbose=2 ; shift ;;
     * ) ;;
esac

case $1 in
    -c ) std=1 ; shift ;;
     * ) ;;
esac

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

    for file in $* ; do
        if [ -f $file ] ; then
            if [ $std = 0 ] ; then
                case $verbose in
                    1)echo -n $command': '$file'... ';;
                    2)echo -n $command': Saving '$file' to '$command.$$'... ';;
                    *);;
                esac

                cat $file | tr $oct1 $oct2 > $command.$$

                if [ $verbose -gt 0 ] ; then
                    echo 'done.'
                    if [ $verbose = 2 ] ; then
                        echo $command': Moving '$command.$$' to '$file
                        echo
                    fi
                fi

                mv $command.$$ $file
            else
                cat $file | tr $oct1 $oct2
            fi
        else
            echo $command": Can't find file "$file"... skipping"
        fi
    done

else
    echo -n '
'$command', version '$version'
Syntax error:  no filename specified

atou [ -v | V ] [-c] file1 files2...
utoa [ -v | V ] [-c] file1 files2...

'
    exit 1
fi

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