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

Lars Henrik Mathiesen thorinn at diku.dk
Sat Jan 5 10:31:08 AEST 1991


First off: Does anybody have a set of test data for shell globbing? It
would be nice to have a positive check on the updated wildmat.c .

bernie at DIALix.oz.au (Bernd Felsche) writes:
>In <3154 at litchi.bbn.com> rsalz at bbn.com (Rich Salz) writes:
>>This is a revised version of my pattern-matching routine.

>It won't match string "ab" 
>to pattern "ab*" A trailing "*" never matches a trailing (null) string.

>The BUG is:

>>X	if (*s == '\0')
>>X	    return ABORT;

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

I'd prefer this FIX:
    if (*s == '\0')
becomes:
    if (*s == '\0' && *p != '*')

It is more general; the first fix will fail to match two trailing "*"s
with a trailing null string.

>What the package really needs, is a syntax parser (to check for
>closing ], and for ][ inside character ranges)

That would be nice. To be more precise, it should check for '\0' and
']' after '-' in ranges, check for '\0' after '\\' outside them, and
either allow ']' as first character in a range (old way) or recognize
'\\' inside ranges (more code, but easier to use).

>						and a compressor
>(for things like "**").

That is one effect of the ABORT stuff: Effectively, only the last of
two "*"s cause a loop. (However, it didn't quite make it into rsalz'
posting, only the bug part :-( See my post in alt.sources.)

>How does this code compare with "bash"?  Anybody familiar enough
>with bash to excise the filename expansion stuff from that?

I just looked at it. It has two routines, much like DoMatch and Star;
it does most of the checks I listed above, and it compresses
consecutive '*'s and '?'s. But it doesn't have anything like ABORT, so
the example shown in wildmat.c will still be very bad for it.

--
Lars Mathiesen, DIKU, U of Copenhagen, Denmark      [uunet!]mcsun!diku!thorinn
Institute of Datalogy -- we're scientists, not engineers.      thorinn at diku.dk



More information about the Alt.sources.d mailing list