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 -- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). --
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
;
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 procedure Parse_Cmd_Line
;
53 -- Parse every switch on the command line
55 procedure Write_Usage
;
56 -- Print a small help page for program usage
62 procedure Parse_Cmd_Line
is
66 GNAT
.Command_Line
.Getopt
67 ("a aI: aO: d f g h I: nostdinc nostdlib p: u v -RTS=")
73 if GNAT
.Command_Line
.Full_Switch
= "a" then
76 elsif GNAT
.Command_Line
.Full_Switch
= "aI" then
77 Osint
.Add_Src_Search_Dir
(GNAT
.Command_Line
.Parameter
);
80 Osint
.Add_Lib_Search_Dir
(GNAT
.Command_Line
.Parameter
);
87 Full_Path_Name
:= True;
90 Local_Symbols
:= False;
96 Osint
.Add_Src_Search_Dir
(GNAT
.Command_Line
.Parameter
);
97 Osint
.Add_Lib_Search_Dir
(GNAT
.Command_Line
.Parameter
);
100 if GNAT
.Command_Line
.Full_Switch
= "nostdinc" then
101 Opt
.No_Stdinc
:= True;
102 elsif GNAT
.Command_Line
.Full_Switch
= "nostlib" then
103 Opt
.No_Stdlib
:= True;
108 S
: constant String := GNAT
.Command_Line
.Parameter
;
111 Prj_File_Length
:= S
'Length;
112 Prj_File
(1 .. Prj_File_Length
) := S
;
116 Search_Unused
:= True;
121 Search_Unused
:= False;
123 -- The only switch starting with -- recognized is --RTS
126 Opt
.No_Stdinc
:= True;
127 Opt
.RTS_Switch
:= True;
130 Src_Path_Name
: String_Ptr
:=
132 (GNAT
.Command_Line
.Parameter
, Include
);
134 Lib_Path_Name
: String_Ptr
:=
136 (GNAT
.Command_Line
.Parameter
, Objects
);
139 if Src_Path_Name
/= null and then Lib_Path_Name
/= null then
140 Add_Search_Dirs
(Src_Path_Name
, Include
);
141 Add_Search_Dirs
(Lib_Path_Name
, Objects
);
143 elsif Src_Path_Name
= null and then Lib_Path_Name
= null then
144 Osint
.Fail
("RTS path not valid: missing " &
145 "adainclude and adalib directories");
147 elsif Src_Path_Name
= null then
148 Osint
.Fail
("RTS path not valid: missing " &
149 "adainclude directory");
151 elsif Lib_Path_Name
= null then
152 Osint
.Fail
("RTS path not valid: missing " &
162 -- Get the other arguments
166 S
: constant String := GNAT
.Command_Line
.Get_Argument
;
169 exit when S
'Length = 0;
171 if Ada
.Strings
.Fixed
.Index
(S
, ":") /= 0 then
173 ("Only file names are allowed on the command line");
183 when GNAT
.Command_Line
.Invalid_Switch
=>
184 Ada
.Text_IO
.Put_Line
("Invalid switch : "
185 & GNAT
.Command_Line
.Full_Switch
);
188 when GNAT
.Command_Line
.Invalid_Parameter
=>
189 Ada
.Text_IO
.Put_Line
("Parameter missing for : "
190 & GNAT
.Command_Line
.Full_Switch
);
198 procedure Write_Usage
is
202 Put_Line
("GNATXREF " & Gnatvsn
.Gnat_Version_String
203 & " Copyright 1998-2002, Ada Core Technologies Inc.");
204 Put_Line
("Usage: gnatxref [switches] file1 file2 ...");
206 Put_Line
(" file ... list of source files to xref, " &
207 "including with'ed units");
209 Put_Line
("gnatxref switches:");
210 Put_Line
(" -a Consider all files, even when the ali file is"
212 Put_Line
(" -aIdir Specify source files search path");
213 Put_Line
(" -aOdir Specify library/object files search path");
214 Put_Line
(" -d Output derived type information");
215 Put_Line
(" -f Output full path name");
216 Put_Line
(" -g Output information only for global symbols");
217 Put_Line
(" -Idir Like -aIdir -aOdir");
218 Put_Line
(" -nostdinc Don't look for sources in the system default"
220 Put_Line
(" -nostdlib Don't look for library files in the system"
221 & " default directory");
222 Put_Line
(" --RTS=dir specify the default source and object search"
224 Put_Line
(" -p file Use file as the default project file");
225 Put_Line
(" -u List unused entities");
226 Put_Line
(" -v Print a 'tags' file for vi");
235 if not Have_File
then
239 Xr_Tabls
.Set_Default_Match
(True);
241 -- Find the project file
243 if Prj_File_Length
= 0 then
244 Xr_Tabls
.Create_Project_File
245 (Default_Project_File
(Osint
.To_Host_Dir_Spec
(".", False).all));
247 Xr_Tabls
.Create_Project_File
(Prj_File
(1 .. Prj_File_Length
));
252 Search_Xref
(Local_Symbols
, Read_Only
, Der_Info
);
254 if Search_Unused
then
255 Print_Unused
(Full_Path_Name
);
257 Print_Vi
(Full_Path_Name
);
259 Print_Xref
(Full_Path_Name
);