1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, 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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
27 with ALI
.Util
; use ALI
.Util
;
28 with Binderr
; use Binderr
;
29 with Butil
; use Butil
;
30 with Csets
; use Csets
;
31 with Fname
; use Fname
;
32 with Gnatvsn
; use Gnatvsn
;
33 with GNAT
.OS_Lib
; use GNAT
.OS_Lib
;
34 with Namet
; use Namet
;
36 with Osint
; use Osint
;
37 with Osint
.L
; use Osint
.L
;
38 with Output
; use Output
;
39 with Prj
.Env
; use Prj
.Env
;
40 with Rident
; use Rident
;
44 with Switch
; use Switch
;
45 with Targparm
; use Targparm
;
46 with Types
; use Types
;
48 with Ada
.Command_Line
; use Ada
.Command_Line
;
50 with GNAT
.Command_Line
; use GNAT
.Command_Line
;
51 with GNAT
.Case_Util
; use GNAT
.Case_Util
;
54 pragma Ident
(Gnat_Static_Version_String
);
56 -- NOTE : The following string may be used by other tools, such as GPS. So
57 -- it can only be modified if these other uses are checked and coordinated.
59 Project_Search_Path
: constant String := "Project Search Path:";
60 -- Label displayed in verbose mode before the directories in the project
61 -- search path. Do not modify without checking NOTE above.
63 Prj_Path
: Prj
.Env
.Project_Search_Path
;
65 Max_Column
: constant := 80;
67 No_Obj
: aliased String := "<no_obj>";
70 OK
, -- matching timestamp
71 Checksum_OK
, -- only matching checksum
72 Not_Found
, -- file not found on source PATH
73 Not_Same
, -- neither checksum nor timestamp matching
74 Not_First_On_PATH
); -- matching file hidden by Not_Same file on path
77 type Dir_Ref
is access Dir_Data
;
79 type Dir_Data
is record
80 Value
: String_Access
;
83 -- Simply linked list of dirs
85 First_Source_Dir
: Dir_Ref
;
86 Last_Source_Dir
: Dir_Ref
;
87 -- The list of source directories from the command line.
88 -- These directories are added using Osint.Add_Src_Search_Dir
89 -- after those of the GNAT Project File, if any.
91 First_Lib_Dir
: Dir_Ref
;
92 Last_Lib_Dir
: Dir_Ref
;
93 -- The list of object directories from the command line.
94 -- These directories are added using Osint.Add_Lib_Search_Dir
95 -- after those of the GNAT Project File, if any.
97 Main_File
: File_Name_Type
;
98 Ali_File
: File_Name_Type
;
99 Text
: Text_Buffer_Ptr
;
102 Too_Long
: Boolean := False;
103 -- When True, lines are too long for multi-column output and each
104 -- item of information is on a different line.
106 Selective_Output
: Boolean := False;
107 Print_Usage
: Boolean := False;
108 Print_Unit
: Boolean := True;
109 Print_Source
: Boolean := True;
110 Print_Object
: Boolean := True;
111 -- Flags controlling the form of the output
113 Also_Predef
: Boolean := False; -- -a
114 Dependable
: Boolean := False; -- -d
115 License
: Boolean := False; -- -l
116 Very_Verbose_Mode
: Boolean := False; -- -V
117 -- Command line flags
119 Unit_Start
: Integer;
121 Source_Start
: Integer;
122 Source_End
: Integer;
123 Object_Start
: Integer;
124 Object_End
: Integer;
125 -- Various column starts and ends
127 Spaces
: constant String (1 .. Max_Column
) := (others => ' ');
129 RTS_Specified
: String_Access
:= null;
130 -- Used to detect multiple use of --RTS= switch
132 Exit_Status
: Exit_Code_Type
:= E_Success
;
133 -- Reset to E_Fatal if bad error found
135 -----------------------
136 -- Local Subprograms --
137 -----------------------
139 procedure Add_Lib_Dir
(Dir
: String);
140 -- Add an object directory in the list First_Lib_Dir-Last_Lib_Dir
142 procedure Add_Source_Dir
(Dir
: String);
143 -- Add a source directory in the list First_Source_Dir-Last_Source_Dir
145 procedure Find_General_Layout
;
146 -- Determine the structure of the output (multi columns or not, etc)
148 procedure Find_Status
149 (FS
: in out File_Name_Type
;
150 Stamp
: Time_Stamp_Type
;
152 Status
: out File_Status
);
153 -- Determine the file status (Status) of the file represented by FS with
154 -- the expected Stamp and checksum given as argument. FS will be updated
155 -- to the full file name if available.
157 function Corresponding_Sdep_Entry
(A
: ALI_Id
; U
: Unit_Id
) return Sdep_Id
;
158 -- Give the Sdep entry corresponding to the unit U in ali record A
160 procedure Output_Object
(O
: File_Name_Type
);
161 -- Print out the name of the object when requested
163 procedure Output_Source
(Sdep_I
: Sdep_Id
);
164 -- Print out the name and status of the source corresponding to this
167 procedure Output_Status
(FS
: File_Status
; Verbose
: Boolean);
168 -- Print out FS either in a coded form if verbose is false or in an
169 -- expanded form otherwise.
171 procedure Output_Unit
(ALI
: ALI_Id
; U_Id
: Unit_Id
);
172 -- Print out information on the unit when requested
174 procedure Reset_Print
;
175 -- Reset Print flags properly when selective output is chosen
177 procedure Scan_Ls_Arg
(Argv
: String);
178 -- Scan and process user specific arguments (Argv is a single argument)
180 procedure Search_RTS
(Name
: String);
181 -- Find include and objects path for the RTS name.
184 -- Print usage message
186 procedure Output_License_Information
;
187 -- Output license statement, and if not found, output reference to COPYING
189 function Image
(Restriction
: Restriction_Id
) return String;
190 -- Returns the capitalized image of Restriction
192 function Normalize
(Path
: String) return String;
193 -- Returns a normalized path name. On Windows, the directory separators are
194 -- set to '\' in Normalize_Pathname.
196 ------------------------------------------
197 -- GNATDIST specific output subprograms --
198 ------------------------------------------
202 -- Any modification to this subunit requires synchronization with the
205 procedure Output_ALI
(A
: ALI_Id
);
206 -- Comment required saying what this routine does ???
208 procedure Output_No_ALI
(Afile
: File_Name_Type
);
209 -- Comments required saying what this routine does ???
217 procedure Add_Lib_Dir
(Dir
: String) is
219 if First_Lib_Dir
= null then
222 (Value => new String'(Dir
),
224 Last_Lib_Dir
:= First_Lib_Dir
;
229 (Value => new String'(Dir
),
231 Last_Lib_Dir
:= Last_Lib_Dir
.Next
;
239 procedure Add_Source_Dir
(Dir
: String) is
241 if First_Source_Dir
= null then
244 (Value => new String'(Dir
),
246 Last_Source_Dir
:= First_Source_Dir
;
249 Last_Source_Dir
.Next
:=
251 (Value => new String'(Dir
),
253 Last_Source_Dir
:= Last_Source_Dir
.Next
;
257 ------------------------------
258 -- Corresponding_Sdep_Entry --
259 ------------------------------
261 function Corresponding_Sdep_Entry
263 U
: Unit_Id
) return Sdep_Id
266 for D
in ALIs
.Table
(A
).First_Sdep
.. ALIs
.Table
(A
).Last_Sdep
loop
267 if Sdep
.Table
(D
).Sfile
= Units
.Table
(U
).Sfile
then
272 Error_Msg_Unit_1
:= Units
.Table
(U
).Uname
;
273 Error_Msg_File_1
:= ALIs
.Table
(A
).Afile
;
275 Error_Msg
("wrong ALI format, can't find dependency line for $ in {");
276 Exit_Program
(E_Fatal
);
278 end Corresponding_Sdep_Entry
;
280 -------------------------
281 -- Find_General_Layout --
282 -------------------------
284 procedure Find_General_Layout
is
285 Max_Unit_Length
: Integer := 11;
286 Max_Src_Length
: Integer := 11;
287 Max_Obj_Length
: Integer := 11;
293 -- Compute maximum of each column
295 for Id
in ALIs
.First
.. ALIs
.Last
loop
296 Get_Name_String
(Units
.Table
(ALIs
.Table
(Id
).First_Unit
).Uname
);
297 if Also_Predef
or else not Is_Internal_Unit
then
301 Max_Unit_Length
:= Integer'Max (Max_Unit_Length
, Len
);
305 FS
:= Full_Source_Name
(ALIs
.Table
(Id
).Sfile
);
308 Get_Name_String
(ALIs
.Table
(Id
).Sfile
);
309 Name_Len
:= Name_Len
+ 13;
311 Get_Name_String
(FS
);
314 Max_Src_Length
:= Integer'Max (Max_Src_Length
, Name_Len
+ 1);
318 if ALIs
.Table
(Id
).No_Object
then
320 Integer'Max (Max_Obj_Length
, No_Obj
'Length);
322 Get_Name_String
(ALIs
.Table
(Id
).Ofile_Full_Name
);
323 Max_Obj_Length
:= Integer'Max (Max_Obj_Length
, Name_Len
+ 1);
329 -- Verify is output is not wider than maximum number of columns
334 (Max_Unit_Length
+ Max_Src_Length
+ Max_Obj_Length
) > Max_Column
;
336 -- Set start and end of columns
339 Object_End
:= Object_Start
- 1;
342 Object_End
:= Object_Start
+ Max_Obj_Length
;
345 Unit_Start
:= Object_End
+ 1;
346 Unit_End
:= Unit_Start
- 1;
349 Unit_End
:= Unit_Start
+ Max_Unit_Length
;
352 Source_Start
:= Unit_End
+ 1;
354 if Source_Start
> Spaces
'Last then
355 Source_Start
:= Spaces
'Last;
358 Source_End
:= Source_Start
- 1;
361 Source_End
:= Source_Start
+ Max_Src_Length
;
363 end Find_General_Layout
;
369 procedure Find_Status
370 (FS
: in out File_Name_Type
;
371 Stamp
: Time_Stamp_Type
;
373 Status
: out File_Status
)
375 Tmp1
: File_Name_Type
;
376 Tmp2
: File_Name_Type
;
379 Tmp1
:= Full_Source_Name
(FS
);
381 if Tmp1
= No_File
then
384 elsif File_Stamp
(Tmp1
) = Stamp
then
388 elsif Checksums_Match
(Get_File_Checksum
(FS
), Checksum
) then
390 Status
:= Checksum_OK
;
393 Tmp2
:= Matching_Full_Source_Name
(FS
, Stamp
);
395 if Tmp2
= No_File
then
400 Status
:= Not_First_On_PATH
;
410 package body GNATDIST
is
413 N_Indents
: Natural := 0;
444 Image
: constant array (Token_Type
) of String_Access
:=
445 (T_No_ALI
=> new String'("No_ALI"),
446 T_ALI => new String'("ALI"),
447 T_Unit
=> new String'("Unit"),
448 T_With => new String'("With"),
449 T_Source
=> new String'("Source"),
450 T_Afile => new String'("Afile"),
451 T_Ofile
=> new String'("Ofile"),
452 T_Sfile => new String'("Sfile"),
453 T_Name
=> new String'("Name"),
454 T_Main => new String'("Main"),
455 T_Kind
=> new String'("Kind"),
456 T_Flags => new String'("Flags"),
457 T_Preelaborated
=> new String'("Preelaborated"),
458 T_Pure => new String'("Pure"),
459 T_Has_RACW
=> new String'("Has_RACW"),
460 T_Remote_Types => new String'("Remote_Types"),
461 T_Shared_Passive
=> new String'("Shared_Passive"),
462 T_RCI => new String'("RCI"),
463 T_Predefined
=> new String'("Predefined"),
464 T_Internal => new String'("Internal"),
465 T_Is_Generic
=> new String'("Is_Generic"),
466 T_Procedure => new String'("procedure"),
467 T_Function
=> new String'("function"),
468 T_Package => new String'("package"),
469 T_Subprogram
=> new String'("subprogram"),
470 T_Spec => new String'("spec"),
471 T_Body
=> new String'("body"));
473 procedure Output_Name (N : Name_Id);
474 -- Remove any encoding info (%b and %s) and output N
476 procedure Output_Afile (A : File_Name_Type);
477 procedure Output_Ofile (O : File_Name_Type);
478 procedure Output_Sfile (S : File_Name_Type);
479 -- Output various names. Check that the name is different from no name.
480 -- Otherwise, skip the output.
482 procedure Output_Token (T : Token_Type);
483 -- Output token using specific format. That is several indentations and:
485 -- T_No_ALI .. T_With : <token> & " =>" & NL
486 -- T_Source .. T_Kind : <token> & " => "
487 -- T_Flags : <token> & " =>"
488 -- T_Preelab .. T_Body : " " & <token>
490 procedure Output_Sdep (S : Sdep_Id);
491 procedure Output_Unit (U : Unit_Id);
492 procedure Output_With (W : With_Id);
493 -- Output this entry as a global section (like ALIs)
499 procedure Output_Afile (A : File_Name_Type) is
502 Output_Token (T_Afile);
512 procedure Output_ALI (A : ALI_Id) is
514 Output_Token (T_ALI);
515 N_Indents := N_Indents + 1;
517 Output_Afile (ALIs.Table (A).Afile);
518 Output_Ofile (ALIs.Table (A).Ofile_Full_Name);
519 Output_Sfile (ALIs.Table (A).Sfile);
523 if ALIs.Table (A).Main_Program /= None then
524 Output_Token (T_Main);
526 if ALIs.Table (A).Main_Program = Proc then
527 Output_Token (T_Procedure);
529 Output_Token (T_Function);
537 for U in ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit loop
543 for S in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
547 N_Indents := N_Indents - 1;
554 procedure Output_No_ALI (Afile : File_Name_Type) is
556 Output_Token (T_No_ALI);
557 N_Indents := N_Indents + 1;
558 Output_Afile (Afile);
559 N_Indents := N_Indents - 1;
566 procedure Output_Name (N : Name_Id) is
568 -- Remove any encoding info (%s or %b)
573 and then Name_Buffer (Name_Len - 1) = '%'
575 Name_Len := Name_Len - 2;
578 Output_Token (T_Name);
579 Write_Str (Name_Buffer (1 .. Name_Len));
587 procedure Output_Ofile (O : File_Name_Type) is
590 Output_Token (T_Ofile);
600 procedure Output_Sdep (S : Sdep_Id) is
602 Output_Token (T_Source);
603 Write_Name (Sdep.Table (S).Sfile);
611 procedure Output_Sfile (S : File_Name_Type) is
612 FS : File_Name_Type := S;
615 if FS /= No_File then
617 -- We want to output the full source name
619 FS := Full_Source_Name (FS);
621 -- There is no full source name. This occurs for instance when a
622 -- withed unit has a spec file but no body file. This situation is
623 -- not a problem for GNATDIST since the unit may be located on a
624 -- partition we do not want to build. However, we need to locate
625 -- the spec file and to find its full source name. Replace the
626 -- body file name with the spec file name used to compile the
627 -- current unit when possible.
633 and then Name_Buffer (Name_Len - 3 .. Name_Len) = ".adb"
635 Name_Buffer (Name_Len) := 's
';
636 FS := Full_Source_Name (Name_Find);
641 if FS /= No_File then
642 Output_Token (T_Sfile);
652 procedure Output_Token (T : Token_Type) is
654 if T in T_No_ALI .. T_Flags then
655 for J in 1 .. N_Indents loop
659 Write_Str (Image (T).all);
661 for J in Image (T)'Length .. 12 loop
667 if T in T_No_ALI .. T_With then
669 elsif T in T_Source .. T_Name then
673 elsif T in T_Preelaborated .. T_Body then
674 if T in T_Preelaborated .. T_Is_Generic then
676 Output_Token (T_Flags);
679 N_Flags := N_Flags + 1;
683 Write_Str (Image (T).all);
686 Write_Str (Image (T).all);
694 procedure Output_Unit (U : Unit_Id) is
696 Output_Token (T_Unit);
697 N_Indents := N_Indents + 1;
701 Output_Name (Name_Id (Units.Table (U).Uname));
705 Output_Token (T_Kind);
707 if Units.Table (U).Unit_Kind = 'p
' then
708 Output_Token (T_Package);
710 Output_Token (T_Subprogram);
713 if Name_Buffer (Name_Len) = 's
' then
714 Output_Token (T_Spec);
716 Output_Token (T_Body);
721 -- Output source file name
723 Output_Sfile (Units.Table (U).Sfile);
729 if Units.Table (U).Preelab then
730 Output_Token (T_Preelaborated);
733 if Units.Table (U).Pure then
734 Output_Token (T_Pure);
737 if Units.Table (U).Has_RACW then
738 Output_Token (T_Has_RACW);
741 if Units.Table (U).Remote_Types then
742 Output_Token (T_Remote_Types);
745 if Units.Table (U).Shared_Passive then
746 Output_Token (T_Shared_Passive);
749 if Units.Table (U).RCI then
750 Output_Token (T_RCI);
753 if Units.Table (U).Predefined then
754 Output_Token (T_Predefined);
757 if Units.Table (U).Internal then
758 Output_Token (T_Internal);
761 if Units.Table (U).Is_Generic then
762 Output_Token (T_Is_Generic);
771 for W in Units.Table (U).First_With .. Units.Table (U).Last_With loop
775 N_Indents := N_Indents - 1;
782 procedure Output_With (W : With_Id) is
784 Output_Token (T_With);
785 N_Indents := N_Indents + 1;
787 Output_Name (Name_Id (Withs.Table (W).Uname));
791 Output_Token (T_Kind);
793 if Name_Buffer (Name_Len) = 's
' then
794 Output_Token (T_Spec);
796 Output_Token (T_Body);
801 Output_Afile (Withs.Table (W).Afile);
802 Output_Sfile (Withs.Table (W).Sfile);
804 N_Indents := N_Indents - 1;
813 function Image (Restriction : Restriction_Id) return String is
814 Result : String := Restriction'Img;
815 Skip : Boolean := True;
818 for J in Result'Range loop
821 Result (J) := To_Upper (Result (J));
823 elsif Result (J) = '_
' then
827 Result (J) := To_Lower (Result (J));
838 function Normalize (Path : String) return String is
840 return Normalize_Pathname (Path);
843 --------------------------------
844 -- Output_License_Information --
845 --------------------------------
847 procedure Output_License_Information is
851 Write_Str ("Please refer to file COPYING in your distribution"
852 & " for license terms.");
856 Exit_Program (E_Success);
857 end Output_License_Information;
863 procedure Output_Object (O : File_Name_Type) is
864 Object_Name : String_Access;
870 Object_Name := To_Host_File_Spec (Name_Buffer (1 .. Name_Len));
872 Object_Name := No_Obj'Unchecked_Access;
875 Write_Str (Object_Name.all);
877 if Print_Source or else Print_Unit then
883 (Object_Start + Object_Name'Length .. Object_End));
893 procedure Output_Source (Sdep_I : Sdep_Id) is
894 Stamp : Time_Stamp_Type;
897 Status : File_Status;
898 Object_Name : String_Access;
901 if Sdep_I = No_Sdep_Id then
905 Stamp := Sdep.Table (Sdep_I).Stamp;
906 Checksum := Sdep.Table (Sdep_I).Checksum;
907 FS := Sdep.Table (Sdep_I).Sfile;
910 Find_Status (FS, Stamp, Checksum, Status);
911 Get_Name_String (FS);
913 Object_Name := To_Host_File_Spec (Name_Buffer (1 .. Name_Len));
916 Write_Str (" Source => ");
917 Write_Str (Object_Name.all);
921 (Spaces (Source_Start + Object_Name'Length .. Source_End));
924 Output_Status (Status, Verbose => True);
929 if not Selective_Output then
930 Output_Status (Status, Verbose => False);
933 Write_Str (Object_Name.all);
942 procedure Output_Status (FS : File_Status; Verbose : Boolean) is
947 Write_Str (" unchanged");
950 Write_Str (" slightly modified");
953 Write_Str (" file not found");
956 Write_Str (" modified");
958 when Not_First_On_PATH =>
959 Write_Str (" unchanged version not first on PATH");
976 when Not_First_On_PATH =>
986 procedure Output_Unit (ALI : ALI_Id; U_Id : Unit_Id) is
988 U : Unit_Record renames Units.Table (U_Id);
992 Get_Name_String (U.Uname);
993 Kind := Name_Buffer (Name_Len);
994 Name_Len := Name_Len - 2;
996 if not Verbose_Mode then
997 Write_Str (Name_Buffer (1 .. Name_Len));
1000 Write_Str ("Unit => ");
1002 Write_Str (" Name => ");
1003 Write_Str (Name_Buffer (1 .. Name_Len));
1005 Write_Str (" Kind => ");
1007 if Units.Table (U_Id).Unit_Kind = 'p
' then
1008 Write_Str ("package ");
1010 Write_Str ("subprogram ");
1020 if Verbose_Mode then
1021 if U.Preelab or else
1024 U.Dynamic_Elab or else
1026 U.Remote_Types or else
1027 U.Shared_Passive or else
1029 U.Predefined or else
1031 U.Is_Generic or else
1032 U.Init_Scalars or else
1033 U.SAL_Interface or else
1034 U.Body_Needed_For_SAL or else
1038 Write_Str (" Flags =>");
1041 Write_Str (" Preelaborable");
1045 Write_Str (" No_Elab_Code");
1049 Write_Str (" Pure");
1052 if U.Dynamic_Elab then
1053 Write_Str (" Dynamic_Elab");
1057 Write_Str (" Has_RACW");
1060 if U.Remote_Types then
1061 Write_Str (" Remote_Types");
1064 if U.Shared_Passive then
1065 Write_Str (" Shared_Passive");
1072 if U.Predefined then
1073 Write_Str (" Predefined");
1077 Write_Str (" Internal");
1080 if U.Is_Generic then
1081 Write_Str (" Is_Generic");
1084 if U.Init_Scalars then
1085 Write_Str (" Init_Scalars");
1088 if U.SAL_Interface then
1089 Write_Str (" SAL_Interface");
1092 if U.Body_Needed_For_SAL then
1093 Write_Str (" Body_Needed_For_SAL");
1096 if U.Elaborate_Body then
1097 Write_Str (" Elaborate Body");
1100 if U.Remote_Types then
1101 Write_Str (" Remote_Types");
1104 if U.Shared_Passive then
1105 Write_Str (" Shared_Passive");
1108 if U.Predefined then
1109 Write_Str (" Predefined");
1114 Restrictions : constant Restrictions_Info :=
1115 ALIs.Table (ALI).Restrictions;
1118 -- If the source was compiled with pragmas Restrictions,
1119 -- Display these restrictions.
1121 if Restrictions.Set /= (All_Restrictions => False) then
1123 Write_Str (" pragma Restrictions =>");
1125 -- For boolean restrictions, just display the name of the
1126 -- restriction; for valued restrictions, also display the
1127 -- restriction value.
1129 for Restriction in All_Restrictions loop
1130 if Restrictions.Set (Restriction) then
1133 Write_Str (Image (Restriction));
1135 if Restriction in All_Parameter_Restrictions then
1137 Write_Str (Restrictions.Value (Restriction)'Img);
1143 -- If the unit violates some Restrictions, display the list of
1144 -- these restrictions.
1146 if Restrictions.Violated /= (All_Restrictions => False) then
1148 Write_Str (" Restrictions violated =>");
1150 -- For boolean restrictions, just display the name of the
1151 -- restriction. For valued restrictions, also display the
1152 -- restriction value.
1154 for Restriction in All_Restrictions loop
1155 if Restrictions.Violated (Restriction) then
1158 Write_Str (Image (Restriction));
1160 if Restriction in All_Parameter_Restrictions then
1161 if Restrictions.Count (Restriction) > 0 then
1164 if Restrictions.Unknown (Restriction) then
1165 Write_Str (" at least");
1168 Write_Str (Restrictions.Count (Restriction)'Img);
1177 if Print_Source then
1182 Write_Str (Spaces (Unit_Start + Name_Len + 1 .. Unit_End));
1192 procedure Reset_Print is
1194 if not Selective_Output then
1195 Selective_Output := True;
1196 Print_Source := False;
1197 Print_Object := False;
1198 Print_Unit := False;
1206 procedure Search_RTS (Name : String) is
1207 Src_Path : String_Ptr;
1208 Lib_Path : String_Ptr;
1209 -- Paths for source and include subdirs
1211 Rts_Full_Path : String_Access;
1212 -- Full path for RTS project
1215 -- Try to find the RTS
1217 Src_Path := Get_RTS_Search_Dir (Name, Include);
1218 Lib_Path := Get_RTS_Search_Dir (Name, Objects);
1220 -- For non-project RTS, both the include and the objects directories
1223 if Src_Path /= null and then Lib_Path /= null then
1224 Add_Search_Dirs (Src_Path, Include);
1225 Add_Search_Dirs (Lib_Path, Objects);
1229 if Lib_Path /= null then
1230 Osint.Fail ("RTS path not valid: missing adainclude directory");
1231 elsif Src_Path /= null then
1232 Osint.Fail ("RTS path not valid: missing adalib directory");
1235 -- Try to find the RTS on the project path. First setup the project path
1237 Initialize_Default_Project_Path
1238 (Prj_Path, Target_Name => Sdefault.Target_Name.all);
1240 Rts_Full_Path := Get_Runtime_Path (Prj_Path, Name);
1242 if Rts_Full_Path /= null then
1244 -- Directory name was found on the project path. Look for the
1245 -- include subdirectory(s).
1247 Src_Path := Get_RTS_Search_Dir (Rts_Full_Path.all, Include);
1249 if Src_Path /= null then
1250 Add_Search_Dirs (Src_Path, Include);
1252 -- Add the lib subdirectory if it exists
1254 Lib_Path := Get_RTS_Search_Dir (Rts_Full_Path.all, Objects);
1256 if Lib_Path /= null then
1257 Add_Search_Dirs (Lib_Path, Objects);
1265 ("RTS path not valid: missing adainclude and adalib directories");
1272 procedure Scan_Ls_Arg (Argv : String) is
1273 FD : File_Descriptor;
1278 pragma Assert (Argv'First = 1);
1280 if Argv'Length = 0 then
1285 if Argv (1) = '-' then
1286 if Argv'Length = 1 then
1287 Fail ("switch character cannot be followed by a blank");
1289 -- Processing for -I-
1291 elsif Argv (2 .. Argv'Last) = "I-" then
1292 Opt.Look_In_Primary_Dir := False;
1294 -- Forbid -?- or -??- where ? is any character
1296 elsif (Argv'Length = 3 and then Argv (3) = '-')
1297 or else (Argv'Length = 4 and then Argv (4) = '-')
1299 Fail ("Trailing ""-"" at the end of " & Argv & " forbidden.");
1301 -- Processing for -Idir
1303 elsif Argv (2) = 'I
' then
1304 Add_Source_Dir (Argv (3 .. Argv'Last));
1305 Add_Lib_Dir (Argv (3 .. Argv'Last));
1307 -- Processing for -aIdir (to gcc this is like a -I switch)
1309 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
1310 Add_Source_Dir (Argv (4 .. Argv'Last));
1312 -- Processing for -aOdir
1314 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
1315 Add_Lib_Dir (Argv (4 .. Argv'Last));
1317 -- Processing for -aLdir (to gnatbind this is like a -aO switch)
1319 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
1320 Add_Lib_Dir (Argv (4 .. Argv'Last));
1322 -- Processing for -aP<dir>
1324 elsif Argv'Length > 3 and then Argv (1 .. 3) = "-aP" then
1325 Add_Directories (Prj_Path, Argv (4 .. Argv'Last));
1327 -- Processing for -nostdinc
1329 elsif Argv (2 .. Argv'Last) = "nostdinc" then
1330 Opt.No_Stdinc := True;
1332 -- Processing for one character switches
1334 elsif Argv'Length = 2 then
1336 when 'a
' => Also_Predef := True;
1337 when 'h
' => Print_Usage := True;
1338 when 'u
' => Reset_Print; Print_Unit := True;
1339 when 's
' => Reset_Print; Print_Source := True;
1340 when 'o
' => Reset_Print; Print_Object := True;
1341 when 'v
' => Verbose_Mode := True;
1342 when 'd
' => Dependable := True;
1343 when 'l
' => License := True;
1344 when 'V
' => Very_Verbose_Mode := True;
1346 when others => OK := False;
1349 -- Processing for -files=file
1351 elsif Argv'Length > 7 and then Argv (1 .. 7) = "-files=" then
1352 FD := Open_Read (Argv (8 .. Argv'Last), GNAT.OS_Lib.Text);
1354 if FD = Invalid_FD then
1355 Osint.Fail ("could not find text file """ &
1356 Argv (8 .. Argv'Last) & '"');
1359 Len := Integer (File_Length (FD));
1362 Buffer : String (1 .. Len + 1);
1363 Index : Positive := 1;
1369 Len := Read (FD, Buffer (1)'Address, Len);
1370 Buffer (Buffer'Last) := ASCII.NUL;
1373 -- Scan the file line by line
1375 while Index < Buffer'Last loop
1377 -- Find the end of line
1380 while Last <= Buffer'Last
1381 and then Buffer (Last) /= ASCII.LF
1382 and then Buffer (Last) /= ASCII.CR
1387 -- Ignore empty lines
1389 if Last > Index then
1390 Add_File (Buffer (Index .. Last - 1));
1393 -- Find the beginning of the next line
1396 while Buffer (Index) = ASCII.CR or else
1397 Buffer (Index) = ASCII.LF
1404 -- Processing for --RTS=path
1406 elsif Argv'Length >= 5 and then Argv (1 .. 5) = "--RTS" then
1407 if Argv
'Length <= 6 or else Argv
(6) /= '='then
1408 Osint
.Fail
("missing path for --RTS");
1411 -- Check that it is the first time we see this switch or, if
1412 -- it is not the first time, the same path is specified.
1414 if RTS_Specified
= null then
1415 RTS_Specified
:= new String'(Argv (7 .. Argv'Last));
1417 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
1418 Osint.Fail ("--RTS cannot be specified multiple times");
1421 -- Valid --RTS switch
1423 Opt.No_Stdinc := True;
1424 Opt.RTS_Switch := True;
1431 -- If not a switch, it must be a file name
1438 Write_Str ("warning: unknown switch """);
1453 Write_Str ("Usage: ");
1454 Osint.Write_Program_Name;
1455 Write_Str (" switches [list of object files]");
1461 Write_Str ("switches:");
1464 Display_Usage_Version_And_Help;
1468 Write_Str (" -a also output relevant predefined units");
1473 Write_Str (" -u output only relevant unit names");
1478 Write_Str (" -h output this help message");
1483 Write_Str (" -s output only relevant source names");
1488 Write_Str (" -o output only relevant object names");
1493 Write_Str (" -d output sources on which specified units " &
1499 Write_Str (" -l output license information");
1504 Write_Str (" -v verbose output, full path and unit " &
1511 Write_Str (" -files=fil files are listed in text file 'fil
'");
1514 -- Line for -aI switch
1516 Write_Str (" -aIdir specify source files search path");
1519 -- Line for -aO switch
1521 Write_Str (" -aOdir specify object files search path");
1524 -- Line for -aP switch
1526 Write_Str (" -aPdir specify project search path");
1529 -- Line for -I switch
1531 Write_Str (" -Idir like -aIdir -aOdir");
1534 -- Line for -I- switch
1536 Write_Str (" -I- do not look for sources & object files");
1537 Write_Str (" in the default directory");
1540 -- Line for -nostdinc
1542 Write_Str (" -nostdinc do not look for source files");
1543 Write_Str (" in the system default directory");
1548 Write_Str (" --RTS=dir specify the default source and object search"
1552 -- File Status explanation
1555 Write_Str (" file status can be:");
1558 for ST in File_Status loop
1560 Output_Status (ST, Verbose => False);
1561 Write_Str (" ==> ");
1562 Output_Status (ST, Verbose => True);
1567 procedure Check_Version_And_Help is new Check_Version_And_Help_G (Usage);
1569 -- Start of processing for Gnatls
1572 -- Initialize standard packages
1578 -- First check for --version or --help
1580 Check_Version_And_Help ("GNATLS", "1992");
1582 -- Loop to scan out arguments
1585 Scan_Args : while Next_Arg < Arg_Count loop
1587 Next_Argv : String (1 .. Len_Arg (Next_Arg));
1589 Fill_Arg (Next_Argv'Address, Next_Arg);
1590 Scan_Ls_Arg (Next_Argv);
1593 Next_Arg := Next_Arg + 1;
1596 -- If -l (output license information) is given, it must be the only switch
1598 if License and then Arg_Count /= 2 then
1600 Write_Str ("Can't use -l with another switch");
1603 Exit_Program (E_Fatal);
1606 -- Handle --RTS switch
1608 if RTS_Specified /= null then
1609 Search_RTS (RTS_Specified.all);
1612 -- Add the source and object directories specified on the command line, if
1613 -- any, to the searched directories.
1615 while First_Source_Dir /= null loop
1616 Add_Src_Search_Dir (First_Source_Dir.Value.all);
1617 First_Source_Dir := First_Source_Dir.Next;
1620 while First_Lib_Dir /= null loop
1621 Add_Lib_Search_Dir (First_Lib_Dir.Value.all);
1622 First_Lib_Dir := First_Lib_Dir.Next;
1625 -- Finally, add the default directories
1627 Osint.Add_Default_Search_Dirs;
1629 -- Get the target parameters, but only if switch -nostdinc was not
1630 -- specified. May not be needed any more, but is harmless.
1632 if not Opt.No_Stdinc then
1633 Get_Target_Parameters;
1636 if Verbose_Mode then
1638 Display_Version ("GNATLS", "1997");
1640 Write_Str ("Source Search Path:");
1643 for J in 1 .. Nb_Dir_In_Src_Search_Path loop
1646 if Dir_In_Src_Search_Path (J)'Length = 0 then
1647 Write_Str ("<Current_Directory>");
1652 (Dir_In_Src_Search_Path (J).all, True).all));
1660 Write_Str ("Object Search Path:");
1663 for J in 1 .. Nb_Dir_In_Obj_Search_Path loop
1666 if Dir_In_Obj_Search_Path (J)'Length = 0 then
1667 Write_Str ("<Current_Directory>");
1672 (Dir_In_Obj_Search_Path (J).all, True).all));
1680 Write_Str (Project_Search_Path);
1682 Write_Str (" <Current_Directory>");
1685 Initialize_Default_Project_Path
1686 (Prj_Path, Target_Name => Sdefault.Target_Name.all);
1689 Project_Path : String_Access;
1694 Get_Path (Prj_Path, Project_Path);
1696 if Project_Path.all /= "" then
1697 First := Project_Path'First;
1699 while First <= Project_Path'Last
1700 and then (Project_Path (First) = Path_Separator)
1705 exit when First > Project_Path'Last;
1708 while Last < Project_Path'Last
1709 and then Project_Path (Last + 1) /= Path_Separator
1714 if First /= Last or else Project_Path (First) /= '.' then
1716 -- If the directory is ".", skip it as it is the current
1717 -- directory and it is already the first directory in the
1724 (Project_Path (First .. Last), True).all));
1736 -- Output usage information when requested
1742 -- Output license information when requested
1745 Output_License_Information;
1746 Exit_Program (E_Success);
1749 if not More_Lib_Files then
1750 if not Print_Usage and then not Verbose_Mode then
1751 if Argument_Count = 0 then
1758 Exit_Program (E_Fatal);
1762 Initialize_ALI_Source;
1764 -- Print out all libraries for which no ALI files can be located
1766 while More_Lib_Files loop
1767 Main_File := Next_Main_Lib_File;
1768 Ali_File := Full_Lib_File_Name (Lib_File_Name (Main_File));
1770 if Ali_File = No_File then
1771 if Very_Verbose_Mode then
1772 GNATDIST.Output_No_ALI (Lib_File_Name (Main_File));
1776 Write_Str ("Can't find library info for ");
1777 Get_Name_String (Main_File);
1778 Write_Char ('"'); -- "
1779 Write_Str
(Name_Buffer
(1 .. Name_Len
));
1780 Write_Char
('"'); -- "
1782 Exit_Status
:= E_Fatal
;
1786 Ali_File
:= Strip_Directory
(Ali_File
);
1788 if Get_Name_Table_Info
(Ali_File
) = 0 then
1789 Text
:= Read_Library_Info
(Ali_File
, True);
1800 Ignore_Errors
=> True);
1808 -- Reset default output file descriptor, if needed
1810 Set_Standard_Output
;
1812 if Very_Verbose_Mode
then
1813 for A
in ALIs
.First
.. ALIs
.Last
loop
1814 GNATDIST
.Output_ALI
(A
);
1820 Find_General_Layout
;
1822 for Id
in ALIs
.First
.. ALIs
.Last
loop
1827 Get_Name_String
(Units
.Table
(ALIs
.Table
(Id
).First_Unit
).Uname
);
1829 if Also_Predef
or else not Is_Internal_Unit
then
1830 if ALIs
.Table
(Id
).No_Object
then
1831 Output_Object
(No_File
);
1833 Output_Object
(ALIs
.Table
(Id
).Ofile_Full_Name
);
1836 -- In verbose mode print all main units in the ALI file, otherwise
1837 -- just print the first one to ease columnwise printout
1839 if Verbose_Mode
then
1840 Last_U
:= ALIs
.Table
(Id
).Last_Unit
;
1842 Last_U
:= ALIs
.Table
(Id
).First_Unit
;
1845 for U
in ALIs
.Table
(Id
).First_Unit
.. Last_U
loop
1846 if U
/= ALIs
.Table
(Id
).First_Unit
1847 and then Selective_Output
1853 Output_Unit
(Id
, U
);
1855 -- Output source now, unless if it will be done as part of
1856 -- outputing dependencies.
1858 if not (Dependable
and then Print_Source
) then
1859 Output_Source
(Corresponding_Sdep_Entry
(Id
, U
));
1863 -- Print out list of units on which this unit depends (D lines)
1865 if Dependable
and then Print_Source
then
1866 if Verbose_Mode
then
1867 Write_Str
("depends upon");
1875 ALIs
.Table
(Id
).First_Sdep
.. ALIs
.Table
(Id
).Last_Sdep
1878 or else not Is_Internal_File_Name
(Sdep
.Table
(D
).Sfile
)
1880 if Verbose_Mode
then
1890 Write_Str
(Spaces
(1 .. Source_Start
- 2));
1903 -- All done. Set proper exit status
1906 Exit_Program
(Exit_Status
);