[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#240887: Package building problem.



On Fri, Apr 16, 2004 at 12:54:03PM +1000, Herbert Xu wrote:
> 
> On Fri, Apr 16, 2004 at 08:09:05AM +1000, herbert wrote:
> > 
> > On Thu, Apr 15, 2004 at 03:10:58PM +0100, Colin Watson wrote:
> >
> > > Accordingly, I believe that the pattern in your example means
> > > "backslash, followed by a, followed by closing square bracket", not what
> > > you think it means.
> > 
> > You're quite right.  This is reaffirmed by the POSIX document for
> > basic regular expressions, which is what POSIX uses to define
> > shell patterns.

For fnmatch it says:

     The fnmatch() function shall match patterns as described in the
     Shell and Utilities volume of IEEE Std 1003.1-2001, Section 2.13.1,
     Patterns Matching a Single Character, and Section 2.13.2, Patterns
     Matching Multiple Characters.

Which says:

   The pattern matching notation described in this section is used to
   specify patterns for matching strings in the shell.  Historically,
   pattern matching notation is related to, but slightly different from,
   the regular expression notation described in the Base Definitions
   volume of IEEE Std 1003.1-2001, Chapter 9, Regular Expressions. For
   this reason, the description of the rules for this pattern matching
   notation are based on the description of regular expression notation,
   modified to include backslash escape processing.

[...]
   A backslash character shall escape the following character.
   The escaping backslash shall be discarded.

[...]
   The description of basic regular expression bracket expressions in the
   Base Definitions volume of IEEE Std 1003.1-2001, Section 9.3.5, RE
   Bracket Expression shall also apply to the pattern bracket expression

That says:

The
       right-bracket ( ']' ) shall lose its special meaning and represent
       itself in a bracket expression if it occurs first in the list
       (after an initial circumflex ( '^' ), if any).
[...]
       The special characters '.' , '*' , '[' , and '\' (period, asterisk,
       left-bracket, and backslash, respectively) shall lose their
       special meaning within a bracket expression.


After reading all that you have to get confused about what "[\[\]\\]" means.
At the "highest level" it says that the '\' should be discarded,
so you end up with "[[]\]" and look at that as a normal regular
expression?  Atleast that is how I interpret things.

But testing this shows that this program:
#include <fnmatch.h>
int main()
{
        printf("%d\n", fnmatch("[\\]a]", "a", 0));
        printf("%d\n", fnmatch("[\\]a]", "\\", 0));
        printf("%d\n", fnmatch("[\\]a]", "]", 0));
        printf("%d\n", fnmatch("[]a]", "a", 0));
        printf("%d\n", fnmatch("[]a]", "]", 0));
        return 0;
}
returns:
1
1
0
0
0

This does _not_ make sense to me in any way.  If the 3rd line says
there is a match, I would think it's interpreting it as "[]a]",
but then the first line should match too.

Ps: On other platforms I get:
0
1
0
0
0

One returned:
1
1
1
0
0


Which atleast make a little more sense.


Kurt



Reply to: