1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 2001-2002 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 was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
31 with Osint; use Osint;
32 with Output; use Output;
36 with Ada.Text_IO; use Ada.Text_IO;
37 with GNAT.Command_Line; use GNAT.Command_Line;
38 with GNAT.OS_Lib; use GNAT.OS_Lib;
42 Usage_Output : Boolean := False;
43 -- Set to True when usage is output, to avoid multiple output
45 Usage_Needed : Boolean := False;
46 -- Set to True by -h switch
48 Version_Output : Boolean := False;
49 -- Set to True when version is output, to avoid multiple output
51 Very_Verbose : Boolean := False;
52 -- Set to True with -v -v
54 Create_Project : Boolean := False;
55 -- Set to True with a -P switch
57 File_Path : String_Access := new String'("gnat.adc");
58 -- Path name of the file specified by -c or -P switch
60 File_Set : Boolean := False;
61 -- Set to True by -c or -P switch.
62 -- Used to detect multiple -c/-P switches.
64 package Excluded_Patterns is new Table.Table
65 (Table_Component_Type => String_Access,
66 Table_Index_Type => Natural,
69 Table_Increment => 10,
70 Table_Name => "Gnatname.Excluded_Patterns");
71 -- Table to accumulate the negative patterns.
73 package Patterns is new Table.Table
74 (Table_Component_Type => String_Access,
75 Table_Index_Type => Natural,
78 Table_Increment => 10,
79 Table_Name => "Gnatname.Patterns");
80 -- Table to accumulate the name patterns.
82 package Source_Directories is new Table.Table
83 (Table_Component_Type => String_Access,
84 Table_Index_Type => Natural,
87 Table_Increment => 10,
88 Table_Name => "Gnatname.Source_Directories");
89 -- Table to accumulate the source directories specified directly with -d
90 -- or indirectly with -D.
92 procedure Output_Version;
93 -- Print name and version
99 -- Scan the command line arguments
101 procedure Add_Source_Directory (S : String);
102 -- Add S in the Source_Directories table
104 procedure Get_Directories (From_File : String);
105 -- Read a source directory text file
107 --------------------------
108 -- Add_Source_Directory --
109 --------------------------
111 procedure Add_Source_Directory (S : String) is
113 Source_Directories.Increment_Last;
114 Source_Directories.Table (Source_Directories.Last) := new String'(S);
115 end Add_Source_Directory;
117 ---------------------
118 -- Get_Directories --
119 ---------------------
121 procedure Get_Directories (From_File : String) is
122 File : Ada.Text_IO.File_Type;
123 Line : String (1 .. 2_000);
127 Open (File, In_File, From_File);
129 while not End_Of_File (File) loop
130 Get_Line (File, Line, Last);
133 Add_Source_Directory (Line (1 .. Last));
141 Fail ("cannot open source directory """ & From_File & '"');
148 procedure Output_Version is
150 if not Version_Output then
151 Version_Output := True;
153 Output.Write_Str ("GNATNAME ");
154 Output.Write_Str (Gnatvsn.Gnat_Version_String);
156 (" Copyright 2001-2002 Free Software Foundation, Inc.");
164 procedure Scan_Args is
166 Initialize_Option_Scan;
168 -- Scan options first
171 case Getopt ("c: d: D: h P: v x:") is
177 Fail ("only one -P or -c switch may be specified");
181 File_Path := new String'(Parameter);
182 Create_Project := False;
185 Add_Source_Directory (Parameter);
188 Get_Directories (Parameter);
191 Usage_Needed := True;
195 Fail ("only one -c or -P switch may be specified");
199 File_Path := new String'(Parameter);
200 Create_Project := True;
203 if Opt.Verbose_Mode then
204 Very_Verbose := True;
207 Opt.Verbose_Mode := True;
211 Excluded_Patterns.Increment_Last;
212 Excluded_Patterns.Table (Excluded_Patterns.Last) :=
213 new String'(Parameter);
220 -- Now, get the name patterns, if any
224 S : constant String := Get_Argument (Do_Expansion => False);
228 Patterns.Increment_Last;
229 Patterns.Table (Patterns.Last) := new String'(S);
234 when Invalid_Switch =>
235 Fail ("invalid switch " & Full_Switch);
245 if not Usage_Output then
246 Usage_Needed := False;
247 Usage_Output := True;
248 Write_Str ("Usage: ");
249 Osint.Write_Program_Name;
250 Write_Line (" [switches] naming-pattern [naming-patterns]");
252 Write_Line ("switches:");
254 Write_Line (" -cfile create configuration pragmas file");
255 Write_Line (" -ddir use dir as one of the source directories");
256 Write_Line (" -Dfile get source directories from file");
257 Write_Line (" -h output this help message");
258 Write_Line (" -Pproj update or create project file proj");
259 Write_Line (" -v verbose output");
260 Write_Line (" -v -v very verbose output");
261 Write_Line (" -xpat exclude pattern pat");
265 -- Start of processing for Gnatname
270 Excluded_Patterns.Set_Last (0);
271 Patterns.Set_Last (0);
272 Source_Directories.Set_Last (0);
278 if Opt.Verbose_Mode then
286 -- If no pattern was specified, print the usage and return
288 if Patterns.Last = 0 then
293 -- If no source directory was specified, use the current directory as the
294 -- unique directory. Note that if a file was specified with directory
295 -- information, the current directory is the directory of the specified
298 if Source_Directories.Last = 0 then
299 Source_Directories.Increment_Last;
300 Source_Directories.Table (Source_Directories.Last) := new String'(".");
304 Directories : Argument_List (1 .. Integer (Source_Directories.Last));
305 Name_Patterns : Argument_List (1 .. Integer (Patterns.Last));
306 Excl_Patterns : Argument_List (1 .. Integer (Excluded_Patterns.Last));
309 -- Build the Directories and Name_Patterns arguments
311 for Index in Directories'Range loop
312 Directories (Index) := Source_Directories.Table (Index);
315 for Index in Name_Patterns'Range loop
316 Name_Patterns (Index) := Patterns.Table (Index);
319 for Index in Excl_Patterns'Range loop
320 Excl_Patterns (Index) := Excluded_Patterns.Table (Index);
323 -- Call Prj.Makr.Make where the real work is done
326 (File_Path => File_Path.all,
327 Project_File => Create_Project,
328 Directories => Directories,
329 Name_Patterns => Name_Patterns,
330 Excluded_Patterns => Excl_Patterns,
331 Very_Verbose => Very_Verbose);
334 if Opt.Verbose_Mode then