OSDN Git Service

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