Subject: Converter BinHex 4.0

From: IBERFORO-MADRID <[email-masked]>
Date: Tue, 14 Oct 1997 10:52:46 +-100

I have received an e-mail with a file attached.  The file has been writen with Word 6.0 for Macintosh and my PC cannot open the file neither convert it.  The message reads (This file must be converted with BinHex 4.0)

Could anyone please send me the converter?  Thank you very much.

---

From: Edward M Greshko <[email-masked]>
Date: Wed, 15 Oct 1997 08:32:29 +0800 (GMT)

On Tue, 14 Oct 1997, IBERFORO-MADRID wrote:

> I have received an e-mail with a file attached.  The file has been
> writen with Word 6.0 for Macintosh and my PC cannot open the file
> neither convert it.  The message reads (This file must be converted with
> BinHex 4.0) 
> 

Attached is a Unix Borne shell script which will accomplish the
conversion.

Ed

-- 
Edward M. Greshko                  Technical Manager, Electronic Commerce
                                   Control Data Asia/Pacific Region
PGPKey-ID:CA3AFA5D  Fingerprint: 2DE6 5527 144E D1BC  3C55 9FA5 518E 52EE
#!/bin/sh
binhex decode $1 PC

---

From: Edward M Greshko <[email-masked]>
Date: Wed, 15 Oct 1997 15:08:29 +0800 (GMT)

> Attached is a Unix Borne shell script which will accomplish the

Ooops....here is the "correct" one.

:

#MBINDIR=/usr/mailhub/sbin/conversion
MBINDIR=$HOME/bin

if [ $# -lt 2 ]; then
  echo "Usage: binhex encode filename
       binhex decode filename MAC|PC
       binhex -help

       The first format encodes the specified file into BinHex format.
       The second format takes a file already in BinHex format and decodes
          it.  If the third parameter is MAC, the file is decoded into
          MacBinary format, and should be uploaded to your Macintosh as
          a MacBinary file.  If the third parameter is PC, then the file
          is run through an additional translation to convert it to 
          straight binary format (data fork only for Mac users).  This
          file may then be downloaded to a PC, or used on unix.\n"
  exit 1
  fi

OPTION=`echo $1 | /usr/bin/cut -c1 | /usr/bin/tr \[a-z\] \[A-Z\]`
TMP=/tmp/binhex$$
OLDDIR=`pwd`

ch1=`echo $2 | /usr/bin/cut -c1`
if [ "$ch1" = "/" ]; then
   FILE="$2"
else
   FILE="$OLDDIR/$2"
   fi

if [ "$OPTION" = "E" ]; then			# If encoding
	if [ $# -ne 2 ]; then
	    echo "Usage: binhex encode filename"
  	    echo "       binhex -help"
	    exit 1
	    fi
        head -1 "$FILE" >/dev/null 2>/dev/null	# Relative to /home only
	if [ $? -ne 0 ]; then
   	    echo "File does not exist."
   	    exit 1
   	    fi
	/bin/mkdir "$TMP"
	cd "$TMP"
	error=0
	MAC_DLOAD_DIR="$TMP"; export MAC_DLOAD_DIR
	ismacbinary "$FILE"		# Is it macbinary?
	if [ $? -eq 0 ]; then
	    $MBINDIR/mcvert -U -x "$FILE"	# Macbinary->hqx
	    error=$?
	else
	    /bin/cp "$FILE" "$TMP"			# Quirk in mcvert
	    $MBINDIR/mcvert -D -d "$2"		# bin->macbinary
	    $MBINDIR/mcvert -U -x "${2}.bin"	# macbin->hqx
	    error=$?
	    fi
	if [ $error -eq 0 ]; then
	    /bin/cp "${2}.hqx" $OLDDIR
	    echo "\nBinHex file created: ${2}.hqx\n"
	else
	    echo 'Unable to encode file.'
	    fi
	cd "$OLDDIR"
	rm -r "$TMP"
elif [ "$OPTION" = "D" ]; then
	if [ $# -ne 3 ]; then
	     echo "Usage: binhex decode filename MAC"
	     echo "       binhex decode filename PC"
  	     echo "       binhex -help"
             exit 1
	     fi
	FTYPE=`echo $3 | /usr/bin/cut -c1 | /usr/bin/tr \[a-z\] \[A-Z\]`
        if [ "$FTYPE" != "M" -a "$FTYPE" != "P" ]; then
             echo "Usage: binhex decode filename MAC"
             echo "       binhex decode filename PC"
  	     echo "       binhex -help"
             exit 1
             fi

        head -1 "$FILE" >/dev/null 2>/dev/null	# Relative to /home only
	if [ $? -ne 0 ]; then
   	    echo "File does not exist."
   	    exit 1
   	    fi

	mkdir "$TMP"
	cd "$TMP"

	error=0
	/bin/cp "$FILE" "$TMP/$2"
#	$MBINDIR/mcvert -D -x "$2"	# binhex -> macbinary
	$MBINDIR/mcvert "$2"	# binhex -> macbinary
	error=$?
	rm "$TMP/$2"
	if [ "$FTYPE" = "M" ]; then
	    /bin/cp * "$OLDDIR"
	    echo "\nFiles decoded:"
	    /bin/ls "$TMP"
	elif [ "$FTYPE" = "P" ]; then
	    $MBINDIR/mcvert -U -d *.bin
	    error=$?
	    rm $TMP/*.bin
	    /bin/cp * "$OLDDIR"
	    echo "\nFiles decoded:"
	    /bin/ls
            fi
	cd "$OLDDIR"
	rm -r "$TMP"
        if [ $error -ne 0 ]; then
	    echo "\nError decoding file.\n"
	    exit 1
	    fi
	echo 

else
	echo "Usage: binhex encode filename"
  	echo "       binhex decode filename MAC|PC"
  	echo "       binhex -help"
  	exit 1
	fi