1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 2001-2002 Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- Extensive contributions were provided by Ada Core Technologies Inc. --
26 ------------------------------------------------------------------------------
30 with Osint
; use Osint
;
31 with Output
; use Output
;
35 with Ada
.Text_IO
; use Ada
.Text_IO
;
36 with GNAT
.Command_Line
; use GNAT
.Command_Line
;
37 with GNAT
.OS_Lib
; use GNAT
.OS_Lib
;
41 Usage_Output
: Boolean := False;
42 -- Set to True when usage is output, to avoid multiple output
44 Usage_Needed
: Boolean := False;
45 -- Set to True by -h switch
47 Version_Output
: Boolean := False;
48 -- Set to True when version is output, to avoid multiple output
50 Very_Verbose
: Boolean := False;
51 -- Set to True with -v -v
53 Create_Project
: Boolean := False;
54 -- Set to True with a -P switch
56 File_Path
: String_Access
:= new String'("gnat.adc");
57 -- Path name of the file specified by -c or -P switch
59 File_Set : Boolean := False;
60 -- Set to True by -c or -P switch.
61 -- Used to detect multiple -c/-P switches.
63 package Excluded_Patterns is new Table.Table
64 (Table_Component_Type => String_Access,
65 Table_Index_Type => Natural,
68 Table_Increment => 10,
69 Table_Name => "Gnatname.Excluded_Patterns");
70 -- Table to accumulate the negative patterns.
72 package Patterns is new Table.Table
73 (Table_Component_Type => String_Access,
74 Table_Index_Type => Natural,
77 Table_Increment => 10,
78 Table_Name => "Gnatname.Patterns");
79 -- Table to accumulate the name patterns.
81 package Source_Directories is new Table.Table
82 (Table_Component_Type => String_Access,
83 Table_Index_Type => Natural,
86 Table_Increment => 10,
87 Table_Name => "Gnatname.Source_Directories");
88 -- Table to accumulate the source directories specified directly with -d
89 -- or indirectly with -D.
91 procedure Output_Version;
92 -- Print name and version
98 -- Scan the command line arguments
100 procedure Add_Source_Directory (S : String);
101 -- Add S in the Source_Directories table
103 procedure Get_Directories (From_File : String);
104 -- Read a source directory text file
106 --------------------------
107 -- Add_Source_Directory --
108 --------------------------
110 procedure Add_Source_Directory (S : String) is
112 Source_Directories.Increment_Last;
113 Source_Directories.Table (Source_Directories.Last) := new String'(S
);
114 end Add_Source_Directory
;
116 ---------------------
117 -- Get_Directories --
118 ---------------------
120 procedure Get_Directories
(From_File
: String) is
121 File
: Ada
.Text_IO
.File_Type
;
122 Line
: String (1 .. 2_000
);
126 Open
(File
, In_File
, From_File
);
128 while not End_Of_File
(File
) loop
129 Get_Line
(File
, Line
, Last
);
132 Add_Source_Directory
(Line
(1 .. Last
));
140 Fail
("cannot open source directory """ & From_File
& '"');
147 procedure Output_Version
is
149 if not Version_Output
then
150 Version_Output
:= True;
152 Output
.Write_Str
("GNATNAME ");
153 Output
.Write_Str
(Gnatvsn
.Gnat_Version_String
);
155 (" Copyright 2001-2002 Free Software Foundation, Inc.");
163 procedure Scan_Args
is
165 Initialize_Option_Scan
;
167 -- Scan options first
170 case Getopt
("c: d: D: h P: v x:") is
176 Fail
("only one -P or -c switch may be specified");
180 File_Path
:= new String'(Parameter);
181 Create_Project := False;
184 Add_Source_Directory (Parameter);
187 Get_Directories (Parameter);
190 Usage_Needed := True;
194 Fail ("only one -c or -P switch may be specified");
198 File_Path := new String'(Parameter
);
199 Create_Project
:= True;
202 if Opt
.Verbose_Mode
then
203 Very_Verbose
:= True;
206 Opt
.Verbose_Mode
:= True;
210 Excluded_Patterns
.Increment_Last
;
211 Excluded_Patterns
.Table
(Excluded_Patterns
.Last
) :=
212 new String'(Parameter);
219 -- Now, get the name patterns, if any
223 S : constant String := Get_Argument (Do_Expansion => False);
227 Patterns.Increment_Last;
228 Patterns.Table (Patterns.Last) := new String'(S
);
233 when Invalid_Switch
=>
234 Fail
("invalid switch " & Full_Switch
);
244 if not Usage_Output
then
245 Usage_Needed
:= False;
246 Usage_Output
:= True;
247 Write_Str
("Usage: ");
248 Osint
.Write_Program_Name
;
249 Write_Line
(" [switches] naming-pattern [naming-patterns]");
251 Write_Line
("switches:");
253 Write_Line
(" -cfile create configuration pragmas file");
254 Write_Line
(" -ddir use dir as one of the source directories");
255 Write_Line
(" -Dfile get source directories from file");
256 Write_Line
(" -h output this help message");
257 Write_Line
(" -Pproj update or create project file proj");
258 Write_Line
(" -v verbose output");
259 Write_Line
(" -v -v very verbose output");
260 Write_Line
(" -xpat exclude pattern pat");
264 -- Start of processing for Gnatname
269 Excluded_Patterns
.Set_Last
(0);
270 Patterns
.Set_Last
(0);
271 Source_Directories
.Set_Last
(0);
277 if Opt
.Verbose_Mode
then
285 -- If no pattern was specified, print the usage and return
287 if Patterns
.Last
= 0 then
292 -- If no source directory was specified, use the current directory as the
293 -- unique directory. Note that if a file was specified with directory
294 -- information, the current directory is the directory of the specified
297 if Source_Directories
.Last
= 0 then
298 Source_Directories
.Increment_Last
;
299 Source_Directories
.Table
(Source_Directories
.Last
) := new String'(".");
303 Directories : Argument_List (1 .. Integer (Source_Directories.Last));
304 Name_Patterns : Argument_List (1 .. Integer (Patterns.Last));
305 Excl_Patterns : Argument_List (1 .. Integer (Excluded_Patterns.Last));
308 -- Build the Directories and Name_Patterns arguments
310 for Index in Directories'Range loop
311 Directories (Index) := Source_Directories.Table (Index);
314 for Index in Name_Patterns'Range loop
315 Name_Patterns (Index) := Patterns.Table (Index);
318 for Index in Excl_Patterns'Range loop
319 Excl_Patterns (Index) := Excluded_Patterns.Table (Index);
322 -- Call Prj.Makr.Make where the real work is done
325 (File_Path => File_Path.all,
326 Project_File => Create_Project,
327 Directories => Directories,
328 Name_Patterns => Name_Patterns,
329 Excluded_Patterns => Excl_Patterns,
330 Very_Verbose => Very_Verbose);
333 if Opt.Verbose_Mode then