#!/bin/sh
######################################
##### Model Transformation Tools #####
######################################
# Bourne shell script: mtt_update
# Generates Updates core representations
# Copyright (C) 2000 by Peter J. Gawthrop
###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.9 2000/10/13 09:55:09 peterg
## Changed state/input name to $4_$3
##
## Revision 1.8 2000/10/13 09:28:16 peterg
## Changed regexp to /\(.*$old.*=\)/
##
## Revision 1.7 2000/10/13 08:56:51 peterg
## Output variables as column, not row.
##
## Revision 1.6 2000/10/13 08:07:24 peterg
## Added state and input - it checks against sympar as well so that
## defined variables may be used here.
##
## Revision 1.5 2000/10/12 19:24:55 peterg
## Corrected output message
##
## Revision 1.4 2000/10/12 17:57:34 peterg
## Fixed header typos
##
## Revision 1.3 2000/10/12 15:11:30 peterg
## Added the update switch
##
## Revision 1.2 2000/10/12 13:45:13 peterg
## Put in the no-file version
##
## Revision 1.1 2000/10/12 12:32:23 peterg
## Initial revision
##
##
###############################################################
sys=$1 # System name
rep=$2 # System representation
update=$3 # Update or not
if [ -z "$2" ]; then
echo Usage mtt_update system representation [update]
exit
fi
rm -f mtt_empty
touch mtt_empty
case $rep in
numpar)
ext=txt
textfile=$1_$2.$ext
infofile=$1_sympar.$ext
moreinfofile=$infofile
default='1.0'
;;
state|input)
ext=txt
textfile=$1_$2.$ext
infofile=mtt_list.$ext
moreinfofile=mtt_list_numpar.$ext
grep "$rep" <$1_struc.txt |\
awk '{printf("%s\n", $4)}' \
> $infofile
cat $infofile $1_sympar.$ext> $moreinfofile
default='0.0'
;;
*)
echo Representation $rep not implemented
exit
esac
if [ -f "$textfile" ]; then
# Inform User
echo Checking $textfile
else
sympar2numpar_txt2txt $1
exit
fi
# Remove tmp files
rm -f mtt_in_text mtt_in_info
# Strip files
strip_comments <$textfile >mtt_text
strip_comments <$infofile >mtt_info
strip_comments <$moreinfofile >mtt_moreinfo
# Use awk to check file
awk '{
if (FILENAME=="mtt_text") {
gsub("[\t ]" ,""); # Remove whitespace
split($0,a,"=");
text[a[1]] = a[2];
}
if (FILENAME=="mtt_info"){
info[$1] = default;
}
if (FILENAME=="mtt_moreinfo"){
moreinfo[$1] = default;
}
}
END{
# for (iname in info) print iname
for (tname in text) {
if (!(tname in moreinfo)) print tname >> "mtt_in_text"
}
for (iname in info) {
if (!(iname in text)) print iname >> "mtt_in_info"
}
}' default=$default mtt_text mtt_info mtt_moreinfo
if [ -z "$update" ]; then
if [ -f "mtt_in_text" ]; then
echo "The following variables are defined in $textfile, but do not exist:"
sort mtt_in_text | awk '{printf("\t%s\n",$1)}'
echo Use mtt $sys $rep $ext to update
fi
if [ -f "mtt_in_info" ]; then
echo "The following variables exist, but are not defined in $textfile:"
sort mtt_in_info | awk '{printf("\t%s\n",$1)}'
echo Use mtt $sys $rep $ext to update
fi
exit
fi
answered=''
if [ -f "mtt_in_text" ]; then
in_text=`sort mtt_in_text`
echo "The following variables are defined in $textfile, but do not exist:"
sort mtt_in_text | awk '{printf("\t%s\n",$1)}'
while [ -z "$answered" ]; do
echo "Update $textfile (y/n)?"
read answer < /dev/tty
case $answer in
y)
answered=yes
for old in $in_text; do
echo Commenting out $old
sed "s/\(.*$old.*=\)/## Removed by MTT on `date`: \1/"\
<$textfile > mtt_tmp
mv mtt_tmp $textfile
changed=yes
done
;;
n)
answered=yes
;;
*)
esac
done
fi
answered=''
if [ -f "mtt_in_info" ]; then
in_info=`sort mtt_in_info`
echo "The following variables exist, but are not defined in $textfile:"
sort mtt_in_info | awk '{printf("\t%s\n",$1)}'
while [ -z "$answered" ]; do
echo "Update $textfile (y/n)?"
read answer < /dev/tty
case $answer in
y)
answered=yes
for new in $in_info; do
echo Adding $new
echo "$new = $default; # Added by MTT on `date`" >> $textfile
changed=yes
done
;;
n)
answered=yes
;;
*)
esac
done
fi