#!/usr/bin/bash

#AnalyzeScript
#1/23/02
#Corinne McNeely

#User may modify the TEXTBROWSER and SMV variable to reflect correct paths.
TEXTBROWSER=write.exe
SMV=./smv/smv.exe

#setting path variables
PARAGEN=./paragen.exe
PARA2SMV=./para2smv.exe
STRIPCR=./stripcr.sh 

#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.out.nocr - created by stripcr.sh which strips out the carriage returns
#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  && 
$STRIPCR $FILENAME.out 
$PARA2SMV -c $FILENAME.ctl $FILENAME.out.nocr > $FILENAME.smv 2>> $FILENAME.err &&  
$SMV $FILENAME.smv > "$FILENAME"_smv.out 2>> $FILENAME.err

if [[ $? -eq 0 ]] 
then
    $TEXTBROWSER $FILENAME.out.nocr &
    $TEXTBROWSER $FILENAME.smv &
    $TEXTBROWSER "$FILENAME"_smv.out &
else
    $TEXTBROWSER $FILENAME.err &
fi
