#!/bin/sh

if test "$1" = ""
then
  echo "This is a tool to fix the bounding box of a .ps or .eps file"
  echo "Usage: ./bbox <name.ps>"
  exit
fi

SIZE0=`grep -n "%%Bounding" $1`
SIZE=`gs -sDEVICE=bbox -dNOPAUSE -dQUIET $1 -c quit 2>&1`

N=`echo $SIZE0 | cut -d":" -f 1`

head -n $[$N-1] $1 > mod_$1
echo "$SIZE" | sed -e "/-1/s//0/g" >> mod_$1
tail -n +$[$N+2] $1 >> mod_$1

echo "$1 : $SIZE0 --> $SIZE"

