2.11BSD/src/usr.sbin/sendmail.MX/src/mkstrcc

#! /bin/sh
# Special cc preprocessor for using mkstr(1) to extract strings from the
# sendmail source.
STRINGS=sendmail.sr

# Get filename and arguments.
initargs=$@
while [ -n "$1" ]
do
	if [ $1 = -o ]
	then
		exec cc $initargs
		exit 1
	fi
	if [ `expr substr $1 1 1` = - ]
	then
		if [ $1 != -c ]
		then
			args="$args $1"
		fi
	else
		csrc=$1
	fi
	shift
done

# Only process compilations, and then only for certain files.
if [ $csrc = err.c -o $csrc = extract.c ]
then
	exec cc $initargs
	exit 1
fi

# String extractions
echo Extracting strings from ${csrc}...
cc -E $args $csrc > xxmk.c
sed -e 's/ferror(/strferrorf(/'				\
    -e 's/sprintf(\([^,][^,]*\),[ ]*\("[^"]*"\)\([,)]\)/strsrerror(\2, \1\3/' \
    -e 's/fprintf(\([^,][^,]*\),[ ]*\("[^"]*"\)\([,)]\)/strfrerror(\2, \1\3/' \
    -e 's/printf("/strprerror("/'				\
    -e 's/syslog(\([^,][^,]*\),[ ]*\("[^"]*"\)\([,)]\)/slogerror(\2, \1\3/' \
    -e 's/syserr(\(".*"\)\([,)]\)/syserror(\1\2/'		\
    -e 's/usrerr(\(".*"\)\([,)]\)/usrerror(\1\2/'		\
    -e 's/nmessage(\([^,][^,]*\),[ ]*\("[^"]*"\)\([,)]\)/nmesserror(\2, \1\3/' \
    -e 's/message(\([^,][^,]*\),[ ]*\("[^"]*"\)\([,)]\)/messerror(\2, \1\3/' \
	xxmk.c > mk.c
mkstr - $STRINGS xx mk.c
sed -e 's/^# \([0-9]\)/#line \1/' xxmk.c > mk.c
echo Compiling...
cc -Dstrferrorf=ferror -Dstrprnf=fprintf -Dstrsprnf=sprintf \
	-Dstrnmessagef=nmessage $args mk.c
mv mk.s `basename $csrc .c`.s
rm -f mk.c xxmk.c