1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1998-2014, 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
.Command_Line
; use Ada
.Command_Line
;
34 with Ada
.Strings
.Fixed
; use Ada
.Strings
.Fixed
;
35 with Ada
.Text_IO
; use Ada
.Text_IO
;
37 with GNAT
.Command_Line
; use GNAT
.Command_Line
;
39 with System
.Strings
; use System
.Strings
;
42 Search_Unused
: Boolean := False;
43 Local_Symbols
: Boolean := True;
44 Prj_File
: File_Name_String
;
45 Prj_File_Length
: Natural := 0;
46 Usage_Error
: exception;
47 Full_Path_Name
: Boolean := False;
48 Vi_Mode
: Boolean := False;
49 Read_Only
: Boolean := False;
50 Have_File
: Boolean := False;
51 Der_Info
: Boolean := False;
53 RTS_Specified
: String_Access
:= null;
54 -- Used to detect multiple use of --RTS= switch
56 EXT_Specified
: String_Access
:= null;
57 -- Used to detect multiple use of --ext= switch
59 procedure Parse_Cmd_Line
;
60 -- Parse every switch on the command line
65 procedure Write_Usage
;
66 -- Print a small help page for program usage
72 procedure Parse_Cmd_Line
is
74 procedure Check_Version_And_Help
is new Check_Version_And_Help_G
(Usage
);
76 -- Start of processing for Parse_Cmd_Line
79 -- First check for --version or --help
81 Check_Version_And_Help
("GNATXREF", "1998");
85 GNAT
.Command_Line
.Getopt
86 ("a aI: aO: d f g h I: nostdinc nostdlib p: u v -RTS= -ext=")
92 if GNAT
.Command_Line
.Full_Switch
= "a" then
95 elsif GNAT
.Command_Line
.Full_Switch
= "aI" then
96 Osint
.Add_Src_Search_Dir
(GNAT
.Command_Line
.Parameter
);
99 Osint
.Add_Lib_Search_Dir
(GNAT
.Command_Line
.Parameter
);
106 Full_Path_Name
:= True;
109 Local_Symbols
:= False;
115 Osint
.Add_Src_Search_Dir
(GNAT
.Command_Line
.Parameter
);
116 Osint
.Add_Lib_Search_Dir
(GNAT
.Command_Line
.Parameter
);
119 if GNAT
.Command_Line
.Full_Switch
= "nostdinc" then
120 Opt
.No_Stdinc
:= True;
121 elsif GNAT
.Command_Line
.Full_Switch
= "nostdlib" then
122 Opt
.No_Stdlib
:= True;
127 S
: constant String := GNAT
.Command_Line
.Parameter
;
129 Prj_File_Length
:= S
'Length;
130 Prj_File
(1 .. Prj_File_Length
) := S
;
134 Search_Unused
:= True;
139 Search_Unused
:= False;
141 -- The only switch starting with -- recognized is --RTS
145 -- Check that it is the first time we see this switch
147 if Full_Switch
= "-RTS" then
148 if RTS_Specified
= null then
149 RTS_Specified
:= new String'(GNAT.Command_Line.Parameter);
151 elsif RTS_Specified.all /= GNAT.Command_Line.Parameter then
152 Osint.Fail ("--RTS cannot be specified multiple times");
155 Opt.No_Stdinc := True;
156 Opt.RTS_Switch := True;
159 Src_Path_Name : constant String_Ptr :=
161 (GNAT.Command_Line.Parameter,
164 Lib_Path_Name : constant String_Ptr :=
166 (GNAT.Command_Line.Parameter,
170 if Src_Path_Name /= null
171 and then Lib_Path_Name /= null
173 Add_Search_Dirs (Src_Path_Name, Include);
174 Add_Search_Dirs (Lib_Path_Name, Objects);
176 elsif Src_Path_Name = null
177 and then Lib_Path_Name = null
179 Osint.Fail ("RTS path not valid: missing " &
180 "adainclude and adalib directories");
182 elsif Src_Path_Name = null then
183 Osint.Fail ("RTS path not valid: missing " &
184 "adainclude directory");
186 elsif Lib_Path_Name = null then
187 Osint.Fail ("RTS path not valid: missing " &
192 elsif GNAT.Command_Line.Full_Switch = "-ext" then
194 -- Check that it is the first time we see this switch
196 if EXT_Specified = null then
197 EXT_Specified := new String'(GNAT
.Command_Line
.Parameter
);
199 elsif EXT_Specified
.all /= GNAT
.Command_Line
.Parameter
then
200 Osint
.Fail
("--ext cannot be specified multiple times");
203 if EXT_Specified
'Length
204 = Osint
.ALI_Default_Suffix
'Length
206 Osint
.ALI_Suffix
:= EXT_Specified
.all'Access;
208 Osint
.Fail
("--ext argument must have 3 characters");
218 -- Get the other arguments
222 S
: constant String := GNAT
.Command_Line
.Get_Argument
;
225 exit when S
'Length = 0;
227 if Ada
.Strings
.Fixed
.Index
(S
, ":") /= 0 then
229 ("Only file names are allowed on the command line");
240 when GNAT
.Command_Line
.Invalid_Switch
=>
241 Ada
.Text_IO
.Put_Line
("Invalid switch : "
242 & GNAT
.Command_Line
.Full_Switch
);
246 when GNAT
.Command_Line
.Invalid_Parameter
=>
247 Ada
.Text_IO
.Put_Line
("Parameter missing for : "
248 & GNAT
.Command_Line
.Full_Switch
);
259 Put_Line
("Usage: gnatxref [switches] file1 file2 ...");
261 Put_Line
(" file ... list of source files to xref, " &
262 "including with'ed units");
264 Put_Line
("gnatxref switches:");
265 Display_Usage_Version_And_Help
;
266 Put_Line
(" -a Consider all files, even when the ali file is"
268 Put_Line
(" -aIdir Specify source files search path");
269 Put_Line
(" -aOdir Specify library/object files search path");
270 Put_Line
(" -d Output derived type information");
271 Put_Line
(" -f Output full path name");
272 Put_Line
(" -g Output information only for global symbols");
273 Put_Line
(" -Idir Like -aIdir -aOdir");
274 Put_Line
(" -nostdinc Don't look for sources in the system default"
276 Put_Line
(" -nostdlib Don't look for library files in the system"
277 & " default directory");
278 Put_Line
(" --ext=xxx Specify alternate ali file extension");
279 Put_Line
(" --RTS=dir specify the default source and object search"
281 Put_Line
(" -p file Use file as the default project file");
282 Put_Line
(" -u List unused entities");
283 Put_Line
(" -v Print a 'tags' file for vi");
292 procedure Write_Usage
is
294 Display_Version
("GNATXREF", "1998");
303 if not Have_File
then
304 if Argument_Count
= 0 then
312 Xr_Tabls
.Set_Default_Match
(True);
314 -- Find the project file
316 if Prj_File_Length
= 0 then
317 Xr_Tabls
.Create_Project_File
318 (Default_Project_File
(Osint
.To_Host_Dir_Spec
(".", False).all));
320 Xr_Tabls
.Create_Project_File
(Prj_File
(1 .. Prj_File_Length
));
325 Search_Xref
(Local_Symbols
, Read_Only
, Der_Info
);
327 if Search_Unused
then
328 Print_Unused
(Full_Path_Name
);
330 Print_Vi
(Full_Path_Name
);
332 Print_Xref
(Full_Path_Name
);