1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2003 Free Software Foundation, Inc. --
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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
29 with Namet; use Namet;
31 with Output; use Output;
32 with Sdefault; use Sdefault;
33 with System.Case_Util; use System.Case_Util;
36 with Unchecked_Conversion;
38 with GNAT.OS_Lib; use GNAT.OS_Lib;
43 Running_Program : Program_Type := Unspecified;
44 -- comment required here ???
46 Program_Set : Boolean := False;
47 -- comment required here ???
49 Std_Prefix : String_Ptr;
50 -- Standard prefix, computed dynamically the first time Relocate_Path
51 -- is called, and cached for subsequent calls.
53 Empty : aliased String := "";
54 No_Dir : constant String_Ptr := Empty'Access;
55 -- Used in Locate_File as a fake directory when Name is already an
58 -------------------------------------
59 -- Use of Name_Find and Name_Enter --
60 -------------------------------------
62 -- This package creates a number of source, ALI and object file names
63 -- that are used to locate the actual file and for the purpose of
64 -- message construction. These names need not be accessible by Name_Find,
65 -- and can be therefore created by using routine Name_Enter. The files in
66 -- question are file names with a prefix directory (ie the files not
67 -- in the current directory). File names without a prefix directory are
68 -- entered with Name_Find because special values might be attached to
69 -- the various Info fields of the corresponding name table entry.
71 -----------------------
72 -- Local Subprograms --
73 -----------------------
75 function Append_Suffix_To_File_Name
77 Suffix : String) return Name_Id;
78 -- Appends Suffix to Name and returns the new name.
80 function OS_Time_To_GNAT_Time (T : OS_Time) return Time_Stamp_Type;
81 -- Convert OS format time to GNAT format time stamp
83 function Concat (String_One : String; String_Two : String) return String;
84 -- Concatenates 2 strings and returns the result of the concatenation
86 function Executable_Prefix return String_Ptr;
87 -- Returns the name of the root directory where the executable is stored.
88 -- The executable must be located in a directory called "bin", or
89 -- under root/lib/gcc-lib/..., or under root/libexec/gcc/... Thus, if
90 -- the executable is stored in directory "/foo/bar/bin", this routine
91 -- returns "/foo/bar/". Return "" if the location is not recognized
92 -- as described above.
94 function Update_Path (Path : String_Ptr) return String_Ptr;
95 -- Update the specified path to replace the prefix with the location
96 -- where GNAT is installed. See the file prefix.c in GCC for details.
98 procedure Write_With_Check (A : Address; N : Integer);
99 -- Writes N bytes from buffer starting at address A to file whose FD is
100 -- stored in Output_FD, and whose file name is stored as a File_Name_Type
101 -- in Output_File_Name. A check is made for disk full, and if this is
102 -- detected, the file being written is deleted, and a fatal error is
109 Name : String) return File_Name_Type;
110 -- See if the file N whose name is Name exists in directory Dir. Dir is
111 -- an index into the Lib_Search_Directories table if T = Library.
112 -- Otherwise if T = Source, Dir is an index into the
113 -- Src_Search_Directories table. Returns the File_Name_Type of the
114 -- full file name if file found, or No_File if not found.
116 function C_String_Length (S : Address) return Integer;
117 -- Returns length of a C string. Returns zero for a null address.
119 function To_Path_String_Access
120 (Path_Addr : Address;
121 Path_Len : Integer) return String_Access;
122 -- Converts a C String to an Ada String. Are we doing this to avoid
123 -- withing Interfaces.C.Strings ???
125 ------------------------------
126 -- Other Local Declarations --
127 ------------------------------
129 EOL : constant Character := ASCII.LF;
130 -- End of line character
132 Number_File_Names : Int := 0;
133 -- The total number of file names found on command line and placed in
136 Look_In_Primary_Directory_For_Current_Main : Boolean := False;
137 -- When this variable is True, Find_File will only look in
138 -- the Primary_Directory for the Current_Main file.
139 -- This variable is always True for the compiler.
140 -- It is also True for gnatmake, when the soucr name given
141 -- on the command line has directory information.
143 Current_Full_Source_Name : File_Name_Type := No_File;
144 Current_Full_Source_Stamp : Time_Stamp_Type := Empty_Time_Stamp;
145 Current_Full_Lib_Name : File_Name_Type := No_File;
146 Current_Full_Lib_Stamp : Time_Stamp_Type := Empty_Time_Stamp;
147 Current_Full_Obj_Name : File_Name_Type := No_File;
148 Current_Full_Obj_Stamp : Time_Stamp_Type := Empty_Time_Stamp;
149 -- Respectively full name (with directory info) and time stamp of
150 -- the latest source, library and object files opened by Read_Source_File
151 -- and Read_Library_Info.
157 Primary_Directory : constant := 0;
158 -- This is index in the tables created below for the first directory to
159 -- search in for source or library information files. This is the
160 -- directory containing the latest main input file (a source file for
161 -- the compiler or a library file for the binder).
163 package Src_Search_Directories is new Table.Table (
164 Table_Component_Type => String_Ptr,
165 Table_Index_Type => Natural,
166 Table_Low_Bound => Primary_Directory,
168 Table_Increment => 100,
169 Table_Name => "Osint.Src_Search_Directories");
170 -- Table of names of directories in which to search for source (Compiler)
171 -- files. This table is filled in the order in which the directories are
172 -- to be searched, and then used in that order.
174 package Lib_Search_Directories is new Table.Table (
175 Table_Component_Type => String_Ptr,
176 Table_Index_Type => Natural,
177 Table_Low_Bound => Primary_Directory,
179 Table_Increment => 100,
180 Table_Name => "Osint.Lib_Search_Directories");
181 -- Table of names of directories in which to search for library (Binder)
182 -- files. This table is filled in the order in which the directories are
183 -- to be searched and then used in that order. The reason for having two
184 -- distinct tables is that we need them both in gnatmake.
186 ---------------------
187 -- File Hash Table --
188 ---------------------
190 -- The file hash table is provided to free the programmer from any
191 -- efficiency concern when retrieving full file names or time stamps of
192 -- source files. If the programmer calls Source_File_Data (Cache => True)
193 -- he is guaranteed that the price to retrieve the full name (ie with
194 -- directory info) or time stamp of the file will be payed only once,
195 -- the first time the full name is actually searched (or the first time
196 -- the time stamp is actually retrieved). This is achieved by employing
197 -- a hash table that stores as a key the File_Name_Type of the file and
198 -- associates to that File_Name_Type the full file name of the file and its
201 File_Cache_Enabled : Boolean := False;
202 -- Set to true if you want the enable the file data caching mechanism.
204 type File_Hash_Num is range 0 .. 1020;
206 function File_Hash (F : File_Name_Type) return File_Hash_Num;
207 -- Compute hash index for use by Simple_HTable
209 package File_Name_Hash_Table is new GNAT.HTable.Simple_HTable (
210 Header_Num => File_Hash_Num,
211 Element => File_Name_Type,
212 No_Element => No_File,
213 Key => File_Name_Type,
217 package File_Stamp_Hash_Table is new GNAT.HTable.Simple_HTable (
218 Header_Num => File_Hash_Num,
219 Element => Time_Stamp_Type,
220 No_Element => Empty_Time_Stamp,
221 Key => File_Name_Type,
225 function Smart_Find_File
227 T : File_Type) return File_Name_Type;
228 -- Exactly like Find_File except that if File_Cache_Enabled is True this
229 -- routine looks first in the hash table to see if the full name of the
230 -- file is already available.
232 function Smart_File_Stamp
234 T : File_Type) return Time_Stamp_Type;
235 -- Takes the same parameter as the routine above (N is a file name
236 -- without any prefix directory information) and behaves like File_Stamp
237 -- except that if File_Cache_Enabled is True this routine looks first in
238 -- the hash table to see if the file stamp of the file is already
241 -----------------------------
242 -- Add_Default_Search_Dirs --
243 -----------------------------
245 procedure Add_Default_Search_Dirs is
246 Search_Dir : String_Access;
247 Search_Path : String_Access;
248 Path_File_Name : String_Access;
250 procedure Add_Search_Dir
251 (Search_Dir : String;
252 Additional_Source_Dir : Boolean);
253 procedure Add_Search_Dir
254 (Search_Dir : String_Access;
255 Additional_Source_Dir : Boolean);
256 -- Add a source search dir or a library search dir, depending on the
257 -- value of Additional_Source_Dir.
259 procedure Get_Dirs_From_File (Additional_Source_Dir : Boolean);
260 -- Open a path file and read the directory to search, one per line
262 function Get_Libraries_From_Registry return String_Ptr;
263 -- On Windows systems, get the list of installed standard libraries
264 -- from the registry key:
265 -- HKEY_LOCAL_MACHINE\SOFTWARE\Ada Core Technologies\
266 -- GNAT\Standard Libraries
267 -- Return an empty string on other systems
273 procedure Add_Search_Dir
274 (Search_Dir : String;
275 Additional_Source_Dir : Boolean)
278 if Additional_Source_Dir then
279 Add_Src_Search_Dir (Search_Dir);
281 Add_Lib_Search_Dir (Search_Dir);
285 procedure Add_Search_Dir
286 (Search_Dir : String_Access;
287 Additional_Source_Dir : Boolean)
290 if Additional_Source_Dir then
291 Add_Src_Search_Dir (Search_Dir.all);
293 Add_Lib_Search_Dir (Search_Dir.all);
297 ------------------------
298 -- Get_Dirs_From_File --
299 ------------------------
301 procedure Get_Dirs_From_File (Additional_Source_Dir : Boolean) is
302 File_FD : File_Descriptor;
303 Buffer : String (1 .. Path_File_Name'Length + 1);
305 Actual_Len : Natural;
312 -- For the call to Close
315 -- Construct a C compatible character string buffer.
317 Buffer (1 .. Buffer'Last - 1) := Path_File_Name.all;
318 Buffer (Buffer'Last) := ASCII.NUL;
320 File_FD := Open_Read (Buffer'Address, Binary);
322 -- If we cannot open the file, we ignore it, we don't fail
324 if File_FD = Invalid_FD then
328 Len := Integer (File_Length (File_FD));
330 S := new String (1 .. Len);
332 -- Read the file. Note that the loop is not necessary since the
333 -- whole file is read at once except on VMS.
337 while Curr <= Len and then Actual_Len /= 0 loop
338 Actual_Len := Read (File_FD, S (Curr)'Address, Len);
339 Curr := Curr + Actual_Len;
342 -- We are done with the file, so we close it
344 Close (File_FD, Status);
345 -- We ignore any error here, because we have successfully read the
348 -- Now, we read line by line
353 while Curr < Len loop
356 if Ch = ASCII.CR or else Ch = ASCII.LF
357 or else Ch = ASCII.FF or else Ch = ASCII.VT
359 if First <= Curr then
360 Add_Search_Dir (S (First .. Curr), Additional_Source_Dir);
369 -- Last line is a special case, if the file does not end with
370 -- an end of line mark.
372 if First <= S'Last then
373 Add_Search_Dir (S (First .. S'Last), Additional_Source_Dir);
375 end Get_Dirs_From_File;
377 ---------------------------------
378 -- Get_Libraries_From_Registry --
379 ---------------------------------
381 function Get_Libraries_From_Registry return String_Ptr is
382 function C_Get_Libraries_From_Registry return Address;
383 pragma Import (C, C_Get_Libraries_From_Registry,
384 "__gnat_get_libraries_from_registry");
385 function Strlen (Str : Address) return Integer;
386 pragma Import (C, Strlen, "strlen");
387 procedure Strncpy (X : Address; Y : Address; Length : Integer);
388 pragma Import (C, Strncpy, "strncpy");
389 Result_Ptr : Address;
390 Result_Length : Integer;
391 Out_String : String_Ptr;
394 Result_Ptr := C_Get_Libraries_From_Registry;
395 Result_Length := Strlen (Result_Ptr);
397 Out_String := new String (1 .. Result_Length);
398 Strncpy (Out_String.all'Address, Result_Ptr, Result_Length);
400 end Get_Libraries_From_Registry;
402 -- Start of processing for Add_Default_Search_Dirs
405 -- After the locations specified on the command line, the next places
406 -- to look for files are the directories specified by the appropriate
407 -- environment variable. Get this value, extract the directory names
408 -- and store in the tables.
410 -- On VMS, don't expand the logical name (e.g. environment variable),
411 -- just put it into Unix (e.g. canonical) format. System services
412 -- will handle the expansion as part of the file processing.
414 for Additional_Source_Dir in False .. True loop
416 if Additional_Source_Dir then
417 Search_Path := Getenv (Ada_Include_Path);
418 if Search_Path'Length > 0 then
419 if Hostparm.OpenVMS then
420 Search_Path := To_Canonical_Path_Spec ("ADA_INCLUDE_PATH:");
422 Search_Path := To_Canonical_Path_Spec (Search_Path.all);
426 Search_Path := Getenv (Ada_Objects_Path);
427 if Search_Path'Length > 0 then
428 if Hostparm.OpenVMS then
429 Search_Path := To_Canonical_Path_Spec ("ADA_OBJECTS_PATH:");
431 Search_Path := To_Canonical_Path_Spec (Search_Path.all);
436 Get_Next_Dir_In_Path_Init (Search_Path);
438 Search_Dir := Get_Next_Dir_In_Path (Search_Path);
439 exit when Search_Dir = null;
440 Add_Search_Dir (Search_Dir, Additional_Source_Dir);
444 -- Check for eventual project path file env vars
446 Path_File_Name := Getenv (Project_Include_Path_File);
448 if Path_File_Name'Length > 0 then
449 Get_Dirs_From_File (Additional_Source_Dir => True);
452 Path_File_Name := Getenv (Project_Objects_Path_File);
454 if Path_File_Name'Length > 0 then
455 Get_Dirs_From_File (Additional_Source_Dir => False);
458 -- For the compiler, if --RTS= was apecified, add the runtime
461 if RTS_Src_Path_Name /= null and then
462 RTS_Lib_Path_Name /= null
464 Add_Search_Dirs (RTS_Src_Path_Name, Include);
465 Add_Search_Dirs (RTS_Lib_Path_Name, Objects);
468 if not Opt.No_Stdinc then
470 -- For WIN32 systems, look for any system libraries defined in
471 -- the registry. These are added to both source and object
474 Search_Path := String_Access (Get_Libraries_From_Registry);
476 Get_Next_Dir_In_Path_Init (Search_Path);
478 Search_Dir := Get_Next_Dir_In_Path (Search_Path);
479 exit when Search_Dir = null;
480 Add_Search_Dir (Search_Dir, False);
481 Add_Search_Dir (Search_Dir, True);
484 -- The last place to look are the defaults
487 Read_Default_Search_Dirs
488 (String_Access (Update_Path (Search_Dir_Prefix)),
490 String_Access (Update_Path (Include_Dir_Default_Name)));
492 Get_Next_Dir_In_Path_Init (Search_Path);
494 Search_Dir := Get_Next_Dir_In_Path (Search_Path);
495 exit when Search_Dir = null;
496 Add_Search_Dir (Search_Dir, True);
500 if not Opt.No_Stdlib and not Opt.RTS_Switch then
502 Read_Default_Search_Dirs
503 (String_Access (Update_Path (Search_Dir_Prefix)),
505 String_Access (Update_Path (Object_Dir_Default_Name)));
507 Get_Next_Dir_In_Path_Init (Search_Path);
509 Search_Dir := Get_Next_Dir_In_Path (Search_Path);
510 exit when Search_Dir = null;
511 Add_Search_Dir (Search_Dir, False);
515 end Add_Default_Search_Dirs;
521 procedure Add_File (File_Name : String) is
523 Number_File_Names := Number_File_Names + 1;
525 -- As Add_File may be called for mains specified inside
526 -- a project file, File_Names may be too short and needs
529 if Number_File_Names > File_Names'Last then
530 File_Names := new File_Name_Array'(File_Names.all & File_Names.all);
533 File_Names (Number_File_Names) := new String'(File_Name);
536 ------------------------
537 -- Add_Lib_Search_Dir --
538 ------------------------
540 procedure Add_Lib_Search_Dir (Dir : String) is
542 if Dir'Length = 0 then
543 Fail ("missing library directory name");
546 Lib_Search_Directories.Increment_Last;
547 Lib_Search_Directories.Table (Lib_Search_Directories.Last) :=
548 Normalize_Directory_Name (Dir);
549 end Add_Lib_Search_Dir;
551 ---------------------
552 -- Add_Search_Dirs --
553 ---------------------
555 procedure Add_Search_Dirs
556 (Search_Path : String_Ptr;
557 Path_Type : Search_File_Type)
559 Current_Search_Path : String_Access;
562 Get_Next_Dir_In_Path_Init (String_Access (Search_Path));
564 Current_Search_Path :=
565 Get_Next_Dir_In_Path (String_Access (Search_Path));
566 exit when Current_Search_Path = null;
568 if Path_Type = Include then
569 Add_Src_Search_Dir (Current_Search_Path.all);
571 Add_Lib_Search_Dir (Current_Search_Path.all);
576 ------------------------
577 -- Add_Src_Search_Dir --
578 ------------------------
580 procedure Add_Src_Search_Dir (Dir : String) is
582 if Dir'Length = 0 then
583 Fail ("missing source directory name");
586 Src_Search_Directories.Increment_Last;
587 Src_Search_Directories.Table (Src_Search_Directories.Last) :=
588 Normalize_Directory_Name (Dir);
589 end Add_Src_Search_Dir;
591 --------------------------------
592 -- Append_Suffix_To_File_Name --
593 --------------------------------
595 function Append_Suffix_To_File_Name
597 Suffix : String) return Name_Id
600 Get_Name_String (Name);
601 Name_Buffer (Name_Len + 1 .. Name_Len + Suffix'Length) := Suffix;
602 Name_Len := Name_Len + Suffix'Length;
604 end Append_Suffix_To_File_Name;
606 ---------------------
607 -- C_String_Length --
608 ---------------------
610 function C_String_Length (S : Address) return Integer is
611 function Strlen (S : Address) return Integer;
612 pragma Import (C, Strlen, "strlen");
615 if S = Null_Address then
622 ------------------------------
623 -- Canonical_Case_File_Name --
624 ------------------------------
626 -- For now, we only deal with the case of a-z. Eventually we should
627 -- worry about other Latin-1 letters on systems that support this ???
629 procedure Canonical_Case_File_Name (S : in out String) is
631 if not File_Names_Case_Sensitive then
632 for J in S'Range loop
633 if S (J) in 'A' .. 'Z' then
634 S (J) := Character'Val (
635 Character'Pos (S (J)) +
636 Character'Pos ('a') -
637 Character'Pos ('A'));
641 end Canonical_Case_File_Name;
647 function Concat (String_One : String; String_Two : String) return String is
648 Buffer : String (1 .. String_One'Length + String_Two'Length);
651 Buffer (1 .. String_One'Length) := String_One;
652 Buffer (String_One'Length + 1 .. Buffer'Last) := String_Two;
656 ---------------------------
657 -- Create_File_And_Check --
658 ---------------------------
660 procedure Create_File_And_Check
661 (Fdesc : out File_Descriptor;
665 Output_File_Name := Name_Enter;
666 Fdesc := Create_File (Name_Buffer'Address, Fmode);
668 if Fdesc = Invalid_FD then
669 Fail ("Cannot create: ", Name_Buffer (1 .. Name_Len));
671 end Create_File_And_Check;
673 --------------------------------
674 -- Current_Library_File_Stamp --
675 --------------------------------
677 function Current_Library_File_Stamp return Time_Stamp_Type is
679 return Current_Full_Lib_Stamp;
680 end Current_Library_File_Stamp;
682 -------------------------------
683 -- Current_Object_File_Stamp --
684 -------------------------------
686 function Current_Object_File_Stamp return Time_Stamp_Type is
688 return Current_Full_Obj_Stamp;
689 end Current_Object_File_Stamp;
691 -------------------------------
692 -- Current_Source_File_Stamp --
693 -------------------------------
695 function Current_Source_File_Stamp return Time_Stamp_Type is
697 return Current_Full_Source_Stamp;
698 end Current_Source_File_Stamp;
700 ----------------------------
701 -- Dir_In_Obj_Search_Path --
702 ----------------------------
704 function Dir_In_Obj_Search_Path (Position : Natural) return String_Ptr is
706 if Opt.Look_In_Primary_Dir then
708 Lib_Search_Directories.Table (Primary_Directory + Position - 1);
710 return Lib_Search_Directories.Table (Primary_Directory + Position);
712 end Dir_In_Obj_Search_Path;
714 ----------------------------
715 -- Dir_In_Src_Search_Path --
716 ----------------------------
718 function Dir_In_Src_Search_Path (Position : Natural) return String_Ptr is
720 if Opt.Look_In_Primary_Dir then
722 Src_Search_Directories.Table (Primary_Directory + Position - 1);
724 return Src_Search_Directories.Table (Primary_Directory + Position);
726 end Dir_In_Src_Search_Path;
728 ---------------------
729 -- Executable_Name --
730 ---------------------
732 function Executable_Name (Name : File_Name_Type) return File_Name_Type is
733 Exec_Suffix : String_Access;
736 if Name = No_File then
740 Get_Name_String (Name);
741 Exec_Suffix := Get_Executable_Suffix;
743 for J in Exec_Suffix'Range loop
744 Name_Len := Name_Len + 1;
745 Name_Buffer (Name_Len) := Exec_Suffix (J);
753 -------------------------
754 -- Executable_Prefix --
755 -------------------------
757 function Executable_Prefix return String_Ptr is
758 Exec_Name : String (1 .. Len_Arg (0));
760 function Get_Install_Dir (Exec : String) return String_Ptr;
761 -- S is the executable name preceeded by the absolute or relative
762 -- path, e.g. "c:\usr\bin\gcc.exe" or "..\bin\gcc".
764 ---------------------
765 -- Get_Install_Dir --
766 ---------------------
768 function Get_Install_Dir (Exec : String) return String_Ptr is
770 for J in reverse Exec'Range loop
771 if Is_Directory_Separator (Exec (J)) then
772 if J < Exec'Last - 5 then
773 if (To_Lower (Exec (J + 1)) = 'l'
774 and then To_Lower (Exec (J + 2)) = 'i'
775 and then To_Lower (Exec (J + 3)) = 'b')
777 (To_Lower (Exec (J + 1)) = 'b'
778 and then To_Lower (Exec (J + 2)) = 'i'
779 and then To_Lower (Exec (J + 3)) = 'n')
781 return new String'(Exec (Exec'First .. J));
787 return new String'("");
790 -- Start of processing for Executable_Prefix
793 Osint.Fill_Arg (Exec_Name'Address, 0);
795 -- First determine if a path prefix was placed in front of the
798 for J in reverse Exec_Name'Range loop
799 if Is_Directory_Separator (Exec_Name (J)) then
800 return Get_Install_Dir (Exec_Name);
804 -- If we come here, the user has typed the executable name with no
807 return Get_Install_Dir (GNAT.OS_Lib.Locate_Exec_On_Path (Exec_Name).all);
808 end Executable_Prefix;
814 procedure Exit_Program (Exit_Code : Exit_Code_Type) is
816 -- The program will exit with the following status:
817 -- 0 if the object file has been generated (with or without warnings)
818 -- 1 if recompilation was not needed (smart recompilation)
819 -- 2 if gnat1 has been killed by a signal (detected by GCC)
820 -- 4 for a fatal error
821 -- 5 if there were errors
822 -- 6 if no code has been generated (spec)
824 -- Note that exit code 3 is not used and must not be used as this is
825 -- the code returned by a program aborted via C abort() routine on
826 -- Windows. GCC checks for that case and thinks that the child process
827 -- has been aborted. This code (exit code 3) used to be the code used
828 -- for E_No_Code, but E_No_Code was changed to 6 for this reason.
831 when E_Success => OS_Exit (0);
832 when E_Warnings => OS_Exit (0);
833 when E_No_Compile => OS_Exit (1);
834 when E_Fatal => OS_Exit (4);
835 when E_Errors => OS_Exit (5);
836 when E_No_Code => OS_Exit (6);
837 when E_Abort => OS_Abort;
845 procedure Fail (S1 : String; S2 : String := ""; S3 : String := "") is
847 -- We use Output in case there is a special output set up.
848 -- In this case Set_Standard_Error will have no immediate effect.
851 Osint.Write_Program_Name;
858 Exit_Program (E_Fatal);
865 function File_Hash (F : File_Name_Type) return File_Hash_Num is
867 return File_Hash_Num (Int (F) rem File_Hash_Num'Range_Length);
874 function File_Stamp (Name : File_Name_Type) return Time_Stamp_Type is
876 if Name = No_File then
877 return Empty_Time_Stamp;
880 Get_Name_String (Name);
882 if not Is_Regular_File (Name_Buffer (1 .. Name_Len)) then
883 return Empty_Time_Stamp;
885 Name_Buffer (Name_Len + 1) := ASCII.NUL;
886 return OS_Time_To_GNAT_Time (File_Time_Stamp (Name_Buffer));
896 T : File_Type) return File_Name_Type
902 File_Name : String renames Name_Buffer (1 .. Name_Len);
903 File : File_Name_Type := No_File;
907 -- If we are looking for a config file, look only in the current
908 -- directory, i.e. return input argument unchanged. Also look
909 -- only in the current directory if we are looking for a .dg
910 -- file (happens in -gnatD mode)
913 or else (Debug_Generated_Code
914 and then Name_Len > 3
916 (Name_Buffer (Name_Len - 2 .. Name_Len) = ".dg"
918 (Hostparm.OpenVMS and then
919 Name_Buffer (Name_Len - 2 .. Name_Len) = "_dg")))
923 -- If we are trying to find the current main file just look in the
924 -- directory where the user said it was.
926 elsif Look_In_Primary_Directory_For_Current_Main
927 and then Current_Main = N
929 return Locate_File (N, T, Primary_Directory, File_Name);
931 -- Otherwise do standard search for source file
934 -- Check the mapping of this file name
936 File := Mapped_Path_Name (N);
938 -- If the file name is mapped to a path name, return the
939 -- corresponding path name
941 if File /= No_File then
942 -- For locally removed file, Error_Name is returned; then
943 -- return No_File, indicating the file is not a source.
945 if File = Error_Name then
953 -- First place to look is in the primary directory (i.e. the same
954 -- directory as the source) unless this has been disabled with -I-
956 if Opt.Look_In_Primary_Dir then
957 File := Locate_File (N, T, Primary_Directory, File_Name);
959 if File /= No_File then
964 -- Finally look in directories specified with switches -I/-aI/-aO
967 Last_Dir := Lib_Search_Directories.Last;
969 Last_Dir := Src_Search_Directories.Last;
972 for D in Primary_Directory + 1 .. Last_Dir loop
973 File := Locate_File (N, T, D, File_Name);
975 if File /= No_File then
985 -----------------------
986 -- Find_Program_Name --
987 -----------------------
989 procedure Find_Program_Name is
990 Command_Name : String (1 .. Len_Arg (0));
991 Cindex1 : Integer := Command_Name'First;
992 Cindex2 : Integer := Command_Name'Last;
995 Fill_Arg (Command_Name'Address, 0);
997 -- The program name might be specified by a full path name. However,
998 -- we don't want to print that all out in an error message, so the
999 -- path might need to be stripped away.
1001 for J in reverse Cindex1 .. Cindex2 loop
1002 if Is_Directory_Separator (Command_Name (J)) then
1008 for J in reverse Cindex1 .. Cindex2 loop
1009 if Command_Name (J) = '.' then
1015 Name_Len := Cindex2 - Cindex1 + 1;
1016 Name_Buffer (1 .. Name_Len) := Command_Name (Cindex1 .. Cindex2);
1017 end Find_Program_Name;
1019 ------------------------
1020 -- Full_Lib_File_Name --
1021 ------------------------
1023 function Full_Lib_File_Name (N : File_Name_Type) return File_Name_Type is
1025 return Find_File (N, Library);
1026 end Full_Lib_File_Name;
1028 ----------------------------
1029 -- Full_Library_Info_Name --
1030 ----------------------------
1032 function Full_Library_Info_Name return File_Name_Type is
1034 return Current_Full_Lib_Name;
1035 end Full_Library_Info_Name;
1037 ---------------------------
1038 -- Full_Object_File_Name --
1039 ---------------------------
1041 function Full_Object_File_Name return File_Name_Type is
1043 return Current_Full_Obj_Name;
1044 end Full_Object_File_Name;
1046 ----------------------
1047 -- Full_Source_Name --
1048 ----------------------
1050 function Full_Source_Name return File_Name_Type is
1052 return Current_Full_Source_Name;
1053 end Full_Source_Name;
1055 ----------------------
1056 -- Full_Source_Name --
1057 ----------------------
1059 function Full_Source_Name (N : File_Name_Type) return File_Name_Type is
1061 return Smart_Find_File (N, Source);
1062 end Full_Source_Name;
1068 function Get_Directory (Name : File_Name_Type) return File_Name_Type is
1070 Get_Name_String (Name);
1072 for J in reverse 1 .. Name_Len loop
1073 if Is_Directory_Separator (Name_Buffer (J)) then
1079 Name_Len := Hostparm.Normalized_CWD'Length;
1080 Name_Buffer (1 .. Name_Len) := Hostparm.Normalized_CWD;
1084 --------------------------
1085 -- Get_Next_Dir_In_Path --
1086 --------------------------
1088 Search_Path_Pos : Integer;
1089 -- Keeps track of current position in search path. Initialized by the
1090 -- call to Get_Next_Dir_In_Path_Init, updated by Get_Next_Dir_In_Path.
1092 function Get_Next_Dir_In_Path
1093 (Search_Path : String_Access) return String_Access
1095 Lower_Bound : Positive := Search_Path_Pos;
1096 Upper_Bound : Positive;
1100 while Lower_Bound <= Search_Path'Last
1101 and then Search_Path.all (Lower_Bound) = Path_Separator
1103 Lower_Bound := Lower_Bound + 1;
1106 exit when Lower_Bound > Search_Path'Last;
1108 Upper_Bound := Lower_Bound;
1109 while Upper_Bound <= Search_Path'Last
1110 and then Search_Path.all (Upper_Bound) /= Path_Separator
1112 Upper_Bound := Upper_Bound + 1;
1115 Search_Path_Pos := Upper_Bound;
1116 return new String'(Search_Path.all (Lower_Bound .. Upper_Bound - 1));
1120 end Get_Next_Dir_In_Path;
1122 -------------------------------
1123 -- Get_Next_Dir_In_Path_Init --
1124 -------------------------------
1126 procedure Get_Next_Dir_In_Path_Init (Search_Path : String_Access) is
1128 Search_Path_Pos := Search_Path'First;
1129 end Get_Next_Dir_In_Path_Init;
1131 --------------------------------------
1132 -- Get_Primary_Src_Search_Directory --
1133 --------------------------------------
1135 function Get_Primary_Src_Search_Directory return String_Ptr is
1137 return Src_Search_Directories.Table (Primary_Directory);
1138 end Get_Primary_Src_Search_Directory;
1140 -------------------------
1141 -- Get_RTS_Search_Dir --
1142 -------------------------
1144 function Get_RTS_Search_Dir
1145 (Search_Dir : String;
1146 File_Type : Search_File_Type) return String_Ptr
1148 procedure Get_Current_Dir
1149 (Dir : System.Address;
1150 Length : System.Address);
1151 pragma Import (C, Get_Current_Dir, "__gnat_get_current_dir");
1154 pragma Import (C, Max_Path, "__gnat_max_path_len");
1155 -- Maximum length of a path name
1157 Current_Dir : String_Ptr;
1158 Default_Search_Dir : String_Access;
1159 Default_Suffix_Dir : String_Access;
1160 Local_Search_Dir : String_Access;
1161 Norm_Search_Dir : String_Access;
1162 Result_Search_Dir : String_Access;
1163 Search_File : String_Access;
1164 Temp_String : String_Ptr;
1167 -- Add a directory separator at the end of the directory if necessary
1168 -- so that we can directly append a file to the directory
1170 if Search_Dir (Search_Dir'Last) /= Directory_Separator then
1171 Local_Search_Dir := new String'
1172 (Concat (Search_Dir, String'(1 => Directory_Separator)));
1174 Local_Search_Dir := new String'(Search_Dir);
1177 if File_Type = Include then
1178 Search_File := Include_Search_File;
1179 Default_Suffix_Dir := new String'("adainclude");
1181 Search_File := Objects_Search_File;
1182 Default_Suffix_Dir := new String'("adalib");
1185 Norm_Search_Dir := To_Canonical_Path_Spec (Local_Search_Dir.all);
1187 if Is_Absolute_Path (Norm_Search_Dir.all) then
1189 -- We first verify if there is a directory Include_Search_Dir
1190 -- containing default search directories
1193 := Read_Default_Search_Dirs (Norm_Search_Dir,
1196 Default_Search_Dir := new String'
1197 (Concat (Norm_Search_Dir.all, Default_Suffix_Dir.all));
1198 Free (Norm_Search_Dir);
1200 if Result_Search_Dir /= null then
1201 return String_Ptr (Result_Search_Dir);
1202 elsif Is_Directory (Default_Search_Dir.all) then
1203 return String_Ptr (Default_Search_Dir);
1209 -- Search in the current directory
1211 -- Get the current directory
1214 Buffer : String (1 .. Max_Path + 2);
1215 Path_Len : Natural := Max_Path;
1218 Get_Current_Dir (Buffer'Address, Path_Len'Address);
1220 if Buffer (Path_Len) /= Directory_Separator then
1221 Path_Len := Path_Len + 1;
1222 Buffer (Path_Len) := Directory_Separator;
1225 Current_Dir := new String'(Buffer (1 .. Path_Len));
1229 new String'(Concat (Current_Dir.all, Local_Search_Dir.all));
1231 Result_Search_Dir :=
1232 Read_Default_Search_Dirs (Norm_Search_Dir, Search_File, null);
1234 Default_Search_Dir :=
1236 (Concat (Norm_Search_Dir.all, Default_Suffix_Dir.all));
1238 Free (Norm_Search_Dir);
1240 if Result_Search_Dir /= null then
1241 return String_Ptr (Result_Search_Dir);
1243 elsif Is_Directory (Default_Search_Dir.all) then
1244 return String_Ptr (Default_Search_Dir);
1247 -- Search in Search_Dir_Prefix/Search_Dir
1251 (Concat (Update_Path (Search_Dir_Prefix).all,
1252 Local_Search_Dir.all));
1254 Result_Search_Dir :=
1255 Read_Default_Search_Dirs (Norm_Search_Dir, Search_File, null);
1257 Default_Search_Dir :=
1259 (Concat (Norm_Search_Dir.all, Default_Suffix_Dir.all));
1261 Free (Norm_Search_Dir);
1263 if Result_Search_Dir /= null then
1264 return String_Ptr (Result_Search_Dir);
1266 elsif Is_Directory (Default_Search_Dir.all) then
1267 return String_Ptr (Default_Search_Dir);
1270 -- We finally search in Search_Dir_Prefix/rts-Search_Dir
1274 (Concat (Update_Path (Search_Dir_Prefix).all, "rts-"));
1277 new String'(Concat (Temp_String.all, Local_Search_Dir.all));
1279 Result_Search_Dir :=
1280 Read_Default_Search_Dirs (Norm_Search_Dir, Search_File, null);
1282 Default_Search_Dir :=
1284 (Concat (Norm_Search_Dir.all, Default_Suffix_Dir.all));
1285 Free (Norm_Search_Dir);
1287 if Result_Search_Dir /= null then
1288 return String_Ptr (Result_Search_Dir);
1290 elsif Is_Directory (Default_Search_Dir.all) then
1291 return String_Ptr (Default_Search_Dir);
1299 end Get_RTS_Search_Dir;
1301 --------------------------------
1302 -- Include_Dir_Default_Prefix --
1303 --------------------------------
1305 function Include_Dir_Default_Prefix return String is
1306 Include_Dir : String_Access :=
1307 String_Access (Update_Path (Include_Dir_Default_Name));
1310 if Include_Dir = null then
1315 Result : constant String := Include_Dir.all;
1321 end Include_Dir_Default_Prefix;
1327 procedure Initialize is
1329 Number_File_Names := 0;
1330 Current_File_Name_Index := 0;
1332 Src_Search_Directories.Init;
1333 Lib_Search_Directories.Init;
1335 -- Start off by setting all suppress options to False, these will
1336 -- be reset later (turning some on if -gnato is not specified, and
1337 -- turning all of them on if -gnatp is specified).
1339 Suppress_Options := (others => False);
1341 -- Reserve the first slot in the search paths table. This is the
1342 -- directory of the main source file or main library file and is
1343 -- filled in by each call to Next_Main_Source/Next_Main_Lib_File with
1344 -- the directory specified for this main source or library file. This
1345 -- is the directory which is searched first by default. This default
1346 -- search is inhibited by the option -I- for both source and library
1349 Src_Search_Directories.Set_Last (Primary_Directory);
1350 Src_Search_Directories.Table (Primary_Directory) := new String'("");
1352 Lib_Search_Directories.Set_Last (Primary_Directory);
1353 Lib_Search_Directories.Table (Primary_Directory) := new String'("");
1356 ----------------------------
1357 -- Is_Directory_Separator --
1358 ----------------------------
1360 function Is_Directory_Separator (C : Character) return Boolean is
1362 -- In addition to the default directory_separator allow the '/' to
1363 -- act as separator since this is allowed in MS-DOS, Windows 95/NT,
1364 -- and OS2 ports. On VMS, the situation is more complicated because
1365 -- there are two characters to check for.
1368 C = Directory_Separator
1370 or else (Hostparm.OpenVMS
1371 and then (C = ']' or else C = ':'));
1372 end Is_Directory_Separator;
1374 -------------------------
1375 -- Is_Readonly_Library --
1376 -------------------------
1378 function Is_Readonly_Library (File : in File_Name_Type) return Boolean is
1380 Get_Name_String (File);
1382 pragma Assert (Name_Buffer (Name_Len - 3 .. Name_Len) = ".ali");
1384 return not Is_Writable_File (Name_Buffer (1 .. Name_Len));
1385 end Is_Readonly_Library;
1391 function Lib_File_Name
1392 (Source_File : File_Name_Type)
1393 return File_Name_Type
1396 -- Pointer to location to set extension in place
1399 Get_Name_String (Source_File);
1400 Fptr := Name_Len + 1;
1402 for J in reverse 2 .. Name_Len loop
1403 if Name_Buffer (J) = '.' then
1409 Name_Buffer (Fptr) := '.';
1410 Name_Buffer (Fptr + 1 .. Fptr + ALI_Suffix'Length) := ALI_Suffix.all;
1411 Name_Buffer (Fptr + ALI_Suffix'Length + 1) := ASCII.NUL;
1412 Name_Len := Fptr + ALI_Suffix'Length;
1416 ------------------------
1417 -- Library_File_Stamp --
1418 ------------------------
1420 function Library_File_Stamp (N : File_Name_Type) return Time_Stamp_Type is
1422 return File_Stamp (Find_File (N, Library));
1423 end Library_File_Stamp;
1429 function Locate_File
1430 (N : File_Name_Type;
1433 Name : String) return File_Name_Type
1435 Dir_Name : String_Ptr;
1438 -- If Name is already an absolute path, do not look for a directory
1440 if Is_Absolute_Path (Name) then
1443 elsif T = Library then
1444 Dir_Name := Lib_Search_Directories.Table (Dir);
1446 else pragma Assert (T /= Config);
1447 Dir_Name := Src_Search_Directories.Table (Dir);
1451 Full_Name : String (1 .. Dir_Name'Length + Name'Length);
1454 Full_Name (1 .. Dir_Name'Length) := Dir_Name.all;
1455 Full_Name (Dir_Name'Length + 1 .. Full_Name'Length) := Name;
1457 if not Is_Regular_File (Full_Name) then
1461 -- If the file is in the current directory then return N itself
1463 if Dir_Name'Length = 0 then
1466 Name_Len := Full_Name'Length;
1467 Name_Buffer (1 .. Name_Len) := Full_Name;
1474 -------------------------------
1475 -- Matching_Full_Source_Name --
1476 -------------------------------
1478 function Matching_Full_Source_Name
1479 (N : File_Name_Type;
1480 T : Time_Stamp_Type) return File_Name_Type
1483 Get_Name_String (N);
1486 File_Name : constant String := Name_Buffer (1 .. Name_Len);
1487 File : File_Name_Type := No_File;
1491 if Opt.Look_In_Primary_Dir then
1492 File := Locate_File (N, Source, Primary_Directory, File_Name);
1494 if File /= No_File and then T = File_Stamp (N) then
1499 Last_Dir := Src_Search_Directories.Last;
1501 for D in Primary_Directory + 1 .. Last_Dir loop
1502 File := Locate_File (N, Source, D, File_Name);
1504 if File /= No_File and then T = File_Stamp (File) then
1511 end Matching_Full_Source_Name;
1517 function More_Files return Boolean is
1519 return (Current_File_Name_Index < Number_File_Names);
1522 -------------------------------
1523 -- Nb_Dir_In_Obj_Search_Path --
1524 -------------------------------
1526 function Nb_Dir_In_Obj_Search_Path return Natural is
1528 if Opt.Look_In_Primary_Dir then
1529 return Lib_Search_Directories.Last - Primary_Directory + 1;
1531 return Lib_Search_Directories.Last - Primary_Directory;
1533 end Nb_Dir_In_Obj_Search_Path;
1535 -------------------------------
1536 -- Nb_Dir_In_Src_Search_Path --
1537 -------------------------------
1539 function Nb_Dir_In_Src_Search_Path return Natural is
1541 if Opt.Look_In_Primary_Dir then
1542 return Src_Search_Directories.Last - Primary_Directory + 1;
1544 return Src_Search_Directories.Last - Primary_Directory;
1546 end Nb_Dir_In_Src_Search_Path;
1548 --------------------
1549 -- Next_Main_File --
1550 --------------------
1552 function Next_Main_File return File_Name_Type is
1553 File_Name : String_Ptr;
1554 Dir_Name : String_Ptr;
1558 pragma Assert (More_Files);
1560 Current_File_Name_Index := Current_File_Name_Index + 1;
1562 -- Get the file and directory name
1564 File_Name := File_Names (Current_File_Name_Index);
1565 Fptr := File_Name'First;
1567 for J in reverse File_Name'Range loop
1568 if File_Name (J) = Directory_Separator
1569 or else File_Name (J) = '/'
1571 if J = File_Name'Last then
1572 Fail ("File name missing");
1580 -- Save name of directory in which main unit resides for use in
1581 -- locating other units
1583 Dir_Name := new String'(File_Name (File_Name'First .. Fptr - 1));
1585 case Running_Program is
1588 Src_Search_Directories.Table (Primary_Directory) := Dir_Name;
1589 Look_In_Primary_Directory_For_Current_Main := True;
1592 Src_Search_Directories.Table (Primary_Directory) := Dir_Name;
1594 if Fptr > File_Name'First then
1595 Look_In_Primary_Directory_For_Current_Main := True;
1598 when Binder | Gnatls =>
1599 Dir_Name := Normalize_Directory_Name (Dir_Name.all);
1600 Lib_Search_Directories.Table (Primary_Directory) := Dir_Name;
1606 Name_Len := File_Name'Last - Fptr + 1;
1607 Name_Buffer (1 .. Name_Len) := File_Name (Fptr .. File_Name'Last);
1608 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1609 Current_Main := File_Name_Type (Name_Find);
1611 -- In the gnatmake case, the main file may have not have the
1612 -- extension. Try ".adb" first then ".ads"
1614 if Running_Program = Make then
1616 Orig_Main : constant File_Name_Type := Current_Main;
1619 if Strip_Suffix (Orig_Main) = Orig_Main then
1620 Current_Main := Append_Suffix_To_File_Name (Orig_Main, ".adb");
1622 if Full_Source_Name (Current_Main) = No_File then
1624 Append_Suffix_To_File_Name (Orig_Main, ".ads");
1626 if Full_Source_Name (Current_Main) = No_File then
1627 Current_Main := Orig_Main;
1634 return Current_Main;
1637 ------------------------------
1638 -- Normalize_Directory_Name --
1639 ------------------------------
1641 function Normalize_Directory_Name (Directory : String) return String_Ptr is
1643 function Is_Quoted (Path : String) return Boolean;
1644 pragma Inline (Is_Quoted);
1645 -- Returns true if Path is quoted (either double or single quotes)
1651 function Is_Quoted (Path : String) return Boolean is
1652 First : constant Character := Path (Path'First);
1653 Last : constant Character := Path (Path'Last);
1656 if (First = ''' and then Last = ''')
1658 (First = '"' and then Last = '"')
1666 Result : String_Ptr;
1668 -- Start of processing for Normalize_Directory_Name
1671 if Directory'Length = 0 then
1672 Result := new String'(Hostparm.Normalized_CWD);
1674 elsif Is_Directory_Separator (Directory (Directory'Last)) then
1675 Result := new String'(Directory);
1677 elsif Is_Quoted (Directory) then
1679 -- This is a quoted string, it certainly means that the directory
1680 -- contains some spaces for example. We can safely remove the quotes
1681 -- here as the OS_Lib.Normalize_Arguments will be called before any
1682 -- spawn routines. This ensure that quotes will be added when needed.
1684 Result := new String (1 .. Directory'Length - 1);
1685 Result (1 .. Directory'Length - 1) :=
1686 Directory (Directory'First + 1 .. Directory'Last - 1);
1687 Result (Result'Last) := Directory_Separator;
1690 Result := new String (1 .. Directory'Length + 1);
1691 Result (1 .. Directory'Length) := Directory;
1692 Result (Directory'Length + 1) := Directory_Separator;
1696 end Normalize_Directory_Name;
1698 ---------------------
1699 -- Number_Of_Files --
1700 ---------------------
1702 function Number_Of_Files return Int is
1704 return Number_File_Names;
1705 end Number_Of_Files;
1707 -------------------------------
1708 -- Object_Dir_Default_Prefix --
1709 -------------------------------
1711 function Object_Dir_Default_Prefix return String is
1712 Object_Dir : String_Access :=
1713 String_Access (Update_Path (Object_Dir_Default_Name));
1716 if Object_Dir = null then
1721 Result : constant String := Object_Dir.all;
1727 end Object_Dir_Default_Prefix;
1729 ----------------------
1730 -- Object_File_Name --
1731 ----------------------
1733 function Object_File_Name (N : File_Name_Type) return File_Name_Type is
1739 Get_Name_String (N);
1740 Name_Len := Name_Len - ALI_Suffix'Length - 1;
1742 for J in Object_Suffix'Range loop
1743 Name_Len := Name_Len + 1;
1744 Name_Buffer (Name_Len) := Object_Suffix (J);
1748 end Object_File_Name;
1750 --------------------------
1751 -- OS_Time_To_GNAT_Time --
1752 --------------------------
1754 function OS_Time_To_GNAT_Time (T : OS_Time) return Time_Stamp_Type is
1755 GNAT_Time : Time_Stamp_Type;
1765 GM_Split (T, Y, Mo, D, H, Mn, S);
1771 Minutes => Nat (Mn),
1776 end OS_Time_To_GNAT_Time;
1782 function Program_Name (Nam : String) return String_Access is
1783 Res : String_Access;
1786 -- Get the name of the current program being executed
1790 -- Find the target prefix if any, for the cross compilation case
1791 -- for instance in "alpha-dec-vxworks-gcc" the target prefix is
1792 -- "alpha-dec-vxworks-"
1794 while Name_Len > 0 loop
1795 if Name_Buffer (Name_Len) = '-' then
1799 Name_Len := Name_Len - 1;
1802 -- Create the new program name
1804 Res := new String (1 .. Name_Len + Nam'Length);
1805 Res.all (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
1806 Res.all (Name_Len + 1 .. Name_Len + Nam'Length) := Nam;
1810 ------------------------------
1811 -- Read_Default_Search_Dirs --
1812 ------------------------------
1814 function Read_Default_Search_Dirs
1815 (Search_Dir_Prefix : String_Access;
1816 Search_File : String_Access;
1817 Search_Dir_Default_Name : String_Access) return String_Access
1819 Prefix_Len : constant Integer := Search_Dir_Prefix.all'Length;
1820 Buffer : String (1 .. Prefix_Len + Search_File.all'Length + 1);
1821 File_FD : File_Descriptor;
1822 S, S1 : String_Access;
1825 Actual_Len : Integer;
1828 Prev_Was_Separator : Boolean;
1829 Nb_Relative_Dir : Integer;
1831 function Is_Relative (S : String; K : Positive) return Boolean;
1832 pragma Inline (Is_Relative);
1833 -- Returns True if a relative directory specification is found
1834 -- in S at position K, False otherwise.
1840 function Is_Relative (S : String; K : Positive) return Boolean is
1842 return not Is_Absolute_Path (S (K .. S'Last));
1845 -- Start of processing for Read_Default_Search_Dirs
1848 -- Construct a C compatible character string buffer.
1850 Buffer (1 .. Search_Dir_Prefix.all'Length)
1851 := Search_Dir_Prefix.all;
1852 Buffer (Search_Dir_Prefix.all'Length + 1 .. Buffer'Last - 1)
1854 Buffer (Buffer'Last) := ASCII.NUL;
1856 File_FD := Open_Read (Buffer'Address, Binary);
1857 if File_FD = Invalid_FD then
1858 return Search_Dir_Default_Name;
1861 Len := Integer (File_Length (File_FD));
1863 -- An extra character for a trailing Path_Separator is allocated
1865 S := new String (1 .. Len + 1);
1866 S (Len + 1) := Path_Separator;
1868 -- Read the file. Note that the loop is not necessary since the
1869 -- whole file is read at once except on VMS.
1873 while Actual_Len /= 0 loop
1874 Actual_Len := Read (File_FD, S (Curr)'Address, Len);
1875 Curr := Curr + Actual_Len;
1878 -- Process the file, translating line and file ending
1879 -- control characters to a path separator character.
1881 Prev_Was_Separator := True;
1882 Nb_Relative_Dir := 0;
1883 for J in 1 .. Len loop
1884 if S (J) in ASCII.NUL .. ASCII.US
1887 S (J) := Path_Separator;
1890 if S (J) = Path_Separator then
1891 Prev_Was_Separator := True;
1893 if Prev_Was_Separator and then Is_Relative (S.all, J) then
1894 Nb_Relative_Dir := Nb_Relative_Dir + 1;
1897 Prev_Was_Separator := False;
1901 if Nb_Relative_Dir = 0 then
1905 -- Add the Search_Dir_Prefix to all relative paths
1907 S1 := new String (1 .. S'Length + Nb_Relative_Dir * Prefix_Len);
1909 Prev_Was_Separator := True;
1910 for J in 1 .. Len + 1 loop
1911 if S (J) = Path_Separator then
1912 Prev_Was_Separator := True;
1915 if Prev_Was_Separator and then Is_Relative (S.all, J) then
1916 S1 (J1 .. J1 + Prefix_Len - 1) := Search_Dir_Prefix.all;
1917 J1 := J1 + Prefix_Len;
1920 Prev_Was_Separator := False;
1928 end Read_Default_Search_Dirs;
1930 -----------------------
1931 -- Read_Library_Info --
1932 -----------------------
1934 function Read_Library_Info
1935 (Lib_File : File_Name_Type;
1936 Fatal_Err : Boolean := False) return Text_Buffer_Ptr
1938 Lib_FD : File_Descriptor;
1939 -- The file descriptor for the current library file. A negative value
1940 -- indicates failure to open the specified source file.
1942 Text : Text_Buffer_Ptr;
1943 -- Allocated text buffer.
1946 -- For the calls to Close
1949 Current_Full_Lib_Name := Find_File (Lib_File, Library);
1950 Current_Full_Obj_Name := Object_File_Name (Current_Full_Lib_Name);
1952 if Current_Full_Lib_Name = No_File then
1954 Fail ("Cannot find: ", Name_Buffer (1 .. Name_Len));
1956 Current_Full_Obj_Stamp := Empty_Time_Stamp;
1961 Get_Name_String (Current_Full_Lib_Name);
1962 Name_Buffer (Name_Len + 1) := ASCII.NUL;
1964 -- Open the library FD, note that we open in binary mode, because as
1965 -- documented in the spec, the caller is expected to handle either
1966 -- DOS or Unix mode files, and there is no point in wasting time on
1967 -- text translation when it is not required.
1969 Lib_FD := Open_Read (Name_Buffer'Address, Binary);
1971 if Lib_FD = Invalid_FD then
1973 Fail ("Cannot open: ", Name_Buffer (1 .. Name_Len));
1975 Current_Full_Obj_Stamp := Empty_Time_Stamp;
1980 -- Check for object file consistency if requested
1982 if Opt.Check_Object_Consistency then
1983 Current_Full_Lib_Stamp := File_Stamp (Current_Full_Lib_Name);
1984 Current_Full_Obj_Stamp := File_Stamp (Current_Full_Obj_Name);
1986 if Current_Full_Obj_Stamp (1) = ' ' then
1988 -- When the library is readonly, always assume that
1989 -- the object is consistent.
1991 if Is_Readonly_Library (Current_Full_Lib_Name) then
1992 Current_Full_Obj_Stamp := Current_Full_Lib_Stamp;
1994 elsif Fatal_Err then
1995 Get_Name_String (Current_Full_Obj_Name);
1996 Close (Lib_FD, Status);
1997 -- No need to check the status, we fail anyway
1999 Fail ("Cannot find: ", Name_Buffer (1 .. Name_Len));
2002 Current_Full_Obj_Stamp := Empty_Time_Stamp;
2003 Close (Lib_FD, Status);
2004 -- No need to check the status, we return null anyway
2010 -- Object file exists, compare object and ALI time stamps
2012 if Current_Full_Lib_Stamp > Current_Full_Obj_Stamp then
2014 Get_Name_String (Current_Full_Obj_Name);
2015 Close (Lib_FD, Status);
2016 -- No need to check the status, we fail anyway
2017 Fail ("Bad time stamp: ", Name_Buffer (1 .. Name_Len));
2019 Current_Full_Obj_Stamp := Empty_Time_Stamp;
2020 Close (Lib_FD, Status);
2021 -- No need to check the status, we return null anyway
2028 -- Read data from the file
2031 Len : constant Integer := Integer (File_Length (Lib_FD));
2032 -- Length of source file text. If it doesn't fit in an integer
2033 -- we're probably stuck anyway (>2 gigs of source seems a lot!)
2035 Actual_Len : Integer := 0;
2037 Lo : constant Text_Ptr := 0;
2038 -- Low bound for allocated text buffer
2040 Hi : Text_Ptr := Text_Ptr (Len);
2041 -- High bound for allocated text buffer. Note length is Len + 1
2042 -- which allows for extra EOF character at the end of the buffer.
2045 -- Allocate text buffer. Note extra character at end for EOF
2047 Text := new Text_Buffer (Lo .. Hi);
2049 -- Some systems (e.g. VMS) have file types that require one
2050 -- read per line, so read until we get the Len bytes or until
2051 -- there are no more characters.
2055 Actual_Len := Read (Lib_FD, Text (Hi)'Address, Len);
2056 Hi := Hi + Text_Ptr (Actual_Len);
2057 exit when Actual_Len = Len or Actual_Len <= 0;
2063 -- Read is complete, close file and we are done
2065 Close (Lib_FD, Status);
2066 -- The status should never be False. But, if it is, what can we do?
2067 -- So, we don't test it.
2071 end Read_Library_Info;
2073 ----------------------
2074 -- Read_Source_File --
2075 ----------------------
2077 procedure Read_Source_File
2078 (N : File_Name_Type;
2080 Hi : out Source_Ptr;
2081 Src : out Source_Buffer_Ptr;
2082 T : File_Type := Source)
2084 Source_File_FD : File_Descriptor;
2085 -- The file descriptor for the current source file. A negative value
2086 -- indicates failure to open the specified source file.
2089 -- Length of file. Assume no more than 2 gigabytes of source!
2091 Actual_Len : Integer;
2094 -- For the call to Close
2097 Current_Full_Source_Name := Find_File (N, T);
2098 Current_Full_Source_Stamp := File_Stamp (Current_Full_Source_Name);
2100 if Current_Full_Source_Name = No_File then
2102 -- If we were trying to access the main file and we could not
2103 -- find it we have an error.
2105 if N = Current_Main then
2106 Get_Name_String (N);
2107 Fail ("Cannot find: ", Name_Buffer (1 .. Name_Len));
2115 Get_Name_String (Current_Full_Source_Name);
2116 Name_Buffer (Name_Len + 1) := ASCII.NUL;
2118 -- Open the source FD, note that we open in binary mode, because as
2119 -- documented in the spec, the caller is expected to handle either
2120 -- DOS or Unix mode files, and there is no point in wasting time on
2121 -- text translation when it is not required.
2123 Source_File_FD := Open_Read (Name_Buffer'Address, Binary);
2125 if Source_File_FD = Invalid_FD then
2131 -- Prepare to read data from the file
2133 Len := Integer (File_Length (Source_File_FD));
2135 -- Set Hi so that length is one more than the physical length,
2136 -- allowing for the extra EOF character at the end of the buffer
2138 Hi := Lo + Source_Ptr (Len);
2140 -- Do the actual read operation
2143 subtype Actual_Source_Buffer is Source_Buffer (Lo .. Hi);
2144 -- Physical buffer allocated
2146 type Actual_Source_Ptr is access Actual_Source_Buffer;
2147 -- This is the pointer type for the physical buffer allocated
2149 Actual_Ptr : Actual_Source_Ptr := new Actual_Source_Buffer;
2150 -- And this is the actual physical buffer
2153 -- Allocate source buffer, allowing extra character at end for EOF
2155 -- Some systems (e.g. VMS) have file types that require one
2156 -- read per line, so read until we get the Len bytes or until
2157 -- there are no more characters.
2161 Actual_Len := Read (Source_File_FD, Actual_Ptr (Hi)'Address, Len);
2162 Hi := Hi + Source_Ptr (Actual_Len);
2163 exit when Actual_Len = Len or Actual_Len <= 0;
2166 Actual_Ptr (Hi) := EOF;
2168 -- Now we need to work out the proper virtual origin pointer to
2169 -- return. This is exactly Actual_Ptr (0)'Address, but we have
2170 -- to be careful to suppress checks to compute this address.
2173 pragma Suppress (All_Checks);
2175 function To_Source_Buffer_Ptr is new
2176 Unchecked_Conversion (Address, Source_Buffer_Ptr);
2179 Src := To_Source_Buffer_Ptr (Actual_Ptr (0)'Address);
2183 -- Read is complete, get time stamp and close file and we are done
2185 Close (Source_File_FD, Status);
2186 -- The status should never be False. But, if it is, what can we do?
2187 -- So, we don't test it.
2189 end Read_Source_File;
2195 function Relocate_Path
2197 Path : String) return String_Ptr
2201 procedure set_std_prefix (S : String; Len : Integer);
2202 pragma Import (C, set_std_prefix);
2205 if Std_Prefix = null then
2206 Std_Prefix := Executable_Prefix;
2208 if Std_Prefix.all /= "" then
2209 -- Remove trailing directory separator when calling set_std_prefix
2211 set_std_prefix (Std_Prefix.all, Std_Prefix'Length - 1);
2215 if Path (Prefix'Range) = Prefix then
2216 if Std_Prefix.all /= "" then
2218 (1 .. Std_Prefix'Length + Path'Last - Prefix'Last);
2219 S (1 .. Std_Prefix'Length) := Std_Prefix.all;
2220 S (Std_Prefix'Length + 1 .. S'Last) :=
2221 Path (Prefix'Last + 1 .. Path'Last);
2226 return new String'(Path);
2233 procedure Set_Program (P : Program_Type) is
2236 Fail ("Set_Program called twice");
2239 Program_Set := True;
2240 Running_Program := P;
2243 ----------------------
2244 -- Smart_File_Stamp --
2245 ----------------------
2247 function Smart_File_Stamp
2248 (N : File_Name_Type;
2249 T : File_Type) return Time_Stamp_Type
2251 Time_Stamp : Time_Stamp_Type;
2254 if not File_Cache_Enabled then
2255 return File_Stamp (Find_File (N, T));
2258 Time_Stamp := File_Stamp_Hash_Table.Get (N);
2260 if Time_Stamp (1) = ' ' then
2261 Time_Stamp := File_Stamp (Smart_Find_File (N, T));
2262 File_Stamp_Hash_Table.Set (N, Time_Stamp);
2266 end Smart_File_Stamp;
2268 ---------------------
2269 -- Smart_Find_File --
2270 ---------------------
2272 function Smart_Find_File
2273 (N : File_Name_Type;
2274 T : File_Type) return File_Name_Type
2276 Full_File_Name : File_Name_Type;
2279 if not File_Cache_Enabled then
2280 return Find_File (N, T);
2283 Full_File_Name := File_Name_Hash_Table.Get (N);
2285 if Full_File_Name = No_File then
2286 Full_File_Name := Find_File (N, T);
2287 File_Name_Hash_Table.Set (N, Full_File_Name);
2290 return Full_File_Name;
2291 end Smart_Find_File;
2293 ----------------------
2294 -- Source_File_Data --
2295 ----------------------
2297 procedure Source_File_Data (Cache : Boolean) is
2299 File_Cache_Enabled := Cache;
2300 end Source_File_Data;
2302 -----------------------
2303 -- Source_File_Stamp --
2304 -----------------------
2306 function Source_File_Stamp (N : File_Name_Type) return Time_Stamp_Type is
2308 return Smart_File_Stamp (N, Source);
2309 end Source_File_Stamp;
2311 ---------------------
2312 -- Strip_Directory --
2313 ---------------------
2315 function Strip_Directory (Name : File_Name_Type) return File_Name_Type is
2317 Get_Name_String (Name);
2319 for J in reverse 1 .. Name_Len - 1 loop
2320 -- If we find the last directory separator
2322 if Is_Directory_Separator (Name_Buffer (J)) then
2323 -- Return the part of Name that follows this last directory
2326 Name_Buffer (1 .. Name_Len - J) := Name_Buffer (J + 1 .. Name_Len);
2327 Name_Len := Name_Len - J;
2332 -- There were no directory separator, just return Name
2335 end Strip_Directory;
2341 function Strip_Suffix (Name : File_Name_Type) return File_Name_Type is
2343 Get_Name_String (Name);
2345 for J in reverse 2 .. Name_Len loop
2347 -- If we found the last '.', return the part of Name that precedes
2350 if Name_Buffer (J) = '.' then
2359 ---------------------------
2360 -- To_Canonical_Dir_Spec --
2361 ---------------------------
2363 function To_Canonical_Dir_Spec
2365 Prefix_Style : Boolean) return String_Access
2367 function To_Canonical_Dir_Spec
2368 (Host_Dir : Address;
2369 Prefix_Flag : Integer) return Address;
2370 pragma Import (C, To_Canonical_Dir_Spec, "__gnat_to_canonical_dir_spec");
2372 C_Host_Dir : String (1 .. Host_Dir'Length + 1);
2373 Canonical_Dir_Addr : Address;
2374 Canonical_Dir_Len : Integer;
2377 C_Host_Dir (1 .. Host_Dir'Length) := Host_Dir;
2378 C_Host_Dir (C_Host_Dir'Last) := ASCII.NUL;
2380 if Prefix_Style then
2381 Canonical_Dir_Addr := To_Canonical_Dir_Spec (C_Host_Dir'Address, 1);
2383 Canonical_Dir_Addr := To_Canonical_Dir_Spec (C_Host_Dir'Address, 0);
2385 Canonical_Dir_Len := C_String_Length (Canonical_Dir_Addr);
2387 if Canonical_Dir_Len = 0 then
2390 return To_Path_String_Access (Canonical_Dir_Addr, Canonical_Dir_Len);
2395 Fail ("erroneous directory spec: ", Host_Dir);
2397 end To_Canonical_Dir_Spec;
2399 ---------------------------
2400 -- To_Canonical_File_List --
2401 ---------------------------
2403 function To_Canonical_File_List
2404 (Wildcard_Host_File : String;
2405 Only_Dirs : Boolean) return String_Access_List_Access
2407 function To_Canonical_File_List_Init
2408 (Host_File : Address;
2409 Only_Dirs : Integer) return Integer;
2410 pragma Import (C, To_Canonical_File_List_Init,
2411 "__gnat_to_canonical_file_list_init");
2413 function To_Canonical_File_List_Next return Address;
2414 pragma Import (C, To_Canonical_File_List_Next,
2415 "__gnat_to_canonical_file_list_next");
2417 procedure To_Canonical_File_List_Free;
2418 pragma Import (C, To_Canonical_File_List_Free,
2419 "__gnat_to_canonical_file_list_free");
2421 Num_Files : Integer;
2422 C_Wildcard_Host_File : String (1 .. Wildcard_Host_File'Length + 1);
2425 C_Wildcard_Host_File (1 .. Wildcard_Host_File'Length) :=
2427 C_Wildcard_Host_File (C_Wildcard_Host_File'Last) := ASCII.NUL;
2429 -- Do the expansion and say how many there are
2431 Num_Files := To_Canonical_File_List_Init
2432 (C_Wildcard_Host_File'Address, Boolean'Pos (Only_Dirs));
2435 Canonical_File_List : String_Access_List (1 .. Num_Files);
2436 Canonical_File_Addr : Address;
2437 Canonical_File_Len : Integer;
2440 -- Retrieve the expanded directoy names and build the list
2442 for J in 1 .. Num_Files loop
2443 Canonical_File_Addr := To_Canonical_File_List_Next;
2444 Canonical_File_Len := C_String_Length (Canonical_File_Addr);
2445 Canonical_File_List (J) := To_Path_String_Access
2446 (Canonical_File_Addr, Canonical_File_Len);
2449 -- Free up the storage
2451 To_Canonical_File_List_Free;
2453 return new String_Access_List'(Canonical_File_List);
2455 end To_Canonical_File_List;
2457 ----------------------------
2458 -- To_Canonical_File_Spec --
2459 ----------------------------
2461 function To_Canonical_File_Spec
2462 (Host_File : String) return String_Access
2464 function To_Canonical_File_Spec (Host_File : Address) return Address;
2466 (C, To_Canonical_File_Spec, "__gnat_to_canonical_file_spec");
2468 C_Host_File : String (1 .. Host_File'Length + 1);
2469 Canonical_File_Addr : Address;
2470 Canonical_File_Len : Integer;
2473 C_Host_File (1 .. Host_File'Length) := Host_File;
2474 C_Host_File (C_Host_File'Last) := ASCII.NUL;
2476 Canonical_File_Addr := To_Canonical_File_Spec (C_Host_File'Address);
2477 Canonical_File_Len := C_String_Length (Canonical_File_Addr);
2479 if Canonical_File_Len = 0 then
2482 return To_Path_String_Access
2483 (Canonical_File_Addr, Canonical_File_Len);
2488 Fail ("erroneous file spec: ", Host_File);
2490 end To_Canonical_File_Spec;
2492 ----------------------------
2493 -- To_Canonical_Path_Spec --
2494 ----------------------------
2496 function To_Canonical_Path_Spec
2497 (Host_Path : String) return String_Access
2499 function To_Canonical_Path_Spec (Host_Path : Address) return Address;
2501 (C, To_Canonical_Path_Spec, "__gnat_to_canonical_path_spec");
2503 C_Host_Path : String (1 .. Host_Path'Length + 1);
2504 Canonical_Path_Addr : Address;
2505 Canonical_Path_Len : Integer;
2508 C_Host_Path (1 .. Host_Path'Length) := Host_Path;
2509 C_Host_Path (C_Host_Path'Last) := ASCII.NUL;
2511 Canonical_Path_Addr := To_Canonical_Path_Spec (C_Host_Path'Address);
2512 Canonical_Path_Len := C_String_Length (Canonical_Path_Addr);
2514 -- Return a null string (vice a null) for zero length paths, for
2515 -- compatibility with getenv().
2517 return To_Path_String_Access (Canonical_Path_Addr, Canonical_Path_Len);
2521 Fail ("erroneous path spec: ", Host_Path);
2523 end To_Canonical_Path_Spec;
2525 ---------------------------
2526 -- To_Host_Dir_Spec --
2527 ---------------------------
2529 function To_Host_Dir_Spec
2530 (Canonical_Dir : String;
2531 Prefix_Style : Boolean) return String_Access
2533 function To_Host_Dir_Spec
2534 (Canonical_Dir : Address;
2535 Prefix_Flag : Integer) return Address;
2536 pragma Import (C, To_Host_Dir_Spec, "__gnat_to_host_dir_spec");
2538 C_Canonical_Dir : String (1 .. Canonical_Dir'Length + 1);
2539 Host_Dir_Addr : Address;
2540 Host_Dir_Len : Integer;
2543 C_Canonical_Dir (1 .. Canonical_Dir'Length) := Canonical_Dir;
2544 C_Canonical_Dir (C_Canonical_Dir'Last) := ASCII.NUL;
2546 if Prefix_Style then
2547 Host_Dir_Addr := To_Host_Dir_Spec (C_Canonical_Dir'Address, 1);
2549 Host_Dir_Addr := To_Host_Dir_Spec (C_Canonical_Dir'Address, 0);
2551 Host_Dir_Len := C_String_Length (Host_Dir_Addr);
2553 if Host_Dir_Len = 0 then
2556 return To_Path_String_Access (Host_Dir_Addr, Host_Dir_Len);
2558 end To_Host_Dir_Spec;
2560 ----------------------------
2561 -- To_Host_File_Spec --
2562 ----------------------------
2564 function To_Host_File_Spec
2565 (Canonical_File : String) return String_Access
2567 function To_Host_File_Spec (Canonical_File : Address) return Address;
2568 pragma Import (C, To_Host_File_Spec, "__gnat_to_host_file_spec");
2570 C_Canonical_File : String (1 .. Canonical_File'Length + 1);
2571 Host_File_Addr : Address;
2572 Host_File_Len : Integer;
2575 C_Canonical_File (1 .. Canonical_File'Length) := Canonical_File;
2576 C_Canonical_File (C_Canonical_File'Last) := ASCII.NUL;
2578 Host_File_Addr := To_Host_File_Spec (C_Canonical_File'Address);
2579 Host_File_Len := C_String_Length (Host_File_Addr);
2581 if Host_File_Len = 0 then
2584 return To_Path_String_Access
2585 (Host_File_Addr, Host_File_Len);
2587 end To_Host_File_Spec;
2589 ---------------------------
2590 -- To_Path_String_Access --
2591 ---------------------------
2593 function To_Path_String_Access
2594 (Path_Addr : Address;
2595 Path_Len : Integer) return String_Access
2597 subtype Path_String is String (1 .. Path_Len);
2598 type Path_String_Access is access Path_String;
2600 function Address_To_Access is new
2601 Unchecked_Conversion (Source => Address,
2602 Target => Path_String_Access);
2604 Path_Access : constant Path_String_Access :=
2605 Address_To_Access (Path_Addr);
2607 Return_Val : String_Access;
2610 Return_Val := new String (1 .. Path_Len);
2612 for J in 1 .. Path_Len loop
2613 Return_Val (J) := Path_Access (J);
2617 end To_Path_String_Access;
2623 function Update_Path (Path : String_Ptr) return String_Ptr is
2625 function C_Update_Path (Path, Component : Address) return Address;
2626 pragma Import (C, C_Update_Path, "update_path");
2628 function Strlen (Str : Address) return Integer;
2629 pragma Import (C, Strlen, "strlen");
2631 procedure Strncpy (X : Address; Y : Address; Length : Integer);
2632 pragma Import (C, Strncpy, "strncpy");
2634 In_Length : constant Integer := Path'Length;
2635 In_String : String (1 .. In_Length + 1);
2636 Component_Name : aliased String := "GCC" & ASCII.NUL;
2637 Result_Ptr : Address;
2638 Result_Length : Integer;
2639 Out_String : String_Ptr;
2642 In_String (1 .. In_Length) := Path.all;
2643 In_String (In_Length + 1) := ASCII.NUL;
2644 Result_Ptr := C_Update_Path (In_String'Address,
2645 Component_Name'Address);
2646 Result_Length := Strlen (Result_Ptr);
2648 Out_String := new String (1 .. Result_Length);
2649 Strncpy (Out_String.all'Address, Result_Ptr, Result_Length);
2657 procedure Write_Info (Info : String) is
2659 Write_With_Check (Info'Address, Info'Length);
2660 Write_With_Check (EOL'Address, 1);
2663 ------------------------
2664 -- Write_Program_Name --
2665 ------------------------
2667 procedure Write_Program_Name is
2668 Save_Buffer : constant String (1 .. Name_Len) :=
2669 Name_Buffer (1 .. Name_Len);
2675 -- Convert the name to lower case so error messages are the same on
2678 for J in 1 .. Name_Len loop
2679 if Name_Buffer (J) in 'A' .. 'Z' then
2681 Character'Val (Character'Pos (Name_Buffer (J)) + 32);
2685 Write_Str (Name_Buffer (1 .. Name_Len));
2687 -- Restore Name_Buffer which was clobbered by the call to
2688 -- Find_Program_Name
2690 Name_Len := Save_Buffer'Last;
2691 Name_Buffer (1 .. Name_Len) := Save_Buffer;
2692 end Write_Program_Name;
2694 ----------------------
2695 -- Write_With_Check --
2696 ----------------------
2698 procedure Write_With_Check (A : Address; N : Integer) is
2702 if N = Write (Output_FD, A, N) then
2706 Write_Str ("error: disk full writing ");
2707 Write_Name_Decoded (Output_File_Name);
2709 Name_Len := Name_Len + 1;
2710 Name_Buffer (Name_Len) := ASCII.NUL;
2711 Delete_File (Name_Buffer'Address, Ignore);
2712 Exit_Program (E_Fatal);
2714 end Write_With_Check;
2716 ----------------------------
2717 -- Package Initialization --
2718 ----------------------------
2721 Initialization : declare
2723 function Get_Default_Identifier_Character_Set return Character;
2724 pragma Import (C, Get_Default_Identifier_Character_Set,
2725 "__gnat_get_default_identifier_character_set");
2726 -- Function to determine the default identifier character set,
2727 -- which is system dependent. See Opt package spec for a list of
2728 -- the possible character codes and their interpretations.
2730 function Get_Maximum_File_Name_Length return Int;
2731 pragma Import (C, Get_Maximum_File_Name_Length,
2732 "__gnat_get_maximum_file_name_length");
2733 -- Function to get maximum file name length for system
2736 Identifier_Character_Set := Get_Default_Identifier_Character_Set;
2737 Maximum_File_Name_Length := Get_Maximum_File_Name_Length;
2739 -- Following should be removed by having above function return
2740 -- Integer'Last as indication of no maximum instead of -1 ???
2742 if Maximum_File_Name_Length = -1 then
2743 Maximum_File_Name_Length := Int'Last;
2746 Src_Search_Directories.Set_Last (Primary_Directory);
2747 Src_Search_Directories.Table (Primary_Directory) := new String'("");
2749 Lib_Search_Directories.Set_Last (Primary_Directory);
2750 Lib_Search_Directories.Table (Primary_Directory) := new String'("");