PR preprocessor/63831
[official-gcc.git] / gcc / ada / gnatls.adb
blob80875b52ffe5c84a4134e382807a22a823852955
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- G N A T L S --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
10 -- --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with ALI; use ALI;
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;
35 with Opt; use Opt;
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;
41 with Sdefault;
42 with Snames;
43 with Stringt;
44 with Switch; use Switch;
45 with Types; use Types;
47 with Ada.Command_Line; use Ada.Command_Line;
49 with GNAT.Command_Line; use GNAT.Command_Line;
50 with GNAT.Case_Util; use GNAT.Case_Util;
52 procedure Gnatls is
53 pragma Ident (Gnat_Static_Version_String);
55 -- NOTE : The following string may be used by other tools, such as GPS. So
56 -- it can only be modified if these other uses are checked and coordinated.
58 Project_Search_Path : constant String := "Project Search Path:";
59 -- Label displayed in verbose mode before the directories in the project
60 -- search path. Do not modify without checking NOTE above.
62 Prj_Path : Prj.Env.Project_Search_Path;
64 Max_Column : constant := 80;
66 No_Obj : aliased String := "<no_obj>";
68 No_Runtime : Boolean := False;
69 -- Set to True if there is no default runtime and --RTS= is not specified
71 type File_Status is (
72 OK, -- matching timestamp
73 Checksum_OK, -- only matching checksum
74 Not_Found, -- file not found on source PATH
75 Not_Same, -- neither checksum nor timestamp matching
76 Not_First_On_PATH); -- matching file hidden by Not_Same file on path
78 type Dir_Data;
79 type Dir_Ref is access Dir_Data;
81 type Dir_Data is record
82 Value : String_Access;
83 Next : Dir_Ref;
84 end record;
85 -- Simply linked list of dirs
87 First_Source_Dir : Dir_Ref;
88 Last_Source_Dir : Dir_Ref;
89 -- The list of source directories from the command line.
90 -- These directories are added using Osint.Add_Src_Search_Dir
91 -- after those of the GNAT Project File, if any.
93 First_Lib_Dir : Dir_Ref;
94 Last_Lib_Dir : Dir_Ref;
95 -- The list of object directories from the command line.
96 -- These directories are added using Osint.Add_Lib_Search_Dir
97 -- after those of the GNAT Project File, if any.
99 Main_File : File_Name_Type;
100 Ali_File : File_Name_Type;
101 Text : Text_Buffer_Ptr;
102 Next_Arg : Positive;
104 Too_Long : Boolean := False;
105 -- When True, lines are too long for multi-column output and each
106 -- item of information is on a different line.
108 Selective_Output : Boolean := False;
109 Print_Usage : Boolean := False;
110 Print_Unit : Boolean := True;
111 Print_Source : Boolean := True;
112 Print_Object : Boolean := True;
113 -- Flags controlling the form of the output
115 Also_Predef : Boolean := False; -- -a
116 Dependable : Boolean := False; -- -d
117 License : Boolean := False; -- -l
118 Very_Verbose_Mode : Boolean := False; -- -V
119 -- Command line flags
121 Unit_Start : Integer;
122 Unit_End : Integer;
123 Source_Start : Integer;
124 Source_End : Integer;
125 Object_Start : Integer;
126 Object_End : Integer;
127 -- Various column starts and ends
129 Spaces : constant String (1 .. Max_Column) := (others => ' ');
131 RTS_Specified : String_Access := null;
132 -- Used to detect multiple use of --RTS= switch
134 Exit_Status : Exit_Code_Type := E_Success;
135 -- Reset to E_Fatal if bad error found
137 -----------------------
138 -- Local Subprograms --
139 -----------------------
141 procedure Add_Lib_Dir (Dir : String);
142 -- Add an object directory in the list First_Lib_Dir-Last_Lib_Dir
144 procedure Add_Source_Dir (Dir : String);
145 -- Add a source directory in the list First_Source_Dir-Last_Source_Dir
147 procedure Find_General_Layout;
148 -- Determine the structure of the output (multi columns or not, etc)
150 procedure Find_Status
151 (FS : in out File_Name_Type;
152 Stamp : Time_Stamp_Type;
153 Checksum : Word;
154 Status : out File_Status);
155 -- Determine the file status (Status) of the file represented by FS with
156 -- the expected Stamp and checksum given as argument. FS will be updated
157 -- to the full file name if available.
159 function Corresponding_Sdep_Entry (A : ALI_Id; U : Unit_Id) return Sdep_Id;
160 -- Give the Sdep entry corresponding to the unit U in ali record A
162 procedure Output_Object (O : File_Name_Type);
163 -- Print out the name of the object when requested
165 procedure Output_Source (Sdep_I : Sdep_Id);
166 -- Print out the name and status of the source corresponding to this
167 -- sdep entry.
169 procedure Output_Status (FS : File_Status; Verbose : Boolean);
170 -- Print out FS either in a coded form if verbose is false or in an
171 -- expanded form otherwise.
173 procedure Output_Unit (ALI : ALI_Id; U_Id : Unit_Id);
174 -- Print out information on the unit when requested
176 procedure Reset_Print;
177 -- Reset Print flags properly when selective output is chosen
179 procedure Scan_Ls_Arg (Argv : String);
180 -- Scan and process user specific arguments (Argv is a single argument)
182 procedure Search_RTS (Name : String);
183 -- Find include and objects path for the RTS name.
185 procedure Usage;
186 -- Print usage message
188 procedure Output_License_Information;
189 -- Output license statement, and if not found, output reference to COPYING
191 function Image (Restriction : Restriction_Id) return String;
192 -- Returns the capitalized image of Restriction
194 function Normalize (Path : String) return String;
195 -- Returns a normalized path name. On Windows, the directory separators are
196 -- set to '\' in Normalize_Pathname.
198 ------------------------------------------
199 -- GNATDIST specific output subprograms --
200 ------------------------------------------
202 package GNATDIST is
204 -- Any modification to this subunit requires synchronization with the
205 -- GNATDIST sources.
207 procedure Output_ALI (A : ALI_Id);
208 -- Comment required saying what this routine does ???
210 procedure Output_No_ALI (Afile : File_Name_Type);
211 -- Comments required saying what this routine does ???
213 end GNATDIST;
215 -----------------
216 -- Add_Lib_Dir --
217 -----------------
219 procedure Add_Lib_Dir (Dir : String) is
220 begin
221 if First_Lib_Dir = null then
222 First_Lib_Dir :=
223 new Dir_Data'
224 (Value => new String'(Dir),
225 Next => null);
226 Last_Lib_Dir := First_Lib_Dir;
228 else
229 Last_Lib_Dir.Next :=
230 new Dir_Data'
231 (Value => new String'(Dir),
232 Next => null);
233 Last_Lib_Dir := Last_Lib_Dir.Next;
234 end if;
235 end Add_Lib_Dir;
237 --------------------
238 -- Add_Source_Dir --
239 --------------------
241 procedure Add_Source_Dir (Dir : String) is
242 begin
243 if First_Source_Dir = null then
244 First_Source_Dir :=
245 new Dir_Data'
246 (Value => new String'(Dir),
247 Next => null);
248 Last_Source_Dir := First_Source_Dir;
250 else
251 Last_Source_Dir.Next :=
252 new Dir_Data'
253 (Value => new String'(Dir),
254 Next => null);
255 Last_Source_Dir := Last_Source_Dir.Next;
256 end if;
257 end Add_Source_Dir;
259 ------------------------------
260 -- Corresponding_Sdep_Entry --
261 ------------------------------
263 function Corresponding_Sdep_Entry
264 (A : ALI_Id;
265 U : Unit_Id) return Sdep_Id
267 begin
268 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
269 if Sdep.Table (D).Sfile = Units.Table (U).Sfile then
270 return D;
271 end if;
272 end loop;
274 Error_Msg_Unit_1 := Units.Table (U).Uname;
275 Error_Msg_File_1 := ALIs.Table (A).Afile;
276 Write_Eol;
277 Error_Msg ("wrong ALI format, can't find dependency line for $ in {");
278 Exit_Program (E_Fatal);
279 return No_Sdep_Id;
280 end Corresponding_Sdep_Entry;
282 -------------------------
283 -- Find_General_Layout --
284 -------------------------
286 procedure Find_General_Layout is
287 Max_Unit_Length : Integer := 11;
288 Max_Src_Length : Integer := 11;
289 Max_Obj_Length : Integer := 11;
291 Len : Integer;
292 FS : File_Name_Type;
294 begin
295 -- Compute maximum of each column
297 for Id in ALIs.First .. ALIs.Last loop
298 Get_Name_String (Units.Table (ALIs.Table (Id).First_Unit).Uname);
299 if Also_Predef or else not Is_Internal_Unit then
301 if Print_Unit then
302 Len := Name_Len - 1;
303 Max_Unit_Length := Integer'Max (Max_Unit_Length, Len);
304 end if;
306 if Print_Source then
307 FS := Full_Source_Name (ALIs.Table (Id).Sfile);
309 if FS = No_File then
310 Get_Name_String (ALIs.Table (Id).Sfile);
311 Name_Len := Name_Len + 13;
312 else
313 Get_Name_String (FS);
314 end if;
316 Max_Src_Length := Integer'Max (Max_Src_Length, Name_Len + 1);
317 end if;
319 if Print_Object then
320 if ALIs.Table (Id).No_Object then
321 Max_Obj_Length :=
322 Integer'Max (Max_Obj_Length, No_Obj'Length);
323 else
324 Get_Name_String (ALIs.Table (Id).Ofile_Full_Name);
325 Max_Obj_Length := Integer'Max (Max_Obj_Length, Name_Len + 1);
326 end if;
327 end if;
328 end if;
329 end loop;
331 -- Verify is output is not wider than maximum number of columns
333 Too_Long :=
334 Verbose_Mode
335 or else
336 (Max_Unit_Length + Max_Src_Length + Max_Obj_Length) > Max_Column;
338 -- Set start and end of columns
340 Object_Start := 1;
341 Object_End := Object_Start - 1;
343 if Print_Object then
344 Object_End := Object_Start + Max_Obj_Length;
345 end if;
347 Unit_Start := Object_End + 1;
348 Unit_End := Unit_Start - 1;
350 if Print_Unit then
351 Unit_End := Unit_Start + Max_Unit_Length;
352 end if;
354 Source_Start := Unit_End + 1;
356 if Source_Start > Spaces'Last then
357 Source_Start := Spaces'Last;
358 end if;
360 Source_End := Source_Start - 1;
362 if Print_Source then
363 Source_End := Source_Start + Max_Src_Length;
364 end if;
365 end Find_General_Layout;
367 -----------------
368 -- Find_Status --
369 -----------------
371 procedure Find_Status
372 (FS : in out File_Name_Type;
373 Stamp : Time_Stamp_Type;
374 Checksum : Word;
375 Status : out File_Status)
377 Tmp1 : File_Name_Type;
378 Tmp2 : File_Name_Type;
380 begin
381 Tmp1 := Full_Source_Name (FS);
383 if Tmp1 = No_File then
384 Status := Not_Found;
386 elsif File_Stamp (Tmp1) = Stamp then
387 FS := Tmp1;
388 Status := OK;
390 elsif Checksums_Match (Get_File_Checksum (FS), Checksum) then
391 FS := Tmp1;
392 Status := Checksum_OK;
394 else
395 Tmp2 := Matching_Full_Source_Name (FS, Stamp);
397 if Tmp2 = No_File then
398 Status := Not_Same;
399 FS := Tmp1;
401 else
402 Status := Not_First_On_PATH;
403 FS := Tmp2;
404 end if;
405 end if;
406 end Find_Status;
408 --------------
409 -- GNATDIST --
410 --------------
412 package body GNATDIST is
414 N_Flags : Natural;
415 N_Indents : Natural := 0;
417 type Token_Type is
418 (T_No_ALI,
419 T_ALI,
420 T_Unit,
421 T_With,
422 T_Source,
423 T_Afile,
424 T_Ofile,
425 T_Sfile,
426 T_Name,
427 T_Main,
428 T_Kind,
429 T_Flags,
430 T_Preelaborated,
431 T_Pure,
432 T_Has_RACW,
433 T_Remote_Types,
434 T_Shared_Passive,
435 T_RCI,
436 T_Predefined,
437 T_Internal,
438 T_Is_Generic,
439 T_Procedure,
440 T_Function,
441 T_Package,
442 T_Subprogram,
443 T_Spec,
444 T_Body);
446 Image : constant array (Token_Type) of String_Access :=
447 (T_No_ALI => new String'("No_ALI"),
448 T_ALI => new String'("ALI"),
449 T_Unit => new String'("Unit"),
450 T_With => new String'("With"),
451 T_Source => new String'("Source"),
452 T_Afile => new String'("Afile"),
453 T_Ofile => new String'("Ofile"),
454 T_Sfile => new String'("Sfile"),
455 T_Name => new String'("Name"),
456 T_Main => new String'("Main"),
457 T_Kind => new String'("Kind"),
458 T_Flags => new String'("Flags"),
459 T_Preelaborated => new String'("Preelaborated"),
460 T_Pure => new String'("Pure"),
461 T_Has_RACW => new String'("Has_RACW"),
462 T_Remote_Types => new String'("Remote_Types"),
463 T_Shared_Passive => new String'("Shared_Passive"),
464 T_RCI => new String'("RCI"),
465 T_Predefined => new String'("Predefined"),
466 T_Internal => new String'("Internal"),
467 T_Is_Generic => new String'("Is_Generic"),
468 T_Procedure => new String'("procedure"),
469 T_Function => new String'("function"),
470 T_Package => new String'("package"),
471 T_Subprogram => new String'("subprogram"),
472 T_Spec => new String'("spec"),
473 T_Body => new String'("body"));
475 procedure Output_Name (N : Name_Id);
476 -- Remove any encoding info (%b and %s) and output N
478 procedure Output_Afile (A : File_Name_Type);
479 procedure Output_Ofile (O : File_Name_Type);
480 procedure Output_Sfile (S : File_Name_Type);
481 -- Output various names. Check that the name is different from no name.
482 -- Otherwise, skip the output.
484 procedure Output_Token (T : Token_Type);
485 -- Output token using specific format. That is several indentations and:
487 -- T_No_ALI .. T_With : <token> & " =>" & NL
488 -- T_Source .. T_Kind : <token> & " => "
489 -- T_Flags : <token> & " =>"
490 -- T_Preelab .. T_Body : " " & <token>
492 procedure Output_Sdep (S : Sdep_Id);
493 procedure Output_Unit (U : Unit_Id);
494 procedure Output_With (W : With_Id);
495 -- Output this entry as a global section (like ALIs)
497 ------------------
498 -- Output_Afile --
499 ------------------
501 procedure Output_Afile (A : File_Name_Type) is
502 begin
503 if A /= No_File then
504 Output_Token (T_Afile);
505 Write_Name (A);
506 Write_Eol;
507 end if;
508 end Output_Afile;
510 ----------------
511 -- Output_ALI --
512 ----------------
514 procedure Output_ALI (A : ALI_Id) is
515 begin
516 Output_Token (T_ALI);
517 N_Indents := N_Indents + 1;
519 Output_Afile (ALIs.Table (A).Afile);
520 Output_Ofile (ALIs.Table (A).Ofile_Full_Name);
521 Output_Sfile (ALIs.Table (A).Sfile);
523 -- Output Main
525 if ALIs.Table (A).Main_Program /= None then
526 Output_Token (T_Main);
528 if ALIs.Table (A).Main_Program = Proc then
529 Output_Token (T_Procedure);
530 else
531 Output_Token (T_Function);
532 end if;
534 Write_Eol;
535 end if;
537 -- Output Units
539 for U in ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit loop
540 Output_Unit (U);
541 end loop;
543 -- Output Sdeps
545 for S in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
546 Output_Sdep (S);
547 end loop;
549 N_Indents := N_Indents - 1;
550 end Output_ALI;
552 -------------------
553 -- Output_No_ALI --
554 -------------------
556 procedure Output_No_ALI (Afile : File_Name_Type) is
557 begin
558 Output_Token (T_No_ALI);
559 N_Indents := N_Indents + 1;
560 Output_Afile (Afile);
561 N_Indents := N_Indents - 1;
562 end Output_No_ALI;
564 -----------------
565 -- Output_Name --
566 -----------------
568 procedure Output_Name (N : Name_Id) is
569 begin
570 -- Remove any encoding info (%s or %b)
572 Get_Name_String (N);
574 if Name_Len > 2
575 and then Name_Buffer (Name_Len - 1) = '%'
576 then
577 Name_Len := Name_Len - 2;
578 end if;
580 Output_Token (T_Name);
581 Write_Str (Name_Buffer (1 .. Name_Len));
582 Write_Eol;
583 end Output_Name;
585 ------------------
586 -- Output_Ofile --
587 ------------------
589 procedure Output_Ofile (O : File_Name_Type) is
590 begin
591 if O /= No_File then
592 Output_Token (T_Ofile);
593 Write_Name (O);
594 Write_Eol;
595 end if;
596 end Output_Ofile;
598 -----------------
599 -- Output_Sdep --
600 -----------------
602 procedure Output_Sdep (S : Sdep_Id) is
603 begin
604 Output_Token (T_Source);
605 Write_Name (Sdep.Table (S).Sfile);
606 Write_Eol;
607 end Output_Sdep;
609 ------------------
610 -- Output_Sfile --
611 ------------------
613 procedure Output_Sfile (S : File_Name_Type) is
614 FS : File_Name_Type := S;
616 begin
617 if FS /= No_File then
619 -- We want to output the full source name
621 FS := Full_Source_Name (FS);
623 -- There is no full source name. This occurs for instance when a
624 -- withed unit has a spec file but no body file. This situation is
625 -- not a problem for GNATDIST since the unit may be located on a
626 -- partition we do not want to build. However, we need to locate
627 -- the spec file and to find its full source name. Replace the
628 -- body file name with the spec file name used to compile the
629 -- current unit when possible.
631 if FS = No_File then
632 Get_Name_String (S);
634 if Name_Len > 4
635 and then Name_Buffer (Name_Len - 3 .. Name_Len) = ".adb"
636 then
637 Name_Buffer (Name_Len) := 's';
638 FS := Full_Source_Name (Name_Find);
639 end if;
640 end if;
641 end if;
643 if FS /= No_File then
644 Output_Token (T_Sfile);
645 Write_Name (FS);
646 Write_Eol;
647 end if;
648 end Output_Sfile;
650 ------------------
651 -- Output_Token --
652 ------------------
654 procedure Output_Token (T : Token_Type) is
655 begin
656 if T in T_No_ALI .. T_Flags then
657 for J in 1 .. N_Indents loop
658 Write_Str (" ");
659 end loop;
661 Write_Str (Image (T).all);
663 for J in Image (T)'Length .. 12 loop
664 Write_Char (' ');
665 end loop;
667 Write_Str ("=>");
669 if T in T_No_ALI .. T_With then
670 Write_Eol;
671 elsif T in T_Source .. T_Name then
672 Write_Char (' ');
673 end if;
675 elsif T in T_Preelaborated .. T_Body then
676 if T in T_Preelaborated .. T_Is_Generic then
677 if N_Flags = 0 then
678 Output_Token (T_Flags);
679 end if;
681 N_Flags := N_Flags + 1;
682 end if;
684 Write_Char (' ');
685 Write_Str (Image (T).all);
687 else
688 Write_Str (Image (T).all);
689 end if;
690 end Output_Token;
692 -----------------
693 -- Output_Unit --
694 -----------------
696 procedure Output_Unit (U : Unit_Id) is
697 begin
698 Output_Token (T_Unit);
699 N_Indents := N_Indents + 1;
701 -- Output Name
703 Output_Name (Name_Id (Units.Table (U).Uname));
705 -- Output Kind
707 Output_Token (T_Kind);
709 if Units.Table (U).Unit_Kind = 'p' then
710 Output_Token (T_Package);
711 else
712 Output_Token (T_Subprogram);
713 end if;
715 if Name_Buffer (Name_Len) = 's' then
716 Output_Token (T_Spec);
717 else
718 Output_Token (T_Body);
719 end if;
721 Write_Eol;
723 -- Output source file name
725 Output_Sfile (Units.Table (U).Sfile);
727 -- Output Flags
729 N_Flags := 0;
731 if Units.Table (U).Preelab then
732 Output_Token (T_Preelaborated);
733 end if;
735 if Units.Table (U).Pure then
736 Output_Token (T_Pure);
737 end if;
739 if Units.Table (U).Has_RACW then
740 Output_Token (T_Has_RACW);
741 end if;
743 if Units.Table (U).Remote_Types then
744 Output_Token (T_Remote_Types);
745 end if;
747 if Units.Table (U).Shared_Passive then
748 Output_Token (T_Shared_Passive);
749 end if;
751 if Units.Table (U).RCI then
752 Output_Token (T_RCI);
753 end if;
755 if Units.Table (U).Predefined then
756 Output_Token (T_Predefined);
757 end if;
759 if Units.Table (U).Internal then
760 Output_Token (T_Internal);
761 end if;
763 if Units.Table (U).Is_Generic then
764 Output_Token (T_Is_Generic);
765 end if;
767 if N_Flags > 0 then
768 Write_Eol;
769 end if;
771 -- Output Withs
773 for W in Units.Table (U).First_With .. Units.Table (U).Last_With loop
774 Output_With (W);
775 end loop;
777 N_Indents := N_Indents - 1;
778 end Output_Unit;
780 -----------------
781 -- Output_With --
782 -----------------
784 procedure Output_With (W : With_Id) is
785 begin
786 Output_Token (T_With);
787 N_Indents := N_Indents + 1;
789 Output_Name (Name_Id (Withs.Table (W).Uname));
791 -- Output Kind
793 Output_Token (T_Kind);
795 if Name_Buffer (Name_Len) = 's' then
796 Output_Token (T_Spec);
797 else
798 Output_Token (T_Body);
799 end if;
801 Write_Eol;
803 Output_Afile (Withs.Table (W).Afile);
804 Output_Sfile (Withs.Table (W).Sfile);
806 N_Indents := N_Indents - 1;
807 end Output_With;
809 end GNATDIST;
811 -----------
812 -- Image --
813 -----------
815 function Image (Restriction : Restriction_Id) return String is
816 Result : String := Restriction'Img;
817 Skip : Boolean := True;
819 begin
820 for J in Result'Range loop
821 if Skip then
822 Skip := False;
823 Result (J) := To_Upper (Result (J));
825 elsif Result (J) = '_' then
826 Skip := True;
828 else
829 Result (J) := To_Lower (Result (J));
830 end if;
831 end loop;
833 return Result;
834 end Image;
836 ---------------
837 -- Normalize --
838 ---------------
840 function Normalize (Path : String) return String is
841 begin
842 return Normalize_Pathname (Path);
843 end Normalize;
845 --------------------------------
846 -- Output_License_Information --
847 --------------------------------
849 procedure Output_License_Information is
850 begin
851 case Build_Type is
852 when others =>
853 Write_Str ("Please refer to file COPYING in your distribution"
854 & " for license terms.");
855 Write_Eol;
856 end case;
858 Exit_Program (E_Success);
859 end Output_License_Information;
861 -------------------
862 -- Output_Object --
863 -------------------
865 procedure Output_Object (O : File_Name_Type) is
866 Object_Name : String_Access;
868 begin
869 if Print_Object then
870 if O /= No_File then
871 Get_Name_String (O);
872 Object_Name := To_Host_File_Spec (Name_Buffer (1 .. Name_Len));
873 else
874 Object_Name := No_Obj'Unchecked_Access;
875 end if;
877 Write_Str (Object_Name.all);
879 if Print_Source or else Print_Unit then
880 if Too_Long then
881 Write_Eol;
882 Write_Str (" ");
883 else
884 Write_Str (Spaces
885 (Object_Start + Object_Name'Length .. Object_End));
886 end if;
887 end if;
888 end if;
889 end Output_Object;
891 -------------------
892 -- Output_Source --
893 -------------------
895 procedure Output_Source (Sdep_I : Sdep_Id) is
896 Stamp : Time_Stamp_Type;
897 Checksum : Word;
898 FS : File_Name_Type;
899 Status : File_Status;
900 Object_Name : String_Access;
902 begin
903 if Sdep_I = No_Sdep_Id then
904 return;
905 end if;
907 Stamp := Sdep.Table (Sdep_I).Stamp;
908 Checksum := Sdep.Table (Sdep_I).Checksum;
909 FS := Sdep.Table (Sdep_I).Sfile;
911 if Print_Source then
912 Find_Status (FS, Stamp, Checksum, Status);
913 Get_Name_String (FS);
915 Object_Name := To_Host_File_Spec (Name_Buffer (1 .. Name_Len));
917 if Verbose_Mode then
918 Write_Str (" Source => ");
919 Write_Str (Object_Name.all);
921 if not Too_Long then
922 Write_Str
923 (Spaces (Source_Start + Object_Name'Length .. Source_End));
924 end if;
926 Output_Status (Status, Verbose => True);
927 Write_Eol;
928 Write_Str (" ");
930 else
931 if not Selective_Output then
932 Output_Status (Status, Verbose => False);
933 end if;
935 Write_Str (Object_Name.all);
936 end if;
937 end if;
938 end Output_Source;
940 -------------------
941 -- Output_Status --
942 -------------------
944 procedure Output_Status (FS : File_Status; Verbose : Boolean) is
945 begin
946 if Verbose then
947 case FS is
948 when OK =>
949 Write_Str (" unchanged");
951 when Checksum_OK =>
952 Write_Str (" slightly modified");
954 when Not_Found =>
955 Write_Str (" file not found");
957 when Not_Same =>
958 Write_Str (" modified");
960 when Not_First_On_PATH =>
961 Write_Str (" unchanged version not first on PATH");
962 end case;
964 else
965 case FS is
966 when OK =>
967 Write_Str (" OK ");
969 when Checksum_OK =>
970 Write_Str (" MOK ");
972 when Not_Found =>
973 Write_Str (" ??? ");
975 when Not_Same =>
976 Write_Str (" DIF ");
978 when Not_First_On_PATH =>
979 Write_Str (" HID ");
980 end case;
981 end if;
982 end Output_Status;
984 -----------------
985 -- Output_Unit --
986 -----------------
988 procedure Output_Unit (ALI : ALI_Id; U_Id : Unit_Id) is
989 Kind : Character;
990 U : Unit_Record renames Units.Table (U_Id);
992 begin
993 if Print_Unit then
994 Get_Name_String (U.Uname);
995 Kind := Name_Buffer (Name_Len);
996 Name_Len := Name_Len - 2;
998 if not Verbose_Mode then
999 Write_Str (Name_Buffer (1 .. Name_Len));
1001 else
1002 Write_Str ("Unit => ");
1003 Write_Eol;
1004 Write_Str (" Name => ");
1005 Write_Str (Name_Buffer (1 .. Name_Len));
1006 Write_Eol;
1007 Write_Str (" Kind => ");
1009 if Units.Table (U_Id).Unit_Kind = 'p' then
1010 Write_Str ("package ");
1011 else
1012 Write_Str ("subprogram ");
1013 end if;
1015 if Kind = 's' then
1016 Write_Str ("spec");
1017 else
1018 Write_Str ("body");
1019 end if;
1020 end if;
1022 if Verbose_Mode then
1023 if U.Preelab or else
1024 U.No_Elab or else
1025 U.Pure or else
1026 U.Dynamic_Elab or else
1027 U.Has_RACW or else
1028 U.Remote_Types or else
1029 U.Shared_Passive or else
1030 U.RCI or else
1031 U.Predefined or else
1032 U.Internal or else
1033 U.Is_Generic or else
1034 U.Init_Scalars or else
1035 U.SAL_Interface or else
1036 U.Body_Needed_For_SAL or else
1037 U.Elaborate_Body
1038 then
1039 Write_Eol;
1040 Write_Str (" Flags =>");
1042 if U.Preelab then
1043 Write_Str (" Preelaborable");
1044 end if;
1046 if U.No_Elab then
1047 Write_Str (" No_Elab_Code");
1048 end if;
1050 if U.Pure then
1051 Write_Str (" Pure");
1052 end if;
1054 if U.Dynamic_Elab then
1055 Write_Str (" Dynamic_Elab");
1056 end if;
1058 if U.Has_RACW then
1059 Write_Str (" Has_RACW");
1060 end if;
1062 if U.Remote_Types then
1063 Write_Str (" Remote_Types");
1064 end if;
1066 if U.Shared_Passive then
1067 Write_Str (" Shared_Passive");
1068 end if;
1070 if U.RCI then
1071 Write_Str (" RCI");
1072 end if;
1074 if U.Predefined then
1075 Write_Str (" Predefined");
1076 end if;
1078 if U.Internal then
1079 Write_Str (" Internal");
1080 end if;
1082 if U.Is_Generic then
1083 Write_Str (" Is_Generic");
1084 end if;
1086 if U.Init_Scalars then
1087 Write_Str (" Init_Scalars");
1088 end if;
1090 if U.SAL_Interface then
1091 Write_Str (" SAL_Interface");
1092 end if;
1094 if U.Body_Needed_For_SAL then
1095 Write_Str (" Body_Needed_For_SAL");
1096 end if;
1098 if U.Elaborate_Body then
1099 Write_Str (" Elaborate Body");
1100 end if;
1102 if U.Remote_Types then
1103 Write_Str (" Remote_Types");
1104 end if;
1106 if U.Shared_Passive then
1107 Write_Str (" Shared_Passive");
1108 end if;
1110 if U.Predefined then
1111 Write_Str (" Predefined");
1112 end if;
1113 end if;
1115 declare
1116 Restrictions : constant Restrictions_Info :=
1117 ALIs.Table (ALI).Restrictions;
1119 begin
1120 -- If the source was compiled with pragmas Restrictions,
1121 -- Display these restrictions.
1123 if Restrictions.Set /= (All_Restrictions => False) then
1124 Write_Eol;
1125 Write_Str (" pragma Restrictions =>");
1127 -- For boolean restrictions, just display the name of the
1128 -- restriction; for valued restrictions, also display the
1129 -- restriction value.
1131 for Restriction in All_Restrictions loop
1132 if Restrictions.Set (Restriction) then
1133 Write_Eol;
1134 Write_Str (" ");
1135 Write_Str (Image (Restriction));
1137 if Restriction in All_Parameter_Restrictions then
1138 Write_Str (" =>");
1139 Write_Str (Restrictions.Value (Restriction)'Img);
1140 end if;
1141 end if;
1142 end loop;
1143 end if;
1145 -- If the unit violates some Restrictions, display the list of
1146 -- these restrictions.
1148 if Restrictions.Violated /= (All_Restrictions => False) then
1149 Write_Eol;
1150 Write_Str (" Restrictions violated =>");
1152 -- For boolean restrictions, just display the name of the
1153 -- restriction. For valued restrictions, also display the
1154 -- restriction value.
1156 for Restriction in All_Restrictions loop
1157 if Restrictions.Violated (Restriction) then
1158 Write_Eol;
1159 Write_Str (" ");
1160 Write_Str (Image (Restriction));
1162 if Restriction in All_Parameter_Restrictions then
1163 if Restrictions.Count (Restriction) > 0 then
1164 Write_Str (" =>");
1166 if Restrictions.Unknown (Restriction) then
1167 Write_Str (" at least");
1168 end if;
1170 Write_Str (Restrictions.Count (Restriction)'Img);
1171 end if;
1172 end if;
1173 end if;
1174 end loop;
1175 end if;
1176 end;
1177 end if;
1179 if Print_Source then
1180 if Too_Long then
1181 Write_Eol;
1182 Write_Str (" ");
1183 else
1184 Write_Str (Spaces (Unit_Start + Name_Len + 1 .. Unit_End));
1185 end if;
1186 end if;
1187 end if;
1188 end Output_Unit;
1190 -----------------
1191 -- Reset_Print --
1192 -----------------
1194 procedure Reset_Print is
1195 begin
1196 if not Selective_Output then
1197 Selective_Output := True;
1198 Print_Source := False;
1199 Print_Object := False;
1200 Print_Unit := False;
1201 end if;
1202 end Reset_Print;
1204 ----------------
1205 -- Search_RTS --
1206 ----------------
1208 procedure Search_RTS (Name : String) is
1209 Src_Path : String_Ptr;
1210 Lib_Path : String_Ptr;
1211 -- Paths for source and include subdirs
1213 Rts_Full_Path : String_Access;
1214 -- Full path for RTS project
1216 begin
1217 -- Try to find the RTS
1219 Src_Path := Get_RTS_Search_Dir (Name, Include);
1220 Lib_Path := Get_RTS_Search_Dir (Name, Objects);
1222 -- For non-project RTS, both the include and the objects directories
1223 -- must be present.
1225 if Src_Path /= null and then Lib_Path /= null then
1226 Add_Search_Dirs (Src_Path, Include);
1227 Add_Search_Dirs (Lib_Path, Objects);
1228 return;
1229 end if;
1231 if Lib_Path /= null then
1232 Osint.Fail ("RTS path not valid: missing adainclude directory");
1233 elsif Src_Path /= null then
1234 Osint.Fail ("RTS path not valid: missing adalib directory");
1235 end if;
1237 -- Try to find the RTS on the project path. First setup the project path
1239 Initialize_Default_Project_Path
1240 (Prj_Path, Target_Name => Sdefault.Target_Name.all);
1242 Rts_Full_Path := Get_Runtime_Path (Prj_Path, Name);
1244 if Rts_Full_Path /= null then
1246 -- Directory name was found on the project path. Look for the
1247 -- include subdirectory(s).
1249 Src_Path := Get_RTS_Search_Dir (Rts_Full_Path.all, Include);
1251 if Src_Path /= null then
1252 Add_Search_Dirs (Src_Path, Include);
1254 -- Add the lib subdirectory if it exists
1256 Lib_Path := Get_RTS_Search_Dir (Rts_Full_Path.all, Objects);
1258 if Lib_Path /= null then
1259 Add_Search_Dirs (Lib_Path, Objects);
1260 end if;
1262 return;
1263 end if;
1264 end if;
1266 Osint.Fail
1267 ("RTS path not valid: missing adainclude and adalib directories");
1268 end Search_RTS;
1270 -------------------
1271 -- Scan_Ls_Arg --
1272 -------------------
1274 procedure Scan_Ls_Arg (Argv : String) is
1275 FD : File_Descriptor;
1276 Len : Integer;
1277 OK : Boolean;
1279 begin
1280 pragma Assert (Argv'First = 1);
1282 if Argv'Length = 0 then
1283 return;
1284 end if;
1286 OK := True;
1287 if Argv (1) = '-' then
1288 if Argv'Length = 1 then
1289 Fail ("switch character cannot be followed by a blank");
1291 -- Processing for -I-
1293 elsif Argv (2 .. Argv'Last) = "I-" then
1294 Opt.Look_In_Primary_Dir := False;
1296 -- Forbid -?- or -??- where ? is any character
1298 elsif (Argv'Length = 3 and then Argv (3) = '-')
1299 or else (Argv'Length = 4 and then Argv (4) = '-')
1300 then
1301 Fail ("Trailing ""-"" at the end of " & Argv & " forbidden.");
1303 -- Processing for -Idir
1305 elsif Argv (2) = 'I' then
1306 Add_Source_Dir (Argv (3 .. Argv'Last));
1307 Add_Lib_Dir (Argv (3 .. Argv'Last));
1309 -- Processing for -aIdir (to gcc this is like a -I switch)
1311 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
1312 Add_Source_Dir (Argv (4 .. Argv'Last));
1314 -- Processing for -aOdir
1316 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
1317 Add_Lib_Dir (Argv (4 .. Argv'Last));
1319 -- Processing for -aLdir (to gnatbind this is like a -aO switch)
1321 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
1322 Add_Lib_Dir (Argv (4 .. Argv'Last));
1324 -- Processing for -aP<dir>
1326 elsif Argv'Length > 3 and then Argv (1 .. 3) = "-aP" then
1327 Add_Directories (Prj_Path, Argv (4 .. Argv'Last));
1329 -- Processing for -nostdinc
1331 elsif Argv (2 .. Argv'Last) = "nostdinc" then
1332 Opt.No_Stdinc := True;
1334 -- Processing for one character switches
1336 elsif Argv'Length = 2 then
1337 case Argv (2) is
1338 when 'a' => Also_Predef := True;
1339 when 'h' => Print_Usage := True;
1340 when 'u' => Reset_Print; Print_Unit := True;
1341 when 's' => Reset_Print; Print_Source := True;
1342 when 'o' => Reset_Print; Print_Object := True;
1343 when 'v' => Verbose_Mode := True;
1344 when 'd' => Dependable := True;
1345 when 'l' => License := True;
1346 when 'V' => Very_Verbose_Mode := True;
1348 when others => OK := False;
1349 end case;
1351 -- Processing for -files=file
1353 elsif Argv'Length > 7 and then Argv (1 .. 7) = "-files=" then
1354 FD := Open_Read (Argv (8 .. Argv'Last), GNAT.OS_Lib.Text);
1356 if FD = Invalid_FD then
1357 Osint.Fail ("could not find text file """ &
1358 Argv (8 .. Argv'Last) & '"');
1359 end if;
1361 Len := Integer (File_Length (FD));
1363 declare
1364 Buffer : String (1 .. Len + 1);
1365 Index : Positive := 1;
1366 Last : Positive;
1368 begin
1369 -- Read the file
1371 Len := Read (FD, Buffer (1)'Address, Len);
1372 Buffer (Buffer'Last) := ASCII.NUL;
1373 Close (FD);
1375 -- Scan the file line by line
1377 while Index < Buffer'Last loop
1379 -- Find the end of line
1381 Last := Index;
1382 while Last <= Buffer'Last
1383 and then Buffer (Last) /= ASCII.LF
1384 and then Buffer (Last) /= ASCII.CR
1385 loop
1386 Last := Last + 1;
1387 end loop;
1389 -- Ignore empty lines
1391 if Last > Index then
1392 Add_File (Buffer (Index .. Last - 1));
1393 end if;
1395 -- Find the beginning of the next line
1397 Index := Last;
1398 while Buffer (Index) = ASCII.CR or else
1399 Buffer (Index) = ASCII.LF
1400 loop
1401 Index := Index + 1;
1402 end loop;
1403 end loop;
1404 end;
1406 -- Processing for --RTS=path
1408 elsif Argv'Length >= 5 and then Argv (1 .. 5) = "--RTS" then
1409 if Argv'Length <= 6 or else Argv (6) /= '='then
1410 Osint.Fail ("missing path for --RTS");
1412 else
1413 -- Check that it is the first time we see this switch or, if
1414 -- it is not the first time, the same path is specified.
1416 if RTS_Specified = null then
1417 RTS_Specified := new String'(Argv (7 .. Argv'Last));
1419 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
1420 Osint.Fail ("--RTS cannot be specified multiple times");
1421 end if;
1423 -- Valid --RTS switch
1425 Opt.No_Stdinc := True;
1426 Opt.RTS_Switch := True;
1427 end if;
1429 else
1430 OK := False;
1431 end if;
1433 -- If not a switch, it must be a file name
1435 else
1436 Add_File (Argv);
1437 end if;
1439 if not OK then
1440 Write_Str ("warning: unknown switch """);
1441 Write_Str (Argv);
1442 Write_Line ("""");
1443 end if;
1445 end Scan_Ls_Arg;
1447 -----------
1448 -- Usage --
1449 -----------
1451 procedure Usage is
1452 begin
1453 -- Usage line
1455 Write_Str ("Usage: ");
1456 Osint.Write_Program_Name;
1457 Write_Str (" switches [list of object files]");
1458 Write_Eol;
1459 Write_Eol;
1461 -- GNATLS switches
1463 Write_Str ("switches:");
1464 Write_Eol;
1466 Display_Usage_Version_And_Help;
1468 -- Line for -a
1470 Write_Str (" -a also output relevant predefined units");
1471 Write_Eol;
1473 -- Line for -u
1475 Write_Str (" -u output only relevant unit names");
1476 Write_Eol;
1478 -- Line for -h
1480 Write_Str (" -h output this help message");
1481 Write_Eol;
1483 -- Line for -s
1485 Write_Str (" -s output only relevant source names");
1486 Write_Eol;
1488 -- Line for -o
1490 Write_Str (" -o output only relevant object names");
1491 Write_Eol;
1493 -- Line for -d
1495 Write_Str (" -d output sources on which specified units " &
1496 "depend");
1497 Write_Eol;
1499 -- Line for -l
1501 Write_Str (" -l output license information");
1502 Write_Eol;
1504 -- Line for -v
1506 Write_Str (" -v verbose output, full path and unit " &
1507 "information");
1508 Write_Eol;
1509 Write_Eol;
1511 -- Line for -files=
1513 Write_Str (" -files=fil files are listed in text file 'fil'");
1514 Write_Eol;
1516 -- Line for -aI switch
1518 Write_Str (" -aIdir specify source files search path");
1519 Write_Eol;
1521 -- Line for -aO switch
1523 Write_Str (" -aOdir specify object files search path");
1524 Write_Eol;
1526 -- Line for -aP switch
1528 Write_Str (" -aPdir specify project search path");
1529 Write_Eol;
1531 -- Line for -I switch
1533 Write_Str (" -Idir like -aIdir -aOdir");
1534 Write_Eol;
1536 -- Line for -I- switch
1538 Write_Str (" -I- do not look for sources & object files");
1539 Write_Str (" in the default directory");
1540 Write_Eol;
1542 -- Line for -nostdinc
1544 Write_Str (" -nostdinc do not look for source files");
1545 Write_Str (" in the system default directory");
1546 Write_Eol;
1548 -- Line for --RTS
1550 Write_Str (" --RTS=dir specify the default source and object search"
1551 & " path");
1552 Write_Eol;
1554 -- File Status explanation
1556 Write_Eol;
1557 Write_Str (" file status can be:");
1558 Write_Eol;
1560 for ST in File_Status loop
1561 Write_Str (" ");
1562 Output_Status (ST, Verbose => False);
1563 Write_Str (" ==> ");
1564 Output_Status (ST, Verbose => True);
1565 Write_Eol;
1566 end loop;
1567 end Usage;
1569 procedure Check_Version_And_Help is new Check_Version_And_Help_G (Usage);
1571 -- Start of processing for Gnatls
1573 begin
1574 -- Initialize standard packages
1576 Csets.Initialize;
1577 Snames.Initialize;
1578 Stringt.Initialize;
1580 -- First check for --version or --help
1582 Check_Version_And_Help ("GNATLS", "1992");
1584 -- Loop to scan out arguments
1586 Next_Arg := 1;
1587 Scan_Args : while Next_Arg < Arg_Count loop
1588 declare
1589 Next_Argv : String (1 .. Len_Arg (Next_Arg));
1590 begin
1591 Fill_Arg (Next_Argv'Address, Next_Arg);
1592 Scan_Ls_Arg (Next_Argv);
1593 end;
1595 Next_Arg := Next_Arg + 1;
1596 end loop Scan_Args;
1598 -- If -l (output license information) is given, it must be the only switch
1600 if License then
1601 if Arg_Count = 2 then
1602 Output_License_Information;
1603 Exit_Program (E_Success);
1605 else
1606 Set_Standard_Error;
1607 Write_Str ("Can't use -l with another switch");
1608 Write_Eol;
1609 Try_Help;
1610 Exit_Program (E_Fatal);
1611 end if;
1612 end if;
1614 -- Handle --RTS switch
1616 if RTS_Specified /= null then
1617 Search_RTS (RTS_Specified.all);
1618 end if;
1620 -- Add the source and object directories specified on the command line, if
1621 -- any, to the searched directories.
1623 while First_Source_Dir /= null loop
1624 Add_Src_Search_Dir (First_Source_Dir.Value.all);
1625 First_Source_Dir := First_Source_Dir.Next;
1626 end loop;
1628 while First_Lib_Dir /= null loop
1629 Add_Lib_Search_Dir (First_Lib_Dir.Value.all);
1630 First_Lib_Dir := First_Lib_Dir.Next;
1631 end loop;
1633 -- Finally, add the default directories
1635 Osint.Add_Default_Search_Dirs;
1637 -- If --RTS= is not specified, check if there is a default runtime
1639 if RTS_Specified = null then
1640 declare
1641 Text : Source_Buffer_Ptr;
1642 Hi : Source_Ptr;
1644 begin
1645 Name_Buffer (1 .. 10) := "system.ads";
1646 Name_Len := 10;
1648 Read_Source_File (Name_Find, Lo => 0, Hi => Hi, Src => Text);
1650 if Text = null then
1651 No_Runtime := True;
1652 end if;
1653 end;
1654 end if;
1656 if Verbose_Mode then
1657 Write_Eol;
1658 Display_Version ("GNATLS", "1997");
1659 Write_Eol;
1661 if No_Runtime then
1662 Write_Str
1663 ("Default runtime not available. Use --RTS= with a valid runtime");
1664 Write_Eol;
1665 Write_Eol;
1666 Exit_Status := E_Warnings;
1667 end if;
1669 Write_Str ("Source Search Path:");
1670 Write_Eol;
1672 for J in 1 .. Nb_Dir_In_Src_Search_Path loop
1673 Write_Str (" ");
1675 if Dir_In_Src_Search_Path (J)'Length = 0 then
1676 Write_Str ("<Current_Directory>");
1677 Write_Eol;
1679 elsif not No_Runtime then
1680 Write_Str
1681 (Normalize
1682 (To_Host_Dir_Spec
1683 (Dir_In_Src_Search_Path (J).all, True).all));
1684 Write_Eol;
1685 end if;
1686 end loop;
1688 Write_Eol;
1689 Write_Eol;
1690 Write_Str ("Object Search Path:");
1691 Write_Eol;
1693 for J in 1 .. Nb_Dir_In_Obj_Search_Path loop
1694 Write_Str (" ");
1696 if Dir_In_Obj_Search_Path (J)'Length = 0 then
1697 Write_Str ("<Current_Directory>");
1698 Write_Eol;
1700 elsif not No_Runtime then
1701 Write_Str
1702 (Normalize
1703 (To_Host_Dir_Spec
1704 (Dir_In_Obj_Search_Path (J).all, True).all));
1705 Write_Eol;
1706 end if;
1707 end loop;
1709 Write_Eol;
1710 Write_Eol;
1711 Write_Str (Project_Search_Path);
1712 Write_Eol;
1713 Write_Str (" <Current_Directory>");
1714 Write_Eol;
1716 Initialize_Default_Project_Path
1717 (Prj_Path, Target_Name => Sdefault.Target_Name.all);
1719 declare
1720 Project_Path : String_Access;
1721 First : Natural;
1722 Last : Natural;
1724 begin
1725 Get_Path (Prj_Path, Project_Path);
1727 if Project_Path.all /= "" then
1728 First := Project_Path'First;
1729 loop
1730 while First <= Project_Path'Last
1731 and then (Project_Path (First) = Path_Separator)
1732 loop
1733 First := First + 1;
1734 end loop;
1736 exit when First > Project_Path'Last;
1738 Last := First;
1739 while Last < Project_Path'Last
1740 and then Project_Path (Last + 1) /= Path_Separator
1741 loop
1742 Last := Last + 1;
1743 end loop;
1745 if First /= Last or else Project_Path (First) /= '.' then
1747 -- If the directory is ".", skip it as it is the current
1748 -- directory and it is already the first directory in the
1749 -- project path.
1751 Write_Str (" ");
1752 Write_Str
1753 (Normalize
1754 (To_Host_Dir_Spec
1755 (Project_Path (First .. Last), True).all));
1756 Write_Eol;
1757 end if;
1759 First := Last + 1;
1760 end loop;
1761 end if;
1762 end;
1764 Write_Eol;
1765 end if;
1767 -- Output usage information when requested
1769 if Print_Usage then
1770 Usage;
1771 end if;
1773 if not More_Lib_Files then
1774 if not Print_Usage and then not Verbose_Mode then
1775 if Argument_Count = 0 then
1776 Usage;
1777 else
1778 Try_Help;
1779 Exit_Status := E_Fatal;
1780 end if;
1781 end if;
1783 Exit_Program (Exit_Status);
1784 end if;
1786 Initialize_ALI;
1787 Initialize_ALI_Source;
1789 -- Print out all libraries for which no ALI files can be located
1791 while More_Lib_Files loop
1792 Main_File := Next_Main_Lib_File;
1793 Ali_File := Full_Lib_File_Name (Lib_File_Name (Main_File));
1795 if Ali_File = No_File then
1796 if Very_Verbose_Mode then
1797 GNATDIST.Output_No_ALI (Lib_File_Name (Main_File));
1799 else
1800 Set_Standard_Error;
1801 Write_Str ("Can't find library info for ");
1802 Get_Name_String (Main_File);
1803 Write_Char ('"'); -- "
1804 Write_Str (Name_Buffer (1 .. Name_Len));
1805 Write_Char ('"'); -- "
1806 Write_Eol;
1807 Exit_Status := E_Fatal;
1808 end if;
1810 else
1811 Ali_File := Strip_Directory (Ali_File);
1813 if Get_Name_Table_Info (Ali_File) = 0 then
1814 Text := Read_Library_Info (Ali_File, True);
1816 declare
1817 Discard : ALI_Id;
1818 begin
1819 Discard :=
1820 Scan_ALI
1821 (Ali_File,
1822 Text,
1823 Ignore_ED => False,
1824 Err => False,
1825 Ignore_Errors => True);
1826 end;
1828 Free (Text);
1829 end if;
1830 end if;
1831 end loop;
1833 -- Reset default output file descriptor, if needed
1835 Set_Standard_Output;
1837 if Very_Verbose_Mode then
1838 for A in ALIs.First .. ALIs.Last loop
1839 GNATDIST.Output_ALI (A);
1840 end loop;
1842 return;
1843 end if;
1845 Find_General_Layout;
1847 for Id in ALIs.First .. ALIs.Last loop
1848 declare
1849 Last_U : Unit_Id;
1851 begin
1852 Get_Name_String (Units.Table (ALIs.Table (Id).First_Unit).Uname);
1854 if Also_Predef or else not Is_Internal_Unit then
1855 if ALIs.Table (Id).No_Object then
1856 Output_Object (No_File);
1857 else
1858 Output_Object (ALIs.Table (Id).Ofile_Full_Name);
1859 end if;
1861 -- In verbose mode print all main units in the ALI file, otherwise
1862 -- just print the first one to ease columnwise printout
1864 if Verbose_Mode then
1865 Last_U := ALIs.Table (Id).Last_Unit;
1866 else
1867 Last_U := ALIs.Table (Id).First_Unit;
1868 end if;
1870 for U in ALIs.Table (Id).First_Unit .. Last_U loop
1871 if U /= ALIs.Table (Id).First_Unit
1872 and then Selective_Output
1873 and then Print_Unit
1874 then
1875 Write_Eol;
1876 end if;
1878 Output_Unit (Id, U);
1880 -- Output source now, unless if it will be done as part of
1881 -- outputing dependencies.
1883 if not (Dependable and then Print_Source) then
1884 Output_Source (Corresponding_Sdep_Entry (Id, U));
1885 end if;
1886 end loop;
1888 -- Print out list of units on which this unit depends (D lines)
1890 if Dependable and then Print_Source then
1891 if Verbose_Mode then
1892 Write_Str ("depends upon");
1893 Write_Eol;
1894 Write_Str (" ");
1895 else
1896 Write_Eol;
1897 end if;
1899 for D in
1900 ALIs.Table (Id).First_Sdep .. ALIs.Table (Id).Last_Sdep
1901 loop
1902 if Also_Predef
1903 or else not Is_Internal_File_Name (Sdep.Table (D).Sfile)
1904 then
1905 if Verbose_Mode then
1906 Write_Str (" ");
1907 Output_Source (D);
1909 elsif Too_Long then
1910 Write_Str (" ");
1911 Output_Source (D);
1912 Write_Eol;
1914 else
1915 Write_Str (Spaces (1 .. Source_Start - 2));
1916 Output_Source (D);
1917 Write_Eol;
1918 end if;
1919 end if;
1920 end loop;
1921 end if;
1923 Write_Eol;
1924 end if;
1925 end;
1926 end loop;
1928 -- All done. Set proper exit status
1930 Namet.Finalize;
1931 Exit_Program (Exit_Status);
1932 end Gnatls;