#! /bin/csh
#
# ps2tex command modifies the postscript file to be accepted by the epsf macro
# 
# 
echo "ps2tex processing $1"
#
set S = "%%BoundingBox:"
if !(-f $1) then
  echo file not found : $1
  exit
endif
set info=`grep $S $1` 
if ("$info" == "") then
  set info="$S""0 0 596 846" 
endif
echo $info >> $1
#
set C = "%%EndComments"
set comment=`grep $C $1`
if ("$comment" == "") then
  echo "No EndComments"
  exit
endif
#
set P = "showpage"
set page=`grep $P $1`
if ("$page" == "") then
  echo "No showpage"
  set C1="1"
else
  set C1='1,\$s/showpage//g' 
endif 
#
ed -  <<FINI 
E $1
${C1}
1,\$s/^%%BoundingBox:[ ]*\([-0-9]*\)\([-0-9.]*\)[      ]*\([-0-9]*\)\([-0-9.]*\)[         ]*\([-0-9]*\)\([-0-9.]*\)[    ]*\([-0-9]*\)\([-0-9.]*\)/%%BoundingBox: \1 \3 \5 \7/
/^%%EndComments/
/^\%\%BoundingBox/m-1
\$d
w $1
Q
FINI


