#!/bin/sh
#
# Usage: prun [ directory ] program [ arguments ]
# Compiles program.p and then runs program (with arguments).
# If directory is given then the output is sent by mail - otherwise to stdout
# Transcribes output to program.log

if [ -d $1 ]; then
  cd $1
  shift
  prun "$@" > /dev/null
  mail $USER < $1.log
  exit 0
fi

( date
  echo prun: compiling and running $1.p on `hostname`
  pc -xl -O -Bstatic -o $1 $1.p 2>&1 &&\
  nice -15 time "$@" 2>&1
  date
) 2>&1 | tee $1.log

test -z "`egrep -i done  $1.log`" && exit 0
test -z "`egrep -i error $1.log`" || exit 0
:> $1.done

