~ubuntu-branches/ubuntu/feisty/unifdef/feisty

« back to all changes in this revision

Viewing changes to src/unifdefall.sh

  • Committer: Bazaar Package Importer
  • Author(s): Bob Proulx
  • Date: 2004-07-03 18:09:39 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040703180939-f7bj8405sqvixczk
Tags: upstream-1.0+20030701
ImportĀ upstreamĀ versionĀ 1.0+20030701

Show diffs side-by-side

added added

removed removed

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