#!/bin/sh 
#--------------------------- Shell MegaWave Macro ----------------------------#
_sccsid="%Z%MegaWave2 %R%, %M% %I%, %G%";
_Prog="mwdoc"
_Vers="1.07";
_Date="1999-2004";
_Func="Enter the MegaWave2 documentation";
_Auth="Jacques Froment";
_Usage="[<name> || M || S || F || 1 || 2 || 3]"
#----------------------------------------------------------------------------#
# This file is part of the MegaWave2 system macros. 
# MegaWave2 is a "soft-publication" for the scientific community. It has
# been developed for research purposes and it comes without any warranty.
# The last version is available at http://www.cmla.ens-cachan.fr/Cmla/Megawave
# CMLA, Ecole Normale Superieure de Cachan, 61 av. du President Wilson,
#       94235 Cachan cedex, France. Email: megawave@cmla.ens-cachan.fr 
#-----------------------------------------------------------------------------

if [ $# -lt 1 ]; then
 echo " "
 echo "> Type the MegaWave2 documentation you want to display <"
 echo " "
 echo "<name>      : name of a module or of a user's macro"
 echo "M           : list all Modules and user's Macros"
 echo "S           : list all System's macros"
 echo "F           : list and describe available external (File) types"
 echo "1           : Vol.1  User's Guide"
 echo "2           : Vol.2  System Library"
 echo "3           : Vol.3  User's Modules and Macros Library"
 echo " "
 mwecho -n ">"
 read X
else
 X=$1 
fi

if [ "$X" = "" ]; then
  exit 0
fi
 
if [ "$X" = "1" ] || [ "$X" = "2" ] || [ "$X" = "3" ]; then

  guid=$MEGAWAVE2/doc/guid$X.dvi
  if [ ! -r ${guid} ]; then
    echo "$_Prog : no such guide available !" 1>&2
    exit 1  
  fi
  xdvi -bg white -fg black -paper a4 -s 7 $guid
  exit 0
fi

if [ "$X" = "l" ] || [ "$X" = "L" ]; then
  echo "$X : depreciated, use M instead."
  X="M"
fi

if [ "$X" = "m" ] || [ "$X" = "M" ]; then
  echo ""
  echo "----- OWN modules and user's macros -----"
  mwmodlist $MY_MEGAWAVE2
  echo ""
  echo "----- PUBLIC modules and user's macros -----"
  mwmodlist $MEGAWAVE2
  exit 0
fi

if [ "$X" = "s" ] || [ "$X" = "S" ]; then
  mwsysmaclist
  exit 0
fi

if [ "$X" = "f" ] || [ "$X" = "F" ]; then
# Select one executable module to call it with -ftypelist
  onemod=`ls -1 ${MEGAWAVE2}/bin/${MW_MACHINETYPE}  2> /dev/null`
  if [ $? -ne 0 ]; then
   echo "Error : no modules compiled or bad directory ${MEGAWAVE2}/bin/${MW_MACHINETYPE} !"
   exit 1
  fi
  onemod=`echo $onemod | cut -f 1 -d " "`
  if [ "$onemod" = "" ]; then
   echo "Error : cannot found any executable module !"
   exit 1
  fi
  echo "What kind of file type(s) are you looking for ? Please enter a keyword"
  mwecho -n "(you may use regular expression, <return> for all file types) : "
  read A
  echo ""
  echo "File type        Description"
  echo "---------        -----------"
  echo ""
  $onemod -ftypelist | grep -i -e "$A" 2> /dev/null
  if [ $? -eq 1 ]; then
   echo "No file type found that matches this keyword !"
  fi
  echo ""  
  echo "You may find more information about file types by reading"
  echo "the guide Vol.2 System Library (type 'mwdoc 2' to get it)."
  exit 0
fi

X=`basename "$X" .c`
tmod=${X}.tex
# Defaults
SRCDIR=$MY_MEGAWAVE2/doc/src
opt=""

if [ ! -r ${SRCDIR}/${tmod} ]; then
  SRCDIR=$MEGAWAVE2/doc/src
  opt="-adm"
  if [ ! -r ${SRCDIR}/${tmod} ]; then
    echo "$_Prog : no such documented module !" 1>&2
    exit 1
  fi
fi
mwdocxdvi $opt $X

