wildmat BUG and Fix (was Re: Revised C filename wildcard routine)

Bernd Felsche bernie at DIALix.oz.au
Sat Jan 5 01:06:44 AEST 1991


In <3154 at litchi.bbn.com> rsalz at bbn.com (Rich Salz) writes:

>This is a revised version of my pattern-matching routine.  It has been
>posted to the net several times, and shows up in several places including
>Gilmore's public domain TAR.  You might want to test this, but I did
>and it seems solid.

It's neat, and arrived at our site on the very day it was needed.  :-)

It's not quite solid enough, though.  It won't match string "ab" 
to pattern "ab*" A trailing "*" never matches a trailing (null) string.

The BUG is:

[... start of shar deleted ...]
>Xstatic int
>XDoMatch(s, p)
>X    register char	*s;
>X    register char	*p;
>X{
>X    register int 	 last;
>X    register int 	 matched;
>X    register int 	 reverse;
>X
>X    for ( ; *p; s++, p++) {
>X	if (*s == '\0')
>X	    return ABORT;
[ ... rest of shar deleted ... ]

The FIX:
	return ABORT;
becomes:
	return *p == '*' && *++p == '\0' ? TRUE : ABORT;

This is not the way I usually write code, but it blends in with
the style of the rest of the code. :-) You probably won't be able to
tell that it's a patch.

What the package really needs, is a syntax parser (to check for
closing ], and for ][ inside character ranges) and a compressor
(for things like "**").  This would stop it rampaging through memory
until it hits an MMU boundary.

How does this code compare with "bash"?  Anybody familiar enough
with bash to excise the filename expansion stuff from that?
-- 
 ________Bernd_Felsche__________bernie at DIALix.oz.au_____________
[ Phone: +61 9 419 2297		19 Coleman Road			]
[ TZ:	 UTC-8			Calista, Western Australia 6167	]



More information about the Alt.sources.d mailing list