File mtt/bin/mtt_find artifact a16165e9f1 part of check-in e824121e11


#! /bin/sh

     ###################################### 
     ##### Model Transformation Tools #####
     ######################################

# Bourne shell script: mtt_find
# mtt_find path name operation
# P.J.Gawthrop Nov 1996
# Copyright (c) P.J.Gawthrop 1996

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.7  2000/10/03 18:29:57  peterg
## *** empty log message ***
##
## Revision 1.6  1998/07/17 19:47:35  peterg
## Minor changes
##
## Revision 1.5  1998/07/17 07:50:33  peterg
## Now handles library name
## Returns a status
##   0 if exactly one result
##   1 if no results
##   2 if two or more results
##   3 if utterly confused
##
## Revision 1.4  1998/07/16 20:40:24  peterg
## Cleaned up algorithms
##
## Revision 1.3  1998/07/16 09:15:34  peterg
## Now prints:
## 	dir
## 	name_lbl.txt
##         access time
##
## Revision 1.2  1997/09/04 09:15:19  peterg
## Includes summary line as well as description lines
##
## Revision 1.1  1996/11/10 10:48:45  peterg
## Initial revision
##
###############################################################

# Set up dummy file
rm -f mtt_junk
touch mtt_junk

# Interpret the arguments
path="$1"

if [ -n "$2" ]; then
    name=`basename $2`
    longname=$2
    Name="-name $name"
else
    name='*'
fi

# If this is non-empty just print the path
path_only=$3

# Find all dirs in path with same name as component
# AND the path contains the full (name+library) name
paths=`echo $path | tr ":" " "`
foundpath=`\
for thepath in $paths; do
    find $thepath -type d  $Name -print 
done |\
sort -u |\
grep "$longname"`

# If empty set foundpath to the simple components path
if [  -z "$foundpath"  ]; then
  foundpath="$MTT_LIB/comp/simple"
fi

# If non-null result, check that the name_ext file exists in dir name
# and print dirname and file name and last access time
if [ -n "$foundpath" ]; then
  if [ -n "$path_only" ]; then
    format='%h\n';
  else
    format='%h\t%f\t%Ac\n';
  fi
  for thepath in $foundpath ;  do
    if [ "$thepath" = "$MTT_COMPONENTS/simple" ]; then
        ext='cause.m'; # finds _cause.m
        simple='simple';
    else
        ext='lbl.txt'; # finds _lbl.txt
    fi    
     dirname=`basename $thepath`
     if [ -n "$simple" ]; then
      fullname="$name"_"$ext"
    else
      fullname="$dirname"_"$ext"
    fi
  find $thepath -maxdepth 1 -name $fullname  -printf $format;
 done |\
 tee mtt_junk
fi

# Check exit status and return 
hits=`wc mtt_junk | gawk '{print $1}'`
rm -f mtt_junk

if [ $hits = "1" ]; then
    exit 0
elif [ $hits = "0" ]; then
    exit 1
elif [ $hits > "1" ]; then
    exit 2
else
    exit 3
fi







MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]