#!/bin/sh -
#
# $Id: chk.flags,v 1.12 2004/10/19 02:28:19 bostic Exp $
#
# Check flag name-spaces.

d=../..
t1=__1
t2=__2

if cc -g -Wall -I.. t.c -o t; then
	:
else
	echo "FAIL: unable to compile test program t.c"
	exit 1
fi

if ./t $d/*/*.[ch] $d/*/*.in > $t1; then
	:
else
	echo "FAIL: test program failed"
	exit 1
fi

echo Checking DB_ENV flags...
cat $t1 |
grep '(dbenv,' |
sed -e '/DB_ENV_/d' \
    -e '/env_method.c.*, mapped_flags*)/d' \
    -e '/env_region.c.*, db_env_reset)/d' \
    > $t2
[ -s $t2 ] && {
	cat $t2
	exit 1
}

grep 'DB_ENV_' $t1 |
sed -e '/((*dbenv)*,/d' \
    -e '/((*dbp)*->dbenv,/d' \
    -e '/((*infop)*->dbenv,/d' \
    -e '/((*reginfop)*->dbenv,/d' \
    -e '/((*sdbp)*->dbenv,/d' \
    > $t2
[ -s $t2 ] && {
	cat $t2
	exit 1
}

echo Checking DB flags...
cp $t1 /tmp/_f
cat $t1 |
grep '(dbp,' |
sed -e '/DB_AM_/d' \
    -e '/dbp, mapped_flag)/d' \
    > $t2
[ -s $t2 ] && {
	cat $t2
	exit 1
}

grep 'DB_AM_' $t1 |
sed -e '/((*[	 ]*db_rep->rep_db)*,/d' \
    -e '/((*[	 ]*dbc)*->dbp,/d' \
    -e '/((*[	 ]*dbc_arg->dbp)*,/d' \
    -e '/((*[	 ]*dbp)*,/d' \
    -e '/((*[	 ]*dbp)*->s_primary,/d' \
    -e '/((D),/d' \
    -e '/(mdbp,/d' \
    -e '/(pdbp,/d' \
    -e '/(pginfo, /d' \
    -e '/(sdbp,/d' \
    -e '/(subdbp,/d' \
    -e '/fop_util.c:.*(t2dbp,/d' \
    -e '/rep_backup.c.*(rfp,/d' \
    > $t2
[ -s $t2 ] && {
	cat $t2
	exit 1
}

echo Checking DBC flags...
cat $t1 |
grep '(dbc,' |
sed -e '/DBC_/d' \
    > $t2
[ -s $t2 ] && {
	cat $t2
	exit 1
}

grep 'DBC_' $t1 |
sed -e '/((*dbc)*,/d' \
    -e '/(dbc_arg,/d' \
    -e '/(dbc_c,/d' \
    -e '/(dbc_n,/d' \
    -e '/(dbc_orig,/d' \
    -e '/(opd,/d' \
    -e '/(pdbc,/d' \
    -e '/(sdbc,/d' \
    > $t2
[ -s $t2 ] && {
	cat $t2
	exit 1
}

echo Checking for bad use of macros...
egrep 'case .*F_SET\(|case .*F_CLR\(' $d/*/*.c > $t1
egrep 'for .*F_SET\(|for .*F_CLR\(' $d/*/*.c >> $t1
egrep 'if .*F_SET\(|if .*F_CLR\(' $d/*/*.c >> $t1
egrep 'switch .*F_SET\(|switch .*F_CLR\(' $d/*/*.c >> $t1
egrep 'while .*F_SET\(|while .*F_CLR\(' $d/*/*.c >> $t1
[ -s $t1 ] && {
	echo 'if statement followed by non-test macro'
	cat $t1
	exit 1
}

exit 0
