diff options
author | Damien Miller <djm@mindrot.org> | 1999-11-25 11:54:57 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 1999-11-25 11:54:57 +1100 |
commit | 5428f646ad32da88ddd04a8c287d595524674fbf (patch) | |
tree | cc1f1e5d7852e1f44d41077f776abf7dab7ac06d /match.c | |
parent | 9072e1889648988da38b7b81bce95291c1dc3a23 (diff) |
- More reformatting merged from OpenBSD CVS
- Merged OpenBSD CVS changes:
- [channels.c]
report from mrwizard@psu.edu via djm@ibs.com.au
- [channels.c]
set SO_REUSEADDR and SO_LINGER for forwarded ports.
chip@valinux.com via damien@ibs.com.au
- [nchan.c]
it's not an error() if shutdown_write failes in nchan.
- [readconf.c]
remove dead #ifdef-0-code
- [readconf.c servconf.c]
strcasecmp instead of tolower
- [scp.c]
progress meter overflow fix from damien@ibs.com.au
- [ssh-add.1 ssh-add.c]
SSH_ASKPASS support
- [ssh.1 ssh.c]
postpone fork_after_authentication until command execution,
request/patch from jahakala@cc.jyu.fi via damien@ibs.com.au
plus: use daemon() for backgrounding
Diffstat (limited to 'match.c')
-rw-r--r-- | match.c | 35 |
1 files changed, 20 insertions, 15 deletions
@@ -14,12 +14,14 @@ | |||
14 | */ | 14 | */ |
15 | 15 | ||
16 | #include "includes.h" | 16 | #include "includes.h" |
17 | RCSID("$Id: match.c,v 1.2 1999/11/24 13:26:22 damien Exp $"); | 17 | RCSID("$Id: match.c,v 1.3 1999/11/25 00:54:59 damien Exp $"); |
18 | 18 | ||
19 | #include "ssh.h" | 19 | #include "ssh.h" |
20 | 20 | ||
21 | /* Returns true if the given string matches the pattern (which may contain | 21 | /* |
22 | ? and * as wildcards), and zero if it does not match. */ | 22 | * Returns true if the given string matches the pattern (which may contain ? |
23 | * and * as wildcards), and zero if it does not match. | ||
24 | */ | ||
23 | 25 | ||
24 | int | 26 | int |
25 | match_pattern(const char *s, const char *pattern) | 27 | match_pattern(const char *s, const char *pattern) |
@@ -29,7 +31,6 @@ match_pattern(const char *s, const char *pattern) | |||
29 | if (!*pattern) | 31 | if (!*pattern) |
30 | return !*s; | 32 | return !*s; |
31 | 33 | ||
32 | /* Process '*'. */ | ||
33 | if (*pattern == '*') { | 34 | if (*pattern == '*') { |
34 | /* Skip the asterisk. */ | 35 | /* Skip the asterisk. */ |
35 | pattern++; | 36 | pattern++; |
@@ -40,9 +41,11 @@ match_pattern(const char *s, const char *pattern) | |||
40 | 41 | ||
41 | /* If next character in pattern is known, optimize. */ | 42 | /* If next character in pattern is known, optimize. */ |
42 | if (*pattern != '?' && *pattern != '*') { | 43 | if (*pattern != '?' && *pattern != '*') { |
43 | /* Look instances of the next character in | 44 | /* |
44 | pattern, and try to match starting from | 45 | * Look instances of the next character in |
45 | those. */ | 46 | * pattern, and try to match starting from |
47 | * those. | ||
48 | */ | ||
46 | for (; *s; s++) | 49 | for (; *s; s++) |
47 | if (*s == *pattern && | 50 | if (*s == *pattern && |
48 | match_pattern(s + 1, pattern + 1)) | 51 | match_pattern(s + 1, pattern + 1)) |
@@ -50,26 +53,28 @@ match_pattern(const char *s, const char *pattern) | |||
50 | /* Failed. */ | 53 | /* Failed. */ |
51 | return 0; | 54 | return 0; |
52 | } | 55 | } |
53 | /* Move ahead one character at a time and try to | 56 | /* |
54 | match at each position. */ | 57 | * Move ahead one character at a time and try to |
58 | * match at each position. | ||
59 | */ | ||
55 | for (; *s; s++) | 60 | for (; *s; s++) |
56 | if (match_pattern(s, pattern)) | 61 | if (match_pattern(s, pattern)) |
57 | return 1; | 62 | return 1; |
58 | /* Failed. */ | 63 | /* Failed. */ |
59 | return 0; | 64 | return 0; |
60 | } | 65 | } |
61 | /* There must be at least one more character in the | 66 | /* |
62 | string. If we are at the end, fail. */ | 67 | * There must be at least one more character in the string. |
68 | * If we are at the end, fail. | ||
69 | */ | ||
63 | if (!*s) | 70 | if (!*s) |
64 | return 0; | 71 | return 0; |
65 | 72 | ||
66 | /* Check if the next character of the string is | 73 | /* Check if the next character of the string is acceptable. */ |
67 | acceptable. */ | ||
68 | if (*pattern != '?' && *pattern != *s) | 74 | if (*pattern != '?' && *pattern != *s) |
69 | return 0; | 75 | return 0; |
70 | 76 | ||
71 | /* Move to the next character, both in string and in | 77 | /* Move to the next character, both in string and in pattern. */ |
72 | pattern. */ | ||
73 | s++; | 78 | s++; |
74 | pattern++; | 79 | pattern++; |
75 | } | 80 | } |