#!/bin/sh
#
# Copyright(c) 1992 Wimsey Information Technologies
# Stuart Lynne <sl@wimsey.bc.ca>
# Portions adapted from work by Nathaniel Borenstein <nsb@bellcore.com>
# Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
#
# Permission to use, copy, modify, and distribute this material 
# for any purpose and without fee is hereby granted, provided 
# that the above copyright notice and this permission notice 
# are included.
#
# WE MAKE NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
# OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
# WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
#
#


#
# usage: mmshowfax [type] file

PATH=$PATH:/usr/local/bin:/usr/local/lib/mm
RC=1
mmreset() {
    if [ -x /usr/bin/tput ] ; then
	echo `tput clear`
    elif [ -x /usr/ucb/reset ] ; then
	/usr/ucb/reset
    fi
}


if [ -x /usr/bin/tput ] ; then
    bd=`tput bold`
    rv=`tput smso`
    Off=`tput rmso`
    cls=`tput clear`
fi

fclean(){
    echo ${Off}
    if [ $RC != 0 ] ; then
	echo 
	echo "Press any key to continue ...\c"
	/usr/local/lib/mm/mmgetchar
	echo
    fi
    exit $RC
}

trap "fclean" 0 1 2 15

# check if we are on X Terminal
if [ "$DISPLAY" ] ; then
    displayprog=/usr/local/bin/X11/xtiff
  
# check if we are on SCO compatible system with vga
elif [ -r /dev/vga ] ; then
    # check if we are on console
    console=`/etc/hwconfig | egrep console | awk -e '{ print $4; }'`
    case $console in
	unit=vga|unit=ega)
	    tty=`tty`
	    tty=`expr $tty : '/dev/tty\(.*\)'`
	    case $tty in
	      01|02|03|04|05|06|07|08|09|10|11|12)
		displayprog=/usr/local/bin/faxvga
		;;
	    esac
	    ;;
    esac
fi

# was this just a check
#if [ $# -ge 1 -a $1 = "-ok" ] ; then
    mmreset
    echo "${bd}mmshowfax:${Off} $*"
    echo "$MM_HEADERS"

    if [ "$displayprog" ] ; then
	echo We can use ${bd}$displayprog${Off} to view ${bd}$2 $3${Off}
	VIEW="View Fax - $displayprog" export VIEW
	MESG="You have received a FAX format message."
	[ $1 = "-ok" ] && RC=0 exit 0
    else
	echo We are not configured view ${bd}$2 $3${Off} on this terminal
	VIEW=
	MESG=
	[ $1 = "-ok" ] && RC=1 exit 1
    fi

#fi

viewfile() {
    mmreset
    echo
    echo Displaying file $file containing $type ....
    echo
    echo Note: to make the picture window go away, just type 'q' in it.
    echo
    $displayprog $file
}

printfile() {
    /usr/lib/cfax/fax/FAXPRINT $1
}


. mmsavefile


