1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
31 with Namet; use Namet;
33 with Output; use Output;
34 with Sdefault; use Sdefault;
36 with Tree_IO; use Tree_IO;
38 with Unchecked_Conversion;
40 with GNAT.OS_Lib; use GNAT.OS_Lib;
45 -------------------------------------
46 -- Use of Name_Find and Name_Enter --
47 -------------------------------------
49 -- This package creates a number of source, ALI and object file names
50 -- that are used to locate the actual file and for the purpose of
51 -- message construction. These names need not be accessible by Name_Find,
52 -- and can be therefore created by using routine Name_Enter. The files in
53 -- question are file names with a prefix directory (ie the files not
54 -- in the current directory). File names without a prefix directory are
55 -- entered with Name_Find because special values might be attached to
56 -- the various Info fields of the corresponding name table entry.
58 -----------------------
59 -- Local Subprograms --
60 -----------------------
62 function Append_Suffix_To_File_Name
66 -- Appends Suffix to Name and returns the new name.
68 function OS_Time_To_GNAT_Time (T : OS_Time) return Time_Stamp_Type;
69 -- Convert OS format time to GNAT format time stamp
71 procedure Create_File_And_Check
72 (Fdesc : out File_Descriptor;
74 -- Create file whose name (NUL terminated) is in Name_Buffer (with the
75 -- length in Name_Len), and place the resulting descriptor in Fdesc.
76 -- Issue message and exit with fatal error if file cannot be created.
77 -- The Fmode parameter is set to either Text or Binary (see description
78 -- of GNAT.OS_Lib.Create_File).
80 procedure Set_Library_Info_Name;
81 -- Sets a default ali file name from the main compiler source name.
82 -- This is used by Create_Output_Library_Info, and by the version of
83 -- Read_Library_Info that takes a default file name.
85 procedure Write_Info (Info : String);
86 -- Implementation of Write_Binder_Info, Write_Debug_Info and
87 -- Write_Library_Info (identical)
89 procedure Write_With_Check (A : Address; N : Integer);
90 -- Writes N bytes from buffer starting at address A to file whose FD is
91 -- stored in Output_FD, and whose file name is stored as a File_Name_Type
92 -- in Output_File_Name. A check is made for disk full, and if this is
93 -- detected, the file being written is deleted, and a fatal error is
96 function More_Files return Boolean;
97 -- Implements More_Source_Files and More_Lib_Files.
99 function Next_Main_File return File_Name_Type;
100 -- Implements Next_Main_Source and Next_Main_Lib_File.
107 return File_Name_Type;
108 -- See if the file N whose name is Name exists in directory Dir. Dir is
109 -- an index into the Lib_Search_Directories table if T = Library.
110 -- Otherwise if T = Source, Dir is an index into the
111 -- Src_Search_Directories table. Returns the File_Name_Type of the
112 -- full file name if file found, or No_File if not found.
114 function C_String_Length (S : Address) return Integer;
115 -- Returns length of a C string. Returns zero for a null address.
117 function To_Path_String_Access
118 (Path_Addr : Address;
120 return String_Access;
121 -- Converts a C String to an Ada String. Are we doing this to avoid
122 -- withing Interfaces.C.Strings ???
124 ------------------------------
125 -- Other Local Declarations --
126 ------------------------------
128 ALI_Suffix : constant String_Ptr := new String'("ali");
129 -- The suffix used for the library files (also known as ALI files).
131 Object_Suffix : constant String := Get_Object_Suffix.all;
132 -- The suffix used for the object files.
134 EOL : constant Character := ASCII.LF;
135 -- End of line character
137 Argument_Count : constant Integer := Arg_Count - 1;
138 -- Number of arguments (excluding program name)
140 type File_Name_Array is array (Int range <>) of String_Ptr;
141 type File_Name_Array_Ptr is access File_Name_Array;
142 File_Names : File_Name_Array_Ptr :=
143 new File_Name_Array (1 .. Int (Argument_Count) + 2);
144 -- As arguments are scanned in Initialize, file names are stored
145 -- in this array. The string does not contain a terminating NUL.
146 -- The array is "extensible" because when using project files,
147 -- there may be more file names than argument on the command line.
149 Number_File_Names : Int := 0;
150 -- The total number of file names found on command line and placed in
153 Current_File_Name_Index : Int := 0;
154 -- The index in File_Names of the last file opened by Next_Main_Source
155 -- or Next_Main_Lib_File. The value 0 indicates that no files have been
158 Current_Main : File_Name_Type := No_File;
159 -- Used to save a simple file name between calls to Next_Main_Source and
160 -- Read_Source_File. If the file name argument to Read_Source_File is
161 -- No_File, that indicates that the file whose name was returned by the
162 -- last call to Next_Main_Source (and stored here) is to be read.
164 Look_In_Primary_Directory_For_Current_Main : Boolean := False;
165 -- When this variable is True, Find_File will only look in
166 -- the Primary_Directory for the Current_Main file.
167 -- This variable is always True for the compiler.
168 -- It is also True for gnatmake, when the soucr name given
169 -- on the command line has directory information.
171 Current_Full_Source_Name : File_Name_Type := No_File;
172 Current_Full_Source_Stamp : Time_Stamp_Type := Empty_Time_Stamp;
173 Current_Full_Lib_Name : File_Name_Type := No_File;
174 Current_Full_Lib_Stamp : Time_Stamp_Type := Empty_Time_Stamp;
175 Current_Full_Obj_Name : File_Name_Type := No_File;
176 Current_Full_Obj_Stamp : Time_Stamp_Type := Empty_Time_Stamp;
177 -- Respectively full name (with directory info) and time stamp of
178 -- the latest source, library and object files opened by Read_Source_File
179 -- and Read_Library_Info.
181 Old_Binder_Output_Time_Stamp : Time_Stamp_Type;
182 New_Binder_Output_Time_Stamp : Time_Stamp_Type;
183 Recording_Time_From_Last_Bind : Boolean := False;
184 Binder_Output_Time_Stamps_Set : Boolean := False;
186 In_Binder : Boolean := False;
187 In_Compiler : Boolean := False;
188 In_Make : Boolean := False;
189 -- Exactly one of these flags is set True to indicate which program
190 -- is bound and executing with Osint, which is used by all these programs.
192 Output_FD : File_Descriptor;
193 -- The file descriptor for the current library info, tree or binder output
195 Output_File_Name : File_Name_Type;
196 -- File_Name_Type for name of open file whose FD is in Output_FD, the name
197 -- stored does not include the trailing NUL character.
199 Output_Object_File_Name : String_Ptr;
200 -- Argument of -o compiler option, if given. This is needed to
201 -- verify consistency with the ALI file name.
207 Primary_Directory : constant := 0;
208 -- This is index in the tables created below for the first directory to
209 -- search in for source or library information files. This is the
210 -- directory containing the latest main input file (a source file for
211 -- the compiler or a library file for the binder).
213 package Src_Search_Directories is new Table.Table (
214 Table_Component_Type => String_Ptr,
215 Table_Index_Type => Natural,
216 Table_Low_Bound => Primary_Directory,
218 Table_Increment => 100,
219 Table_Name => "Osint.Src_Search_Directories");
220 -- Table of names of directories in which to search for source (Compiler)
221 -- files. This table is filled in the order in which the directories are
222 -- to be searched, and then used in that order.
224 package Lib_Search_Directories is new Table.Table (
225 Table_Component_Type => String_Ptr,
226 Table_Index_Type => Natural,
227 Table_Low_Bound => Primary_Directory,
229 Table_Increment => 100,
230 Table_Name => "Osint.Lib_Search_Directories");
231 -- Table of names of directories in which to search for library (Binder)
232 -- files. This table is filled in the order in which the directories are
233 -- to be searched and then used in that order. The reason for having two
234 -- distinct tables is that we need them both in gnatmake.
236 ---------------------
237 -- File Hash Table --
238 ---------------------
240 -- The file hash table is provided to free the programmer from any
241 -- efficiency concern when retrieving full file names or time stamps of
242 -- source files. If the programmer calls Source_File_Data (Cache => True)
243 -- he is guaranteed that the price to retrieve the full name (ie with
244 -- directory info) or time stamp of the file will be payed only once,
245 -- the first time the full name is actually searched (or the first time
246 -- the time stamp is actually retrieved). This is achieved by employing
247 -- a hash table that stores as a key the File_Name_Type of the file and
248 -- associates to that File_Name_Type the full file name of the file and its
251 File_Cache_Enabled : Boolean := False;
252 -- Set to true if you want the enable the file data caching mechanism.
254 type File_Hash_Num is range 0 .. 1020;
256 function File_Hash (F : File_Name_Type) return File_Hash_Num;
257 -- Compute hash index for use by Simple_HTable
259 package File_Name_Hash_Table is new GNAT.HTable.Simple_HTable (
260 Header_Num => File_Hash_Num,
261 Element => File_Name_Type,
262 No_Element => No_File,
263 Key => File_Name_Type,
267 package File_Stamp_Hash_Table is new GNAT.HTable.Simple_HTable (
268 Header_Num => File_Hash_Num,
269 Element => Time_Stamp_Type,
270 No_Element => Empty_Time_Stamp,
271 Key => File_Name_Type,
275 function Smart_Find_File
278 return File_Name_Type;
279 -- Exactly like Find_File except that if File_Cache_Enabled is True this
280 -- routine looks first in the hash table to see if the full name of the
281 -- file is already available.
283 function Smart_File_Stamp
286 return Time_Stamp_Type;
287 -- Takes the same parameter as the routine above (N is a file name
288 -- without any prefix directory information) and behaves like File_Stamp
289 -- except that if File_Cache_Enabled is True this routine looks first in
290 -- the hash table to see if the file stamp of the file is already
293 -----------------------------
294 -- Add_Default_Search_Dirs --
295 -----------------------------
297 procedure Add_Default_Search_Dirs is
298 Search_Dir : String_Access;
299 Search_Path : String_Access;
301 procedure Add_Search_Dir
302 (Search_Dir : String_Access;
303 Additional_Source_Dir : Boolean);
304 -- Needs documentation ???
306 function Get_Libraries_From_Registry return String_Ptr;
307 -- On Windows systems, get the list of installed standard libraries
308 -- from the registry key:
309 -- HKEY_LOCAL_MACHINE\SOFTWARE\Ada Core Technologies\
310 -- GNAT\Standard Libraries
311 -- Return an empty string on other systems
313 function Update_Path (Path : String_Ptr) return String_Ptr;
314 -- Update the specified path to replace the prefix with
315 -- the location where GNAT is installed. See the file prefix.c
316 -- in GCC for more details.
322 procedure Add_Search_Dir
323 (Search_Dir : String_Access;
324 Additional_Source_Dir : Boolean)
327 if Additional_Source_Dir then
328 Add_Src_Search_Dir (Search_Dir.all);
330 Add_Lib_Search_Dir (Search_Dir.all);
334 ---------------------------------
335 -- Get_Libraries_From_Registry --
336 ---------------------------------
338 function Get_Libraries_From_Registry return String_Ptr is
339 function C_Get_Libraries_From_Registry return Address;
340 pragma Import (C, C_Get_Libraries_From_Registry,
341 "__gnat_get_libraries_from_registry");
342 function Strlen (Str : Address) return Integer;
343 pragma Import (C, Strlen, "strlen");
344 procedure Strncpy (X : Address; Y : Address; Length : Integer);
345 pragma Import (C, Strncpy, "strncpy");
346 Result_Ptr : Address;
347 Result_Length : Integer;
348 Out_String : String_Ptr;
351 Result_Ptr := C_Get_Libraries_From_Registry;
352 Result_Length := Strlen (Result_Ptr);
354 Out_String := new String (1 .. Result_Length);
355 Strncpy (Out_String.all'Address, Result_Ptr, Result_Length);
357 end Get_Libraries_From_Registry;
363 function Update_Path (Path : String_Ptr) return String_Ptr is
365 function C_Update_Path (Path, Component : Address) return Address;
366 pragma Import (C, C_Update_Path, "update_path");
368 function Strlen (Str : Address) return Integer;
369 pragma Import (C, Strlen, "strlen");
371 procedure Strncpy (X : Address; Y : Address; Length : Integer);
372 pragma Import (C, Strncpy, "strncpy");
374 In_Length : constant Integer := Path'Length;
375 In_String : String (1 .. In_Length + 1);
376 Component_Name : aliased String := "GNAT" & ASCII.NUL;
377 Result_Ptr : Address;
378 Result_Length : Integer;
379 Out_String : String_Ptr;
382 In_String (1 .. In_Length) := Path.all;
383 In_String (In_Length + 1) := ASCII.NUL;
384 Result_Ptr := C_Update_Path (In_String'Address,
385 Component_Name'Address);
386 Result_Length := Strlen (Result_Ptr);
388 Out_String := new String (1 .. Result_Length);
389 Strncpy (Out_String.all'Address, Result_Ptr, Result_Length);
393 -- Start of processing for Add_Default_Search_Dirs
396 -- After the locations specified on the command line, the next places
397 -- to look for files are the directories specified by the appropriate
398 -- environment variable. Get this value, extract the directory names
399 -- and store in the tables.
401 -- On VMS, don't expand the logical name (e.g. environment variable),
402 -- just put it into Unix (e.g. canonical) format. System services
403 -- will handle the expansion as part of the file processing.
405 for Additional_Source_Dir in False .. True loop
407 if Additional_Source_Dir then
408 Search_Path := Getenv ("ADA_INCLUDE_PATH");
409 if Search_Path'Length > 0 then
410 if Hostparm.OpenVMS then
411 Search_Path := To_Canonical_Path_Spec ("ADA_INCLUDE_PATH:");
413 Search_Path := To_Canonical_Path_Spec (Search_Path.all);
417 Search_Path := Getenv ("ADA_OBJECTS_PATH");
418 if Search_Path'Length > 0 then
419 if Hostparm.OpenVMS then
420 Search_Path := To_Canonical_Path_Spec ("ADA_OBJECTS_PATH:");
422 Search_Path := To_Canonical_Path_Spec (Search_Path.all);
427 Get_Next_Dir_In_Path_Init (Search_Path);
429 Search_Dir := Get_Next_Dir_In_Path (Search_Path);
430 exit when Search_Dir = null;
431 Add_Search_Dir (Search_Dir, Additional_Source_Dir);
435 if not Opt.No_Stdinc then
436 -- For WIN32 systems, look for any system libraries defined in
437 -- the registry. These are added to both source and object
440 Search_Path := String_Access (Get_Libraries_From_Registry);
441 Get_Next_Dir_In_Path_Init (Search_Path);
443 Search_Dir := Get_Next_Dir_In_Path (Search_Path);
444 exit when Search_Dir = null;
445 Add_Search_Dir (Search_Dir, False);
446 Add_Search_Dir (Search_Dir, True);
449 -- The last place to look are the defaults
451 Search_Path := Read_Default_Search_Dirs
452 (String_Access (Update_Path (Search_Dir_Prefix)),
454 String_Access (Update_Path (Include_Dir_Default_Name)));
456 Get_Next_Dir_In_Path_Init (Search_Path);
458 Search_Dir := Get_Next_Dir_In_Path (Search_Path);
459 exit when Search_Dir = null;
460 Add_Search_Dir (Search_Dir, True);
464 if not Opt.No_Stdlib then
465 Search_Path := Read_Default_Search_Dirs
466 (String_Access (Update_Path (Search_Dir_Prefix)),
468 String_Access (Update_Path (Object_Dir_Default_Name)));
470 Get_Next_Dir_In_Path_Init (Search_Path);
472 Search_Dir := Get_Next_Dir_In_Path (Search_Path);
473 exit when Search_Dir = null;
474 Add_Search_Dir (Search_Dir, False);
478 end Add_Default_Search_Dirs;
484 procedure Add_File (File_Name : String) is
486 Number_File_Names := Number_File_Names + 1;
488 -- As Add_File may be called for mains specified inside
489 -- a project file, File_Names may be too short and needs
492 if Number_File_Names > File_Names'Last then
493 File_Names := new File_Name_Array'(File_Names.all & File_Names.all);
496 File_Names (Number_File_Names) := new String'(File_Name);
499 ------------------------
500 -- Add_Lib_Search_Dir --
501 ------------------------
503 procedure Add_Lib_Search_Dir (Dir : String) is
505 if Dir'Length = 0 then
506 Fail ("missing library directory name");
509 Lib_Search_Directories.Increment_Last;
510 Lib_Search_Directories.Table (Lib_Search_Directories.Last) :=
511 Normalize_Directory_Name (Dir);
512 end Add_Lib_Search_Dir;
514 ------------------------
515 -- Add_Src_Search_Dir --
516 ------------------------
518 procedure Add_Src_Search_Dir (Dir : String) is
520 if Dir'Length = 0 then
521 Fail ("missing source directory name");
524 Src_Search_Directories.Increment_Last;
525 Src_Search_Directories.Table (Src_Search_Directories.Last) :=
526 Normalize_Directory_Name (Dir);
527 end Add_Src_Search_Dir;
529 --------------------------------
530 -- Append_Suffix_To_File_Name --
531 --------------------------------
533 function Append_Suffix_To_File_Name
539 Get_Name_String (Name);
540 Name_Buffer (Name_Len + 1 .. Name_Len + Suffix'Length) := Suffix;
541 Name_Len := Name_Len + Suffix'Length;
543 end Append_Suffix_To_File_Name;
545 ---------------------
546 -- C_String_Length --
547 ---------------------
549 function C_String_Length (S : Address) return Integer is
550 function Strlen (S : Address) return Integer;
551 pragma Import (C, Strlen, "strlen");
554 if S = Null_Address then
561 ------------------------------
562 -- Canonical_Case_File_Name --
563 ------------------------------
565 -- For now, we only deal with the case of a-z. Eventually we should
566 -- worry about other Latin-1 letters on systems that support this ???
568 procedure Canonical_Case_File_Name (S : in out String) is
570 if not File_Names_Case_Sensitive then
571 for J in S'Range loop
572 if S (J) in 'A' .. 'Z' then
573 S (J) := Character'Val (
574 Character'Pos (S (J)) +
575 Character'Pos ('a') -
576 Character'Pos ('A'));
580 end Canonical_Case_File_Name;
582 -------------------------
583 -- Close_Binder_Output --
584 -------------------------
586 procedure Close_Binder_Output is
588 pragma Assert (In_Binder);
591 if Recording_Time_From_Last_Bind then
592 New_Binder_Output_Time_Stamp := File_Stamp (Output_File_Name);
593 Binder_Output_Time_Stamps_Set := True;
595 end Close_Binder_Output;
597 ----------------------
598 -- Close_Debug_File --
599 ----------------------
601 procedure Close_Debug_File is
603 pragma Assert (In_Compiler);
605 end Close_Debug_File;
607 -------------------------------
608 -- Close_Output_Library_Info --
609 -------------------------------
611 procedure Close_Output_Library_Info is
613 pragma Assert (In_Compiler);
615 end Close_Output_Library_Info;
617 --------------------------
618 -- Create_Binder_Output --
619 --------------------------
621 procedure Create_Binder_Output
622 (Output_File_Name : String;
626 File_Name : String_Ptr;
632 pragma Assert (In_Binder);
634 if Output_File_Name /= "" then
635 Name_Buffer (Output_File_Name'Range) := Output_File_Name;
636 Name_Buffer (Output_File_Name'Last + 1) := ASCII.NUL;
639 Name_Buffer (Output_File_Name'Last) := 's';
642 Name_Len := Output_File_Name'Last;
645 Name_Buffer (1) := 'b';
646 File_Name := File_Names (Current_File_Name_Index);
648 Findex1 := File_Name'First;
650 -- The ali file might be specified by a full path name. However,
651 -- the binder generated file should always be created in the
652 -- current directory, so the path might need to be stripped away.
653 -- In addition to the default directory_separator allow the '/' to
654 -- act as separator since this is allowed in MS-DOS and OS2 ports.
656 for J in reverse File_Name'Range loop
657 if File_Name (J) = Directory_Separator
658 or else File_Name (J) = '/'
665 Findex2 := File_Name'Last;
666 while File_Name (Findex2) /= '.' loop
667 Findex2 := Findex2 - 1;
670 Flength := Findex2 - Findex1;
672 if Maximum_File_Name_Length > 0 then
674 -- Make room for the extra two characters in "b?"
676 while Int (Flength) > Maximum_File_Name_Length - 2 loop
677 Findex2 := Findex2 - 1;
678 Flength := Findex2 - Findex1;
682 Name_Buffer (3 .. Flength + 2) := File_Name (Findex1 .. Findex2 - 1);
683 Name_Buffer (Flength + 3) := '.';
685 -- C bind file, name is b_xxx.c
688 Name_Buffer (2) := '_';
689 Name_Buffer (Flength + 4) := 'c';
690 Name_Buffer (Flength + 5) := ASCII.NUL;
691 Name_Len := Flength + 4;
693 -- Ada bind file, name is b~xxx.adb or b~xxx.ads
694 -- (with $ instead of ~ in VMS)
697 if Hostparm.OpenVMS then
698 Name_Buffer (2) := '$';
700 Name_Buffer (2) := '~';
703 Name_Buffer (Flength + 4) := 'a';
704 Name_Buffer (Flength + 5) := 'd';
705 Name_Buffer (Flength + 6) := Typ;
706 Name_Buffer (Flength + 7) := ASCII.NUL;
707 Name_Len := Flength + 6;
713 if Recording_Time_From_Last_Bind then
714 Old_Binder_Output_Time_Stamp := File_Stamp (Bfile);
717 Create_File_And_Check (Output_FD, Text);
718 end Create_Binder_Output;
720 -----------------------
721 -- Create_Debug_File --
722 -----------------------
724 function Create_Debug_File (Src : File_Name_Type) return File_Name_Type is
725 Result : File_Name_Type;
728 Get_Name_String (Src);
730 if Hostparm.OpenVMS then
731 Name_Buffer (Name_Len + 1 .. Name_Len + 3) := "_dg";
733 Name_Buffer (Name_Len + 1 .. Name_Len + 3) := ".dg";
736 Name_Len := Name_Len + 3;
738 if Output_Object_File_Name /= null then
740 for Index in reverse Output_Object_File_Name'Range loop
742 if Output_Object_File_Name (Index) = Directory_Separator then
744 File_Name : constant String := Name_Buffer (1 .. Name_Len);
747 Name_Len := Index - Output_Object_File_Name'First + 1;
748 Name_Buffer (1 .. Name_Len) :=
749 Output_Object_File_Name
750 (Output_Object_File_Name'First .. Index);
751 Name_Buffer (Name_Len + 1 .. Name_Len + File_Name'Length) :=
753 Name_Len := Name_Len + File_Name'Length;
762 Name_Buffer (Name_Len + 1) := ASCII.NUL;
763 Create_File_And_Check (Output_FD, Text);
765 end Create_Debug_File;
767 ---------------------------
768 -- Create_File_And_Check --
769 ---------------------------
771 procedure Create_File_And_Check
772 (Fdesc : out File_Descriptor;
776 Output_File_Name := Name_Enter;
777 Fdesc := Create_File (Name_Buffer'Address, Fmode);
779 if Fdesc = Invalid_FD then
780 Fail ("Cannot create: ", Name_Buffer (1 .. Name_Len));
782 end Create_File_And_Check;
784 --------------------------------
785 -- Create_Output_Library_Info --
786 --------------------------------
788 procedure Create_Output_Library_Info is
790 Set_Library_Info_Name;
791 Create_File_And_Check (Output_FD, Text);
792 end Create_Output_Library_Info;
794 --------------------------------
795 -- Current_Library_File_Stamp --
796 --------------------------------
798 function Current_Library_File_Stamp return Time_Stamp_Type is
800 return Current_Full_Lib_Stamp;
801 end Current_Library_File_Stamp;
803 -------------------------------
804 -- Current_Object_File_Stamp --
805 -------------------------------
807 function Current_Object_File_Stamp return Time_Stamp_Type is
809 return Current_Full_Obj_Stamp;
810 end Current_Object_File_Stamp;
812 -------------------------------
813 -- Current_Source_File_Stamp --
814 -------------------------------
816 function Current_Source_File_Stamp return Time_Stamp_Type is
818 return Current_Full_Source_Stamp;
819 end Current_Source_File_Stamp;
821 ---------------------------
822 -- Debug_File_Eol_Length --
823 ---------------------------
825 function Debug_File_Eol_Length return Nat is
827 -- There has to be a cleaner way to do this! ???
829 if Directory_Separator = '/' then
834 end Debug_File_Eol_Length;
836 ----------------------------
837 -- Dir_In_Obj_Search_Path --
838 ----------------------------
840 function Dir_In_Obj_Search_Path (Position : Natural) return String_Ptr is
842 if Opt.Look_In_Primary_Dir then
844 Lib_Search_Directories.Table (Primary_Directory + Position - 1);
846 return Lib_Search_Directories.Table (Primary_Directory + Position);
848 end Dir_In_Obj_Search_Path;
850 ----------------------------
851 -- Dir_In_Src_Search_Path --
852 ----------------------------
854 function Dir_In_Src_Search_Path (Position : Natural) return String_Ptr is
856 if Opt.Look_In_Primary_Dir then
858 Src_Search_Directories.Table (Primary_Directory + Position - 1);
860 return Src_Search_Directories.Table (Primary_Directory + Position);
862 end Dir_In_Src_Search_Path;
864 ---------------------
865 -- Executable_Name --
866 ---------------------
868 function Executable_Name (Name : File_Name_Type) return File_Name_Type is
869 Exec_Suffix : String_Access;
872 if Name = No_File then
876 Get_Name_String (Name);
877 Exec_Suffix := Get_Executable_Suffix;
879 for J in Exec_Suffix.all'Range loop
880 Name_Len := Name_Len + 1;
881 Name_Buffer (Name_Len) := Exec_Suffix.all (J);
891 procedure Exit_Program (Exit_Code : Exit_Code_Type) is
893 -- The program will exit with the following status:
894 -- 0 if the object file has been generated (with or without warnings)
895 -- 1 if recompilation was not needed (smart recompilation)
896 -- 2 if gnat1 has been killed by a signal (detected by GCC)
897 -- 3 if no code has been generated (spec)
898 -- 4 for a fatal error
899 -- 5 if there were errors
902 when E_Success => OS_Exit (0);
903 when E_Warnings => OS_Exit (0);
904 when E_No_Compile => OS_Exit (1);
905 when E_No_Code => OS_Exit (3);
906 when E_Fatal => OS_Exit (4);
907 when E_Errors => OS_Exit (5);
908 when E_Abort => OS_Abort;
916 procedure Fail (S1 : String; S2 : String := ""; S3 : String := "") is
919 Osint.Write_Program_Name;
926 -- ??? Using Output is ugly, should do direct writes
927 -- ??? shouldn't this go to standard error instead of stdout?
929 Exit_Program (E_Fatal);
936 function File_Hash (F : File_Name_Type) return File_Hash_Num is
938 return File_Hash_Num (Int (F) rem File_Hash_Num'Range_Length);
945 function File_Stamp (Name : File_Name_Type) return Time_Stamp_Type is
947 if Name = No_File then
948 return Empty_Time_Stamp;
951 Get_Name_String (Name);
953 if not Is_Regular_File (Name_Buffer (1 .. Name_Len)) then
954 return Empty_Time_Stamp;
956 Name_Buffer (Name_Len + 1) := ASCII.NUL;
957 return OS_Time_To_GNAT_Time (File_Time_Stamp (Name_Buffer));
968 return File_Name_Type
974 File_Name : String renames Name_Buffer (1 .. Name_Len);
975 File : File_Name_Type := No_File;
979 -- If we are looking for a config file, look only in the current
980 -- directory, i.e. return input argument unchanged. Also look
981 -- only in the current directory if we are looking for a .dg
982 -- file (happens in -gnatD mode)
985 or else (Debug_Generated_Code
986 and then Name_Len > 3
988 (Name_Buffer (Name_Len - 2 .. Name_Len) = ".dg"
990 (Hostparm.OpenVMS and then
991 Name_Buffer (Name_Len - 2 .. Name_Len) = "_dg")))
995 -- If we are trying to find the current main file just look in the
996 -- directory where the user said it was.
998 elsif Look_In_Primary_Directory_For_Current_Main
999 and then Current_Main = N
1001 return Locate_File (N, T, Primary_Directory, File_Name);
1003 -- Otherwise do standard search for source file
1006 -- Check the mapping of this file name
1008 File := Mapped_Path_Name (N);
1010 -- If the file name is mapped to a path name, return the
1011 -- corresponding path name
1013 if File /= No_File then
1017 -- First place to look is in the primary directory (i.e. the same
1018 -- directory as the source) unless this has been disabled with -I-
1020 if Opt.Look_In_Primary_Dir then
1021 File := Locate_File (N, T, Primary_Directory, File_Name);
1023 if File /= No_File then
1028 -- Finally look in directories specified with switches -I/-aI/-aO
1031 Last_Dir := Lib_Search_Directories.Last;
1033 Last_Dir := Src_Search_Directories.Last;
1036 for D in Primary_Directory + 1 .. Last_Dir loop
1037 File := Locate_File (N, T, D, File_Name);
1039 if File /= No_File then
1049 -----------------------
1050 -- Find_Program_Name --
1051 -----------------------
1053 procedure Find_Program_Name is
1054 Command_Name : String (1 .. Len_Arg (0));
1055 Cindex1 : Integer := Command_Name'First;
1056 Cindex2 : Integer := Command_Name'Last;
1059 Fill_Arg (Command_Name'Address, 0);
1061 -- The program name might be specified by a full path name. However,
1062 -- we don't want to print that all out in an error message, so the
1063 -- path might need to be stripped away.
1065 for J in reverse Cindex1 .. Cindex2 loop
1066 if Is_Directory_Separator (Command_Name (J)) then
1072 for J in reverse Cindex1 .. Cindex2 loop
1073 if Command_Name (J) = '.' then
1079 Name_Len := Cindex2 - Cindex1 + 1;
1080 Name_Buffer (1 .. Name_Len) := Command_Name (Cindex1 .. Cindex2);
1081 end Find_Program_Name;
1083 ------------------------
1084 -- Full_Lib_File_Name --
1085 ------------------------
1087 function Full_Lib_File_Name (N : File_Name_Type) return File_Name_Type is
1089 return Find_File (N, Library);
1090 end Full_Lib_File_Name;
1092 ----------------------------
1093 -- Full_Library_Info_Name --
1094 ----------------------------
1096 function Full_Library_Info_Name return File_Name_Type is
1098 return Current_Full_Lib_Name;
1099 end Full_Library_Info_Name;
1101 ---------------------------
1102 -- Full_Object_File_Name --
1103 ---------------------------
1105 function Full_Object_File_Name return File_Name_Type is
1107 return Current_Full_Obj_Name;
1108 end Full_Object_File_Name;
1110 ----------------------
1111 -- Full_Source_Name --
1112 ----------------------
1114 function Full_Source_Name return File_Name_Type is
1116 return Current_Full_Source_Name;
1117 end Full_Source_Name;
1119 ----------------------
1120 -- Full_Source_Name --
1121 ----------------------
1123 function Full_Source_Name (N : File_Name_Type) return File_Name_Type is
1125 return Smart_Find_File (N, Source);
1126 end Full_Source_Name;
1132 function Get_Directory (Name : File_Name_Type) return File_Name_Type is
1134 Get_Name_String (Name);
1136 for J in reverse 1 .. Name_Len loop
1137 if Is_Directory_Separator (Name_Buffer (J)) then
1143 Name_Len := Hostparm.Normalized_CWD'Length;
1144 Name_Buffer (1 .. Name_Len) := Hostparm.Normalized_CWD;
1148 --------------------------
1149 -- Get_Next_Dir_In_Path --
1150 --------------------------
1152 Search_Path_Pos : Integer;
1153 -- Keeps track of current position in search path. Initialized by the
1154 -- call to Get_Next_Dir_In_Path_Init, updated by Get_Next_Dir_In_Path.
1156 function Get_Next_Dir_In_Path
1157 (Search_Path : String_Access)
1158 return String_Access
1160 Lower_Bound : Positive := Search_Path_Pos;
1161 Upper_Bound : Positive;
1165 while Lower_Bound <= Search_Path'Last
1166 and then Search_Path.all (Lower_Bound) = Path_Separator
1168 Lower_Bound := Lower_Bound + 1;
1171 exit when Lower_Bound > Search_Path'Last;
1173 Upper_Bound := Lower_Bound;
1174 while Upper_Bound <= Search_Path'Last
1175 and then Search_Path.all (Upper_Bound) /= Path_Separator
1177 Upper_Bound := Upper_Bound + 1;
1180 Search_Path_Pos := Upper_Bound;
1181 return new String'(Search_Path.all (Lower_Bound .. Upper_Bound - 1));
1185 end Get_Next_Dir_In_Path;
1187 -------------------------------
1188 -- Get_Next_Dir_In_Path_Init --
1189 -------------------------------
1191 procedure Get_Next_Dir_In_Path_Init (Search_Path : String_Access) is
1193 Search_Path_Pos := Search_Path'First;
1194 end Get_Next_Dir_In_Path_Init;
1196 --------------------------------------
1197 -- Get_Primary_Src_Search_Directory --
1198 --------------------------------------
1200 function Get_Primary_Src_Search_Directory return String_Ptr is
1202 return Src_Search_Directories.Table (Primary_Directory);
1203 end Get_Primary_Src_Search_Directory;
1209 procedure Initialize (P : Program_Type) is
1210 function Get_Default_Identifier_Character_Set return Character;
1211 pragma Import (C, Get_Default_Identifier_Character_Set,
1212 "__gnat_get_default_identifier_character_set");
1213 -- Function to determine the default identifier character set,
1214 -- which is system dependent. See Opt package spec for a list of
1215 -- the possible character codes and their interpretations.
1217 function Get_Maximum_File_Name_Length return Int;
1218 pragma Import (C, Get_Maximum_File_Name_Length,
1219 "__gnat_get_maximum_file_name_length");
1220 -- Function to get maximum file name length for system
1222 procedure Adjust_OS_Resource_Limits;
1223 pragma Import (C, Adjust_OS_Resource_Limits,
1224 "__gnat_adjust_os_resource_limits");
1225 -- Procedure to make system specific adjustments to make GNAT
1228 -- Start of processing for Initialize
1234 when Binder => In_Binder := True;
1235 when Compiler => In_Compiler := True;
1236 when Make => In_Make := True;
1240 Adjust_OS_Resource_Limits;
1243 Src_Search_Directories.Init;
1244 Lib_Search_Directories.Init;
1246 Identifier_Character_Set := Get_Default_Identifier_Character_Set;
1247 Maximum_File_Name_Length := Get_Maximum_File_Name_Length;
1249 -- Following should be removed by having above function return
1250 -- Integer'Last as indication of no maximum instead of -1 ???
1252 if Maximum_File_Name_Length = -1 then
1253 Maximum_File_Name_Length := Int'Last;
1256 -- Start off by setting all suppress options to False, these will
1257 -- be reset later (turning some on if -gnato is not specified, and
1258 -- turning all of them on if -gnatp is specified).
1260 Suppress_Options := (others => False);
1262 -- Set software overflow check flag. For now all targets require the
1263 -- use of software overflow checks. Later on, this will have to be
1264 -- specialized to the backend target. Also, if software overflow
1265 -- checking mode is set, then the default for suppressing overflow
1266 -- checks is True, since the software approach is expensive.
1268 Software_Overflow_Checking := True;
1269 Suppress_Options.Overflow_Checks := True;
1271 -- Reserve the first slot in the search paths table. This is the
1272 -- directory of the main source file or main library file and is
1273 -- filled in by each call to Next_Main_Source/Next_Main_Lib_File with
1274 -- the directory specified for this main source or library file. This
1275 -- is the directory which is searched first by default. This default
1276 -- search is inhibited by the option -I- for both source and library
1279 Src_Search_Directories.Set_Last (Primary_Directory);
1280 Src_Search_Directories.Table (Primary_Directory) := new String'("");
1282 Lib_Search_Directories.Set_Last (Primary_Directory);
1283 Lib_Search_Directories.Table (Primary_Directory) := new String'("");
1287 ----------------------------
1288 -- Is_Directory_Separator --
1289 ----------------------------
1291 function Is_Directory_Separator (C : Character) return Boolean is
1293 -- In addition to the default directory_separator allow the '/' to
1294 -- act as separator since this is allowed in MS-DOS, Windows 95/NT,
1295 -- and OS2 ports. On VMS, the situation is more complicated because
1296 -- there are two characters to check for.
1299 C = Directory_Separator
1301 or else (Hostparm.OpenVMS
1302 and then (C = ']' or else C = ':'));
1303 end Is_Directory_Separator;
1305 -------------------------
1306 -- Is_Readonly_Library --
1307 -------------------------
1309 function Is_Readonly_Library (File : in File_Name_Type) return Boolean is
1311 Get_Name_String (File);
1313 pragma Assert (Name_Buffer (Name_Len - 3 .. Name_Len) = ".ali");
1315 return not Is_Writable_File (Name_Buffer (1 .. Name_Len));
1316 end Is_Readonly_Library;
1322 function Lib_File_Name
1323 (Source_File : File_Name_Type)
1324 return File_Name_Type
1327 -- Pointer to location to set extension in place
1330 Get_Name_String (Source_File);
1331 Fptr := Name_Len + 1;
1333 for J in reverse 1 .. Name_Len loop
1334 if Name_Buffer (J) = '.' then
1340 Name_Buffer (Fptr) := '.';
1341 Name_Buffer (Fptr + 1 .. Fptr + ALI_Suffix'Length) := ALI_Suffix.all;
1342 Name_Buffer (Fptr + ALI_Suffix'Length + 1) := ASCII.NUL;
1343 Name_Len := Fptr + ALI_Suffix'Length;
1347 ------------------------
1348 -- Library_File_Stamp --
1349 ------------------------
1351 function Library_File_Stamp (N : File_Name_Type) return Time_Stamp_Type is
1353 return File_Stamp (Find_File (N, Library));
1354 end Library_File_Stamp;
1360 function Locate_File
1361 (N : File_Name_Type;
1365 return File_Name_Type
1367 Dir_Name : String_Ptr;
1371 Dir_Name := Lib_Search_Directories.Table (Dir);
1373 else pragma Assert (T = Source);
1374 Dir_Name := Src_Search_Directories.Table (Dir);
1378 Full_Name : String (1 .. Dir_Name'Length + Name'Length);
1381 Full_Name (1 .. Dir_Name'Length) := Dir_Name.all;
1382 Full_Name (Dir_Name'Length + 1 .. Full_Name'Length) := Name;
1384 if not Is_Regular_File (Full_Name) then
1388 -- If the file is in the current directory then return N itself
1390 if Dir_Name'Length = 0 then
1393 Name_Len := Full_Name'Length;
1394 Name_Buffer (1 .. Name_Len) := Full_Name;
1401 -------------------------------
1402 -- Matching_Full_Source_Name --
1403 -------------------------------
1405 function Matching_Full_Source_Name
1406 (N : File_Name_Type;
1407 T : Time_Stamp_Type)
1408 return File_Name_Type
1411 Get_Name_String (N);
1414 File_Name : constant String := Name_Buffer (1 .. Name_Len);
1415 File : File_Name_Type := No_File;
1419 if Opt.Look_In_Primary_Dir then
1420 File := Locate_File (N, Source, Primary_Directory, File_Name);
1422 if File /= No_File and then T = File_Stamp (N) then
1427 Last_Dir := Src_Search_Directories.Last;
1429 for D in Primary_Directory + 1 .. Last_Dir loop
1430 File := Locate_File (N, Source, D, File_Name);
1432 if File /= No_File and then T = File_Stamp (File) then
1439 end Matching_Full_Source_Name;
1445 function More_Files return Boolean is
1447 return (Current_File_Name_Index < Number_File_Names);
1450 --------------------
1451 -- More_Lib_Files --
1452 --------------------
1454 function More_Lib_Files return Boolean is
1456 pragma Assert (In_Binder);
1460 -----------------------
1461 -- More_Source_Files --
1462 -----------------------
1464 function More_Source_Files return Boolean is
1466 pragma Assert (In_Compiler or else In_Make);
1468 end More_Source_Files;
1470 -------------------------------
1471 -- Nb_Dir_In_Obj_Search_Path --
1472 -------------------------------
1474 function Nb_Dir_In_Obj_Search_Path return Natural is
1476 if Opt.Look_In_Primary_Dir then
1477 return Lib_Search_Directories.Last - Primary_Directory + 1;
1479 return Lib_Search_Directories.Last - Primary_Directory;
1481 end Nb_Dir_In_Obj_Search_Path;
1483 -------------------------------
1484 -- Nb_Dir_In_Src_Search_Path --
1485 -------------------------------
1487 function Nb_Dir_In_Src_Search_Path return Natural is
1489 if Opt.Look_In_Primary_Dir then
1490 return Src_Search_Directories.Last - Primary_Directory + 1;
1492 return Src_Search_Directories.Last - Primary_Directory;
1494 end Nb_Dir_In_Src_Search_Path;
1496 --------------------
1497 -- Next_Main_File --
1498 --------------------
1500 function Next_Main_File return File_Name_Type is
1501 File_Name : String_Ptr;
1502 Dir_Name : String_Ptr;
1506 pragma Assert (More_Files);
1508 Current_File_Name_Index := Current_File_Name_Index + 1;
1510 -- Get the file and directory name
1512 File_Name := File_Names (Current_File_Name_Index);
1513 Fptr := File_Name'First;
1515 for J in reverse File_Name'Range loop
1516 if File_Name (J) = Directory_Separator
1517 or else File_Name (J) = '/'
1519 if J = File_Name'Last then
1520 Fail ("File name missing");
1528 -- Save name of directory in which main unit resides for use in
1529 -- locating other units
1531 Dir_Name := new String'(File_Name (File_Name'First .. Fptr - 1));
1534 Src_Search_Directories.Table (Primary_Directory) := Dir_Name;
1535 Look_In_Primary_Directory_For_Current_Main := True;
1538 Src_Search_Directories.Table (Primary_Directory) := Dir_Name;
1539 if Fptr > File_Name'First then
1540 Look_In_Primary_Directory_For_Current_Main := True;
1543 else pragma Assert (In_Binder);
1544 Dir_Name := Normalize_Directory_Name (Dir_Name.all);
1545 Lib_Search_Directories.Table (Primary_Directory) := Dir_Name;
1548 Name_Len := File_Name'Last - Fptr + 1;
1549 Name_Buffer (1 .. Name_Len) := File_Name (Fptr .. File_Name'Last);
1550 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
1551 Current_Main := File_Name_Type (Name_Find);
1553 -- In the gnatmake case, the main file may have not have the
1554 -- extension. Try ".adb" first then ".ads"
1558 Orig_Main : File_Name_Type := Current_Main;
1561 if Strip_Suffix (Orig_Main) = Orig_Main then
1562 Current_Main := Append_Suffix_To_File_Name (Orig_Main, ".adb");
1564 if Full_Source_Name (Current_Main) = No_File then
1566 Append_Suffix_To_File_Name (Orig_Main, ".ads");
1568 if Full_Source_Name (Current_Main) = No_File then
1569 Current_Main := Orig_Main;
1576 return Current_Main;
1579 ------------------------
1580 -- Next_Main_Lib_File --
1581 ------------------------
1583 function Next_Main_Lib_File return File_Name_Type is
1585 pragma Assert (In_Binder);
1586 return Next_Main_File;
1587 end Next_Main_Lib_File;
1589 ----------------------
1590 -- Next_Main_Source --
1591 ----------------------
1593 function Next_Main_Source return File_Name_Type is
1594 Main_File : File_Name_Type := Next_Main_File;
1597 pragma Assert (In_Compiler or else In_Make);
1599 end Next_Main_Source;
1601 ------------------------------
1602 -- Normalize_Directory_Name --
1603 ------------------------------
1605 function Normalize_Directory_Name (Directory : String) return String_Ptr is
1606 Result : String_Ptr;
1609 if Directory'Length = 0 then
1610 Result := new String'(Hostparm.Normalized_CWD);
1612 elsif Is_Directory_Separator (Directory (Directory'Last)) then
1613 Result := new String'(Directory);
1615 Result := new String (1 .. Directory'Length + 1);
1616 Result (1 .. Directory'Length) := Directory;
1617 Result (Directory'Length + 1) := Directory_Separator;
1621 end Normalize_Directory_Name;
1623 ---------------------
1624 -- Number_Of_Files --
1625 ---------------------
1627 function Number_Of_Files return Int is
1629 return Number_File_Names;
1630 end Number_Of_Files;
1632 ----------------------
1633 -- Object_File_Name --
1634 ----------------------
1636 function Object_File_Name (N : File_Name_Type) return File_Name_Type is
1642 Get_Name_String (N);
1643 Name_Len := Name_Len - ALI_Suffix'Length - 1;
1645 for J in Object_Suffix'Range loop
1646 Name_Len := Name_Len + 1;
1647 Name_Buffer (Name_Len) := Object_Suffix (J);
1651 end Object_File_Name;
1653 --------------------------
1654 -- OS_Time_To_GNAT_Time --
1655 --------------------------
1657 function OS_Time_To_GNAT_Time (T : OS_Time) return Time_Stamp_Type is
1658 GNAT_Time : Time_Stamp_Type;
1668 GM_Split (T, Y, Mo, D, H, Mn, S);
1674 Minutes => Nat (Mn),
1679 end OS_Time_To_GNAT_Time;
1685 function Program_Name (Nam : String) return String_Access is
1686 Res : String_Access;
1689 -- Get the name of the current program being executed
1693 -- Find the target prefix if any, for the cross compilation case
1694 -- for instance in "alpha-dec-vxworks-gcc" the target prefix is
1695 -- "alpha-dec-vxworks-"
1697 while Name_Len > 0 loop
1698 if Name_Buffer (Name_Len) = '-' then
1702 Name_Len := Name_Len - 1;
1705 -- Create the new program name
1707 Res := new String (1 .. Name_Len + Nam'Length);
1708 Res.all (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
1709 Res.all (Name_Len + 1 .. Name_Len + Nam'Length) := Nam;
1713 ------------------------------
1714 -- Read_Default_Search_Dirs --
1715 ------------------------------
1717 function Read_Default_Search_Dirs
1718 (Search_Dir_Prefix : String_Access;
1719 Search_File : String_Access;
1720 Search_Dir_Default_Name : String_Access)
1721 return String_Access
1723 Prefix_Len : constant Integer := Search_Dir_Prefix.all'Length;
1724 Buffer : String (1 .. Prefix_Len + Search_File.all'Length + 1);
1725 File_FD : File_Descriptor;
1726 S, S1 : String_Access;
1729 Actual_Len : Integer;
1732 Prev_Was_Separator : Boolean;
1733 Nb_Relative_Dir : Integer;
1735 function Is_Relative (S : String; K : Positive) return Boolean;
1736 pragma Inline (Is_Relative);
1737 -- Returns True if a relative directory specification is found
1738 -- in S at position K, False otherwise.
1744 function Is_Relative (S : String; K : Positive) return Boolean is
1746 return not Is_Absolute_Path (S (K .. S'Last));
1749 -- Start of processing for Read_Default_Search_Dirs
1752 -- Construct a C compatible character string buffer.
1754 Buffer (1 .. Search_Dir_Prefix.all'Length)
1755 := Search_Dir_Prefix.all;
1756 Buffer (Search_Dir_Prefix.all'Length + 1 .. Buffer'Last - 1)
1758 Buffer (Buffer'Last) := ASCII.NUL;
1760 File_FD := Open_Read (Buffer'Address, Binary);
1761 if File_FD = Invalid_FD then
1762 return Search_Dir_Default_Name;
1765 Len := Integer (File_Length (File_FD));
1767 -- An extra character for a trailing Path_Separator is allocated
1769 S := new String (1 .. Len + 1);
1770 S (Len + 1) := Path_Separator;
1772 -- Read the file. Note that the loop is not necessary since the
1773 -- whole file is read at once except on VMS.
1777 while Actual_Len /= 0 loop
1778 Actual_Len := Read (File_FD, S (Curr)'Address, Len);
1779 Curr := Curr + Actual_Len;
1782 -- Process the file, translating line and file ending
1783 -- control characters to a path separator character.
1785 Prev_Was_Separator := True;
1786 Nb_Relative_Dir := 0;
1787 for J in 1 .. Len loop
1788 if S (J) in ASCII.NUL .. ASCII.US
1791 S (J) := Path_Separator;
1794 if S (J) = Path_Separator then
1795 Prev_Was_Separator := True;
1797 if Prev_Was_Separator and then Is_Relative (S.all, J) then
1798 Nb_Relative_Dir := Nb_Relative_Dir + 1;
1801 Prev_Was_Separator := False;
1805 if Nb_Relative_Dir = 0 then
1809 -- Add the Search_Dir_Prefix to all relative paths
1811 S1 := new String (1 .. S'Length + Nb_Relative_Dir * Prefix_Len);
1813 Prev_Was_Separator := True;
1814 for J in 1 .. Len + 1 loop
1815 if S (J) = Path_Separator then
1816 Prev_Was_Separator := True;
1819 if Prev_Was_Separator and then Is_Relative (S.all, J) then
1820 S1 (J1 .. J1 + Prefix_Len) := Search_Dir_Prefix.all;
1821 J1 := J1 + Prefix_Len;
1824 Prev_Was_Separator := False;
1832 end Read_Default_Search_Dirs;
1834 -----------------------
1835 -- Read_Library_Info --
1836 -----------------------
1838 function Read_Library_Info
1839 (Lib_File : File_Name_Type;
1840 Fatal_Err : Boolean := False)
1841 return Text_Buffer_Ptr
1843 Lib_FD : File_Descriptor;
1844 -- The file descriptor for the current library file. A negative value
1845 -- indicates failure to open the specified source file.
1847 Text : Text_Buffer_Ptr;
1848 -- Allocated text buffer.
1851 Current_Full_Lib_Name := Find_File (Lib_File, Library);
1852 Current_Full_Obj_Name := Object_File_Name (Current_Full_Lib_Name);
1854 if Current_Full_Lib_Name = No_File then
1856 Fail ("Cannot find: ", Name_Buffer (1 .. Name_Len));
1858 Current_Full_Obj_Stamp := Empty_Time_Stamp;
1863 Get_Name_String (Current_Full_Lib_Name);
1864 Name_Buffer (Name_Len + 1) := ASCII.NUL;
1866 -- Open the library FD, note that we open in binary mode, because as
1867 -- documented in the spec, the caller is expected to handle either
1868 -- DOS or Unix mode files, and there is no point in wasting time on
1869 -- text translation when it is not required.
1871 Lib_FD := Open_Read (Name_Buffer'Address, Binary);
1873 if Lib_FD = Invalid_FD then
1875 Fail ("Cannot open: ", Name_Buffer (1 .. Name_Len));
1877 Current_Full_Obj_Stamp := Empty_Time_Stamp;
1882 -- Check for object file consistency if requested
1884 if Opt.Check_Object_Consistency then
1885 Current_Full_Lib_Stamp := File_Stamp (Current_Full_Lib_Name);
1886 Current_Full_Obj_Stamp := File_Stamp (Current_Full_Obj_Name);
1888 if Current_Full_Obj_Stamp (1) = ' ' then
1890 -- When the library is readonly, always assume that
1891 -- the object is consistent.
1893 if Is_Readonly_Library (Current_Full_Lib_Name) then
1894 Current_Full_Obj_Stamp := Current_Full_Lib_Stamp;
1896 elsif Fatal_Err then
1897 Get_Name_String (Current_Full_Obj_Name);
1899 Fail ("Cannot find: ", Name_Buffer (1 .. Name_Len));
1902 Current_Full_Obj_Stamp := Empty_Time_Stamp;
1908 -- Object file exists, compare object and ALI time stamps
1910 if Current_Full_Lib_Stamp > Current_Full_Obj_Stamp then
1912 Get_Name_String (Current_Full_Obj_Name);
1914 Fail ("Bad time stamp: ", Name_Buffer (1 .. Name_Len));
1916 Current_Full_Obj_Stamp := Empty_Time_Stamp;
1923 -- Read data from the file
1926 Len : Integer := Integer (File_Length (Lib_FD));
1927 -- Length of source file text. If it doesn't fit in an integer
1928 -- we're probably stuck anyway (>2 gigs of source seems a lot!)
1930 Actual_Len : Integer := 0;
1933 -- Low bound for allocated text buffer
1935 Hi : Text_Ptr := Text_Ptr (Len);
1936 -- High bound for allocated text buffer. Note length is Len + 1
1937 -- which allows for extra EOF character at the end of the buffer.
1940 -- Allocate text buffer. Note extra character at end for EOF
1942 Text := new Text_Buffer (Lo .. Hi);
1944 -- Some systems (e.g. VMS) have file types that require one
1945 -- read per line, so read until we get the Len bytes or until
1946 -- there are no more characters.
1950 Actual_Len := Read (Lib_FD, Text (Hi)'Address, Len);
1951 Hi := Hi + Text_Ptr (Actual_Len);
1952 exit when Actual_Len = Len or Actual_Len <= 0;
1958 -- Read is complete, close file and we are done
1963 end Read_Library_Info;
1965 -- Version with default file name
1967 procedure Read_Library_Info
1968 (Name : out File_Name_Type;
1969 Text : out Text_Buffer_Ptr)
1972 Set_Library_Info_Name;
1974 Text := Read_Library_Info (Name, Fatal_Err => False);
1975 end Read_Library_Info;
1977 ----------------------
1978 -- Read_Source_File --
1979 ----------------------
1981 procedure Read_Source_File
1982 (N : File_Name_Type;
1984 Hi : out Source_Ptr;
1985 Src : out Source_Buffer_Ptr;
1986 T : File_Type := Source)
1988 Source_File_FD : File_Descriptor;
1989 -- The file descriptor for the current source file. A negative value
1990 -- indicates failure to open the specified source file.
1993 -- Length of file. Assume no more than 2 gigabytes of source!
1995 Actual_Len : Integer;
1998 Current_Full_Source_Name := Find_File (N, T);
1999 Current_Full_Source_Stamp := File_Stamp (Current_Full_Source_Name);
2001 if Current_Full_Source_Name = No_File then
2003 -- If we were trying to access the main file and we could not
2004 -- find it we have an error.
2006 if N = Current_Main then
2007 Get_Name_String (N);
2008 Fail ("Cannot find: ", Name_Buffer (1 .. Name_Len));
2016 Get_Name_String (Current_Full_Source_Name);
2017 Name_Buffer (Name_Len + 1) := ASCII.NUL;
2019 -- Open the source FD, note that we open in binary mode, because as
2020 -- documented in the spec, the caller is expected to handle either
2021 -- DOS or Unix mode files, and there is no point in wasting time on
2022 -- text translation when it is not required.
2024 Source_File_FD := Open_Read (Name_Buffer'Address, Binary);
2026 if Source_File_FD = Invalid_FD then
2032 -- Prepare to read data from the file
2034 Len := Integer (File_Length (Source_File_FD));
2036 -- Set Hi so that length is one more than the physical length,
2037 -- allowing for the extra EOF character at the end of the buffer
2039 Hi := Lo + Source_Ptr (Len);
2041 -- Do the actual read operation
2044 subtype Actual_Source_Buffer is Source_Buffer (Lo .. Hi);
2045 -- Physical buffer allocated
2047 type Actual_Source_Ptr is access Actual_Source_Buffer;
2048 -- This is the pointer type for the physical buffer allocated
2050 Actual_Ptr : Actual_Source_Ptr := new Actual_Source_Buffer;
2051 -- And this is the actual physical buffer
2054 -- Allocate source buffer, allowing extra character at end for EOF
2056 -- Some systems (e.g. VMS) have file types that require one
2057 -- read per line, so read until we get the Len bytes or until
2058 -- there are no more characters.
2062 Actual_Len := Read (Source_File_FD, Actual_Ptr (Hi)'Address, Len);
2063 Hi := Hi + Source_Ptr (Actual_Len);
2064 exit when Actual_Len = Len or Actual_Len <= 0;
2067 Actual_Ptr (Hi) := EOF;
2069 -- Now we need to work out the proper virtual origin pointer to
2070 -- return. This is exactly Actual_Ptr (0)'Address, but we have
2071 -- to be careful to suppress checks to compute this address.
2074 pragma Suppress (All_Checks);
2076 function To_Source_Buffer_Ptr is new
2077 Unchecked_Conversion (Address, Source_Buffer_Ptr);
2080 Src := To_Source_Buffer_Ptr (Actual_Ptr (0)'Address);
2084 -- Read is complete, get time stamp and close file and we are done
2086 Close (Source_File_FD);
2088 end Read_Source_File;
2090 --------------------------------
2091 -- Record_Time_From_Last_Bind --
2092 --------------------------------
2094 procedure Record_Time_From_Last_Bind is
2096 Recording_Time_From_Last_Bind := True;
2097 end Record_Time_From_Last_Bind;
2099 ---------------------------
2100 -- Set_Library_Info_Name --
2101 ---------------------------
2103 procedure Set_Library_Info_Name is
2104 Dot_Index : Natural;
2107 pragma Assert (In_Compiler);
2108 Get_Name_String (Current_Main);
2110 -- Find last dot since we replace the existing extension by .ali. The
2111 -- initialization to Name_Len + 1 provides for simply adding the .ali
2112 -- extension if the source file name has no extension.
2114 Dot_Index := Name_Len + 1;
2115 for J in reverse 1 .. Name_Len loop
2116 if Name_Buffer (J) = '.' then
2122 -- Make sure that the output file name matches the source file name.
2123 -- To compare them, remove file name directories and extensions.
2125 if Output_Object_File_Name /= null then
2127 Name : constant String := Name_Buffer (1 .. Dot_Index);
2128 Len : constant Natural := Dot_Index;
2131 Name_Buffer (1 .. Output_Object_File_Name'Length)
2132 := Output_Object_File_Name.all;
2135 for J in reverse Output_Object_File_Name'Range loop
2136 if Name_Buffer (J) = '.' then
2142 pragma Assert (Dot_Index /= 0);
2143 -- We check for the extension elsewhere
2145 if Name /= Name_Buffer (Dot_Index - Len + 1 .. Dot_Index) then
2146 Fail ("incorrect object file name");
2151 Name_Buffer (Dot_Index) := '.';
2152 Name_Buffer (Dot_Index + 1 .. Dot_Index + 3) := ALI_Suffix.all;
2153 Name_Buffer (Dot_Index + 4) := ASCII.NUL;
2154 Name_Len := Dot_Index + 3;
2155 end Set_Library_Info_Name;
2157 ---------------------------------
2158 -- Set_Output_Object_File_Name --
2159 ---------------------------------
2161 procedure Set_Output_Object_File_Name (Name : String) is
2162 Ext : constant String := Object_Suffix;
2163 NL : constant Natural := Name'Length;
2164 EL : constant Natural := Ext'Length;
2167 -- Make sure that the object file has the expected extension.
2170 or else Name (NL - EL + Name'First .. Name'Last) /= Ext
2172 Fail ("incorrect object file extension");
2175 Output_Object_File_Name := new String'(Name);
2176 end Set_Output_Object_File_Name;
2178 ------------------------
2179 -- Set_Main_File_Name --
2180 ------------------------
2182 procedure Set_Main_File_Name (Name : String) is
2184 Number_File_Names := Number_File_Names + 1;
2185 File_Names (Number_File_Names) := new String'(Name);
2186 end Set_Main_File_Name;
2188 ----------------------
2189 -- Smart_File_Stamp --
2190 ----------------------
2192 function Smart_File_Stamp
2193 (N : File_Name_Type;
2195 return Time_Stamp_Type
2197 Time_Stamp : Time_Stamp_Type;
2200 if not File_Cache_Enabled then
2201 return File_Stamp (Find_File (N, T));
2204 Time_Stamp := File_Stamp_Hash_Table.Get (N);
2206 if Time_Stamp (1) = ' ' then
2207 Time_Stamp := File_Stamp (Smart_Find_File (N, T));
2208 File_Stamp_Hash_Table.Set (N, Time_Stamp);
2212 end Smart_File_Stamp;
2214 ---------------------
2215 -- Smart_Find_File --
2216 ---------------------
2218 function Smart_Find_File
2219 (N : File_Name_Type;
2221 return File_Name_Type
2223 Full_File_Name : File_Name_Type;
2226 if not File_Cache_Enabled then
2227 return Find_File (N, T);
2230 Full_File_Name := File_Name_Hash_Table.Get (N);
2232 if Full_File_Name = No_File then
2233 Full_File_Name := Find_File (N, T);
2234 File_Name_Hash_Table.Set (N, Full_File_Name);
2237 return Full_File_Name;
2238 end Smart_Find_File;
2240 ----------------------
2241 -- Source_File_Data --
2242 ----------------------
2244 procedure Source_File_Data (Cache : Boolean) is
2246 File_Cache_Enabled := Cache;
2247 end Source_File_Data;
2249 -----------------------
2250 -- Source_File_Stamp --
2251 -----------------------
2253 function Source_File_Stamp (N : File_Name_Type) return Time_Stamp_Type is
2255 return Smart_File_Stamp (N, Source);
2256 end Source_File_Stamp;
2258 ---------------------
2259 -- Strip_Directory --
2260 ---------------------
2262 function Strip_Directory (Name : File_Name_Type) return File_Name_Type is
2264 Get_Name_String (Name);
2267 S : String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
2268 Fptr : Natural := S'First;
2271 for J in reverse S'Range loop
2272 if Is_Directory_Separator (S (J)) then
2278 if Fptr = S'First then
2282 Name_Buffer (1 .. S'Last - Fptr + 1) := S (Fptr .. S'Last);
2283 Name_Len := S'Last - Fptr + 1;
2286 end Strip_Directory;
2292 function Strip_Suffix (Name : File_Name_Type) return File_Name_Type is
2294 Get_Name_String (Name);
2296 for J in reverse 1 .. Name_Len loop
2297 if Name_Buffer (J) = '.' then
2306 -------------------------
2307 -- Time_From_Last_Bind --
2308 -------------------------
2310 function Time_From_Last_Bind return Nat is
2324 type Month_Data is array (Int range 1 .. 12) of Int;
2325 Cumul : constant Month_Data := (0, 0, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7);
2326 -- Represents the difference in days from a period compared to the
2327 -- same period if all months had 31 days, i.e:
2329 -- Cumul (m) = 31x(m-1) - (number of days from 01/01 to m/01)
2334 if not Recording_Time_From_Last_Bind
2335 or else not Binder_Output_Time_Stamps_Set
2336 or else Old_Binder_Output_Time_Stamp = Empty_Time_Stamp
2342 (Old_Binder_Output_Time_Stamp,
2343 Old_Y, Old_M, Old_D, Old_H, Old_Mi, Old_S);
2346 (New_Binder_Output_Time_Stamp,
2347 New_Y, New_M, New_D, New_H, New_Mi, New_S);
2349 Res := New_Mi - Old_Mi;
2351 -- 60 minutes in an hour
2353 Res := Res + 60 * (New_H - Old_H);
2355 -- 24 hours in a day
2357 Res := Res + 60 * 24 * (New_D - Old_D);
2359 -- Almost 31 days in a month
2361 Res := Res + 60 * 24 *
2362 (31 * (New_M - Old_M) - Cumul (New_M) + Cumul (Old_M));
2364 -- 365 days in a year
2366 Res := Res + 60 * 24 * 365 * (New_Y - Old_Y);
2369 end Time_From_Last_Bind;
2371 ---------------------------
2372 -- To_Canonical_Dir_Spec --
2373 ---------------------------
2375 function To_Canonical_Dir_Spec
2377 Prefix_Style : Boolean)
2378 return String_Access
2380 function To_Canonical_Dir_Spec
2381 (Host_Dir : Address;
2382 Prefix_Flag : Integer)
2384 pragma Import (C, To_Canonical_Dir_Spec, "__gnat_to_canonical_dir_spec");
2386 C_Host_Dir : String (1 .. Host_Dir'Length + 1);
2387 Canonical_Dir_Addr : Address;
2388 Canonical_Dir_Len : Integer;
2391 C_Host_Dir (1 .. Host_Dir'Length) := Host_Dir;
2392 C_Host_Dir (C_Host_Dir'Last) := ASCII.NUL;
2394 if Prefix_Style then
2395 Canonical_Dir_Addr := To_Canonical_Dir_Spec (C_Host_Dir'Address, 1);
2397 Canonical_Dir_Addr := To_Canonical_Dir_Spec (C_Host_Dir'Address, 0);
2399 Canonical_Dir_Len := C_String_Length (Canonical_Dir_Addr);
2401 if Canonical_Dir_Len = 0 then
2404 return To_Path_String_Access (Canonical_Dir_Addr, Canonical_Dir_Len);
2409 Fail ("erroneous directory spec: ", Host_Dir);
2411 end To_Canonical_Dir_Spec;
2413 ---------------------------
2414 -- To_Canonical_File_List --
2415 ---------------------------
2417 function To_Canonical_File_List
2418 (Wildcard_Host_File : String;
2419 Only_Dirs : Boolean)
2420 return String_Access_List_Access
2422 function To_Canonical_File_List_Init
2423 (Host_File : Address;
2424 Only_Dirs : Integer)
2426 pragma Import (C, To_Canonical_File_List_Init,
2427 "__gnat_to_canonical_file_list_init");
2429 function To_Canonical_File_List_Next return Address;
2430 pragma Import (C, To_Canonical_File_List_Next,
2431 "__gnat_to_canonical_file_list_next");
2433 procedure To_Canonical_File_List_Free;
2434 pragma Import (C, To_Canonical_File_List_Free,
2435 "__gnat_to_canonical_file_list_free");
2437 Num_Files : Integer;
2438 C_Wildcard_Host_File : String (1 .. Wildcard_Host_File'Length + 1);
2441 C_Wildcard_Host_File (1 .. Wildcard_Host_File'Length) :=
2443 C_Wildcard_Host_File (C_Wildcard_Host_File'Last) := ASCII.NUL;
2445 -- Do the expansion and say how many there are
2447 Num_Files := To_Canonical_File_List_Init
2448 (C_Wildcard_Host_File'Address, Boolean'Pos (Only_Dirs));
2451 Canonical_File_List : String_Access_List (1 .. Num_Files);
2452 Canonical_File_Addr : Address;
2453 Canonical_File_Len : Integer;
2456 -- Retrieve the expanded directoy names and build the list
2458 for J in 1 .. Num_Files loop
2459 Canonical_File_Addr := To_Canonical_File_List_Next;
2460 Canonical_File_Len := C_String_Length (Canonical_File_Addr);
2461 Canonical_File_List (J) := To_Path_String_Access
2462 (Canonical_File_Addr, Canonical_File_Len);
2465 -- Free up the storage
2467 To_Canonical_File_List_Free;
2469 return new String_Access_List'(Canonical_File_List);
2471 end To_Canonical_File_List;
2473 ----------------------------
2474 -- To_Canonical_File_Spec --
2475 ----------------------------
2477 function To_Canonical_File_Spec
2478 (Host_File : String)
2479 return String_Access
2481 function To_Canonical_File_Spec (Host_File : Address) return Address;
2483 (C, To_Canonical_File_Spec, "__gnat_to_canonical_file_spec");
2485 C_Host_File : String (1 .. Host_File'Length + 1);
2486 Canonical_File_Addr : Address;
2487 Canonical_File_Len : Integer;
2490 C_Host_File (1 .. Host_File'Length) := Host_File;
2491 C_Host_File (C_Host_File'Last) := ASCII.NUL;
2493 Canonical_File_Addr := To_Canonical_File_Spec (C_Host_File'Address);
2494 Canonical_File_Len := C_String_Length (Canonical_File_Addr);
2496 if Canonical_File_Len = 0 then
2499 return To_Path_String_Access
2500 (Canonical_File_Addr, Canonical_File_Len);
2505 Fail ("erroneous file spec: ", Host_File);
2507 end To_Canonical_File_Spec;
2509 ----------------------------
2510 -- To_Canonical_Path_Spec --
2511 ----------------------------
2513 function To_Canonical_Path_Spec
2514 (Host_Path : String)
2515 return String_Access
2517 function To_Canonical_Path_Spec (Host_Path : Address) return Address;
2519 (C, To_Canonical_Path_Spec, "__gnat_to_canonical_path_spec");
2521 C_Host_Path : String (1 .. Host_Path'Length + 1);
2522 Canonical_Path_Addr : Address;
2523 Canonical_Path_Len : Integer;
2526 C_Host_Path (1 .. Host_Path'Length) := Host_Path;
2527 C_Host_Path (C_Host_Path'Last) := ASCII.NUL;
2529 Canonical_Path_Addr := To_Canonical_Path_Spec (C_Host_Path'Address);
2530 Canonical_Path_Len := C_String_Length (Canonical_Path_Addr);
2532 -- Return a null string (vice a null) for zero length paths, for
2533 -- compatibility with getenv().
2535 return To_Path_String_Access (Canonical_Path_Addr, Canonical_Path_Len);
2539 Fail ("erroneous path spec: ", Host_Path);
2541 end To_Canonical_Path_Spec;
2543 ---------------------------
2544 -- To_Host_Dir_Spec --
2545 ---------------------------
2547 function To_Host_Dir_Spec
2548 (Canonical_Dir : String;
2549 Prefix_Style : Boolean)
2550 return String_Access
2552 function To_Host_Dir_Spec
2553 (Canonical_Dir : Address;
2554 Prefix_Flag : Integer)
2556 pragma Import (C, To_Host_Dir_Spec, "__gnat_to_host_dir_spec");
2558 C_Canonical_Dir : String (1 .. Canonical_Dir'Length + 1);
2559 Host_Dir_Addr : Address;
2560 Host_Dir_Len : Integer;
2563 C_Canonical_Dir (1 .. Canonical_Dir'Length) := Canonical_Dir;
2564 C_Canonical_Dir (C_Canonical_Dir'Last) := ASCII.NUL;
2566 if Prefix_Style then
2567 Host_Dir_Addr := To_Host_Dir_Spec (C_Canonical_Dir'Address, 1);
2569 Host_Dir_Addr := To_Host_Dir_Spec (C_Canonical_Dir'Address, 0);
2571 Host_Dir_Len := C_String_Length (Host_Dir_Addr);
2573 if Host_Dir_Len = 0 then
2576 return To_Path_String_Access (Host_Dir_Addr, Host_Dir_Len);
2578 end To_Host_Dir_Spec;
2580 ----------------------------
2581 -- To_Host_File_Spec --
2582 ----------------------------
2584 function To_Host_File_Spec
2585 (Canonical_File : String)
2586 return String_Access
2588 function To_Host_File_Spec (Canonical_File : Address) return Address;
2589 pragma Import (C, To_Host_File_Spec, "__gnat_to_host_file_spec");
2591 C_Canonical_File : String (1 .. Canonical_File'Length + 1);
2592 Host_File_Addr : Address;
2593 Host_File_Len : Integer;
2596 C_Canonical_File (1 .. Canonical_File'Length) := Canonical_File;
2597 C_Canonical_File (C_Canonical_File'Last) := ASCII.NUL;
2599 Host_File_Addr := To_Host_File_Spec (C_Canonical_File'Address);
2600 Host_File_Len := C_String_Length (Host_File_Addr);
2602 if Host_File_Len = 0 then
2605 return To_Path_String_Access
2606 (Host_File_Addr, Host_File_Len);
2608 end To_Host_File_Spec;
2610 ---------------------------
2611 -- To_Path_String_Access --
2612 ---------------------------
2614 function To_Path_String_Access
2615 (Path_Addr : Address;
2617 return String_Access
2619 subtype Path_String is String (1 .. Path_Len);
2620 type Path_String_Access is access Path_String;
2622 function Address_To_Access is new
2623 Unchecked_Conversion (Source => Address,
2624 Target => Path_String_Access);
2626 Path_Access : Path_String_Access := Address_To_Access (Path_Addr);
2628 Return_Val : String_Access;
2631 Return_Val := new String (1 .. Path_Len);
2633 for J in 1 .. Path_Len loop
2634 Return_Val (J) := Path_Access (J);
2638 end To_Path_String_Access;
2644 procedure Tree_Close is
2646 pragma Assert (In_Compiler);
2647 Tree_Write_Terminate;
2655 procedure Tree_Create is
2656 Dot_Index : Natural;
2659 pragma Assert (In_Compiler);
2660 Get_Name_String (Current_Main);
2662 -- If an object file has been specified, then the ALI file
2663 -- will be in the same directory as the object file;
2664 -- so, we put the tree file in this same directory,
2665 -- even though no object file needs to be generated.
2667 if Output_Object_File_Name /= null then
2668 Name_Len := Output_Object_File_Name'Length;
2669 Name_Buffer (1 .. Name_Len) := Output_Object_File_Name.all;
2673 for J in reverse 1 .. Name_Len loop
2674 if Name_Buffer (J) = '.' then
2680 -- Should be impossible to not have an extension
2682 pragma Assert (Dot_Index /= 0);
2684 -- Change exctension to adt
2686 Name_Buffer (Dot_Index + 1) := 'a';
2687 Name_Buffer (Dot_Index + 2) := 'd';
2688 Name_Buffer (Dot_Index + 3) := 't';
2689 Name_Buffer (Dot_Index + 4) := ASCII.NUL;
2690 Name_Len := Dot_Index + 3;
2691 Create_File_And_Check (Output_FD, Binary);
2693 Tree_Write_Initialize (Output_FD);
2700 procedure Write_Info (Info : String) is
2702 pragma Assert (In_Binder or In_Compiler);
2703 Write_With_Check (Info'Address, Info'Length);
2704 Write_With_Check (EOL'Address, 1);
2707 -----------------------
2708 -- Write_Binder_Info --
2709 -----------------------
2711 procedure Write_Binder_Info (Info : String) renames Write_Info;
2713 -----------------------
2714 -- Write_Debug_Info --
2715 -----------------------
2717 procedure Write_Debug_Info (Info : String) renames Write_Info;
2719 ------------------------
2720 -- Write_Library_Info --
2721 ------------------------
2723 procedure Write_Library_Info (Info : String) renames Write_Info;
2725 ------------------------
2726 -- Write_Program_Name --
2727 ------------------------
2729 procedure Write_Program_Name is
2730 Save_Buffer : String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
2736 -- Convert the name to lower case so error messages are the same on
2739 for J in 1 .. Name_Len loop
2740 if Name_Buffer (J) in 'A' .. 'Z' then
2742 Character'Val (Character'Pos (Name_Buffer (J)) + 32);
2746 Write_Str (Name_Buffer (1 .. Name_Len));
2748 -- Restore Name_Buffer which was clobbered by the call to
2749 -- Find_Program_Name
2751 Name_Len := Save_Buffer'Last;
2752 Name_Buffer (1 .. Name_Len) := Save_Buffer;
2753 end Write_Program_Name;
2755 ----------------------
2756 -- Write_With_Check --
2757 ----------------------
2759 procedure Write_With_Check (A : Address; N : Integer) is
2763 if N = Write (Output_FD, A, N) then
2767 Write_Str ("error: disk full writing ");
2768 Write_Name_Decoded (Output_File_Name);
2770 Name_Len := Name_Len + 1;
2771 Name_Buffer (Name_Len) := ASCII.NUL;
2772 Delete_File (Name_Buffer'Address, Ignore);
2773 Exit_Program (E_Fatal);
2775 end Write_With_Check;