OSDN Git Service

2011-10-16 Tristan Gingold <gingold@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / gnatname.adb
index dbd7f50..c741834 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 2001-2008, Free Software Foundation, Inc.         --
+--          Copyright (C) 2001-2011, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -186,7 +186,7 @@ procedure Gnatname is
       Excluded_Pattern_Expected : Boolean;
 
       procedure Check_Regular_Expression (S : String);
-      --  Compile string S into a Regexp. Fail if any error.
+      --  Compile string S into a Regexp, fail if any error
 
       -----------------------------
       -- Check_Regular_Expression--
@@ -199,8 +199,11 @@ procedure Gnatname is
          Dummy := Compile (S, Glob => True);
       exception
          when Error_In_Regexp =>
-            Fail ("invalid regular expression """, S, """");
+            Fail ("invalid regular expression """ & S & """");
       end Check_Regular_Expression;
+
+   --  Start of processing for Scan_Args
+
    begin
       --  First check for --version or --help
 
@@ -214,6 +217,7 @@ procedure Gnatname is
       Dir_File_Name_Expected     := False;
       Foreign_Pattern_Expected   := False;
       Excluded_Pattern_Expected  := False;
+
       for Next_Arg in 1 .. Argument_Count loop
          declare
             Next_Argv : constant String := Argument (Next_Arg);
@@ -221,9 +225,10 @@ procedure Gnatname is
 
          begin
             if Arg'Length > 0 then
-               if Project_File_Name_Expected then
-                  --  -P xxx
 
+               --  -P xxx
+
+               if Project_File_Name_Expected then
                   if Arg (1) = '-' then
                      Fail ("project file name missing");
 
@@ -233,48 +238,50 @@ procedure Gnatname is
                      Project_File_Name_Expected := False;
                   end if;
 
-               elsif Pragmas_File_Expected then
-                  --  -c file
+               --  -c file
 
+               elsif Pragmas_File_Expected then
                   File_Set := True;
                   File_Path := new String'(Arg);
                   Create_Project := False;
                   Pragmas_File_Expected := False;
 
-               elsif Directory_Expected then
-                  --  -d xxx
+               --  -d xxx
 
+               elsif Directory_Expected then
                   Add_Source_Directory (Arg);
                   Directory_Expected := False;
 
-               elsif Dir_File_Name_Expected then
-                  --  -D xxx
+               --  -D xxx
 
+               elsif Dir_File_Name_Expected then
                   Get_Directories (Arg);
                   Dir_File_Name_Expected := False;
 
-               elsif Foreign_Pattern_Expected then
-                  --  -f xxx
+               --  -f xxx
 
+               elsif Foreign_Pattern_Expected then
                   Patterns.Append
                     (Arguments.Table (Arguments.Last).Foreign_Patterns,
                      new String'(Arg));
                   Check_Regular_Expression (Arg);
                   Foreign_Pattern_Expected := False;
 
-               elsif Excluded_Pattern_Expected then
-                  --  -x xxx
+               --  -x xxx
 
+               elsif Excluded_Pattern_Expected then
                   Patterns.Append
                     (Arguments.Table (Arguments.Last).Excluded_Patterns,
                      new String'(Arg));
                   Check_Regular_Expression (Arg);
                   Excluded_Pattern_Expected := False;
 
-               elsif Arg = "--and" then
+               --  There must be at least one Ada pattern or one foreign
+               --  pattern for the previous section.
 
-                  --  There must be at least one Ada pattern or one foreign
-                  --  pattern for the previous section.
+               --  --and
+
+               elsif Arg = "--and" then
 
                   if Patterns.Last
                     (Arguments.Table (Arguments.Last).Name_Patterns) = 0
@@ -297,10 +304,22 @@ procedure Gnatname is
                         new String'("."));
                   end if;
 
-                  --  Add another component in table Arguments and initialize
-                  --  it.
+                  --  Add and initialize another component to Arguments table
 
-                  Arguments.Increment_Last;
+                  declare
+                     New_Arguments : Argument_Data;
+                     pragma Warnings (Off, New_Arguments);
+                     --  Declaring this defaulted initialized object ensures
+                     --  that the new allocated component of table Arguments
+                     --  is correctly initialized.
+
+                     --  This is VERY ugly, Table should never be used with
+                     --  data requiring default initialization. We should
+                     --  find a way to avoid violating this rule ???
+
+                  begin
+                     Arguments.Append (New_Arguments);
+                  end;
 
                   Patterns.Init
                     (Arguments.Table (Arguments.Last).Directories);
@@ -319,12 +338,16 @@ procedure Gnatname is
                   Patterns.Set_Last
                     (Arguments.Table (Arguments.Last).Foreign_Patterns, 0);
 
+               --  Subdirectory switch
+
                elsif Arg'Length > Subdirs_Switch'Length
                  and then Arg (1 .. Subdirs_Switch'Length) = Subdirs_Switch
                then
                   Subdirs :=
                     new String'(Arg (Subdirs_Switch'Length + 1 .. Arg'Last));
 
+               --  -c
+
                elsif Arg'Length >= 2 and then Arg (1 .. 2) = "-c" then
                   if File_Set then
                      Fail ("only one -P or -c switch may be specified");
@@ -343,6 +366,8 @@ procedure Gnatname is
                      Create_Project := False;
                   end if;
 
+               --  -d
+
                elsif Arg'Length >= 2 and then Arg (1 .. 2) = "-d" then
                   if Arg'Length = 2 then
                      Directory_Expected := True;
@@ -355,6 +380,8 @@ procedure Gnatname is
                      Add_Source_Directory (Arg (3 .. Arg'Last));
                   end if;
 
+               --  -D
+
                elsif Arg'Length >= 2 and then Arg (1 .. 2) = "-D" then
                   if Arg'Length = 2 then
                      Dir_File_Name_Expected := True;
@@ -367,8 +394,13 @@ procedure Gnatname is
                      Get_Directories (Arg (3 .. Arg'Last));
                   end if;
 
+               --  -eL
+
                elsif Arg = "-eL" then
                   Opt.Follow_Links_For_Files := True;
+                  Opt.Follow_Links_For_Dirs  := True;
+
+               --  -f
 
                elsif Arg'Length >= 2 and then Arg (1 .. 2) = "-f" then
                   if Arg'Length = 2 then
@@ -385,15 +417,20 @@ procedure Gnatname is
                      Check_Regular_Expression (Arg (3 .. Arg'Last));
                   end if;
 
+               --  -gnatep or -gnateD
+
                elsif Arg'Length > 7 and then
                  (Arg  (1 .. 7) = "-gnatep" or else Arg (1 .. 7) = "-gnateD")
                then
-
                   Preprocessor_Switches.Append (new String'(Arg));
 
+               --  -h
+
                elsif Arg = "-h" then
                   Usage_Needed := True;
 
+               --  -p
+
                elsif Arg'Length >= 2 and then Arg (1 .. 2) = "-P" then
                   if File_Set then
                      Fail ("only one -c or -P switch may be specified");
@@ -414,6 +451,8 @@ procedure Gnatname is
 
                   Create_Project := True;
 
+               --  -v
+
                elsif Arg = "-v" then
                   if Opt.Verbose_Mode then
                      Very_Verbose := True;
@@ -421,6 +460,8 @@ procedure Gnatname is
                      Opt.Verbose_Mode := True;
                   end if;
 
+               --  -x
+
                elsif Arg'Length >= 2 and then Arg (1 .. 2) = "-x" then
                   if Arg'Length = 2 then
                      Excluded_Pattern_Expected := True;
@@ -436,9 +477,13 @@ procedure Gnatname is
                      Check_Regular_Expression (Arg (3 .. Arg'Last));
                   end if;
 
+               --  Junk switch starting with minus
+
                elsif Arg (1) = '-' then
                   Fail ("wrong switch: " & Arg);
 
+               --  Not a recognized switch, assume file name
+
                else
                   Canonical_Case_File_Name (Arg);
                   Patterns.Append
@@ -467,6 +512,8 @@ procedure Gnatname is
          Write_Eol;
          Write_Line ("switches:");
 
+         Display_Usage_Version_And_Help;
+
          Write_Line ("  --subdirs=dir real obj/lib/exec dirs are subdirs");
          Write_Eol;
 
@@ -493,8 +540,6 @@ procedure Gnatname is
 --  Start of processing for Gnatname
 
 begin
-   Prj.Set_Mode (Prj.Ada_Only);
-
    --  Add the directory where gnatname is invoked in front of the
    --  path, if gnatname is invoked with directory information.
    --  Only do this if the platform is not VMS, where the notion of path
@@ -591,7 +636,8 @@ begin
         (File_Path         => File_Path.all,
          Project_File      => Create_Project,
          Preproc_Switches  => Prep_Switches,
-         Very_Verbose      => Very_Verbose);
+         Very_Verbose      => Very_Verbose,
+         Flags             => Gnatmake_Flags);
    end;
 
    --  Process each section successively