1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
#!/bin/sh
# short-term editing tasks for PCP
#
sts=1
tmp=/var/tmp/$$
trap "rm -f $tmp.tmp; exit \$sts" 0 1 2 3 15
_usage()
{
echo "Usage: hack [-p pattern] [-v] [file ...]"
exit
}
pattern=""
verbose=false
while getopts "p:v?" c
do
case $c
in
p)
pattern="$OPTARG"
;;
v)
verbose=true
;;
?)
_usage
;;
esac
done
shift `expr $OPTIND - 1`
[ $# -eq 0 ] && set -- *.c *.cxx *.h *.y *.l *.in
for file
do
case $file
in
'*'.*)
;;
qa/[0-9][0-9][0-9][0-9]*|qa/[0-9][0-9][0-9]*)
;;
*)
if [ ! -f "$file" ]
then
echo "Warning: $file: file not found"
exit
fi
if [ -z "$pattern" ]
then
do_me=true
else
do_me=false
grep "$pattern" $file >/dev/null && do_me=true
fi
if $do_me
then
if grep '^#include .*libpcp.h' $file >/dev/null
then
$verbose && echo "$file: libpcp.h already in place"
else
if grep '^#include .*impl.h' $file >/dev/null
then
sed <$file >$tmp.tmp \
-e '/^#include .*impl.h/{
p
s/impl.h/libpcp.h/
}'
if diff $file $tmp.tmp >/dev/null
then
$verbose && echo "Botch: $file: failed to add libpcp.h after impl.h"
else
echo "$file: add libpcp.h after impl.h"
mv $tmp.tmp $file
fi
elif grep '^#include .*pmapi.h' $file >/dev/null
then
sed <$file >$tmp.tmp \
-e '/^#include .*pmapi.h/{
p
s/pmapi.h/impl.h/
p
s/impl.h/libpcp.h/
}'
if diff $file $tmp.tmp >/dev/null
then
$verbose && echo "Botch: $file: failed to add libpcp.h after pmapi.h"
else
echo "$file: add impl.h and libpcp.h after pmapi.h"
mv $tmp.tmp $file
fi
else
echo "Warning: $file: no place to add libpcp.h"
exit
fi
fi
else
$verbose && echo "$file: skipped (no match for $pattern)"
fi
;;
esac
case $file
in
qa/src/*.c|qa/qt/*/*.cpp)
sed <$file >$tmp.tmp \
-e '/include <pcp\/libpcp.h>/{
s/<pcp\//"/
s/>/"/
}'
if diff $file $tmp.tmp >/dev/null
then
:
else
echo "$file: QA special fix for libpcp.h"
mv $tmp.tmp $file
fi
;;
esac
done
sts=0
|