Skip to content

Commit

Permalink
Merge pull request #251 from mknos/ed-1c0
Browse files Browse the repository at this point in the history
ed: fix handling of bad command 1c0
  • Loading branch information
briandfoy authored Sep 19, 2023
2 parents 86c4a47 + f8fee45 commit 172702d
Showing 1 changed file with 52 additions and 13 deletions.
65 changes: 52 additions & 13 deletions bin/ed
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,10 @@ while (1) {
} elsif ($command eq 'a') {
&edInsert($APPEND_MODE);
} elsif ($command eq 'c') {
&edDelete;
$adrs[1] = undef;
&edInsert($INSERT_MODE);
if (edDelete()) {
$adrs[1] = undef;
edInsert($INSERT_MODE);
}
} elsif ($command eq 's') {
&edSubstitute;

Expand All @@ -260,22 +261,15 @@ while (1) {
} elsif ($command eq 'p') {
&edPrint;
} elsif ($command eq 'P') {
if (defined $Prompt) {
$Prompt = undef;
} else {
$Prompt = defined $opt{'p'} ? $opt{'p'} : '*';
}
edPrompt();
} elsif ($command =~ /^q$/) {
&edQuit($QUESTIONS_MODE);
} elsif ($command =~ /^Q$/) {
&edQuit($NO_QUESTIONS_MODE);
} elsif ($command eq 'h') {
print("$Error\n") if (defined $Error);
edHelp();
} elsif ($command eq 'H') {
$EXTENDED_MESSAGES ^= 1;
if ($EXTENDED_MESSAGES && defined $Error) {
print "$Error\n";
}
edHelp(1);
} elsif ($command eq 'j') {
&edJoin;
} elsif ($command eq 'l') {
Expand Down Expand Up @@ -303,6 +297,42 @@ sub maxline {
return $n;
}

sub edPrompt {
if (defined $adrs[0]) {
edWarn('Too many addressses');
return;
}
if (defined $args[0]) {
edWarn('Extra arguments detected');
return;
}
if (defined $Prompt) {
$Prompt = undef;
} else {
$Prompt = defined $opt{'p'} ? $opt{'p'} : '*';
}
}

sub edHelp {
my $toggle = shift;

if (defined $adrs[0]) {
edWarn('Too many addressses');
return;
}
if (defined $args[0]) {
edWarn('Extra arguments detected');
return;
}
if ($toggle) {
$EXTENDED_MESSAGES ^= 1;
return unless $EXTENDED_MESSAGES;
}
if (defined $Error) {
print "$Error\n";
}
}

#
# Print contents of requested lines
#
Expand Down Expand Up @@ -519,6 +549,10 @@ sub edDelete {
edWarn('invalid address');
return;
}
if (defined $args[0]) {
edWarn('Extra arguments detected');
return;
}

my $NumLines = $adrs[1]-$adrs[0]+1;

Expand All @@ -531,6 +565,7 @@ sub edDelete {
if ($CurrentLineNum > maxline()) {
$CurrentLineNum = maxline();
}
return 1;
}

#
Expand Down Expand Up @@ -834,6 +869,10 @@ sub edPrintLineNum {
sub edQuit {
my($QuestionMode) = @_;

if (defined $adrs[0]) {
edWarn('Too many addressses');
return;
}
if (defined($args[0])) {
edWarn('Extra arguments detected');
return;
Expand Down

0 comments on commit 172702d

Please sign in to comment.