File mttroot/mtt/bin/trans/sub_sh2tex artifact dc7875384c part of check-in fd75fa927a


#!/bin/sh

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

# Bourne shell script: sub_sh2tex
# Converts _sub_sh files to a latex itemized list.
# P.J.Gawthrop May 1997
# Copyright (c) P.J.Gawthrop, 1997.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.5  2004/02/10 16:11:01  gawthrop
## Removed debug
##
## Revision 1.4  2004/02/10 10:22:10  gawthrop
## Do proper arithmetic via let
## Three levels of output
## enumerate, not itemize
##
## Revision 1.3  2004/02/10 10:13:05  gawthrop
## Handles #SUMMARY correctely
## Refined count of subsystems within fig file (avoilds ports with same
## name as system
##
## Revision 1.2  2004/02/10 09:51:07  gawthrop
## Updated obsolete path name.
##
## Revision 1.1  2000/12/27 16:04:08  peterg
## Initial revision
##
## Revision 1.7  1998/02/04 10:59:37  peterg
## Tidied up.
##
# Revision 1.6  1997/09/08  19:42:37  peterg
# Replaced copy by compcopy
#
## Revision 1.5  1997/08/15 11:20:13  peterg
## Explicitly copies compound components (if not already there)
##
# Revision 1.4  1997/06/24  08:28:26  peterg
# Now takes %SUMMARY description from the label file
# Appends count of number of subsystems at that level
#
## Revision 1.3  1997/05/21 10:07:36  peterg
## Fixed \ probs for GNU sh/echo
##
## Revision 1.2  1997/05/19 16:46:17  peterg
## *** empty log message ***
##
# Revision 1.1  1997/05/19  11:29:44  peterg
# Initial revision
#
###############################################################


#Useful strings
quote="'";
listtype="enumerate"

# Maximum list depth 
# Just go to 3 levels
maxlevel=3; 

#Look for a command line argument
labels=''; arg='';
while [ -n "`echo $1 | grep '-'`" ]; do
  case $1 in
	-l )
		labels='yes'; arg='-l' ;;
	*)
		echo "$1 is an invalid argument - ignoring" ;;
  esac
  shift
done


system=$1
filename=$2 


if [ -z "$3" ]; then
    let level=0;
else
    let level=$4;
fi
echo "level: $level"
#Top-level commands
if [ -z "$2" ]; then
  filename="$1_sub.tex"

  # Inform user
  echo "Creating $filename"

  #Write some file headers
  echo "% Subsystem file for system $system ($filename)"   > $filename
  echo "% Generated by MTT at `date`"  >> $filename
  echo  >> $filename
fi

# Write list item if not at the top level.
if [ -n "$2" ]; then
  #Set up some names
  filename=$2
  abgfile=$3_abg.m
  lblfile=$1_lbl.txt
  summary='[%|#]SUMMARY'

  #Get the system description, copying where necesary
  mtt -q -u compcopy $system $MTT_LIB/comp/compound
  # mtt -q -u $system lbl txt
  desc=`grep $summary $lblfile | sed "s/$summary//"`

  #Count the number of subsystems
  subs=`grep -c " $system" $abgfile`

  if [ "$labels" = "yes" ]; then
    echo '  \item '$desc ' ('$subs') Section \Ref{sec:'$system'}' >> $filename
  else
    echo '  \item' $desc ' ('$subs')'   >> $filename
  fi
fi

# Create the subsystem sh files (if not too deep)
if [ "$level" != "$maxlevel" ]; then
    mtt -q -u  -l 1 $system sub sh

    # Write the list of subsystems (if they exist).
    n_subsystems=`grep -c '$1' $1_sub.sh`

    if [ "$n_subsystems" != "0" ]; then
	cat <<EOF >> $filename
	    \begin{$listtype}
EOF
	# Recursively generate the subsystems
        let level1="$level+1"
	sh $system\_sub.sh "sub_sh2tex $arg " " $filename $system $level1" 
	cat <<EOF >> $filename
	    \end{$listtype}
EOF
#else
#    cat  <<EOF >> $filename
#         No subsystems.
#EOF
fi
fi










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