wsh/
wsh/binsrc/
wsh/docs/help/
wsh/docs/old/
wsh/etc/
wsh/src/util/
#!/bin/sh
# try /bin/sh5 if you get errors
#
#           help (sh version 1.3)
#
# This is another option to using help.c
# This has two distinct advantages:
#   It takes up less space than an executable
#   It searches all the directories in the HELP_PATH variable inside of DOC_DIR
# The disadvantage is that it is much slower.
# Also, realize that this program can be fooled by links (in case you allow
# your wizzes to use the 'ln' command) - so that if a link were made to outside
# the mud directory, then they would have access to read your files.
# In fact, this program gives them read access to anything inside of HELP_PATH
# Make sure you set the following options:

# default file (if no arg)
#
DEFAULT_HELP="wshhelp"

# The prefix of all help directories (don't use any '/' in any of the paths)
#
DOC_DIR="doc"

# paths to search in
#
HELP_PATH=". helpdir efun lfun wshdocs"

# what pager to use
# if you want 'less,' then make sure you use the full path to the MODIFIED less!
#
#PAGER=cat
PAGER=less

#############################################################################
#                                                                           #
#  shell help                                                               #
#  You shouldn't need to touch anything below here                          #
#                                                                           #
#############################################################################


# for 'help topics'
do_topics() {
  topic_prompt=""
  for p in $HELP_PATH; do
# do a prompt if this isn't the first time
    echo
    if [ -n "$topic_prompt" ]; then
      echo "$DOC_DIR/$p:: hit return to continue ('q' to quit)..."
      read answer
      if [ "$answer" = "q" ]; then
        return
      fi
    else
      echo "$DOC_DIR/$p::"
    fi

    ls $DOC_DIR/$p/
    topic_prompt="yuppers"
  done
}

# $1 is name of file - assume that it exists
do_file() {
  if [ "$1" = "topics" ]; then
    do_topics
    return 1
  fi
  for p in $HELP_PATH; do
    if [ -r $DOC_DIR/$p/$1 ]; then
      echo File: /$DOC_DIR/$p/$1::
      $PAGER $DOC_DIR/$p/$1
      return 1
    fi
  done
  return 0
}

if [ $# -lt 1 ]; then
  do_file $DEFAULT_HELP
  if [ $? -ne 1 ]; then
    echo "Couldn't find help for: $DEFAULT_HELP"
  fi
else
  FILES=$*
  for FILE in $FILES; do
# do a prompt if this isn't the first time
    if [ -n "$PROMPT" ]; then
      echo "Done.  Hit return to continue ('q' to quit)..."
      read answer
      if [ "$answer" = "q" ]; then
        exit
      fi
    fi

# do the file
    do_file $FILE
    if [ $? -ne 1 ]; then
      echo "Couldn't find help for: $FILE"
    fi

# next time, do a prompt
    PROMPT="yuppers"
  done
fi

exit