Source-Changes-HG archive

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

[src/netbsd-1-5]: src/lib/libc/gen Pull up rev. 1.18:



details:   https://anonhg.NetBSD.org/src/rev/472d6fa60120
branches:  netbsd-1-5
changeset: 488392:472d6fa60120
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Mon Jul 03 22:30:13 2000 +0000

description:
Pull up rev. 1.18:
Implement FNM_CASEFOLD, for matching the pattern in a case-insensitive
way.  Flag name taken from glibc.

diffstat:

 lib/libc/gen/fnmatch.c |  43 +++++++++++++++++++++++++++++--------------
 1 files changed, 29 insertions(+), 14 deletions(-)

diffs (125 lines):

diff -r c31b282a3df8 -r 472d6fa60120 lib/libc/gen/fnmatch.c
--- a/lib/libc/gen/fnmatch.c    Mon Jul 03 22:29:48 2000 +0000
+++ b/lib/libc/gen/fnmatch.c    Mon Jul 03 22:30:13 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fnmatch.c,v 1.17 2000/01/22 22:19:10 mycroft Exp $     */
+/*     $NetBSD: fnmatch.c,v 1.17.4.1 2000/07/03 22:30:13 thorpej Exp $ */
 
 /*
  * Copyright (c) 1989, 1993, 1994
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)fnmatch.c  8.2 (Berkeley) 4/16/94";
 #else
-__RCSID("$NetBSD: fnmatch.c,v 1.17 2000/01/22 22:19:10 mycroft Exp $");
+__RCSID("$NetBSD: fnmatch.c,v 1.17.4.1 2000/07/03 22:30:13 thorpej Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -53,6 +53,7 @@
 #include "namespace.h"
 
 #include <assert.h>
+#include <ctype.h>
 #include <fnmatch.h>
 #include <string.h>
 
@@ -64,6 +65,17 @@
 
 static const char *rangematch __P((const char *, int, int));
 
+static __inline int
+foldcase(int ch, int flags)
+{
+
+       if ((flags & FNM_CASEFOLD) != 0 && isupper(ch))
+               return (tolower(ch));
+       return (ch);
+}
+
+#define        FOLDCASE(ch, flags)     foldcase((unsigned char)(ch), (flags))
+
 int
 fnmatch(pattern, string, flags)
        const char *pattern, *string;
@@ -76,7 +88,7 @@
        _DIAGASSERT(string != NULL);
 
        for (stringstart = string;;)
-               switch (c = *pattern++) {
+               switch (c = FOLDCASE(*pattern++, flags)) {
                case EOS:
                        return (*string == EOS ? 0 : FNM_NOMATCH);
                case '?':
@@ -91,10 +103,10 @@
                        ++string;
                        break;
                case '*':
-                       c = *pattern;
+                       c = FOLDCASE(*pattern, flags);
                        /* Collapse multiple stars. */
                        while (c == '*')
-                               c = *++pattern;
+                               c = FOLDCASE(*++pattern, flags);
 
                        if (*string == '.' && (flags & FNM_PERIOD) &&
                            (string == stringstart ||
@@ -115,8 +127,9 @@
                        }
 
                        /* General case, use recursion. */
-                       while ((test = *string) != EOS) {
-                               if (!fnmatch(pattern, string, flags & ~FNM_PERIOD))
+                       while ((test = FOLDCASE(*string, flags)) != EOS) {
+                               if (!fnmatch(pattern, string,
+                                            flags & ~FNM_PERIOD))
                                        return (0);
                                if (test == '/' && flags & FNM_PATHNAME)
                                        break;
@@ -129,20 +142,21 @@
                        if (*string == '/' && flags & FNM_PATHNAME)
                                return (FNM_NOMATCH);
                        if ((pattern =
-                           rangematch(pattern, *string, flags)) == NULL)
+                           rangematch(pattern, FOLDCASE(*string, flags),
+                                      flags)) == NULL)
                                return (FNM_NOMATCH);
                        ++string;
                        break;
                case '\\':
                        if (!(flags & FNM_NOESCAPE)) {
-                               if ((c = *pattern++) == EOS) {
+                               if ((c = FOLDCASE(*pattern++, flags)) == EOS) {
                                        c = '\\';
                                        --pattern;
                                }
                        }
                        /* FALLTHROUGH */
                default:
-                       if (c != *string++)
+                       if (c != FOLDCASE(*string++, flags))
                                return (FNM_NOMATCH);
                        break;
                }
@@ -169,16 +183,17 @@
        if ((negate = (*pattern == '!' || *pattern == '^')) != 0)
                ++pattern;
        
-       for (ok = 0; (c = *pattern++) != ']';) {
+       for (ok = 0; (c = FOLDCASE(*pattern++, flags)) != ']';) {
                if (c == '\\' && !(flags & FNM_NOESCAPE))
-                       c = *pattern++;
+                       c = FOLDCASE(*pattern++, flags);
                if (c == EOS)
                        return (NULL);
                if (*pattern == '-' 
-                   && (c2 = *(pattern+1)) != EOS && c2 != ']') {
+                   && (c2 = FOLDCASE(*(pattern+1), flags)) != EOS &&
+                       c2 != ']') {
                        pattern += 2;
                        if (c2 == '\\' && !(flags & FNM_NOESCAPE))
-                               c2 = *pattern++;
+                               c2 = FOLDCASE(*pattern++, flags);
                        if (c2 == EOS)
                                return (NULL);
                        if (c <= test && test <= c2)



Home | Main Index | Thread Index | Old Index