1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1998-2002 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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 ------------------------------------------------------------------------------
24 with Xr_Tabls
; use Xr_Tabls
;
25 with Xref_Lib
; use Xref_Lib
;
26 with Osint
; use Osint
;
27 with Types
; use Types
;
32 with Ada
.Strings
.Fixed
; use Ada
.Strings
.Fixed
;
33 with Ada
.Text_IO
; use Ada
.Text_IO
;
34 with GNAT
.Command_Line
; use GNAT
.Command_Line
;
38 Search_Unused
: Boolean := False;
39 Local_Symbols
: Boolean := True;
40 Prj_File
: File_Name_String
;
41 Prj_File_Length
: Natural := 0;
42 Usage_Error
: exception;
43 Full_Path_Name
: Boolean := False;
44 Vi_Mode
: Boolean := False;
45 Read_Only
: Boolean := False;
46 Have_File
: Boolean := False;
47 Der_Info
: Boolean := False;
49 procedure Parse_Cmd_Line
;
50 -- Parse every switch on the command line
52 procedure Write_Usage
;
53 -- Print a small help page for program usage
59 procedure Parse_Cmd_Line
is
63 GNAT
.Command_Line
.Getopt
64 ("a aI: aO: d f g h I: nostdinc nostdlib p: u v -RTS=")
70 if GNAT
.Command_Line
.Full_Switch
= "a" then
73 elsif GNAT
.Command_Line
.Full_Switch
= "aI" then
74 Osint
.Add_Src_Search_Dir
(GNAT
.Command_Line
.Parameter
);
77 Osint
.Add_Lib_Search_Dir
(GNAT
.Command_Line
.Parameter
);
84 Full_Path_Name
:= True;
87 Local_Symbols
:= False;
93 Osint
.Add_Src_Search_Dir
(GNAT
.Command_Line
.Parameter
);
94 Osint
.Add_Lib_Search_Dir
(GNAT
.Command_Line
.Parameter
);
97 if GNAT
.Command_Line
.Full_Switch
= "nostdinc" then
98 Opt
.No_Stdinc
:= True;
99 elsif GNAT
.Command_Line
.Full_Switch
= "nostlib" then
100 Opt
.No_Stdlib
:= True;
105 S
: constant String := GNAT
.Command_Line
.Parameter
;
108 Prj_File_Length
:= S
'Length;
109 Prj_File
(1 .. Prj_File_Length
) := S
;
113 Search_Unused
:= True;
118 Search_Unused
:= False;
120 -- The only switch starting with -- recognized is --RTS
123 Opt
.No_Stdinc
:= True;
124 Opt
.RTS_Switch
:= True;
127 Src_Path_Name
: String_Ptr
:=
129 (GNAT
.Command_Line
.Parameter
, Include
);
131 Lib_Path_Name
: String_Ptr
:=
133 (GNAT
.Command_Line
.Parameter
, Objects
);
136 if Src_Path_Name
/= null and then Lib_Path_Name
/= null then
137 Add_Search_Dirs
(Src_Path_Name
, Include
);
138 Add_Search_Dirs
(Lib_Path_Name
, Objects
);
140 elsif Src_Path_Name
= null and then Lib_Path_Name
= null then
141 Osint
.Fail
("RTS path not valid: missing " &
142 "adainclude and adalib directories");
144 elsif Src_Path_Name
= null then
145 Osint
.Fail
("RTS path not valid: missing " &
146 "adainclude directory");
148 elsif Lib_Path_Name
= null then
149 Osint
.Fail
("RTS path not valid: missing " &
159 -- Get the other arguments
163 S
: constant String := GNAT
.Command_Line
.Get_Argument
;
166 exit when S
'Length = 0;
168 if Ada
.Strings
.Fixed
.Index
(S
, ":") /= 0 then
170 ("Only file names are allowed on the command line");
180 when GNAT
.Command_Line
.Invalid_Switch
=>
181 Ada
.Text_IO
.Put_Line
("Invalid switch : "
182 & GNAT
.Command_Line
.Full_Switch
);
185 when GNAT
.Command_Line
.Invalid_Parameter
=>
186 Ada
.Text_IO
.Put_Line
("Parameter missing for : "
187 & GNAT
.Command_Line
.Full_Switch
);
195 procedure Write_Usage
is
199 Put_Line
("GNATXREF " & Gnatvsn
.Gnat_Version_String
200 & " Copyright 1998-2002, Ada Core Technologies Inc.");
201 Put_Line
("Usage: gnatxref [switches] file1 file2 ...");
203 Put_Line
(" file ... list of source files to xref, " &
204 "including with'ed units");
206 Put_Line
("gnatxref switches:");
207 Put_Line
(" -a Consider all files, even when the ali file is"
209 Put_Line
(" -aIdir Specify source files search path");
210 Put_Line
(" -aOdir Specify library/object files search path");
211 Put_Line
(" -d Output derived type information");
212 Put_Line
(" -f Output full path name");
213 Put_Line
(" -g Output information only for global symbols");
214 Put_Line
(" -Idir Like -aIdir -aOdir");
215 Put_Line
(" -nostdinc Don't look for sources in the system default"
217 Put_Line
(" -nostdlib Don't look for library files in the system"
218 & " default directory");
219 Put_Line
(" --RTS=dir specify the default source and object search"
221 Put_Line
(" -p file Use file as the default project file");
222 Put_Line
(" -u List unused entities");
223 Put_Line
(" -v Print a 'tags' file for vi");
232 if not Have_File
then
236 Xr_Tabls
.Set_Default_Match
(True);
238 -- Find the project file
240 if Prj_File_Length
= 0 then
241 Xr_Tabls
.Create_Project_File
242 (Default_Project_File
(Osint
.To_Host_Dir_Spec
(".", False).all));
244 Xr_Tabls
.Create_Project_File
(Prj_File
(1 .. Prj_File_Length
));
249 Search_Xref
(Local_Symbols
, Read_Only
, Der_Info
);
251 if Search_Unused
then
252 Print_Unused
(Full_Path_Name
);
254 Print_Vi
(Full_Path_Name
);
256 Print_Xref
(Full_Path_Name
);