[hackers] [sbase] [PATCH] fix problems in sed

From: izabera <izaberina_AT_gmail.com>
Date: Sun, 14 Feb 2016 14:10:07 +0100

s/x/y/w file <- chomp whitespace
s/x/y/1p <- don't ignore first char after number
s[x[y[ <- [ is a valid delim
---
 sed.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/sed.c b/sed.c
index 8480477..6cfd121 100644
--- a/sed.c
+++ b/sed.c
_AT_@ -553,8 +553,8 @@ find_delim(char *s, Rune delim, int do_brackets)
 		else if (state == BRACKETS_INSIDE        &&  r == ']'  ) { state  = OUTSIDE         ;           }
 		else if (state == OUTSIDE                &&  escape    ) { escape = 0               ;           }
 		else if (state == OUTSIDE                &&  r == '\\' ) { escape = 1               ;           }
-		else if (state == OUTSIDE && do_brackets &&  r == '['  ) { state  = BRACKETS_OPENING;           }
 		else if (state == OUTSIDE                &&  r == delim) return s;
+		else if (state == OUTSIDE && do_brackets &&  r == '['  ) { state  = BRACKETS_OPENING;           }
 	}
 	return s;
 }
_AT_@ -892,6 +892,7 @@ get_s_arg(Cmd *c, char *s)
 	for (; s < p; s++) {
 		if (isdigit(*s)) {
 			c->u.s.occurrence = stol(s, &s);
+			s--; /* for loop will advance pointer */
 		} else {
 			switch (*s) {
 			case 'g': c->u.s.occurrence = 0; break;
_AT_@ -899,7 +900,7 @@ get_s_arg(Cmd *c, char *s)
 			case 'w':
 				/* must be last flag, take everything up to newline/semicolon
 				 * s == p after this */
-				s = get_w_arg(&buf, s);
+				s = get_w_arg(&buf, chomp(s+1));
 				c->u.s.file = buf.u.file;
 				break;
 			}
-- 
2.7.1
Received on Sun Feb 14 2016 - 14:10:07 CET

This archive was generated by hypermail 2.3.0 : Sun Feb 14 2016 - 14:12:13 CET