Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / usr.bin / unifdef / unifdefall.sh
1 #!/bin/sh
2 #
3 # remove all the #if's from a source file
4 #
5 #       $dotat: things/unifdefall.sh,v 1.9 2002/09/24 19:43:57 fanf2 Exp $
6 # $FreeBSD: src/usr.bin/unifdef/unifdefall.sh,v 1.1.2.2 2002/10/20 13:44:11 fanf Exp $
7 # $DragonFly: src/usr.bin/unifdef/unifdefall.sh,v 1.2 2003/06/17 04:29:33 dillon Exp $
8
9 set -e
10
11 basename=`basename $0`
12 tmp=`mktemp -d -t $basename` || exit 2
13
14 unifdef -s "$@" | sort | uniq > $tmp/ctrl
15 cpp -dM "$@" | sort |
16         sed -Ee 's/^#define[    ]+(.*[^  ])[    ]*$/\1/' > $tmp/hashdefs
17 sed -Ee 's/^([A-Za-z0-9_]+).*$/\1/' $tmp/hashdefs > $tmp/alldef
18 comm -23 $tmp/ctrl $tmp/alldef > $tmp/undef
19 comm -12 $tmp/ctrl $tmp/alldef > $tmp/def
20
21 echo unifdef -k \\ > $tmp/cmd
22 sed -Ee 's/^(.*)$/-U\1 \\/' $tmp/undef >> $tmp/cmd
23 while read sym
24 do      sed -Ee '/^('"$sym"')([(][^)]*[)])?([   ]+(.*))?$/!d;s//-D\1=\4/' $tmp/hashdefs
25 done < $tmp/def |
26         sed -Ee 's/\\/\\\\/g;s/"/\\"/g;s/^/"/;s/$/" \\/' >> $tmp/cmd
27 echo '"$@"' >> $tmp/cmd
28 sh $tmp/cmd "$@"
29
30 rm -r $tmp