#!/usr/bin/ksh

#AnalyzeScript
#1/23/02
#Corinne McNeely

#setting path variables
PARAGEN=./ParaGen
PARA2SMV=./Para2Smv
#Eventually TEXTBROWSER and SMV will be set by the user.
TEXTBROWSER=xemacs
SMV=./smv/smv

#The PLAT demo passes in the DemoType.
DEMOTYPE="${1:-foo}"
#The demo type determines the Filename or relative path of the related .argo, .xmi, .ctl files
if [[ $DEMOTYPE = "Browser" ]]
then
    FILENAME=browser/Browser
elif [[ $DEMOTYPE = "afs" ]]
then 
    FILENAME=afs/afs
else
    print "Demo ${DEMOTYPE} does not exist."
    exit
fi

#The LD_LIBRARY_PATH must be set to the current location of the  Xerxes Library
#ParaGen will not run without it.
export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH

#These commands run ParaGen, Para2Smv, and SMV seqentially.
#If the programs exit correctly, the text browser will display the output of all three programs:
#Demo.out - Paragen output
#Demo.smv - Para2Smv output
#Demo_smv.out - Smv output.
#If any of the programs exits incorrectly, the text browser will display the Demo.err file which 
#contains any error messages.  
$PARAGEN $FILENAME.xmi > $FILENAME.out 2> $FILENAME.err  && \
$PARA2SMV -c $FILENAME.ctl $FILENAME.out > $FILENAME.smv 2>> $FILENAME.err && \
$SMV $FILENAME.smv > "$FILENAME"_smv.out 2>> $FILENAME.err
if [[ $? -eq 0 ]] 
then
    $TEXTBROWSER $FILENAME.out &
    $TEXTBROWSER $FILENAME.smv &
    $TEXTBROWSER "$FILENAME"_smv.out &
else
    $TEXTBROWSER $FILENAME.err &
fi
