#!/bin/sh
comment=`gsnd bbprint.ps bb4gs.ps $1 quit.ps </dev/null | grep %%`
if [ -n "$comment" ]; then
     echo computed bounding box: $comment 1>&2
else
     echo could not find bounding box. 1>&2
     exit 1
fi
if grep -s %%BoundingBox $1 ; then
     echo replacing bounding box. 1>&2
     # replace the bounding box and write it out to stdout
     sed -e "/%%BoundingBox/s/.*/$comment/" <$1
else
     echo inserting bounding box. 1>&2
     # insert the bounding box on the second line and write it out to stdout
     sed -e '2i\
'"$comment"'
' <$1
fi
exit
