Skip to content

Commit

Permalink
ed: 1s/pat1/pat2/ incorrectly processes multiple lines (#441)
Browse files Browse the repository at this point in the history
* ed: 1s/pat1/pat2/ incorrectly processes multiple lines

* If current line is 10, and I enter 1s/e/E/, the substitution was occurring for lines 1-10 instead of just line 1
* If I want substitution on lines 1-10 I'm supposed to type 1,10s/e/E/
* If I only want to substitute on the current line I omit the addresses and type s/e/E/
* Patch is based on existing behaviour of edPrint()
* When searching for assignments of $adrs[1] I didn't find any more instances where it's set to current line

* fix h command

* more correct to check both addresses
  • Loading branch information
mknos authored Feb 7, 2024
1 parent 525bc32 commit bc9de7f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions bin/ed
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ sub edHelp {
if ($toggle) {
$EXTENDED_MESSAGES ^= 1;
}
if ($EXTENDED_MESSAGES && defined($Error)) {
if (defined($Error) && ($EXTENDED_MESSAGES || !$toggle)) {
print "$Error\n";
}
}
Expand Down Expand Up @@ -499,8 +499,12 @@ sub edSubstitute {
# parse args

$adrs[0] = $CurrentLineNum unless (defined($adrs[0]));
$adrs[1] = $CurrentLineNum unless (defined($adrs[1]));
$adrs[1] = $adrs[0] unless (defined $adrs[1]);

if ($adrs[0] == 0 || $adrs[1] == 0) {
edWarn(E_ADDRBAD);
return;
}
unless (defined($args[0])) {
edWarn(E_PATTERN);
return;
Expand Down

0 comments on commit bc9de7f

Please sign in to comment.