[net.sources] = vs ==

nelson@ecsvax.UUCP (jim nelson) (09/30/86)

# !/bin/sh
# Looks for "=" in the () of a while() or if().
# Also looks for while() or if() followed by any number
# of blanks then a semi-colon.
# NOTE: for uucp purposes I have changed all occurrences of
# true tab chars to the 3-character sequence TAB
# use your editor to replace TAB by a real tab-char.
# jhn 10 june 86
# jim nelson, uncw, cs dept, wilmington nc 28405 919-395-3300
# Runs on AT&T 3b2/300 SysVr2v2
# BSD'ers probably can extend the egrepping to speed it up.
# NOTE: is fooled by parenthesized expressions.
# NOTE: jhn is by no means a [ef]*grep expert.  Comments and
# corrections (even flames, i've got tenure) 
# welcome.  just trying to learn. ...
case $# in
TAB0) echo "usage: finddumb filename.c
TABFinds possibly erroneous confusion between \"=\" and \"==\", and looks
TABfor  \"while(...) ;\"   (also if) statements.
TABHelp is best gotten by listing /usr/uncw/finddumb itself."
TABexit 1;;
esac
# find (if or while) followed by zero or more (blank or tab)
# followed by left-paren
# followed by either ( an = sign not preceded by !<>= or
#                      an = sign preceded by << preceded by at least one char or
#                      an = sign preceded by >> preceded by at least one char  )
# followed by something that's not an = sign
# followed by zero or more anythings
# followed by a right-paren.
echo ""
if egrep '(if|while)[ TAB]*\(([^=!<>]*|.+>>|.+<<)=[^=].*\)' $*
then
echo "*****  assignment statement in if(...) or while(...) *****"
fi
# Why make two passes? Because trying to combine the two causes egrep
# to abort with "regular expression too long" error message.
#
# It does return a bunch of false alarms, but it will at least catch
# all the real ones.  Bayesian decision to suffer high risk of
# false positive in return for low risk of false negative.
# Also: a do...while(); statement is perfectly correct, but will
#  of course be flagged by this dumb program.
echo ""
if egrep 'while[ TAB]*\(.*\)[ TAB]*;' $*
then
echo "*****  null body of while-loop *****"
fi
echo ""
if egrep 'if[ TAB]*\(.*\)[ TAB]*;' $*
then
echo "*****  null stmt following if *****"
fi
-- 
Jim Nelson, Univ.NC at Wilmington/CS Dept.  (919) 395-3300 
Wilmington NC 28403 
UUCP: ...{decvax,seismo,philabs,ihnp4,akgua}!mcnc!ecsvax!nelson