File mttroot/mtt/bin/trans/mtt_update artifact 9f0ffb24f1 part of check-in 9a68fc3954


#!/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.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

ext=txt
textfile=$1_$2.$ext
infofile=$1_sympar.$ext
default='1.0'

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

# 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;
  }
END{
  # for (iname in info) print iname
  for (tname in text) {
    if (!(tname in info)) print tname >> "mtt_in_text"
  }
  for (iname in info) {
    if (!(iname in text)) print iname >> "mtt_in_info"
  }
  }'  default=$default mtt_text mtt_info


if [ -z "$update" ]; then
  if [ -f "mtt_in_text" ]; then
    in_text=`cat mtt_in_text`
    echo "The following variables are defined in $textfile, but do not exist:"
    echo $in_text
    echo Use mtt $sys $rep $ext to update
  fi
  if [ -f "mtt_in_info" ]; then
    in_info=`cat mtt_in_info`
    echo "The following variables exist, but are not defined in $textfile:"
    echo $in_info
    echo Use mtt $sys $rep $ext to update
  fi
  exit    
fi
answered=''
if [ -f "mtt_in_text" ]; then
  in_text=`cat mtt_in_text`
  echo "The following variables are defined in $textfile, but do not exist:"
  echo $in_text    

  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
	      sed "s/\($old[ \t]*=\)/## 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=`cat mtt_in_info`
  echo "The following variables exist, but are not defined in $textfile:"
  echo $in_info

  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 "$new = $default; # Added by MTT on `date`" >> $textfile
                changed=yes
	    done
	    ;;
	n)
	    answered=yes
	    ;;
	*)
    esac
  done      
fi


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