fnmatch.c (17552) | fnmatch.c (19059) |
---|---|
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 --- 29 unchanged lines hidden (view full) --- 38static char sccsid[] = "@(#)fnmatch.c 8.2 (Berkeley) 4/16/94"; 39#endif /* LIBC_SCCS and not lint */ 40 41/* 42 * Function fnmatch() as specified in POSIX 1003.2-1992, section B.6. 43 * Compares a filename or pathname to a pattern. 44 */ 45 | 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 --- 29 unchanged lines hidden (view full) --- 38static char sccsid[] = "@(#)fnmatch.c 8.2 (Berkeley) 4/16/94"; 39#endif /* LIBC_SCCS and not lint */ 40 41/* 42 * Function fnmatch() as specified in POSIX 1003.2-1992, section B.6. 43 * Compares a filename or pathname to a pattern. 44 */ 45 |
46#include <ctype.h> |
|
46#include <fnmatch.h> 47#include <locale.h> 48#include <string.h> | 47#include <fnmatch.h> 48#include <locale.h> 49#include <string.h> |
50#include <stdio.h> |
|
49 50#define EOS '\0' 51 52static const char *rangematch __P((const char *, int, int)); 53 54int 55fnmatch(pattern, string, flags) 56 const char *pattern, *string; --- 64 unchanged lines hidden (view full) --- 121 if (!(flags & FNM_NOESCAPE)) { 122 if ((c = *pattern++) == EOS) { 123 c = '\\'; 124 --pattern; 125 } 126 } 127 /* FALLTHROUGH */ 128 default: | 51 52#define EOS '\0' 53 54static const char *rangematch __P((const char *, int, int)); 55 56int 57fnmatch(pattern, string, flags) 58 const char *pattern, *string; --- 64 unchanged lines hidden (view full) --- 123 if (!(flags & FNM_NOESCAPE)) { 124 if ((c = *pattern++) == EOS) { 125 c = '\\'; 126 --pattern; 127 } 128 } 129 /* FALLTHROUGH */ 130 default: |
129 if (c != *string++) | 131 if (c == *string) 132 ; 133 else if ((flags & FNM_ICASE) && 134 (tolower(c) == tolower(*string))) 135 ; 136 else |
130 return (FNM_NOMATCH); | 137 return (FNM_NOMATCH); |
138 string++; |
|
131 break; 132 } 133 /* NOTREACHED */ 134} 135 136static const char * 137rangematch(pattern, test, flags) 138 const char *pattern; --- 7 unchanged lines hidden (view full) --- 146 * character produces unspecified results (IEEE 1003.2-1992, 147 * 3.13.2). This implementation treats it like '!', for 148 * consistency with the regular expression syntax. 149 * J.T. Conklin (conklin@ngai.kaleida.com) 150 */ 151 if ( (negate = (*pattern == '!' || *pattern == '^')) ) 152 ++pattern; 153 | 139 break; 140 } 141 /* NOTREACHED */ 142} 143 144static const char * 145rangematch(pattern, test, flags) 146 const char *pattern; --- 7 unchanged lines hidden (view full) --- 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 |
162 if (flags & FNM_ICASE) 163 test = tolower(test); 164 |
|
154 for (ok = 0; (c = *pattern++) != ']';) { 155 if (c == '\\' && !(flags & FNM_NOESCAPE)) 156 c = *pattern++; 157 if (c == EOS) 158 return (NULL); | 165 for (ok = 0; (c = *pattern++) != ']';) { 166 if (c == '\\' && !(flags & FNM_NOESCAPE)) 167 c = *pattern++; 168 if (c == EOS) 169 return (NULL); |
170 171 if (flags & FNM_ICASE) 172 c = tolower(c); 173 |
|
159 if (*pattern == '-' 160 && (c2 = *(pattern+1)) != EOS && c2 != ']') { 161 pattern += 2; 162 if (c2 == '\\' && !(flags & FNM_NOESCAPE)) 163 c2 = *pattern++; 164 if (c2 == EOS) 165 return (NULL); | 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 182 if (flags & FNM_ICASE) 183 c2 = tolower(c2); 184 |
|
166 if ( collate_range_cmp(c, test) <= 0 167 && collate_range_cmp(test, c2) <= 0 168 ) 169 ok = 1; 170 } else if (c == test) 171 ok = 1; 172 } 173 return (ok == negate ? NULL : pattern); 174} | 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} |