diff options
Diffstat (limited to 'shell/match.c')
-rw-r--r-- | shell/match.c | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/shell/match.c b/shell/match.c index 8b1ddacd5..01b843918 100644 --- a/shell/match.c +++ b/shell/match.c | |||
@@ -31,26 +31,23 @@ char *scanleft(char *string, char *pattern, bool match_at_left) | |||
31 | char c; | 31 | char c; |
32 | char *loc = string; | 32 | char *loc = string; |
33 | 33 | ||
34 | do { | 34 | while (1) { |
35 | int match; | 35 | int match; |
36 | const char *s; | ||
37 | 36 | ||
38 | c = *loc; | 37 | c = *loc; |
39 | if (match_at_left) { | 38 | if (match_at_left) { |
40 | *loc = '\0'; | 39 | *loc = '\0'; |
41 | s = string; | 40 | match = pmatch(pattern, string); |
42 | } else | 41 | *loc = c; |
43 | s = loc; | 42 | } else { |
44 | match = pmatch(pattern, s); | 43 | match = pmatch(pattern, loc); |
45 | *loc = c; | 44 | } |
46 | |||
47 | if (match) | 45 | if (match) |
48 | return loc; | 46 | return loc; |
49 | 47 | if (!c) | |
48 | return NULL; | ||
50 | loc++; | 49 | loc++; |
51 | } while (c); | 50 | } |
52 | |||
53 | return NULL; | ||
54 | } | 51 | } |
55 | 52 | ||
56 | char *scanright(char *string, char *pattern, bool match_at_left) | 53 | char *scanright(char *string, char *pattern, bool match_at_left) |
@@ -60,20 +57,17 @@ char *scanright(char *string, char *pattern, bool match_at_left) | |||
60 | 57 | ||
61 | while (loc >= string) { | 58 | while (loc >= string) { |
62 | int match; | 59 | int match; |
63 | const char *s; | ||
64 | 60 | ||
65 | c = *loc; | 61 | c = *loc; |
66 | if (match_at_left) { | 62 | if (match_at_left) { |
67 | *loc = '\0'; | 63 | *loc = '\0'; |
68 | s = string; | 64 | match = pmatch(pattern, string); |
69 | } else | 65 | *loc = c; |
70 | s = loc; | 66 | } else { |
71 | match = pmatch(pattern, s); | 67 | match = pmatch(pattern, loc); |
72 | *loc = c; | 68 | } |
73 | |||
74 | if (match) | 69 | if (match) |
75 | return loc; | 70 | return loc; |
76 | |||
77 | loc--; | 71 | loc--; |
78 | } | 72 | } |
79 | 73 | ||