File mtt/bin/mtt_help artifact 92a6751c3c part of check-in a8cce33cfa


#! /bin/sh

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

# Bourne shell script: mtt_help

# P.J.Gawthrop Nov 1996
# Copyright (c) P.J.Gawthrop 1996

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.14  2000/10/03 18:29:26  peterg
## crs now works after a fashion
##
## Revision 1.13  2000/04/04 15:22:44  peterg
## Major changes: simple components now work
## Single components now work
##
## Revision 1.12  1998/07/21 08:47:59  peterg
## Default null $2 (regexp) to '^' - ie match any line
##
## Revision 1.11  1998/07/16 20:41:05  peterg
## Now uses new mtt_help
##
## Revision 1.10  1998/05/18 08:35:19  peterg
## Surround arguments to tr with ""
##
## Revision 1.9  1998/03/26 08:23:02  peterg
## Use mixed case Topic for *) part of case sttement
##
## Revision 1.8  1998/03/22 21:13:17  peterg
## Fixed bug in above
##
## Revision 1.7  1998/03/22 20:21:11  peterg
## $topic now converted to lower case.
##
## Revision 1.6  1997/09/04 09:35:04  peterg
## Changed $ext to give accurate match -- matches t ot m at end of
## filename
##
# Revision 1.5  1997/09/04  09:21:01  peterg
# Added context-dependent sort.
#
# Revision 1.4  1997/09/04  09:16:29  peterg
# Removed sort -u
#
## Revision 1.3  1996/11/09 21:10:20  peterg
## Tidied up searches by putting everyrhing into lib.
##
# Revision 1.2  1996/11/02  10:22:54  peterg
# Now browses crs.
#
## Revision 1.1  1996/11/01 12:34:54  peterg
## Initial revision
##
###############################################################

comment='#';
Topic=$1
topic=`echo $Topic | tr "[A-Z]" "[a-z]"`

if [ -n "$2" ]; then
    regexp=$2;
else
    regexp='^';
fi

if [ "$topic" = "" ]; then
    echo 'Usage: mtt help representations'
    echo '       mtt help simple'
    echo '       mtt help components'
    echo '       mtt help examples' 
    echo '       mtt help CRs'    
    echo '       mtt help representations <match_string>'
    echo '       mtt help components <match_string>'
    echo '       mtt help examples  <match_string>'
    echo '       mtt help CRs <match_string>'
    echo '       mtt help <component_or_example_or_CR_name>'
  exit
fi

ext='_[cl]*.*[mt]'
summary='[%#]SUMMARY'
description='[%#]DESCRIPTION'
alias='[%#]ALIAS'
lbl="_lbl.txt"

case $topic in
  components)
    key=$summary 
    find_path="$MTT_COMPONENTS"
    name=''
    sort='sort -u'
    blurb="components";;

  simple)
    key=$summary 
    find_path="$MTT_COMPONENTS/simple"
    name=''
    sort='sort -u'
    blurb="simple components";;

  crs) 
    key=$summary 
    find_path=$MTT_CRS/r
    name='*.cr'
    sort='sort -u'
    blurb="constitutive relationships";;

  examples) 
    key=$summary 
    find_path=$MTT_EXAMPLES
    name=''
    all='all'
    sort='sort -u'
    blurb="Examples";;

  representations)
    key=$summary 
    find_path=$MTTPATH
    name='mtt'
    all='all'
    sort='sort -u'
    blurb="Representations";;

  *)
    other=OTHER;
    key="$summary|$description|$alias" 
    find_path=$MTT_LIB
    name=$Topic
    all='all'
    sort='cat'
    blurb=$Topic;;     
esac

subtopic=$2
if [ "$subtopic" = "" ]; then
  subtopic='.'
fi;


case $topic in
    representations)
         echo $comment $blurb
         mtt2reps_txt

	;;
    crs)
	echo  $comment $blurb
        find $find_path -name "$name" -print |\
        gawk '{print "grep", key, $1}' key=$key | sh |\
        sed "s/$key //" | $sort
	;;
    *)
	
    fullnames=`mtt_find $find_path "$name" | gawk '{printf("%s/%s\n",$1,$2)}'`
    N=`echo $fullnames | wc -w`;
    if [ -z "$fullnames" ]; then
	echo $comment No $blurb found.
    else
    echo $comment $N $blurb found.
    for fullname in $fullnames; do
        name=`basename $fullname`
	if [ -n "$other" ]; then
	cat $fullname | egrep $key 
	else
        info=`cat $fullname | egrep $key | gawk '{for (i=2;i<=NF;i++) print $i}'`
	category=`echo $fullname |   sed "s!$find_path/!!" ` 
        category=`dirname $category`
	echo $category $name $info
	fi
    done
    fi
  esac
exit


  gawk '{print "cat " $1 "/" $2}'  | sh |\
  egrep $key  | egrep $regexp  |\
  sed "s/$summary[	]*//" |\
  sed "s/$description[	]*/  /" |\
  sed "s/$alias[	]*/  Alias: /" |\
  sed "s!$find_path/!!" |\
  $sort










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