Deleted Added
full compact
fnmatch.c (19059) fnmatch.c (19132)
1/*
2 * Copyright (c) 1989, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Guido van Rossum.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 37 unchanged lines hidden (view full) ---

46#include <ctype.h>
47#include <fnmatch.h>
48#include <locale.h>
49#include <string.h>
50#include <stdio.h>
51
52#define EOS '\0'
53
1/*
2 * Copyright (c) 1989, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Guido van Rossum.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 37 unchanged lines hidden (view full) ---

46#include <ctype.h>
47#include <fnmatch.h>
48#include <locale.h>
49#include <string.h>
50#include <stdio.h>
51
52#define EOS '\0'
53
54static const char *rangematch __P((const char *, int, int));
54static const char *rangematch __P((const char *, char, int));
55
56int
57fnmatch(pattern, string, flags)
58 const char *pattern, *string;
59 int flags;
60{
61 const char *stringstart;
62 char c, test;
63
64 for (stringstart = string;;)
65 switch (c = *pattern++) {
66 case EOS:
55
56int
57fnmatch(pattern, string, flags)
58 const char *pattern, *string;
59 int flags;
60{
61 const char *stringstart;
62 char c, test;
63
64 for (stringstart = string;;)
65 switch (c = *pattern++) {
66 case EOS:
67 if ((flags & FNM_LEADING_DIR) && *string == '/')
68 return (0);
67 return (*string == EOS ? 0 : FNM_NOMATCH);
68 case '?':
69 if (*string == EOS)
70 return (FNM_NOMATCH);
71 if (*string == '/' && (flags & FNM_PATHNAME))
72 return (FNM_NOMATCH);
73 if (*string == '.' && (flags & FNM_PERIOD) &&
74 (string == stringstart ||

--- 50 unchanged lines hidden (view full) ---

125 c = '\\';
126 --pattern;
127 }
128 }
129 /* FALLTHROUGH */
130 default:
131 if (c == *string)
132 ;
69 return (*string == EOS ? 0 : FNM_NOMATCH);
70 case '?':
71 if (*string == EOS)
72 return (FNM_NOMATCH);
73 if (*string == '/' && (flags & FNM_PATHNAME))
74 return (FNM_NOMATCH);
75 if (*string == '.' && (flags & FNM_PERIOD) &&
76 (string == stringstart ||

--- 50 unchanged lines hidden (view full) ---

127 c = '\\';
128 --pattern;
129 }
130 }
131 /* FALLTHROUGH */
132 default:
133 if (c == *string)
134 ;
133 else if ((flags & FNM_ICASE) &&
134 (tolower(c) == tolower(*string)))
135 else if ((flags & FNM_CASEFOLD) &&
136 (tolower((unsigned char)c) ==
137 tolower((unsigned char)*string)))
135 ;
136 else
137 return (FNM_NOMATCH);
138 string++;
139 break;
140 }
141 /* NOTREACHED */
142}
143
144static const char *
145rangematch(pattern, test, flags)
146 const char *pattern;
138 ;
139 else
140 return (FNM_NOMATCH);
141 string++;
142 break;
143 }
144 /* NOTREACHED */
145}
146
147static const char *
148rangematch(pattern, test, flags)
149 const char *pattern;
147 int test, flags;
150 char test;
151 int flags;
148{
149 int negate, ok;
150 char c, c2;
151
152 /*
153 * A bracket expression starting with an unquoted circumflex
154 * character produces unspecified results (IEEE 1003.2-1992,
155 * 3.13.2). This implementation treats it like '!', for
156 * consistency with the regular expression syntax.
157 * J.T. Conklin (conklin@ngai.kaleida.com)
158 */
159 if ( (negate = (*pattern == '!' || *pattern == '^')) )
160 ++pattern;
161
152{
153 int negate, ok;
154 char c, c2;
155
156 /*
157 * A bracket expression starting with an unquoted circumflex
158 * character produces unspecified results (IEEE 1003.2-1992,
159 * 3.13.2). This implementation treats it like '!', for
160 * consistency with the regular expression syntax.
161 * J.T. Conklin (conklin@ngai.kaleida.com)
162 */
163 if ( (negate = (*pattern == '!' || *pattern == '^')) )
164 ++pattern;
165
162 if (flags & FNM_ICASE)
163 test = tolower(test);
166 if (flags & FNM_CASEFOLD)
167 test = tolower((unsigned char)test);
164
165 for (ok = 0; (c = *pattern++) != ']';) {
166 if (c == '\\' && !(flags & FNM_NOESCAPE))
167 c = *pattern++;
168 if (c == EOS)
169 return (NULL);
170
168
169 for (ok = 0; (c = *pattern++) != ']';) {
170 if (c == '\\' && !(flags & FNM_NOESCAPE))
171 c = *pattern++;
172 if (c == EOS)
173 return (NULL);
174
171 if (flags & FNM_ICASE)
172 c = tolower(c);
175 if (flags & FNM_CASEFOLD)
176 c = tolower((unsigned char)c);
173
174 if (*pattern == '-'
175 && (c2 = *(pattern+1)) != EOS && c2 != ']') {
176 pattern += 2;
177 if (c2 == '\\' && !(flags & FNM_NOESCAPE))
178 c2 = *pattern++;
179 if (c2 == EOS)
180 return (NULL);
181
177
178 if (*pattern == '-'
179 && (c2 = *(pattern+1)) != EOS && c2 != ']') {
180 pattern += 2;
181 if (c2 == '\\' && !(flags & FNM_NOESCAPE))
182 c2 = *pattern++;
183 if (c2 == EOS)
184 return (NULL);
185
182 if (flags & FNM_ICASE)
183 c2 = tolower(c2);
186 if (flags & FNM_CASEFOLD)
187 c2 = tolower((unsigned char)c2);
184
185 if ( collate_range_cmp(c, test) <= 0
186 && collate_range_cmp(test, c2) <= 0
187 )
188 ok = 1;
189 } else if (c == test)
190 ok = 1;
191 }
192 return (ok == negate ? NULL : pattern);
193}
188
189 if ( collate_range_cmp(c, test) <= 0
190 && collate_range_cmp(test, c2) <= 0
191 )
192 ok = 1;
193 } else if (c == test)
194 ok = 1;
195 }
196 return (ok == negate ? NULL : pattern);
197}