Skip to content

Commit 7ed0b25

Browse files
authored
ed: clean some redundant code (#437)
* In edMove(), special code isn't needed for $count of one because the .. operator can handle 1..1 * edPrint() already relies on this because it loops with "$adrs[0] .. $adrs[1]", where both can be equal * Tested with command "1m20" to move the 1st line in buffer ($end is inferred from $start) * Remove chmod() comment in edWrite(); OpenBSD version does not perform chmod() and that is a better reference * Standards document mentions nothing about changing file modes/permissions[1] * In edHelp() the saved error will be printed each time the "H" command enables the help flag; avoid extra return statement 1. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ed.html
1 parent 15f7f71 commit 7ed0b25

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

bin/ed

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,8 @@ sub edHelp {
324324
}
325325
if ($toggle) {
326326
$EXTENDED_MESSAGES ^= 1;
327-
return unless $EXTENDED_MESSAGES;
328327
}
329-
if (defined $Error) {
328+
if ($EXTENDED_MESSAGES && defined($Error)) {
330329
print "$Error\n";
331330
}
332331
}
@@ -475,12 +474,7 @@ sub edMove {
475474
}
476475

477476
my $count = $end - $start + 1;
478-
my @copy;
479-
if ($count == 1) {
480-
push @copy, $lines[$start];
481-
} else {
482-
@copy = @lines[$start .. $end];
483-
}
477+
my @copy = @lines[$start .. $end];
484478
if ($start > $dst && $end > $dst) {
485479
splice(@lines, $start, $count) if $delete;
486480
splice @lines, $dst + 1, 0, @copy;
@@ -653,9 +647,6 @@ sub edWrite {
653647
$UserHasBeenWarned = 0;
654648
print "$chars\n" unless ($SupressCounts);
655649

656-
# v7 docs say to chmod 666 the file ... we're not going to
657-
# follow the docs *that* closely today (6/16/99 ---gmj)
658-
659650
if ($qflag) {
660651
exit 0;
661652
}

0 commit comments

Comments
 (0)