I'm not really get into sed source code, so I might be wrong. Please recheck it.
With this patch, the following command should return 'abc' (GNU sed
does but busybox did not):
echo 'URL: abc'|busybox sed -ne '/^URL: */{ s///p; q }'
-- 
Duy
diff --git a/box/editors/sed.c b/box/editors/sed.c
index d49627f..b621844 100644
--- a/box/editors/sed.c
+++ b/box/editors/sed.c
@@ -830,6 +830,14 @@ static void puts_maybe_newline(char *s, FILE *file, char *last_puts_char, char l
 
 #define sed_puts(s, n) (puts_maybe_newline(s, G.nonstdout, &last_puts_char, n))
 
+static inline int beg_match(sed_cmd_t *sed_cmd, const char *pattern_space)
+{
+	int retval = sed_cmd->beg_match && !regexec(sed_cmd->beg_match, pattern_space, 0, NULL, 0);
+	if (retval)
+		G.previous_regex_ptr = sed_cmd->beg_match;
+	return retval;
+}
+
 /* Process all the lines in all the files */
 
 static void process_files(void)
@@ -874,8 +882,7 @@ restart:
 			/* Or did we match the start of a numerical range? */
 			|| (sed_cmd->beg_line > 0 && (sed_cmd->beg_line == linenum))
 			/* Or does this line match our begin address regex? */
-			|| (sed_cmd->beg_match &&
-			    !regexec(sed_cmd->beg_match, pattern_space, 0, NULL, 0))
+			|| (beg_match(sed_cmd, pattern_space))
 			/* Or did we match last line of input? */
 			|| (sed_cmd->beg_line == -1 && next_line == NULL);
 
-- 
1.5.2.2

_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to