xref: /dragonfly/usr.bin/unifdef/unifdefall.sh (revision 333227be)
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
9set -e
10
11basename=`basename $0`
12tmp=`mktemp -d -t $basename` || exit 2
13
14unifdef -s "$@" | sort | uniq > $tmp/ctrl
15cpp -dM "$@" | sort |
16	sed -Ee 's/^#define[ 	]+(.*[^	 ])[ 	]*$/\1/' > $tmp/hashdefs
17sed -Ee 's/^([A-Za-z0-9_]+).*$/\1/' $tmp/hashdefs > $tmp/alldef
18comm -23 $tmp/ctrl $tmp/alldef > $tmp/undef
19comm -12 $tmp/ctrl $tmp/alldef > $tmp/def
20
21echo unifdef -k \\ > $tmp/cmd
22sed -Ee 's/^(.*)$/-U\1 \\/' $tmp/undef >> $tmp/cmd
23while read sym
24do	sed -Ee '/^('"$sym"')([(][^)]*[)])?([ 	]+(.*))?$/!d;s//-D\1=\4/' $tmp/hashdefs
25done < $tmp/def |
26	sed -Ee 's/\\/\\\\/g;s/"/\\"/g;s/^/"/;s/$/" \\/' >> $tmp/cmd
27echo '"$@"' >> $tmp/cmd
28sh $tmp/cmd "$@"
29
30rm -r $tmp
31