OSDN Git Service

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