Daily bump.
[official-gcc.git] / gcc / ada / gnatls.adb
blobc52c1aea9c3f5bdc5a62811dd2120cbe4a468121
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-2024, 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 pragma Ada_2012;
28 with ALI; use ALI;
29 with ALI.Util; use ALI.Util;
30 with Binderr; use Binderr;
31 with Butil; use Butil;
32 with Csets;
33 with Fname; use Fname;
34 with Gnatvsn; use Gnatvsn;
35 with Make_Util; use Make_Util;
36 with Namet; use Namet;
37 with Opt; use Opt;
38 with Osint; use Osint;
39 with Osint.L; use Osint.L;
40 with Output; use Output;
41 with Rident; use Rident;
42 with Sdefault;
43 with Snames;
44 with Stringt;
45 with Switch; use Switch;
46 with Types; use Types;
47 with Uintp;
49 with GNAT.Case_Util; use GNAT.Case_Util;
50 with GNAT.Command_Line; use GNAT.Command_Line;
51 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
52 with GNAT.OS_Lib; use GNAT.OS_Lib;
54 procedure Gnatls is
55 pragma Ident (Gnat_Static_Version_String);
57 -- NOTE : The following string may be used by other tools, such as
58 -- GNAT Studio. So it can only be modified if these other uses are checked
59 -- and coordinated.
61 Project_Search_Path : constant String := "Project Search Path:";
62 -- Label displayed in verbose mode before the directories in the project
63 -- search path. Do not modify without checking NOTE above.
65 Prj_Path : String_Access;
67 Max_Column : constant := 80;
69 No_Obj : aliased String := "<no_obj>";
71 No_Runtime : Boolean := False;
72 -- Set to True if there is no default runtime and --RTS= is not specified
74 type File_Status is (
75 OK, -- matching timestamp
76 Checksum_OK, -- only matching checksum
77 Not_Found, -- file not found on source PATH
78 Not_Same, -- neither checksum nor timestamp matching
79 Not_First_On_PATH); -- matching file hidden by Not_Same file on path
81 type Dir_Data;
82 type Dir_Ref is access Dir_Data;
84 type Dir_Data is record
85 Value : String_Access;
86 Next : Dir_Ref;
87 end record;
88 -- Simply linked list of dirs
90 First_Source_Dir : Dir_Ref;
91 Last_Source_Dir : Dir_Ref;
92 -- The list of source directories from the command line.
93 -- These directories are added using Osint.Add_Src_Search_Dir
94 -- after those of the GNAT Project File, if any.
96 First_Lib_Dir : Dir_Ref;
97 Last_Lib_Dir : Dir_Ref;
98 -- The list of object directories from the command line.
99 -- These directories are added using Osint.Add_Lib_Search_Dir
100 -- after those of the GNAT Project File, if any.
102 Main_File : File_Name_Type;
103 Ali_File : File_Name_Type;
104 Text : Text_Buffer_Ptr;
105 Next_Arg : Positive;
107 Too_Long : Boolean := False;
108 -- When True, lines are too long for multi-column output and each
109 -- item of information is on a different line.
111 Selective_Output : Boolean := False;
112 Print_Usage : Boolean := False;
113 Print_Unit : Boolean := True;
114 Print_Source : Boolean := True;
115 Print_Object : Boolean := True;
116 -- Flags controlling the form of the output
118 Also_Predef : Boolean := False; -- -a
119 Dependable : Boolean := False; -- -d
120 License : Boolean := False; -- -l
121 Very_Verbose_Mode : Boolean := False; -- -V
122 -- Command line flags
124 Unit_Start : Integer;
125 Unit_End : Integer;
126 Source_Start : Integer;
127 Source_End : Integer;
128 Object_Start : Integer;
129 Object_End : Integer;
130 -- Various column starts and ends
132 Spaces : constant String (1 .. Max_Column) := (others => ' ');
134 RTS_Specified : String_Access := null;
135 -- Used to detect multiple use of --RTS= switch
137 Exit_Status : Exit_Code_Type := E_Success;
138 -- Reset to E_Fatal if bad error found
140 -----------------------
141 -- Local Subprograms --
142 -----------------------
144 procedure Add_Lib_Dir (Dir : String);
145 -- Add an object directory in the list First_Lib_Dir-Last_Lib_Dir
147 procedure Add_Source_Dir (Dir : String);
148 -- Add a source directory in the list First_Source_Dir-Last_Source_Dir
150 procedure Find_General_Layout;
151 -- Determine the structure of the output (multi columns or not, etc)
153 procedure Find_Status
154 (FS : in out File_Name_Type;
155 Stamp : Time_Stamp_Type;
156 Checksum : Word;
157 Status : out File_Status);
158 -- Determine the file status (Status) of the file represented by FS with
159 -- the expected Stamp and checksum given as argument. FS will be updated
160 -- to the full file name if available.
162 function Corresponding_Sdep_Entry (A : ALI_Id; U : Unit_Id) return Sdep_Id;
163 -- Give the Sdep entry corresponding to the unit U in ali record A
165 procedure Output_Object (O : File_Name_Type);
166 -- Print out the name of the object when requested
168 procedure Output_Source (Sdep_I : Sdep_Id);
169 -- Print out the name and status of the source corresponding to this
170 -- sdep entry.
172 procedure Output_Status (FS : File_Status; Verbose : Boolean);
173 -- Print out FS either in a coded form if verbose is false or in an
174 -- expanded form otherwise.
176 procedure Output_Unit (ALI : ALI_Id; U_Id : Unit_Id);
177 -- Print out information on the unit when requested
179 procedure Reset_Print;
180 -- Reset Print flags properly when selective output is chosen
182 procedure Scan_Ls_Arg (Argv : String);
183 -- Scan and process user specific arguments (Argv is a single argument)
185 procedure Search_RTS (Name : String);
186 -- Find include and objects path for the RTS name.
188 procedure Usage;
189 -- Print usage message
191 procedure Output_License_Information;
192 -- Output license statement, and if not found, output reference to COPYING
194 function Image (Restriction : Restriction_Id) return String;
195 -- Returns the capitalized image of Restriction
197 function Normalize (Path : String) return String;
198 -- Returns a normalized path name. On Windows, the directory separators are
199 -- set to '\' in Normalize_Pathname.
201 ------------------------------------------
202 -- GNATDIST specific output subprograms --
203 ------------------------------------------
205 package GNATDIST is
207 -- Any modification to this subunit requires synchronization with the
208 -- GNATDIST sources.
210 procedure Output_ALI (A : ALI_Id);
211 -- Comment required saying what this routine does ???
213 procedure Output_No_ALI (Afile : File_Name_Type);
214 -- Comments required saying what this routine does ???
216 end GNATDIST;
218 ------------------------------
219 -- Support for project path --
220 ------------------------------
222 package Prj_Env is
224 procedure Initialize_Default_Project_Path
225 (Self : in out String_Access;
226 Target_Name : String;
227 Runtime_Name : String := "");
228 -- Initialize Self. It will then contain the default project path on
229 -- the given target and runtime (including directories specified by the
230 -- environment variables GPR_PROJECT_PATH_FILE, GPR_PROJECT_PATH and
231 -- ADA_PROJECT_PATH). If one of the directory or Target_Name is "-",
232 -- then the path contains only those directories specified by the
233 -- environment variables (except "-"). This does nothing if Self has
234 -- already been initialized.
236 procedure Add_Directories
237 (Self : in out String_Access;
238 Path : String);
239 -- Add one or more directories to the path. Directories added with this
240 -- procedure are added in order after the current directory and before
241 -- the path given by the environment variable GPR_PROJECT_PATH. A value
242 -- of "-" will remove the default project directory from the project
243 -- path.
245 -- Calls to this subprogram must be performed before the first call to
246 -- Find_Project below, or PATH will be added at the end of the search
247 -- path.
249 function Get_Runtime_Path
250 (Self : String_Access;
251 Path : String) return String_Access;
252 -- Compute the full path for the project-based runtime name.
253 -- Path is simply searched on the project path.
255 end Prj_Env;
257 -----------------
258 -- Add_Lib_Dir --
259 -----------------
261 procedure Add_Lib_Dir (Dir : String) is
262 begin
263 if First_Lib_Dir = null then
264 First_Lib_Dir :=
265 new Dir_Data'
266 (Value => new String'(Dir),
267 Next => null);
268 Last_Lib_Dir := First_Lib_Dir;
270 else
271 Last_Lib_Dir.Next :=
272 new Dir_Data'
273 (Value => new String'(Dir),
274 Next => null);
275 Last_Lib_Dir := Last_Lib_Dir.Next;
276 end if;
277 end Add_Lib_Dir;
279 --------------------
280 -- Add_Source_Dir --
281 --------------------
283 procedure Add_Source_Dir (Dir : String) is
284 begin
285 if First_Source_Dir = null then
286 First_Source_Dir :=
287 new Dir_Data'
288 (Value => new String'(Dir),
289 Next => null);
290 Last_Source_Dir := First_Source_Dir;
292 else
293 Last_Source_Dir.Next :=
294 new Dir_Data'
295 (Value => new String'(Dir),
296 Next => null);
297 Last_Source_Dir := Last_Source_Dir.Next;
298 end if;
299 end Add_Source_Dir;
301 ------------------------------
302 -- Corresponding_Sdep_Entry --
303 ------------------------------
305 function Corresponding_Sdep_Entry
306 (A : ALI_Id;
307 U : Unit_Id) return Sdep_Id
309 begin
310 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
311 if Sdep.Table (D).Sfile = Units.Table (U).Sfile then
312 return D;
313 end if;
314 end loop;
316 Error_Msg_Unit_1 := Units.Table (U).Uname;
317 Error_Msg_File_1 := ALIs.Table (A).Afile;
318 Write_Eol;
319 Error_Msg ("wrong ALI format, can't find dependency line for $ in {");
320 Exit_Program (E_Fatal);
321 end Corresponding_Sdep_Entry;
323 -------------------------
324 -- Find_General_Layout --
325 -------------------------
327 procedure Find_General_Layout is
328 Max_Unit_Length : Integer := 11;
329 Max_Src_Length : Integer := 11;
330 Max_Obj_Length : Integer := 11;
332 Len : Integer;
333 FS : File_Name_Type;
335 begin
336 -- Compute maximum of each column
338 for Id in ALIs.First .. ALIs.Last loop
339 Get_Name_String (Units.Table (ALIs.Table (Id).First_Unit).Uname);
340 if Also_Predef or else not Is_Internal_Unit then
342 if Print_Unit then
343 Len := Name_Len - 1;
344 Max_Unit_Length := Integer'Max (Max_Unit_Length, Len);
345 end if;
347 if Print_Source then
348 FS := Full_Source_Name (ALIs.Table (Id).Sfile);
350 if FS = No_File then
351 Get_Name_String (ALIs.Table (Id).Sfile);
352 Name_Len := Name_Len + 13;
353 else
354 Get_Name_String (FS);
355 end if;
357 Max_Src_Length := Integer'Max (Max_Src_Length, Name_Len + 1);
358 end if;
360 if Print_Object then
361 if ALIs.Table (Id).No_Object then
362 Max_Obj_Length :=
363 Integer'Max (Max_Obj_Length, No_Obj'Length);
364 else
365 Get_Name_String (ALIs.Table (Id).Ofile_Full_Name);
366 Max_Obj_Length := Integer'Max (Max_Obj_Length, Name_Len + 1);
367 end if;
368 end if;
369 end if;
370 end loop;
372 -- Verify is output is not wider than maximum number of columns
374 Too_Long :=
375 Verbose_Mode
376 or else
377 (Max_Unit_Length + Max_Src_Length + Max_Obj_Length) > Max_Column;
379 -- Set start and end of columns
381 Object_Start := 1;
382 Object_End := Object_Start - 1;
384 if Print_Object then
385 Object_End := Object_Start + Max_Obj_Length;
386 end if;
388 Unit_Start := Object_End + 1;
389 Unit_End := Unit_Start - 1;
391 if Print_Unit then
392 Unit_End := Unit_Start + Max_Unit_Length;
393 end if;
395 Source_Start := Unit_End + 1;
397 if Source_Start > Spaces'Last then
398 Source_Start := Spaces'Last;
399 end if;
401 Source_End := Source_Start - 1;
403 if Print_Source then
404 Source_End := Source_Start + Max_Src_Length;
405 end if;
406 end Find_General_Layout;
408 -----------------
409 -- Find_Status --
410 -----------------
412 procedure Find_Status
413 (FS : in out File_Name_Type;
414 Stamp : Time_Stamp_Type;
415 Checksum : Word;
416 Status : out File_Status)
418 Tmp1 : File_Name_Type;
419 Tmp2 : File_Name_Type;
421 begin
422 Tmp1 := Full_Source_Name (FS);
424 if Tmp1 = No_File then
425 Status := Not_Found;
427 elsif File_Stamp (Tmp1) = Stamp then
428 FS := Tmp1;
429 Status := OK;
431 elsif Checksums_Match (Get_File_Checksum (FS), Checksum) then
432 FS := Tmp1;
433 Status := Checksum_OK;
435 else
436 Tmp2 := Matching_Full_Source_Name (FS, Stamp);
438 if Tmp2 = No_File then
439 Status := Not_Same;
440 FS := Tmp1;
442 else
443 Status := Not_First_On_PATH;
444 FS := Tmp2;
445 end if;
446 end if;
447 end Find_Status;
449 --------------
450 -- GNATDIST --
451 --------------
453 package body GNATDIST is
455 N_Flags : Natural;
456 N_Indents : Natural := 0;
458 type Token_Type is
459 (T_No_ALI,
460 T_ALI,
461 T_Unit,
462 T_With,
463 T_Source,
464 T_Afile,
465 T_Ofile,
466 T_Sfile,
467 T_Name,
468 T_Main,
469 T_Kind,
470 T_Flags,
471 T_Preelaborated,
472 T_Pure,
473 T_Has_RACW,
474 T_Remote_Types,
475 T_Shared_Passive,
476 T_RCI,
477 T_Predefined,
478 T_Internal,
479 T_Is_Generic,
480 T_Procedure,
481 T_Function,
482 T_Package,
483 T_Subprogram,
484 T_Spec,
485 T_Body);
487 Image : constant array (Token_Type) of String_Access :=
488 (T_No_ALI => new String'("No_ALI"),
489 T_ALI => new String'("ALI"),
490 T_Unit => new String'("Unit"),
491 T_With => new String'("With"),
492 T_Source => new String'("Source"),
493 T_Afile => new String'("Afile"),
494 T_Ofile => new String'("Ofile"),
495 T_Sfile => new String'("Sfile"),
496 T_Name => new String'("Name"),
497 T_Main => new String'("Main"),
498 T_Kind => new String'("Kind"),
499 T_Flags => new String'("Flags"),
500 T_Preelaborated => new String'("Preelaborated"),
501 T_Pure => new String'("Pure"),
502 T_Has_RACW => new String'("Has_RACW"),
503 T_Remote_Types => new String'("Remote_Types"),
504 T_Shared_Passive => new String'("Shared_Passive"),
505 T_RCI => new String'("RCI"),
506 T_Predefined => new String'("Predefined"),
507 T_Internal => new String'("Internal"),
508 T_Is_Generic => new String'("Is_Generic"),
509 T_Procedure => new String'("procedure"),
510 T_Function => new String'("function"),
511 T_Package => new String'("package"),
512 T_Subprogram => new String'("subprogram"),
513 T_Spec => new String'("spec"),
514 T_Body => new String'("body"));
516 procedure Output_Name (N : Name_Id);
517 -- Remove any encoding info (%b and %s) and output N
519 procedure Output_Afile (A : File_Name_Type);
520 procedure Output_Ofile (O : File_Name_Type);
521 procedure Output_Sfile (S : File_Name_Type);
522 -- Output various names. Check that the name is different from no name.
523 -- Otherwise, skip the output.
525 procedure Output_Token (T : Token_Type);
526 -- Output token using specific format. That is several indentations and:
528 -- T_No_ALI .. T_With : <token> & " =>" & NL
529 -- T_Source .. T_Kind : <token> & " => "
530 -- T_Flags : <token> & " =>"
531 -- T_Preelab .. T_Body : " " & <token>
533 procedure Output_Sdep (S : Sdep_Id);
534 procedure Output_Unit (U : Unit_Id);
535 procedure Output_With (W : With_Id);
536 -- Output this entry as a global section (like ALIs)
538 ------------------
539 -- Output_Afile --
540 ------------------
542 procedure Output_Afile (A : File_Name_Type) is
543 begin
544 if A /= No_File then
545 Output_Token (T_Afile);
546 Write_Name (A);
547 Write_Eol;
548 end if;
549 end Output_Afile;
551 ----------------
552 -- Output_ALI --
553 ----------------
555 procedure Output_ALI (A : ALI_Id) is
556 begin
557 Output_Token (T_ALI);
558 N_Indents := N_Indents + 1;
560 Output_Afile (ALIs.Table (A).Afile);
561 Output_Ofile (ALIs.Table (A).Ofile_Full_Name);
562 Output_Sfile (ALIs.Table (A).Sfile);
564 -- Output Main
566 if ALIs.Table (A).Main_Program /= None then
567 Output_Token (T_Main);
569 if ALIs.Table (A).Main_Program = Proc then
570 Output_Token (T_Procedure);
571 else
572 Output_Token (T_Function);
573 end if;
575 Write_Eol;
576 end if;
578 -- Output Units
580 for U in ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit loop
581 Output_Unit (U);
582 end loop;
584 -- Output Sdeps
586 for S in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
587 Output_Sdep (S);
588 end loop;
590 N_Indents := N_Indents - 1;
591 end Output_ALI;
593 -------------------
594 -- Output_No_ALI --
595 -------------------
597 procedure Output_No_ALI (Afile : File_Name_Type) is
598 begin
599 Output_Token (T_No_ALI);
600 N_Indents := N_Indents + 1;
601 Output_Afile (Afile);
602 N_Indents := N_Indents - 1;
603 end Output_No_ALI;
605 -----------------
606 -- Output_Name --
607 -----------------
609 procedure Output_Name (N : Name_Id) is
610 begin
611 -- Remove any encoding info (%s or %b)
613 Get_Name_String (N);
615 if Name_Len > 2
616 and then Name_Buffer (Name_Len - 1) = '%'
617 then
618 Name_Len := Name_Len - 2;
619 end if;
621 Output_Token (T_Name);
622 Write_Str (Name_Buffer (1 .. Name_Len));
623 Write_Eol;
624 end Output_Name;
626 ------------------
627 -- Output_Ofile --
628 ------------------
630 procedure Output_Ofile (O : File_Name_Type) is
631 begin
632 if O /= No_File then
633 Output_Token (T_Ofile);
634 Write_Name (O);
635 Write_Eol;
636 end if;
637 end Output_Ofile;
639 -----------------
640 -- Output_Sdep --
641 -----------------
643 procedure Output_Sdep (S : Sdep_Id) is
644 begin
645 Output_Token (T_Source);
646 Write_Name (Sdep.Table (S).Sfile);
647 Write_Eol;
648 end Output_Sdep;
650 ------------------
651 -- Output_Sfile --
652 ------------------
654 procedure Output_Sfile (S : File_Name_Type) is
655 FS : File_Name_Type := S;
657 begin
658 if FS /= No_File then
660 -- We want to output the full source name
662 FS := Full_Source_Name (FS);
664 -- There is no full source name. This occurs for instance when a
665 -- withed unit has a spec file but no body file. This situation is
666 -- not a problem for GNATDIST since the unit may be located on a
667 -- partition we do not want to build. However, we need to locate
668 -- the spec file and to find its full source name. Replace the
669 -- body file name with the spec file name used to compile the
670 -- current unit when possible.
672 if FS = No_File then
673 Get_Name_String (S);
675 if Name_Len > 4
676 and then Name_Buffer (Name_Len - 3 .. Name_Len) = ".adb"
677 then
678 Name_Buffer (Name_Len) := 's';
679 FS := Full_Source_Name (Name_Find);
680 end if;
681 end if;
682 end if;
684 if FS /= No_File then
685 Output_Token (T_Sfile);
686 Write_Name (FS);
687 Write_Eol;
688 end if;
689 end Output_Sfile;
691 ------------------
692 -- Output_Token --
693 ------------------
695 procedure Output_Token (T : Token_Type) is
696 begin
697 case T is
698 when T_No_ALI .. T_Flags =>
699 for J in 1 .. N_Indents loop
700 Write_Str (" ");
701 end loop;
703 Write_Str (Image (T).all);
705 for J in Image (T)'Length .. 12 loop
706 Write_Char (' ');
707 end loop;
709 Write_Str ("=>");
711 if T in T_No_ALI .. T_With then
712 Write_Eol;
713 elsif T in T_Source .. T_Name then
714 Write_Char (' ');
715 end if;
717 when T_Preelaborated .. T_Body =>
718 if T in T_Preelaborated .. T_Is_Generic then
719 if N_Flags = 0 then
720 Output_Token (T_Flags);
721 end if;
723 N_Flags := N_Flags + 1;
724 end if;
726 Write_Char (' ');
727 Write_Str (Image (T).all);
728 end case;
729 end Output_Token;
731 -----------------
732 -- Output_Unit --
733 -----------------
735 procedure Output_Unit (U : Unit_Id) is
736 begin
737 Output_Token (T_Unit);
738 N_Indents := N_Indents + 1;
740 -- Output Name
742 Output_Name (Name_Id (Units.Table (U).Uname));
744 -- Output Kind
746 Output_Token (T_Kind);
748 if Units.Table (U).Unit_Kind = 'p' then
749 Output_Token (T_Package);
750 else
751 Output_Token (T_Subprogram);
752 end if;
754 if Name_Buffer (Name_Len) = 's' then
755 Output_Token (T_Spec);
756 else
757 Output_Token (T_Body);
758 end if;
760 Write_Eol;
762 -- Output source file name
764 Output_Sfile (Units.Table (U).Sfile);
766 -- Output Flags
768 N_Flags := 0;
770 if Units.Table (U).Preelab then
771 Output_Token (T_Preelaborated);
772 end if;
774 if Units.Table (U).Pure then
775 Output_Token (T_Pure);
776 end if;
778 if Units.Table (U).Has_RACW then
779 Output_Token (T_Has_RACW);
780 end if;
782 if Units.Table (U).Remote_Types then
783 Output_Token (T_Remote_Types);
784 end if;
786 if Units.Table (U).Shared_Passive then
787 Output_Token (T_Shared_Passive);
788 end if;
790 if Units.Table (U).RCI then
791 Output_Token (T_RCI);
792 end if;
794 if Units.Table (U).Predefined then
795 Output_Token (T_Predefined);
796 end if;
798 if Units.Table (U).Internal then
799 Output_Token (T_Internal);
800 end if;
802 if Units.Table (U).Is_Generic then
803 Output_Token (T_Is_Generic);
804 end if;
806 if N_Flags > 0 then
807 Write_Eol;
808 end if;
810 -- Output Withs
812 for W in Units.Table (U).First_With .. Units.Table (U).Last_With loop
813 Output_With (W);
814 end loop;
816 N_Indents := N_Indents - 1;
817 end Output_Unit;
819 -----------------
820 -- Output_With --
821 -----------------
823 procedure Output_With (W : With_Id) is
824 begin
825 Output_Token (T_With);
826 N_Indents := N_Indents + 1;
828 Output_Name (Name_Id (Withs.Table (W).Uname));
830 -- Output Kind
832 Output_Token (T_Kind);
834 if Name_Buffer (Name_Len) = 's' then
835 Output_Token (T_Spec);
836 else
837 Output_Token (T_Body);
838 end if;
840 Write_Eol;
842 Output_Afile (Withs.Table (W).Afile);
843 Output_Sfile (Withs.Table (W).Sfile);
845 N_Indents := N_Indents - 1;
846 end Output_With;
848 end GNATDIST;
850 -----------
851 -- Image --
852 -----------
854 function Image (Restriction : Restriction_Id) return String is
855 Result : String := Restriction'Img;
856 Skip : Boolean := True;
858 begin
859 for J in Result'Range loop
860 if Skip then
861 Skip := False;
862 Result (J) := To_Upper (Result (J));
864 elsif Result (J) = '_' then
865 Skip := True;
867 else
868 Result (J) := To_Lower (Result (J));
869 end if;
870 end loop;
872 return Result;
873 end Image;
875 ---------------
876 -- Normalize --
877 ---------------
879 function Normalize (Path : String) return String is
880 begin
881 return Normalize_Pathname (Path);
882 end Normalize;
884 --------------------------------
885 -- Output_License_Information --
886 --------------------------------
888 procedure Output_License_Information is
889 begin
890 case Build_Type is
891 when others =>
892 Write_Str ("Please refer to file COPYING in your distribution"
893 & " for license terms.");
894 Write_Eol;
895 end case;
896 end Output_License_Information;
898 -------------------
899 -- Output_Object --
900 -------------------
902 procedure Output_Object (O : File_Name_Type) is
903 Object_Name : String_Access;
905 begin
906 if Print_Object then
907 if O /= No_File then
908 Get_Name_String (O);
909 Object_Name := To_Host_File_Spec (Name_Buffer (1 .. Name_Len));
910 else
911 Object_Name := No_Obj'Unchecked_Access;
912 end if;
914 Write_Str (Object_Name.all);
916 if Print_Source or else Print_Unit then
917 if Too_Long then
918 Write_Eol;
919 Write_Str (" ");
920 else
921 Write_Str (Spaces
922 (Object_Start + Object_Name'Length .. Object_End));
923 end if;
924 end if;
925 end if;
926 end Output_Object;
928 -------------------
929 -- Output_Source --
930 -------------------
932 procedure Output_Source (Sdep_I : Sdep_Id) is
933 Stamp : Time_Stamp_Type;
934 Checksum : Word;
935 FS : File_Name_Type;
936 Status : File_Status;
937 Object_Name : String_Access;
939 begin
940 if Sdep_I = No_Sdep_Id then
941 return;
942 end if;
944 Stamp := Sdep.Table (Sdep_I).Stamp;
945 Checksum := Sdep.Table (Sdep_I).Checksum;
946 FS := Sdep.Table (Sdep_I).Sfile;
948 if Print_Source then
949 Find_Status (FS, Stamp, Checksum, Status);
950 Get_Name_String (FS);
952 Object_Name := To_Host_File_Spec (Name_Buffer (1 .. Name_Len));
954 if Verbose_Mode then
955 Write_Str (" Source => ");
956 Write_Str (Object_Name.all);
958 if not Too_Long then
959 Write_Str
960 (Spaces (Source_Start + Object_Name'Length .. Source_End));
961 end if;
963 Output_Status (Status, Verbose => True);
964 Write_Eol;
965 Write_Str (" ");
967 else
968 if not Selective_Output then
969 Output_Status (Status, Verbose => False);
970 end if;
972 Write_Str (Object_Name.all);
973 end if;
974 end if;
975 end Output_Source;
977 -------------------
978 -- Output_Status --
979 -------------------
981 procedure Output_Status (FS : File_Status; Verbose : Boolean) is
982 begin
983 if Verbose then
984 case FS is
985 when OK =>
986 Write_Str (" unchanged");
988 when Checksum_OK =>
989 Write_Str (" slightly modified");
991 when Not_Found =>
992 Write_Str (" file not found");
994 when Not_Same =>
995 Write_Str (" modified");
997 when Not_First_On_PATH =>
998 Write_Str (" unchanged version not first on PATH");
999 end case;
1001 else
1002 case FS is
1003 when OK =>
1004 Write_Str (" OK ");
1006 when Checksum_OK =>
1007 Write_Str (" MOK ");
1009 when Not_Found =>
1010 Write_Str (" ??? ");
1012 when Not_Same =>
1013 Write_Str (" DIF ");
1015 when Not_First_On_PATH =>
1016 Write_Str (" HID ");
1017 end case;
1018 end if;
1019 end Output_Status;
1021 -----------------
1022 -- Output_Unit --
1023 -----------------
1025 procedure Output_Unit (ALI : ALI_Id; U_Id : Unit_Id) is
1026 Kind : Character;
1027 U : Unit_Record renames Units.Table (U_Id);
1029 begin
1030 if Print_Unit then
1031 Get_Name_String (U.Uname);
1032 Kind := Name_Buffer (Name_Len);
1033 Name_Len := Name_Len - 2;
1035 if not Verbose_Mode then
1036 Write_Str (Name_Buffer (1 .. Name_Len));
1038 else
1039 Write_Str ("Unit => ");
1040 Write_Eol;
1041 Write_Str (" Name => ");
1042 Write_Str (Name_Buffer (1 .. Name_Len));
1043 Write_Eol;
1044 Write_Str (" Kind => ");
1046 if Units.Table (U_Id).Unit_Kind = 'p' then
1047 Write_Str ("package ");
1048 else
1049 Write_Str ("subprogram ");
1050 end if;
1052 if Kind = 's' then
1053 Write_Str ("spec");
1054 else
1055 Write_Str ("body");
1056 end if;
1057 end if;
1059 if Verbose_Mode then
1060 if U.Preelab or else
1061 U.No_Elab or else
1062 U.Pure or else
1063 U.Dynamic_Elab or else
1064 U.Has_RACW or else
1065 U.Remote_Types or else
1066 U.Shared_Passive or else
1067 U.RCI or else
1068 U.Predefined or else
1069 U.Internal or else
1070 U.Is_Generic or else
1071 U.Init_Scalars or else
1072 U.SAL_Interface or else
1073 U.Body_Needed_For_SAL or else
1074 U.Elaborate_Body
1075 then
1076 Write_Eol;
1077 Write_Str (" Flags =>");
1079 if U.Preelab then
1080 Write_Str (" Preelaborable");
1081 end if;
1083 if U.No_Elab then
1084 Write_Str (" No_Elab_Code");
1085 end if;
1087 if U.Pure then
1088 Write_Str (" Pure");
1089 end if;
1091 if U.Dynamic_Elab then
1092 Write_Str (" Dynamic_Elab");
1093 end if;
1095 if U.Has_RACW then
1096 Write_Str (" Has_RACW");
1097 end if;
1099 if U.Remote_Types then
1100 Write_Str (" Remote_Types");
1101 end if;
1103 if U.Shared_Passive then
1104 Write_Str (" Shared_Passive");
1105 end if;
1107 if U.RCI then
1108 Write_Str (" RCI");
1109 end if;
1111 if U.Predefined then
1112 Write_Str (" Predefined");
1113 end if;
1115 if U.Internal then
1116 Write_Str (" Internal");
1117 end if;
1119 if U.Is_Generic then
1120 Write_Str (" Is_Generic");
1121 end if;
1123 if U.Init_Scalars then
1124 Write_Str (" Init_Scalars");
1125 end if;
1127 if U.SAL_Interface then
1128 Write_Str (" SAL_Interface");
1129 end if;
1131 if U.Body_Needed_For_SAL then
1132 Write_Str (" Body_Needed_For_SAL");
1133 end if;
1135 if U.Elaborate_Body then
1136 Write_Str (" Elaborate Body");
1137 end if;
1139 if U.Remote_Types then
1140 Write_Str (" Remote_Types");
1141 end if;
1143 if U.Shared_Passive then
1144 Write_Str (" Shared_Passive");
1145 end if;
1147 if U.Predefined then
1148 Write_Str (" Predefined");
1149 end if;
1150 end if;
1152 declare
1153 Restrictions : constant Restrictions_Info :=
1154 ALIs.Table (ALI).Restrictions;
1156 begin
1157 -- If the source was compiled with pragmas Restrictions,
1158 -- Display these restrictions.
1160 if Restrictions.Set /= (All_Restrictions => False) then
1161 Write_Eol;
1162 Write_Str (" pragma Restrictions =>");
1164 -- For boolean restrictions, just display the name of the
1165 -- restriction; for valued restrictions, also display the
1166 -- restriction value.
1168 for Restriction in All_Restrictions loop
1169 if Restrictions.Set (Restriction) then
1170 Write_Eol;
1171 Write_Str (" ");
1172 Write_Str (Image (Restriction));
1174 if Restriction in All_Parameter_Restrictions then
1175 Write_Str (" =>");
1176 Write_Str (Restrictions.Value (Restriction)'Img);
1177 end if;
1178 end if;
1179 end loop;
1180 end if;
1182 -- If the unit violates some Restrictions, display the list of
1183 -- these restrictions.
1185 if Restrictions.Violated /= (All_Restrictions => False) then
1186 Write_Eol;
1187 Write_Str (" Restrictions violated =>");
1189 -- For boolean restrictions, just display the name of the
1190 -- restriction. For valued restrictions, also display the
1191 -- restriction value.
1193 for Restriction in All_Restrictions loop
1194 if Restrictions.Violated (Restriction) then
1195 Write_Eol;
1196 Write_Str (" ");
1197 Write_Str (Image (Restriction));
1199 if Restriction in All_Parameter_Restrictions then
1200 if Restrictions.Count (Restriction) > 0 then
1201 Write_Str (" =>");
1203 if Restrictions.Unknown (Restriction) then
1204 Write_Str (" at least");
1205 end if;
1207 Write_Str (Restrictions.Count (Restriction)'Img);
1208 end if;
1209 end if;
1210 end if;
1211 end loop;
1212 end if;
1213 end;
1214 end if;
1216 if Print_Source then
1217 if Too_Long then
1218 Write_Eol;
1219 Write_Str (" ");
1220 else
1221 Write_Str (Spaces (Unit_Start + Name_Len + 1 .. Unit_End));
1222 end if;
1223 end if;
1224 end if;
1225 end Output_Unit;
1227 package body Prj_Env is
1229 Uninitialized_Prefix : constant String := '#' & Path_Separator;
1230 -- Prefix to indicate that the project path has not been initialized
1231 -- yet. Must be two characters long.
1233 ---------------------
1234 -- Add_Directories --
1235 ---------------------
1237 procedure Add_Directories
1238 (Self : in out String_Access;
1239 Path : String)
1241 Tmp : String_Access;
1243 begin
1244 if Self = null then
1245 Self := new String'(Uninitialized_Prefix & Path);
1246 else
1247 Tmp := Self;
1248 Self := new String'(Tmp.all & Path_Separator & Path);
1249 Free (Tmp);
1250 end if;
1251 end Add_Directories;
1253 -------------------------------------
1254 -- Initialize_Default_Project_Path --
1255 -------------------------------------
1257 procedure Initialize_Default_Project_Path
1258 (Self : in out String_Access;
1259 Target_Name : String;
1260 Runtime_Name : String := "")
1262 Add_Default_Dir : Boolean := Target_Name /= "-";
1263 First : Positive;
1264 Last : Positive;
1266 Ada_Project_Path : constant String := "ADA_PROJECT_PATH";
1267 Gpr_Project_Path : constant String := "GPR_PROJECT_PATH";
1268 Gpr_Project_Path_File : constant String := "GPR_PROJECT_PATH_FILE";
1269 -- Names of alternate env. variables that contain path name(s) of
1270 -- directories where project files may reside. They are taken into
1271 -- account in this order: GPR_PROJECT_PATH_FILE, GPR_PROJECT_PATH,
1272 -- ADA_PROJECT_PATH.
1274 Gpr_Prj_Path_File : String_Access;
1275 Gpr_Prj_Path : String_Access;
1276 Ada_Prj_Path : String_Access;
1277 -- The path name(s) of directories where project files may reside.
1278 -- May be empty.
1280 Prefix : String_Ptr;
1281 Runtime : String_Ptr;
1283 procedure Add_Target (Suffix : String);
1284 -- Add :<prefix>/<target>/Suffix to the project path
1286 FD : File_Descriptor;
1287 Len : Integer;
1289 ----------------
1290 -- Add_Target --
1291 ----------------
1293 procedure Add_Target (Suffix : String) is
1294 Extra_Sep : constant String :=
1295 (if Target_Name (Target_Name'Last) = '/' then
1297 else
1298 (1 => Directory_Separator));
1299 -- Note: Target_Name has a trailing / when it comes from Sdefault
1301 begin
1302 Add_Str_To_Name_Buffer
1303 (Path_Separator & Prefix.all & Target_Name & Extra_Sep & Suffix);
1304 end Add_Target;
1306 -- Start of processing for Initialize_Default_Project_Path
1308 begin
1309 if Self /= null
1310 and then (Self'Length = 0
1311 or else Self (Self'First) /= '#')
1312 then
1313 return;
1314 end if;
1316 -- The current directory is always first in the search path. Since
1317 -- the Project_Path currently starts with '#:' as a sign that it is
1318 -- not initialized, we simply replace '#' with '.'
1320 if Self = null then
1321 Self := new String'('.' & Path_Separator);
1322 else
1323 Self (Self'First) := '.';
1324 end if;
1326 -- Then the reset of the project path (if any) currently contains the
1327 -- directories added through Add_Search_Project_Directory
1329 -- If environment variables are defined and not empty, add their
1330 -- content
1332 Gpr_Prj_Path_File := Getenv (Gpr_Project_Path_File);
1333 Gpr_Prj_Path := Getenv (Gpr_Project_Path);
1334 Ada_Prj_Path := Getenv (Ada_Project_Path);
1336 if Gpr_Prj_Path_File.all /= "" then
1337 FD := Open_Read (Gpr_Prj_Path_File.all, GNAT.OS_Lib.Text);
1339 if FD /= Invalid_FD then
1340 Len := Integer (File_Length (FD));
1342 declare
1343 Buffer : String (1 .. Len);
1344 Index : Positive := 1;
1345 Last : Positive;
1346 Tmp : String_Access;
1348 begin
1349 -- Read the file
1351 Len := Read (FD, Buffer (1)'Address, Len);
1352 Close (FD);
1354 -- Scan the file line by line
1356 while Index < Buffer'Last loop
1358 -- Find the end of line
1360 Last := Index;
1361 while Last <= Buffer'Last
1362 and then Buffer (Last) /= ASCII.LF
1363 and then Buffer (Last) /= ASCII.CR
1364 loop
1365 Last := Last + 1;
1366 end loop;
1368 -- Ignore empty lines
1370 if Last > Index then
1371 Tmp := Self;
1372 Self :=
1373 new String'
1374 (Tmp.all & Path_Separator &
1375 Buffer (Index .. Last - 1));
1376 Free (Tmp);
1377 end if;
1379 -- Find the beginning of the next line
1381 Index := Last;
1382 while Buffer (Index) = ASCII.CR or else
1383 Buffer (Index) = ASCII.LF
1384 loop
1385 Index := Index + 1;
1386 end loop;
1387 end loop;
1388 end;
1389 end if;
1391 end if;
1393 if Gpr_Prj_Path.all /= "" then
1394 Add_Directories (Self, Gpr_Prj_Path.all);
1395 end if;
1397 Free (Gpr_Prj_Path);
1399 if Ada_Prj_Path.all /= "" then
1400 Add_Directories (Self, Ada_Prj_Path.all);
1401 end if;
1403 Free (Ada_Prj_Path);
1405 -- Copy to Name_Buffer, since we will need to manipulate the path
1407 Name_Len := Self'Length;
1408 Name_Buffer (1 .. Name_Len) := Self.all;
1410 -- Scan the directory path to see if "-" is one of the directories.
1411 -- Remove each occurrence of "-" and set Add_Default_Dir to False.
1412 -- Also resolve relative paths and symbolic links.
1414 First := 3;
1415 loop
1416 while First <= Name_Len
1417 and then Name_Buffer (First) = Path_Separator
1418 loop
1419 First := First + 1;
1420 end loop;
1422 exit when First > Name_Len;
1424 Last := First;
1426 while Last < Name_Len
1427 and then Name_Buffer (Last + 1) /= Path_Separator
1428 loop
1429 Last := Last + 1;
1430 end loop;
1432 -- If the directory is "-", set Add_Default_Dir to False and
1433 -- remove from path.
1435 if Name_Buffer (First .. Last) = "-" then
1436 Add_Default_Dir := False;
1438 for J in Last + 1 .. Name_Len loop
1439 Name_Buffer (J - 2) := Name_Buffer (J);
1440 end loop;
1442 Name_Len := Name_Len - 2;
1444 -- After removing the '-', go back one character to get the
1445 -- next directory correctly.
1447 Last := Last - 1;
1449 else
1450 declare
1451 New_Dir : constant String :=
1452 Normalize_Pathname
1453 (Name_Buffer (First .. Last),
1454 Resolve_Links => Opt.Follow_Links_For_Dirs);
1455 New_Len : Positive;
1456 New_Last : Positive;
1458 begin
1459 -- If the absolute path was resolved and is different from
1460 -- the original, replace original with the resolved path.
1462 if New_Dir /= Name_Buffer (First .. Last)
1463 and then New_Dir'Length /= 0
1464 then
1465 New_Len := Name_Len + New_Dir'Length - (Last - First + 1);
1466 New_Last := First + New_Dir'Length - 1;
1467 Name_Buffer (New_Last + 1 .. New_Len) :=
1468 Name_Buffer (Last + 1 .. Name_Len);
1469 Name_Buffer (First .. New_Last) := New_Dir;
1470 Name_Len := New_Len;
1471 Last := New_Last;
1472 end if;
1473 end;
1474 end if;
1476 First := Last + 1;
1477 end loop;
1479 Free (Self);
1481 -- Set the initial value of Current_Project_Path
1483 if Add_Default_Dir then
1484 if Sdefault.Search_Dir_Prefix = null then
1486 -- gprbuild case
1488 Prefix := new String'(Executable_Prefix_Path);
1490 else
1491 Prefix := new String'(Sdefault.Search_Dir_Prefix.all
1492 & ".." & Dir_Separator
1493 & ".." & Dir_Separator
1494 & ".." & Dir_Separator
1495 & ".." & Dir_Separator);
1496 end if;
1498 if Prefix.all /= "" then
1499 if Target_Name /= "" then
1501 if Runtime_Name /= "" then
1502 if Base_Name (Runtime_Name) = Runtime_Name then
1504 -- $prefix/$target/$runtime/lib/gnat
1506 Add_Target
1507 (Runtime_Name & Directory_Separator &
1508 "lib" & Directory_Separator & "gnat");
1510 -- $prefix/$target/$runtime/share/gpr
1512 Add_Target
1513 (Runtime_Name & Directory_Separator &
1514 "share" & Directory_Separator & "gpr");
1516 else
1517 Runtime :=
1518 new String'(Normalize_Pathname (Runtime_Name));
1520 -- $runtime_dir/lib/gnat
1522 Add_Str_To_Name_Buffer
1523 (Path_Separator & Runtime.all & Directory_Separator &
1524 "lib" & Directory_Separator & "gnat");
1526 -- $runtime_dir/share/gpr
1528 Add_Str_To_Name_Buffer
1529 (Path_Separator & Runtime.all & Directory_Separator &
1530 "share" & Directory_Separator & "gpr");
1531 end if;
1532 end if;
1534 -- $prefix/$target/lib/gnat
1536 Add_Target
1537 ("lib" & Directory_Separator & "gnat");
1539 -- $prefix/$target/share/gpr
1541 Add_Target
1542 ("share" & Directory_Separator & "gpr");
1543 end if;
1545 -- $prefix/share/gpr
1547 Add_Str_To_Name_Buffer
1548 (Path_Separator & Prefix.all & "share"
1549 & Directory_Separator & "gpr");
1551 -- $prefix/lib/gnat
1553 Add_Str_To_Name_Buffer
1554 (Path_Separator & Prefix.all & "lib"
1555 & Directory_Separator & "gnat");
1556 end if;
1558 Free (Prefix);
1559 end if;
1561 Self := new String'(Name_Buffer (1 .. Name_Len));
1562 end Initialize_Default_Project_Path;
1564 -----------------------
1565 -- Get_Runtime_Path --
1566 -----------------------
1568 function Get_Runtime_Path
1569 (Self : String_Access;
1570 Path : String) return String_Access
1572 First : Natural;
1573 Last : Natural;
1575 begin
1577 if Is_Absolute_Path (Path) then
1578 if Is_Directory (Path) then
1579 return new String'(Path);
1580 else
1581 return null;
1582 end if;
1584 else
1585 -- Because we do not want to resolve symbolic links, we cannot
1586 -- use Locate_Regular_File. Instead we try each possible path
1587 -- successively.
1589 First := Self'First;
1590 while First <= Self'Last loop
1591 while First <= Self'Last
1592 and then Self (First) = Path_Separator
1593 loop
1594 First := First + 1;
1595 end loop;
1597 exit when First > Self'Last;
1599 Last := First;
1600 while Last < Self'Last
1601 and then Self (Last + 1) /= Path_Separator
1602 loop
1603 Last := Last + 1;
1604 end loop;
1606 Name_Len := 0;
1608 if not Is_Absolute_Path (Self (First .. Last)) then
1609 Add_Str_To_Name_Buffer (Get_Current_Dir); -- ??? System call
1610 Add_Char_To_Name_Buffer (Directory_Separator);
1611 end if;
1613 Add_Str_To_Name_Buffer (Self (First .. Last));
1614 Add_Char_To_Name_Buffer (Directory_Separator);
1615 Add_Str_To_Name_Buffer (Path);
1617 if Is_Directory (Name_Buffer (1 .. Name_Len)) then
1618 return new String'(Name_Buffer (1 .. Name_Len));
1619 end if;
1621 First := Last + 1;
1622 end loop;
1623 end if;
1625 return null;
1626 end Get_Runtime_Path;
1628 end Prj_Env;
1630 -----------------
1631 -- Reset_Print --
1632 -----------------
1634 procedure Reset_Print is
1635 begin
1636 if not Selective_Output then
1637 Selective_Output := True;
1638 Print_Source := False;
1639 Print_Object := False;
1640 Print_Unit := False;
1641 end if;
1642 end Reset_Print;
1644 ----------------
1645 -- Search_RTS --
1646 ----------------
1648 procedure Search_RTS (Name : String) is
1649 Src_Path : String_Ptr;
1650 Lib_Path : String_Ptr;
1651 -- Paths for source and include subdirs
1653 Rts_Full_Path : String_Access;
1654 -- Full path for RTS project
1656 begin
1657 -- Try to find the RTS
1659 Src_Path := Get_RTS_Search_Dir (Name, Include);
1660 Lib_Path := Get_RTS_Search_Dir (Name, Objects);
1662 -- For non-project RTS, both the include and the objects directories
1663 -- must be present.
1665 if Src_Path /= null and then Lib_Path /= null then
1666 Add_Search_Dirs (Src_Path, Include);
1667 Add_Search_Dirs (Lib_Path, Objects);
1668 Prj_Env.Initialize_Default_Project_Path
1669 (Prj_Path,
1670 Target_Name => Sdefault.Target_Name.all,
1671 Runtime_Name => Name);
1672 return;
1673 end if;
1675 if Lib_Path /= null then
1676 Osint.Fail
1677 ("RTS path """ & Name
1678 & """ not valid: missing adainclude directory");
1679 elsif Src_Path /= null then
1680 Osint.Fail
1681 ("RTS path """ & Name
1682 & """ not valid: missing adalib directory");
1683 end if;
1685 -- Try to find the RTS on the project path. First setup the project path
1687 Prj_Env.Initialize_Default_Project_Path
1688 (Prj_Path,
1689 Target_Name => Sdefault.Target_Name.all,
1690 Runtime_Name => Name);
1692 Rts_Full_Path := Prj_Env.Get_Runtime_Path (Prj_Path, Name);
1694 if Rts_Full_Path /= null then
1696 -- Directory name was found on the project path. Look for the
1697 -- include subdirectory(s).
1699 Src_Path := Get_RTS_Search_Dir (Rts_Full_Path.all, Include);
1701 if Src_Path /= null then
1702 Add_Search_Dirs (Src_Path, Include);
1704 -- Add the lib subdirectory if it exists
1706 Lib_Path := Get_RTS_Search_Dir (Rts_Full_Path.all, Objects);
1708 if Lib_Path /= null then
1709 Add_Search_Dirs (Lib_Path, Objects);
1710 end if;
1712 return;
1713 end if;
1714 end if;
1716 Osint.Fail
1717 ("RTS path """ & Name
1718 & """ not valid: missing adainclude and adalib directories");
1719 end Search_RTS;
1721 -------------------
1722 -- Scan_Ls_Arg --
1723 -------------------
1725 procedure Scan_Ls_Arg (Argv : String) is
1726 FD : File_Descriptor;
1727 Len : Integer;
1728 OK : Boolean;
1730 begin
1731 pragma Assert (Argv'First = 1);
1733 if Argv'Length = 0 then
1734 return;
1735 end if;
1737 OK := True;
1738 if Argv (1) = '-' then
1739 if Argv'Length = 1 then
1740 Fail ("switch character cannot be followed by a blank");
1742 -- Processing for -I-
1744 elsif Argv (2 .. Argv'Last) = "I-" then
1745 Opt.Look_In_Primary_Dir := False;
1747 -- Forbid -?- or -??- where ? is any character
1749 elsif (Argv'Length = 3 and then Argv (3) = '-')
1750 or else (Argv'Length = 4 and then Argv (4) = '-')
1751 then
1752 Fail ("Trailing ""-"" at the end of " & Argv & " forbidden.");
1754 -- Processing for -Idir
1756 elsif Argv (2) = 'I' then
1757 Add_Source_Dir (Argv (3 .. Argv'Last));
1758 Add_Lib_Dir (Argv (3 .. Argv'Last));
1760 -- Processing for -aIdir (to gcc this is like a -I switch)
1762 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
1763 Add_Source_Dir (Argv (4 .. Argv'Last));
1765 -- Processing for -aOdir
1767 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
1768 Add_Lib_Dir (Argv (4 .. Argv'Last));
1770 -- Processing for -aLdir (to gnatbind this is like a -aO switch)
1772 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
1773 Add_Lib_Dir (Argv (4 .. Argv'Last));
1775 -- Processing for -aP<dir>
1777 elsif Argv'Length > 3 and then Argv (1 .. 3) = "-aP" then
1778 Prj_Env.Add_Directories (Prj_Path, Argv (4 .. Argv'Last));
1780 -- Processing for -nostdinc
1782 elsif Argv (2 .. Argv'Last) = "nostdinc" then
1783 Opt.No_Stdinc := True;
1785 -- Processing for one character switches
1787 elsif Argv'Length = 2 then
1788 case Argv (2) is
1789 when 'a' => Also_Predef := True;
1790 when 'h' => Print_Usage := True;
1791 when 'u' => Reset_Print; Print_Unit := True;
1792 when 's' => Reset_Print; Print_Source := True;
1793 when 'o' => Reset_Print; Print_Object := True;
1794 when 'v' => Verbose_Mode := True;
1795 when 'd' => Dependable := True;
1796 when 'l' => License := True;
1797 when 'V' => Very_Verbose_Mode := True;
1799 when others => OK := False;
1800 end case;
1802 -- Processing for -files=file
1804 elsif Argv'Length > 7 and then Argv (1 .. 7) = "-files=" then
1805 FD := Open_Read (Argv (8 .. Argv'Last), GNAT.OS_Lib.Text);
1807 if FD = Invalid_FD then
1808 Osint.Fail ("could not find text file """ &
1809 Argv (8 .. Argv'Last) & '"');
1810 end if;
1812 Len := Integer (File_Length (FD));
1814 declare
1815 Buffer : String (1 .. Len + 1);
1816 Index : Positive := 1;
1817 Last : Positive;
1819 begin
1820 -- Read the file
1822 Len := Read (FD, Buffer (1)'Address, Len);
1823 Buffer (Buffer'Last) := ASCII.NUL;
1824 Close (FD);
1826 -- Scan the file line by line
1828 while Index < Buffer'Last loop
1830 -- Find the end of line
1832 Last := Index;
1833 while Last <= Buffer'Last
1834 and then Buffer (Last) /= ASCII.LF
1835 and then Buffer (Last) /= ASCII.CR
1836 loop
1837 Last := Last + 1;
1838 end loop;
1840 -- Ignore empty lines
1842 if Last > Index then
1843 Add_File (Buffer (Index .. Last - 1));
1844 end if;
1846 -- Find the beginning of the next line
1848 Index := Last;
1849 while Buffer (Index) = ASCII.CR or else
1850 Buffer (Index) = ASCII.LF
1851 loop
1852 Index := Index + 1;
1853 end loop;
1854 end loop;
1855 end;
1857 -- Processing for --RTS=path
1859 elsif Argv'Length >= 5 and then Argv (1 .. 5) = "--RTS" then
1860 if Argv'Length <= 6 or else Argv (6) /= '='then
1861 Osint.Fail ("missing path for --RTS");
1863 else
1864 -- Check that it is the first time we see this switch or, if
1865 -- it is not the first time, the same path is specified.
1867 if RTS_Specified = null then
1868 RTS_Specified := new String'(Argv (7 .. Argv'Last));
1870 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
1871 Osint.Fail ("--RTS cannot be specified multiple times");
1872 end if;
1874 -- Valid --RTS switch
1876 Opt.No_Stdinc := True;
1877 Opt.RTS_Switch := True;
1878 end if;
1880 else
1881 OK := False;
1882 end if;
1884 -- If not a switch, it must be a file name
1886 else
1887 Add_File (Argv);
1888 end if;
1890 if not OK then
1891 Write_Str ("warning: unknown switch """);
1892 Write_Str (Argv);
1893 Write_Line ("""");
1894 end if;
1896 end Scan_Ls_Arg;
1898 -----------
1899 -- Usage --
1900 -----------
1902 procedure Usage is
1903 begin
1904 -- Usage line
1906 Write_Str ("Usage: ");
1907 Osint.Write_Program_Name;
1908 Write_Str (" switches [list of object files]");
1909 Write_Eol;
1910 Write_Eol;
1912 -- GNATLS switches
1914 Write_Str ("switches:");
1915 Write_Eol;
1917 Display_Usage_Version_And_Help;
1919 -- Line for -a
1921 Write_Str (" -a also output relevant predefined units");
1922 Write_Eol;
1924 -- Line for -u
1926 Write_Str (" -u output only relevant unit names");
1927 Write_Eol;
1929 -- Line for -h
1931 Write_Str (" -h output this help message");
1932 Write_Eol;
1934 -- Line for -s
1936 Write_Str (" -s output only relevant source names");
1937 Write_Eol;
1939 -- Line for -o
1941 Write_Str (" -o output only relevant object names");
1942 Write_Eol;
1944 -- Line for -d
1946 Write_Str (" -d output sources on which specified units " &
1947 "depend");
1948 Write_Eol;
1950 -- Line for -l
1952 Write_Str (" -l output license information");
1953 Write_Eol;
1955 -- Line for -v
1957 Write_Str (" -v verbose output, full path and unit " &
1958 "information");
1959 Write_Eol;
1960 Write_Eol;
1962 -- Line for -files=
1964 Write_Str (" -files=fil files are listed in text file 'fil'");
1965 Write_Eol;
1967 -- Line for -aI switch
1969 Write_Str (" -aIdir specify source files search path");
1970 Write_Eol;
1972 -- Line for -aO switch
1974 Write_Str (" -aOdir specify object files search path");
1975 Write_Eol;
1977 -- Line for -aP switch
1979 Write_Str (" -aPdir specify project search path");
1980 Write_Eol;
1982 -- Line for -I switch
1984 Write_Str (" -Idir like -aIdir -aOdir");
1985 Write_Eol;
1987 -- Line for -I- switch
1989 Write_Str (" -I- do not look for sources & object files");
1990 Write_Str (" in the default directory");
1991 Write_Eol;
1993 -- Line for -nostdinc
1995 Write_Str (" -nostdinc do not look for source files");
1996 Write_Str (" in the system default directory");
1997 Write_Eol;
1999 -- Line for --RTS
2001 Write_Str (" --RTS=dir specify the default source and object search"
2002 & " path");
2003 Write_Eol;
2005 -- File Status explanation
2007 Write_Eol;
2008 Write_Str (" file status can be:");
2009 Write_Eol;
2011 for ST in File_Status loop
2012 Write_Str (" ");
2013 Output_Status (ST, Verbose => False);
2014 Write_Str (" ==> ");
2015 Output_Status (ST, Verbose => True);
2016 Write_Eol;
2017 end loop;
2018 end Usage;
2020 procedure Check_Version_And_Help is new Check_Version_And_Help_G (Usage);
2022 -- Start of processing for Gnatls
2024 begin
2025 -- Initialize standard packages
2027 Csets.Initialize;
2028 Uintp.Initialize;
2029 Snames.Initialize;
2030 Stringt.Initialize;
2032 -- First check for --version or --help
2034 Check_Version_And_Help ("GNATLS", "1992");
2036 -- Loop to scan out arguments
2038 Next_Arg := 1;
2039 Scan_Args : while Next_Arg < Arg_Count loop
2040 declare
2041 Next_Argv : String (1 .. Len_Arg (Next_Arg));
2042 begin
2043 Fill_Arg (Next_Argv'Address, Next_Arg);
2044 Scan_Ls_Arg (Next_Argv);
2045 end;
2047 Next_Arg := Next_Arg + 1;
2048 end loop Scan_Args;
2050 -- If -l (output license information) is given, it must be the only switch
2052 if License then
2053 if Arg_Count = 2 then
2054 Output_License_Information;
2056 else
2057 Set_Standard_Error;
2058 Write_Str ("Can't use -l with another switch");
2059 Write_Eol;
2060 Try_Help;
2061 Exit_Program (E_Fatal);
2062 end if;
2063 end if;
2065 -- Handle --RTS switch
2067 if RTS_Specified /= null then
2068 Search_RTS (RTS_Specified.all);
2069 end if;
2071 -- Add the source and object directories specified on the command line, if
2072 -- any, to the searched directories.
2074 while First_Source_Dir /= null loop
2075 Add_Src_Search_Dir (First_Source_Dir.Value.all);
2076 First_Source_Dir := First_Source_Dir.Next;
2077 end loop;
2079 while First_Lib_Dir /= null loop
2080 Add_Lib_Search_Dir (First_Lib_Dir.Value.all);
2081 First_Lib_Dir := First_Lib_Dir.Next;
2082 end loop;
2084 -- Finally, add the default directories
2086 Osint.Add_Default_Search_Dirs;
2088 -- If --RTS= is not specified, check if there is a default runtime
2090 if RTS_Specified = null then
2091 declare
2092 FD : File_Descriptor;
2093 Text : Source_Buffer_Ptr;
2094 Hi : Source_Ptr;
2096 begin
2097 Read_Source_File (Name_Find ("system.ads"), 0, Hi, Text, FD);
2099 if Null_Source_Buffer_Ptr (Text) then
2100 No_Runtime := True;
2101 end if;
2102 end;
2103 end if;
2105 if Verbose_Mode then
2106 Write_Eol;
2107 Display_Version ("GNATLS", "1997");
2108 Write_Eol;
2110 if No_Runtime then
2111 Write_Str
2112 ("Default runtime not available. Use --RTS= with a valid runtime");
2113 Write_Eol;
2114 Write_Eol;
2115 Exit_Status := E_Warnings;
2116 end if;
2118 Write_Str ("Source Search Path:");
2119 Write_Eol;
2121 for J in 1 .. Nb_Dir_In_Src_Search_Path loop
2122 Write_Str (" ");
2124 if Dir_In_Src_Search_Path (J)'Length = 0 then
2125 Write_Str ("<Current_Directory>");
2126 Write_Eol;
2128 elsif not No_Runtime then
2129 Write_Str
2130 (Normalize
2131 (To_Host_Dir_Spec
2132 (Dir_In_Src_Search_Path (J).all, True).all));
2133 Write_Eol;
2134 end if;
2135 end loop;
2137 Write_Eol;
2138 Write_Eol;
2139 Write_Str ("Object Search Path:");
2140 Write_Eol;
2142 for J in 1 .. Nb_Dir_In_Obj_Search_Path loop
2143 Write_Str (" ");
2145 if Dir_In_Obj_Search_Path (J)'Length = 0 then
2146 Write_Str ("<Current_Directory>");
2147 Write_Eol;
2149 elsif not No_Runtime then
2150 Write_Str
2151 (Normalize
2152 (To_Host_Dir_Spec
2153 (Dir_In_Obj_Search_Path (J).all, True).all));
2154 Write_Eol;
2155 end if;
2156 end loop;
2158 Write_Eol;
2159 Write_Eol;
2160 Write_Str (Project_Search_Path);
2161 Write_Eol;
2162 Write_Str (" <Current_Directory>");
2163 Write_Eol;
2165 Prj_Env.Initialize_Default_Project_Path
2166 (Prj_Path, Target_Name => Sdefault.Target_Name.all);
2168 declare
2169 First : Natural;
2170 Last : Natural;
2172 begin
2174 if Prj_Path.all /= "" then
2175 First := Prj_Path'First;
2176 loop
2177 while First <= Prj_Path'Last
2178 and then Prj_Path (First) = Path_Separator
2179 loop
2180 First := First + 1;
2181 end loop;
2183 exit when First > Prj_Path'Last;
2185 Last := First;
2186 while Last < Prj_Path'Last
2187 and then Prj_Path (Last + 1) /= Path_Separator
2188 loop
2189 Last := Last + 1;
2190 end loop;
2192 if First /= Last or else Prj_Path (First) /= '.' then
2194 -- If the directory is ".", skip it as it is the current
2195 -- directory and it is already the first directory in the
2196 -- project path.
2198 Write_Str (" ");
2199 Write_Str
2200 (Normalize
2201 (To_Host_Dir_Spec
2202 (Prj_Path (First .. Last), True).all));
2203 Write_Eol;
2204 end if;
2206 First := Last + 1;
2207 end loop;
2208 end if;
2209 end;
2211 Write_Eol;
2212 end if;
2214 -- Output usage information when requested
2216 if Print_Usage then
2217 Usage;
2218 end if;
2220 if not More_Lib_Files then
2221 if not Print_Usage and then not Verbose_Mode then
2222 if Arg_Count = 1 then
2223 Usage;
2224 else
2225 Try_Help;
2226 Exit_Status := E_Fatal;
2227 end if;
2228 end if;
2230 Exit_Program (Exit_Status);
2231 end if;
2233 Initialize_ALI;
2234 Initialize_ALI_Source;
2236 -- Print out all libraries for which no ALI files can be located
2238 while More_Lib_Files loop
2239 Main_File := Next_Main_Lib_File;
2240 Ali_File := Full_Lib_File_Name (Lib_File_Name (Main_File));
2242 if Ali_File = No_File then
2243 if Very_Verbose_Mode then
2244 GNATDIST.Output_No_ALI (Lib_File_Name (Main_File));
2246 else
2247 Set_Standard_Error;
2248 Write_Str ("Can't find library info for ");
2249 Get_Name_String (Main_File);
2250 Write_Char ('"'); -- "
2251 Write_Str (Name_Buffer (1 .. Name_Len));
2252 Write_Char ('"'); -- "
2253 Write_Eol;
2254 Exit_Status := E_Fatal;
2255 end if;
2257 else
2258 Ali_File := Strip_Directory (Ali_File);
2260 if Get_Name_Table_Int (Ali_File) = 0 then
2261 Text := Read_Library_Info (Ali_File, True);
2263 declare
2264 Discard : ALI_Id;
2265 begin
2266 Discard :=
2267 Scan_ALI
2268 (Ali_File,
2269 Text,
2270 Err => False,
2271 Ignore_Errors => True);
2272 end;
2274 Free (Text);
2275 end if;
2276 end if;
2277 end loop;
2279 -- Reset default output file descriptor, if needed
2281 Set_Standard_Output;
2283 if Very_Verbose_Mode then
2284 for A in ALIs.First .. ALIs.Last loop
2285 GNATDIST.Output_ALI (A);
2286 end loop;
2288 return;
2289 end if;
2291 Find_General_Layout;
2293 for Id in ALIs.First .. ALIs.Last loop
2294 declare
2295 Last_U : Unit_Id;
2297 begin
2298 Get_Name_String (Units.Table (ALIs.Table (Id).First_Unit).Uname);
2300 if Also_Predef or else not Is_Internal_Unit then
2301 if ALIs.Table (Id).No_Object then
2302 Output_Object (No_File);
2303 else
2304 Output_Object (ALIs.Table (Id).Ofile_Full_Name);
2305 end if;
2307 -- In verbose mode print all main units in the ALI file, otherwise
2308 -- just print the first one to ease columnwise printout
2310 if Verbose_Mode then
2311 Last_U := ALIs.Table (Id).Last_Unit;
2312 else
2313 Last_U := ALIs.Table (Id).First_Unit;
2314 end if;
2316 for U in ALIs.Table (Id).First_Unit .. Last_U loop
2317 if U /= ALIs.Table (Id).First_Unit
2318 and then Selective_Output
2319 and then Print_Unit
2320 then
2321 Write_Eol;
2322 end if;
2324 Output_Unit (Id, U);
2326 -- Output source now, unless if it will be done as part of
2327 -- outputing dependencies.
2329 if not (Dependable and then Print_Source) then
2330 Output_Source (Corresponding_Sdep_Entry (Id, U));
2331 end if;
2332 end loop;
2334 -- Print out list of units on which this unit depends (D lines)
2336 if Dependable and then Print_Source then
2337 if Verbose_Mode then
2338 Write_Str ("depends upon");
2339 Write_Eol;
2340 Write_Str (" ");
2341 else
2342 Write_Eol;
2343 end if;
2345 for D in
2346 ALIs.Table (Id).First_Sdep .. ALIs.Table (Id).Last_Sdep
2347 loop
2348 if Also_Predef
2349 or else not Is_Internal_File_Name (Sdep.Table (D).Sfile)
2350 then
2351 if Verbose_Mode then
2352 Write_Str (" ");
2353 Output_Source (D);
2355 elsif Too_Long then
2356 Write_Str (" ");
2357 Output_Source (D);
2358 Write_Eol;
2360 else
2361 Write_Str (Spaces (1 .. Source_Start - 2));
2362 Output_Source (D);
2363 Write_Eol;
2364 end if;
2365 end if;
2366 end loop;
2367 end if;
2369 Write_Eol;
2370 end if;
2371 end;
2372 end loop;
2374 -- All done. Set proper exit status
2376 Namet.Finalize;
2377 Exit_Program (Exit_Status);
2378 end Gnatls;