-- --
-- S p e c --
-- --
--- Copyright (C) 1992-2004 Free Software Foundation, Inc. --
+-- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- --
------------------------------------------------------------------------------
--- This package contains the low level, operating system routines used in
--- the GNAT compiler and binder for command line processing and file input
--- output.
+-- This package contains the low level, operating system routines used in the
+-- compiler and binder for command line processing and file input output.
-with GNAT.OS_Lib; use GNAT.OS_Lib;
-with System; use System;
-with Types; use Types;
+with Namet; use Namet;
+with Types; use Types;
-pragma Elaborate (GNAT.OS_Lib);
+with System.OS_Lib; use System.OS_Lib;
+with System; use System;
+
+pragma Elaborate_All (System.OS_Lib);
+-- For the call to function Get_Target_Object_Suffix in the private part
package Osint is
Multi_Unit_Index_Character : Character := '~';
- -- The character before the index of the unit in a multi-unit source,
- -- in ALI and object file names. This is not a constant, because it is
- -- changed to '$' on VMS.
+ -- The character before the index of the unit in a multi-unit source, in
+ -- ALI and object file names. This is not a constant, because it is changed
+ -- to '$' on VMS.
Ada_Include_Path : constant String := "ADA_INCLUDE_PATH";
Ada_Objects_Path : constant String := "ADA_OBJECTS_PATH";
function Find_File
(N : File_Name_Type;
T : File_Type) return File_Name_Type;
- -- Finds a source, library or config file depending on the value
- -- of T following the directory search order rules unless N is the
- -- name of the file just read with Next_Main_File and already
- -- contains directiory information, in which case just look in the
- -- Primary_Directory. Returns File_Name_Type of the full file name
- -- if found, No_File if file not found. Note that for the special
- -- case of gnat.adc, only the compilation environment directory is
- -- searched, i.e. the directory where the ali and object files are
- -- written. Another special case is when Debug_Generated_Code is
- -- set and the file name ends on ".dg", in which case we look for
- -- the generated file only in the current directory, since that is
- -- where it is always built.
+ -- Finds a source, library or config file depending on the value of T
+ -- following the directory search order rules unless N is the name of the
+ -- file just read with Next_Main_File and already contains directiory
+ -- information, in which case just look in the Primary_Directory. Returns
+ -- File_Name_Type of the full file name if found, No_File if file not
+ -- found. Note that for the special case of gnat.adc, only the compilation
+ -- environment directory is searched, i.e. the directory where the ali and
+ -- object files are written. Another special case is Debug_Generated_Code
+ -- set and the file name ends on ".dg", in which case we look for the
+ -- generated file only in the current directory, since that is where it is
+ -- always built.
function Get_File_Names_Case_Sensitive return Int;
pragma Import (C, Get_File_Names_Case_Sensitive,
-- so that two file names compare equal if they refer to the same file.
function Number_Of_Files return Int;
- -- gives the total number of filenames found on the command line.
+ -- Gives the total number of filenames found on the command line
No_Index : constant := -1;
- -- Value used in Add_File to indicate that no index is specified
- -- for a main.
+ -- Value used in Add_File to indicate no index is specified for main
procedure Add_File (File_Name : String; Index : Int := No_Index);
- -- Called by the subprogram processing the command line for each
- -- file name found. The index, when not defaulted to No_Index
- -- is the index of the subprogram in its source, zero indicating
- -- that the source is not multi-unit.
+ -- Called by the subprogram processing the command line for each file name
+ -- found. The index, when not defaulted to No_Index is the index of the
+ -- subprogram in its source, zero indicating that the source is not
+ -- multi-unit.
procedure Find_Program_Name;
-- Put simple name of current program being run (excluding the directory
-- path) in Name_Buffer, with the length in Name_Len.
function Program_Name (Nam : String) return String_Access;
- -- In the native compilation case, Create a string containing Nam. In
- -- the cross compilation case, looks at the prefix of the current
- -- program being run and prepend it to Nam. For instance if the program
- -- being run is <target>-gnatmake and Nam is "gcc", the returned value
- -- will be a pointer to "<target>-gcc". This function clobbers
- -- Name_Buffer and Name_Len.
+ -- In the native compilation case, Create a string containing Nam. In the
+ -- cross compilation case, looks at the prefix of the current program being
+ -- run and prepend it to Nam. For instance if the program being run is
+ -- <target>-gnatmake and Nam is "gcc", the returned value will be a pointer
+ -- to "<target>-gcc". This function clobbers Name_Buffer and Name_Len.
procedure Write_Program_Name;
-- Writes name of program as invoked to the current output
procedure Fail (S1 : String; S2 : String := ""; S3 : String := "");
pragma No_Return (Fail);
-- Outputs error messages S1 & S2 & S3 preceded by the name of the
- -- executing program and exits with E_Fatal. The output goes to
- -- standard error, except if special output is in effect (see Output).
+ -- executing program and exits with E_Fatal. The output goes to standard
+ -- error, except if special output is in effect (see Output).
function Is_Directory_Separator (C : Character) return Boolean;
-- Returns True if C is a directory separator
-- directory part in the name.
function Is_Readonly_Library (File : File_Name_Type) return Boolean;
- -- Check if this library file is a read-only file.
+ -- Check if this library file is a read-only file
function Strip_Directory (Name : File_Name_Type) return File_Name_Type;
-- Strips the prefix directory name (if any) from Name. Returns the
-- instance under DOS it adds the ".exe" suffix, whereas under UNIX no
-- suffix is added.
+ function Executable_Name (Name : String) return String;
+ -- Same as above, with String parameters
+
function File_Stamp (Name : File_Name_Type) return Time_Stamp_Type;
- -- Returns the time stamp of file Name. Name should include relative
- -- path information in order to locate it. If the source file cannot be
- -- opened, or Name = No_File, and all blank time stamp is returned (this is
- -- not an error situation).
+ -- Returns the time stamp of file Name. Name should include relative path
+ -- information in order to locate it. If the source file cannot be opened,
+ -- or Name = No_File, and all blank time stamp is returned (this is not an
+ -- error situation).
+
+ function File_Stamp (Name : Path_Name_Type) return Time_Stamp_Type;
+ -- Same as above for a path name
type String_Access_List is array (Positive range <>) of String_Access;
-- Deferenced type used to return a list of file specs in
Prefix_Style : Boolean) return String_Access;
-- Convert a host syntax directory specification (e.g. on a VMS host:
-- "SYS$DEVICE:[DIR]") to canonical (Unix) syntax (e.g. "/sys$device/dir").
- -- If Prefix_Style then make it a valid file specification prefix.
- -- A file specification prefix is a directory specification that
- -- can be appended with a simple file specification to yield a valid
- -- absolute or relative path to a file. On a conversion to Unix syntax
- -- this simply means the spec has a trailing slash ("/").
+ -- If Prefix_Style then make it a valid file specification prefix. A file
+ -- specification prefix is a directory specification that can be appended
+ -- with a simple file specification to yield a valid absolute or relative
+ -- path to a file. On a conversion to Unix syntax this simply means the
+ -- spec has a trailing slash ("/").
function To_Canonical_File_Spec
(Host_File : String) return String_Access;
function To_Host_File_Spec
(Canonical_File : String) return String_Access;
- -- Convert a canonical syntax file specification to host syntax.
+ -- Convert a canonical syntax file specification to host syntax
function Relocate_Path
(Prefix : String;
function Source_File_Stamp (N : File_Name_Type) return Time_Stamp_Type;
-- Returns the full name/time stamp of the source file whose simple name
-- is N which should not include path information. Note that if the file
- -- cannot be located No_File is returned for the first routine and an
- -- all blank time stamp is returned for the second (this is not an error
- -- situation). The full name includes the appropriate directory
- -- information. The source file directory lookup penalty is incurred
- -- every single time the routines are called unless you have previously
- -- called Source_File_Data (Cache => True). See below.
+ -- cannot be located No_File is returned for the first routine and an all
+ -- blank time stamp is returned for the second (this is not an error
+ -- situation). The full name includes appropriate directory information.
+ -- The source file directory lookup penalty is incurred every single time
+ -- the routines are called unless you have previously called
+ -- Source_File_Data (Cache => True). See below.
function Current_File_Index return Int;
-- Return the index in its source file of the current main unit
function Matching_Full_Source_Name
(N : File_Name_Type;
T : Time_Stamp_Type) return File_Name_Type;
- -- Same semantics than Full_Source_Name but will search on the source
- -- path until a source file with time stamp matching T is found. If
- -- none is found returns No_File.
+ -- Same semantics than Full_Source_Name but will search on the source path
+ -- until a source file with time stamp matching T is found. If none is
+ -- found returns No_File.
procedure Source_File_Data (Cache : Boolean);
-- By default source file data (full source file name and time stamp)
-- Which of these three methods is chosen depends on the constraints of the
-- host operating system. The interface described here is independent of
- -- which of these approaches is used.
+ -- which of these approaches is used. Currently all versions of GNAT use
+ -- the third approach with a file name of xxx.ali where xxx is the source
+ -- file name.
-------------------------------
-- Library Information Input --
function Full_Lib_File_Name (N : File_Name_Type) return File_Name_Type;
function Library_File_Stamp (N : File_Name_Type) return Time_Stamp_Type;
- -- Returns the full name/time stamp of library file N. N should not
- -- include path information. Note that if the file cannot be located
- -- No_File is returned for the first routine and an all blank time stamp
- -- is returned for the second (this is not an error situation). The
- -- full name includes the appropriate directory information. The library
- -- file directory lookup penalty is incurred every single time this
- -- routine is called.
+ -- Returns the full name/time stamp of library file N. N should not include
+ -- path information. Note that if the file cannot be located No_File is
+ -- returned for the first routine and an all blank time stamp is returned
+ -- for the second (this is not an error situation). The full name includes
+ -- the appropriate directory information. The library file directory lookup
+ -- penalty is incurred every single time this routine is called.
function Lib_File_Name
(Source_File : File_Name_Type;
procedure Exit_Program (Exit_Code : Exit_Code_Type);
pragma No_Return (Exit_Program);
- -- A call to Exit_Program terminates execution with the given status.
- -- A status of zero indicates normal completion, a non-zero status
- -- indicates abnormal termination.
+ -- A call to Exit_Program terminates execution with the given status. A
+ -- status of zero indicates normal completion, a non-zero status indicates
+ -- abnormal termination.
-------------------------
-- Command Line Access --
private
ALI_Suffix : constant String_Ptr := new String'("ali");
- -- The suffix used for the library files (also known as ALI files).
+ -- The suffix used for the library files (also known as ALI files)
Current_Main : File_Name_Type := No_File;
-- Used to save a simple file name between calls to Next_Main_Source and
-- No_File, that indicates that the file whose name was returned by the
-- last call to Next_Main_Source (and stored here) is to be read.
- Object_Suffix : constant String := Get_Object_Suffix.all;
- -- The suffix used for the object files.
+ Target_Object_Suffix : constant String := Get_Target_Object_Suffix.all;
+ -- The suffix used for the target object files
Output_FD : File_Descriptor;
- -- The file descriptor for the current library info, tree or binder output
+ -- File descriptor for current library info, list, tree, or binder output
Output_File_Name : File_Name_Type;
-- File_Name_Type for name of open file whose FD is in Output_FD, the name
type File_Name_Array_Ptr is access File_Name_Array;
File_Names : File_Name_Array_Ptr :=
new File_Name_Array (1 .. Int (Argument_Count) + 2);
- -- As arguments are scanned, file names are stored in this array
- -- The strings do not have terminating NUL files. The array is
- -- extensible, because when using project files, there may be
- -- more files than arguments on the command line.
+ -- As arguments are scanned, file names are stored in this array The
+ -- strings do not have terminating NUL files. The array is extensible,
+ -- because when using project files, there may be more files than
+ -- arguments on the command line.
type File_Index_Array is array (Int range <>) of Int;
type File_Index_Array_Ptr is access File_Index_Array;
(Fdesc : out File_Descriptor;
Fmode : Mode);
-- Create file whose name (NUL terminated) is in Name_Buffer (with the
- -- length in Name_Len), and place the resulting descriptor in Fdesc.
- -- Issue message and exit with fatal error if file cannot be created.
- -- The Fmode parameter is set to either Text or Binary (see description
- -- of GNAT.OS_Lib.Create_File).
+ -- length in Name_Len), and place the resulting descriptor in Fdesc. Issue
+ -- message and exit with fatal error if file cannot be created. The Fmode
+ -- parameter is set to either Text or Binary (for details see description
+ -- of System.OS_Lib.Create_File).
type Program_Type is (Compiler, Binder, Make, Gnatls, Unspecified);
-- Program currently running
procedure Set_Program (P : Program_Type);
- -- Indicates to the body of Osint the program currently running.
- -- This procedure is called by the child packages of Osint.
- -- A check is made that this procedure is not called several times.
+ -- Indicates to the body of Osint the program currently running. This
+ -- procedure is called by the child packages of Osint. A check is made
+ -- that this procedure is not called more than once.
function More_Files return Boolean;
- -- Implements More_Source_Files and More_Lib_Files.
+ -- Implements More_Source_Files and More_Lib_Files
function Next_Main_File return File_Name_Type;
- -- Implements Next_Main_Source and Next_Main_Lib_File.
+ -- Implements Next_Main_Source and Next_Main_Lib_File
function Object_File_Name (N : File_Name_Type) return File_Name_Type;
- -- Constructs the name of the object file corresponding to library
- -- file N. If N is a full file name than the returned file name will
- -- also be a full file name. Note that no lookup in the library file
- -- directories is done for this file. This routine merely constructs
- -- the name.
+ -- Constructs the name of the object file corresponding to library file N.
+ -- If N is a full file name than the returned file name will also be a full
+ -- file name. Note that no lookup in the library file directories is done
+ -- for this file. This routine merely constructs the name.
procedure Write_Info (Info : String);
-- Implementation of Write_Binder_Info, Write_Debug_Info and
-- Write_Library_Info (identical)
+ procedure Write_With_Check (A : Address; N : Integer);
+ -- Writes N bytes from buffer starting at address A to file whose FD is
+ -- stored in Output_FD, and whose file name is stored as a File_Name_Type
+ -- in Output_File_Name. A check is made for disk full, and if this is
+ -- detected, the file being written is deleted, and a fatal error is
+ -- signalled.
+
end Osint;