4.3BSD/usr/contrib/B/src/bint/Change

: 'Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. '
: '$Header: Change,v 1.1 85/08/22 16:38:36 timo Exp $'

: 'Change error messages in limited number of files'

case $1 in
[0-9]*) start=$1; shift;
	case $1 in
	[0-9]*) step=$1; shift;;
	*) step=100;
	esac;;
*)	start=100; step=100;;
esac

for file
do
	if test -f @$file
	then
		echo @$file already exists, $file skipped
	else
		mv $file @$file || exit
		echo $file $start
		sed 's/pprerr2 *( *\(.*\) *, *\(".*"\));/pprerr2(\1, MESS($, \2));/
			 s/fixerr2 *( *\(.*\) *, *\(".*"\));/fixerr2(\1, MESS($, \2));/
			 s/\(err[a-z]*[23]*\) *( *\(".*"\)/\1(MESS($, \2)/
			 s/MESS([0-9\$]*/MESS($/' @$file |
		awk "BEGIN {messnum=$start}"'
			/MESS\(/ {n=split($0, field, "$");
			 if (n==2) {print field[1] messnum field[2]; ++messnum}
			 else print
			}
			!/MESS\(/ {print}' >$file
		if test -s $file
		then
			if cmp -s @$file $file
			then
				mv @$file $file
				echo $file unchanged
			else
				start=`expr $start + $step`
			fi
		else
			mv @$file $file
			echo $file clobbered, old version put back
		fi
	fi
done