5 Author: Tatu Ylonen <ylo@cs.hut.fi>
7 Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
10 Created: Thu Jun 22 01:17:50 1995 ylo
12 Simple pattern matching, with '*' and '?' as wildcards.
21 /* Returns true if the given string matches the pattern (which may contain
22 ? and * as wildcards), and zero if it does not match. */
24 int match_pattern(const char *s, const char *pattern)
28 /* If at end of pattern, accept if also at end of string. */
35 /* Skip the asterisk. */
38 /* If at end of pattern, accept immediately. */
42 /* If next character in pattern is known, optimize. */
43 if (*pattern != '?' && *pattern != '*')
45 /* Look instances of the next character in pattern, and try
46 to match starting from those. */
49 match_pattern(s + 1, pattern + 1))
55 /* Move ahead one character at a time and try to match at each
58 if (match_pattern(s, pattern))
64 /* There must be at least one more character in the string. If we are
69 /* Check if the next character of the string is acceptable. */
70 if (*pattern != '?' && *pattern != *s)
73 /* Move to the next character, both in string and in pattern. */