1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1998-2007, 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 procedure Parse_Cmd_Line;
56 -- Parse every switch on the command line
61 procedure Write_Usage;
62 -- Print a small help page for program usage
68 procedure Parse_Cmd_Line is
70 -- First check for --version or --help
72 Check_Version_And_Help ("GNATXREF", "1998", Usage'Unrestricted_Access);
76 GNAT.Command_Line.Getopt
77 ("a aI: aO: d f g h I: nostdinc nostdlib p: u v -RTS=")
83 if GNAT.Command_Line.Full_Switch = "a" then
86 elsif GNAT.Command_Line.Full_Switch = "aI" then
87 Osint.Add_Src_Search_Dir (GNAT.Command_Line.Parameter);
90 Osint.Add_Lib_Search_Dir (GNAT.Command_Line.Parameter);
97 Full_Path_Name := True;
100 Local_Symbols := False;
106 Osint.Add_Src_Search_Dir (GNAT.Command_Line.Parameter);
107 Osint.Add_Lib_Search_Dir (GNAT.Command_Line.Parameter);
110 if GNAT.Command_Line.Full_Switch = "nostdinc" then
111 Opt.No_Stdinc := True;
112 elsif GNAT.Command_Line.Full_Switch = "nostlib" then
113 Opt.No_Stdlib := True;
118 S : constant String := GNAT.Command_Line.Parameter;
120 Prj_File_Length := S'Length;
121 Prj_File (1 .. Prj_File_Length) := S;
125 Search_Unused := True;
130 Search_Unused := False;
132 -- The only switch starting with -- recognized is --RTS
136 -- Check that it is the first time we see this switch
138 if RTS_Specified = null then
139 RTS_Specified := new String'(GNAT.Command_Line.Parameter);
141 elsif RTS_Specified.all /= GNAT.Command_Line.Parameter then
142 Osint.Fail ("--RTS cannot be specified multiple times");
145 Opt.No_Stdinc := True;
146 Opt.RTS_Switch := True;
149 Src_Path_Name : constant String_Ptr :=
151 (GNAT.Command_Line.Parameter, Include);
153 Lib_Path_Name : constant String_Ptr :=
155 (GNAT.Command_Line.Parameter, Objects);
158 if Src_Path_Name /= null and then Lib_Path_Name /= null then
159 Add_Search_Dirs (Src_Path_Name, Include);
160 Add_Search_Dirs (Lib_Path_Name, Objects);
162 elsif Src_Path_Name = null and then Lib_Path_Name = null then
163 Osint.Fail ("RTS path not valid: missing " &
164 "adainclude and adalib directories");
166 elsif Src_Path_Name = null then
167 Osint.Fail ("RTS path not valid: missing " &
168 "adainclude directory");
170 elsif Lib_Path_Name = null then
171 Osint.Fail ("RTS path not valid: missing " &
181 -- Get the other arguments
185 S : constant String := GNAT.Command_Line.Get_Argument;
188 exit when S'Length = 0;
190 if Ada.Strings.Fixed.Index (S, ":") /= 0 then
192 ("Only file names are allowed on the command line");
202 when GNAT.Command_Line.Invalid_Switch =>
203 Ada.Text_IO.Put_Line ("Invalid switch : "
204 & GNAT.Command_Line.Full_Switch);
207 when GNAT.Command_Line.Invalid_Parameter =>
208 Ada.Text_IO.Put_Line ("Parameter missing for : "
209 & GNAT.Command_Line.Full_Switch);
219 Put_Line ("Usage: gnatxref [switches] file1 file2 ...");
221 Put_Line (" file ... list of source files to xref, " &
222 "including with'ed units");
224 Put_Line ("gnatxref switches:");
225 Put_Line (" -a Consider all files, even when the ali file is"
227 Put_Line (" -aIdir Specify source files search path");
228 Put_Line (" -aOdir Specify library/object files search path");
229 Put_Line (" -d Output derived type information");
230 Put_Line (" -f Output full path name");
231 Put_Line (" -g Output information only for global symbols");
232 Put_Line (" -Idir Like -aIdir -aOdir");
233 Put_Line (" -nostdinc Don't look for sources in the system default"
235 Put_Line (" -nostdlib Don't look for library files in the system"
236 & " default directory");
237 Put_Line (" --RTS=dir specify the default source and object search"
239 Put_Line (" -p file Use file as the default project file");
240 Put_Line (" -u List unused entities");
241 Put_Line (" -v Print a 'tags' file for vi");
250 procedure Write_Usage is
252 Display_Version ("GNATXREF", "1998");
261 if not Have_File then
265 Xr_Tabls.Set_Default_Match (True);
267 -- Find the project file
269 if Prj_File_Length = 0 then
270 Xr_Tabls.Create_Project_File
271 (Default_Project_File (Osint.To_Host_Dir_Spec (".", False).all));
273 Xr_Tabls.Create_Project_File (Prj_File (1 .. Prj_File_Length));
278 Search_Xref (Local_Symbols, Read_Only, Der_Info);
280 if Search_Unused then
281 Print_Unused (Full_Path_Name);
283 Print_Vi (Full_Path_Name);
285 Print_Xref (Full_Path_Name);