From e298ce69baef029f3951dd1d5ed50fdbc6c55c80 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 4 Sep 2010 19:52:44 +0200 Subject: hush: fix handling of backslashes in variable assignment Signed-off-by: Denys Vlasenko --- shell/match.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'shell/match.c') 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) char c; char *loc = string; - do { + while (1) { int match; - const char *s; c = *loc; if (match_at_left) { *loc = '\0'; - s = string; - } else - s = loc; - match = pmatch(pattern, s); - *loc = c; - + match = pmatch(pattern, string); + *loc = c; + } else { + match = pmatch(pattern, loc); + } if (match) return loc; - + if (!c) + return NULL; loc++; - } while (c); - - return NULL; + } } char *scanright(char *string, char *pattern, bool match_at_left) @@ -60,20 +57,17 @@ char *scanright(char *string, char *pattern, bool match_at_left) while (loc >= string) { int match; - const char *s; c = *loc; if (match_at_left) { *loc = '\0'; - s = string; - } else - s = loc; - match = pmatch(pattern, s); - *loc = c; - + match = pmatch(pattern, string); + *loc = c; + } else { + match = pmatch(pattern, loc); + } if (match) return loc; - loc--; } -- cgit v1.2.3