gpattern questions



Last night I wrote api documentation for gpattern. Since I deduced the
semantics of the functions be reading their source, I would be grateful
if the authors of that code would doublecheck my findings. (I know already
that I probably have to give a few more details about the differences to
glob(7),
for instance mention that '*' and '?' _can_ match path separators with
g_pattern_match unlike glob).

Here are the questions which came up while I wrote the documentation:

Shouldn't GPatternSpec be an opaque structure ? The fields are really
useless
to anybody except the pattern matcher itself. And once GPatternSpec is
opaque there is no reason to have GMatchType in the header at all, since it
is only used for communication between the 'pattern compiler' and the
'pattern matcher'. Would a patch to do this be accepted ?

There is one piece of code in the pattern matcher which I don't understand:
If you look at
the snipplet below,  t and h are pointing into different strings, therefore
the comparsions t < h
in line 171 and 178 are rather meaningless. Just guessing: maybe the intent
was to compare
(t - p_spec->pattern_reversed) < (h - pattern) ?



161             pspec->pattern_reversed = g_new (gchar,
pspec->pattern_length + 1);
162             t = pspec->pattern_reversed + pspec->pattern_length;
163             *(t--) = 0;
164             h = pattern;
165             while (t >= pspec->pattern_reversed)
166               {
167                 register gchar c = *(h++);
168
169                 if (c == '*')
170           	{
171           	  if (t < h)
172                               hw++;
173           	  else
174           	    tw++;
175           	}
176                 else if (c == '?')
177           	{
178           	  if (t < h)
179           	    hj++;
180           	  else
181           	    tj++;
182           	}
183

Matthias





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