warn-ignored-err.sh [plain text]
#!/bin/sh
HELP="\
Usage: $0 [--remove] [FILE...]
Insert or remove the GCC attribute \"warn_unused_result\" on each function
that returns a Subversion error, in the specified files or, by default,
*.h and *.c in the ./subversion and ./tools trees.
"
LC_ALL=C
REMOVE=
case "$1" in
--remove) REMOVE=1; shift;;
--help) echo "$HELP"; exit 0;;
--*) echo "$0: unknown option \"$1\"; try \"--help\""; exit 1;;
esac
if [ $ set -- `find subversion/ tools/ -name '*.[ch]'`
fi
PREFIX="^\( *\| *static *\| *typedef *\)"
RET_TYPE="\(svn_error_t *\* *\)"
IDENT="[a-zA-Z_][a-zA-Z0-9_]*"
DECLR="\($IDENT\|( *\(\*\|\) *$IDENT *)\)"
SUFFIX="\($DECLR *\((.*\|\)\|\)$"
ATTRIB_RE="__attribute__((warn_unused_result))" ATTRIB_STR="__attribute__((warn_unused_result))"
if [ $REMOVE ]; then
SUBST="s/$PREFIX$ATTRIB_RE $RET_TYPE$SUFFIX/\1\2\3/"
else
SUBST="s/$PREFIX$RET_TYPE$SUFFIX/\1$ATTRIB_STR \2\3/"
fi
for F do
{ sed -e "$SUBST" "$F" > "$F~1" &&
{ ! cmp -s "$F" "$F~1"; } &&
mv "$F" "$F~" && mv "$F~1" "$F"
} ||
rm "$F~1"
done