1 1.1 itojun #!/bin/sh 2 1.1 itojun # 3 1.1 itojun # remove all the #if's from a source file 4 1.1 itojun # 5 1.1 itojun # $dotat: things/unifdefall.sh,v 1.10 2002/09/24 19:52:11 fanf2 Exp $ 6 1.1 itojun # $FreeBSD: src/usr.bin/unifdef/unifdefall.sh,v 1.2 2002/09/24 19:50:03 fanf Exp $ 7 1.1 itojun 8 1.1 itojun set -e 9 1.1 itojun 10 1.1 itojun basename=`basename $0` 11 1.1 itojun tmp=`mktemp -d -t $basename` || exit 2 12 1.1 itojun 13 1.1 itojun unifdef -s "$@" | sort | uniq > $tmp/ctrl 14 1.1 itojun cpp -dM "$@" | sort | 15 1.1 itojun sed -Ee 's/^#define[ ]+(.*[^ ])[ ]*$/\1/' > $tmp/hashdefs 16 1.1 itojun sed -Ee 's/^([A-Za-z0-9_]+).*$/\1/' $tmp/hashdefs > $tmp/alldef 17 1.1 itojun comm -23 $tmp/ctrl $tmp/alldef > $tmp/undef 18 1.1 itojun comm -12 $tmp/ctrl $tmp/alldef > $tmp/def 19 1.1 itojun 20 1.1 itojun echo unifdef -k \\ > $tmp/cmd 21 1.1 itojun sed -Ee 's/^(.*)$/-U\1 \\/' $tmp/undef >> $tmp/cmd 22 1.1 itojun while read sym 23 1.1 itojun do sed -Ee '/^('"$sym"')([(][^)]*[)])?([ ]+(.*))?$/!d;s//-D\1=\4/' $tmp/hashdefs 24 1.1 itojun done < $tmp/def | 25 1.1 itojun sed -Ee 's/\\/\\\\/g;s/"/\\"/g;s/^/"/;s/$/" \\/' >> $tmp/cmd 26 1.1 itojun echo '"$@"' >> $tmp/cmd 27 1.1 itojun sh $tmp/cmd "$@" 28 1.1 itojun 29 1.1 itojun rm -r $tmp 30