1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1998-2008, 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
.Strings
.Fixed
; use Ada
.Strings
.Fixed
;
34 with Ada
.Text_IO
; use Ada
.Text_IO
;
36 with GNAT
.Command_Line
; use GNAT
.Command_Line
;
38 with System
.Strings
; use System
.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
61 procedure Write_Usage
;
62 -- Print a small help page for program usage
68 procedure Parse_Cmd_Line
is
70 procedure Check_Version_And_Help
is new Check_Version_And_Help_G
(Usage
);
72 -- Start of processing for Parse_Cmd_Line
75 -- First check for --version or --help
77 Check_Version_And_Help
("GNATXREF", "1998");
81 GNAT
.Command_Line
.Getopt
82 ("a aI: aO: d f g h I: nostdinc nostdlib p: u v -RTS=")
88 if GNAT
.Command_Line
.Full_Switch
= "a" then
91 elsif GNAT
.Command_Line
.Full_Switch
= "aI" then
92 Osint
.Add_Src_Search_Dir
(GNAT
.Command_Line
.Parameter
);
95 Osint
.Add_Lib_Search_Dir
(GNAT
.Command_Line
.Parameter
);
102 Full_Path_Name
:= True;
105 Local_Symbols
:= False;
111 Osint
.Add_Src_Search_Dir
(GNAT
.Command_Line
.Parameter
);
112 Osint
.Add_Lib_Search_Dir
(GNAT
.Command_Line
.Parameter
);
115 if GNAT
.Command_Line
.Full_Switch
= "nostdinc" then
116 Opt
.No_Stdinc
:= True;
117 elsif GNAT
.Command_Line
.Full_Switch
= "nostdlib" then
118 Opt
.No_Stdlib
:= True;
123 S
: constant String := GNAT
.Command_Line
.Parameter
;
125 Prj_File_Length
:= S
'Length;
126 Prj_File
(1 .. Prj_File_Length
) := S
;
130 Search_Unused
:= True;
135 Search_Unused
:= False;
137 -- The only switch starting with -- recognized is --RTS
141 -- Check that it is the first time we see this switch
143 if RTS_Specified
= null then
144 RTS_Specified
:= new String'(GNAT.Command_Line.Parameter);
146 elsif RTS_Specified.all /= GNAT.Command_Line.Parameter then
147 Osint.Fail ("--RTS cannot be specified multiple times");
150 Opt.No_Stdinc := True;
151 Opt.RTS_Switch := True;
154 Src_Path_Name : constant String_Ptr :=
156 (GNAT.Command_Line.Parameter, Include);
158 Lib_Path_Name : constant String_Ptr :=
160 (GNAT.Command_Line.Parameter, Objects);
163 if Src_Path_Name /= null and then Lib_Path_Name /= null then
164 Add_Search_Dirs (Src_Path_Name, Include);
165 Add_Search_Dirs (Lib_Path_Name, Objects);
167 elsif Src_Path_Name = null and then Lib_Path_Name = null then
168 Osint.Fail ("RTS path not valid: missing " &
169 "adainclude and adalib directories");
171 elsif Src_Path_Name = null then
172 Osint.Fail ("RTS path not valid: missing " &
173 "adainclude directory");
175 elsif Lib_Path_Name = null then
176 Osint.Fail ("RTS path not valid: missing " &
186 -- Get the other arguments
190 S : constant String := GNAT.Command_Line.Get_Argument;
193 exit when S'Length = 0;
195 if Ada.Strings.Fixed.Index (S, ":") /= 0 then
197 ("Only file names are allowed on the command line");
207 when GNAT.Command_Line.Invalid_Switch =>
208 Ada.Text_IO.Put_Line ("Invalid switch : "
209 & GNAT.Command_Line.Full_Switch);
212 when GNAT.Command_Line.Invalid_Parameter =>
213 Ada.Text_IO.Put_Line ("Parameter missing for : "
214 & GNAT.Command_Line.Full_Switch);
224 Put_Line ("Usage: gnatxref [switches] file1 file2 ...");
226 Put_Line (" file ... list of source files to xref, " &
227 "including with'ed units");
229 Put_Line ("gnatxref switches:");
230 Put_Line (" -a Consider all files, even when the ali file is"
232 Put_Line (" -aIdir Specify source files search path");
233 Put_Line (" -aOdir Specify library/object files search path");
234 Put_Line (" -d Output derived type information");
235 Put_Line (" -f Output full path name");
236 Put_Line (" -g Output information only for global symbols");
237 Put_Line (" -Idir Like -aIdir -aOdir");
238 Put_Line (" -nostdinc Don't look for sources in the system default"
240 Put_Line (" -nostdlib Don't look for library files in the system"
241 & " default directory");
242 Put_Line (" --RTS=dir specify the default source and object search"
244 Put_Line (" -p file Use file as the default project file");
245 Put_Line (" -u List unused entities");
246 Put_Line (" -v Print a 'tags
' file for vi");
255 procedure Write_Usage is
257 Display_Version ("GNATXREF", "1998");
266 if not Have_File then
270 Xr_Tabls.Set_Default_Match (True);
272 -- Find the project file
274 if Prj_File_Length = 0 then
275 Xr_Tabls.Create_Project_File
276 (Default_Project_File (Osint.To_Host_Dir_Spec (".", False).all));
278 Xr_Tabls.Create_Project_File (Prj_File (1 .. Prj_File_Length));
283 Search_Xref (Local_Symbols, Read_Only, Der_Info);
285 if Search_Unused then
286 Print_Unused (Full_Path_Name);
288 Print_Vi (Full_Path_Name);
290 Print_Xref (Full_Path_Name);