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. */
25 match_pattern(const char *s, const char *pattern)
28 /* If at end of pattern, accept if also at end of string. */
33 if (*pattern == '*') {
34 /* Skip the asterisk. */
37 /* If at end of pattern, accept immediately. */
41 /* If next character in pattern is known, optimize. */
42 if (*pattern != '?' && *pattern != '*') {
43 /* Look instances of the next character in
44 pattern, and try to match starting from
48 match_pattern(s + 1, pattern + 1))
53 /* Move ahead one character at a time and try to
54 match at each position. */
56 if (match_pattern(s, pattern))
61 /* There must be at least one more character in the
62 string. If we are at the end, fail. */
66 /* Check if the next character of the string is
68 if (*pattern != '?' && *pattern != *s)
71 /* Move to the next character, both in string and in