1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1998-2011, 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;
30 with Xr_Tabls; use Xr_Tabls;
31 with Xref_Lib; use Xref_Lib;
33 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
34 with Ada.Text_IO; use Ada.Text_IO;
36 with GNAT.Command_Line; use GNAT.Command_Line;
38 with System.Strings; use System.Strings;
41 Search_Unused : Boolean := False;
42 Local_Symbols : Boolean := True;
43 Prj_File : File_Name_String;
44 Prj_File_Length : Natural := 0;
45 Usage_Error : exception;
46 Full_Path_Name : Boolean := False;
47 Vi_Mode : Boolean := False;
48 Read_Only : Boolean := False;
49 Have_File : Boolean := False;
50 Der_Info : Boolean := False;
52 RTS_Specified : String_Access := null;
53 -- Used to detect multiple use of --RTS= switch
55 EXT_Specified : String_Access := null;
56 -- Used to detect multiple use of --ext= switch
58 procedure Parse_Cmd_Line;
59 -- Parse every switch on the command line
64 procedure Write_Usage;
65 -- Print a small help page for program usage
71 procedure Parse_Cmd_Line is
73 procedure Check_Version_And_Help is new Check_Version_And_Help_G (Usage);
75 -- Start of processing for Parse_Cmd_Line
78 -- First check for --version or --help
80 Check_Version_And_Help ("GNATXREF", "1998");
84 GNAT.Command_Line.Getopt
85 ("a aI: aO: d f g h I: nostdinc nostdlib p: u v -RTS= -ext=")
91 if GNAT.Command_Line.Full_Switch = "a" then
94 elsif GNAT.Command_Line.Full_Switch = "aI" then
95 Osint.Add_Src_Search_Dir (GNAT.Command_Line.Parameter);
98 Osint.Add_Lib_Search_Dir (GNAT.Command_Line.Parameter);
105 Full_Path_Name := True;
108 Local_Symbols := False;
114 Osint.Add_Src_Search_Dir (GNAT.Command_Line.Parameter);
115 Osint.Add_Lib_Search_Dir (GNAT.Command_Line.Parameter);
118 if GNAT.Command_Line.Full_Switch = "nostdinc" then
119 Opt.No_Stdinc := True;
120 elsif GNAT.Command_Line.Full_Switch = "nostdlib" then
121 Opt.No_Stdlib := True;
126 S : constant String := GNAT.Command_Line.Parameter;
128 Prj_File_Length := S'Length;
129 Prj_File (1 .. Prj_File_Length) := S;
133 Search_Unused := True;
138 Search_Unused := False;
140 -- The only switch starting with -- recognized is --RTS
144 -- Check that it is the first time we see this switch
146 if Full_Switch = "-RTS" then
147 if RTS_Specified = null then
148 RTS_Specified := new String'(GNAT.Command_Line.Parameter);
150 elsif RTS_Specified.all /= GNAT.Command_Line.Parameter then
151 Osint.Fail ("--RTS cannot be specified multiple times");
154 Opt.No_Stdinc := True;
155 Opt.RTS_Switch := True;
158 Src_Path_Name : constant String_Ptr :=
160 (GNAT.Command_Line.Parameter,
163 Lib_Path_Name : constant String_Ptr :=
165 (GNAT.Command_Line.Parameter,
169 if Src_Path_Name /= null
170 and then Lib_Path_Name /= null
172 Add_Search_Dirs (Src_Path_Name, Include);
173 Add_Search_Dirs (Lib_Path_Name, Objects);
175 elsif Src_Path_Name = null
176 and then Lib_Path_Name = null
178 Osint.Fail ("RTS path not valid: missing " &
179 "adainclude and adalib directories");
181 elsif Src_Path_Name = null then
182 Osint.Fail ("RTS path not valid: missing " &
183 "adainclude directory");
185 elsif Lib_Path_Name = null then
186 Osint.Fail ("RTS path not valid: missing " &
191 elsif GNAT.Command_Line.Full_Switch = "-ext" then
193 -- Check that it is the first time we see this switch
195 if EXT_Specified = null then
196 EXT_Specified := new String'(GNAT.Command_Line.Parameter);
198 elsif EXT_Specified.all /= GNAT.Command_Line.Parameter then
199 Osint.Fail ("--ext cannot be specified multiple times");
202 if EXT_Specified'Length
203 = Osint.ALI_Default_Suffix'Length
205 Osint.ALI_Suffix := EXT_Specified.all'Access;
207 Osint.Fail ("--ext argument must have 3 characters");
216 -- Get the other arguments
220 S : constant String := GNAT.Command_Line.Get_Argument;
223 exit when S'Length = 0;
225 if Ada.Strings.Fixed.Index (S, ":") /= 0 then
227 ("Only file names are allowed on the command line");
237 when GNAT.Command_Line.Invalid_Switch =>
238 Ada.Text_IO.Put_Line ("Invalid switch : "
239 & GNAT.Command_Line.Full_Switch);
242 when GNAT.Command_Line.Invalid_Parameter =>
243 Ada.Text_IO.Put_Line ("Parameter missing for : "
244 & GNAT.Command_Line.Full_Switch);
254 Put_Line ("Usage: gnatxref [switches] file1 file2 ...");
256 Put_Line (" file ... list of source files to xref, " &
257 "including with'ed units");
259 Put_Line ("gnatxref switches:");
260 Display_Usage_Version_And_Help;
261 Put_Line (" -a Consider all files, even when the ali file is"
263 Put_Line (" -aIdir Specify source files search path");
264 Put_Line (" -aOdir Specify library/object files search path");
265 Put_Line (" -d Output derived type information");
266 Put_Line (" -f Output full path name");
267 Put_Line (" -g Output information only for global symbols");
268 Put_Line (" -Idir Like -aIdir -aOdir");
269 Put_Line (" -nostdinc Don't look for sources in the system default"
271 Put_Line (" -nostdlib Don't look for library files in the system"
272 & " default directory");
273 Put_Line (" --ext=xxx Specify alternate ali file extension");
274 Put_Line (" --RTS=dir specify the default source and object search"
276 Put_Line (" -p file Use file as the default project file");
277 Put_Line (" -u List unused entities");
278 Put_Line (" -v Print a 'tags' file for vi");
287 procedure Write_Usage is
289 Display_Version ("GNATXREF", "1998");
298 if not Have_File then
302 Xr_Tabls.Set_Default_Match (True);
304 -- Find the project file
306 if Prj_File_Length = 0 then
307 Xr_Tabls.Create_Project_File
308 (Default_Project_File (Osint.To_Host_Dir_Spec (".", False).all));
310 Xr_Tabls.Create_Project_File (Prj_File (1 .. Prj_File_Length));
315 Search_Xref (Local_Symbols, Read_Only, Der_Info);
317 if Search_Unused then
318 Print_Unused (Full_Path_Name);
320 Print_Vi (Full_Path_Name);
322 Print_Xref (Full_Path_Name);