#!/bin/sh
# The SPIMS software is covered by a license. The use of the software
# represents acceptance of the terms and conditions in the license.
# ******************************************************************
# Copyright (c) 1989, Swedish Institute of Computer Science
# Args: Sed-strings File-name

if test "$#" != "2" -o -z "$1" ; then
	if test "$#" != "2" ; then
		echo "Wrong number of args: $*"
	else
		echo Empty substitution string
	fi
	exit 1
fi

# This meens executable shell scripts have to be modified by hand
if test -x "$2" -o "$2" = "./modrecur_temp.tmp" ; then
	echo "Skipping executable file $2"
	exit 0
fi

# $1 SHOULD expand to (perhaps) several arguments to sed
if sed $1 "$2" > modrecur_temp.tmp ; then
	if cmp -s "$2" modrecur_temp.tmp ; then
		echo "$2 didn't change, not overwriting"
		rm -f modrecur_temp.tmp
	else
		mv -f modrecur_temp.tmp "$2"
	fi
else
	echo "Sed failed for file $2"
	rm -f modrecur_temp.tmp
fi
