#! /bin/sh
#
# $Id: xfig-www-browser,v 1.12 2004/02/20 18:55:09 roland Exp $
#
##########################################################################
#
# xfig-www-browser is a little shell script, which tries to find out
# which web browsers you have installed on your system and then starts
# them.  The environment variable BROWSER has priority over all other
# browsers.
# See xfig-www-browser(1) man page for more information.
#
##########################################################################
#
#   Copyright (C) 1999-2003  Roland Rosenfeld <roland@spinnaker.de>
#
#   This program is free software; you can redistribute it and/or
#   modify it under the terms of the GNU General Public License as
#   published by the Free Software Foundation; either version 2 of
#   the License, or (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#   General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
##########################################################################

if [ "$1" = "-n" ]; then
    echo "No browser found in xfig-www-browser(1), please set BROWSER"
    echo "environment variable or install a web browser"
    read dummy
    exit 0
fi

if [ $# -ne 1 ]; then
    echo "Usage: $0 file.html"
    exit 0
fi

if [ "$BROWSER" != "" ]; then
    case "$BROWSER" in
	*lynx*) ASCII=true
		break;;
	*w3m)   ASCII=true
		break;;
	*links) ASCII=true
		break;;
	*mmm)   ASCII=true
		break;;
    esac
elif type mozilla >/dev/null 2>&1; then
    BROWSER=mozilla
elif type mozilla-firebird >/dev/null 2>&1; then
    BROWSER=mozilla-firebird
elif type epiphany >/dev/null 2>&1; then
    BROWSER=epiphany
elif type galeon >/dev/null 2>&1; then
    BROWSER=galeon
elif type netscape >/dev/null 2>&1; then
    BROWSER=netscape
elif type light >/dev/null 2>&1; then
    BROWSER=light
elif type skipstone >/dev/null 2>&1; then
    BROWSER=skipstone
elif type opera >/dev/null 2>&1; then
    BROWSER=opera
elif type konqueror >/dev/null 2>&1; then
    BROWSER=konqueror
elif type dillo >/dev/null 2>&1; then
    BROWSER=dillo
elif type chimera >/dev/null 2>&1; then
    BROWSER=chimera
elif type kdehelp >/dev/null 2>&1; then
    BROWSER=kdehelp
elif type gzilla >/dev/null 2>&1; then
    BROWSER=gzilla
elif type arena >/dev/null 2>&1; then
    BROWSER=arena
elif type gnome-help-browser >/dev/null 2>&1; then
    BROWSER=gnome-help-browser
elif type chimera2 >/dev/null 2>&1; then
    BROWSER=chimera2
elif type amaya >/dev/null 2>&1l; then
    BROWSER=amaya
elif type links >/dev/null 2>&1; then
    BROWSER=links
    ASCII=true
elif type w3m >/dev/null 2>&1; then
    BROWSER=w3m
    ASCII=true
elif type lynx >/dev/null 2>&1; then
    BROWSER=lynx
    ASCII=true
else
    BROWSER='xfig-www-browser -n'
    ASCII=true
fi


if [ "$ASCII" = "true" ]; then
    if type x-terminal-emulator >/dev/null 2>&1; then
	XTERM=x-terminal-emulator
    elif type xterm >/dev/null 2>&1; then
	XTERM=xterm
    elif type rxvt >/dev/null 2>&1; then
	XTERM=rxvt
    elif type Eterm >/dev/null 2>&1; then
	XTERM=Eterm
    fi
    case "$LANG" in
	ja*) if type kterm >/dev/null 2>&1; then
		    XTERM=kterm
	     fi
	     break;;
	ko*) if type hanterm >/dev/null 2>&1; then
		    XTERM=hanterm
	     fi
	     break;;
    esac
    if [ -z "$XTERM" ]; then
	echo "No x terminal emulator found, please install one" 1>&2
	exit 1
    fi


    exec $XTERM -e $BROWSER "$1"
else
    exec $BROWSER "$1"
fi
