#!/bin/sh 
#--------------------------- Shell MegaWave Macro ----------------------------#
_sccsid="%Z%MegaWave2 %R%, %M% %I%, %G%";
_Prog="mwwhere"
_Vers="1.04";
_Date="1999-2002";
_Func="Give the location(s) where the module is";
_Auth="Jacques Froment";
_Usage="[-macro] [-bin] module"
#----------------------------------------------------------------------------#
# 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 
#-----------------------------------------------------------------------------

# Search on MegaWave2 directory $1
Where()

{
 if [ $macro -eq 1 ]; then
   mbin=$1/shell/${bmodule}
 else
   mbin=$1/bin/${MW_MACHINETYPE}/${bmodule}
 fi

 if [ -d $1/src ]; then
   if [ $bin -eq 0 ] || [ -x $mbin ]; then
     find $1/src -name "${module}" -print
   fi
 fi
}

# Check input
if [ $# -lt 1 ] || [ $# -gt 3 ]; then
   . .mw2_help_lg_com
fi


# Defaults
macro=0
bin=0

while [ "$1" != "" ]
do
    case "$1" in

# Identify a module as a macro
    -macro) macro=1
            shift
 	    ;;

# Give the location if the binary exists only
    -bin)  bin=1
           shift
           ;;

    -*)   . .mw2_help_lg_com;
	  ;;

    *)  module=$1
        shift
	;;

    esac
done

# Automatically identifies a module as a macro when its name 
# begins with a capital letter.
if [ $macro -eq 0 ]; then
 mwisupper $module > /dev/null
 macro=$?
fi

bmodule=`basename $module .c`
if [ $macro -eq 0 ]; then
  module=${bmodule}.c
else
  module=$bmodule
fi

modfound1=`Where ${MY_MEGAWAVE2}`
if [ "$modfound1" != "" ]; then
  echo $modfound1
fi
modfound2=`Where ${MEGAWAVE2}`
if [ "$modfound2" != "" ]; then
  echo $modfound2
fi

# Exit 2 in case of hidden module
if [ $bin -eq 1 ] && [ "$modfound1" != "" ] && [ "$modfound2" != "" ]; then
  exit 2
fi
exit 0








