#!/bin/sh
#-----------------------------------------------------------------------
#;  Copyright (C) 1996, 1998, 2004, 2007, 2010
#;  Associated Universities, Inc. Washington DC, USA.
#;
#;  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 Massachusetts Ave, Cambridge,
#;  MA 02139, USA.
#;
#;  Correspondence concerning AIPS should be addressed as follows:
#;         Internet email: aipsmail@nrao.edu.
#;         Postal address: AIPS Project Office
#;                         National Radio Astronomy Observatory
#;                         520 Edgemont Road
#;                         Charlottesville, VA 22903-2475 USA
#-----------------------------------------------------------------------
# Usage: ZXHLP2 helptag
#-----------------------------------------------------------------------
# This script displays the help text specified by helptag in a World-
# Wide Web browser.
#
# The helptag is assumed to be either the base name of an HTML file
# in AIPSHTML or the basename of of a conventional AIPS help file
# (which will be loaded as plain text).  If neither of these are true
# then the top level hypertext index file will be loaded.
#
# This version only supports the Netscape browser.  It would be
# reasonable to allow the user to choose a browser by setting an
# environment variable.
#-----------------------------------------------------------------------
#                                       Set browser: firefox
#                                       allow external setting
if [ "$AIPS_BROWSER" = "" ] ; then
   AIPS_BROWSER=firefox
fi
#                                       CGI location.  If you install a
#                                       local copy of the AIPSHELP perl
#                                       cgi script, replace this
#                                       definition.  Also, if you want
#                                       to disable the CGI (yours or
#                                       ours) totally, comment out the
#                                       next two lines.
AIPSHELP_CGI="http://www.aips.nrao.edu/cgi-bin/ZXHLP2.PL"
export AIPSHELP_CGI
#                                       --------------------------------
#                                       Check argument count
if [ $# != 1 ]
then
    echo "Usage: ZXHLP2 helptag"
    exit 1
fi
#                                       Argument
helptag=$1
#                                       full pathname of help file
pathname=""
#                                       Check for matching hypertext
if [ -r ${AIPSHTML}/${helptag}.html ]
then
    pathname="file://${AIPSHTML}/${helptag}.html"
elif [ -r ${AIPSHTML}/${helptag}.HTML ]
then
    pathname="file://${AIPSHTML}/${helptag}.HTML"
elif [ -f ${AIPSHTML}/${helptag} ]
then
    pathname="file://${AIPSHTML}/${helptag}"
elif [ -z "$AIPSHELP_CGI" ]
then
#                                       Check for plain help if there
#                                       was no hypertext
    if [ -r $HLPFIL/$helptag.HLP ]
    then
	pathname="file://${HLPFIL}/${helptag}.HLP"
    else
#                                       Use the default index page
#                                       if nothing else was found
	pathname="file://${AIPSHTML}/INDEX.html"
    fi
else
#                                       Use CGI script instead.
    pathname="${AIPSHELP_CGI}?$helptag"
fi
#                                       Now attempt to load the file
#                                       into a running web browser.  If
#                                       this fails start a new instance
#                                       of the browser of choice.  This
#                                       syntax should work for mozilla
#                                       and netscape; others may have
#                                       different conventions.
$AIPS_BROWSER -remote "OpenURL($pathname)" || $AIPS_BROWSER $pathname &
exit $?
