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.
11 #pragma ident "%Z%%M% %I% %E% SMI"
14 SM_RCSID("@(#)$Id: match.c,v 1.8 2001/03/02 19:57:08 ca Exp $")
16 #include <sm/string.h>
19 ** SM_MATCH -- Match a character string against a glob pattern.
23 ** par -- pattern to find in str.
26 ** true on match, false on non-match.
28 ** A pattern consists of normal characters, which match themselves,
29 ** and meta-sequences. A * matches any sequence of characters.
30 ** A ? matches any single character. A [ introduces a character class.
31 ** A ] marks the end of a character class; if the ] is missing then
32 ** the [ matches itself rather than introducing a character class.
33 ** A character class matches any of the characters between the brackets.
34 ** The range of characters from X to Y inclusive is written X-Y.
35 ** If the first character after the [ is ! then the character class is
38 ** To include a ] in a character class, make it the first character
39 ** listed (after the !, if any). To include a -, make it the first
40 ** character listed (after the !, if any) or the last character.
41 ** It is impossible for a ] to be the final character in a range.
42 ** For glob patterns that literally match "*", "?" or "[",
43 ** use [*], [?] or [[].
51 bool ccnot
, ccmatch
, ccfirst
;
71 /* optimize case of trailing '*' */
76 if (sm_match(pat
, str
))
100 if (*pat
== ']' && !ccfirst
)
104 if (*pat
== '-' && pat
[1] != ']')
113 if (*str
>= c
&& *str
<= c2
)