A.15 The Package Command_Line
The package Command_Line allows a program to obtain
the values of its arguments and to set the exit status code to be returned
on normal termination.
Static Semantics
The library package
Ada.Command_Line has the following declaration:
package Ada.Command_Line
is
pragma Preelaborate(Command_Line);
function Argument_Count
return Natural;
function Argument (Number :
in Positive)
return String;
function Command_Name
return String;
type Exit_Status
is implementation-defined integer type;
Success :
constant Exit_Status;
Failure :
constant Exit_Status;
procedure Set_Exit_Status (Code :
in Exit_Status);
private
... -- not specified by the language
end Ada.Command_Line;
function Argument_Count return Natural;
If the external
execution environment supports passing arguments to a program, then Argument_Count
returns the number of arguments passed to the program invoking the function.
Otherwise it returns 0. The meaning of “number of arguments”
is implementation defined.
function Argument (Number : in Positive) return String;
If the external
execution environment supports passing arguments to a program, then Argument
returns an implementation-defined value corresponding to the argument
at relative position Number.
If Number is outside
the range 1..Argument_Count, then Constraint_Error is propagated.
function Command_Name return String;
If the external
execution environment supports passing arguments to a program, then Command_Name
returns an implementation-defined value corresponding to the name of
the command invoking the program; otherwise Command_Name returns the
null string.
type Exit_Status is implementation-defined integer type;
The type Exit_Status
represents the range of exit status values supported by the external
execution environment. The constants Success and Failure correspond to
success and failure, respectively.
procedure Set_Exit_Status (Code : in Exit_Status);
If the external execution environment supports
returning an exit status from a program, then Set_Exit_Status sets Code
as the status. Normal termination of a program returns as the exit status
the value most recently set by Set_Exit_Status, or, if no such value
has been set, then the value Success. If a program terminates abnormally,
the status set by Set_Exit_Status is ignored, and an implementation-defined
exit status value is set.
If the external execution environment does not
support returning an exit value from a program, then Set_Exit_Status
does nothing.
Implementation Permissions
An alternative declaration is allowed for package
Command_Line if different functionality is appropriate for the external
execution environment.
36 Argument_Count, Argument, and Command_Name
correspond to the C language's argc, argv[n] (for n>0) and argv[0],
respectively.