Path: utzoo!censor!comspec!humvax!becker!ncrcan!attcan!uunet!spool2.mu.edu!think.com!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!dkuug!diku!thorinn From: thorinn@diku.dk (Lars Henrik Mathiesen) Newsgroups: alt.sources.d Subject: Re: wildmat BUG and Fix (was Re: Revised C filename wildcard routine) Message-ID: <1991Jan4.233108.849@odin.diku.dk> Date: 4 Jan 91 23:31:08 GMT References: <3154@litchi.bbn.com> <709@DIALix.oz.au> Sender: news@odin.diku.dk (Netnews System) Organization: Institute of Computer Science, U of Copenhagen Lines: 54 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@DIALix.oz.au (Bernd Felsche) writes: >In <3154@litchi.bbn.com> rsalz@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@diku.dk