2014-10-31 Hristian Kirtchev <kirtchev@adacore.com>
[official-gcc.git] / gcc / ada / gnatls.adb
blob808b00937b5bd62ae2f727a89a59148c42246d94
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 end if;
1668 Write_Str ("Source Search Path:");
1669 Write_Eol;
1671 for J in 1 .. Nb_Dir_In_Src_Search_Path loop
1672 Write_Str (" ");
1674 if Dir_In_Src_Search_Path (J)'Length = 0 then
1675 Write_Str ("<Current_Directory>");
1676 Write_Eol;
1678 elsif not No_Runtime then
1679 Write_Str
1680 (Normalize
1681 (To_Host_Dir_Spec
1682 (Dir_In_Src_Search_Path (J).all, True).all));
1683 Write_Eol;
1684 end if;
1685 end loop;
1687 Write_Eol;
1688 Write_Eol;
1689 Write_Str ("Object Search Path:");
1690 Write_Eol;
1692 for J in 1 .. Nb_Dir_In_Obj_Search_Path loop
1693 Write_Str (" ");
1695 if Dir_In_Obj_Search_Path (J)'Length = 0 then
1696 Write_Str ("<Current_Directory>");
1697 Write_Eol;
1699 elsif not No_Runtime then
1700 Write_Str
1701 (Normalize
1702 (To_Host_Dir_Spec
1703 (Dir_In_Obj_Search_Path (J).all, True).all));
1704 Write_Eol;
1705 end if;
1706 end loop;
1708 Write_Eol;
1709 Write_Eol;
1710 Write_Str (Project_Search_Path);
1711 Write_Eol;
1712 Write_Str (" <Current_Directory>");
1713 Write_Eol;
1715 Initialize_Default_Project_Path
1716 (Prj_Path, Target_Name => Sdefault.Target_Name.all);
1718 declare
1719 Project_Path : String_Access;
1720 First : Natural;
1721 Last : Natural;
1723 begin
1724 Get_Path (Prj_Path, Project_Path);
1726 if Project_Path.all /= "" then
1727 First := Project_Path'First;
1728 loop
1729 while First <= Project_Path'Last
1730 and then (Project_Path (First) = Path_Separator)
1731 loop
1732 First := First + 1;
1733 end loop;
1735 exit when First > Project_Path'Last;
1737 Last := First;
1738 while Last < Project_Path'Last
1739 and then Project_Path (Last + 1) /= Path_Separator
1740 loop
1741 Last := Last + 1;
1742 end loop;
1744 if First /= Last or else Project_Path (First) /= '.' then
1746 -- If the directory is ".", skip it as it is the current
1747 -- directory and it is already the first directory in the
1748 -- project path.
1750 Write_Str (" ");
1751 Write_Str
1752 (Normalize
1753 (To_Host_Dir_Spec
1754 (Project_Path (First .. Last), True).all));
1755 Write_Eol;
1756 end if;
1758 First := Last + 1;
1759 end loop;
1760 end if;
1761 end;
1763 Write_Eol;
1764 end if;
1766 -- Output usage information when requested
1768 if Print_Usage then
1769 Usage;
1770 end if;
1772 if not More_Lib_Files then
1773 if not Print_Usage and then not Verbose_Mode then
1774 if Argument_Count = 0 then
1775 Usage;
1776 else
1777 Try_Help;
1778 end if;
1779 end if;
1781 Exit_Program (E_Fatal);
1782 end if;
1784 Initialize_ALI;
1785 Initialize_ALI_Source;
1787 -- Print out all libraries for which no ALI files can be located
1789 while More_Lib_Files loop
1790 Main_File := Next_Main_Lib_File;
1791 Ali_File := Full_Lib_File_Name (Lib_File_Name (Main_File));
1793 if Ali_File = No_File then
1794 if Very_Verbose_Mode then
1795 GNATDIST.Output_No_ALI (Lib_File_Name (Main_File));
1797 else
1798 Set_Standard_Error;
1799 Write_Str ("Can't find library info for ");
1800 Get_Name_String (Main_File);
1801 Write_Char ('"'); -- "
1802 Write_Str (Name_Buffer (1 .. Name_Len));
1803 Write_Char ('"'); -- "
1804 Write_Eol;
1805 Exit_Status := E_Fatal;
1806 end if;
1808 else
1809 Ali_File := Strip_Directory (Ali_File);
1811 if Get_Name_Table_Info (Ali_File) = 0 then
1812 Text := Read_Library_Info (Ali_File, True);
1814 declare
1815 Discard : ALI_Id;
1816 begin
1817 Discard :=
1818 Scan_ALI
1819 (Ali_File,
1820 Text,
1821 Ignore_ED => False,
1822 Err => False,
1823 Ignore_Errors => True);
1824 end;
1826 Free (Text);
1827 end if;
1828 end if;
1829 end loop;
1831 -- Reset default output file descriptor, if needed
1833 Set_Standard_Output;
1835 if Very_Verbose_Mode then
1836 for A in ALIs.First .. ALIs.Last loop
1837 GNATDIST.Output_ALI (A);
1838 end loop;
1840 return;
1841 end if;
1843 Find_General_Layout;
1845 for Id in ALIs.First .. ALIs.Last loop
1846 declare
1847 Last_U : Unit_Id;
1849 begin
1850 Get_Name_String (Units.Table (ALIs.Table (Id).First_Unit).Uname);
1852 if Also_Predef or else not Is_Internal_Unit then
1853 if ALIs.Table (Id).No_Object then
1854 Output_Object (No_File);
1855 else
1856 Output_Object (ALIs.Table (Id).Ofile_Full_Name);
1857 end if;
1859 -- In verbose mode print all main units in the ALI file, otherwise
1860 -- just print the first one to ease columnwise printout
1862 if Verbose_Mode then
1863 Last_U := ALIs.Table (Id).Last_Unit;
1864 else
1865 Last_U := ALIs.Table (Id).First_Unit;
1866 end if;
1868 for U in ALIs.Table (Id).First_Unit .. Last_U loop
1869 if U /= ALIs.Table (Id).First_Unit
1870 and then Selective_Output
1871 and then Print_Unit
1872 then
1873 Write_Eol;
1874 end if;
1876 Output_Unit (Id, U);
1878 -- Output source now, unless if it will be done as part of
1879 -- outputing dependencies.
1881 if not (Dependable and then Print_Source) then
1882 Output_Source (Corresponding_Sdep_Entry (Id, U));
1883 end if;
1884 end loop;
1886 -- Print out list of units on which this unit depends (D lines)
1888 if Dependable and then Print_Source then
1889 if Verbose_Mode then
1890 Write_Str ("depends upon");
1891 Write_Eol;
1892 Write_Str (" ");
1893 else
1894 Write_Eol;
1895 end if;
1897 for D in
1898 ALIs.Table (Id).First_Sdep .. ALIs.Table (Id).Last_Sdep
1899 loop
1900 if Also_Predef
1901 or else not Is_Internal_File_Name (Sdep.Table (D).Sfile)
1902 then
1903 if Verbose_Mode then
1904 Write_Str (" ");
1905 Output_Source (D);
1907 elsif Too_Long then
1908 Write_Str (" ");
1909 Output_Source (D);
1910 Write_Eol;
1912 else
1913 Write_Str (Spaces (1 .. Source_Start - 2));
1914 Output_Source (D);
1915 Write_Eol;
1916 end if;
1917 end if;
1918 end loop;
1919 end if;
1921 Write_Eol;
1922 end if;
1923 end;
1924 end loop;
1926 -- All done. Set proper exit status
1928 Namet.Finalize;
1929 Exit_Program (Exit_Status);
1930 end Gnatls;