wildmatch: remove unnecessary functions
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Oct 15, 2012 at 13:25 UTC
b0e0287626d6257dd45df5502a07efd15a7255bc
2 files changed
+10
-156
wildmatch.c
+10
-154
@@ -53,33 +53,18 @@
53
#define ISUPPER(c) (ISASCII(c) && isupper(c))
54
#define ISXDIGIT(c) (ISASCII(c) && isxdigit(c))
55
56
-#ifdef WILD_TEST_ITERATIONS
57
-int wildmatch_iteration_count;
58
-#endif
59
-
56
static int force_lower_case = 0;
57
62
-/* Match pattern "p" against the a virtually-joined string consisting
63
- * of "text" and any strings in array "a". */
64
-static int dowild(const uchar *p, const uchar *text, const uchar*const *a)
58
+/* Match pattern "p" against "text" */
59
+static int dowild(const uchar *p, const uchar *text)
60
{
61
uchar p_ch;
62
68
-#ifdef WILD_TEST_ITERATIONS
69
- wildmatch_iteration_count++;
70
-#endif
71
-
63
for ( ; (p_ch = *p) != '\0'; text++, p++) {
64
int matched, special;
65
uchar t_ch, prev_ch;
75
- while ((t_ch = *text) == '\0') {
76
- if (*a == NULL) {
77
- if (p_ch != '*')
78
- return ABORT_ALL;
79
- break;
80
- }
81
- text = *a++;
82
- }
66
+ if ((t_ch = *text) == '\0' && p_ch != '*')
67
+ return ABORT_ALL;
68
if (force_lower_case && ISUPPER(t_ch))
69
t_ch = tolower(t_ch);
70
switch (p_ch) {
@@ -107,21 +92,15 @@ static int dowild(const uchar *p, const uchar *text, const uchar*const *a)
92
/* Trailing "**" matches everything. Trailing "*" matches
93
* only if there are no more slash characters. */
94
if (!special) {
110
- do {
95
if (strchr((char*)text, '/') != NULL)
96
return FALSE;
113
- } while ((text = *a++) != NULL);
97
}
98
return TRUE;
99
}
100
while (1) {
118
- if (t_ch == '\0') {
119
- if ((text = *a++) == NULL)
120
- break;
121
- t_ch = *text;
122
- continue;
123
- }
124
- if ((matched = dowild(p, text, a)) != FALSE) {
101
+ if (t_ch == '\0')
102
+ break;
103
+ if ((matched = dowild(p, text)) != FALSE) {
104
if (!special || matched != ABORT_TO_STARSTAR)
105
return matched;
106
} else if (!special && t_ch == '/')
@@ -225,144 +204,21 @@ static int dowild(const uchar *p, const uchar *text, const uchar*const *a)
204
}
205
}
206
228
- do {
229
- if (*text)
230
- return FALSE;
231
- } while ((text = *a++) != NULL);
232
-
233
- return TRUE;
234
-}
235
-
236
-/* Match literal string "s" against the a virtually-joined string consisting
237
- * of "text" and any strings in array "a". */
238
-static int doliteral(const uchar *s, const uchar *text, const uchar*const *a)
239
-{
240
- for ( ; *s != '\0'; text++, s++) {
241
- while (*text == '\0') {
242
- if ((text = *a++) == NULL)
243
- return FALSE;
244
- }
245
- if (*text != *s)
246
- return FALSE;
247
- }
248
-
249
- do {
250
- if (*text)
251
- return FALSE;
252
- } while ((text = *a++) != NULL);
253
-
254
- return TRUE;
255
-}
256
-
257
-/* Return the last "count" path elements from the concatenated string.
258
- * We return a string pointer to the start of the string, and update the
259
- * array pointer-pointer to point to any remaining string elements. */
260
-static const uchar *trailing_N_elements(const uchar*const **a_ptr, int count)
261
-{
262
- const uchar*const *a = *a_ptr;
263
- const uchar*const *first_a = a;
264
-
265
- while (*a)
266
- a++;
267
-
268
- while (a != first_a) {
269
- const uchar *s = *--a;
270
- s += strlen((char*)s);
271
- while (--s >= *a) {
272
- if (*s == '/' && !--count) {
273
- *a_ptr = a+1;
274
- return s+1;
275
- }
276
- }
277
- }
278
-
279
- if (count == 1) {
280
- *a_ptr = a+1;
281
- return *a;
282
- }
283
-
284
- return NULL;
207
+ return *text ? FALSE : TRUE;
208
}
209
210
/* Match the "pattern" against the "text" string. */
211
int wildmatch(const char *pattern, const char *text)
212
{
290
- static const uchar *nomore[1]; /* A NULL pointer. */
291
-#ifdef WILD_TEST_ITERATIONS
292
- wildmatch_iteration_count = 0;
293
-#endif
294
- return dowild((const uchar*)pattern, (const uchar*)text, nomore) == TRUE;
213
+ return dowild((const uchar*)pattern, (const uchar*)text) == TRUE;
214
}
215
216
/* Match the "pattern" against the forced-to-lower-case "text" string. */
217
int iwildmatch(const char *pattern, const char *text)
218
{
300
- static const uchar *nomore[1]; /* A NULL pointer. */
219
int ret;
302
-#ifdef WILD_TEST_ITERATIONS
303
- wildmatch_iteration_count = 0;
304
-#endif
220
force_lower_case = 1;
306
- ret = dowild((const uchar*)pattern, (const uchar*)text, nomore) == TRUE;
221
+ ret = dowild((const uchar*)pattern, (const uchar*)text) == TRUE;
222
force_lower_case = 0;
223
return ret;
224
}
310
-
311
-/* Match pattern "p" against the a virtually-joined string consisting
312
- * of all the pointers in array "texts" (which has a NULL pointer at the
313
- * end). The int "where" can be 0 (normal matching), > 0 (match only
314
- * the trailing N slash-separated filename components of "texts"), or < 0
315
- * (match the "pattern" at the start or after any slash in "texts"). */
316
-int wildmatch_array(const char *pattern, const char*const *texts, int where)
317
-{
318
- const uchar *p = (const uchar*)pattern;
319
- const uchar*const *a = (const uchar*const*)texts;
320
- const uchar *text;
321
- int matched;
322
-
323
-#ifdef WILD_TEST_ITERATIONS
324
- wildmatch_iteration_count = 0;
325
-#endif
326
-
327
- if (where > 0)
328
- text = trailing_N_elements(&a, where);
329
- else
330
- text = *a++;
331
- if (!text)
332
- return FALSE;
333
-
334
- if ((matched = dowild(p, text, a)) != TRUE && where < 0
335
- && matched != ABORT_ALL) {
336
- while (1) {
337
- if (*text == '\0') {
338
- if ((text = (uchar*)*a++) == NULL)
339
- return FALSE;
340
- continue;
341
- }
342
- if (*text++ == '/' && (matched = dowild(p, text, a)) != FALSE
343
- && matched != ABORT_TO_STARSTAR)
344
- break;
345
- }
346
- }
347
- return matched == TRUE;
348
-}
349
-
350
-/* Match literal string "s" against the a virtually-joined string consisting
351
- * of all the pointers in array "texts" (which has a NULL pointer at the
352
- * end). The int "where" can be 0 (normal matching), or > 0 (match
353
- * only the trailing N slash-separated filename components of "texts"). */
354
-int litmatch_array(const char *string, const char*const *texts, int where)
355
-{
356
- const uchar *s = (const uchar*)string;
357
- const uchar*const *a = (const uchar* const*)texts;
358
- const uchar *text;
359
-
360
- if (where > 0)
361
- text = trailing_N_elements(&a, where);
362
- else
363
- text = *a++;
364
- if (!text)
365
- return FALSE;
366
-
367
- return doliteral(s, text, a) == TRUE;
368
-}
wildmatch.h
-2
@@ -2,5 +2,3 @@
2
3
int wildmatch(const char *pattern, const char *text);
4
int iwildmatch(const char *pattern, const char *text);
5
-int wildmatch_array(const char *pattern, const char*const *texts, int where);
6
-int litmatch_array(const char *string, const char*const *texts, int where);