#!/bin/sh
#ident "@(#) WebBrowser, Rev 1.6, 97/03/21"
#
#      Copyright (c) 1995-1997, Sun Microsystems, Inc.
#      All rights reserved.

##BEGIN TEMPLATE WRAPPER SHELL SCRIPT

# A variable to hold arguments after we strip OpenStep specific information
args=

# If you are debugging this script you might uncomment the following
# two lines.
#set -x
#echo input=$*

# Loop until argv ($#) is zero, each iteration will decrement (shift)
# argv/argc.
while [ $# != 0 ] ; do
  case $1 in
    # -NSOpen is an OpenStep standard command line flag which
    # lets the NSApplication know what file to open.
    -NSOpen)
        args="$args $2"
        shift             
        ;;
    # -NSOpenTemp is an OpenStep standard command line flag which
    # lets the NSApplication know what file to open and that it is
	# a temporary file and should be resaved somewhere else if edited.
    -NSOpenTemp)
        args="$args $2"
        shift
        ;;
    # -_NSMachLaunch is an undocumented additional flag to NSApplication.
    # We just ignore it here.
    -_NSMachLaunch)
        shift
        ;;
    *)
        args="$args $1"
        ;;
  esac
  shift
done

##END OF TEMPLATE WRAPPER SHELL SCRIPT


# Now execute the program with the real arguments and place it in the
# background.
netscape="netscape"

running=`/usr/bin/ps -ef | grep netscape | grep -v grep | awk '{print $1}'`
if [ "$args" ]; then
  ext=`echo $args | awk -F. '{i = NF; print $i}'`
else
  ext=""
fi

case $ext in
    url | uri)
        args=`cat $args`
        if [ "$running" ]
	then
	  exec $netscape -remote openURL\($args\) &
        else
	  exec $netscape $args &
        fi
        ;;
    mailto)
        if [ "$running" ]
	then
          args=`cat $args`
	  exec $netscape -remote mailto\($args\) &
        else
          args=`cat $args`
          exec $netscape "mailto:$args" &
        fi
        ;;
    "")
        if [ -z "$running" ]
	then
          exec $netscape &
        fi
        ;;

    html | htm)
	args=`echo "$args" | sed -e 's/ //g'`
        if [ "$running" ]
	then
	  exec $netscape -remote openURL\(file://$args\) &
        else
          exec $netscape file://$args &
        fi
        ;;
    *)
	args=`echo "$args" | sed -e 's/ //g'`
        if [ "$running" ]
	then
	  exec $netscape -remote openURL\(file://$args\) &
        else
          exec $netscape file://$args &
        fi
        ;;
esac

