2.11BSD/src/usr.sbin/sendmail/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 | \
sed -e 's/ferror(/ferror_(/'				\
    -e 's/smtpmessage(/smtpmessage_(/'	\
    -e 's/sprintf(\([^,][^,]*\),[ ]*\("[^"]*"\)\([,)]\)/strsrerror(\2, \1\3/' \
    -e 's/fprintf(\([^,][^,]*\),[ ]*\("[^"]*"\)\([,)]\)/strfrerror(\2, \1\3/' \
    -e 's/printf("/strprerror("/'				\
    -e 's/putline("/strputlinerror("/'				\
    -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/' \
    -e 's/^# \([0-9]\)/#line \1/' > mk.c
mkstr - $STRINGS xx mk.c
echo Doing shared strings...
cc -E -Dferror=ferror_ -Dsmtpmessage=smtpmessage_ $args xxmk.c | xstr -c -
echo Compiling...
cc $args -c x.c
mv x.o `basename $csrc .c`.o
rm -f x.c mk.c xxmk.c