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 GNAT.Command_Line;
34 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
42 Output_Ref : Boolean := False;
43 Pattern : Xref_Lib.Search_Pattern;
44 Local_Symbols : Boolean := True;
45 Prj_File : File_Name_String;
46 Prj_File_Length : Natural := 0;
47 Nb_File : Natural := 0;
48 Usage_Error : exception;
49 Full_Path_Name : Boolean := False;
50 Have_Entity : Boolean := False;
51 Wide_Search : Boolean := True;
52 Glob_Mode : Boolean := True;
53 Der_Info : Boolean := False;
54 Type_Tree : Boolean := False;
55 Read_Only : Boolean := False;
56 Source_Lines : Boolean := False;
58 Has_File_In_Entity : Boolean := False;
59 -- Will be true if a file name was specified in the entity
61 procedure Parse_Cmd_Line;
62 -- Parse every switch on the command line
64 procedure Write_Usage;
65 -- Print a small help page for program usage
71 procedure Parse_Cmd_Line is
74 case GNAT.Command_Line.Getopt ("a aI: aO: d e f g h I: p: r s t") is
79 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);
84 Osint.Add_Lib_Search_Dir (GNAT.Command_Line.Parameter);
94 Full_Path_Name := True;
97 Local_Symbols := False;
103 Osint.Add_Src_Search_Dir (GNAT.Command_Line.Parameter);
104 Osint.Add_Lib_Search_Dir (GNAT.Command_Line.Parameter);
108 S : constant String := GNAT.Command_Line.Parameter;
110 Prj_File_Length := S'Length;
111 Prj_File (1 .. Prj_File_Length) := S;
118 Source_Lines := True;
128 -- Get the other arguments
132 S : constant String := GNAT.Command_Line.Get_Argument;
134 exit when S'Length = 0;
136 -- First argument is the pattern
138 if not Have_Entity then
139 Add_Entity (Pattern, S, Glob_Mode);
142 if not Has_File_In_Entity
143 and then Index (S, ":") /= 0
145 Has_File_In_Entity := True;
148 -- Next arguments are the files to search
151 Wide_Search := False;
152 Nb_File := Nb_File + 1;
158 when GNAT.Command_Line.Invalid_Switch =>
159 Ada.Text_IO.Put_Line ("Invalid switch : "
160 & GNAT.Command_Line.Full_Switch);
163 when GNAT.Command_Line.Invalid_Parameter =>
164 Ada.Text_IO.Put_Line ("Parameter missing for : "
165 & GNAT.Command_Line.Parameter);
168 when Xref_Lib.Invalid_Argument =>
169 Ada.Text_IO.Put_Line ("Invalid line or column in the pattern");
177 procedure Write_Usage is
181 Put_Line ("GNATFIND " & Gnatvsn.Gnat_Version_String
182 & " Copyright 1998-2001, Ada Core Technologies Inc.");
183 Put_Line ("Usage: gnatfind pattern[:sourcefile[:line[:column]]] "
184 & "[file1 file2 ...]");
186 Put_Line (" pattern Name of the entity to look for (can have "
188 Put_Line (" sourcefile Only find entities referenced from this "
190 Put_Line (" line Only find entities referenced from this line "
192 Put_Line (" column Only find entities referenced from this columns"
194 Put_Line (" file ... Set of Ada source files to search for "
195 & "references. This parameters are optional");
197 Put_Line ("gnatfind switches:");
198 Put_Line (" -a Consider all files, even when the ali file is "
200 Put_Line (" -aIdir Specify source files search path");
201 Put_Line (" -aOdir Specify library/object files search path");
202 Put_Line (" -d Output derived type information");
203 Put_Line (" -e Use the full regular expression set for pattern");
204 Put_Line (" -f Output full path name");
205 Put_Line (" -g Output information only for global symbols");
206 Put_Line (" -Idir Like -aIdir -aOdir");
207 Put_Line (" -p file Use file as the default project file");
208 Put_Line (" -r Find all references (default to find declaration"
210 Put_Line (" -s Print source line");
211 Put_Line (" -t Print type hierarchy");
218 Osint.Initialize (Osint.Compiler);
222 if not Have_Entity then
226 -- Special case to speed things up: if the user has a command line of the
227 -- form 'gnatfind entity:file', ie has specified a file and only wants the
228 -- bodies and specs, then we can restrict the search to the .ali file
229 -- associated with 'file'.
231 if Has_File_In_Entity
232 and then not Output_Ref
234 Wide_Search := False;
237 -- Find the project file
239 if Prj_File_Length = 0 then
240 Xr_Tabls.Create_Project_File (Default_Project_File ("."));
242 Xr_Tabls.Create_Project_File (Prj_File (1 .. Prj_File_Length));
247 if Type_Tree and then Nb_File > 1 then
248 Ada.Text_IO.Put_Line ("Error: for type hierarchy output you must "
249 & "specify only one file.");
250 Ada.Text_IO.New_Line;
254 Search (Pattern, Local_Symbols, Wide_Search, Read_Only,
255 Der_Info, Type_Tree);
258 Xr_Tabls.Grep_Source_Files;
261 Print_Gnatfind (Output_Ref, Full_Path_Name);