# hdrs.ksh
#!/bin/sh
if [ $# -lt 3 ]
then
echo "usage: $0 modifydir fromdir prefix [oldprefix]"
exit 1
fi
modifydir=$1
shift
fromdir=$1
shift
prefix=$1
if ! expr "$prefix" : '.*/$' >nul:
then
prefix="$prefix/"
fi
shift
if [ "x$1" != x ]
then
oldpre=$1
if ! expr "$oldpre" : '.*/$' >nul:
then
oldpre="$oldpre/"
fi
else
oldpre=""
fi
find $fromdir -name \*.h |\
grep -v replacebackup |\
while read header
do
n=`expr $header : "$fromdir/"'\(.*\)'`
if [ $fromdir == $modifydir ] || ! [ -f $modifydir/$n ]
then
# only do this if the file doesn't exist in the modifydir
echo 's,^([ ]*#include.*[<"])'"$oldpre"'('"$n"'[">]),$1'"$prefix"'$2,i;'
bs=`echo $n | sed 's,/,.,'`
if [ "$bs" != "$n" ]
then
print 's,^([ ]*#include.*[<"])'"$oldpre"'('"$bs"'[">]),$1'"$prefix"'$2,i;'
fi
fi
done >$TMPDIR/perl.$$
find $modifydir -name \*.h |\
grep -v replacebackup |\
while read header
do
perl -p $TMPDIR/perl.$$ <$header >$TMPDIR/hdr.$$
if ! cmp -s $header $TMPDIR/hdr.$$
then
p4 edit $header
mkdir -p `dirname $header`/replacebackup.$$
cp -p $header `dirname $header`/replacebackup.$$/`basename $header`
cp $TMPDIR/hdr.$$ $header
fi
done
rm -f $TMPDIR/perl.$$
rm -f $TMPDIR/hdr.$$