
# DO NOT REMOVE THE BLANK LINE ABOVE ...
# that blank line ensures this script is executed by sh(1).
#
#
# Stata 15 component stata_br
# version 15.0.0
# 01feb2017
#
# DESCRIPTION
#
#    When a user of Stata for Unix clicks on a {browse <url>}, by default
#    Stata executes the instruction "/usr/local/stata15/stata_br <url>",
#    prepending whatever is the appropriate directory where stata_br should
#    be located (i.e, the sysdir STATA).  E.g., if the user clicked on a 
#    link going to http://www.stata.com, Stata would execute the Unix 
#    command 
#
#        /usr/local/stata15/stata_br http://www.stata.com
#
#    and if they clicked on a link to "mailto:stata@stata.com", Stata would 
#    execute 
#
#        /usr/local/stata15/stata_br mailto:stata@stata.com
#
#    stata_br is responsible for locating and launching the browser.
#
#
#
#  ALTERNATIVES TO STATA_BR
#  -------------------------
#
#    stata_br is known to work with Firefox and may be sufficient for
#    working with other browsers.
#
#    Users of Stata may substitute a different script for launching the 
#    browser in one of two ways:
#
#        1.  They could modify this script (not recommended)
#
#        2.  They could set the Unix environment variable STATA_BR.
# 
#    Rather than calling "/usr/local/stata15/stata_br <url>", if the Unix
#    environment variable $STATA_BR is defined, Stata calls "$STATA_BR <url>".
#    In this case, Stata does *NOT* prepend the sysdir STATA to whatever is in
#    $STATA_BR.  For instance, a user might define the environment variable
#
#            sh(1)                   or        csh(1)
#            --------------------              ---------------------------
#            STATA_BR="mybrowser"              setenv STATA_BR "mybrowser"
#            export STATA_BR
#
#    Launching Stata and clicking on, say, http://www.stata.com, Stata would
#    then execute
#
#            mybrowser http://www.stata.com
#
#     Warning:  Environment variable STATA_BR may contain only one token,
#     e.g., STATA_BR might contain "mybrowser" or "/usr/local/bin/mybrowser",
#     but may not contain, for instance, "/usr/local/bin/mybrowser -r".
#
#
# UNIX ENVIRONMENT VARIABLES USED BY THIS SCRIPT
#
#            environment     default if 
#            variable        not defined        meaning
#            ------------------------------------------------------------
#            $BROWSER        "firefox"          command to launch browser
#
#    The script below also assumes that the command 
#
#            $BROWSE -remote "openURL(<url>)"
#
#    will communicate with an open browser, if one is open, and tell it
#    to go to the specified page.  If there is no open browser, this script
#    assumes the command will fail.  In that case, this script assumes
#
#            $BROWSE <url>
#
#    will launch a new browser and display the specified <url>
#


case "$BROWSER" in 
"")	cmd="firefox"
	;;
*)	cmd="$BROWSER"
	;;
esac

case "$1" in 
"")	wh="http://www.stata.com/"
	;;
*)	wh="$1"
	;;
esac

if $cmd -remote "openURL($wh)" 1>/dev/null 2>&1
then
	exit
fi

exec $cmd $wh
