#!/bin/bash
#
# Scriptname: generate-diff-report
#     Author: Shri Amit (amit)     
#
#      Usage: generate-diff-report -i <ImageName> -[w] -r <Root> 
#             -p <PersonalRoot> -l <LibraryName> -s <SuiteName> -f <LogFile>
#   Synopsis: The following script starts <ImageName>, the argument
#	      to -[webster|emulator] and compiles and executes <SuiteName>, 
#             the argument to -suite, with the diff-report-function.
#	      The output is stored into <LogFile>, the arg to -logfile
#             Only webster & emulator images are supported.
#  Arguments: -i: Image
#             -w: Marks Image to be a webster image otherwise assumes to
#                 be an emulator image. (No args, this is only a flag)
#             -r: Dylan Root, defaults to ~/releases/webster-8000
#             -p: Dylan Personal Root to ~/
#             -l: Name of Library in which suite is contained
#             -s: Name of Suite(emulator) or App (Webster) , defaults to
#                 LibraryName
#             -f: DiffReportLogFile
############################################################################

## Initialize all constants

script=`basename $0`
platform=`/u/dylan/tools/admin/get-host-name.pl`
report="diff-report-function"
websh=/u/dylan/releases/webster/admin/webster-env.sh

## Parse the options & flags on the command line

while getopts i:r:p:s:l:f:w option
do case $option in
     i) image=$OPTARG;;
     r) root=$OPTARG;;
     p) personalroot=$OPTARG;;
     s) suitename=$OPTARG;;
     f) logfile=$OPTARG;;
     w) imagetype=2;;
     l) libraryname=$OPTARG;;
    \?) echo "Usage: generate-diff-report -[w|e] <ImageName> -r <Root> -p <PersonalRoot> -s <SuiteName> -l <LogFile>"
        exit 2;;
   esac
done
shift `expr $OPTIND - 1`

## Assign defaults

image=${image:-foo}
suitename=${suitename:-$libraryname}
imagetype=${imagetype:-1}
personalroot=${personalroot:-~/}
root=${root:-~/releases/webster-8000}
builddir=$root/build/$platform

## Ensure image existance

if test ! -f $image; then
  echo "$script: Invalid image pathname. What should I compile in?"
  echo "Usage: generate-diff-report -[w|e] <ImageName> -r <Root> -p <PersonalRoot> -s <SuiteName> -l <LogFile>"
  exit 1;
fi

## Depending upon imagetype, compile suite and emit diff logfile

if test $imagetype -eq 1; then
  echo "All initializations successful ... starting the emulator ..."
  echo
  $image -init - <<SCRIPT
  (dylan:tty-infix-dylan-listen)
  import-cl-functions(system(bye)(as: bye));
  in: $libraryname;
  run-test-application($suitename, filename: $logfile, report-function: $report);
  bye:;
  (bye 0)
SCRIPT
  exit 0;
elif test $imagetype -eq 2; then
  echo "All initializations successful ... starting webster ..."
  echo
  $image -r $root -pr $personalroot <<SCRIPT
  (dylan:tty-infix-dylan-listen)
  import-cl-functions(system(bye)(as: bye));
  update-libraries(#"$libraryname");
  bye:;
  (bye 0)
SCRIPT
  cd $builddir/$suitename
  source $websh -r $root -pr $personalroot
  make app
  `./$suitename -report diff > $logfile`
  exit 0;
fi

#eof

syntax highlighted by Code2HTML, v. 0.9.1