From: stefan-lucks@see-the.signature
Subject: Re: How to exit an Ada program with (unix shell) error code?
Date: Mon, 4 May 2009 12:07:47 +0200
Date: 2009-05-04T12:07:47+02:00 [thread overview]
Message-ID: <Pine.LNX.4.64.0905041147510.22185@medsec1.medien.uni-weimar.de> (raw)
In-Reply-To: <10acae13-98dc-48da-9de4-9c01ea07abd4@g19g2000vbi.googlegroups.com>
On Mon, 4 May 2009, Ludovic Brenta wrote:
> reinkor wrote on comp.lang.ada:
> > Thanks, but how I terminate the program in a "natural" way
> > (without using goto or "raise exception") ?
>
> Simply allow the execution to reach the "end;" of the main subprogram.
>
> with Ada.Command_Line;
> procedure Exit_With_False is
> begin
> Ada.Command_Line.Set_Exit_Status (1); -- False, in shell terms
Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
> end Exit_With_False; -- nothing else required
I believe, it is preferable to use the predefined constants "Success" and
"Failure" in Ada.Command line:
1. If you port your program to another (i.e. non-unix) system,
it is not clear that "1" maintains the logical value "False".
(Perhaps the RM is clear about that -- I didn't check ...)
2. Without the comment "-- False, in shell terms", many readers
(except for unix-shell experts, of course) would rather expect
Ada.Command_Line.Set_Exit_Status (1);
to indicate a positive result ("True"), rather then "False".
Here is a slightly larger example:
with Ada.Command_Line;
procedure False_If_No_Arguments is
package ACL renames Ada.Command_Line;
begin
if ACL.Argument_Count > 0 then
ACL.Set_Exit_Status (ACL.Success);
else
ACL.Set_Exit_Status (ACL.Failure);
end if;
end False_If_No_Arguments;
P.S.: (As you see, you can indicate either a positive or a negative
outcome without ever having to raise an exception ...)
--
------ Stefan Lucks -- Bauhaus-University Weimar -- Germany ------
Stefan dot Lucks at uni minus weimar dot de
------ I love the taste of Cryptanalysis in the morning! ------
next prev parent reply other threads:[~2009-05-04 10:07 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-04 9:08 How to exit an Ada program with (unix shell) error code? reinkor
2009-05-04 9:17 ` Samuel Tardieu
2009-05-04 9:26 ` reinkor
2009-05-04 9:31 ` Ludovic Brenta
2009-05-04 9:47 ` reinkor
2009-05-04 9:54 ` Martin
2009-05-04 11:38 ` sjw
2009-05-04 10:07 ` stefan-lucks [this message]
2009-05-04 13:42 ` Robert A Duff
2009-05-04 16:19 ` Martin
2009-05-07 9:48 ` anon
2009-05-04 16:09 ` anon
2009-05-05 10:49 ` Rob Norris
2009-05-05 11:15 ` Georg Bauhaus
2009-05-05 11:43 ` Martin
2009-05-05 14:57 ` Adam Beneschan
2009-05-05 15:34 ` Jean-Pierre Rosen
2009-05-06 15:28 ` Adam Beneschan
2009-05-06 22:10 ` Randy Brukardt
2009-05-07 9:08 ` anon
2009-05-07 10:01 ` Georg Bauhaus
2009-05-07 11:22 ` anon
2009-05-07 12:08 ` Martin
2009-05-07 13:34 ` Georg Bauhaus
2009-05-07 16:26 ` Adam Beneschan
2009-05-08 10:17 ` anon
2009-05-12 22:55 ` Adam Beneschan
2009-05-14 2:55 ` anon
2009-05-14 8:04 ` Martin
2009-05-14 8:39 ` Martin
2009-05-14 8:45 ` Martin
2009-05-14 9:34 ` Ludovic Brenta
2009-05-14 10:05 ` Martin
2009-05-14 12:38 ` Georg Bauhaus
2009-05-14 15:34 ` Adam Beneschan
2009-05-15 10:20 ` anon
2009-05-15 11:19 ` Martin
2009-05-05 20:48 ` anon
2009-05-05 21:01 ` Adam Beneschan
2009-05-06 11:30 ` Hibou57 (Yannick Duchêne)
2009-05-05 20:31 ` anon
2009-05-05 21:27 ` Martin
2009-05-06 8:41 ` anon
2009-05-06 9:14 ` Martin
2009-05-06 11:41 ` Georg Bauhaus
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox