#!/bin/sh
#	BSDI	showpicture,v 1.2 1995/12/10 23:55:56 sanders Exp
#
# 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 
# appear in all copies, and that the name of Bellcore not be 
# used in advertising or publicity pertaining to this 
# material without the specific, prior written permission 
# of an authorized representative of Bellcore.  BELLCORE 
# MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
# OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
# WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
#

unset IFS

# Defaults
METAMAIL_TMPDIR=${METAMAIL_TMPDIR:-${TMPDIR:-/tmp}}
X_VIEWER=${X_VIEWER:-"xv -geometry +0+0 -perfect -2xlimit"}

usage() { echo "Usage: showpicture [-viewer program] [file(s)]" 1>&2; }

case $1 in
    -v*) shift;
	 if [ $# -lt 1 ]; then usage; exit 1; fi
	 X_VIEWER="$1"; shift;
	 ;;
esac

if [ $# -eq 0 ]; then
    set ${METAMAIL_TMPDIR}/picture.$$
    cat > $1
fi

if [ ! "$DISPLAY" ]; then
    echo ""
    echo This message contains a picture, which can currently only be
    echo viewed when running X11.  If you read this message while running
    echo X11, and have your DISPLAY variable set, you will then
    echo be able to see the picture properly.
    echo ""
    echo "The picture data is saved in:"
    ls -l "$@"
    # for i in "$@"; do echo $i; done | column
    echo "If you do not want this data, please delete it."
    exit 0
fi

echo "Type into the picture window: space to see next picture, 'q' to quit"
$X_VIEWER "$@"
rm -f ${METAMAIL_TMPDIR}/picture.$$
