From fb6adf65903095d3857e3f6cb868f6c5f906eb40 Mon Sep 17 00:00:00 2001 From: Michael Mikonos <127171689+mknos@users.noreply.github.com> Date: Sat, 7 Dec 2024 01:08:48 +0800 Subject: [PATCH] ed: standard exit code (#863) * 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 --- bin/ed | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/bin/ed b/bin/ed index a5cf3067..2e9ac6b1 100755 --- a/bin/ed +++ b/bin/ed @@ -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', @@ -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) { @@ -646,7 +651,7 @@ sub edWrite { $NeedToSave = $UserHasBeenWarned = 0; print "$chars\n" unless $Scripted; - exit EX_SUCCESS if $qflag; + exit getrc() if $qflag; return; } @@ -815,7 +820,7 @@ sub edQuit { $UserHasBeenWarned = 1; return E_UNSAVED; } - exit EX_SUCCESS; + exit getrc(); } # @@ -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