2 * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
12 SM_RCSID("@(#)$Id: match.c,v 1.10 2001/09/11 04:04:48 gshapiro Exp $")
14 #include <sm/string.h>
17 ** SM_MATCH -- Match a character string against a glob pattern.
21 ** par -- pattern to find in str.
24 ** true on match, false on non-match.
26 ** A pattern consists of normal characters, which match themselves,
27 ** and meta-sequences. A * matches any sequence of characters.
28 ** A ? matches any single character. A [ introduces a character class.
29 ** A ] marks the end of a character class; if the ] is missing then
30 ** the [ matches itself rather than introducing a character class.
31 ** A character class matches any of the characters between the brackets.
32 ** The range of characters from X to Y inclusive is written X-Y.
33 ** If the first character after the [ is ! then the character class is
36 ** To include a ] in a character class, make it the first character
37 ** listed (after the !, if any). To include a -, make it the first
38 ** character listed (after the !, if any) or the last character.
39 ** It is impossible for a ] to be the final character in a range.
40 ** For glob patterns that literally match "*", "?" or "[",
41 ** use [*], [?] or [[].
49 bool ccnot
, ccmatch
, ccfirst
;
69 /* optimize case of trailing '*' */
74 if (sm_match(pat
, str
))
98 if (*pat
== ']' && !ccfirst
)
102 if (*pat
== '-' && pat
[1] != ']')
111 if (*str
>= c
&& *str
<= c2
)