dbsql/test/scr021/chk.flags
Gregory Burd c39ba47f61 Finished a pass over all the non-SQLite derrived tests (which all
live in scr050) and brought them up to date, some minor fixes along
the way.  A few tests don't work properly, I've noted those in the
TODO file for some other time.
2009-09-01 19:21:41 -04:00

191 lines
3.1 KiB
Bash

#!/bin/sh -
#
# Check flag name-spaces.
d=../..
t1=__1
t2=__2
trap 'rm -f $t1 $t2 t' 0 1 2 3 13 15
cat << END_OF_CODE > t.c
#include <sys/types.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void
chk(f, str)
char *f, *str;
{
char *s;
int ch, l, ok, pc;
if (freopen(f, "r", stdin) == NULL) {
fprintf(stderr, "%s: %s\n", f, strerror(errno));
exit (1);
}
for (l = 1, ok = 1, s = str; (ch = getchar()) != EOF;) {
if (ch == '\n')
++l;
if (!ok || ch != *s) {
s = str;
ok = !isalpha(ch) && !isdigit(ch) && ch != '_';
continue;
}
if (*++s != '\0')
continue;
/* Match. */
printf("%s: %d: %s", f, l, str);
for (pc = 1; (ch = getchar()) != EOF;) {
switch (ch) {
case '(':
++pc;
break;
case ')':
--pc;
break;
case '\n':
++l;
break;
}
if (ch == '\n')
putchar(' ');
else
putchar(ch);
if (pc <= 0) {
putchar('\n');
break;
}
}
s = str;
}
}
int
main(int argc, char *argv[])
{
int r;
for (r = 0; *++argv != NULL;) {
chk(*argv, "F_ISSET(");
chk(*argv, "F_CLR(");
chk(*argv, "F_SET(");
}
return (0);
}
END_OF_CODE
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/src/*/*.[ch] $d/src/*/*.in > $t1; then
:
else
echo "FAIL: test program failed"
exit 1
fi
echo Checking DBSQL_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