summaryrefslogtreecommitdiffstats
path: root/usr.bin/unifdef/unifdefall.sh
diff options
context:
space:
mode:
authorfanf <fanf@FreeBSD.org>2002-05-15 16:30:28 +0000
committerfanf <fanf@FreeBSD.org>2002-05-15 16:30:28 +0000
commit94a883658e1000832629fafcd2412eb9fa74e48f (patch)
tree223cd7d3676754661a0b6d33c272d00175913620 /usr.bin/unifdef/unifdefall.sh
parentb860787a1895c30ea1f8f8c93c0b4578de259cf3 (diff)
downloadFreeBSD-src-94a883658e1000832629fafcd2412eb9fa74e48f.zip
FreeBSD-src-94a883658e1000832629fafcd2412eb9fa74e48f.tar.gz
Upgrade unifdef:
* It now knows about the existence of #elif which would have caused it to produce incorrect results in some situations. * It can now process #if and #elif lines according to the values of symbols that are specified on the command line. The expression parser is only a simple subset of what C allows but it should be sufficient for most real-world code (it can cope with everything it finds in xterm). * It has an option for printing all of the symbols that might control #if processing. The unifdefall script uses this option along with cpp -dM to strip all #ifs from a file. * It has much larger static limits. * It handles nested #ifs much more completely. There have also been many style improvements: KNF; ANSI function definitions; all global stuff moved to the top of the file; use stdbool instead of h0h0bool; const-correctness; err(3) instead of fprintf(stderr, ...); enum instead of #define; commentary. I used NetBSD's unifdef as the basis of this since it has received the most attention over the years. PR: 37454 Reviewed by: markm, dwmalone Approved by: dwmalone (mentor) MFC after: 3 weeks
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..5625eb9
--- /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.8 2002/05/15 10:31:20 fanf Exp $
+# $FreeBSD$
+
+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 \\ > $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
OpenPOWER on IntegriCloud