aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-07-14 01:02:57 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-07-14 01:02:57 +0200
commit8e96b5b5314c3f2c3fdb6fd04abfa3e73ac27a5a (patch)
tree52a023e31acf6314c2a7ce8d5d3a807b31781298
parent2907e7974924e7e8f1a64874b5c3cb48ebd25d5d (diff)
downloadbusybox-w32-8e96b5b5314c3f2c3fdb6fd04abfa3e73ac27a5a.tar.gz
busybox-w32-8e96b5b5314c3f2c3fdb6fd04abfa3e73ac27a5a.tar.bz2
busybox-w32-8e96b5b5314c3f2c3fdb6fd04abfa3e73ac27a5a.zip
sed: simpler fix for recent GNU compat stuff (by Rob Landley)
function old new delta process_files 2120 2102 -18 Signed-off-by: Rob Landley <rob@landley.net> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/sed.c37
1 files changed, 14 insertions, 23 deletions
diff --git a/editors/sed.c b/editors/sed.c
index ed12e4336..de18996b8 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -888,53 +888,44 @@ static void process_files(void)
888 old_matched = sed_cmd->in_match; 888 old_matched = sed_cmd->in_match;
889 889
890 /* Determine if this command matches this line: */ 890 /* Determine if this command matches this line: */
891 /* Are we continuing a previous multi-line match? */ 891
892 /* Are we continuing a previous multi-line match? */
892 sed_cmd->in_match = sed_cmd->in_match 893 sed_cmd->in_match = sed_cmd->in_match
893 /* Or is no range necessary? */ 894 /* Or is no range necessary? */
894 || (!sed_cmd->beg_line && !sed_cmd->end_line 895 || (!sed_cmd->beg_line && !sed_cmd->end_line
895 && !sed_cmd->beg_match && !sed_cmd->end_match) 896 && !sed_cmd->beg_match && !sed_cmd->end_match)
896 /* Or did we match the start of a numerical range? */ 897 /* Or did we match the start of a numerical range? */
897 || (sed_cmd->beg_line > 0 898 || (sed_cmd->beg_line > 0 && (sed_cmd->beg_line <= linenum))
898 && (sed_cmd->beg_line == linenum
899 /* GNU sed compat:
900 * "shadowed beginning" case: "1d;1,ENDp" - p still matches at line 2
901 * even though 1d skipped line 1 which is a start line for p */
902 || (sed_cmd->beg_line < linenum && (sed_cmd->end_line > 0 || sed_cmd->end_match))
903 )
904 )
905 /* Or does this line match our begin address regex? */ 899 /* Or does this line match our begin address regex? */
906 || (beg_match(sed_cmd, pattern_space)) 900 || (beg_match(sed_cmd, pattern_space))
907 /* Or did we match last line of input? */ 901 /* Or did we match last line of input? */
908 || (sed_cmd->beg_line == -1 && next_line == NULL); 902 || (sed_cmd->beg_line == -1 && next_line == NULL);
909 903
904 /* Snapshot the value */
910 matched = sed_cmd->in_match; 905 matched = sed_cmd->in_match;
911 906
912 //bb_error_msg("cmd:'%c' matched:%d beg_line:%d end_line:%d linenum:%d", 907 //bb_error_msg("cmd:'%c' matched:%d beg_line:%d end_line:%d linenum:%d",
913 //sed_cmd->cmd, matched, sed_cmd->beg_line, sed_cmd->end_line, linenum); 908 //sed_cmd->cmd, matched, sed_cmd->beg_line, sed_cmd->end_line, linenum);
914 909
915 /* Is this line the end of the current match? */ 910 /* Is this line the end of the current match? */
911
916 if (matched) { 912 if (matched) {
917 int n = ( 913 /* once matched, "n,xxx" range is dead, disabling it */
914 if (sed_cmd->beg_line > 0)
915 sed_cmd->beg_line = -2;
916 sed_cmd->in_match = !(
918 /* has the ending line come, or is this a single address command? */ 917 /* has the ending line come, or is this a single address command? */
919 sed_cmd->end_line ? 918 (sed_cmd->end_line ?
920 sed_cmd->end_line == -1 ? 919 sed_cmd->end_line == -1 ?
921 !next_line 920 !next_line
922 : (sed_cmd->end_line <= linenum) 921 : (sed_cmd->end_line <= linenum)
923 : !sed_cmd->end_match 922 : !sed_cmd->end_match
924 ); 923 )
925 if (!n) {
926 /* or does this line matches our last address regex */ 924 /* or does this line matches our last address regex */
927 n = (sed_cmd->end_match 925 || (sed_cmd->end_match && old_matched
928 && old_matched
929 && (regexec(sed_cmd->end_match, 926 && (regexec(sed_cmd->end_match,
930 pattern_space, 0, NULL, 0) == 0) 927 pattern_space, 0, NULL, 0) == 0))
931 ); 928 );
932 }
933 if (n && sed_cmd->beg_line > 0) {
934 /* once matched, "n,xxx" range is dead, disabling it */
935 sed_cmd->beg_line = -2;
936 }
937 sed_cmd->in_match = !n;
938 } 929 }
939 930
940 /* Skip blocks of commands we didn't match */ 931 /* Skip blocks of commands we didn't match */