re PR ada/4720 (GNAT programs do not support --help and --version)
[gcc.git] / gcc / ada / gnatls.adb
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-2007, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
26
27 with ALI; use ALI;
28 with ALI.Util; use ALI.Util;
29 with Binderr; use Binderr;
30 with Butil; use Butil;
31 with Csets; use Csets;
32 with Fname; use Fname;
33 with Gnatvsn; use Gnatvsn;
34 with GNAT.OS_Lib; use GNAT.OS_Lib;
35 with Namet; use Namet;
36 with Opt; use Opt;
37 with Osint; use Osint;
38 with Osint.L; use Osint.L;
39 with Output; use Output;
40 with Rident; use Rident;
41 with Sdefault;
42 with Snames;
43 with Switch; use Switch;
44 with Targparm; use Targparm;
45 with Types; use Types;
46
47 with GNAT.Case_Util; use GNAT.Case_Util;
48
49 procedure Gnatls is
50 pragma Ident (Gnat_Static_Version_String);
51
52 Gpr_Project_Path : constant String := "GPR_PROJECT_PATH";
53 Ada_Project_Path : constant String := "ADA_PROJECT_PATH";
54 -- Names of the env. variables that contains path name(s) of directories
55 -- where project files may reside. If GPR_PROJECT_PATH is defined, its
56 -- value is used, otherwise ADA_PROJECT_PATH is used, if defined.
57
58 -- NOTE : The following string may be used by other tools, such as GPS. So
59 -- it can only be modified if these other uses are checked and coordinated.
60
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.
64
65 No_Project_Default_Dir : constant String := "-";
66
67 Max_Column : constant := 80;
68
69 No_Obj : aliased String := "<no_obj>";
70
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
77
78 type Dir_Data;
79 type Dir_Ref is access Dir_Data;
80
81 type Dir_Data is record
82 Value : String_Access;
83 Next : Dir_Ref;
84 end record;
85 -- ??? comment needed
86
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.
92
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.
98
99 Main_File : File_Name_Type;
100 Ali_File : File_Name_Type;
101 Text : Text_Buffer_Ptr;
102 Next_Arg : Positive;
103
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.
107
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
114
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
120
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
128
129 Spaces : constant String (1 .. Max_Column) := (others => ' ');
130
131 RTS_Specified : String_Access := null;
132 -- Used to detect multiple use of --RTS= switch
133
134 -----------------------
135 -- Local Subprograms --
136 -----------------------
137
138 procedure Add_Lib_Dir (Dir : String);
139 -- Add an object directory in the list First_Lib_Dir-Last_Lib_Dir
140
141 procedure Add_Source_Dir (Dir : String);
142 -- Add a source directory in the list First_Source_Dir-Last_Source_Dir
143
144 procedure Find_General_Layout;
145 -- Determine the structure of the output (multi columns or not, etc)
146
147 procedure Find_Status
148 (FS : in out File_Name_Type;
149 Stamp : Time_Stamp_Type;
150 Checksum : Word;
151 Status : out File_Status);
152 -- Determine the file status (Status) of the file represented by FS
153 -- with the expected Stamp and checksum given as argument. FS will be
154 -- updated to the full file name if available.
155
156 function Corresponding_Sdep_Entry (A : ALI_Id; U : Unit_Id) return Sdep_Id;
157 -- Give the Sdep entry corresponding to the unit U in ali record A
158
159 procedure Output_Object (O : File_Name_Type);
160 -- Print out the name of the object when requested
161
162 procedure Output_Source (Sdep_I : Sdep_Id);
163 -- Print out the name and status of the source corresponding to this
164 -- sdep entry.
165
166 procedure Output_Status (FS : File_Status; Verbose : Boolean);
167 -- Print out FS either in a coded form if verbose is false or in an
168 -- expanded form otherwise.
169
170 procedure Output_Unit (ALI : ALI_Id; U_Id : Unit_Id);
171 -- Print out information on the unit when requested
172
173 procedure Reset_Print;
174 -- Reset Print flags properly when selective output is chosen
175
176 procedure Scan_Ls_Arg (Argv : String);
177 -- Scan and process lser specific arguments. Argv is a single argument
178
179 procedure Usage;
180 -- Print usage message
181
182 procedure Output_License_Information;
183 -- Output license statement, and if not found, output reference to
184 -- COPYING.
185
186 function Image (Restriction : Restriction_Id) return String;
187 -- Returns the capitalized image of Restriction
188
189 ---------------------------------------
190 -- GLADE specific output subprograms --
191 ---------------------------------------
192
193 package GLADE is
194
195 -- Any modification to this subunit requires a synchronization
196 -- with the GLADE implementation.
197
198 procedure Output_ALI (A : ALI_Id);
199 procedure Output_No_ALI (Afile : File_Name_Type);
200
201 end GLADE;
202
203 -----------------
204 -- Add_Lib_Dir --
205 -----------------
206
207 procedure Add_Lib_Dir (Dir : String) is
208 begin
209 if First_Lib_Dir = null then
210 First_Lib_Dir :=
211 new Dir_Data'
212 (Value => new String'(Dir),
213 Next => null);
214 Last_Lib_Dir := First_Lib_Dir;
215
216 else
217 Last_Lib_Dir.Next :=
218 new Dir_Data'
219 (Value => new String'(Dir),
220 Next => null);
221 Last_Lib_Dir := Last_Lib_Dir.Next;
222 end if;
223 end Add_Lib_Dir;
224
225 -- -----------------
226 -- Add_Source_Dir --
227 --------------------
228
229 procedure Add_Source_Dir (Dir : String) is
230 begin
231 if First_Source_Dir = null then
232 First_Source_Dir :=
233 new Dir_Data'
234 (Value => new String'(Dir),
235 Next => null);
236 Last_Source_Dir := First_Source_Dir;
237
238 else
239 Last_Source_Dir.Next :=
240 new Dir_Data'
241 (Value => new String'(Dir),
242 Next => null);
243 Last_Source_Dir := Last_Source_Dir.Next;
244 end if;
245 end Add_Source_Dir;
246
247 ------------------------------
248 -- Corresponding_Sdep_Entry --
249 ------------------------------
250
251 function Corresponding_Sdep_Entry
252 (A : ALI_Id;
253 U : Unit_Id) return Sdep_Id
254 is
255 begin
256 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
257 if Sdep.Table (D).Sfile = Units.Table (U).Sfile then
258 return D;
259 end if;
260 end loop;
261
262 Error_Msg_Unit_1 := Units.Table (U).Uname;
263 Error_Msg_File_1 := ALIs.Table (A).Afile;
264 Write_Eol;
265 Error_Msg ("wrong ALI format, can't find dependency line for $ in {");
266 Exit_Program (E_Fatal);
267 return No_Sdep_Id;
268 end Corresponding_Sdep_Entry;
269
270 -------------------------
271 -- Find_General_Layout --
272 -------------------------
273
274 procedure Find_General_Layout is
275 Max_Unit_Length : Integer := 11;
276 Max_Src_Length : Integer := 11;
277 Max_Obj_Length : Integer := 11;
278
279 Len : Integer;
280 FS : File_Name_Type;
281
282 begin
283 -- Compute maximum of each column
284
285 for Id in ALIs.First .. ALIs.Last loop
286 Get_Name_String (Units.Table (ALIs.Table (Id).First_Unit).Uname);
287 if Also_Predef or else not Is_Internal_Unit then
288
289 if Print_Unit then
290 Len := Name_Len - 1;
291 Max_Unit_Length := Integer'Max (Max_Unit_Length, Len);
292 end if;
293
294 if Print_Source then
295 FS := Full_Source_Name (ALIs.Table (Id).Sfile);
296
297 if FS = No_File then
298 Get_Name_String (ALIs.Table (Id).Sfile);
299 Name_Len := Name_Len + 13;
300 else
301 Get_Name_String (FS);
302 end if;
303
304 Max_Src_Length := Integer'Max (Max_Src_Length, Name_Len + 1);
305 end if;
306
307 if Print_Object then
308 if ALIs.Table (Id).No_Object then
309 Max_Obj_Length :=
310 Integer'Max (Max_Obj_Length, No_Obj'Length);
311 else
312 Get_Name_String (ALIs.Table (Id).Ofile_Full_Name);
313 Max_Obj_Length := Integer'Max (Max_Obj_Length, Name_Len + 1);
314 end if;
315 end if;
316 end if;
317 end loop;
318
319 -- Verify is output is not wider than maximum number of columns
320
321 Too_Long :=
322 Verbose_Mode
323 or else
324 (Max_Unit_Length + Max_Src_Length + Max_Obj_Length) > Max_Column;
325
326 -- Set start and end of columns
327
328 Object_Start := 1;
329 Object_End := Object_Start - 1;
330
331 if Print_Object then
332 Object_End := Object_Start + Max_Obj_Length;
333 end if;
334
335 Unit_Start := Object_End + 1;
336 Unit_End := Unit_Start - 1;
337
338 if Print_Unit then
339 Unit_End := Unit_Start + Max_Unit_Length;
340 end if;
341
342 Source_Start := Unit_End + 1;
343
344 if Source_Start > Spaces'Last then
345 Source_Start := Spaces'Last;
346 end if;
347
348 Source_End := Source_Start - 1;
349
350 if Print_Source then
351 Source_End := Source_Start + Max_Src_Length;
352 end if;
353 end Find_General_Layout;
354
355 -----------------
356 -- Find_Status --
357 -----------------
358
359 procedure Find_Status
360 (FS : in out File_Name_Type;
361 Stamp : Time_Stamp_Type;
362 Checksum : Word;
363 Status : out File_Status)
364 is
365 Tmp1 : File_Name_Type;
366 Tmp2 : File_Name_Type;
367
368 begin
369 Tmp1 := Full_Source_Name (FS);
370
371 if Tmp1 = No_File then
372 Status := Not_Found;
373
374 elsif File_Stamp (Tmp1) = Stamp then
375 FS := Tmp1;
376 Status := OK;
377
378 elsif Checksums_Match (Get_File_Checksum (FS), Checksum) then
379 FS := Tmp1;
380 Status := Checksum_OK;
381
382 else
383 Tmp2 := Matching_Full_Source_Name (FS, Stamp);
384
385 if Tmp2 = No_File then
386 Status := Not_Same;
387 FS := Tmp1;
388
389 else
390 Status := Not_First_On_PATH;
391 FS := Tmp2;
392 end if;
393 end if;
394 end Find_Status;
395
396 -----------
397 -- GLADE --
398 -----------
399
400 package body GLADE is
401
402 N_Flags : Natural;
403 N_Indents : Natural := 0;
404
405 type Token_Type is
406 (T_No_ALI,
407 T_ALI,
408 T_Unit,
409 T_With,
410 T_Source,
411 T_Afile,
412 T_Ofile,
413 T_Sfile,
414 T_Name,
415 T_Main,
416 T_Kind,
417 T_Flags,
418 T_Preelaborated,
419 T_Pure,
420 T_Has_RACW,
421 T_Remote_Types,
422 T_Shared_Passive,
423 T_RCI,
424 T_Predefined,
425 T_Internal,
426 T_Is_Generic,
427 T_Procedure,
428 T_Function,
429 T_Package,
430 T_Subprogram,
431 T_Spec,
432 T_Body);
433
434 Image : constant array (Token_Type) of String_Access :=
435 (T_No_ALI => new String'("No_ALI"),
436 T_ALI => new String'("ALI"),
437 T_Unit => new String'("Unit"),
438 T_With => new String'("With"),
439 T_Source => new String'("Source"),
440 T_Afile => new String'("Afile"),
441 T_Ofile => new String'("Ofile"),
442 T_Sfile => new String'("Sfile"),
443 T_Name => new String'("Name"),
444 T_Main => new String'("Main"),
445 T_Kind => new String'("Kind"),
446 T_Flags => new String'("Flags"),
447 T_Preelaborated => new String'("Preelaborated"),
448 T_Pure => new String'("Pure"),
449 T_Has_RACW => new String'("Has_RACW"),
450 T_Remote_Types => new String'("Remote_Types"),
451 T_Shared_Passive => new String'("Shared_Passive"),
452 T_RCI => new String'("RCI"),
453 T_Predefined => new String'("Predefined"),
454 T_Internal => new String'("Internal"),
455 T_Is_Generic => new String'("Is_Generic"),
456 T_Procedure => new String'("procedure"),
457 T_Function => new String'("function"),
458 T_Package => new String'("package"),
459 T_Subprogram => new String'("subprogram"),
460 T_Spec => new String'("spec"),
461 T_Body => new String'("body"));
462
463 procedure Output_Name (N : Name_Id);
464 -- Remove any encoding info (%b and %s) and output N
465
466 procedure Output_Afile (A : File_Name_Type);
467 procedure Output_Ofile (O : File_Name_Type);
468 procedure Output_Sfile (S : File_Name_Type);
469 -- Output various names. Check that the name is different from
470 -- no name. Otherwise, skip the output.
471
472 procedure Output_Token (T : Token_Type);
473 -- Output token using a specific format. That is several
474 -- indentations and:
475 --
476 -- T_No_ALI .. T_With : <token> & " =>" & NL
477 -- T_Source .. T_Kind : <token> & " => "
478 -- T_Flags : <token> & " =>"
479 -- T_Preelab .. T_Body : " " & <token>
480
481 procedure Output_Sdep (S : Sdep_Id);
482 procedure Output_Unit (U : Unit_Id);
483 procedure Output_With (W : With_Id);
484 -- Output this entry as a global section (like ALIs)
485
486 ------------------
487 -- Output_Afile --
488 ------------------
489
490 procedure Output_Afile (A : File_Name_Type) is
491 begin
492 if A /= No_File then
493 Output_Token (T_Afile);
494 Write_Name (A);
495 Write_Eol;
496 end if;
497 end Output_Afile;
498
499 ----------------
500 -- Output_ALI --
501 ----------------
502
503 procedure Output_ALI (A : ALI_Id) is
504 begin
505 Output_Token (T_ALI);
506 N_Indents := N_Indents + 1;
507
508 Output_Afile (ALIs.Table (A).Afile);
509 Output_Ofile (ALIs.Table (A).Ofile_Full_Name);
510 Output_Sfile (ALIs.Table (A).Sfile);
511
512 -- Output Main
513
514 if ALIs.Table (A).Main_Program /= None then
515 Output_Token (T_Main);
516
517 if ALIs.Table (A).Main_Program = Proc then
518 Output_Token (T_Procedure);
519 else
520 Output_Token (T_Function);
521 end if;
522
523 Write_Eol;
524 end if;
525
526 -- Output Units
527
528 for U in ALIs.Table (A).First_Unit .. ALIs.Table (A).Last_Unit loop
529 Output_Unit (U);
530 end loop;
531
532 -- Output Sdeps
533
534 for S in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
535 Output_Sdep (S);
536 end loop;
537
538 N_Indents := N_Indents - 1;
539 end Output_ALI;
540
541 -------------------
542 -- Output_No_ALI --
543 -------------------
544
545 procedure Output_No_ALI (Afile : File_Name_Type) is
546 begin
547 Output_Token (T_No_ALI);
548 N_Indents := N_Indents + 1;
549 Output_Afile (Afile);
550 N_Indents := N_Indents - 1;
551 end Output_No_ALI;
552
553 -----------------
554 -- Output_Name --
555 -----------------
556
557 procedure Output_Name (N : Name_Id) is
558 begin
559 -- Remove any encoding info (%s or %b)
560
561 Get_Name_String (N);
562
563 if Name_Len > 2
564 and then Name_Buffer (Name_Len - 1) = '%'
565 then
566 Name_Len := Name_Len - 2;
567 end if;
568
569 Output_Token (T_Name);
570 Write_Str (Name_Buffer (1 .. Name_Len));
571 Write_Eol;
572 end Output_Name;
573
574 ------------------
575 -- Output_Ofile --
576 ------------------
577
578 procedure Output_Ofile (O : File_Name_Type) is
579 begin
580 if O /= No_File then
581 Output_Token (T_Ofile);
582 Write_Name (O);
583 Write_Eol;
584 end if;
585 end Output_Ofile;
586
587 -----------------
588 -- Output_Sdep --
589 -----------------
590
591 procedure Output_Sdep (S : Sdep_Id) is
592 begin
593 Output_Token (T_Source);
594 Write_Name (Sdep.Table (S).Sfile);
595 Write_Eol;
596 end Output_Sdep;
597
598 ------------------
599 -- Output_Sfile --
600 ------------------
601
602 procedure Output_Sfile (S : File_Name_Type) is
603 FS : File_Name_Type := S;
604
605 begin
606 if FS /= No_File then
607
608 -- We want to output the full source name
609
610 FS := Full_Source_Name (FS);
611
612 -- There is no full source name. This occurs for instance when a
613 -- withed unit has a spec file but no body file. This situation
614 -- is not a problem for GLADE since the unit may be located on
615 -- a partition we do not want to build. However, we need to
616 -- locate the spec file and to find its full source name.
617 -- Replace the body file name with the spec file name used to
618 -- compile the current unit when possible.
619
620 if FS = No_File then
621 Get_Name_String (S);
622
623 if Name_Len > 4
624 and then Name_Buffer (Name_Len - 3 .. Name_Len) = ".adb"
625 then
626 Name_Buffer (Name_Len) := 's';
627 FS := Full_Source_Name (Name_Find);
628 end if;
629 end if;
630 end if;
631
632 if FS /= No_File then
633 Output_Token (T_Sfile);
634 Write_Name (FS);
635 Write_Eol;
636 end if;
637 end Output_Sfile;
638
639 ------------------
640 -- Output_Token --
641 ------------------
642
643 procedure Output_Token (T : Token_Type) is
644 begin
645 if T in T_No_ALI .. T_Flags then
646 for J in 1 .. N_Indents loop
647 Write_Str (" ");
648 end loop;
649
650 Write_Str (Image (T).all);
651
652 for J in Image (T)'Length .. 12 loop
653 Write_Char (' ');
654 end loop;
655
656 Write_Str ("=>");
657
658 if T in T_No_ALI .. T_With then
659 Write_Eol;
660 elsif T in T_Source .. T_Name then
661 Write_Char (' ');
662 end if;
663
664 elsif T in T_Preelaborated .. T_Body then
665 if T in T_Preelaborated .. T_Is_Generic then
666 if N_Flags = 0 then
667 Output_Token (T_Flags);
668 end if;
669
670 N_Flags := N_Flags + 1;
671 end if;
672
673 Write_Char (' ');
674 Write_Str (Image (T).all);
675
676 else
677 Write_Str (Image (T).all);
678 end if;
679 end Output_Token;
680
681 -----------------
682 -- Output_Unit --
683 -----------------
684
685 procedure Output_Unit (U : Unit_Id) is
686 begin
687 Output_Token (T_Unit);
688 N_Indents := N_Indents + 1;
689
690 -- Output Name
691
692 Output_Name (Name_Id (Units.Table (U).Uname));
693
694 -- Output Kind
695
696 Output_Token (T_Kind);
697
698 if Units.Table (U).Unit_Kind = 'p' then
699 Output_Token (T_Package);
700 else
701 Output_Token (T_Subprogram);
702 end if;
703
704 if Name_Buffer (Name_Len) = 's' then
705 Output_Token (T_Spec);
706 else
707 Output_Token (T_Body);
708 end if;
709
710 Write_Eol;
711
712 -- Output source file name
713
714 Output_Sfile (Units.Table (U).Sfile);
715
716 -- Output Flags
717
718 N_Flags := 0;
719
720 if Units.Table (U).Preelab then
721 Output_Token (T_Preelaborated);
722 end if;
723
724 if Units.Table (U).Pure then
725 Output_Token (T_Pure);
726 end if;
727
728 if Units.Table (U).Has_RACW then
729 Output_Token (T_Has_RACW);
730 end if;
731
732 if Units.Table (U).Remote_Types then
733 Output_Token (T_Remote_Types);
734 end if;
735
736 if Units.Table (U).Shared_Passive then
737 Output_Token (T_Shared_Passive);
738 end if;
739
740 if Units.Table (U).RCI then
741 Output_Token (T_RCI);
742 end if;
743
744 if Units.Table (U).Predefined then
745 Output_Token (T_Predefined);
746 end if;
747
748 if Units.Table (U).Internal then
749 Output_Token (T_Internal);
750 end if;
751
752 if Units.Table (U).Is_Generic then
753 Output_Token (T_Is_Generic);
754 end if;
755
756 if N_Flags > 0 then
757 Write_Eol;
758 end if;
759
760 -- Output Withs
761
762 for W in Units.Table (U).First_With .. Units.Table (U).Last_With loop
763 Output_With (W);
764 end loop;
765
766 N_Indents := N_Indents - 1;
767 end Output_Unit;
768
769 -----------------
770 -- Output_With --
771 -----------------
772
773 procedure Output_With (W : With_Id) is
774 begin
775 Output_Token (T_With);
776 N_Indents := N_Indents + 1;
777
778 Output_Name (Name_Id (Withs.Table (W).Uname));
779
780 -- Output Kind
781
782 Output_Token (T_Kind);
783
784 if Name_Buffer (Name_Len) = 's' then
785 Output_Token (T_Spec);
786 else
787 Output_Token (T_Body);
788 end if;
789
790 Write_Eol;
791
792 Output_Afile (Withs.Table (W).Afile);
793 Output_Sfile (Withs.Table (W).Sfile);
794
795 N_Indents := N_Indents - 1;
796 end Output_With;
797
798 end GLADE;
799
800 -----------
801 -- Image --
802 -----------
803
804 function Image (Restriction : Restriction_Id) return String is
805 Result : String := Restriction'Img;
806 Skip : Boolean := True;
807
808 begin
809 for J in Result'Range loop
810 if Skip then
811 Skip := False;
812 Result (J) := To_Upper (Result (J));
813
814 elsif Result (J) = '_' then
815 Skip := True;
816
817 else
818 Result (J) := To_Lower (Result (J));
819 end if;
820 end loop;
821
822 return Result;
823 end Image;
824
825 --------------------------------
826 -- Output_License_Information --
827 --------------------------------
828
829 procedure Output_License_Information is
830 Params_File_Name : constant String := "gnatlic.adl";
831 -- Name of license file
832
833 Lo : constant Source_Ptr := 1;
834 Hi : Source_Ptr;
835 Text : Source_Buffer_Ptr;
836
837 begin
838 Name_Len := 0;
839 Add_Str_To_Name_Buffer (Params_File_Name);
840 Read_Source_File (Name_Find, Lo, Hi, Text);
841
842 if Text /= null then
843
844 -- Omit last character (end-of-file marker) in output
845
846 Write_Str (String (Text (Lo .. Hi - 1)));
847 Write_Eol;
848
849 -- The following condition is determined at compile time: disable
850 -- "condition is always true/false" warning.
851
852 pragma Warnings (Off);
853 elsif Build_Type /= GPL and then Build_Type /= FSF then
854 pragma Warnings (On);
855
856 Write_Str ("License file missing, please contact AdaCore.");
857 Write_Eol;
858
859 else
860 Write_Str ("Please refer to file COPYING in your distribution"
861 & " for license terms.");
862 Write_Eol;
863
864 end if;
865
866 Exit_Program (E_Success);
867 end Output_License_Information;
868
869 -------------------
870 -- Output_Object --
871 -------------------
872
873 procedure Output_Object (O : File_Name_Type) is
874 Object_Name : String_Access;
875
876 begin
877 if Print_Object then
878 if O /= No_File then
879 Get_Name_String (O);
880 Object_Name := To_Host_File_Spec (Name_Buffer (1 .. Name_Len));
881 else
882 Object_Name := No_Obj'Unchecked_Access;
883 end if;
884
885 Write_Str (Object_Name.all);
886
887 if Print_Source or else Print_Unit then
888 if Too_Long then
889 Write_Eol;
890 Write_Str (" ");
891 else
892 Write_Str (Spaces
893 (Object_Start + Object_Name'Length .. Object_End));
894 end if;
895 end if;
896 end if;
897 end Output_Object;
898
899 -------------------
900 -- Output_Source --
901 -------------------
902
903 procedure Output_Source (Sdep_I : Sdep_Id) is
904 Stamp : Time_Stamp_Type;
905 Checksum : Word;
906 FS : File_Name_Type;
907 Status : File_Status;
908 Object_Name : String_Access;
909
910 begin
911 if Sdep_I = No_Sdep_Id then
912 return;
913 end if;
914
915 Stamp := Sdep.Table (Sdep_I).Stamp;
916 Checksum := Sdep.Table (Sdep_I).Checksum;
917 FS := Sdep.Table (Sdep_I).Sfile;
918
919 if Print_Source then
920 Find_Status (FS, Stamp, Checksum, Status);
921 Get_Name_String (FS);
922
923 Object_Name := To_Host_File_Spec (Name_Buffer (1 .. Name_Len));
924
925 if Verbose_Mode then
926 Write_Str (" Source => ");
927 Write_Str (Object_Name.all);
928
929 if not Too_Long then
930 Write_Str
931 (Spaces (Source_Start + Object_Name'Length .. Source_End));
932 end if;
933
934 Output_Status (Status, Verbose => True);
935 Write_Eol;
936 Write_Str (" ");
937
938 else
939 if not Selective_Output then
940 Output_Status (Status, Verbose => False);
941 end if;
942
943 Write_Str (Object_Name.all);
944 end if;
945 end if;
946 end Output_Source;
947
948 -------------------
949 -- Output_Status --
950 -------------------
951
952 procedure Output_Status (FS : File_Status; Verbose : Boolean) is
953 begin
954 if Verbose then
955 case FS is
956 when OK =>
957 Write_Str (" unchanged");
958
959 when Checksum_OK =>
960 Write_Str (" slightly modified");
961
962 when Not_Found =>
963 Write_Str (" file not found");
964
965 when Not_Same =>
966 Write_Str (" modified");
967
968 when Not_First_On_PATH =>
969 Write_Str (" unchanged version not first on PATH");
970 end case;
971
972 else
973 case FS is
974 when OK =>
975 Write_Str (" OK ");
976
977 when Checksum_OK =>
978 Write_Str (" MOK ");
979
980 when Not_Found =>
981 Write_Str (" ??? ");
982
983 when Not_Same =>
984 Write_Str (" DIF ");
985
986 when Not_First_On_PATH =>
987 Write_Str (" HID ");
988 end case;
989 end if;
990 end Output_Status;
991
992 -----------------
993 -- Output_Unit --
994 -----------------
995
996 procedure Output_Unit (ALI : ALI_Id; U_Id : Unit_Id) is
997 Kind : Character;
998 U : Unit_Record renames Units.Table (U_Id);
999
1000 begin
1001 if Print_Unit then
1002 Get_Name_String (U.Uname);
1003 Kind := Name_Buffer (Name_Len);
1004 Name_Len := Name_Len - 2;
1005
1006 if not Verbose_Mode then
1007 Write_Str (Name_Buffer (1 .. Name_Len));
1008
1009 else
1010 Write_Str ("Unit => ");
1011 Write_Eol;
1012 Write_Str (" Name => ");
1013 Write_Str (Name_Buffer (1 .. Name_Len));
1014 Write_Eol;
1015 Write_Str (" Kind => ");
1016
1017 if Units.Table (U_Id).Unit_Kind = 'p' then
1018 Write_Str ("package ");
1019 else
1020 Write_Str ("subprogram ");
1021 end if;
1022
1023 if Kind = 's' then
1024 Write_Str ("spec");
1025 else
1026 Write_Str ("body");
1027 end if;
1028 end if;
1029
1030 if Verbose_Mode then
1031 if U.Preelab or
1032 U.No_Elab or
1033 U.Pure or
1034 U.Dynamic_Elab or
1035 U.Has_RACW or
1036 U.Remote_Types or
1037 U.Shared_Passive or
1038 U.RCI or
1039 U.Predefined or
1040 U.Internal or
1041 U.Is_Generic or
1042 U.Init_Scalars or
1043 U.SAL_Interface or
1044 U.Body_Needed_For_SAL or
1045 U.Elaborate_Body
1046 then
1047 Write_Eol;
1048 Write_Str (" Flags =>");
1049
1050 if U.Preelab then
1051 Write_Str (" Preelaborable");
1052 end if;
1053
1054 if U.No_Elab then
1055 Write_Str (" No_Elab_Code");
1056 end if;
1057
1058 if U.Pure then
1059 Write_Str (" Pure");
1060 end if;
1061
1062 if U.Dynamic_Elab then
1063 Write_Str (" Dynamic_Elab");
1064 end if;
1065
1066 if U.Has_RACW then
1067 Write_Str (" Has_RACW");
1068 end if;
1069
1070 if U.Remote_Types then
1071 Write_Str (" Remote_Types");
1072 end if;
1073
1074 if U.Shared_Passive then
1075 Write_Str (" Shared_Passive");
1076 end if;
1077
1078 if U.RCI then
1079 Write_Str (" RCI");
1080 end if;
1081
1082 if U.Predefined then
1083 Write_Str (" Predefined");
1084 end if;
1085
1086 if U.Internal then
1087 Write_Str (" Internal");
1088 end if;
1089
1090 if U.Is_Generic then
1091 Write_Str (" Is_Generic");
1092 end if;
1093
1094 if U.Init_Scalars then
1095 Write_Str (" Init_Scalars");
1096 end if;
1097
1098 if U.SAL_Interface then
1099 Write_Str (" SAL_Interface");
1100 end if;
1101
1102 if U.Body_Needed_For_SAL then
1103 Write_Str (" Body_Needed_For_SAL");
1104 end if;
1105
1106 if U.Elaborate_Body then
1107 Write_Str (" Elaborate Body");
1108 end if;
1109
1110 if U.Remote_Types then
1111 Write_Str (" Remote_Types");
1112 end if;
1113
1114 if U.Shared_Passive then
1115 Write_Str (" Shared_Passive");
1116 end if;
1117
1118 if U.Predefined then
1119 Write_Str (" Predefined");
1120 end if;
1121
1122 end if;
1123
1124 declare
1125 Restrictions : constant Restrictions_Info :=
1126 ALIs.Table (ALI).Restrictions;
1127
1128 begin
1129 -- If the source was compiled with pragmas Restrictions,
1130 -- Display these restrictions.
1131
1132 if Restrictions.Set /= (All_Restrictions => False) then
1133 Write_Eol;
1134 Write_Str (" pragma Restrictions =>");
1135
1136 -- For boolean restrictions, just display the name of the
1137 -- restriction; for valued restrictions, also display the
1138 -- restriction value.
1139
1140 for Restriction in All_Restrictions loop
1141 if Restrictions.Set (Restriction) then
1142 Write_Eol;
1143 Write_Str (" ");
1144 Write_Str (Image (Restriction));
1145
1146 if Restriction in All_Parameter_Restrictions then
1147 Write_Str (" =>");
1148 Write_Str (Restrictions.Value (Restriction)'Img);
1149 end if;
1150 end if;
1151 end loop;
1152 end if;
1153
1154 -- If the unit violates some Restrictions, display the list of
1155 -- these restrictions.
1156
1157 if Restrictions.Violated /= (All_Restrictions => False) then
1158 Write_Eol;
1159 Write_Str (" Restrictions violated =>");
1160
1161 -- For boolean restrictions, just display the name of the
1162 -- restriction; for valued restrictions, also display the
1163 -- restriction value.
1164
1165 for Restriction in All_Restrictions loop
1166 if Restrictions.Violated (Restriction) then
1167 Write_Eol;
1168 Write_Str (" ");
1169 Write_Str (Image (Restriction));
1170
1171 if Restriction in All_Parameter_Restrictions then
1172 if Restrictions.Count (Restriction) > 0 then
1173 Write_Str (" =>");
1174
1175 if Restrictions.Unknown (Restriction) then
1176 Write_Str (" at least");
1177 end if;
1178
1179 Write_Str (Restrictions.Count (Restriction)'Img);
1180 end if;
1181 end if;
1182 end if;
1183 end loop;
1184 end if;
1185 end;
1186 end if;
1187
1188 if Print_Source then
1189 if Too_Long then
1190 Write_Eol;
1191 Write_Str (" ");
1192 else
1193 Write_Str (Spaces (Unit_Start + Name_Len + 1 .. Unit_End));
1194 end if;
1195 end if;
1196 end if;
1197 end Output_Unit;
1198
1199 -----------------
1200 -- Reset_Print --
1201 -----------------
1202
1203 procedure Reset_Print is
1204 begin
1205 if not Selective_Output then
1206 Selective_Output := True;
1207 Print_Source := False;
1208 Print_Object := False;
1209 Print_Unit := False;
1210 end if;
1211 end Reset_Print;
1212
1213 -------------------
1214 -- Scan_Ls_Arg --
1215 -------------------
1216
1217 procedure Scan_Ls_Arg (Argv : String) is
1218 FD : File_Descriptor;
1219 Len : Integer;
1220
1221 begin
1222 pragma Assert (Argv'First = 1);
1223
1224 if Argv'Length = 0 then
1225 return;
1226 end if;
1227
1228 if Argv (1) = '-' then
1229 if Argv'Length = 1 then
1230 Fail ("switch character cannot be followed by a blank");
1231
1232 -- Processing for -I-
1233
1234 elsif Argv (2 .. Argv'Last) = "I-" then
1235 Opt.Look_In_Primary_Dir := False;
1236
1237 -- Forbid -?- or -??- where ? is any character
1238
1239 elsif (Argv'Length = 3 and then Argv (3) = '-')
1240 or else (Argv'Length = 4 and then Argv (4) = '-')
1241 then
1242 Fail ("Trailing ""-"" at the end of ", Argv, " forbidden.");
1243
1244 -- Processing for -Idir
1245
1246 elsif Argv (2) = 'I' then
1247 Add_Source_Dir (Argv (3 .. Argv'Last));
1248 Add_Lib_Dir (Argv (3 .. Argv'Last));
1249
1250 -- Processing for -aIdir (to gcc this is like a -I switch)
1251
1252 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aI" then
1253 Add_Source_Dir (Argv (4 .. Argv'Last));
1254
1255 -- Processing for -aOdir
1256
1257 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aO" then
1258 Add_Lib_Dir (Argv (4 .. Argv'Last));
1259
1260 -- Processing for -aLdir (to gnatbind this is like a -aO switch)
1261
1262 elsif Argv'Length >= 3 and then Argv (2 .. 3) = "aL" then
1263 Add_Lib_Dir (Argv (4 .. Argv'Last));
1264
1265 -- Processing for -nostdinc
1266
1267 elsif Argv (2 .. Argv'Last) = "nostdinc" then
1268 Opt.No_Stdinc := True;
1269
1270 -- Processing for one character switches
1271
1272 elsif Argv'Length = 2 then
1273 case Argv (2) is
1274 when 'a' => Also_Predef := True;
1275 when 'h' => Print_Usage := True;
1276 when 'u' => Reset_Print; Print_Unit := True;
1277 when 's' => Reset_Print; Print_Source := True;
1278 when 'o' => Reset_Print; Print_Object := True;
1279 when 'v' => Verbose_Mode := True;
1280 when 'd' => Dependable := True;
1281 when 'l' => License := True;
1282 when 'V' => Very_Verbose_Mode := True;
1283
1284 when others => null;
1285 end case;
1286
1287 -- Processing for -files=file
1288
1289 elsif Argv'Length > 7 and then Argv (1 .. 7) = "-files=" then
1290 FD := Open_Read (Argv (8 .. Argv'Last), GNAT.OS_Lib.Text);
1291
1292 if FD = Invalid_FD then
1293 Osint.Fail ("could not find text file """ &
1294 Argv (8 .. Argv'Last) & '"');
1295 end if;
1296
1297 Len := Integer (File_Length (FD));
1298
1299 declare
1300 Buffer : String (1 .. Len + 1);
1301 Index : Positive := 1;
1302 Last : Positive;
1303
1304 begin
1305 -- Read the file
1306
1307 Len := Read (FD, Buffer (1)'Address, Len);
1308 Buffer (Buffer'Last) := ASCII.NUL;
1309 Close (FD);
1310
1311 -- Scan the file line by line
1312
1313 while Index < Buffer'Last loop
1314
1315 -- Find the end of line
1316
1317 Last := Index;
1318
1319 while Last <= Buffer'Last
1320 and then Buffer (Last) /= ASCII.LF
1321 and then Buffer (Last) /= ASCII.CR
1322 loop
1323 Last := Last + 1;
1324 end loop;
1325
1326 -- Ignore empty lines
1327
1328 if Last > Index then
1329 Add_File (Buffer (Index .. Last - 1));
1330 end if;
1331
1332 Index := Last;
1333
1334 -- Find the beginning of the next line
1335
1336 while Buffer (Index) = ASCII.CR or else
1337 Buffer (Index) = ASCII.LF
1338 loop
1339 Index := Index + 1;
1340 end loop;
1341 end loop;
1342 end;
1343
1344 -- Processing for --RTS=path
1345
1346 elsif Argv'Length >= 5 and then Argv (1 .. 5) = "--RTS" then
1347 if Argv'Length <= 6 or else Argv (6) /= '='then
1348 Osint.Fail ("missing path for --RTS");
1349
1350 else
1351 -- Check that it is the first time we see this switch or, if
1352 -- it is not the first time, the same path is specified.
1353
1354 if RTS_Specified = null then
1355 RTS_Specified := new String'(Argv (7 .. Argv'Last));
1356
1357 elsif RTS_Specified.all /= Argv (7 .. Argv'Last) then
1358 Osint.Fail ("--RTS cannot be specified multiple times");
1359 end if;
1360
1361 -- Valid --RTS switch
1362
1363 Opt.No_Stdinc := True;
1364 Opt.RTS_Switch := True;
1365
1366 declare
1367 Src_Path_Name : constant String_Ptr :=
1368 String_Ptr
1369 (Get_RTS_Search_Dir
1370 (Argv (7 .. Argv'Last), Include));
1371 Lib_Path_Name : constant String_Ptr :=
1372 String_Ptr
1373 (Get_RTS_Search_Dir
1374 (Argv (7 .. Argv'Last), Objects));
1375
1376 begin
1377 if Src_Path_Name /= null
1378 and then Lib_Path_Name /= null
1379 then
1380 Add_Search_Dirs (Src_Path_Name, Include);
1381 Add_Search_Dirs (Lib_Path_Name, Objects);
1382
1383 elsif Src_Path_Name = null
1384 and then Lib_Path_Name = null
1385 then
1386 Osint.Fail ("RTS path not valid: missing " &
1387 "adainclude and adalib directories");
1388
1389 elsif Src_Path_Name = null then
1390 Osint.Fail ("RTS path not valid: missing " &
1391 "adainclude directory");
1392
1393 elsif Lib_Path_Name = null then
1394 Osint.Fail ("RTS path not valid: missing " &
1395 "adalib directory");
1396 end if;
1397 end;
1398 end if;
1399 end if;
1400
1401 -- If not a switch, it must be a file name
1402
1403 else
1404 Add_File (Argv);
1405 end if;
1406 end Scan_Ls_Arg;
1407
1408 -----------
1409 -- Usage --
1410 -----------
1411
1412 procedure Usage is
1413 begin
1414 -- Usage line
1415
1416 Write_Str ("Usage: ");
1417 Osint.Write_Program_Name;
1418 Write_Str (" switches [list of object files]");
1419 Write_Eol;
1420 Write_Eol;
1421
1422 -- GNATLS switches
1423
1424 Write_Str ("switches:");
1425 Write_Eol;
1426
1427 -- Line for -a
1428
1429 Write_Str (" -a also output relevant predefined units");
1430 Write_Eol;
1431
1432 -- Line for -u
1433
1434 Write_Str (" -u output only relevant unit names");
1435 Write_Eol;
1436
1437 -- Line for -h
1438
1439 Write_Str (" -h output this help message");
1440 Write_Eol;
1441
1442 -- Line for -s
1443
1444 Write_Str (" -s output only relevant source names");
1445 Write_Eol;
1446
1447 -- Line for -o
1448
1449 Write_Str (" -o output only relevant object names");
1450 Write_Eol;
1451
1452 -- Line for -d
1453
1454 Write_Str (" -d output sources on which specified units " &
1455 "depend");
1456 Write_Eol;
1457
1458 -- Line for -l
1459
1460 Write_Str (" -l output license information");
1461 Write_Eol;
1462
1463 -- Line for -v
1464
1465 Write_Str (" -v verbose output, full path and unit " &
1466 "information");
1467 Write_Eol;
1468 Write_Eol;
1469
1470 -- Line for -files=
1471
1472 Write_Str (" -files=fil files are listed in text file 'fil'");
1473 Write_Eol;
1474
1475 -- Line for -aI switch
1476
1477 Write_Str (" -aIdir specify source files search path");
1478 Write_Eol;
1479
1480 -- Line for -aO switch
1481
1482 Write_Str (" -aOdir specify object files search path");
1483 Write_Eol;
1484
1485 -- Line for -I switch
1486
1487 Write_Str (" -Idir like -aIdir -aOdir");
1488 Write_Eol;
1489
1490 -- Line for -I- switch
1491
1492 Write_Str (" -I- do not look for sources & object files");
1493 Write_Str (" in the default directory");
1494 Write_Eol;
1495
1496 -- Line for -nostdinc
1497
1498 Write_Str (" -nostdinc do not look for source files");
1499 Write_Str (" in the system default directory");
1500 Write_Eol;
1501
1502 -- Line for --RTS
1503
1504 Write_Str (" --RTS=dir specify the default source and object search"
1505 & " path");
1506 Write_Eol;
1507
1508 -- File Status explanation
1509
1510 Write_Eol;
1511 Write_Str (" file status can be:");
1512 Write_Eol;
1513
1514 for ST in File_Status loop
1515 Write_Str (" ");
1516 Output_Status (ST, Verbose => False);
1517 Write_Str (" ==> ");
1518 Output_Status (ST, Verbose => True);
1519 Write_Eol;
1520 end loop;
1521 end Usage;
1522
1523 -- Start of processing for Gnatls
1524
1525 begin
1526 -- Initialize standard packages
1527
1528 Namet.Initialize;
1529 Csets.Initialize;
1530 Snames.Initialize;
1531
1532 -- First check for --version or --help
1533
1534 Check_Version_And_Help ("GNATLS", "1997", Usage'Unrestricted_Access);
1535
1536 -- Loop to scan out arguments
1537
1538 Next_Arg := 1;
1539 Scan_Args : while Next_Arg < Arg_Count loop
1540 declare
1541 Next_Argv : String (1 .. Len_Arg (Next_Arg));
1542 begin
1543 Fill_Arg (Next_Argv'Address, Next_Arg);
1544 Scan_Ls_Arg (Next_Argv);
1545 end;
1546
1547 Next_Arg := Next_Arg + 1;
1548 end loop Scan_Args;
1549
1550 -- If -l (output license information) is given, it must be the only switch
1551
1552 if License and then Arg_Count /= 2 then
1553 Write_Str ("Can't use -l with another switch");
1554 Write_Eol;
1555 Usage;
1556 Exit_Program (E_Fatal);
1557 end if;
1558
1559 -- Add the source and object directories specified on the
1560 -- command line, if any, to the searched directories.
1561
1562 while First_Source_Dir /= null loop
1563 Add_Src_Search_Dir (First_Source_Dir.Value.all);
1564 First_Source_Dir := First_Source_Dir.Next;
1565 end loop;
1566
1567 while First_Lib_Dir /= null loop
1568 Add_Lib_Search_Dir (First_Lib_Dir.Value.all);
1569 First_Lib_Dir := First_Lib_Dir.Next;
1570 end loop;
1571
1572 -- Finally, add the default directories and obtain target parameters
1573
1574 Osint.Add_Default_Search_Dirs;
1575
1576 if Verbose_Mode then
1577 Targparm.Get_Target_Parameters;
1578
1579 Write_Eol;
1580 Display_Version ("GNATLS", "1997");
1581 Write_Eol;
1582 Write_Str ("Source Search Path:");
1583 Write_Eol;
1584
1585 for J in 1 .. Nb_Dir_In_Src_Search_Path loop
1586 Write_Str (" ");
1587
1588 if Dir_In_Src_Search_Path (J)'Length = 0 then
1589 Write_Str ("<Current_Directory>");
1590 else
1591 Write_Str (To_Host_Dir_Spec
1592 (Dir_In_Src_Search_Path (J).all, True).all);
1593 end if;
1594
1595 Write_Eol;
1596 end loop;
1597
1598 Write_Eol;
1599 Write_Eol;
1600 Write_Str ("Object Search Path:");
1601 Write_Eol;
1602
1603 for J in 1 .. Nb_Dir_In_Obj_Search_Path loop
1604 Write_Str (" ");
1605
1606 if Dir_In_Obj_Search_Path (J)'Length = 0 then
1607 Write_Str ("<Current_Directory>");
1608 else
1609 Write_Str (To_Host_Dir_Spec
1610 (Dir_In_Obj_Search_Path (J).all, True).all);
1611 end if;
1612
1613 Write_Eol;
1614 end loop;
1615
1616 Write_Eol;
1617 Write_Eol;
1618 Write_Str (Project_Search_Path);
1619 Write_Eol;
1620 Write_Str (" <Current_Directory>");
1621 Write_Eol;
1622
1623 declare
1624 Project_Path : String_Access := Getenv (Gpr_Project_Path);
1625
1626 Lib : constant String :=
1627 Directory_Separator & "lib" & Directory_Separator;
1628
1629 First : Natural;
1630 Last : Natural;
1631
1632 Add_Default_Dir : Boolean := True;
1633
1634 begin
1635 -- If there is a project path, display each directory in the path
1636
1637 if Project_Path.all = "" then
1638 Project_Path := Getenv (Ada_Project_Path);
1639 end if;
1640
1641 if Project_Path.all /= "" then
1642 First := Project_Path'First;
1643 loop
1644 while First <= Project_Path'Last
1645 and then (Project_Path (First) = Path_Separator)
1646 loop
1647 First := First + 1;
1648 end loop;
1649
1650 exit when First > Project_Path'Last;
1651
1652 Last := First;
1653 while Last < Project_Path'Last
1654 and then Project_Path (Last + 1) /= Path_Separator
1655 loop
1656 Last := Last + 1;
1657 end loop;
1658
1659 -- If the directory is No_Default_Project_Dir, set
1660 -- Add_Default_Dir to False.
1661
1662 if Project_Path (First .. Last) = No_Project_Default_Dir then
1663 Add_Default_Dir := False;
1664
1665 elsif First /= Last or else Project_Path (First) /= '.' then
1666
1667 -- If the directory is ".", skip it as it is the current
1668 -- directory and it is already the first directory in the
1669 -- project path.
1670
1671 Write_Str (" ");
1672 Write_Str
1673 (To_Host_Dir_Spec
1674 (Project_Path (First .. Last), True).all);
1675 Write_Eol;
1676 end if;
1677
1678 First := Last + 1;
1679 end loop;
1680 end if;
1681
1682 -- Add the default dir, except if "-" was one of the "directories"
1683 -- specified in ADA_PROJECT_DIR.
1684
1685 if Add_Default_Dir then
1686 Name_Len := 0;
1687 Add_Str_To_Name_Buffer (Sdefault.Search_Dir_Prefix.all);
1688
1689 -- On Windows, make sure that all directory separators are '\'
1690
1691 if Directory_Separator /= '/' then
1692 for J in 1 .. Name_Len loop
1693 if Name_Buffer (J) = '/' then
1694 Name_Buffer (J) := Directory_Separator;
1695 end if;
1696 end loop;
1697 end if;
1698
1699 -- Find the sequence "/lib/"
1700
1701 while Name_Len >= Lib'Length
1702 and then Name_Buffer (Name_Len - 4 .. Name_Len) /= Lib
1703 loop
1704 Name_Len := Name_Len - 1;
1705 end loop;
1706
1707 -- If the sequence "/lib"/ was found, display the default
1708 -- directory <prefix>/lib/gnat/.
1709
1710 if Name_Len >= 5 then
1711 Name_Buffer (Name_Len + 1 .. Name_Len + 4) := "gnat";
1712 Name_Buffer (Name_Len + 5) := Directory_Separator;
1713 Name_Len := Name_Len + 5;
1714 Write_Str (" ");
1715 Write_Line
1716 (To_Host_Dir_Spec (Name_Buffer (1 .. Name_Len), True).all);
1717 end if;
1718 end if;
1719 end;
1720
1721 Write_Eol;
1722 end if;
1723
1724 -- Output usage information when requested
1725
1726 if Print_Usage then
1727 Usage;
1728 end if;
1729
1730 -- Output license information when requested
1731
1732 if License then
1733 Output_License_Information;
1734 Exit_Program (E_Success);
1735 end if;
1736
1737 if not More_Lib_Files then
1738 if not Print_Usage and then not Verbose_Mode then
1739 Usage;
1740 end if;
1741
1742 Exit_Program (E_Fatal);
1743 end if;
1744
1745 Initialize_ALI;
1746 Initialize_ALI_Source;
1747
1748 -- Print out all library for which no ALI files can be located
1749
1750 while More_Lib_Files loop
1751 Main_File := Next_Main_Lib_File;
1752 Ali_File := Full_Lib_File_Name (Lib_File_Name (Main_File));
1753
1754 if Ali_File = No_File then
1755 if Very_Verbose_Mode then
1756 GLADE.Output_No_ALI (Lib_File_Name (Main_File));
1757
1758 else
1759 Write_Str ("Can't find library info for ");
1760 Get_Name_String (Main_File);
1761 Write_Char ('"'); -- "
1762 Write_Str (Name_Buffer (1 .. Name_Len));
1763 Write_Char ('"'); -- "
1764 Write_Eol;
1765 end if;
1766
1767 else
1768 Ali_File := Strip_Directory (Ali_File);
1769
1770 if Get_Name_Table_Info (Ali_File) = 0 then
1771 Text := Read_Library_Info (Ali_File, True);
1772
1773 declare
1774 Discard : ALI_Id;
1775 pragma Unreferenced (Discard);
1776 begin
1777 Discard :=
1778 Scan_ALI
1779 (Ali_File,
1780 Text,
1781 Ignore_ED => False,
1782 Err => False,
1783 Ignore_Errors => True);
1784 end;
1785
1786 Free (Text);
1787 end if;
1788 end if;
1789 end loop;
1790
1791 if Very_Verbose_Mode then
1792 for A in ALIs.First .. ALIs.Last loop
1793 GLADE.Output_ALI (A);
1794 end loop;
1795
1796 return;
1797 end if;
1798
1799 Find_General_Layout;
1800
1801 for Id in ALIs.First .. ALIs.Last loop
1802 declare
1803 Last_U : Unit_Id;
1804
1805 begin
1806 Get_Name_String (Units.Table (ALIs.Table (Id).First_Unit).Uname);
1807
1808 if Also_Predef or else not Is_Internal_Unit then
1809 if ALIs.Table (Id).No_Object then
1810 Output_Object (No_File);
1811 else
1812 Output_Object (ALIs.Table (Id).Ofile_Full_Name);
1813 end if;
1814
1815 -- In verbose mode print all main units in the ALI file, otherwise
1816 -- just print the first one to ease columnwise printout
1817
1818 if Verbose_Mode then
1819 Last_U := ALIs.Table (Id).Last_Unit;
1820 else
1821 Last_U := ALIs.Table (Id).First_Unit;
1822 end if;
1823
1824 for U in ALIs.Table (Id).First_Unit .. Last_U loop
1825 if U /= ALIs.Table (Id).First_Unit
1826 and then Selective_Output
1827 and then Print_Unit
1828 then
1829 Write_Eol;
1830 end if;
1831
1832 Output_Unit (Id, U);
1833
1834 -- Output source now, unless if it will be done as part of
1835 -- outputing dependencies.
1836
1837 if not (Dependable and then Print_Source) then
1838 Output_Source (Corresponding_Sdep_Entry (Id, U));
1839 end if;
1840 end loop;
1841
1842 -- Print out list of units on which this unit depends (D lines)
1843
1844 if Dependable and then Print_Source then
1845 if Verbose_Mode then
1846 Write_Str ("depends upon");
1847 Write_Eol;
1848 Write_Str (" ");
1849 else
1850 Write_Eol;
1851 end if;
1852
1853 for D in
1854 ALIs.Table (Id).First_Sdep .. ALIs.Table (Id).Last_Sdep
1855 loop
1856 if Also_Predef
1857 or else not Is_Internal_File_Name (Sdep.Table (D).Sfile)
1858 then
1859 if Verbose_Mode then
1860 Write_Str (" ");
1861 Output_Source (D);
1862
1863 elsif Too_Long then
1864 Write_Str (" ");
1865 Output_Source (D);
1866 Write_Eol;
1867
1868 else
1869 Write_Str (Spaces (1 .. Source_Start - 2));
1870 Output_Source (D);
1871 Write_Eol;
1872 end if;
1873 end if;
1874 end loop;
1875 end if;
1876
1877 Write_Eol;
1878 end if;
1879 end;
1880 end loop;
1881
1882 -- All done. Set proper exit status
1883
1884 Namet.Finalize;
1885 Exit_Program (E_Success);
1886 end Gnatls;