Parolin 0.7.9 6796
Console (soon DLLs) to do a tar like job
Loading...
Searching...
No Matches
fnmatch_arp.c
Go to the documentation of this file.
1//2021 amanda & ricardo
2/*
3 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 *
5 * @APPLE_LICENSE_HEADER_START@
6 *
7 * The contents of this file constitute Original Code as defined in and
8 * are subject to the Apple Public Source License Version 1.1 (the
9 * "License"). You may not use this file except in compliance with the
10 * License. Please obtain a copy of the License at
11 * http://www.apple.com/publicsource and read it before using this file.
12 *
13 * This Original Code and all software distributed under the License are
14 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
18 * License for the specific language governing rights and limitations
19 * under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/*
24 * Copyright (c) 1989, 1993, 1994
25 * The Regents of the University of California. All rights reserved.
26 *
27 * This code is derived from software contributed to Berkeley by
28 * Guido van Rossum.
29 *
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions
32 * are met:
33 * 1. Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in the
37 * documentation and/or other materials provided with the distribution.
38 * 3. All advertising materials mentioning features or use of this software
39 * must display the following acknowledgement:
40 * This product includes software developed by the University of
41 * California, Berkeley and its contributors.
42 * 4. Neither the name of the University nor the names of its contributors
43 * may be used to endorse or promote products derived from this software
44 * without specific prior written permission.
45 *
46 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * SUCH DAMAGE.
57 */
58
59
60/*
61 * Function fnmatch() as specified in POSIX 1003.2-1992, section B.6.
62 * Compares a filename or pathname to a pattern.
63 */
64
65//#include <fnmatch.h>
66#include <string.h>
67
68#define EOS '\0'
69
70#define FNM_NOMATCH 1
71#define FNM_PATHNAME (1 << 0) /* No wildcard can ever match '/'. */
72#define FNM_NOESCAPE (1 << 1) /* Backslashes don't quote special chars. */
73#define FNM_PERIOD (1 << 2) /* Leading '.' is matched only explicitly. */
74
75static const char *rangematch (const char *, int, int);
76
77int
78fnmatch(const char *pattern, const char * string, int flags)
79{
80 const char *stringstart;
81 char c, test;
82
83 for (stringstart = string;;)
84 switch (c = *pattern++) {
85 case EOS:
86 return (*string == EOS ? 0 : FNM_NOMATCH);
87 case '?':
88 if (*string == EOS)
89 return (FNM_NOMATCH);
90 if (*string == '/' && (flags & FNM_PATHNAME))
91 return (FNM_NOMATCH);
92 if (*string == '.' && (flags & FNM_PERIOD) &&
93 (string == stringstart ||
94 ((flags & FNM_PATHNAME) && *(string - 1) == '/')))
95 return (FNM_NOMATCH);
96 ++string;
97 break;
98 case '*':
99 c = *pattern;
100 /* Collapse multiple stars. */
101 while (c == '*')
102 c = *++pattern;
103
104 if (*string == '.' && (flags & FNM_PERIOD) &&
105 (string == stringstart ||
106 ((flags & FNM_PATHNAME) && *(string - 1) == '/')))
107 return (FNM_NOMATCH);
108
109 /* Optimize for pattern with * at end or before /. */
110 if (c == EOS)
111 if (flags & FNM_PATHNAME)
112 return (strchr(string, '/') == NULL ?
113 0 : FNM_NOMATCH);
114 else
115 return (0);
116 else if (c == '/' && flags & FNM_PATHNAME) {
117 if ((string = strchr(string, '/')) == NULL)
118 return (FNM_NOMATCH);
119 break;
120 }
121
122 /* General case, use recursion. */
123 while ((test = *string) != EOS) {
124 if (!fnmatch(pattern, string, flags & ~FNM_PERIOD))
125 return (0);
126 if (test == '/' && flags & FNM_PATHNAME)
127 break;
128 ++string;
129 }
130 return (FNM_NOMATCH);
131 case '[':
132 if (*string == EOS)
133 return (FNM_NOMATCH);
134 if (*string == '/' && flags & FNM_PATHNAME)
135 return (FNM_NOMATCH);
136 if ((pattern =
137 rangematch(pattern, *string, flags)) == NULL)
138 return (FNM_NOMATCH);
139 ++string;
140 break;
141 case '\\':
142 if (!(flags & FNM_NOESCAPE)) {
143 if ((c = *pattern++) == EOS) {
144 c = '\\';
145 --pattern;
146 }
147 }
148 /* FALLTHROUGH */
149 default:
150 if (c != *string++)
151 return (FNM_NOMATCH);
152 break;
153 }
154 /* NOTREACHED */
155}
156
157static const char *
158rangematch(pattern, test, flags)
159 const char *pattern;
160 int test, flags;
161{
162 int negate, ok;
163 char c, c2;
164
165 /*
166 * A bracket expression starting with an unquoted circumflex
167 * character produces unspecified results (IEEE 1003.2-1992,
168 * 3.13.2). This implementation treats it like '!', for
169 * consistency with the regular expression syntax.
170 * J.T. Conklin (conklin@ngai.kaleida.com)
171 */
172 if ((negate = (*pattern == '!' || *pattern == '^')))
173 ++pattern;
174
175 for (ok = 0; (c = *pattern++) != ']';) {
176 if (c == '\\' && !(flags & FNM_NOESCAPE))
177 c = *pattern++;
178 if (c == EOS)
179 return (NULL);
180 if (*pattern == '-'
181 && (c2 = *(pattern+1)) != EOS && c2 != ']') {
182 pattern += 2;
183 if (c2 == '\\' && !(flags & FNM_NOESCAPE))
184 c2 = *pattern++;
185 if (c2 == EOS)
186 return (NULL);
187 if (c <= test && test <= c2)
188 ok = 1;
189 } else if (c == test)
190 ok = 1;
191 }
192 return (ok == negate ? NULL : pattern);
193}
int fnmatch(const char *pattern, const char *string, int flags)
Definition fnmatch_arp.c:78
#define FNM_NOESCAPE
Definition fnmatch_arp.c:72
#define FNM_PERIOD
Definition fnmatch_arp.c:73
#define EOS
Definition fnmatch_arp.c:68
#define FNM_PATHNAME
Definition fnmatch_arp.c:71
#define FNM_NOMATCH
Definition fnmatch_arp.c:70
-lz4-abi
#define c(i)
Definition sha256.c:43
uint32_t flags
Definition container.h:628
#define NULL
Definition getopt1.c:37