#! /bin/sh

# Make relative URLs in trabaco.pt.pdf (or some other file named in
# the second argument) relative to the directory containing the file
# (or any URL in the first argument).

case $2 in
"")
  dir=`dirname $0`
  cd "$dir"
  dir=`pwd`
  filebase=trabaco.pt
  ;;
*.pdf)
  dir=`dirname "$2"`
  cd "$dir" || exit 1
  dir=`pwd`
  filebase=`basename "$2" .pdf`
  ;;
*)
  dir=$2
  cd "$dir"
  dir=`pwd`
  filebase=trabaco.pt
  ;;
esac

case $1 in
"") url=file://$dir ;;
*) url=$1 ;;
esac

url=`echo "$url" | sed 's,/,\\\\/,g'`

cd "$dir" || exit 1

sed "s/URI(http:\\/\\/www.fsfla.org\\/~lxoliva\\/fsfla\\/trabaco/URI($url/g" < $filebase.pdf > $filebase.rel.pdf
