#! /bin/bash
# Last edited on 2009-10-08 16:22:24 by stolfi

# Applies a 'sed' script to a set of files
usage="sed-files [-h] -f <script file> <file>..."

diffopt=( )
if [[ "/$1" == "/-h" ]]; then
  diffopt=( "$1" )
  shift
fi

if [[ ( $# -ge 2 ) && ( "/$1" == '/-f') ]]; then
  script="$2"; shift; shift
else
  echo "Usage: ${usage}" 1>&2
  exit 1
fi

if [[ ! ( -s "${script}" ) ]]; then
  echo "${script} is unreadable or empty" 1>&2
  exit 1
fi
if [[ ! ( -f "${script}" ) ]]; then
  echo "${script} is not a file" 1>&2
  exit 1
fi

echo "script = [${script}]" 1>&2

${STOLFIHOME}/bin/filter-files ${diffopt} "sed -f ${script}" "$@"
