Skip to content

Commit b05f44b

Browse files
authored
ed: implement ';' addressing mode
* ";" address by itself is taken to mean current address to end, i.e. ".,$" * "A1;A2" expression is the same as "A1,A2" * ";A2" expression works like ".,A2" * I tested the following combinations... ,p ---> all lines %p ---> all lines ;p ---> current line to end 1,p ---> only line 1 1%p ---> not supported 1;p ---> only line 1 1,2p ---> range 1-2 1%2p ---> not supported 1;2p ---> range 1-2 ,2p ---> range 1-2 %2n ---> range 1-2 ;20p ---> range current line to 20 (error if current>20)
1 parent 524062c commit b05f44b

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

bin/ed

+8-13
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ use Getopt::Std qw(getopts);
6262

6363
use constant A_NOMATCH => -1;
6464
use constant A_NOPAT => -2;
65-
use constant A_ALL => -3;
66-
use constant A_PATTERN => -4;
65+
use constant A_PATTERN => -3;
6766

6867
use constant E_ADDREXT => 'unexpected address';
6968
use constant E_ADDRBAD => 'invalid address';
@@ -110,7 +109,7 @@ my $NO_QUESTIONS_MODE = 0;
110109
my $PRINT_NUM = 1;
111110
my $PRINT_BIN = 2;
112111

113-
our $VERSION = '0.13';
112+
our $VERSION = '0.14';
114113

115114
my @ESC = (
116115
'\\000', '\\001', '\\002', '\\003', '\\004', '\\005', '\\006', '\\a',
@@ -917,16 +916,14 @@ sub edParse {
917916
if (defined($adrs[0]) && ($adrs[0] == A_NOPAT || $adrs[0] == A_NOMATCH)) {
918917
return 1;
919918
}
920-
if (defined($adrs[0]) && $adrs[0] == A_ALL) {
921-
$adrs[0] = 1;
922-
$adrs[1] = maxline();
923-
} elsif (s/\A,//) { # ',' and '%' cannot be combined
919+
if (s/\A([,;\%])//) {
920+
my $sep = $1;
921+
return 0 if $sep eq '%' && defined($adrs[0]);
924922
$adrs[1] = getAddr();
925-
if (defined($adrs[1]) && $adrs[1] < 0) {
926-
return 1;
927-
}
923+
return 1 if defined($adrs[1]) && $adrs[1] < 0;
924+
928925
unless (defined $adrs[0]) {
929-
$adrs[0] = 1;
926+
$adrs[0] = $sep eq ';' ? $CurrentLineNum : 1;
930927
$adrs[1] = maxline() unless defined $adrs[1];
931928
}
932929
}
@@ -977,8 +974,6 @@ sub getAddr {
977974
foreach my $c (split //, $1) {
978975
$n += $c eq '+' ? 1 : -1;
979976
}
980-
} elsif (s/\A\%//) {
981-
$n = A_ALL;
982977
} elsif (s/\A([0-9]+)//) { # '10' == 10
983978
$n = $1;
984979
} elsif (s/\A\.//) { # '.' == current line

0 commit comments

Comments
 (0)