#!/bin/sh
# fixrtf
# Repair (slightly) damaged RTF generated by jade
# Applixware wants the s0 stylesheet defined, whereas
#  M$Word does not care about it.
# (c) 2001, Thomas Lockhart, PostgreSQL Inc.

flist=""
RPAT=""
for i in $@ ; do
  case "$i" in
    -r|--refentry)
      RPAT='-e s/\\\keepn/\\\keep/g'
      ;;
    -?|--help)
      echo "$0 [--refentry] <rtf file> ..."
      exit 0
      ;;
    -*)
      echo "Command $i not recognized"
      $0 --help
      exit 1
      ;;
    *)
      flist="$flist $i"
  esac
done

if [ "$flist" = "" ] ; then
  flist=*.rtf
fi

for f in $flist ; do
  echo -n "Repairing '$f' ..."
  if [ -r $f ] ; then
    (sed -e 's/{\\stylesheet{\\s1/{\\stylesheet{\\s0 Normal 0;}{\\s1/g' $RPAT $f > $f.new \
      && mv -f $f.new $f \
      && echo " done") || echo " failed"
  else
    echo " file not found"
  fi
done
exit
