:
#	@(#) translate.sh 22.1 89/11/14 
#
#	Copyright (C) The Santa Cruz Operation, 1988.
#	This Module contains Proprietary Information of
#	The Santa Cruz Operation, Microsoft Corporation
#	and AT&T, and should be treated as Confidential.
#

# Name: Translate
# Syntax: translate -FT [format] input_file output_file
# Description: Translate translates files according to the options specified.
#              Translation is done from format F to format T with an optional
#              [format] file specification.

cmd=""
chmod=""
remote=""
mapfile="/usr/lib/translate/"

usage () { echo "translate -{option} [input_file] [output_file]

	options = ae  - ascii input to an ebcdic output
	  	  ea  - ebcdic input to an ascii output
	  	  mb  - encoded input back to original format 
	  	  bm  - binary input to a mailable format
	  	  fa  format - user defined input to an ascii output
	  	  fe  format - user defined input to an ebcdic output
	  	  ef  format - ebcdic input to a user defined format
	  	  af  format - ascii input to a user defined format
	"; exit 1 ; }

# check for an absolute pathname when using a mapfile 

case "$1" in
    -fe | -fa | -ef | -af ) 
        if [ "$2" ] 
	then
  	    case  "$2" in
	        /*) mapfile=$2  ;;
	         *) mapfile=$mapfile$2 ;;
 	    esac
        else 
	    usage
        fi ;;
esac

# determine which command to use 

case "$1" in
       -ae) cmd="(dd conv=ebcdic 2>/dev/null)" 
	    shift ;;
       -ea) cmd="(dd conv=ascii 2>/dev/null) " 
	    shift ;;
       -bm) if [ "$2" ]
	    then
		remote="$2"
	        shift ; 
	    else 
		remote="stdin" 
		shift ; 
            fi 
  	    cmd="uuencode \$remote" 
	    ;;
       -mb) cmd="uudecode -s" 	
	    if [ "$3" ] 
	    then
		chmod=" ;chmod +x $3"
	    fi
	    shift ;;
       -fa) cmd="trchan $mapfile " 	
	    shift ; shift ;;
       -fe) cmd="trchan $mapfile |(dd conv=ebcdic  2>/dev/null)" 
	    shift ; shift ;;
       -ef) cmd="(dd conv=ascii 2>/dev/null) | trchan $mapfile " 
	    shift ; shift ;;
       -af) cmd="trchan $mapfile"        
	    shift ; shift ;;
         *) usage  ;;
esac 

case $# in
    0) input_file=""
       output_file="" ;;
    1) input_file=" < $1"
       output_file="" ;;
    2) input_file=" < $1"
       output_file=" > $2" ;;
    *) usage
esac
eval $input_file $cmd $output_file $chmod

exit $? 
