| 1 |
@comment{ $Source: e:\\cvsroot/ARM/Source/pre_cmdln.mss,v $ } |
| 2 |
@comment{ $Revision: 1.24 $ $Date: 2005/10/31 17:34:29 $ $Author: Randy $ } |
| 3 |
@Part(predefcmdln, Root="ada.mss") |
| 4 |
|
| 5 |
@Comment{$Date: 2005/10/31 17:34:29 $} |
| 6 |
@LabeledClause{The Package Command_Line} |
| 7 |
@begin{Intro} |
| 8 |
The package Command_Line allows a program to obtain the values of its |
| 9 |
arguments and to set the exit status code to be returned on normal termination. |
| 10 |
@ChgImplDef{Version=[2],Kind=[Revised],Text=[The meaning of Argument_Count, |
| 11 |
Argument, and Command_Name@Chg{Version=[2],New=[ for package Command_Line. The |
| 12 |
bounds of type Command_Line.Exit_Status],Old=[]}.]} |
| 13 |
@end{Intro} |
| 14 |
|
| 15 |
@begin{StaticSem} |
| 16 |
@Leading@Keepnext@;The library package Ada.Command_Line has the following declaration: |
| 17 |
@begin{Example} |
| 18 |
@key[package] Ada.Command_Line @key[is]@ChildUnit{Parent=[Ada],Child=[Command_Line]} |
| 19 |
@key[pragma] Preelaborate(Command_Line); |
| 20 |
|
| 21 |
@key[function] @AdaSubDefn{Argument_Count} @key[return] Natural; |
| 22 |
|
| 23 |
@key[function] @AdaSubDefn{Argument} (Number : @key[in] Positive) @key[return] String; |
| 24 |
|
| 25 |
@key[function] @AdaSubDefn{Command_Name} @key[return] String; |
| 26 |
|
| 27 |
@key[type] @AdaTypeDefn{Exit_Status} @key[is] @RI{implementation-defined integer type}; |
| 28 |
|
| 29 |
@AdaObjDefn{Success} : @key[constant] Exit_Status; |
| 30 |
@AdaObjDefn{Failure} : @key[constant] Exit_Status; |
| 31 |
|
| 32 |
@key[procedure] @AdaSubDefn{Set_Exit_Status} (Code : @key[in] Exit_Status); |
| 33 |
|
| 34 |
@key[private] |
| 35 |
... -- @RI{not specified by the language} |
| 36 |
@key[end] Ada.Command_Line; |
| 37 |
@comment{Blank line} |
| 38 |
@end{example} |
| 39 |
@begin{DescribeCode} |
| 40 |
@begin{Example}@Keepnext |
| 41 |
@key[function] Argument_Count @key[return] Natural; |
| 42 |
@end{Example} |
| 43 |
@Trailing@;If the external execution environment supports passing arguments to |
| 44 |
a program, then |
| 45 |
Argument_Count returns |
| 46 |
the number of arguments passed to the program |
| 47 |
invoking the function. Otherwise it returns 0. |
| 48 |
The meaning of @lquotes@;number of arguments@rquotes@; is implementation defined. |
| 49 |
|
| 50 |
@begin{Example}@Keepnext |
| 51 |
@key[function] Argument (Number : @key[in] Positive) @key[return] String; |
| 52 |
@end{Example} |
| 53 |
@Trailing@;If the external execution environment supports passing arguments to |
| 54 |
a program, then |
| 55 |
Argument returns an implementation-defined value corresponding to |
| 56 |
the argument at relative position Number. |
| 57 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 58 |
If Number is outside the range 1..Argument_Count, then |
| 59 |
Constraint_Error is propagated. |
| 60 |
@begin{Ramification} |
| 61 |
If the external execution environment does not support |
| 62 |
passing arguments to a program, then Argument(N) for any N will |
| 63 |
raise Constraint_Error, since Argument_Count is 0.@end{ramification} |
| 64 |
|
| 65 |
@begin{Example}@Keepnext |
| 66 |
@key[function] Command_Name @key[return] String; |
| 67 |
@end{Example} |
| 68 |
@Trailing@;If the external execution environment supports passing arguments to |
| 69 |
a program, then |
| 70 |
Command_Name returns an implementation-defined value corresponding to |
| 71 |
the name of the command invoking the program; |
| 72 |
otherwise Command_Name returns the null string. |
| 73 |
|
| 74 |
@Comment{This is missing; leading the following paragraph glued to "Command_Name"} |
| 75 |
@begin{Example}@Keepnext |
| 76 |
@ChgRef{Version=[1],Kind=[Added]} |
| 77 |
@Chg{New=[@key[type] Exit_Status @key[is] @RI{implementation-defined integer type};],Old=[]} |
| 78 |
@end{Example} |
| 79 |
@Trailing@; |
| 80 |
The type Exit_Status represents the range of exit |
| 81 |
status values supported by the external execution environment. |
| 82 |
The constants Success and Failure correspond to success and failure, |
| 83 |
respectively. |
| 84 |
|
| 85 |
@begin{Example}@Keepnext |
| 86 |
@key[procedure] Set_Exit_Status (Code : @key[in] Exit_Status); |
| 87 |
@end{Example} |
| 88 |
If the external execution environment supports returning an exit status |
| 89 |
from a program, then Set_Exit_Status sets Code as the status. Normal |
| 90 |
termination of a program returns as the exit status the value most |
| 91 |
recently set by Set_Exit_Status, or, if no such value has been set, then the |
| 92 |
value Success. If a program terminates abnormally, the status set by |
| 93 |
Set_Exit_Status is ignored, and an implementation-defined exit status value |
| 94 |
is set. |
| 95 |
|
| 96 |
@ChgNote{An incorrect index entry; presentation AI-00005} |
| 97 |
@Chg{New=[],Old=[@PDefn{unspecified}]} |
| 98 |
If the external execution environment does not support returning |
| 99 |
an exit value from a program, then Set_Exit_Status does nothing. |
| 100 |
@end{DescribeCode} |
| 101 |
@end{StaticSem} |
| 102 |
|
| 103 |
@begin{ImplPerm} |
| 104 |
An alternative declaration is allowed |
| 105 |
for package Command_Line if different functionality is appropriate |
| 106 |
for the external execution environment. |
| 107 |
@end{ImplPerm} |
| 108 |
|
| 109 |
|
| 110 |
@begin{Notes} |
| 111 |
Argument_Count, Argument, and Command_Name |
| 112 |
correspond to the C language's argc, argv[n] (for n>0) and argv[0], |
| 113 |
respectively. |
| 114 |
@begin{Honest} |
| 115 |
The correspondence of Argument_Count to argc is not direct @em |
| 116 |
argc would be one more than Argument_Count, since the argc count |
| 117 |
includes the command name, whereas Argument_Count does not. |
| 118 |
@end{Honest} |
| 119 |
@end{Notes} |
| 120 |
|
| 121 |
@begin{Extend83} |
| 122 |
@Defn{extensions to Ada 83} |
| 123 |
This clause is new in Ada 95. |
| 124 |
@end{Extend83} |