#!/bin/sh
#
# simhelp : Corresponds to 'man' for the standard install of Simscript.
# =======   (no write access to man pages at install time).
#
# simhelp topic looks for a file $1 in the $SIMHOME/help directory.
# The help files are already processed with nroff. 
# The help files here contain _^H sequences to do underlining. When your
# tty display/ terminal emulator doesn't support that you can call simhelp
# with the option "noctrl" to filter out those control sequences.
#
# This program resides in $SIMHOME/bin (dir should be in PATH). It is used/
# needed only for the standard installation.
#---------------------------------------------------------------------------


#
prog=`basename $0`
STANDARD_INSTALL=y
INST_HELP=$SIMHOME/help

#-- check if SIMHOME is used and defined
if [ "$STANDARD_INSTALL" = "y"  -a  "$SIMHOME" = "" ]; then
  echo "$prog ERROR: Env. var SIMHOME undefined. Cannot run. Aborted."
  exit 1
fi
#

#---- do we have a topic argument ??
if [ $# -lt 1 ]; then
  echo "simhelp topic [noctrl]  : Simscript help information on topic."
  echo 
  echo "  topic  : Shows help/man page on Simscript topic."
  echo "  noctrl : filter out _^H control sequences (underlining)"
  echo
  echo "---- Currently available topics are: ---- "
  ls $INST_HELP
  exit 0
fi

#---- has topic a man page ?
if [ ! -f $INST_HELP/$1 ]; then
  echo "$prog: No help page available for '$1'."
  exit 1
fi
#
if [ "$2" = "noctrl" ]; then
  cat $INST_HELP/$1 | sed '/_/ s/_//g' | more
else
  more $INST_HELP/$1 
fi
