Re: [checks/scripts] [PATCH 3/4] shell script wrapper detection
On Sat, 2008-06-14 at 05:08 +0200, Frank Lichtenheld wrote:
> On Fri, Jun 13, 2008 at 03:09:00PM +0100, Adam D. Barratt wrote:
> > + last if (++$i > 55);
> > + if (/(^\s*|\beval\s*[\'\"]|(;|&&)\s*)exec\s*.+\s*.?\$$var.?\s*(--\s*)?.?(\${1:?\+.?)?(\$(\@|\*))?/) {
>
> I guess that regex could really use a little /x treatment.
It's certainly not the nicest expression; it's grown somewhat over time.
My first attempt at splitting it up results in:
if (m~
# the exec should either be "eval"ed or a new statement
(^\s*|\beval\s*[\'\"]|(;|&&)\s*)
# eat anything between the exec and $0
exec\s*.+\s*
# optionally quoted executable name (via $0)
.?\$$var.?\s*
# optional "end of options" indicator
(--\s*)?
# Match expressions of the form '${1+$@}', '${1:+"$@"',
# '"${1+$@', "$@", etc where the quotes (before the dollar
# sign(s)) are optional and the second (or only if the $1
# clause is omitted) parameter may be $@ or $*.
#
# Finally the whole subexpression may be omitted for scripts
# which do not pass on their parameters (i.e. after re-execing
# they take their parameters (and potentially data) from stdin
.?(\${1:?\+.?)?(\$(\@|\*))?~x) {
which is (at least imho) a significant improvement on the original.
Suggestions for better wording welcome. :)
Adam
Reply to: