#!/bin/sh
#
# This script executes a sed-script on the given file.
# It is mainly used as helper script for dosed, but can also be
# used in itself.
#
# It takes care that the date of the file only changes if the file
# contents are changed. In this way make does not rebuild unnecessarily.
#
# Run as:
#    dosed_one <sed-script> <file>


  echo "Execute dosed_one on $2 ..."
  sed -f $1 $2 > $2.new
  diff $2 $2.new >& /dev/null
  # Only rename if different, so date only changes if necessary.
  if [ $? != 0 ]; then
    mv $2.new $2
  else
    \rm -f $2.new
  fi
