#!/bin/csh -f

#
# Shell Script to send a document to a browser
# Jim Newberry, Applied Precision, November 1996
# 
# Pass one argument: the entire file name
# The file name may have a target (#target_tag) at the end
#

if($#argv != "1") then
	echo "You must pass this script one argument"
        exit
endif

set BROWSER=""
if(-e /usr/bin/firefox) then
    set BROWSER=/usr/bin/firefox
endif

if ( $BROWSER == "" && -e /usr/bin/mozilla) then
    set BROWSER=/usr/bin/mozilla
endif

#
# If the argument begins with http: it is a URL spec
# otherwise it is a file
#
set IS_URL=0

echo $1 | grep --quiet http:
if( $status == 0) then
    set IS_URL=1
    set TARGETURL="$1"
else
  # softWoRx 3.7.0 Help had trouble "moving" the target file to main help file
  #  plus the bookmarked target.  Without the main help file the contents pane
  #  is not displayed.  It turned out to be easier to manipulate the situation
  #  in this script rather than search for the option in ROBOHelp.
  
  # The help target will be the path to the target file, the base help 
  #  filename, the bookmark character (#), and finally the target file
  set TARGETURL="`dirname $1`/softWoRx.htm#`basename $1`"
endif
    
if($BROWSER != "") then

    #
    # Tell a (presumably) running netscape to open a URL or file
    #
    if($IS_URL == 1) then
        $BROWSER -remote 'openURL('$TARGETURL')' >& /dev/null
        set RETSTAT=$status
    else
        $BROWSER -remote 'openFile(file://'$TARGETURL')' >& /dev/null
        set RETSTAT=$status
    endif
    
    #
    # If there's a non-zero return code, the browser wasn't running. Start it up
    #
    if($RETSTAT != 0) then
        if($IS_URL == 1) then
                $BROWSER  $TARGETURL &
        else
                $BROWSER  file://$TARGETURL &
        endif
    endif
else
    xmessage -center -timeout 6 "No appropriate help browser could be found."
endif

