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