Skip to content

Commit

Permalink
ed: simplify edSetCurrentLine() (#489)
Browse files Browse the repository at this point in the history
* Code can be reduced by checking for error instead of checking for success
* Style: consistently return 1 or 0 (return value is not currently checked)
  • Loading branch information
mknos committed Mar 9, 2024
1 parent 3182a26 commit 87d2885
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions bin/ed
Expand Up @@ -860,32 +860,25 @@ sub edQuit {
sub edSetCurrentLine {
if (defined($args[0])) {
edWarn(E_ARGEXT);
return;
return 0;
}

my $adr = $adrs[1];
if (!defined($adr)) {
$adr = $adrs[0];
}
if (defined($adr)) {

# user gave us a line, go to it
if ($adr <= maxline() && $adr > 0 && maxline() != 0) {
$CurrentLineNum = $adr;
} else {
if ($adr <= 0 || maxline() == 0 || $adr > maxline()) {
edWarn(E_ADDRBAD);
return 0;
}

$CurrentLineNum = $adr; # jump to specified line
} else {

# simply increment the line
if ($CurrentLineNum < maxline()) {
$CurrentLineNum++;
} else {
if ($CurrentLineNum == maxline()) {
edWarn(E_ADDRBAD);
return 0;
}
$CurrentLineNum++;
}

print $lines[$CurrentLineNum];
Expand Down

0 comments on commit 87d2885

Please sign in to comment.