1 /* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Library General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Library General Public License for more details.
13 * You should have received a copy of the GNU Library General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 02111-1307, USA.
20 * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
21 * file for a list of people on the GTK+ Team. See the ChangeLog
22 * files for a list of changes. These files are distributed with
23 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
32 /* Added for GTK. We need to make sure that all constants are defined
33 * to properly compile this file */
39 /* We need glib.h for G_DIR_SEPARATOR and G_OS_WIN32 */
44 /* Comment out all this code if we are using the GNU C Library, and are not
45 actually compiling the library itself. This code is part of the GNU C
46 Library, but also included in many other GNU distributions. Compiling
47 and linking in this code is a waste when using the GNU C library
48 (especially if it is a shared library). Rather than having every GNU
49 program understand `configure --with-gnu-libc' and omit the object files,
50 it is simpler to just do this in the source for each such file. */
52 #if defined (_LIBC) || !defined (__GNU_LIBRARY__)
54 #if !defined(__GNU_LIBRARY__) && !defined(STDC_HEADERS)
58 /* Match STRING against the filename pattern PATTERN, returning zero if
59 it matches, nonzero if not. */
61 fnmatch (pattern, string, flags)
66 register const char *p = pattern, *n = string;
69 /* Note that this evalutes C many times. */
70 #if !defined(G_OS_WIN32) && !defined(G_HAVE_CYGWIN)
71 #define FOLD(c) ((flags & FNM_CASEFOLD) && isupper (c) ? tolower (c) : (c))
73 #define FOLD(c) (tolower (c))
76 while ((c = *p++) != '\0')
85 else if ((flags & FNM_FILE_NAME) && *n == G_DIR_SEPARATOR)
87 else if ((flags & FNM_PERIOD) && *n == '.' &&
88 (n == string || ((flags & FNM_FILE_NAME) && n[-1] == G_DIR_SEPARATOR)))
93 if (!(flags & FNM_NOESCAPE))
103 if ((flags & FNM_PERIOD) && *n == '.' &&
104 (n == string || ((flags & FNM_FILE_NAME) && n[-1] == G_DIR_SEPARATOR)))
107 for (c = *p++; c == '?' || c == '*'; c = *p++, ++n)
108 if (((flags & FNM_FILE_NAME) && *n == G_DIR_SEPARATOR) ||
109 (c == '?' && *n == '\0'))
117 char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? *p : c;
122 for (--p; *n != '\0'; ++n)
123 if ((c == '[' || FOLD (*n) == c1) &&
124 fnmatch (p, n, flags & ~FNM_PERIOD) == 0)
131 /* Nonzero if the sense of the character class is inverted. */
137 if ((flags & FNM_PERIOD) && *n == '.' &&
138 (n == string || ((flags & FNM_FILE_NAME) && n[-1] == G_DIR_SEPARATOR)))
141 not = (*p == '!' || *p == '^');
148 register char cstart = c, cend = c;
150 if (!(flags & FNM_NOESCAPE) && c == '\\')
151 cstart = cend = *p++;
153 cstart = cend = FOLD (cstart);
156 /* [ (unterminated) loses. */
162 if ((flags & FNM_FILE_NAME) && c == G_DIR_SEPARATOR)
163 /* [/] can never match. */
166 if (c == '-' && *p != ']')
170 if (!(flags & FNM_NOESCAPE) && cend == '\\')
180 if (FOLD (*n) >= cstart && FOLD (*n) <= cend)
191 /* Skip the rest of the [...] that already matched. */
195 /* [... (unterminated) loses. */
200 if (!(flags & FNM_NOESCAPE) && c == '\\')
201 /* XXX 1003.2d11 is unclear if this is right. */
221 if ((flags & FNM_LEADING_DIR) && *n == G_DIR_SEPARATOR)
222 /* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz". */
228 #endif /* _LIBC or not __GNU_LIBRARY__. */