aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2009-04-22 22:36:09 +1000
committerNguyễn Thái Ngọc Duy <pclouds@gmail.com>2009-04-23 04:44:39 +1000
commitba71eb646163b316b721e135818cb04932bfa39c (patch)
treec7f5b9d1975ed65d9b4dcf924066f1546198e00c
parent06f9649550cd02a17ce2ce4ad554dd4a4e7bb768 (diff)
downloadbusybox-w32-ba71eb646163b316b721e135818cb04932bfa39c.tar.gz
busybox-w32-ba71eb646163b316b721e135818cb04932bfa39c.tar.bz2
busybox-w32-ba71eb646163b316b721e135818cb04932bfa39c.zip
editors/sed: save the last regex for use later with s///
-rw-r--r--editors/sed.c11
1 files 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
830 830
831#define sed_puts(s, n) (puts_maybe_newline(s, G.nonstdout, &last_puts_char, n)) 831#define sed_puts(s, n) (puts_maybe_newline(s, G.nonstdout, &last_puts_char, n))
832 832
833static inline int beg_match(sed_cmd_t *sed_cmd, const char *pattern_space)
834{
835 int retval = sed_cmd->beg_match && !regexec(sed_cmd->beg_match, pattern_space, 0, NULL, 0);
836 if (retval)
837 G.previous_regex_ptr = sed_cmd->beg_match;
838 return retval;
839}
840
833/* Process all the lines in all the files */ 841/* Process all the lines in all the files */
834 842
835static void process_files(void) 843static void process_files(void)
@@ -874,8 +882,7 @@ restart:
874 /* Or did we match the start of a numerical range? */ 882 /* Or did we match the start of a numerical range? */
875 || (sed_cmd->beg_line > 0 && (sed_cmd->beg_line == linenum)) 883 || (sed_cmd->beg_line > 0 && (sed_cmd->beg_line == linenum))
876 /* Or does this line match our begin address regex? */ 884 /* Or does this line match our begin address regex? */
877 || (sed_cmd->beg_match && 885 || (beg_match(sed_cmd, pattern_space))
878 !regexec(sed_cmd->beg_match, pattern_space, 0, NULL, 0))
879 /* Or did we match last line of input? */ 886 /* Or did we match last line of input? */
880 || (sed_cmd->beg_line == -1 && next_line == NULL); 887 || (sed_cmd->beg_line == -1 && next_line == NULL);
881 888