From ba71eb646163b316b721e135818cb04932bfa39c Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Wed, 22 Apr 2009 22:36:09 +1000 Subject: editors/sed: save the last regex for use later with s/// --- editors/sed.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/editors/sed.c b/editors/sed.c index d49627ff4..b6218446f 100644 --- a/editors/sed.c +++ b/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); -- cgit v1.2.3-55-g6feb