summaryrefslogtreecommitdiff
path: root/usr.bin/unifdef/unifdefall.sh
diff options
context:
space:
mode:
authorKiyoshi Aman <kiyoshi.aman+adelie@gmail.com>2019-02-01 22:55:37 +0000
committerKiyoshi Aman <kiyoshi.aman+adelie@gmail.com>2019-02-03 18:22:05 -0600
commit5b57d28ffb6e1ef86b50f7d05d977826eae89bfe (patch)
tree154a22fe556b49e6927197336f8bf91b12eacd5e /usr.bin/unifdef/unifdefall.sh
downloaduserland-5b57d28ffb6e1ef86b50f7d05d977826eae89bfe.tar.gz
userland-5b57d28ffb6e1ef86b50f7d05d977826eae89bfe.tar.bz2
userland-5b57d28ffb6e1ef86b50f7d05d977826eae89bfe.tar.xz
userland-5b57d28ffb6e1ef86b50f7d05d977826eae89bfe.zip
initial population
Diffstat (limited to 'usr.bin/unifdef/unifdefall.sh')
-rw-r--r--usr.bin/unifdef/unifdefall.sh29
1 files changed, 29 insertions, 0 deletions
diff --git a/usr.bin/unifdef/unifdefall.sh b/usr.bin/unifdef/unifdefall.sh
new file mode 100644
index 0000000..7c1d643
--- /dev/null
+++ b/usr.bin/unifdef/unifdefall.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+#
+# remove all the #if's from a source file
+#
+# $dotat: things/unifdefall.sh,v 1.10 2002/09/24 19:52:11 fanf2 Exp $
+# $FreeBSD: src/usr.bin/unifdef/unifdefall.sh,v 1.2 2002/09/24 19:50:03 fanf Exp $
+
+set -e
+
+basename=`basename $0`
+tmp=`mktemp -d -t $basename` || exit 2
+
+unifdef -s "$@" | sort | uniq > $tmp/ctrl
+cpp -dM "$@" | sort |
+ sed -Ee 's/^#define[ ]+(.*[^ ])[ ]*$/\1/' > $tmp/hashdefs
+sed -Ee 's/^([A-Za-z0-9_]+).*$/\1/' $tmp/hashdefs > $tmp/alldef
+comm -23 $tmp/ctrl $tmp/alldef > $tmp/undef
+comm -12 $tmp/ctrl $tmp/alldef > $tmp/def
+
+echo unifdef -k \\ > $tmp/cmd
+sed -Ee 's/^(.*)$/-U\1 \\/' $tmp/undef >> $tmp/cmd
+while read sym
+do sed -Ee '/^('"$sym"')([(][^)]*[)])?([ ]+(.*))?$/!d;s//-D\1=\4/' $tmp/hashdefs
+done < $tmp/def |
+ sed -Ee 's/\\/\\\\/g;s/"/\\"/g;s/^/"/;s/$/" \\/' >> $tmp/cmd
+echo '"$@"' >> $tmp/cmd
+sh $tmp/cmd "$@"
+
+rm -r $tmp