1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1998-2005, 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 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. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Xr_Tabls
; use Xr_Tabls
;
28 with Xref_Lib
; use Xref_Lib
;
29 with Osint
; use Osint
;
30 with Types
; use Types
;
35 with Ada
.Strings
.Fixed
; use Ada
.Strings
.Fixed
;
36 with Ada
.Text_IO
; use Ada
.Text_IO
;
37 with GNAT
.Command_Line
; use GNAT
.Command_Line
;
38 with GNAT
.Strings
; use GNAT
.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
58 procedure Write_Usage
;
59 -- Print a small help page for program usage
65 procedure Parse_Cmd_Line
is
69 GNAT
.Command_Line
.Getopt
70 ("a aI: aO: d f g h I: nostdinc nostdlib p: u v -RTS=")
76 if GNAT
.Command_Line
.Full_Switch
= "a" then
79 elsif GNAT
.Command_Line
.Full_Switch
= "aI" then
80 Osint
.Add_Src_Search_Dir
(GNAT
.Command_Line
.Parameter
);
83 Osint
.Add_Lib_Search_Dir
(GNAT
.Command_Line
.Parameter
);
90 Full_Path_Name
:= True;
93 Local_Symbols
:= False;
99 Osint
.Add_Src_Search_Dir
(GNAT
.Command_Line
.Parameter
);
100 Osint
.Add_Lib_Search_Dir
(GNAT
.Command_Line
.Parameter
);
103 if GNAT
.Command_Line
.Full_Switch
= "nostdinc" then
104 Opt
.No_Stdinc
:= True;
105 elsif GNAT
.Command_Line
.Full_Switch
= "nostlib" then
106 Opt
.No_Stdlib
:= True;
111 S
: constant String := GNAT
.Command_Line
.Parameter
;
113 Prj_File_Length
:= S
'Length;
114 Prj_File
(1 .. Prj_File_Length
) := S
;
118 Search_Unused
:= True;
123 Search_Unused
:= False;
125 -- The only switch starting with -- recognized is --RTS
129 -- Check that it is the first time we see this switch
131 if RTS_Specified
= null then
132 RTS_Specified
:= new String'(GNAT.Command_Line.Parameter);
134 elsif RTS_Specified.all /= GNAT.Command_Line.Parameter then
135 Osint.Fail ("--RTS cannot be specified multiple times");
138 Opt.No_Stdinc := True;
139 Opt.RTS_Switch := True;
142 Src_Path_Name : constant String_Ptr :=
144 (GNAT.Command_Line.Parameter, Include);
146 Lib_Path_Name : constant String_Ptr :=
148 (GNAT.Command_Line.Parameter, Objects);
151 if Src_Path_Name /= null and then Lib_Path_Name /= null then
152 Add_Search_Dirs (Src_Path_Name, Include);
153 Add_Search_Dirs (Lib_Path_Name, Objects);
155 elsif Src_Path_Name = null and then Lib_Path_Name = null then
156 Osint.Fail ("RTS path not valid: missing " &
157 "adainclude and adalib directories");
159 elsif Src_Path_Name = null then
160 Osint.Fail ("RTS path not valid: missing " &
161 "adainclude directory");
163 elsif Lib_Path_Name = null then
164 Osint.Fail ("RTS path not valid: missing " &
174 -- Get the other arguments
178 S : constant String := GNAT.Command_Line.Get_Argument;
181 exit when S'Length = 0;
183 if Ada.Strings.Fixed.Index (S, ":") /= 0 then
185 ("Only file names are allowed on the command line");
195 when GNAT.Command_Line.Invalid_Switch =>
196 Ada.Text_IO.Put_Line ("Invalid switch : "
197 & GNAT.Command_Line.Full_Switch);
200 when GNAT.Command_Line.Invalid_Parameter =>
201 Ada.Text_IO.Put_Line ("Parameter missing for : "
202 & GNAT.Command_Line.Full_Switch);
210 procedure Write_Usage is
212 Put_Line ("GNATXREF " & Gnatvsn.Gnat_Version_String);
213 Put_Line ("Copyright 1998-2005, AdaCore");
214 Put_Line ("Usage: gnatxref [switches] file1 file2 ...");
216 Put_Line (" file ... list of source files to xref, " &
217 "including with'ed units");
219 Put_Line ("gnatxref switches:");
220 Put_Line (" -a Consider all files, even when the ali file is"
222 Put_Line (" -aIdir Specify source files search path");
223 Put_Line (" -aOdir Specify library/object files search path");
224 Put_Line (" -d Output derived type information");
225 Put_Line (" -f Output full path name");
226 Put_Line (" -g Output information only for global symbols");
227 Put_Line (" -Idir Like -aIdir -aOdir");
228 Put_Line (" -nostdinc Don't look for sources in the system default"
230 Put_Line (" -nostdlib Don't look for library files in the system"
231 & " default directory");
232 Put_Line (" --RTS=dir specify the default source and object search"
234 Put_Line (" -p file Use file as the default project file");
235 Put_Line (" -u List unused entities");
236 Put_Line (" -v Print a 'tags
' file for vi");
245 if not Have_File then
249 Xr_Tabls.Set_Default_Match (True);
251 -- Find the project file
253 if Prj_File_Length = 0 then
254 Xr_Tabls.Create_Project_File
255 (Default_Project_File (Osint.To_Host_Dir_Spec (".", False).all));
257 Xr_Tabls.Create_Project_File (Prj_File (1 .. Prj_File_Length));
262 Search_Xref (Local_Symbols, Read_Only, Der_Info);
264 if Search_Unused then
265 Print_Unused (Full_Path_Name);
267 Print_Vi (Full_Path_Name);
269 Print_Xref (Full_Path_Name);