aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-08-23 17:56:03 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-08-23 17:56:03 +0200
commit9c47c43e07365abe1eda02d69572b9e579b49cec (patch)
tree00d5d88812ecf1eddc37f2112e9cf4ae57e2570c
parent8b77a9ea81a0bd89ee69e7742d9b920dd1562763 (diff)
downloadbusybox-w32-9c47c43e07365abe1eda02d69572b9e579b49cec.tar.gz
busybox-w32-9c47c43e07365abe1eda02d69572b9e579b49cec.tar.bz2
busybox-w32-9c47c43e07365abe1eda02d69572b9e579b49cec.zip
sed: in '/regexp/cmd1;//cmd2', cmd2 should use the same regexp as cmd1
function old new delta get_address 165 211 +46 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/sed.c14
-rwxr-xr-xtestsuite/sed.tests6
2 files changed, 16 insertions, 4 deletions
diff --git a/editors/sed.c b/editors/sed.c
index 3fc40ceef..7ed9937d2 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -350,10 +350,16 @@ static int get_address(const char *my_str, int *linenum, regex_t ** regex)
350 if (*my_str == '\\') 350 if (*my_str == '\\')
351 delimiter = *++pos; 351 delimiter = *++pos;
352 next = index_of_next_unescaped_regexp_delim(delimiter, ++pos); 352 next = index_of_next_unescaped_regexp_delim(delimiter, ++pos);
353 temp = copy_parsing_escapes(pos, next); 353 if (next != 0) {
354 *regex = xzalloc(sizeof(regex_t)); 354 temp = copy_parsing_escapes(pos, next);
355 xregcomp(*regex, temp, G.regex_type); 355 G.previous_regex_ptr = *regex = xzalloc(sizeof(regex_t));
356 free(temp); 356 xregcomp(*regex, temp, G.regex_type);
357 free(temp);
358 } else {
359 *regex = G.previous_regex_ptr;
360 if (!G.previous_regex_ptr)
361 bb_error_msg_and_die("no previous regexp");
362 }
357 /* Move position to next character after last delimiter */ 363 /* Move position to next character after last delimiter */
358 pos += (next+1); 364 pos += (next+1);
359 } 365 }
diff --git a/testsuite/sed.tests b/testsuite/sed.tests
index 05c00a99b..675cb4f10 100755
--- a/testsuite/sed.tests
+++ b/testsuite/sed.tests
@@ -387,6 +387,12 @@ testing "sed 's///w FILE'" \
387 "" \ 387 "" \
388 "123\nqwe\nasd\n" 388 "123\nqwe\nasd\n"
389 389
390testing "sed uses previous regexp" \
391 "sed '/w/p;//q'" \
392 "q\nw\nw\n" \
393 "" \
394 "q\nw\ne\nr\n"
395
390# testing "description" "commands" "result" "infile" "stdin" 396# testing "description" "commands" "result" "infile" "stdin"
391 397
392exit $FAILCOUNT 398exit $FAILCOUNT