1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1998-2007, 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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;
38 with GNAT.Command_Line; use GNAT.Command_Line;
40 with System.Strings; use System.Strings;
43 Search_Unused : Boolean := False;
44 Local_Symbols : Boolean := True;
45 Prj_File : File_Name_String;
46 Prj_File_Length : Natural := 0;
47 Usage_Error : exception;
48 Full_Path_Name : Boolean := False;
49 Vi_Mode : Boolean := False;
50 Read_Only : Boolean := False;
51 Have_File : Boolean := False;
52 Der_Info : Boolean := False;
54 RTS_Specified : String_Access := null;
55 -- Used to detect multiple use of --RTS= switch
57 procedure Parse_Cmd_Line;
58 -- Parse every switch on the command line
60 procedure Write_Usage;
61 -- Print a small help page for program usage
67 procedure Parse_Cmd_Line is
71 GNAT.Command_Line.Getopt
72 ("a aI: aO: d f g h I: nostdinc nostdlib p: u v -RTS=")
78 if GNAT.Command_Line.Full_Switch = "a" then
81 elsif GNAT.Command_Line.Full_Switch = "aI" then
82 Osint.Add_Src_Search_Dir (GNAT.Command_Line.Parameter);
85 Osint.Add_Lib_Search_Dir (GNAT.Command_Line.Parameter);
92 Full_Path_Name := True;
95 Local_Symbols := False;
101 Osint.Add_Src_Search_Dir (GNAT.Command_Line.Parameter);
102 Osint.Add_Lib_Search_Dir (GNAT.Command_Line.Parameter);
105 if GNAT.Command_Line.Full_Switch = "nostdinc" then
106 Opt.No_Stdinc := True;
107 elsif GNAT.Command_Line.Full_Switch = "nostlib" then
108 Opt.No_Stdlib := True;
113 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
131 -- Check that it is the first time we see this switch
133 if RTS_Specified = null then
134 RTS_Specified := new String'(GNAT.Command_Line.Parameter);
136 elsif RTS_Specified.all /= GNAT.Command_Line.Parameter then
137 Osint.Fail ("--RTS cannot be specified multiple times");
140 Opt.No_Stdinc := True;
141 Opt.RTS_Switch := True;
144 Src_Path_Name : constant String_Ptr :=
146 (GNAT.Command_Line.Parameter, Include);
148 Lib_Path_Name : constant String_Ptr :=
150 (GNAT.Command_Line.Parameter, Objects);
153 if Src_Path_Name /= null and then Lib_Path_Name /= null then
154 Add_Search_Dirs (Src_Path_Name, Include);
155 Add_Search_Dirs (Lib_Path_Name, Objects);
157 elsif Src_Path_Name = null and then Lib_Path_Name = null then
158 Osint.Fail ("RTS path not valid: missing " &
159 "adainclude and adalib directories");
161 elsif Src_Path_Name = null then
162 Osint.Fail ("RTS path not valid: missing " &
163 "adainclude directory");
165 elsif Lib_Path_Name = null then
166 Osint.Fail ("RTS path not valid: missing " &
176 -- Get the other arguments
180 S : constant String := GNAT.Command_Line.Get_Argument;
183 exit when S'Length = 0;
185 if Ada.Strings.Fixed.Index (S, ":") /= 0 then
187 ("Only file names are allowed on the command line");
197 when GNAT.Command_Line.Invalid_Switch =>
198 Ada.Text_IO.Put_Line ("Invalid switch : "
199 & GNAT.Command_Line.Full_Switch);
202 when GNAT.Command_Line.Invalid_Parameter =>
203 Ada.Text_IO.Put_Line ("Parameter missing for : "
204 & GNAT.Command_Line.Full_Switch);
212 procedure Write_Usage is
214 Put_Line ("GNATXREF " & Gnatvsn.Gnat_Version_String);
215 Put_Line ("Copyright 1998-2005, AdaCore");
216 Put_Line ("Usage: gnatxref [switches] file1 file2 ...");
218 Put_Line (" file ... list of source files to xref, " &
219 "including with'ed units");
221 Put_Line ("gnatxref switches:");
222 Put_Line (" -a Consider all files, even when the ali file is"
224 Put_Line (" -aIdir Specify source files search path");
225 Put_Line (" -aOdir Specify library/object files search path");
226 Put_Line (" -d Output derived type information");
227 Put_Line (" -f Output full path name");
228 Put_Line (" -g Output information only for global symbols");
229 Put_Line (" -Idir Like -aIdir -aOdir");
230 Put_Line (" -nostdinc Don't look for sources in the system default"
232 Put_Line (" -nostdlib Don't look for library files in the system"
233 & " default directory");
234 Put_Line (" --RTS=dir specify the default source and object search"
236 Put_Line (" -p file Use file as the default project file");
237 Put_Line (" -u List unused entities");
238 Put_Line (" -v Print a 'tags' file for vi");
247 if not Have_File then
251 Xr_Tabls.Set_Default_Match (True);
253 -- Find the project file
255 if Prj_File_Length = 0 then
256 Xr_Tabls.Create_Project_File
257 (Default_Project_File (Osint.To_Host_Dir_Spec (".", False).all));
259 Xr_Tabls.Create_Project_File (Prj_File (1 .. Prj_File_Length));
264 Search_Xref (Local_Symbols, Read_Only, Der_Info);
266 if Search_Unused then
267 Print_Unused (Full_Path_Name);
269 Print_Vi (Full_Path_Name);
271 Print_Xref (Full_Path_Name);