1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004 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 ------------------------------------------------------------------------------
28 with ALI
.Util
; use ALI
.Util
;
29 with Binderr
; use Binderr
;
30 with Butil
; use Butil
;
31 with Csets
; use Csets
;
32 with Fname
; use Fname
;
33 with Gnatvsn
; use Gnatvsn
;
34 with GNAT
.OS_Lib
; use GNAT
.OS_Lib
;
35 with Namet
; use Namet
;
37 with Osint
; use Osint
;
38 with Osint
.L
; use Osint
.L
;
39 with Output
; use Output
;
40 with Rident
; use Rident
;
42 with Targparm
; use Targparm
;
43 with Types
; use Types
;
45 with GNAT
.Case_Util
; use GNAT
.Case_Util
;
48 pragma Ident
(Gnat_Static_Version_String
);
50 Max_Column
: constant := 80;
52 No_Obj
: aliased String := "<no_obj>";
55 OK
, -- matching timestamp
56 Checksum_OK
, -- only matching checksum
57 Not_Found
, -- file not found on source PATH
58 Not_Same
, -- neither checksum nor timestamp matching
59 Not_First_On_PATH
); -- matching file hidden by Not_Same file on path
62 type Dir_Ref
is access Dir_Data
;
64 type Dir_Data
is record
65 Value
: String_Access
;
70 First_Source_Dir
: Dir_Ref
;
71 Last_Source_Dir
: Dir_Ref
;
72 -- The list of source directories from the command line.
73 -- These directories are added using Osint.Add_Src_Search_Dir
74 -- after those of the GNAT Project File, if any.
76 First_Lib_Dir
: Dir_Ref
;
77 Last_Lib_Dir
: Dir_Ref
;
78 -- The list of object directories from the command line.
79 -- These directories are added using Osint.Add_Lib_Search_Dir
80 -- after those of the GNAT Project File, if any.
82 Main_File
: File_Name_Type
;
83 Ali_File
: File_Name_Type
;
84 Text
: Text_Buffer_Ptr
;
87 Too_Long
: Boolean := False;
88 -- When True, lines are too long for multi-column output and each
89 -- item of information is on a different line.
91 Selective_Output
: Boolean := False;
92 Print_Usage
: Boolean := False;
93 Print_Unit
: Boolean := True;
94 Print_Source
: Boolean := True;
95 Print_Object
: Boolean := True;
96 -- Flags controlling the form of the output
98 Dependable
: Boolean := False; -- flag -d
99 Also_Predef
: Boolean := False;
101 Very_Verbose_Mode
: Boolean := False; -- flag -V
103 Unit_Start
: Integer;
105 Source_Start
: Integer;
106 Source_End
: Integer;
107 Object_Start
: Integer;
108 Object_End
: Integer;
109 -- Various column starts and ends
111 Spaces
: constant String (1 .. Max_Column
) := (others => ' ');
113 RTS_Specified
: String_Access
:= null;
114 -- Used to detect multiple use of --RTS= switch
116 -----------------------
117 -- Local Subprograms --
118 -----------------------
120 procedure Add_Lib_Dir
(Dir
: String);
121 -- Add an object directory in the list First_Lib_Dir-Last_Lib_Dir
123 procedure Add_Source_Dir
(Dir
: String);
124 -- Add a source directory in the list First_Source_Dir-Last_Source_Dir
126 procedure Find_General_Layout
;
127 -- Determine the structure of the output (multi columns or not, etc)
129 procedure Find_Status
130 (FS
: in out File_Name_Type
;
131 Stamp
: Time_Stamp_Type
;
133 Status
: out File_Status
);
134 -- Determine the file status (Status) of the file represented by FS
135 -- with the expected Stamp and checksum given as argument. FS will be
136 -- updated to the full file name if available.
138 function Corresponding_Sdep_Entry
(A
: ALI_Id
; U
: Unit_Id
) return Sdep_Id
;
139 -- Give the Sdep entry corresponding to the unit U in ali record A
141 procedure Output_Object
(O
: File_Name_Type
);
142 -- Print out the name of the object when requested
144 procedure Output_Source
(Sdep_I
: Sdep_Id
);
145 -- Print out the name and status of the source corresponding to this
148 procedure Output_Status
(FS
: File_Status
; Verbose
: Boolean);
149 -- Print out FS either in a coded form if verbose is false or in an
150 -- expanded form otherwise.
152 procedure Output_Unit
(ALI
: ALI_Id
; U_Id
: Unit_Id
);
153 -- Print out information on the unit when requested
155 procedure Reset_Print
;
156 -- Reset Print flags properly when selective output is chosen
158 procedure Scan_Ls_Arg
(Argv
: String);
159 -- Scan and process lser specific arguments. Argv is a single argument
162 -- Print usage message
164 function Image
(Restriction
: Restriction_Id
) return String;
165 -- Returns the capitalized image of Restriction
167 ---------------------------------------
168 -- GLADE specific output subprograms --
169 ---------------------------------------
173 -- Any modification to this subunit requires a synchronization
174 -- with the GLADE implementation.
176 procedure Output_ALI
(A
: ALI_Id
);
177 procedure Output_No_ALI
(Afile
: File_Name_Type
);
185 procedure Add_Lib_Dir
(Dir
: String) is
187 if First_Lib_Dir
= null then
190 (Value => new String'(Dir
),
192 Last_Lib_Dir
:= First_Lib_Dir
;
197 (Value => new String'(Dir
),
199 Last_Lib_Dir
:= Last_Lib_Dir
.Next
;
207 procedure Add_Source_Dir
(Dir
: String) is
209 if First_Source_Dir
= null then
212 (Value => new String'(Dir
),
214 Last_Source_Dir
:= First_Source_Dir
;
217 Last_Source_Dir
.Next
:=
219 (Value => new String'(Dir
),
221 Last_Source_Dir
:= Last_Source_Dir
.Next
;
225 ------------------------------
226 -- Corresponding_Sdep_Entry --
227 ------------------------------
229 function Corresponding_Sdep_Entry
231 U
: Unit_Id
) return Sdep_Id
234 for D
in ALIs
.Table
(A
).First_Sdep
.. ALIs
.Table
(A
).Last_Sdep
loop
235 if Sdep
.Table
(D
).Sfile
= Units
.Table
(U
).Sfile
then
240 Error_Msg_Name_1
:= Units
.Table
(U
).Uname
;
241 Error_Msg_Name_2
:= ALIs
.Table
(A
).Afile
;
243 Error_Msg
("wrong ALI format, can't find dependency line for & in %");
244 Exit_Program
(E_Fatal
);
245 end Corresponding_Sdep_Entry
;
247 -------------------------
248 -- Find_General_Layout --
249 -------------------------
251 procedure Find_General_Layout
is
252 Max_Unit_Length
: Integer := 11;
253 Max_Src_Length
: Integer := 11;
254 Max_Obj_Length
: Integer := 11;
260 -- Compute maximum of each column
262 for Id
in ALIs
.First
.. ALIs
.Last
loop
263 Get_Name_String
(Units
.Table
(ALIs
.Table
(Id
).First_Unit
).Uname
);
264 if Also_Predef
or else not Is_Internal_Unit
then
268 Max_Unit_Length
:= Integer'Max (Max_Unit_Length
, Len
);
272 FS
:= Full_Source_Name
(ALIs
.Table
(Id
).Sfile
);
275 Get_Name_String
(ALIs
.Table
(Id
).Sfile
);
276 Name_Len
:= Name_Len
+ 13;
278 Get_Name_String
(FS
);
281 Max_Src_Length
:= Integer'Max (Max_Src_Length
, Name_Len
+ 1);
285 if ALIs
.Table
(Id
).No_Object
then
287 Integer'Max (Max_Obj_Length
, No_Obj
'Length);
289 Get_Name_String
(ALIs
.Table
(Id
).Ofile_Full_Name
);
290 Max_Obj_Length
:= Integer'Max (Max_Obj_Length
, Name_Len
+ 1);
296 -- Verify is output is not wider than maximum number of columns
301 (Max_Unit_Length
+ Max_Src_Length
+ Max_Obj_Length
) > Max_Column
;
303 -- Set start and end of columns
306 Object_End
:= Object_Start
- 1;
309 Object_End
:= Object_Start
+ Max_Obj_Length
;
312 Unit_Start
:= Object_End
+ 1;
313 Unit_End
:= Unit_Start
- 1;
316 Unit_End
:= Unit_Start
+ Max_Unit_Length
;
319 Source_Start
:= Unit_End
+ 1;
321 if Source_Start
> Spaces
'Last then
322 Source_Start
:= Spaces
'Last;
325 Source_End
:= Source_Start
- 1;
328 Source_End
:= Source_Start
+ Max_Src_Length
;
330 end Find_General_Layout
;
336 procedure Find_Status
337 (FS
: in out File_Name_Type
;
338 Stamp
: Time_Stamp_Type
;
340 Status
: out File_Status
)
342 Tmp1
: File_Name_Type
;
343 Tmp2
: File_Name_Type
;
346 Tmp1
:= Full_Source_Name
(FS
);
348 if Tmp1
= No_File
then
351 elsif File_Stamp
(Tmp1
) = Stamp
then
355 elsif Checksums_Match
(Get_File_Checksum
(FS
), Checksum
) then
357 Status
:= Checksum_OK
;
360 Tmp2
:= Matching_Full_Source_Name
(FS
, Stamp
);
362 if Tmp2
= No_File
then
367 Status
:= Not_First_On_PATH
;
377 package body GLADE
is
380 N_Indents
: Natural := 0;
411 Image
: constant array (Token_Type
) of String_Access
:=
412 (T_No_ALI
=> new String'("No_ALI"),
413 T_ALI => new String'("ALI"),
414 T_Unit
=> new String'("Unit"),
415 T_With => new String'("With"),
416 T_Source
=> new String'("Source"),
417 T_Afile => new String'("Afile"),
418 T_Ofile
=> new String'("Ofile"),
419 T_Sfile => new String'("Sfile"),
420 T_Name
=> new String'("Name"),
421 T_Main => new String'("Main"),
422 T_Kind
=> new String'("Kind"),
423 T_Flags => new String'("Flags"),
424 T_Preelaborated
=> new String'("Preelaborated"),
425 T_Pure => new String'("Pure"),
426 T_Has_RACW
=> new String'("Has_RACW"),
427 T_Remote_Types => new String'("Remote_Types"),
428 T_Shared_Passive
=> new String'("Shared_Passive"),
429 T_RCI => new String'("RCI"),
430 T_Predefined
=> new String'("Predefined"),
431 T_Internal => new String'("Internal"),
432 T_Is_Generic
=> new String'("Is_Generic"),
433 T_Procedure => new String'("procedure"),
434 T_Function
=> new String'("function"),
435 T_Package => new String'("package"),
436 T_Subprogram
=> new String'("subprogram"),
437 T_Spec => new String'("spec"),
438 T_Body
=> new String'("body"));
440 procedure Output_Name (N : Name_Id);
441 -- Remove any encoding info (%b and %s) and output N
443 procedure Output_Afile (A : File_Name_Type);
444 procedure Output_Ofile (O : File_Name_Type);
445 procedure Output_Sfile (S : File_Name_Type);
446 -- Output various names. Check that the name is different from
447 -- no name. Otherwise, skip the output.
449 procedure Output_Token (T : Token_Type);
450 -- Output token using a specific format. That is several
453 -- T_No_ALI .. T_With : <token> & " =>" & NL
454 -- T_Source .. T_Kind : <token> & " => "
455 -- T_Flags : <token> & " =>"
456 -- T_Preelab .. T_Body : " " & <token>
458 procedure Output_Sdep (S : Sdep_Id);
459 procedure Output_Unit (U : Unit_Id);
460 procedure Output_With (W : With_Id);
461 -- Output this entry as a global section (like ALIs)
467 procedure Output_Afile (A : File_Name_Type) is
470 Output_Token (T_Afile);
480 procedure Output_ALI (A : ALI_Id) is
482 Output_Token (T_ALI);
483 N_Indents := N_Indents + 1;
485 Output_Afile (ALIs.Table (A).Afile);
486 Output_Ofile (ALIs.Table (A).Ofile_Full_Name);
487 Output_Sfile (ALIs.Table (A).Sfile);
491 if ALIs.Table (A).Main_Program /= None then
492 Output_Token (T_Main);
494 if ALIs.Table (A).Main_Program = Proc then
495 Output_Token (T_Procedure);
497 Output_Token (T_Function);
505 for U in ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit loop
511 for S in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
515 N_Indents := N_Indents - 1;
522 procedure Output_No_ALI (Afile : File_Name_Type) is
524 Output_Token (T_No_ALI);
525 N_Indents := N_Indents + 1;
526 Output_Afile (Afile);
527 N_Indents := N_Indents - 1;
534 procedure Output_Name (N : Name_Id) is
536 -- Remove any encoding info (%s or %b)
540 and then Name_Buffer (Name_Len - 1) = '%'
542 Name_Len := Name_Len - 2;
545 Output_Token (T_Name);
546 Write_Str (Name_Buffer (1 .. Name_Len));
554 procedure Output_Ofile (O : File_Name_Type) is
557 Output_Token (T_Ofile);
567 procedure Output_Sdep (S : Sdep_Id) is
569 Output_Token (T_Source);
570 Write_Name (Sdep.Table (S).Sfile);
578 procedure Output_Sfile (S : File_Name_Type) is
579 FS : File_Name_Type := S;
582 if FS /= No_File then
584 -- We want to output the full source name
586 FS := Full_Source_Name (FS);
588 -- There is no full source name. This occurs for instance when a
589 -- withed unit has a spec file but no body file. This situation
590 -- is not a problem for GLADE since the unit may be located on
591 -- a partition we do not want to build. However, we need to
592 -- locate the spec file and to find its full source name.
593 -- Replace the body file name with the spec file name used to
594 -- compile the current unit when possible.
600 and then Name_Buffer (Name_Len - 3 .. Name_Len) = ".adb"
602 Name_Buffer (Name_Len) := 's
';
603 FS := Full_Source_Name (Name_Find);
608 if FS /= No_File then
609 Output_Token (T_Sfile);
619 procedure Output_Token (T : Token_Type) is
621 if T in T_No_ALI .. T_Flags then
622 for J in 1 .. N_Indents loop
626 Write_Str (Image (T).all);
628 for J in Image (T)'Length .. 12 loop
634 if T in T_No_ALI .. T_With then
636 elsif T in T_Source .. T_Name then
640 elsif T in T_Preelaborated .. T_Body then
641 if T in T_Preelaborated .. T_Is_Generic then
643 Output_Token (T_Flags);
646 N_Flags := N_Flags + 1;
650 Write_Str (Image (T).all);
653 Write_Str (Image (T).all);
661 procedure Output_Unit (U : Unit_Id) is
663 Output_Token (T_Unit);
664 N_Indents := N_Indents + 1;
668 Output_Name (Units.Table (U).Uname);
672 Output_Token (T_Kind);
674 if Units.Table (U).Unit_Kind = 'p
' then
675 Output_Token (T_Package);
677 Output_Token (T_Subprogram);
680 if Name_Buffer (Name_Len) = 's
' then
681 Output_Token (T_Spec);
683 Output_Token (T_Body);
688 -- Output source file name
690 Output_Sfile (Units.Table (U).Sfile);
696 if Units.Table (U).Preelab then
697 Output_Token (T_Preelaborated);
700 if Units.Table (U).Pure then
701 Output_Token (T_Pure);
704 if Units.Table (U).Has_RACW then
705 Output_Token (T_Has_RACW);
708 if Units.Table (U).Remote_Types then
709 Output_Token (T_Remote_Types);
712 if Units.Table (U).Shared_Passive then
713 Output_Token (T_Shared_Passive);
716 if Units.Table (U).RCI then
717 Output_Token (T_RCI);
720 if Units.Table (U).Predefined then
721 Output_Token (T_Predefined);
724 if Units.Table (U).Internal then
725 Output_Token (T_Internal);
728 if Units.Table (U).Is_Generic then
729 Output_Token (T_Is_Generic);
738 for W in Units.Table (U).First_With .. Units.Table (U).Last_With loop
742 N_Indents := N_Indents - 1;
749 procedure Output_With (W : With_Id) is
751 Output_Token (T_With);
752 N_Indents := N_Indents + 1;
754 Output_Name (Withs.Table (W).Uname);
758 Output_Token (T_Kind);
760 if Name_Buffer (Name_Len) = 's
' then
761 Output_Token (T_Spec);
763 Output_Token (T_Body);
768 Output_Afile (Withs.Table (W).Afile);
769 Output_Sfile (Withs.Table (W).Sfile);
771 N_Indents := N_Indents - 1;
780 function Image (Restriction : Restriction_Id) return String is
781 Result : String := Restriction'Img;
782 Skip : Boolean := True;
785 for J in Result'Range loop
788 Result (J) := To_Upper (Result (J));
790 elsif Result (J) = '_
' then
794 Result (J) := To_Lower (Result (J));
805 procedure Output_Object (O : File_Name_Type) is
806 Object_Name : String_Access;
812 Object_Name := To_Host_File_Spec (Name_Buffer (1 .. Name_Len));
814 Object_Name := No_Obj'Unchecked_Access;
817 Write_Str (Object_Name.all);
819 if Print_Source or else Print_Unit then
825 (Object_Start + Object_Name'Length .. Object_End));
835 procedure Output_Source (Sdep_I : Sdep_Id) is
836 Stamp : constant Time_Stamp_Type := Sdep.Table (Sdep_I).Stamp;
837 Checksum : constant Word := Sdep.Table (Sdep_I).Checksum;
838 FS : File_Name_Type := Sdep.Table (Sdep_I).Sfile;
839 Status : File_Status;
840 Object_Name : String_Access;
844 Find_Status (FS, Stamp, Checksum, Status);
845 Get_Name_String (FS);
847 Object_Name := To_Host_File_Spec (Name_Buffer (1 .. Name_Len));
850 Write_Str (" Source => ");
851 Write_Str (Object_Name.all);
855 (Spaces (Source_Start + Object_Name'Length .. Source_End));
858 Output_Status (Status, Verbose => True);
863 if not Selective_Output then
864 Output_Status (Status, Verbose => False);
867 Write_Str (Object_Name.all);
876 procedure Output_Status (FS : File_Status; Verbose : Boolean) is
881 Write_Str (" unchanged");
884 Write_Str (" slightly modified");
887 Write_Str (" file not found");
890 Write_Str (" modified");
892 when Not_First_On_PATH =>
893 Write_Str (" unchanged version not first on PATH");
910 when Not_First_On_PATH =>
920 procedure Output_Unit (ALI : ALI_Id; U_Id : Unit_Id) is
922 U : Unit_Record renames Units.Table (U_Id);
926 Get_Name_String (U.Uname);
927 Kind := Name_Buffer (Name_Len);
928 Name_Len := Name_Len - 2;
930 if not Verbose_Mode then
931 Write_Str (Name_Buffer (1 .. Name_Len));
934 Write_Str ("Unit => ");
936 Write_Str (" Name => ");
937 Write_Str (Name_Buffer (1 .. Name_Len));
939 Write_Str (" Kind => ");
941 if Units.Table (U_Id).Unit_Kind = 'p
' then
942 Write_Str ("package ");
944 Write_Str ("subprogram ");
968 U.Body_Needed_For_SAL or
972 Write_Str (" Flags =>");
975 Write_Str (" Preelaborable");
979 Write_Str (" No_Elab_Code");
986 if U.Dynamic_Elab then
987 Write_Str (" Dynamic_Elab");
991 Write_Str (" Has_RACW");
994 if U.Remote_Types then
995 Write_Str (" Remote_Types");
998 if U.Shared_Passive then
999 Write_Str (" Shared_Passive");
1006 if U.Predefined then
1007 Write_Str (" Predefined");
1011 Write_Str (" Internal");
1014 if U.Is_Generic then
1015 Write_Str (" Is_Generic");
1018 if U.Init_Scalars then
1019 Write_Str (" Init_Scalars");
1023 Write_Str (" Interface");
1026 if U.Body_Needed_For_SAL then
1027 Write_Str (" Body_Needed_For_SAL");
1030 if U.Elaborate_Body then
1031 Write_Str (" Elaborate Body");
1034 if U.Remote_Types then
1035 Write_Str (" Remote_Types");
1038 if U.Shared_Passive then
1039 Write_Str (" Shared_Passive");
1042 if U.Predefined then
1043 Write_Str (" Predefined");
1049 Restrictions : constant Restrictions_Info :=
1050 ALIs.Table (ALI).Restrictions;
1053 -- If the source was compiled with pragmas Restrictions,
1054 -- Display these restrictions.
1056 if Restrictions.Set /= (All_Restrictions => False) then
1058 Write_Str (" pragma Restrictions =>");
1060 -- For boolean restrictions, just display the name of the
1061 -- restriction; for valued restrictions, also display the
1062 -- restriction value.
1064 for Restriction in All_Restrictions loop
1065 if Restrictions.Set (Restriction) then
1068 Write_Str (Image (Restriction));
1070 if Restriction in All_Parameter_Restrictions then
1072 Write_Str (Restrictions.Value (Restriction)'Img);
1078 -- If the unit violates some Restrictions, display the list of
1079 -- these restrictions.
1081 if Restrictions.Violated /= (All_Restrictions => False) then
1083 Write_Str (" Restrictions violated =>");
1085 -- For boolean restrictions, just display the name of the
1086 -- restriction; for valued restrictions, also display the
1087 -- restriction value.
1089 for Restriction in All_Restrictions loop
1090 if Restrictions.Violated (Restriction) then
1093 Write_Str (Image (Restriction));
1095 if Restriction in All_Parameter_Restrictions then
1096 if Restrictions.Count (Restriction) > 0 then
1099 if Restrictions.Unknown (Restriction) then
1100 Write_Str (" at least");
1103 Write_Str (Restrictions.Count (Restriction)'Img);
1112 if Print_Source then
1117 Write_Str (Spaces (Unit_Start + Name_Len + 1 .. Unit_End));
1127 procedure Reset_Print is
1129 if not Selective_Output then
1130 Selective_Output := True;
1131 Print_Source := False;
1132 Print_Object := False;
1133 Print_Unit := False;
1141 procedure Scan_Ls_Arg (Argv : String) is
1142 FD : File_Descriptor;
1146 pragma Assert (Argv'First = 1);
1148 if Argv'Length = 0 then
1152 if Argv (1) = '-' then
1153 if Argv'Length = 1 then
1154 Fail ("switch character cannot be followed by a blank");
1156 -- Processing for -I-
1158 elsif Argv (2 .. Argv'Last) = "I-" then
1159 Opt.Look_In_Primary_Dir := False;
1161 -- Forbid -?- or -??- where ? is any character
1163 elsif (Argv'Length = 3 and then Argv (3) = '-')
1164 or else (Argv'Length = 4 and then Argv (4) = '-')
1166 Fail ("Trailing ""-"" at the end of ", Argv, " forbidden.");
1168 -- Processing for -Idir
1170 elsif Argv (2) = 'I
' then
1171 Add_Source_Dir (Argv (3 .. Argv'Last));
1172 Add_Lib_Dir (Argv (3 .. Argv'Last));
1174 -- Processing for -aIdir (to gcc this is like a -I switch)
1176 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
1177 Add_Source_Dir (Argv (4 .. Argv'Last));
1179 -- Processing for -aOdir
1181 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
1182 Add_Lib_Dir (Argv (4 .. Argv'Last));
1184 -- Processing for -aLdir (to gnatbind this is like a -aO switch)
1186 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
1187 Add_Lib_Dir (Argv (4 .. Argv'Last));
1189 -- Processing for -nostdinc
1191 elsif Argv (2 .. Argv'Last) = "nostdinc" then
1192 Opt.No_Stdinc := True;
1194 -- Processing for one character switches
1196 elsif Argv'Length = 2 then
1198 when 'a
' => Also_Predef := True;
1199 when 'h
' => Print_Usage := True;
1200 when 'u
' => Reset_Print; Print_Unit := True;
1201 when 's
' => Reset_Print; Print_Source := True;
1202 when 'o
' => Reset_Print; Print_Object := True;
1203 when 'v
' => Verbose_Mode := True;
1204 when 'd
' => Dependable := True;
1205 when 'V
' => Very_Verbose_Mode := True;
1207 when others => null;
1210 -- Processing for -files=file
1212 elsif Argv'Length > 7 and then Argv (1 .. 7) = "-files=" then
1213 FD := Open_Read (Argv (8 .. Argv'Last), GNAT.OS_Lib.Text);
1215 if FD = Invalid_FD then
1216 Osint.Fail ("could not find text file """ &
1217 Argv (8 .. Argv'Last) & '"');
1220 Len := Integer (File_Length (FD));
1223 Buffer : String (1 .. Len + 1);
1224 Index : Positive := 1;
1230 Len := Read (FD, Buffer (1)'Address, Len);
1231 Buffer (Buffer'Last) := ASCII.NUL;
1234 -- Scan the file line by line
1236 while Index < Buffer'Last loop
1237 -- Find the end of line
1241 while Last <= Buffer'Last
1242 and then Buffer (Last) /= ASCII.LF
1243 and then Buffer (Last) /= ASCII.CR
1248 -- Ignore empty lines
1250 if Last > Index then
1251 Add_File (Buffer (Index .. Last - 1));
1256 -- Find the beginning of the next line
1258 while Buffer (Index) = ASCII.CR or else
1259 Buffer (Index) = ASCII.LF
1266 -- Processing for --RTS=path
1268 elsif Argv'Length >= 5 and then Argv (1 .. 5) = "--RTS" then
1269 if Argv
'Length <= 6 or else Argv
(6) /= '='then
1270 Osint
.Fail
("missing path for --RTS");
1273 -- Check that it is the first time we see this switch or, if
1274 -- it is not the first time, the same path is specified.
1276 if RTS_Specified
= null then
1277 RTS_Specified
:= new String'(Argv (7 .. Argv'Last));
1279 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
1280 Osint.Fail ("--RTS cannot be specified multiple times");
1283 -- Valid --RTS switch
1285 Opt.No_Stdinc := True;
1286 Opt.RTS_Switch := True;
1289 Src_Path_Name : constant String_Ptr :=
1292 (Argv (7 .. Argv'Last), Include));
1293 Lib_Path_Name : constant String_Ptr :=
1296 (Argv (7 .. Argv'Last), Objects));
1299 if Src_Path_Name /= null
1300 and then Lib_Path_Name /= null
1302 Add_Search_Dirs (Src_Path_Name, Include);
1303 Add_Search_Dirs (Lib_Path_Name, Objects);
1305 elsif Src_Path_Name = null
1306 and then Lib_Path_Name = null
1308 Osint.Fail ("RTS path not valid: missing " &
1309 "adainclude and adalib directories");
1311 elsif Src_Path_Name = null then
1312 Osint.Fail ("RTS path not valid: missing " &
1313 "adainclude directory");
1315 elsif Lib_Path_Name = null then
1316 Osint.Fail ("RTS path not valid: missing " &
1317 "adalib directory");
1323 -- If not a switch, it must be a file name
1338 Write_Str ("Usage: ");
1339 Osint.Write_Program_Name;
1340 Write_Str (" switches [list of object files]");
1346 Write_Str ("switches:");
1351 Write_Str (" -a also output relevant predefined units");
1356 Write_Str (" -u output only relevant unit names");
1361 Write_Str (" -h output this help message");
1366 Write_Str (" -s output only relevant source names");
1371 Write_Str (" -o output only relevant object names");
1376 Write_Str (" -d output sources on which specified units " &
1382 Write_Str (" -v verbose output, full path and unit " &
1389 Write_Str (" -files=fil files are listed in text file 'fil
'");
1392 -- Line for -aI switch
1394 Write_Str (" -aIdir specify source files search path");
1397 -- Line for -aO switch
1399 Write_Str (" -aOdir specify object files search path");
1402 -- Line for -I switch
1404 Write_Str (" -Idir like -aIdir -aOdir");
1407 -- Line for -I- switch
1409 Write_Str (" -I- do not look for sources & object files");
1410 Write_Str (" in the default directory");
1413 -- Line for -nostdinc
1415 Write_Str (" -nostdinc do not look for source files");
1416 Write_Str (" in the system default directory");
1421 Write_Str (" --RTS=dir specify the default source and object search"
1425 -- File Status explanation
1428 Write_Str (" file status can be:");
1431 for ST in File_Status loop
1433 Output_Status (ST, Verbose => False);
1434 Write_Str (" ==> ");
1435 Output_Status (ST, Verbose => True);
1441 -- Start of processing for Gnatls
1444 -- Initialize standard packages
1450 -- Loop to scan out arguments
1453 Scan_Args : while Next_Arg < Arg_Count loop
1455 Next_Argv : String (1 .. Len_Arg (Next_Arg));
1457 Fill_Arg (Next_Argv'Address, Next_Arg);
1458 Scan_Ls_Arg (Next_Argv);
1461 Next_Arg := Next_Arg + 1;
1464 -- Add the source and object directories specified on the
1465 -- command line, if any, to the searched directories.
1467 while First_Source_Dir /= null loop
1468 Add_Src_Search_Dir (First_Source_Dir.Value.all);
1469 First_Source_Dir := First_Source_Dir.Next;
1472 while First_Lib_Dir /= null loop
1473 Add_Lib_Search_Dir (First_Lib_Dir.Value.all);
1474 First_Lib_Dir := First_Lib_Dir.Next;
1477 -- Finally, add the default directories and obtain target parameters
1479 Osint.Add_Default_Search_Dirs;
1481 if Verbose_Mode then
1482 Targparm.Get_Target_Parameters;
1485 Write_Str ("GNATLS ");
1486 Write_Str (Gnat_Version_String);
1488 Write_Str ("Copyright 1997-2004 Free Software Foundation, Inc.");
1491 Write_Str ("Source Search Path:");
1494 for J in 1 .. Nb_Dir_In_Src_Search_Path loop
1497 if Dir_In_Src_Search_Path (J)'Length = 0 then
1498 Write_Str ("<Current_Directory>");
1500 Write_Str (To_Host_Dir_Spec
1501 (Dir_In_Src_Search_Path (J).all, True).all);
1509 Write_Str ("Object Search Path:");
1512 for J in 1 .. Nb_Dir_In_Obj_Search_Path loop
1515 if Dir_In_Obj_Search_Path (J)'Length = 0 then
1516 Write_Str ("<Current_Directory>");
1518 Write_Str (To_Host_Dir_Spec
1519 (Dir_In_Obj_Search_Path (J).all, True).all);
1528 -- Output usage information when requested
1534 if not More_Lib_Files then
1535 if not Print_Usage and then not Verbose_Mode then
1539 Exit_Program (E_Fatal);
1543 Initialize_ALI_Source;
1545 -- Print out all library for which no ALI files can be located
1547 while More_Lib_Files loop
1548 Main_File := Next_Main_Lib_File;
1549 Ali_File := Full_Lib_File_Name (Lib_File_Name (Main_File));
1551 if Ali_File = No_File then
1552 if Very_Verbose_Mode then
1553 GLADE.Output_No_ALI (Lib_File_Name (Main_File));
1556 Write_Str ("Can't find library info for ");
1557 Get_Name_String (Main_File);
1558 Write_Char ('"'); -- "
1559 Write_Str
(Name_Buffer
(1 .. Name_Len
));
1560 Write_Char
('"'); -- "
1565 Ali_File
:= Strip_Directory
(Ali_File
);
1567 if Get_Name_Table_Info
(Ali_File
) = 0 then
1568 Text
:= Read_Library_Info
(Ali_File
, True);
1572 pragma Unreferenced
(Discard
);
1580 Ignore_Errors
=> True);
1588 if Very_Verbose_Mode
then
1589 for A
in ALIs
.First
.. ALIs
.Last
loop
1590 GLADE
.Output_ALI
(A
);
1596 Find_General_Layout
;
1598 for Id
in ALIs
.First
.. ALIs
.Last
loop
1603 Get_Name_String
(Units
.Table
(ALIs
.Table
(Id
).First_Unit
).Uname
);
1605 if Also_Predef
or else not Is_Internal_Unit
then
1606 if ALIs
.Table
(Id
).No_Object
then
1607 Output_Object
(No_File
);
1609 Output_Object
(ALIs
.Table
(Id
).Ofile_Full_Name
);
1612 -- In verbose mode print all main units in the ALI file, otherwise
1613 -- just print the first one to ease columnwise printout
1615 if Verbose_Mode
then
1616 Last_U
:= ALIs
.Table
(Id
).Last_Unit
;
1618 Last_U
:= ALIs
.Table
(Id
).First_Unit
;
1621 for U
in ALIs
.Table
(Id
).First_Unit
.. Last_U
loop
1622 if U
/= ALIs
.Table
(Id
).First_Unit
1623 and then Selective_Output
1629 Output_Unit
(Id
, U
);
1631 -- Output source now, unless if it will be done as part of
1632 -- outputing dependencies.
1634 if not (Dependable
and then Print_Source
) then
1635 Output_Source
(Corresponding_Sdep_Entry
(Id
, U
));
1639 -- Print out list of units on which this unit depends (D lines)
1641 if Dependable
and then Print_Source
then
1642 if Verbose_Mode
then
1643 Write_Str
("depends upon");
1652 ALIs
.Table
(Id
).First_Sdep
.. ALIs
.Table
(Id
).Last_Sdep
1655 or else not Is_Internal_File_Name
(Sdep
.Table
(D
).Sfile
)
1657 if Verbose_Mode
then
1667 Write_Str
(Spaces
(1 .. Source_Start
- 2));
1680 -- All done. Set proper exit status
1683 Exit_Program
(E_Success
);