1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, 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 Rident; use Rident;
42 with Switch; use Switch;
43 with Targparm; use Targparm;
44 with Types; use Types;
46 with GNAT.Case_Util; use GNAT.Case_Util;
49 pragma Ident (Gnat_Static_Version_String);
51 Gpr_Project_Path : constant String := "GPR_PROJECT_PATH";
52 Ada_Project_Path : constant String := "ADA_PROJECT_PATH";
53 -- Names of the env. variables that contains path name(s) of directories
54 -- where project files may reside. If GPR_PROJECT_PATH is defined, its
55 -- value is used, otherwise ADA_PROJECT_PATH is used, if defined.
57 -- NOTE : The following string may be used by other tools, such as GPS. So
58 -- it can only be modified if these other uses are checked and coordinated.
60 Project_Search_Path : constant String := "Project Search Path:";
61 -- Label displayed in verbose mode before the directories in the project
62 -- search path. Do not modify without checking NOTE above.
64 No_Project_Default_Dir : constant String := "-";
66 Max_Column : constant := 80;
68 No_Obj : aliased String := "<no_obj>";
71 OK, -- matching timestamp
72 Checksum_OK, -- only matching checksum
73 Not_Found, -- file not found on source PATH
74 Not_Same, -- neither checksum nor timestamp matching
75 Not_First_On_PATH); -- matching file hidden by Not_Same file on path
78 type Dir_Ref is access Dir_Data;
80 type Dir_Data is record
81 Value : String_Access;
86 First_Source_Dir : Dir_Ref;
87 Last_Source_Dir : Dir_Ref;
88 -- The list of source directories from the command line.
89 -- These directories are added using Osint.Add_Src_Search_Dir
90 -- after those of the GNAT Project File, if any.
92 First_Lib_Dir : Dir_Ref;
93 Last_Lib_Dir : Dir_Ref;
94 -- The list of object directories from the command line.
95 -- These directories are added using Osint.Add_Lib_Search_Dir
96 -- after those of the GNAT Project File, if any.
98 Main_File : File_Name_Type;
99 Ali_File : File_Name_Type;
100 Text : Text_Buffer_Ptr;
103 Too_Long : Boolean := False;
104 -- When True, lines are too long for multi-column output and each
105 -- item of information is on a different line.
107 Selective_Output : Boolean := False;
108 Print_Usage : Boolean := False;
109 Print_Unit : Boolean := True;
110 Print_Source : Boolean := True;
111 Print_Object : Boolean := True;
112 -- Flags controlling the form of the output
114 Also_Predef : Boolean := False; -- -a
115 Dependable : Boolean := False; -- -d
116 License : Boolean := False; -- -l
117 Very_Verbose_Mode : Boolean := False; -- -V
118 -- Command line flags
120 Unit_Start : Integer;
122 Source_Start : Integer;
123 Source_End : Integer;
124 Object_Start : Integer;
125 Object_End : Integer;
126 -- Various column starts and ends
128 Spaces : constant String (1 .. Max_Column) := (others => ' ');
130 RTS_Specified : String_Access := null;
131 -- Used to detect multiple use of --RTS= switch
133 -----------------------
134 -- Local Subprograms --
135 -----------------------
137 procedure Add_Lib_Dir (Dir : String);
138 -- Add an object directory in the list First_Lib_Dir-Last_Lib_Dir
140 procedure Add_Source_Dir (Dir : String);
141 -- Add a source directory in the list First_Source_Dir-Last_Source_Dir
143 procedure Find_General_Layout;
144 -- Determine the structure of the output (multi columns or not, etc)
146 procedure Find_Status
147 (FS : in out File_Name_Type;
148 Stamp : Time_Stamp_Type;
150 Status : out File_Status);
151 -- Determine the file status (Status) of the file represented by FS
152 -- with the expected Stamp and checksum given as argument. FS will be
153 -- updated to the full file name if available.
155 function Corresponding_Sdep_Entry (A : ALI_Id; U : Unit_Id) return Sdep_Id;
156 -- Give the Sdep entry corresponding to the unit U in ali record A
158 procedure Output_Object (O : File_Name_Type);
159 -- Print out the name of the object when requested
161 procedure Output_Source (Sdep_I : Sdep_Id);
162 -- Print out the name and status of the source corresponding to this
165 procedure Output_Status (FS : File_Status; Verbose : Boolean);
166 -- Print out FS either in a coded form if verbose is false or in an
167 -- expanded form otherwise.
169 procedure Output_Unit (ALI : ALI_Id; U_Id : Unit_Id);
170 -- Print out information on the unit when requested
172 procedure Reset_Print;
173 -- Reset Print flags properly when selective output is chosen
175 procedure Scan_Ls_Arg (Argv : String);
176 -- Scan and process lser specific arguments. Argv is a single argument
179 -- Print usage message
181 procedure Output_License_Information;
182 -- Output license statement, and if not found, output reference to
185 function Image (Restriction : Restriction_Id) return String;
186 -- Returns the capitalized image of Restriction
188 ------------------------------------------
189 -- GNATDIST specific output subprograms --
190 ------------------------------------------
194 -- Any modification to this subunit requires synchronization with the
197 procedure Output_ALI (A : ALI_Id);
198 -- Comment required saying what this routine does ???
200 procedure Output_No_ALI (Afile : File_Name_Type);
201 -- Comments required saying what this routine does ???
209 procedure Add_Lib_Dir (Dir : String) is
211 if First_Lib_Dir = null then
214 (Value => new String'(Dir),
216 Last_Lib_Dir := First_Lib_Dir;
221 (Value => new String'(Dir),
223 Last_Lib_Dir := Last_Lib_Dir.Next;
231 procedure Add_Source_Dir (Dir : String) is
233 if First_Source_Dir = null then
236 (Value => new String'(Dir),
238 Last_Source_Dir := First_Source_Dir;
241 Last_Source_Dir.Next :=
243 (Value => new String'(Dir),
245 Last_Source_Dir := Last_Source_Dir.Next;
249 ------------------------------
250 -- Corresponding_Sdep_Entry --
251 ------------------------------
253 function Corresponding_Sdep_Entry
255 U : Unit_Id) return Sdep_Id
258 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
259 if Sdep.Table (D).Sfile = Units.Table (U).Sfile then
264 Error_Msg_Unit_1 := Units.Table (U).Uname;
265 Error_Msg_File_1 := ALIs.Table (A).Afile;
267 Error_Msg ("wrong ALI format, can't find dependency line for $ in {");
268 Exit_Program (E_Fatal);
270 end Corresponding_Sdep_Entry;
272 -------------------------
273 -- Find_General_Layout --
274 -------------------------
276 procedure Find_General_Layout is
277 Max_Unit_Length : Integer := 11;
278 Max_Src_Length : Integer := 11;
279 Max_Obj_Length : Integer := 11;
285 -- Compute maximum of each column
287 for Id in ALIs.First .. ALIs.Last loop
288 Get_Name_String (Units.Table (ALIs.Table (Id).First_Unit).Uname);
289 if Also_Predef or else not Is_Internal_Unit then
293 Max_Unit_Length := Integer'Max (Max_Unit_Length, Len);
297 FS := Full_Source_Name (ALIs.Table (Id).Sfile);
300 Get_Name_String (ALIs.Table (Id).Sfile);
301 Name_Len := Name_Len + 13;
303 Get_Name_String (FS);
306 Max_Src_Length := Integer'Max (Max_Src_Length, Name_Len + 1);
310 if ALIs.Table (Id).No_Object then
312 Integer'Max (Max_Obj_Length, No_Obj'Length);
314 Get_Name_String (ALIs.Table (Id).Ofile_Full_Name);
315 Max_Obj_Length := Integer'Max (Max_Obj_Length, Name_Len + 1);
321 -- Verify is output is not wider than maximum number of columns
326 (Max_Unit_Length + Max_Src_Length + Max_Obj_Length) > Max_Column;
328 -- Set start and end of columns
331 Object_End := Object_Start - 1;
334 Object_End := Object_Start + Max_Obj_Length;
337 Unit_Start := Object_End + 1;
338 Unit_End := Unit_Start - 1;
341 Unit_End := Unit_Start + Max_Unit_Length;
344 Source_Start := Unit_End + 1;
346 if Source_Start > Spaces'Last then
347 Source_Start := Spaces'Last;
350 Source_End := Source_Start - 1;
353 Source_End := Source_Start + Max_Src_Length;
355 end Find_General_Layout;
361 procedure Find_Status
362 (FS : in out File_Name_Type;
363 Stamp : Time_Stamp_Type;
365 Status : out File_Status)
367 Tmp1 : File_Name_Type;
368 Tmp2 : File_Name_Type;
371 Tmp1 := Full_Source_Name (FS);
373 if Tmp1 = No_File then
376 elsif File_Stamp (Tmp1) = Stamp then
380 elsif Checksums_Match (Get_File_Checksum (FS), Checksum) then
382 Status := Checksum_OK;
385 Tmp2 := Matching_Full_Source_Name (FS, Stamp);
387 if Tmp2 = No_File then
392 Status := Not_First_On_PATH;
402 package body GNATDIST is
405 N_Indents : Natural := 0;
436 Image : constant array (Token_Type) of String_Access :=
437 (T_No_ALI => new String'("No_ALI"),
438 T_ALI => new String'("ALI"),
439 T_Unit => new String'("Unit"),
440 T_With => new String'("With"),
441 T_Source => new String'("Source"),
442 T_Afile => new String'("Afile"),
443 T_Ofile => new String'("Ofile"),
444 T_Sfile => new String'("Sfile"),
445 T_Name => new String'("Name"),
446 T_Main => new String'("Main"),
447 T_Kind => new String'("Kind"),
448 T_Flags => new String'("Flags"),
449 T_Preelaborated => new String'("Preelaborated"),
450 T_Pure => new String'("Pure"),
451 T_Has_RACW => new String'("Has_RACW"),
452 T_Remote_Types => new String'("Remote_Types"),
453 T_Shared_Passive => new String'("Shared_Passive"),
454 T_RCI => new String'("RCI"),
455 T_Predefined => new String'("Predefined"),
456 T_Internal => new String'("Internal"),
457 T_Is_Generic => new String'("Is_Generic"),
458 T_Procedure => new String'("procedure"),
459 T_Function => new String'("function"),
460 T_Package => new String'("package"),
461 T_Subprogram => new String'("subprogram"),
462 T_Spec => new String'("spec"),
463 T_Body => new String'("body"));
465 procedure Output_Name (N : Name_Id);
466 -- Remove any encoding info (%b and %s) and output N
468 procedure Output_Afile (A : File_Name_Type);
469 procedure Output_Ofile (O : File_Name_Type);
470 procedure Output_Sfile (S : File_Name_Type);
471 -- Output various names. Check that the name is different from no name.
472 -- Otherwise, skip the output.
474 procedure Output_Token (T : Token_Type);
475 -- Output token using specific format. That is several indentations and:
477 -- T_No_ALI .. T_With : <token> & " =>" & NL
478 -- T_Source .. T_Kind : <token> & " => "
479 -- T_Flags : <token> & " =>"
480 -- T_Preelab .. T_Body : " " & <token>
482 procedure Output_Sdep (S : Sdep_Id);
483 procedure Output_Unit (U : Unit_Id);
484 procedure Output_With (W : With_Id);
485 -- Output this entry as a global section (like ALIs)
491 procedure Output_Afile (A : File_Name_Type) is
494 Output_Token (T_Afile);
504 procedure Output_ALI (A : ALI_Id) is
506 Output_Token (T_ALI);
507 N_Indents := N_Indents + 1;
509 Output_Afile (ALIs.Table (A).Afile);
510 Output_Ofile (ALIs.Table (A).Ofile_Full_Name);
511 Output_Sfile (ALIs.Table (A).Sfile);
515 if ALIs.Table (A).Main_Program /= None then
516 Output_Token (T_Main);
518 if ALIs.Table (A).Main_Program = Proc then
519 Output_Token (T_Procedure);
521 Output_Token (T_Function);
529 for U in ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit loop
535 for S in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
539 N_Indents := N_Indents - 1;
546 procedure Output_No_ALI (Afile : File_Name_Type) is
548 Output_Token (T_No_ALI);
549 N_Indents := N_Indents + 1;
550 Output_Afile (Afile);
551 N_Indents := N_Indents - 1;
558 procedure Output_Name (N : Name_Id) is
560 -- Remove any encoding info (%s or %b)
565 and then Name_Buffer (Name_Len - 1) = '%'
567 Name_Len := Name_Len - 2;
570 Output_Token (T_Name);
571 Write_Str (Name_Buffer (1 .. Name_Len));
579 procedure Output_Ofile (O : File_Name_Type) is
582 Output_Token (T_Ofile);
592 procedure Output_Sdep (S : Sdep_Id) is
594 Output_Token (T_Source);
595 Write_Name (Sdep.Table (S).Sfile);
603 procedure Output_Sfile (S : File_Name_Type) is
604 FS : File_Name_Type := S;
607 if FS /= No_File then
609 -- We want to output the full source name
611 FS := Full_Source_Name (FS);
613 -- There is no full source name. This occurs for instance when a
614 -- withed unit has a spec file but no body file. This situation is
615 -- not a problem for GNATDIST since the unit may be located on a
616 -- partition we do not want to build. However, we need to locate
617 -- the spec file and to find its full source name. Replace the
618 -- body file name with the spec file name used to compile the
619 -- current unit when possible.
625 and then Name_Buffer (Name_Len - 3 .. Name_Len) = ".adb"
627 Name_Buffer (Name_Len) := 's';
628 FS := Full_Source_Name (Name_Find);
633 if FS /= No_File then
634 Output_Token (T_Sfile);
644 procedure Output_Token (T : Token_Type) is
646 if T in T_No_ALI .. T_Flags then
647 for J in 1 .. N_Indents loop
651 Write_Str (Image (T).all);
653 for J in Image (T)'Length .. 12 loop
659 if T in T_No_ALI .. T_With then
661 elsif T in T_Source .. T_Name then
665 elsif T in T_Preelaborated .. T_Body then
666 if T in T_Preelaborated .. T_Is_Generic then
668 Output_Token (T_Flags);
671 N_Flags := N_Flags + 1;
675 Write_Str (Image (T).all);
678 Write_Str (Image (T).all);
686 procedure Output_Unit (U : Unit_Id) is
688 Output_Token (T_Unit);
689 N_Indents := N_Indents + 1;
693 Output_Name (Name_Id (Units.Table (U).Uname));
697 Output_Token (T_Kind);
699 if Units.Table (U).Unit_Kind = 'p' then
700 Output_Token (T_Package);
702 Output_Token (T_Subprogram);
705 if Name_Buffer (Name_Len) = 's' then
706 Output_Token (T_Spec);
708 Output_Token (T_Body);
713 -- Output source file name
715 Output_Sfile (Units.Table (U).Sfile);
721 if Units.Table (U).Preelab then
722 Output_Token (T_Preelaborated);
725 if Units.Table (U).Pure then
726 Output_Token (T_Pure);
729 if Units.Table (U).Has_RACW then
730 Output_Token (T_Has_RACW);
733 if Units.Table (U).Remote_Types then
734 Output_Token (T_Remote_Types);
737 if Units.Table (U).Shared_Passive then
738 Output_Token (T_Shared_Passive);
741 if Units.Table (U).RCI then
742 Output_Token (T_RCI);
745 if Units.Table (U).Predefined then
746 Output_Token (T_Predefined);
749 if Units.Table (U).Internal then
750 Output_Token (T_Internal);
753 if Units.Table (U).Is_Generic then
754 Output_Token (T_Is_Generic);
763 for W in Units.Table (U).First_With .. Units.Table (U).Last_With loop
767 N_Indents := N_Indents - 1;
774 procedure Output_With (W : With_Id) is
776 Output_Token (T_With);
777 N_Indents := N_Indents + 1;
779 Output_Name (Name_Id (Withs.Table (W).Uname));
783 Output_Token (T_Kind);
785 if Name_Buffer (Name_Len) = 's' then
786 Output_Token (T_Spec);
788 Output_Token (T_Body);
793 Output_Afile (Withs.Table (W).Afile);
794 Output_Sfile (Withs.Table (W).Sfile);
796 N_Indents := N_Indents - 1;
805 function Image (Restriction : Restriction_Id) return String is
806 Result : String := Restriction'Img;
807 Skip : Boolean := True;
810 for J in Result'Range loop
813 Result (J) := To_Upper (Result (J));
815 elsif Result (J) = '_' then
819 Result (J) := To_Lower (Result (J));
826 --------------------------------
827 -- Output_License_Information --
828 --------------------------------
830 procedure Output_License_Information is
831 Params_File_Name : constant String := "gnatlic.adl";
832 -- Name of license file
834 Lo : constant Source_Ptr := 1;
836 Text : Source_Buffer_Ptr;
840 Add_Str_To_Name_Buffer (Params_File_Name);
841 Read_Source_File (Name_Find, Lo, Hi, Text);
845 -- Omit last character (end-of-file marker) in output
847 Write_Str (String (Text (Lo .. Hi - 1)));
850 -- The following condition is determined at compile time: disable
851 -- "condition is always true/false" warning.
853 pragma Warnings (Off);
854 elsif Build_Type /= GPL and then Build_Type /= FSF then
855 pragma Warnings (On);
857 Write_Str ("License file missing, please contact AdaCore.");
861 Write_Str ("Please refer to file COPYING in your distribution"
862 & " for license terms.");
867 Exit_Program (E_Success);
868 end Output_License_Information;
874 procedure Output_Object (O : File_Name_Type) is
875 Object_Name : String_Access;
881 Object_Name := To_Host_File_Spec (Name_Buffer (1 .. Name_Len));
883 Object_Name := No_Obj'Unchecked_Access;
886 Write_Str (Object_Name.all);
888 if Print_Source or else Print_Unit then
894 (Object_Start + Object_Name'Length .. Object_End));
904 procedure Output_Source (Sdep_I : Sdep_Id) is
905 Stamp : Time_Stamp_Type;
908 Status : File_Status;
909 Object_Name : String_Access;
912 if Sdep_I = No_Sdep_Id then
916 Stamp := Sdep.Table (Sdep_I).Stamp;
917 Checksum := Sdep.Table (Sdep_I).Checksum;
918 FS := Sdep.Table (Sdep_I).Sfile;
921 Find_Status (FS, Stamp, Checksum, Status);
922 Get_Name_String (FS);
924 Object_Name := To_Host_File_Spec (Name_Buffer (1 .. Name_Len));
927 Write_Str (" Source => ");
928 Write_Str (Object_Name.all);
932 (Spaces (Source_Start + Object_Name'Length .. Source_End));
935 Output_Status (Status, Verbose => True);
940 if not Selective_Output then
941 Output_Status (Status, Verbose => False);
944 Write_Str (Object_Name.all);
953 procedure Output_Status (FS : File_Status; Verbose : Boolean) is
958 Write_Str (" unchanged");
961 Write_Str (" slightly modified");
964 Write_Str (" file not found");
967 Write_Str (" modified");
969 when Not_First_On_PATH =>
970 Write_Str (" unchanged version not first on PATH");
987 when Not_First_On_PATH =>
997 procedure Output_Unit (ALI : ALI_Id; U_Id : Unit_Id) is
999 U : Unit_Record renames Units.Table (U_Id);
1003 Get_Name_String (U.Uname);
1004 Kind := Name_Buffer (Name_Len);
1005 Name_Len := Name_Len - 2;
1007 if not Verbose_Mode then
1008 Write_Str (Name_Buffer (1 .. Name_Len));
1011 Write_Str ("Unit => ");
1013 Write_Str (" Name => ");
1014 Write_Str (Name_Buffer (1 .. Name_Len));
1016 Write_Str (" Kind => ");
1018 if Units.Table (U_Id).Unit_Kind = 'p' then
1019 Write_Str ("package ");
1021 Write_Str ("subprogram ");
1031 if Verbose_Mode then
1045 U.Body_Needed_For_SAL or
1049 Write_Str (" Flags =>");
1052 Write_Str (" Preelaborable");
1056 Write_Str (" No_Elab_Code");
1060 Write_Str (" Pure");
1063 if U.Dynamic_Elab then
1064 Write_Str (" Dynamic_Elab");
1068 Write_Str (" Has_RACW");
1071 if U.Remote_Types then
1072 Write_Str (" Remote_Types");
1075 if U.Shared_Passive then
1076 Write_Str (" Shared_Passive");
1083 if U.Predefined then
1084 Write_Str (" Predefined");
1088 Write_Str (" Internal");
1091 if U.Is_Generic then
1092 Write_Str (" Is_Generic");
1095 if U.Init_Scalars then
1096 Write_Str (" Init_Scalars");
1099 if U.SAL_Interface then
1100 Write_Str (" SAL_Interface");
1103 if U.Body_Needed_For_SAL then
1104 Write_Str (" Body_Needed_For_SAL");
1107 if U.Elaborate_Body then
1108 Write_Str (" Elaborate Body");
1111 if U.Remote_Types then
1112 Write_Str (" Remote_Types");
1115 if U.Shared_Passive then
1116 Write_Str (" Shared_Passive");
1119 if U.Predefined then
1120 Write_Str (" Predefined");
1126 Restrictions : constant Restrictions_Info :=
1127 ALIs.Table (ALI).Restrictions;
1130 -- If the source was compiled with pragmas Restrictions,
1131 -- Display these restrictions.
1133 if Restrictions.Set /= (All_Restrictions => False) then
1135 Write_Str (" pragma Restrictions =>");
1137 -- For boolean restrictions, just display the name of the
1138 -- restriction; for valued restrictions, also display the
1139 -- restriction value.
1141 for Restriction in All_Restrictions loop
1142 if Restrictions.Set (Restriction) then
1145 Write_Str (Image (Restriction));
1147 if Restriction in All_Parameter_Restrictions then
1149 Write_Str (Restrictions.Value (Restriction)'Img);
1155 -- If the unit violates some Restrictions, display the list of
1156 -- these restrictions.
1158 if Restrictions.Violated /= (All_Restrictions => False) then
1160 Write_Str (" Restrictions violated =>");
1162 -- For boolean restrictions, just display the name of the
1163 -- restriction; for valued restrictions, also display the
1164 -- restriction value.
1166 for Restriction in All_Restrictions loop
1167 if Restrictions.Violated (Restriction) then
1170 Write_Str (Image (Restriction));
1172 if Restriction in All_Parameter_Restrictions then
1173 if Restrictions.Count (Restriction) > 0 then
1176 if Restrictions.Unknown (Restriction) then
1177 Write_Str (" at least");
1180 Write_Str (Restrictions.Count (Restriction)'Img);
1189 if Print_Source then
1194 Write_Str (Spaces (Unit_Start + Name_Len + 1 .. Unit_End));
1204 procedure Reset_Print is
1206 if not Selective_Output then
1207 Selective_Output := True;
1208 Print_Source := False;
1209 Print_Object := False;
1210 Print_Unit := False;
1218 procedure Scan_Ls_Arg (Argv : String) is
1219 FD : File_Descriptor;
1223 pragma Assert (Argv'First = 1);
1225 if Argv'Length = 0 then
1229 if Argv (1) = '-' then
1230 if Argv'Length = 1 then
1231 Fail ("switch character cannot be followed by a blank");
1233 -- Processing for -I-
1235 elsif Argv (2 .. Argv'Last) = "I-" then
1236 Opt.Look_In_Primary_Dir := False;
1238 -- Forbid -?- or -??- where ? is any character
1240 elsif (Argv'Length = 3 and then Argv (3) = '-')
1241 or else (Argv'Length = 4 and then Argv (4) = '-')
1243 Fail ("Trailing ""-"" at the end of " & Argv & " forbidden.");
1245 -- Processing for -Idir
1247 elsif Argv (2) = 'I' then
1248 Add_Source_Dir (Argv (3 .. Argv'Last));
1249 Add_Lib_Dir (Argv (3 .. Argv'Last));
1251 -- Processing for -aIdir (to gcc this is like a -I switch)
1253 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
1254 Add_Source_Dir (Argv (4 .. Argv'Last));
1256 -- Processing for -aOdir
1258 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
1259 Add_Lib_Dir (Argv (4 .. Argv'Last));
1261 -- Processing for -aLdir (to gnatbind this is like a -aO switch)
1263 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
1264 Add_Lib_Dir (Argv (4 .. Argv'Last));
1266 -- Processing for -nostdinc
1268 elsif Argv (2 .. Argv'Last) = "nostdinc" then
1269 Opt.No_Stdinc := True;
1271 -- Processing for one character switches
1273 elsif Argv'Length = 2 then
1275 when 'a' => Also_Predef := True;
1276 when 'h' => Print_Usage := True;
1277 when 'u' => Reset_Print; Print_Unit := True;
1278 when 's' => Reset_Print; Print_Source := True;
1279 when 'o' => Reset_Print; Print_Object := True;
1280 when 'v' => Verbose_Mode := True;
1281 when 'd' => Dependable := True;
1282 when 'l' => License := True;
1283 when 'V' => Very_Verbose_Mode := True;
1285 when others => null;
1288 -- Processing for -files=file
1290 elsif Argv'Length > 7 and then Argv (1 .. 7) = "-files=" then
1291 FD := Open_Read (Argv (8 .. Argv'Last), GNAT.OS_Lib.Text);
1293 if FD = Invalid_FD then
1294 Osint.Fail ("could not find text file """ &
1295 Argv (8 .. Argv'Last) & '"');
1298 Len := Integer (File_Length (FD));
1301 Buffer : String (1 .. Len + 1);
1302 Index : Positive := 1;
1308 Len := Read (FD, Buffer (1)'Address, Len);
1309 Buffer (Buffer'Last) := ASCII.NUL;
1312 -- Scan the file line by line
1314 while Index < Buffer'Last loop
1316 -- Find the end of line
1320 while Last <= Buffer'Last
1321 and then Buffer (Last) /= ASCII.LF
1322 and then Buffer (Last) /= ASCII.CR
1327 -- Ignore empty lines
1329 if Last > Index then
1330 Add_File (Buffer (Index .. Last - 1));
1335 -- Find the beginning of the next line
1337 while Buffer (Index) = ASCII.CR or else
1338 Buffer (Index) = ASCII.LF
1345 -- Processing for --RTS=path
1347 elsif Argv'Length >= 5 and then Argv (1 .. 5) = "--RTS" then
1348 if Argv'Length <= 6 or else Argv (6) /= '='then
1349 Osint.Fail ("missing path for --RTS");
1352 -- Check that it is the first time we see this switch or, if
1353 -- it is not the first time, the same path is specified.
1355 if RTS_Specified = null then
1356 RTS_Specified := new String'(Argv (7 .. Argv'Last));
1358 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
1359 Osint.Fail ("--RTS cannot be specified multiple times");
1362 -- Valid --RTS switch
1364 Opt.No_Stdinc := True;
1365 Opt.RTS_Switch := True;
1368 Src_Path_Name : constant String_Ptr :=
1371 (Argv (7 .. Argv'Last), Include));
1372 Lib_Path_Name : constant String_Ptr :=
1375 (Argv (7 .. Argv'Last), Objects));
1378 if Src_Path_Name /= null
1379 and then Lib_Path_Name /= null
1381 Add_Search_Dirs (Src_Path_Name, Include);
1382 Add_Search_Dirs (Lib_Path_Name, Objects);
1384 elsif Src_Path_Name = null
1385 and then Lib_Path_Name = null
1387 Osint.Fail ("RTS path not valid: missing " &
1388 "adainclude and adalib directories");
1390 elsif Src_Path_Name = null then
1391 Osint.Fail ("RTS path not valid: missing " &
1392 "adainclude directory");
1394 elsif Lib_Path_Name = null then
1395 Osint.Fail ("RTS path not valid: missing " &
1396 "adalib directory");
1402 -- If not a switch, it must be a file name
1417 Write_Str ("Usage: ");
1418 Osint.Write_Program_Name;
1419 Write_Str (" switches [list of object files]");
1425 Write_Str ("switches:");
1430 Write_Str (" -a also output relevant predefined units");
1435 Write_Str (" -u output only relevant unit names");
1440 Write_Str (" -h output this help message");
1445 Write_Str (" -s output only relevant source names");
1450 Write_Str (" -o output only relevant object names");
1455 Write_Str (" -d output sources on which specified units " &
1461 Write_Str (" -l output license information");
1466 Write_Str (" -v verbose output, full path and unit " &
1473 Write_Str (" -files=fil files are listed in text file 'fil'");
1476 -- Line for -aI switch
1478 Write_Str (" -aIdir specify source files search path");
1481 -- Line for -aO switch
1483 Write_Str (" -aOdir specify object files search path");
1486 -- Line for -I switch
1488 Write_Str (" -Idir like -aIdir -aOdir");
1491 -- Line for -I- switch
1493 Write_Str (" -I- do not look for sources & object files");
1494 Write_Str (" in the default directory");
1497 -- Line for -nostdinc
1499 Write_Str (" -nostdinc do not look for source files");
1500 Write_Str (" in the system default directory");
1505 Write_Str (" --RTS=dir specify the default source and object search"
1509 -- File Status explanation
1512 Write_Str (" file status can be:");
1515 for ST in File_Status loop
1517 Output_Status (ST, Verbose => False);
1518 Write_Str (" ==> ");
1519 Output_Status (ST, Verbose => True);
1524 procedure Check_Version_And_Help is new Check_Version_And_Help_G (Usage);
1526 -- Start of processing for Gnatls
1529 -- Initialize standard packages
1535 -- First check for --version or --help
1537 Check_Version_And_Help ("GNATLS", "1997");
1539 -- Loop to scan out arguments
1542 Scan_Args : while Next_Arg < Arg_Count loop
1544 Next_Argv : String (1 .. Len_Arg (Next_Arg));
1546 Fill_Arg (Next_Argv'Address, Next_Arg);
1547 Scan_Ls_Arg (Next_Argv);
1550 Next_Arg := Next_Arg + 1;
1553 -- If -l (output license information) is given, it must be the only switch
1555 if License and then Arg_Count /= 2 then
1556 Write_Str ("Can't use -l with another switch");
1559 Exit_Program (E_Fatal);
1562 -- Add the source and object directories specified on the
1563 -- command line, if any, to the searched directories.
1565 while First_Source_Dir /= null loop
1566 Add_Src_Search_Dir (First_Source_Dir.Value.all);
1567 First_Source_Dir := First_Source_Dir.Next;
1570 while First_Lib_Dir /= null loop
1571 Add_Lib_Search_Dir (First_Lib_Dir.Value.all);
1572 First_Lib_Dir := First_Lib_Dir.Next;
1575 -- Finally, add the default directories and obtain target parameters
1577 Osint.Add_Default_Search_Dirs;
1579 if Verbose_Mode then
1580 Targparm.Get_Target_Parameters;
1583 Display_Version ("GNATLS", "1997");
1585 Write_Str ("Source Search Path:");
1588 for J in 1 .. Nb_Dir_In_Src_Search_Path loop
1591 if Dir_In_Src_Search_Path (J)'Length = 0 then
1592 Write_Str ("<Current_Directory>");
1594 Write_Str (To_Host_Dir_Spec
1595 (Dir_In_Src_Search_Path (J).all, True).all);
1603 Write_Str ("Object Search Path:");
1606 for J in 1 .. Nb_Dir_In_Obj_Search_Path loop
1609 if Dir_In_Obj_Search_Path (J)'Length = 0 then
1610 Write_Str ("<Current_Directory>");
1612 Write_Str (To_Host_Dir_Spec
1613 (Dir_In_Obj_Search_Path (J).all, True).all);
1621 Write_Str (Project_Search_Path);
1623 Write_Str (" <Current_Directory>");
1627 Project_Path : String_Access := Getenv (Gpr_Project_Path);
1629 Lib : constant String :=
1630 Directory_Separator & "lib" & Directory_Separator;
1635 Add_Default_Dir : Boolean := True;
1638 -- If there is a project path, display each directory in the path
1640 if Project_Path.all = "" then
1641 Project_Path := Getenv (Ada_Project_Path);
1644 if Project_Path.all /= "" then
1645 First := Project_Path'First;
1647 while First <= Project_Path'Last
1648 and then (Project_Path (First) = Path_Separator)
1653 exit when First > Project_Path'Last;
1656 while Last < Project_Path'Last
1657 and then Project_Path (Last + 1) /= Path_Separator
1662 -- If the directory is No_Default_Project_Dir, set
1663 -- Add_Default_Dir to False.
1665 if Project_Path (First .. Last) = No_Project_Default_Dir then
1666 Add_Default_Dir := False;
1668 elsif First /= Last or else Project_Path (First) /= '.' then
1670 -- If the directory is ".", skip it as it is the current
1671 -- directory and it is already the first directory in the
1677 (Project_Path (First .. Last), True).all);
1685 -- Add the default dir, except if "-" was one of the "directories"
1686 -- specified in ADA_PROJECT_DIR.
1688 if Add_Default_Dir then
1690 Add_Str_To_Name_Buffer (Sdefault.Search_Dir_Prefix.all);
1692 -- On Windows, make sure that all directory separators are '\'
1694 if Directory_Separator /= '/' then
1695 for J in 1 .. Name_Len loop
1696 if Name_Buffer (J) = '/' then
1697 Name_Buffer (J) := Directory_Separator;
1702 -- Find the sequence "/lib/"
1704 while Name_Len >= Lib'Length
1705 and then Name_Buffer (Name_Len - 4 .. Name_Len) /= Lib
1707 Name_Len := Name_Len - 1;
1710 -- If the sequence "/lib"/ was found, display the default
1711 -- directory <prefix>/lib/gnat/.
1713 if Name_Len >= 5 then
1714 Name_Buffer (Name_Len + 1 .. Name_Len + 4) := "gnat";
1715 Name_Buffer (Name_Len + 5) := Directory_Separator;
1716 Name_Len := Name_Len + 5;
1719 (To_Host_Dir_Spec (Name_Buffer (1 .. Name_Len), True).all);
1727 -- Output usage information when requested
1733 -- Output license information when requested
1736 Output_License_Information;
1737 Exit_Program (E_Success);
1740 if not More_Lib_Files then
1741 if not Print_Usage and then not Verbose_Mode then
1745 Exit_Program (E_Fatal);
1749 Initialize_ALI_Source;
1751 -- Print out all library for which no ALI files can be located
1753 while More_Lib_Files loop
1754 Main_File := Next_Main_Lib_File;
1755 Ali_File := Full_Lib_File_Name (Lib_File_Name (Main_File));
1757 if Ali_File = No_File then
1758 if Very_Verbose_Mode then
1759 GNATDIST.Output_No_ALI (Lib_File_Name (Main_File));
1762 Write_Str ("Can't find library info for ");
1763 Get_Name_String (Main_File);
1764 Write_Char ('"'); -- "
1765 Write_Str (Name_Buffer (1 .. Name_Len));
1766 Write_Char ('"'); -- "
1771 Ali_File := Strip_Directory (Ali_File);
1773 if Get_Name_Table_Info (Ali_File) = 0 then
1774 Text := Read_Library_Info (Ali_File, True);
1778 pragma Unreferenced (Discard);
1786 Ignore_Errors => True);
1794 if Very_Verbose_Mode then
1795 for A in ALIs.First .. ALIs.Last loop
1796 GNATDIST.Output_ALI (A);
1802 Find_General_Layout;
1804 for Id in ALIs.First .. ALIs.Last loop
1809 Get_Name_String (Units.Table (ALIs.Table (Id).First_Unit).Uname);
1811 if Also_Predef or else not Is_Internal_Unit then
1812 if ALIs.Table (Id).No_Object then
1813 Output_Object (No_File);
1815 Output_Object (ALIs.Table (Id).Ofile_Full_Name);
1818 -- In verbose mode print all main units in the ALI file, otherwise
1819 -- just print the first one to ease columnwise printout
1821 if Verbose_Mode then
1822 Last_U := ALIs.Table (Id).Last_Unit;
1824 Last_U := ALIs.Table (Id).First_Unit;
1827 for U in ALIs.Table (Id).First_Unit .. Last_U loop
1828 if U /= ALIs.Table (Id).First_Unit
1829 and then Selective_Output
1835 Output_Unit (Id, U);
1837 -- Output source now, unless if it will be done as part of
1838 -- outputing dependencies.
1840 if not (Dependable and then Print_Source) then
1841 Output_Source (Corresponding_Sdep_Entry (Id, U));
1845 -- Print out list of units on which this unit depends (D lines)
1847 if Dependable and then Print_Source then
1848 if Verbose_Mode then
1849 Write_Str ("depends upon");
1857 ALIs.Table (Id).First_Sdep .. ALIs.Table (Id).Last_Sdep
1860 or else not Is_Internal_File_Name (Sdep.Table (D).Sfile)
1862 if Verbose_Mode then
1872 Write_Str (Spaces (1 .. Source_Start - 2));
1885 -- All done. Set proper exit status
1888 Exit_Program (E_Success);