1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1998-2001 Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). --
26 ------------------------------------------------------------------------------
29 with Xref_Lib; use Xref_Lib;
31 with Ada.Strings.Fixed;
32 with GNAT.Command_Line;
38 Search_Unused : Boolean := False;
39 Local_Symbols : Boolean := True;
40 Prj_File : File_Name_String;
41 Prj_File_Length : Natural := 0;
42 Usage_Error : exception;
43 Full_Path_Name : Boolean := False;
44 Vi_Mode : Boolean := False;
45 Read_Only : Boolean := False;
46 Have_File : Boolean := False;
47 Der_Info : Boolean := False;
49 procedure Parse_Cmd_Line;
50 -- Parse every switch on the command line
52 procedure Write_Usage;
53 -- Print a small help page for program usage
59 procedure Parse_Cmd_Line is
62 case GNAT.Command_Line.Getopt ("a aI: aO: d f g h I: p: u v") is
67 if GNAT.Command_Line.Full_Switch = "a" then
69 elsif GNAT.Command_Line.Full_Switch = "aI" then
70 Osint.Add_Src_Search_Dir (GNAT.Command_Line.Parameter);
72 Osint.Add_Lib_Search_Dir (GNAT.Command_Line.Parameter);
79 Full_Path_Name := True;
82 Local_Symbols := False;
88 Osint.Add_Src_Search_Dir (GNAT.Command_Line.Parameter);
89 Osint.Add_Lib_Search_Dir (GNAT.Command_Line.Parameter);
93 S : constant String := GNAT.Command_Line.Parameter;
96 Prj_File_Length := S'Length;
97 Prj_File (1 .. Prj_File_Length) := S;
101 Search_Unused := True;
106 Search_Unused := False;
113 -- Get the other arguments
117 S : constant String := GNAT.Command_Line.Get_Argument;
120 exit when S'Length = 0;
122 if Ada.Strings.Fixed.Index (S, ":") /= 0 then
124 ("Only file names are allowed on the command line");
134 when GNAT.Command_Line.Invalid_Switch =>
135 Ada.Text_IO.Put_Line ("Invalid switch : "
136 & GNAT.Command_Line.Full_Switch);
139 when GNAT.Command_Line.Invalid_Parameter =>
140 Ada.Text_IO.Put_Line ("Parameter missing for : "
141 & GNAT.Command_Line.Parameter);
149 procedure Write_Usage is
153 Put_Line ("GNATXREF " & Gnatvsn.Gnat_Version_String
154 & " Copyright 1998-2001, Ada Core Technologies Inc.");
155 Put_Line ("Usage: gnatxref [switches] file1 file2 ...");
157 Put_Line (" file ... list of source files to xref, " &
158 "including with'ed units");
160 Put_Line ("gnatxref switches:");
161 Put_Line (" -a Consider all files, even when the ali file is"
163 Put_Line (" -aIdir Specify source files search path");
164 Put_Line (" -aOdir Specify library/object files search path");
165 Put_Line (" -d Output derived type information");
166 Put_Line (" -f Output full path name");
167 Put_Line (" -g Output information only for global symbols");
168 Put_Line (" -Idir Like -aIdir -aOdir");
169 Put_Line (" -p file Use file as the default project file");
170 Put_Line (" -u List unused entities");
171 Put_Line (" -v Print a 'tags' file for vi");
180 if not Have_File then
184 Xr_Tabls.Set_Default_Match (True);
186 -- Find the project file
188 if Prj_File_Length = 0 then
189 Xr_Tabls.Create_Project_File
190 (Default_Project_File (Osint.To_Host_Dir_Spec (".", False).all));
192 Xr_Tabls.Create_Project_File (Prj_File (1 .. Prj_File_Length));
197 Search_Xref (Local_Symbols, Read_Only, Der_Info);
199 if Search_Unused then
200 Print_Unused (Full_Path_Name);
202 Print_Vi (Full_Path_Name);
204 Print_Xref (Full_Path_Name);