1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1998-2020, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
27 with Osint; use Osint;
28 with Types; use Types;
29 with Switch; use Switch;
31 with Xref_Lib; use Xref_Lib;
33 with Ada.Command_Line; use Ada.Command_Line;
34 with Ada.Strings.Fixed;
35 with Ada.Text_IO; use Ada.Text_IO;
37 with GNAT.Command_Line; use GNAT.Command_Line;
39 with System.Strings; use System.Strings;
42 Search_Unused : Boolean := False;
43 Local_Symbols : Boolean := True;
44 Prj_File : File_Name_String;
45 Prj_File_Length : Natural := 0;
46 Usage_Error : exception;
47 Full_Path_Name : Boolean := False;
48 Vi_Mode : Boolean := False;
49 Read_Only : Boolean := False;
50 Have_File : Boolean := False;
51 Der_Info : Boolean := False;
53 RTS_Specified : String_Access := null;
54 -- Used to detect multiple use of --RTS= switch
56 EXT_Specified : String_Access := null;
57 -- Used to detect multiple use of --ext= switch
59 procedure Parse_Cmd_Line;
60 -- Parse every switch on the command line
65 procedure Write_Usage;
66 pragma No_Return (Write_Usage);
67 -- Print a small help page for program usage
73 procedure Parse_Cmd_Line is
75 procedure Check_Version_And_Help is new Check_Version_And_Help_G (Usage);
77 -- Start of processing for Parse_Cmd_Line
80 -- First check for --version or --help
82 Check_Version_And_Help ("GNATXREF", "1998");
86 GNAT.Command_Line.Getopt
87 ("a aI: aO: d f g h I: nostdinc nostdlib p: u v -RTS= -ext=")
93 if GNAT.Command_Line.Full_Switch = "a" then
96 elsif GNAT.Command_Line.Full_Switch = "aI" then
97 Osint.Add_Src_Search_Dir (GNAT.Command_Line.Parameter);
100 Osint.Add_Lib_Search_Dir (GNAT.Command_Line.Parameter);
107 Full_Path_Name := True;
110 Local_Symbols := False;
116 Osint.Add_Src_Search_Dir (GNAT.Command_Line.Parameter);
117 Osint.Add_Lib_Search_Dir (GNAT.Command_Line.Parameter);
120 if GNAT.Command_Line.Full_Switch = "nostdinc" then
121 Opt.No_Stdinc := True;
122 elsif GNAT.Command_Line.Full_Switch = "nostdlib" then
123 Opt.No_Stdlib := True;
128 S : constant String := GNAT.Command_Line.Parameter;
130 Prj_File_Length := S'Length;
131 Prj_File (1 .. Prj_File_Length) := S;
135 Search_Unused := True;
140 Search_Unused := False;
142 -- The only switch starting with -- recognized is --RTS
146 -- Check that it is the first time we see this switch
148 if Full_Switch = "-RTS" then
149 if RTS_Specified = null then
150 RTS_Specified := new String'(GNAT.Command_Line.Parameter);
152 elsif RTS_Specified.all /= GNAT.Command_Line.Parameter then
153 Osint.Fail ("--RTS cannot be specified multiple times");
156 Opt.No_Stdinc := True;
157 Opt.RTS_Switch := True;
160 Src_Path_Name : constant String_Ptr :=
162 (GNAT.Command_Line.Parameter,
165 Lib_Path_Name : constant String_Ptr :=
167 (GNAT.Command_Line.Parameter,
171 if Src_Path_Name /= null
172 and then Lib_Path_Name /= null
174 Add_Search_Dirs (Src_Path_Name, Include);
175 Add_Search_Dirs (Lib_Path_Name, Objects);
177 elsif Src_Path_Name = null
178 and then Lib_Path_Name = null
181 ("RTS path not valid: missing adainclude and "
182 & "adalib directories");
184 elsif Src_Path_Name = null then
186 ("RTS path not valid: missing adainclude directory");
188 elsif Lib_Path_Name = null then
190 ("RTS path not valid: missing adalib directory");
194 elsif GNAT.Command_Line.Full_Switch = "-ext" then
196 -- Check that it is the first time we see this switch
198 if EXT_Specified = null then
199 EXT_Specified := new String'(GNAT.Command_Line.Parameter);
201 elsif EXT_Specified.all /= GNAT.Command_Line.Parameter then
202 Osint.Fail ("--ext cannot be specified multiple times");
205 if EXT_Specified'Length = Osint.ALI_Default_Suffix'Length
207 Osint.ALI_Suffix := EXT_Specified.all'Access;
209 Osint.Fail ("--ext argument must have 3 characters");
219 -- Get the other arguments
223 S : constant String := GNAT.Command_Line.Get_Argument;
226 exit when S'Length = 0;
228 if Ada.Strings.Fixed.Index (S, ":") /= 0 then
230 ("Only file names are allowed on the command line");
241 when GNAT.Command_Line.Invalid_Switch =>
242 Ada.Text_IO.Put_Line ("Invalid switch : "
243 & GNAT.Command_Line.Full_Switch);
247 when GNAT.Command_Line.Invalid_Parameter =>
248 Ada.Text_IO.Put_Line ("Parameter missing for : "
249 & GNAT.Command_Line.Full_Switch);
260 Put_Line ("Usage: gnatxref [switches] file1 file2 ...");
262 Put_Line (" file ... list of source files to xref, " &
263 "including with'ed units");
265 Put_Line ("gnatxref switches:");
266 Display_Usage_Version_And_Help;
267 Put_Line (" -a Consider all files, even when the ali file is"
269 Put_Line (" -aIdir Specify source files search path");
270 Put_Line (" -aOdir Specify library/object files search path");
271 Put_Line (" -d Output derived type information");
272 Put_Line (" -f Output full path name");
273 Put_Line (" -g Output information only for global symbols");
274 Put_Line (" -Idir Like -aIdir -aOdir");
275 Put_Line (" -nostdinc Don't look for sources in the system default"
277 Put_Line (" -nostdlib Don't look for library files in the system"
278 & " default directory");
279 Put_Line (" --ext=xxx Specify alternate ali file extension");
280 Put_Line (" --RTS=dir specify the default source and object search"
282 Put_Line (" -p file Use file as the configuration file");
283 Put_Line (" -u List unused entities");
284 Put_Line (" -v Print a 'tags' file for vi");
293 procedure Write_Usage is
295 Display_Version ("GNATXREF", "1998");
304 if not Have_File then
305 if Argument_Count = 0 then
313 Xr_Tabls.Set_Default_Match (True);
315 -- Find the project file
317 if Prj_File_Length = 0 then
318 Xr_Tabls.Create_Project_File
319 (Default_Project_File (Osint.To_Host_Dir_Spec (".", False).all));
321 Xr_Tabls.Create_Project_File (Prj_File (1 .. Prj_File_Length));
326 Search_Xref (Local_Symbols, Read_Only, Der_Info);
328 if Search_Unused then
329 Print_Unused (Full_Path_Name);
331 Print_Vi (Full_Path_Name);
333 Print_Xref (Full_Path_Name);