#! /bin/sh /usr/share/dpatch/dpatch-run
## 302-scripts-comply-with-FHS.dpatch by  <kmccarty@debian.org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Put data files under @DATADIR@ and assume $CERN is @PREFIX@ by default
## DP: in scripts.  (These values are filled in from add-ons/Makefile.)
## DP: Also some other improvements.

@DPATCH@
diff -urNad cernlib-2005.05.09.dfsg~/src/scripts/paw cernlib-2005.05.09.dfsg/src/scripts/paw
--- cernlib-2005.05.09.dfsg~/src/scripts/paw	1995-02-07 04:54:06.000000000 -0500
+++ cernlib-2005.05.09.dfsg/src/scripts/paw	2005-12-13 10:10:17.850939931 -0500
@@ -21,9 +21,9 @@
   SHOPT="d:h:v:"
 #SEQ,GETOPTD.
   [ "`uname -s`" = "DomainOS" ] && drv="GKS" || drv="X11"
-  [ -z "$CERN"       ] && CERN="/cern"
-  [ -z "$CERN_LEVEL" ] && ver="pro" || ver="$CERN_LEVEL"
- 
+  [ -z "$CERN"       ] && CERN="@PREFIX@"
+  [ -z "$CERN_LEVEL" ] && ver="" || ver="$CERN_LEVEL"
+  [ -e "$CERN/$CERN_LEVEL/bin/pawX11" ] || drv="++" # use paw++ if no pawX11
   while [ $# -gt 0 ]
   do case $1 in
        -d) drv=$2 ; shift      ;;
@@ -43,15 +43,26 @@
 #    inlib $GKS_INLIB
      GDIR=$CERN/$ver/gksbin
   fi
-  if [ "$drv" = "X11" -a -n "$hst" ] ; then
+  if [ \( "$drv" = "X11" -o "$drv" = "++" \) -a -n "$hst" ] ; then
      nw=`echo $hst | awk -F: '{ print NF }'`
      [ $nw -eq 1 ] && hst="$hst:0"
      DISPLAY="$hst" ; export DISPLAY
   fi
-  if [ "$ver" != "pro" ] ; then
+  if [ -n "$ver" ] ; then
      echo
      echo " Calling $ver version of paw-$drv"
      echo
   fi
-  $GDIR/paw$drv $*
-  [ ! -s paw.metafile ] && rm paw.metafile
+  if [ ! -x "$GDIR/paw$drv" ] ; then
+     echo " Error: PAW executable $GDIR/paw${drv} does not exist!"
+     exit 1
+  fi
+  "$GDIR/paw$drv" "$@"
+  [ ! -s paw.metafile ] && rm -f paw.metafile
+  [ ! -s PAW.METAFILE ] && rm -f PAW.METAFILE
+
+  # clean up comis temporary working directories if empty
+  [ "`(echo /tmp/comis*) 2> /dev/null`" = '/tmp/comis*' ] || \
+    rmdir /tmp/comis* > /dev/null 2>&1 || true
+  [ "`(echo "$TMPDIR"/comis*) 2> /dev/null`" = "$TMPDIR"/'comis*' ] || \
+    rmdir "$TMPDIR"/comis* > /dev/null 2>&1 || true
