#! /bin/sh
 
#   DEC 09/91 - F.Majaess
 
#id aid     - Used to list help lines from a script (or file)
 
#   AUTHOR  - F.Majaess
 
#hd PURPOSE - "aid" script is used to list help lines for "procnam" script
#hd           (or file) in "lpath" subdirectory.
#hd           NOTE: "procnam" is ignored if ("full" = "yes").
 
#pr PARAMETERS:
#pr
#pr   POSITIONAL     
#pr
#pr     procnam = script (or file) name 
#pr               (needed only if "full" != "yes").
#pr
#pr   PRIMARY/SECONDARY
#pr
#pr     full   = switch accomodating user request to process whole set in 
#pr              "lpath" (=no/yes).
#pr     lpath  = path of subdirectory containing scripts (=$CCRNSTD/$SUBPROC).
#pr
#ex EXAMPLE: 
#ex
#ex   aid aid
#ex   aid  procnam=audit
#ex   aid  full lpath
 
IFS=' '
export IFS

unset procnam full lpath prmtrl

#  * Obtain the file names and any specified option.

arg_list=$@
for arg in $arg_list
do
  case $arg in
      -*) set $arg ; set_opt=$arg  ;;
     *=*) eval $arg                ;;
    full) full=yes                 ;;
   lpath) lpath="$SUBPROC"         ;;
       *) tmp1=${procnam:+$arg} ;
          procnam=${procnam:=$arg}
  esac
done

full=${full:='no'}
lpath=${lpath:="$CCRNSTD"}

if [ "$full" != "yes" ] ; then

#     * Prompt for a positional parameter value(s) if none was/were
#     * specified...
 
  while [ -z "$procnam" ] ; do
    echo "please enter script (or file) name ? > \\c"
    read procnam
  done
 
  prmtrl="$procnam"
  Teor=
else
  if [ -d "${lpath}/." ] ; then
   cd $lpath
   prmtrl=`echo *`
   if [ "$prmtrl" = 'echo *' ] ; then
    unset prmtrl
   fi
  fi
# Teor=" ; echo '*EOR' "
  Teor=" ; echo '' "
fi
 
#   ****   Task of the script...   ****
 
# * cycle through parameter(s) in "prmtrl"...
 
procnam=''
 
for procnam in $prmtrl
 do
 
# * if script file exist, non-empty with read permission use it ...
# * otherwise display an error message.
 
 if [ -n "${procnam}" -a ! -d "${procnam}/." ] ; then
  if [ -f $lpath/$procnam ] ; then
   if [ -s $lpath/$procnam -a -r $lpath/$procnam ] ; then
    eval "( sed -n -e 's/^#hd / /p' -e 's/^#pr / /p' -e 's/^#ex / /p' \\
                          $lpath/$procnam $Teor ) | ${PAGER-more } "
   fi
  else
    if [ -n "$CCRNSTD" -a "$lpath" = "$CCRNSTD" ] ; then
     if [ -n "${BEDIR}" -a -d "${BEDIR}/." ] ; then
      eval "aid $set_opt lpath=$BEDIR full=$full $procnam "
     else
      if [ -n "${SUBPROC}" -a -d "${SUBPROC}/." ] ; then
       eval "aid $set_opt lpath=$SUBPROC full=$full $procnam "
      fi
     fi
    else
     if [ -n "${BEDIR}" -a "$lpath" = "$BEDIR" -a -n "${SUBPROC}" ] ; then
       eval "aid $set_opt lpath=$SUBPROC full=$full $procnam "
     else
      if [ -n "$procnam" -a ! -d "${procnam}/." ] ; then
       eval "echo $procnam file is not found !"
#      exit 2
      fi
     fi
    fi
  fi
 fi
done

if [ "$full" = "yes" ] ; then
  if [ -n "$CCRNSTD" -a "$lpath" = "$CCRNSTD"  ] ; then
     if [ -n "${BEDIR}" -a -d "${BEDIR}/." ] ; then
      eval "aid $set_opt lpath=$BEDIR full=$full $procnam "
     else
      if [ -n "${SUBPROC}" -a -d "${SUBPROC}/." ] ; then
       eval "aid $set_opt lpath=$SUBPROC full=$full $procnam "
      fi
     fi
  fi
  if [ -n "${BEDIR}" -a "$lpath" = "$BEDIR"  ] ; then
    if [ -n "${SUBPROC}" -a -d "${SUBPROC}/." ] ; then
      eval "aid $set_opt lpath=$SUBPROC full=$full $procnam "
    fi
  fi
fi
