1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1998-2003 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 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
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;
38 with GNAT.Strings; use GNAT.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 procedure Parse_Cmd_Line;
57 -- Parse every switch on the command line
59 procedure Write_Usage;
60 -- Print a small help page for program usage
66 procedure Parse_Cmd_Line is
70 GNAT.Command_Line.Getopt
71 ("a aI: aO: d f g h I: nostdinc nostdlib p: u v -RTS=")
77 if GNAT.Command_Line.Full_Switch = "a" then
80 elsif GNAT.Command_Line.Full_Switch = "aI" then
81 Osint.Add_Src_Search_Dir (GNAT.Command_Line.Parameter);
84 Osint.Add_Lib_Search_Dir (GNAT.Command_Line.Parameter);
91 Full_Path_Name := True;
94 Local_Symbols := False;
100 Osint.Add_Src_Search_Dir (GNAT.Command_Line.Parameter);
101 Osint.Add_Lib_Search_Dir (GNAT.Command_Line.Parameter);
104 if GNAT.Command_Line.Full_Switch = "nostdinc" then
105 Opt.No_Stdinc := True;
106 elsif GNAT.Command_Line.Full_Switch = "nostlib" then
107 Opt.No_Stdlib := True;
112 S : constant String := GNAT.Command_Line.Parameter;
115 Prj_File_Length := S'Length;
116 Prj_File (1 .. Prj_File_Length) := S;
120 Search_Unused := True;
125 Search_Unused := False;
127 -- The only switch starting with -- recognized is --RTS
130 -- Check that it is the first time we see this switch
132 if RTS_Specified = null then
133 RTS_Specified := new String'(GNAT.Command_Line.Parameter);
135 elsif RTS_Specified.all /= GNAT.Command_Line.Parameter then
136 Osint.Fail ("--RTS cannot be specified multiple times");
139 Opt.No_Stdinc := True;
140 Opt.RTS_Switch := True;
143 Src_Path_Name : constant String_Ptr :=
145 (GNAT.Command_Line.Parameter, Include);
147 Lib_Path_Name : constant String_Ptr :=
149 (GNAT.Command_Line.Parameter, Objects);
152 if Src_Path_Name /= null and then Lib_Path_Name /= null then
153 Add_Search_Dirs (Src_Path_Name, Include);
154 Add_Search_Dirs (Lib_Path_Name, Objects);
156 elsif Src_Path_Name = null and then Lib_Path_Name = null then
157 Osint.Fail ("RTS path not valid: missing " &
158 "adainclude and adalib directories");
160 elsif Src_Path_Name = null then
161 Osint.Fail ("RTS path not valid: missing " &
162 "adainclude directory");
164 elsif Lib_Path_Name = null then
165 Osint.Fail ("RTS path not valid: missing " &
175 -- Get the other arguments
179 S : constant String := GNAT.Command_Line.Get_Argument;
182 exit when S'Length = 0;
184 if Ada.Strings.Fixed.Index (S, ":") /= 0 then
186 ("Only file names are allowed on the command line");
196 when GNAT.Command_Line.Invalid_Switch =>
197 Ada.Text_IO.Put_Line ("Invalid switch : "
198 & GNAT.Command_Line.Full_Switch);
201 when GNAT.Command_Line.Invalid_Parameter =>
202 Ada.Text_IO.Put_Line ("Parameter missing for : "
203 & GNAT.Command_Line.Full_Switch);
211 procedure Write_Usage is
215 Put_Line ("GNATXREF " & Gnatvsn.Gnat_Version_String
216 & " Copyright 1998-2003, Ada Core Technologies Inc.");
217 Put_Line ("Usage: gnatxref [switches] file1 file2 ...");
219 Put_Line (" file ... list of source files to xref, " &
220 "including with'ed units");
222 Put_Line ("gnatxref switches:");
223 Put_Line (" -a Consider all files, even when the ali file is"
225 Put_Line (" -aIdir Specify source files search path");
226 Put_Line (" -aOdir Specify library/object files search path");
227 Put_Line (" -d Output derived type information");
228 Put_Line (" -f Output full path name");
229 Put_Line (" -g Output information only for global symbols");
230 Put_Line (" -Idir Like -aIdir -aOdir");
231 Put_Line (" -nostdinc Don't look for sources in the system default"
233 Put_Line (" -nostdlib Don't look for library files in the system"
234 & " default directory");
235 Put_Line (" --RTS=dir specify the default source and object search"
237 Put_Line (" -p file Use file as the default project file");
238 Put_Line (" -u List unused entities");
239 Put_Line (" -v Print a 'tags' file for vi");
248 if not Have_File then
252 Xr_Tabls.Set_Default_Match (True);
254 -- Find the project file
256 if Prj_File_Length = 0 then
257 Xr_Tabls.Create_Project_File
258 (Default_Project_File (Osint.To_Host_Dir_Spec (".", False).all));
260 Xr_Tabls.Create_Project_File (Prj_File (1 .. Prj_File_Length));
265 Search_Xref (Local_Symbols, Read_Only, Der_Info);
267 if Search_Unused then
268 Print_Unused (Full_Path_Name);
270 Print_Vi (Full_Path_Name);
272 Print_Xref (Full_Path_Name);