diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2003-09-13 06:57:39 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2003-09-13 06:57:39 +0000 |
commit | c18ce373a21f72b23259c9c15503ac8800d605c7 (patch) | |
tree | 4cfed64c2642b0aed4214dbbc6216eda1c3c51ea | |
parent | c2b9186be16e71a2fc5c4f05346a876a30bfbd16 (diff) | |
download | busybox-w32-c18ce373a21f72b23259c9c15503ac8800d605c7.tar.gz busybox-w32-c18ce373a21f72b23259c9c15503ac8800d605c7.tar.bz2 busybox-w32-c18ce373a21f72b23259c9c15503ac8800d605c7.zip |
Fix the following testcase by storing the state of the adress match with
the command.
# cat strings
a
b
c
d
e
f
g
# ./busybox sed '1,2d;4,$d' <strings
c
# ./busybox sed '4,$d;1,2d' <strings
# sed '4,$d;1,2d' <strings
c
# sed '1,2d;4,$d' <strings
c
-rw-r--r-- | editors/sed.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/editors/sed.c b/editors/sed.c index b06d5a8d8..5bfe924a5 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -75,6 +75,9 @@ typedef struct sed_cmd_s { | |||
75 | int invert; /* the '!' after the address */ | 75 | int invert; /* the '!' after the address */ |
76 | // int block_cmd; /* This command is part of a group that has a command address */ | 76 | // int block_cmd; /* This command is part of a group that has a command address */ |
77 | 77 | ||
78 | /* Runtime flag no not if the current command match's */ | ||
79 | int still_in_range; | ||
80 | |||
78 | /* SUBSTITUTION COMMAND SPECIFIC FIELDS */ | 81 | /* SUBSTITUTION COMMAND SPECIFIC FIELDS */ |
79 | 82 | ||
80 | /* sed -e 's/sub_match/replace/' */ | 83 | /* sed -e 's/sub_match/replace/' */ |
@@ -491,7 +494,7 @@ static char *parse_cmd_str(sed_cmd_t * sed_cmd, char *cmdstr) | |||
491 | return (cmdstr); | 494 | return (cmdstr); |
492 | } | 495 | } |
493 | 496 | ||
494 | static char *add_cmd(sed_cmd_t * sed_cmd, char *cmdstr) | 497 | static char *add_cmd(sed_cmd_t *sed_cmd, char *cmdstr) |
495 | { | 498 | { |
496 | /* Skip over leading whitespace and semicolons */ | 499 | /* Skip over leading whitespace and semicolons */ |
497 | cmdstr += strspn(cmdstr, semicolon_whitespace); | 500 | cmdstr += strspn(cmdstr, semicolon_whitespace); |
@@ -793,7 +796,6 @@ static void process_file(FILE * file) | |||
793 | char *pattern_space; /* Posix requires it be able to hold at least 8192 bytes */ | 796 | char *pattern_space; /* Posix requires it be able to hold at least 8192 bytes */ |
794 | char *hold_space = NULL; /* Posix requires it be able to hold at least 8192 bytes */ | 797 | char *hold_space = NULL; /* Posix requires it be able to hold at least 8192 bytes */ |
795 | static int linenum = 0; /* GNU sed does not restart counting lines at EOF */ | 798 | static int linenum = 0; /* GNU sed does not restart counting lines at EOF */ |
796 | unsigned int still_in_range = 0; | ||
797 | int altered; | 799 | int altered; |
798 | int force_print; | 800 | int force_print; |
799 | 801 | ||
@@ -836,7 +838,7 @@ static void process_file(FILE * file) | |||
836 | && (regexec(sed_cmd->beg_match, pattern_space, 0, NULL, | 838 | && (regexec(sed_cmd->beg_match, pattern_space, 0, NULL, |
837 | 0) == 0)) || | 839 | 0) == 0)) || |
838 | /* we are currently within the beginning & ending address range */ | 840 | /* we are currently within the beginning & ending address range */ |
839 | still_in_range || ((sed_cmd->beg_line == -1) | 841 | sed_cmd->still_in_range || ((sed_cmd->beg_line == -1) |
840 | && (next_line == NULL)) | 842 | && (next_line == NULL)) |
841 | ); | 843 | ); |
842 | if (sed_cmd->cmd == '{') { | 844 | if (sed_cmd->cmd == '{') { |
@@ -1077,7 +1079,7 @@ static void process_file(FILE * file) | |||
1077 | /* If only one address */ | 1079 | /* If only one address */ |
1078 | /* we were in the middle of our address range (this | 1080 | /* we were in the middle of our address range (this |
1079 | * isn't the first time through) and.. */ | 1081 | * isn't the first time through) and.. */ |
1080 | || ((still_in_range == 1) | 1082 | || ((sed_cmd->still_in_range == 1) |
1081 | /* this line number is the last address we're looking for or... */ | 1083 | /* this line number is the last address we're looking for or... */ |
1082 | && ((sed_cmd->end_line > 0 | 1084 | && ((sed_cmd->end_line > 0 |
1083 | && (sed_cmd->end_line == linenum)) | 1085 | && (sed_cmd->end_line == linenum)) |
@@ -1086,10 +1088,10 @@ static void process_file(FILE * file) | |||
1086 | && (regexec(sed_cmd->end_match, pattern_space, | 1088 | && (regexec(sed_cmd->end_match, pattern_space, |
1087 | 0, NULL, 0) == 0))))) { | 1089 | 0, NULL, 0) == 0))))) { |
1088 | /* we're out of our address range */ | 1090 | /* we're out of our address range */ |
1089 | still_in_range = 0; | 1091 | sed_cmd->still_in_range = 0; |
1090 | } else { | 1092 | } else { |
1091 | /* didn't hit the exit? then we're still in the middle of an address range */ | 1093 | /* didn't hit the exit? then we're still in the middle of an address range */ |
1092 | still_in_range = 1; | 1094 | sed_cmd->still_in_range = 1; |
1093 | } | 1095 | } |
1094 | } | 1096 | } |
1095 | 1097 | ||