1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#!/bin/sh
# This thing may be better off incorporated in Makefile.am.
# FIXME: sed implementation dependency
#
# This script does not work on some sed implementations, at least BSD sed.
# So GNU sed is explicitly used as temporary solution.
#
# $ ./collect.sh test-storage.c
# line 1 "test-storage.c"
# sed: 25: "259 { p; s/^.*$/vector/ ...": unexpected EOF (pending }'s)
#
# man sed on *BSD:
# > The ``{'' can be preceded by white space and can be followed by white
# > space. The function can be preceded by white space. The terminating
# > ``}'' must be preceded by a newline or optional white space.
[ "x$2" = "x" ] || { echo >&2 "usage: collect.sh <c source>"; exit 1; }
echo "#line 1 \"$1\""
decls=`grep -n '^TST_CASE[[:space:]]*(' "$1" | \
sed 's/^\([0-9]*:\)TST_CASE[[:space:]]*(/\1/'`
have_id=`echo "$decls" | sed -n '
/^\([0-9]*\):\([_[:alnum:]]*\),.*$/ {
s||\1 { p; s/^.*$/\2/; H; b skip_print; };|
p
}
'`
need_id=`echo "$decls" | \
grep -n '^[0-9]*:[[:space:]]*"' | \
sed \
's|^\([0-9]*\):\([0-9]*\):.*$|\2 { s/(/(tst_\1, /; p; s/^.*$/tst_\1/; H; b skip_print; };|'`
@SED@ -n "$have_id""$need_id;p;"'
: skip_print
$ { g
s/\n\([[:alnum:]_]*\)/\n TST_REGISTER(\1)/g
s/^/TST_LIST_BEGIN()/
p
i\
TST_LIST_END()
}
' "$1"
|