~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/tools/pginclude/pgrminclude

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
:
 
2
# remove extra #include's
 
3
 
 
4
trap "rm -f /tmp/$$.c /tmp/$$.o /tmp/$$ /tmp/$$a /tmp/$$b" 0 1 2 3 15
 
5
find . \( -name CVS -a -prune \) -o -type f -print | 
 
6
grep -v '\./postgres.h' |
 
7
grep -v '\./pg_config.h' |
 
8
grep -v '\./c.h' |
 
9
while read FILE
 
10
do
 
11
        if [ "`echo $FILE | sed -n 's/^.*\.\([^\.]*\)$/\1/p'`" = "h" ]
 
12
        then    IS_INCLUDE="Y"
 
13
        else    IS_INCLUDE="N"
 
14
        fi
 
15
        
 
16
        # remove defines
 
17
        if [ "$IS_INCLUDE" = "Y" ]
 
18
        then    cat "$FILE" | grep -v "^#if" | grep -v "^#else" | 
 
19
                grep -v "^#endif" | sed 's/->[a-zA-Z0-9_\.]*//g' >/tmp/$$a
 
20
        else    cat "$FILE" >/tmp/$$a
 
21
        fi
 
22
 
 
23
        # loop through all includes
 
24
        cat /tmp/$$a | grep "^#include" |
 
25
        sed 's/^#include[       ]*[<"]\([^>"]*\).*$/\1/g' |
 
26
        while read INCLUDE
 
27
        do
 
28
                [ -s /usr/include/$INCLUDE ] && continue
 
29
                [ "$INCLUDE" = postgres.h ] && continue
 
30
                [ "$INCLUDE" = config.h ] && continue
 
31
                [ "$INCLUDE" = c.h ] && continue
 
32
 
 
33
                # preserve configure-specific includes
 
34
                # these includes are surrounded by #ifdef's
 
35
                grep -B1 '^#include[    ][      ]*[<"]'"$INCLUDE"'[>"]' "$FILE" |
 
36
                     egrep -q '^#if|^#else' && continue         
 
37
                grep -A1 '^#include[    ][      ]*[<"]'"$INCLUDE"'[>"]' "$FILE" |
 
38
                     egrep -q '^#else|^#endif' && continue              
 
39
 
 
40
                cat /tmp/$$a |
 
41
                grep -v '^#include[     ]*[<"]'"$INCLUDE"'[>"]' >/tmp/$$b
 
42
                if [ "$IS_INCLUDE" = "Y" ]
 
43
                then    echo "#include \"postgres.h\"" >/tmp/$$.c
 
44
                else    >/tmp/$$.c
 
45
                fi
 
46
                echo "#include \"/tmp/$$b\"" >>/tmp/$$.c
 
47
                echo "void include_test(void);" >>/tmp/$$.c
 
48
                echo "void include_test() {" >>/tmp/$$.c
 
49
                if [ "$IS_INCLUDE" = "Y" ]
 
50
                then    pgdefine "$FILE" >>/tmp/$$.c
 
51
                fi
 
52
                echo "}" >>/tmp/$$.c
 
53
                cc -fsyntax-only -Werror -Wall -Wmissing-prototypes -Wmissing-declarations -I/pg/include -I/pg/backend -c /tmp/$$.c -o /tmp/$$.o >/tmp/$$ 2>&1
 
54
                if [ "$?" -eq 0 ]
 
55
                then    echo "$FILE $INCLUDE"
 
56
                        if [ "$IS_INCLUDE" = "N" ]
 
57
                        then    grep -v '^#include[     ][      ]*[<"]'"$INCLUDE"'[>"]' "$FILE" >/tmp/$$b
 
58
                                mv /tmp/$$b "$FILE"
 
59
                        fi
 
60
                        if [ "$1" = "-v" ]
 
61
                        then    cat /tmp/$$
 
62
                                cat /tmp/$$.c
 
63
                        fi
 
64
                fi
 
65
        done
 
66
done