OSDN Git Service

* gcc-interface/misc.c (gnat_expand_expr): Remove.
[pf3gnuchains/gcc-fork.git] / gcc / ada / osint.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                                O S I N T                                 --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2008, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 3,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license.          --
20 --                                                                          --
21 -- GNAT was originally developed  by the GNAT team at  New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
23 --                                                                          --
24 ------------------------------------------------------------------------------
25
26 --  This package contains the low level, operating system routines used in the
27 --  compiler and binder for command line processing and file input output.
28
29 with Namet; use Namet;
30 with Types; use Types;
31
32 with System.OS_Lib; use System.OS_Lib;
33 with System;        use System;
34
35 pragma Elaborate_All (System.OS_Lib);
36 --  For the call to function Get_Target_Object_Suffix in the private part
37
38 package Osint is
39
40    Multi_Unit_Index_Character : Character := '~';
41    --  The character before the index of the unit in a multi-unit source, in
42    --  ALI and object file names. This is not a constant, because it is changed
43    --  to '$' on VMS.
44
45    Ada_Include_Path          : constant String := "ADA_INCLUDE_PATH";
46    Ada_Objects_Path          : constant String := "ADA_OBJECTS_PATH";
47    Project_Include_Path_File : constant String := "ADA_PRJ_INCLUDE_FILE";
48    Project_Objects_Path_File : constant String := "ADA_PRJ_OBJECTS_FILE";
49
50    procedure Initialize;
51    --  Initialize internal tables
52
53    function Normalize_Directory_Name (Directory : String) return String_Ptr;
54    --  Verify and normalize a directory name. If directory name is invalid,
55    --  this will return an empty string. Otherwise it will insure a trailing
56    --  slash and make other normalizations.
57
58    type File_Type is (Source, Library, Config, Definition, Preprocessing_Data);
59
60    function Find_File
61      (N : File_Name_Type;
62       T : File_Type) return File_Name_Type;
63    --  Finds a source, library or config file depending on the value of T
64    --  following the directory search order rules unless N is the name of the
65    --  file just read with Next_Main_File and already contains directory
66    --  information, in which case just look in the Primary_Directory. Returns
67    --  File_Name_Type of the full file name if found, No_File if file not
68    --  found. Note that for the special case of gnat.adc, only the compilation
69    --  environment directory is searched, i.e. the directory where the ali and
70    --  object files are written. Another special case is Debug_Generated_Code
71    --  set and the file name ends on ".dg", in which case we look for the
72    --  generated file only in the current directory, since that is where it is
73    --  always built.
74
75    function Get_File_Names_Case_Sensitive return Int;
76    pragma Import (C, Get_File_Names_Case_Sensitive,
77                   "__gnat_get_file_names_case_sensitive");
78    File_Names_Case_Sensitive : constant Boolean :=
79                                  Get_File_Names_Case_Sensitive /= 0;
80    --  Set to indicate whether the operating system convention is for file
81    --  names to be case sensitive (e.g., in Unix, set True), or non case
82    --  sensitive (e.g., in OS/2, set False).
83
84    procedure Canonical_Case_File_Name (S : in out String);
85    --  Given a file name, converts it to canonical case form. For systems
86    --  where file names are case sensitive, this procedure has no effect.
87    --  If file names are not case sensitive (i.e. for example if you have
88    --  the file "xyz.adb", you can refer to it as XYZ.adb or XyZ.AdB), then
89    --  this call converts the given string to canonical all lower case form,
90    --  so that two file names compare equal if they refer to the same file.
91
92    function Number_Of_Files return Int;
93    --  Gives the total number of filenames found on the command line
94
95    No_Index : constant := -1;
96    --  Value used in Add_File to indicate no index is specified for main
97
98    procedure Add_File (File_Name : String; Index : Int := No_Index);
99    --  Called by the subprogram processing the command line for each file name
100    --  found. The index, when not defaulted to No_Index is the index of the
101    --  subprogram in its source, zero indicating that the source is not
102    --  multi-unit.
103
104    procedure Find_Program_Name;
105    --  Put simple name of current program being run (excluding the directory
106    --  path) in Name_Buffer, with the length in Name_Len.
107
108    function Program_Name (Nam : String; Prog : String) return String_Access;
109    --  In the native compilation case, Create a string containing Nam. In the
110    --  cross compilation case, looks at the prefix of the current program being
111    --  run and prepend it to Nam. For instance if the program being run is
112    --  <target>-gnatmake and Nam is "gcc", the returned value will be a pointer
113    --  to "<target>-gcc". In the specific case where AAMP_On_Target is set, the
114    --  name "gcc" is mapped to "gnaamp", and names of the form "gnat*" are
115    --  mapped to "gnaamp*". This function clobbers Name_Buffer and Name_Len.
116    --  Also look at any suffix, e.g. gnatmake-4.1 -> "gcc-4.1". Prog is the
117    --  default name of the current program being executed, e.g. "gnatmake",
118    --  "gnatlink".
119
120    procedure Write_Program_Name;
121    --  Writes name of program as invoked to the current output (normally
122    --  standard output).
123
124    procedure Fail (S : String);
125    pragma No_Return (Fail);
126    --  Outputs error message S preceded by the name of the executing program
127    --  and exits with E_Fatal. The output goes to standard error, except if
128    --  special output is in effect (see Output).
129
130    function Is_Directory_Separator (C : Character) return Boolean;
131    --  Returns True if C is a directory separator
132
133    function Get_Directory (Name : File_Name_Type) return File_Name_Type;
134    --  Get the prefix directory name (if any) from Name. The last separator
135    --  is preserved. Return the normalized current directory if there is no
136    --  directory part in the name.
137
138    function Is_Readonly_Library (File : File_Name_Type) return Boolean;
139    --  Check if this library file is a read-only file
140
141    function Strip_Directory (Name : File_Name_Type) return File_Name_Type;
142    --  Strips the prefix directory name (if any) from Name. Returns the
143    --  stripped name. Name cannot end with a directory separator.
144
145    function Strip_Suffix (Name : File_Name_Type) return File_Name_Type;
146    --  Strips the suffix (the last '.' and whatever comes after it) from Name.
147    --  Returns the stripped name.
148
149    function Executable_Name (Name : File_Name_Type) return File_Name_Type;
150    --  Given a file name it adds the appropriate suffix at the end so that
151    --  it becomes the name of the executable on the system at end. For
152    --  instance under DOS it adds the ".exe" suffix, whereas under UNIX no
153    --  suffix is added.
154
155    function Executable_Name (Name : String) return String;
156    --  Same as above, with String parameters
157
158    function File_Stamp (Name : File_Name_Type) return Time_Stamp_Type;
159    --  Returns the time stamp of file Name. Name should include relative path
160    --  information in order to locate it. If the source file cannot be opened,
161    --  or Name = No_File, and all blank time stamp is returned (this is not an
162    --  error situation).
163
164    function File_Stamp (Name : Path_Name_Type) return Time_Stamp_Type;
165    --  Same as above for a path name
166
167    type String_Access_List is array (Positive range <>) of String_Access;
168    --  Dereferenced type used to return a list of file specs in
169    --  To_Canonical_File_List.
170
171    type String_Access_List_Access is access all String_Access_List;
172    --  Type used to return a String_Access_List without dragging in secondary
173    --  stack.
174
175    function To_Canonical_File_List
176      (Wildcard_Host_File : String;
177       Only_Dirs          : Boolean) return String_Access_List_Access;
178    --  Expand a wildcard host syntax file or directory specification (e.g. on
179    --  a VMS host, any file or directory spec that contains: "*", or "%", or
180    --  "...") and return a list of valid Unix syntax file or directory specs.
181    --  If Only_Dirs is True, then only return directories.
182
183    function To_Canonical_Dir_Spec
184      (Host_Dir     : String;
185       Prefix_Style : Boolean) return String_Access;
186    --  Convert a host syntax directory specification (e.g. on a VMS host:
187    --  "SYS$DEVICE:[DIR]") to canonical (Unix) syntax (e.g. "/sys$device/dir").
188    --  If Prefix_Style then make it a valid file specification prefix. A file
189    --  specification prefix is a directory specification that can be appended
190    --  with a simple file specification to yield a valid absolute or relative
191    --  path to a file. On a conversion to Unix syntax this simply means the
192    --  spec has a trailing slash ("/").
193
194    function To_Canonical_File_Spec
195      (Host_File : String) return String_Access;
196    --  Convert a host syntax file specification (e.g. on a VMS host:
197    --  "SYS$DEVICE:[DIR]FILE.EXT;69 to canonical (Unix) syntax (e.g.
198    --  "/sys$device/dir/file.ext.69").
199
200    function To_Canonical_Path_Spec
201      (Host_Path : String) return String_Access;
202    --  Convert a host syntax Path specification (e.g. on a VMS host:
203    --  "SYS$DEVICE:[BAR],DISK$USER:[FOO] to canonical (Unix) syntax (e.g.
204    --  "/sys$device/foo:disk$user/foo").
205
206    function To_Host_Dir_Spec
207      (Canonical_Dir : String;
208       Prefix_Style  : Boolean) return String_Access;
209    --  Convert a canonical syntax directory specification to host syntax.
210    --  The Prefix_Style flag is currently ignored but should be set to
211    --  False.
212
213    function To_Host_File_Spec
214      (Canonical_File : String) return String_Access;
215    --  Convert a canonical syntax file specification to host syntax
216
217    function Relocate_Path
218      (Prefix : String;
219       Path   : String) return String_Ptr;
220    --  Given an absolute path and a prefix, if Path starts with Prefix,
221    --  replace the Prefix substring with the root installation directory.
222    --  By default, try to compute the root installation directory by looking
223    --  at the executable name as it was typed on the command line and, if
224    --  needed, use the PATH environment variable. If the above computation
225    --  fails, return Path. This function assumes Prefix'First = Path'First.
226
227    function Shared_Lib (Name : String) return String;
228    --  Returns the runtime shared library in the form -l<name>-<version> where
229    --  version is the GNAT runtime library option for the platform. For example
230    --  this routine called with Name set to "gnat" will return "-lgnat-5.02"
231    --  on UNIX and Windows and -lgnat_5_02 on VMS.
232
233    -------------------------
234    -- Search Dir Routines --
235    -------------------------
236
237    function Include_Dir_Default_Prefix return String;
238    --  Return the directory of the run-time library sources, as modified
239    --  by update_path.
240
241    function Object_Dir_Default_Prefix return String;
242    --  Return the directory of the run-time library ALI and object files, as
243    --  modified by update_path.
244
245    procedure Add_Default_Search_Dirs;
246    --  This routine adds the default search dirs indicated by the environment
247    --  variables and sdefault package.
248
249    procedure Add_Lib_Search_Dir (Dir : String);
250    --  Add Dir at the end of the library file search path
251
252    procedure Add_Src_Search_Dir (Dir : String);
253    --  Add Dir at the end of the source file search path
254
255    procedure Get_Next_Dir_In_Path_Init
256      (Search_Path : String_Access);
257    function Get_Next_Dir_In_Path
258      (Search_Path : String_Access) return String_Access;
259    --  These subprograms are used to parse out the directory names in a search
260    --  path specified by a Search_Path argument. The procedure initializes an
261    --  internal pointer to point to the initial directory name, and calls to
262    --  the function return successive directory names, with a null pointer
263    --  marking the end of the list.
264
265    type Search_File_Type is (Include, Objects);
266
267    procedure Add_Search_Dirs
268      (Search_Path : String_Ptr;
269       Path_Type   : Search_File_Type);
270    --  These procedure adds all the search directories that are in Search_Path
271    --  in the proper file search path (library or source)
272
273    function Get_Primary_Src_Search_Directory return String_Ptr;
274    --  Retrieved the primary directory (directory containing the main source
275    --  file for Gnatmake.
276
277    function Nb_Dir_In_Src_Search_Path return Natural;
278    function Dir_In_Src_Search_Path (Position : Natural) return String_Ptr;
279    --  Functions to access the directory names in the source search path
280
281    function Nb_Dir_In_Obj_Search_Path return Natural;
282    function Dir_In_Obj_Search_Path (Position : Natural) return String_Ptr;
283    --  Functions to access the directory names in the Object search path
284
285    Include_Search_File : constant String_Access :=
286                            new String'("ada_source_path");
287    Objects_Search_File : constant String_Access :=
288                            new String'("ada_object_path");
289    --  Names of the files containing the default include or objects search
290    --  directories. These files, located in Sdefault.Search_Dir_Prefix, do
291    --  not necessarily exist.
292
293    Exec_Name : String_Ptr;
294    --  Executable name as typed by the user (used to compute the
295    --  executable prefix).
296
297    function Read_Default_Search_Dirs
298      (Search_Dir_Prefix       : String_Access;
299       Search_File             : String_Access;
300       Search_Dir_Default_Name : String_Access) return String_Access;
301    --  Read and return the default search directories from the file located
302    --  in Search_Dir_Prefix (as modified by update_path) and named Search_File.
303    --  If no such file exists or an error occurs then instead return the
304    --  Search_Dir_Default_Name (as modified by update_path).
305
306    function Get_RTS_Search_Dir
307      (Search_Dir : String;
308       File_Type  : Search_File_Type) return String_Ptr;
309    --  This function retrieves the paths to the search (resp. lib) dirs and
310    --  return them. The search dir can be absolute or relative. If the search
311    --  dir contains Include_Search_File (resp. Object_Search_File), then this
312    --  function reads and returns the default search directories from the file.
313    --  Otherwise, if the directory is absolute, it will try to find 'adalib'
314    --  (resp. 'adainclude'). If found, null is returned. If the directory is
315    --  relative, the following directories for the directories 'adalib' and
316    --  'adainclude' will be scanned:
317    --
318    --   - current directory (from which the tool has been spawned)
319    --   - $GNAT_ROOT/gcc/gcc-lib/$targ/$vers/
320    --   - $GNAT_ROOT/gcc/gcc-lib/$targ/$vers/rts-
321    --
322    --  The scan will stop as soon as the directory being searched for (adalib
323    --  or adainclude) is found. If the scan fails, null is returned.
324
325    -----------------------
326    -- Source File Input --
327    -----------------------
328
329    --  Source file input routines are used by the compiler to read the main
330    --  source files and the subsidiary source files (e.g. with'ed units), and
331    --  also by the binder to check presence/time stamps of sources.
332
333    procedure Read_Source_File
334      (N   : File_Name_Type;
335       Lo  : Source_Ptr;
336       Hi  : out Source_Ptr;
337       Src : out Source_Buffer_Ptr;
338       T   : File_Type := Source);
339    --  Allocates a Source_Buffer of appropriate length and then reads the
340    --  entire contents of the source file N into the buffer. The address of
341    --  the allocated buffer is returned in Src.
342    --
343    --  Each line of text is terminated by one of the sequences:
344    --
345    --    CR
346    --    CR/LF
347    --    LF
348
349    --  The source is terminated by an EOF (16#1A#) character, which is the last
350    --  character of the returned source buffer (note that any EOF characters in
351    --  positions other than the last source character are treated as blanks).
352    --
353    --  The logical lower bound of the source buffer is the input value of Lo,
354    --  and on exit Hi is set to the logical upper bound of the source buffer.
355    --  Note that the returned value in Src points to an array with a physical
356    --  lower bound of zero. This virtual origin addressing approach means that
357    --  a constrained array pointer can be used with a low bound of zero which
358    --  results in more efficient code.
359    --
360    --  If the given file cannot be opened, then the action depends on whether
361    --  this file is the current main unit (i.e. its name matches the name
362    --  returned by the most recent call to Next_Main_Source). If so, then the
363    --  failure to find the file is a fatal error, an error message is output,
364    --  and program execution is terminated. Otherwise (for the case of a
365    --  subsidiary source loaded directly or indirectly using with), a file
366    --  not found condition causes null to be set as the result value.
367    --
368    --  Note that the name passed to this function is the simple file name,
369    --  without any directory information. The implementation is responsible
370    --  for searching for the file in the appropriate directories.
371    --
372    --  Note the special case that if the file name is gnat.adc, then the search
373    --  for the file is done ONLY in the directory corresponding to the current
374    --  compilation environment, i.e. in the same directory where the ali and
375    --  object files will be written.
376
377    function Full_Source_Name return File_Name_Type;
378    function Current_Source_File_Stamp return Time_Stamp_Type;
379    --  Returns the full name/time stamp of the source file most recently read
380    --  using Read_Source_File. Calling this routine entails no source file
381    --  directory lookup penalty.
382
383    function Full_Source_Name (N : File_Name_Type) return File_Name_Type;
384    function Source_File_Stamp (N : File_Name_Type) return Time_Stamp_Type;
385    --  Returns the full name/time stamp of the source file whose simple name
386    --  is N which should not include path information. Note that if the file
387    --  cannot be located No_File is returned for the first routine and an all
388    --  blank time stamp is returned for the second (this is not an error
389    --  situation). The full name includes appropriate directory information.
390    --  The source file directory lookup penalty is incurred every single time
391    --  the routines are called unless you have previously called
392    --  Source_File_Data (Cache => True). See below.
393
394    function Current_File_Index return Int;
395    --  Return the index in its source file of the current main unit
396
397    function Matching_Full_Source_Name
398      (N : File_Name_Type;
399       T : Time_Stamp_Type) return File_Name_Type;
400    --  Same semantics than Full_Source_Name but will search on the source path
401    --  until a source file with time stamp matching T is found. If none is
402    --  found returns No_File.
403
404    procedure Source_File_Data (Cache : Boolean);
405    --  By default source file data (full source file name and time stamp)
406    --  are looked up every time a call to Full_Source_Name (N) or
407    --  Source_File_Stamp (N) is made. This may be undesirable in certain
408    --  applications as this is uselessly slow if source file data does not
409    --  change during program execution. When this procedure is called with
410    --  Cache => True access to source file data does not incur a penalty if
411    --  this data was previously retrieved.
412
413    -------------------------------------------
414    -- Representation of Library Information --
415    -------------------------------------------
416
417    --  Associated with each compiled source file is library information,
418    --  a string of bytes whose exact format is described in the body of
419    --  Lib.Writ. Compiling a source file generates this library information
420    --  for the compiled unit, and access the library information for units
421    --  that were compiled previously on which the unit being compiled depends.
422
423    --  How this information is stored is up to the implementation of this
424    --  package. At the interface level, this information is simply associated
425    --  with its corresponding source.
426
427    --  Several different implementations are possible:
428
429    --    1. The information could be directly associated with the source file,
430    --       e.g. placed in a resource fork of this file on the Mac, or on
431    --       MS-DOS, written to the source file after the end of file mark.
432
433    --    2. The information could be written into the generated object module
434    --       if the system supports the inclusion of arbitrary informational
435    --       byte streams into object files. In this case there must be a naming
436    --       convention that allows object files to be located given the name of
437    --       the corresponding source file.
438
439    --    3. The information could be written to a separate file, whose name is
440    --       related to the name of the source file by a fixed convention.
441
442    --  Which of these three methods is chosen depends on the constraints of the
443    --  host operating system. The interface described here is independent of
444    --  which of these approaches is used. Currently all versions of GNAT use
445    --  the third approach with a file name of xxx.ali where xxx is the source
446    --  file name.
447
448    -------------------------------
449    -- Library Information Input --
450    -------------------------------
451
452    --  These subprograms are used by the binder to read library information
453    --  files, see section above for representation of these files.
454
455    function Read_Library_Info
456      (Lib_File  : File_Name_Type;
457       Fatal_Err : Boolean := False) return Text_Buffer_Ptr;
458    --  Allocates a Text_Buffer of appropriate length and reads in the entire
459    --  source of the library information from the library information file
460    --  whose name is given by the parameter Name.
461    --
462    --  See description of Read_Source_File for details on the format of the
463    --  returned text buffer (the format is identical). The lower bound of
464    --  the Text_Buffer is always zero
465    --
466    --  If the specified file cannot be opened, then the action depends on
467    --  Fatal_Err. If Fatal_Err is True, an error message is given and the
468    --  compilation is abandoned. Otherwise if Fatal_Err is False, then null
469    --  is returned. Note that the Lib_File is a simple name which does not
470    --  include any directory information. The implementation is responsible
471    --  for searching for the file in appropriate directories.
472    --
473    --  If Opt.Check_Object_Consistency is set to True then this routine
474    --  checks whether the object file corresponding to the Lib_File is
475    --  consistent with it. The object file is inconsistent if the object
476    --  does not exist or if it has an older time stamp than Lib_File.
477    --  This check is not performed when the Lib_File is "locked" (i.e.
478    --  read/only) because in this case the object file may be buried
479    --  in a library. In case of inconsistencies Read_Library_Info
480    --  behaves as if it did not find Lib_File (namely if Fatal_Err is
481    --  False, null is returned).
482
483    function Full_Library_Info_Name return File_Name_Type;
484    function Full_Object_File_Name return File_Name_Type;
485    --  Returns the full name of the library/object file most recently read
486    --  using Read_Library_Info, including appropriate directory information.
487    --  Calling this routine entails no library file directory lookup
488    --  penalty. Note that the object file corresponding to a library file
489    --  is not actually read. Its time stamp is affected when the flag
490    --  Opt.Check_Object_Consistency is set.
491
492    function Current_Library_File_Stamp return Time_Stamp_Type;
493    function Current_Object_File_Stamp return Time_Stamp_Type;
494    --  The time stamps of the files returned by the previous two routines.
495    --  It is an error to call Current_Object_File_Stamp if
496    --  Opt.Check_Object_Consistency is set to False.
497
498    function Full_Lib_File_Name (N : File_Name_Type) return File_Name_Type;
499    function Library_File_Stamp (N : File_Name_Type) return Time_Stamp_Type;
500    --  Returns the full name/time stamp of library file N. N should not include
501    --  path information. Note that if the file cannot be located No_File is
502    --  returned for the first routine and an all blank time stamp is returned
503    --  for the second (this is not an error situation). The full name includes
504    --  the appropriate directory information. The library file directory lookup
505    --  penalty is incurred every single time this routine is called.
506
507    function Lib_File_Name
508      (Source_File : File_Name_Type;
509       Munit_Index : Nat := 0) return File_Name_Type;
510    --  Given the name of a source file, returns the name of the corresponding
511    --  library information file. This may be the name of the object file or of
512    --  a separate file used to store the library information. In the current
513    --  implementation, a separate file (the ALI file) is always used. In either
514    --  case the returned result is suitable for calling Read_Library_Info. The
515    --  Munit_Index is the unit index in multiple unit per file mode, or zero in
516    --  normal single unit per file mode (used to add ~nnn suffix). Note: this
517    --  subprogram is in this section because it is used by the compiler to
518    --  determine the proper library information names to be placed in the
519    --  generated library information file.
520
521    -----------------
522    -- Termination --
523    -----------------
524
525    Current_Exit_Status : Integer := 0;
526    --  Exit status that is set with procedure OS_Exit_Through_Exception below
527    --  and can be used in exception handler for Types.Terminate_Program to call
528    --  Set_Exit_Status as the last action of the program.
529
530    procedure OS_Exit_Through_Exception (Status : Integer);
531    --  Set the Current_Exit_Status, then raise Types.Terminate_Program
532
533    type Exit_Code_Type is (
534       E_Success,    -- No warnings or errors
535       E_Warnings,   -- Compiler warnings generated
536       E_No_Code,    -- No code generated
537       E_No_Compile, -- Compilation not needed (smart recompilation)
538       E_Errors,     -- Compiler error messages generated
539       E_Fatal,      -- Fatal (serious) error, e.g. source file not found
540       E_Abort);     -- Internally detected compiler error
541
542    procedure Exit_Program (Exit_Code : Exit_Code_Type);
543    pragma No_Return (Exit_Program);
544    --  A call to Exit_Program terminates execution with the given status. A
545    --  status of zero indicates normal completion, a non-zero status indicates
546    --  abnormal termination.
547
548    -------------------------
549    -- Command Line Access --
550    -------------------------
551
552    --  Direct interface to command line parameters. (We don't want to use
553    --  the predefined command line package because it defines functions
554    --  returning string)
555
556    function Arg_Count return Natural;
557    pragma Import (C, Arg_Count, "__gnat_arg_count");
558    --  Get number of arguments (note: optional globbing may be enabled)
559
560    procedure Fill_Arg (A : System.Address; Arg_Num : Integer);
561    pragma Import (C, Fill_Arg, "__gnat_fill_arg");
562    --  Store one argument
563
564    function Len_Arg (Arg_Num : Integer) return Integer;
565    pragma Import (C, Len_Arg, "__gnat_len_arg");
566    --  Get length of argument
567
568 private
569
570    ALI_Suffix : constant String_Ptr := new String'("ali");
571    --  The suffix used for the library files (also known as ALI files)
572
573    Current_Main : File_Name_Type := No_File;
574    --  Used to save a simple file name between calls to Next_Main_Source and
575    --  Read_Source_File. If the file name argument to Read_Source_File is
576    --  No_File, that indicates that the file whose name was returned by the
577    --  last call to Next_Main_Source (and stored here) is to be read.
578
579    Target_Object_Suffix : constant String := Get_Target_Object_Suffix.all;
580    --  The suffix used for the target object files
581
582    Output_FD : File_Descriptor;
583    --  File descriptor for current library info, list, tree, or binder output
584
585    Output_File_Name : File_Name_Type;
586    --  File_Name_Type for name of open file whose FD is in Output_FD, the name
587    --  stored does not include the trailing NUL character.
588
589    Argument_Count : constant Integer := Arg_Count - 1;
590    --  Number of arguments (excluding program name)
591
592    type File_Name_Array is array (Int range <>) of String_Ptr;
593    type File_Name_Array_Ptr is access File_Name_Array;
594    File_Names : File_Name_Array_Ptr :=
595                   new File_Name_Array (1 .. Int (Argument_Count) + 2);
596    --  As arguments are scanned, file names are stored in this array. The
597    --  strings do not have terminating NUL files. The array is extensible,
598    --  because when using project files, there may be more files than
599    --  arguments on the command line.
600
601    type File_Index_Array is array (Int range <>) of Int;
602    type File_Index_Array_Ptr is access File_Index_Array;
603    File_Indexes : File_Index_Array_Ptr :=
604                     new File_Index_Array (1 .. Int (Argument_Count) + 2);
605
606    Current_File_Name_Index : Int := 0;
607    --  The index in File_Names of the last file opened by Next_Main_Source
608    --  or Next_Main_Lib_File. The value 0 indicates that no files have been
609    --  opened yet.
610
611    procedure Create_File_And_Check
612      (Fdesc : out File_Descriptor;
613       Fmode : Mode);
614    --  Create file whose name (NUL terminated) is in Name_Buffer (with the
615    --  length in Name_Len), and place the resulting descriptor in Fdesc. Issue
616    --  message and exit with fatal error if file cannot be created. The Fmode
617    --  parameter is set to either Text or Binary (for details see description
618    --  of System.OS_Lib.Create_File).
619
620    type Program_Type is (Compiler, Binder, Make, Gnatls, Unspecified);
621    --  Program currently running
622    procedure Set_Program (P : Program_Type);
623    --  Indicates to the body of Osint the program currently running. This
624    --  procedure is called by the child packages of Osint. A check is made
625    --  that this procedure is not called more than once.
626
627    function More_Files return Boolean;
628    --  Implements More_Source_Files and More_Lib_Files
629
630    function Next_Main_File return File_Name_Type;
631    --  Implements Next_Main_Source and Next_Main_Lib_File
632
633    function Object_File_Name (N : File_Name_Type) return File_Name_Type;
634    --  Constructs the name of the object file corresponding to library file N.
635    --  If N is a full file name than the returned file name will also be a full
636    --  file name. Note that no lookup in the library file directories is done
637    --  for this file. This routine merely constructs the name.
638
639    procedure Write_Info (Info : String);
640    --  Implementation of Write_Binder_Info, Write_Debug_Info and
641    --  Write_Library_Info (identical)
642
643    procedure Write_With_Check (A : Address; N  : Integer);
644    --  Writes N bytes from buffer starting at address A to file whose FD is
645    --  stored in Output_FD, and whose file name is stored as a File_Name_Type
646    --  in Output_File_Name. A check is made for disk full, and if this is
647    --  detected, the file being written is deleted, and a fatal error is
648    --  signalled.
649
650 end Osint;