Skip to content

Commit

Permalink
ed: standard exit code (#863)
Browse files Browse the repository at this point in the history
* When running an ed script the exit code is important
* If any command in the script fails, edWarn() will be called and $Error will be set; this should translate to a failure exit code
* Tested against GNU version

#test1: q command after invalid address error
470
*H
*100p
?
invalid address
*10p
	/* this? */
*q
%echo $?
1

#test2: wq command after invalid address error
470
*H
*100p
?
invalid address
*1,2wq new.txt
39
%echo $?
1
  • Loading branch information
mknos authored Dec 6, 2024
1 parent bc0c5d5 commit fb6adf6
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions bin/ed
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ my $NO_QUESTIONS_MODE = 0;
my $PRINT_NUM = 1;
my $PRINT_BIN = 2;

our $VERSION = '0.20';
our $VERSION = '0.21';

my @ESC = (
'\\000', '\\001', '\\002', '\\003', '\\004', '\\005', '\\006', '\\a',
Expand Down Expand Up @@ -275,6 +275,11 @@ sub maxline {
return $n;
}

sub getrc {
return EX_FAILURE if defined $Error;
return EX_SUCCESS;
}

sub edChangeLines {
my $err = edDelete();
unless ($err) {
Expand Down Expand Up @@ -646,7 +651,7 @@ sub edWrite {

$NeedToSave = $UserHasBeenWarned = 0;
print "$chars\n" unless $Scripted;
exit EX_SUCCESS if $qflag;
exit getrc() if $qflag;
return;
}

Expand Down Expand Up @@ -815,7 +820,7 @@ sub edQuit {
$UserHasBeenWarned = 1;
return E_UNSAVED;
}
exit EX_SUCCESS;
exit getrc();
}

#
Expand Down Expand Up @@ -1240,6 +1245,16 @@ Display current line number
=back
=head1 EXIT STATUS
=over 4
=item * 0 - All commands were processed successfully
=item * 1 - An error occurred
=back
=head1 AUTHOR
Written by George M Jones
Expand Down

0 comments on commit fb6adf6

Please sign in to comment.