1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 1998-2002 Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 ------------------------------------------------------------------------------
25 with Xr_Tabls
; use Xr_Tabls
;
26 with Xref_Lib
; use Xref_Lib
;
27 with Osint
; use Osint
;
28 with Types
; use Types
;
33 with Ada
.Strings
.Fixed
; use Ada
.Strings
.Fixed
;
34 with Ada
.Text_IO
; use Ada
.Text_IO
;
35 with GNAT
.Command_Line
; use GNAT
.Command_Line
;
39 Search_Unused
: Boolean := False;
40 Local_Symbols
: Boolean := True;
41 Prj_File
: File_Name_String
;
42 Prj_File_Length
: Natural := 0;
43 Usage_Error
: exception;
44 Full_Path_Name
: Boolean := False;
45 Vi_Mode
: Boolean := False;
46 Read_Only
: Boolean := False;
47 Have_File
: Boolean := False;
48 Der_Info
: Boolean := False;
50 procedure Parse_Cmd_Line
;
51 -- Parse every switch on the command line
53 procedure Write_Usage
;
54 -- Print a small help page for program usage
60 procedure Parse_Cmd_Line
is
64 GNAT
.Command_Line
.Getopt
65 ("a aI: aO: d f g h I: nostdinc nostdlib p: u v -RTS=")
71 if GNAT
.Command_Line
.Full_Switch
= "a" then
74 elsif GNAT
.Command_Line
.Full_Switch
= "aI" then
75 Osint
.Add_Src_Search_Dir
(GNAT
.Command_Line
.Parameter
);
78 Osint
.Add_Lib_Search_Dir
(GNAT
.Command_Line
.Parameter
);
85 Full_Path_Name
:= True;
88 Local_Symbols
:= False;
94 Osint
.Add_Src_Search_Dir
(GNAT
.Command_Line
.Parameter
);
95 Osint
.Add_Lib_Search_Dir
(GNAT
.Command_Line
.Parameter
);
98 if GNAT
.Command_Line
.Full_Switch
= "nostdinc" then
99 Opt
.No_Stdinc
:= True;
100 elsif GNAT
.Command_Line
.Full_Switch
= "nostlib" then
101 Opt
.No_Stdlib
:= True;
106 S
: constant String := GNAT
.Command_Line
.Parameter
;
109 Prj_File_Length
:= S
'Length;
110 Prj_File
(1 .. Prj_File_Length
) := S
;
114 Search_Unused
:= True;
119 Search_Unused
:= False;
121 -- The only switch starting with -- recognized is --RTS
124 Opt
.No_Stdinc
:= True;
125 Opt
.RTS_Switch
:= True;
128 Src_Path_Name
: String_Ptr
:=
130 (GNAT
.Command_Line
.Parameter
, Include
);
132 Lib_Path_Name
: String_Ptr
:=
134 (GNAT
.Command_Line
.Parameter
, Objects
);
137 if Src_Path_Name
/= null and then Lib_Path_Name
/= null then
138 Add_Search_Dirs
(Src_Path_Name
, Include
);
139 Add_Search_Dirs
(Lib_Path_Name
, Objects
);
141 elsif Src_Path_Name
= null and then Lib_Path_Name
= null then
142 Osint
.Fail
("RTS path not valid: missing " &
143 "adainclude and adalib directories");
145 elsif Src_Path_Name
= null then
146 Osint
.Fail
("RTS path not valid: missing " &
147 "adainclude directory");
149 elsif Lib_Path_Name
= null then
150 Osint
.Fail
("RTS path not valid: missing " &
160 -- Get the other arguments
164 S
: constant String := GNAT
.Command_Line
.Get_Argument
;
167 exit when S
'Length = 0;
169 if Ada
.Strings
.Fixed
.Index
(S
, ":") /= 0 then
171 ("Only file names are allowed on the command line");
181 when GNAT
.Command_Line
.Invalid_Switch
=>
182 Ada
.Text_IO
.Put_Line
("Invalid switch : "
183 & GNAT
.Command_Line
.Full_Switch
);
186 when GNAT
.Command_Line
.Invalid_Parameter
=>
187 Ada
.Text_IO
.Put_Line
("Parameter missing for : "
188 & GNAT
.Command_Line
.Full_Switch
);
196 procedure Write_Usage
is
200 Put_Line
("GNATXREF " & Gnatvsn
.Gnat_Version_String
201 & " Copyright 1998-2002, Ada Core Technologies Inc.");
202 Put_Line
("Usage: gnatxref [switches] file1 file2 ...");
204 Put_Line
(" file ... list of source files to xref, " &
205 "including with'ed units");
207 Put_Line
("gnatxref switches:");
208 Put_Line
(" -a Consider all files, even when the ali file is"
210 Put_Line
(" -aIdir Specify source files search path");
211 Put_Line
(" -aOdir Specify library/object files search path");
212 Put_Line
(" -d Output derived type information");
213 Put_Line
(" -f Output full path name");
214 Put_Line
(" -g Output information only for global symbols");
215 Put_Line
(" -Idir Like -aIdir -aOdir");
216 Put_Line
(" -nostdinc Don't look for sources in the system default"
218 Put_Line
(" -nostdlib Don't look for library files in the system"
219 & " default directory");
220 Put_Line
(" --RTS=dir specify the default source and object search"
222 Put_Line
(" -p file Use file as the default project file");
223 Put_Line
(" -u List unused entities");
224 Put_Line
(" -v Print a 'tags' file for vi");
233 if not Have_File
then
237 Xr_Tabls
.Set_Default_Match
(True);
239 -- Find the project file
241 if Prj_File_Length
= 0 then
242 Xr_Tabls
.Create_Project_File
243 (Default_Project_File
(Osint
.To_Host_Dir_Spec
(".", False).all));
245 Xr_Tabls
.Create_Project_File
(Prj_File
(1 .. Prj_File_Length
));
250 Search_Xref
(Local_Symbols
, Read_Only
, Der_Info
);
252 if Search_Unused
then
253 Print_Unused
(Full_Path_Name
);
255 Print_Vi
(Full_Path_Name
);
257 Print_Xref
(Full_Path_Name
);