OSDN Git Service

* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Class_Wide_Type>: Fix
[pf3gnuchains/gcc-fork.git] / gcc / ada / gnatfind.adb
index 3becc88..8af7b9e 100644 (file)
@@ -6,31 +6,29 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1998-2007, Free Software Foundation, Inc.         --
+--          Copyright (C) 1998-2009, 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- --
--- ware  Foundation;  either version 2,  or (at your option) any later ver- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
 -- for  more details.  You should have  received  a copy of the GNU General --
--- Public License  distributed with GNAT;  see file COPYING.  If not, write --
--- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
--- Boston, MA 02110-1301, USA.                                              --
+-- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
+-- http://www.gnu.org/licenses for a complete copy of the license.          --
 --                                                                          --
 -- GNAT was originally developed  by the GNAT team at  New York University. --
 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
 --                                                                          --
 ------------------------------------------------------------------------------
 
-with Xr_Tabls; use Xr_Tabls;
-with Xref_Lib; use Xref_Lib;
+with Opt;
 with Osint;    use Osint;
+with Switch;   use Switch;
 with Types;    use Types;
-
-with Gnatvsn;
-with Opt;
+with Xr_Tabls; use Xr_Tabls;
+with Xref_Lib; use Xref_Lib;
 
 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
 with Ada.Text_IO;       use Ada.Text_IO;
@@ -66,22 +64,41 @@ procedure Gnatfind is
    RTS_Specified : String_Access := null;
    --  Used to detect multiple use of --RTS= switch
 
+   EXT_Specified : String_Access := null;
+   --  Used to detect multiple use of --ext= switch
+
    procedure Parse_Cmd_Line;
    --  Parse every switch on the command line
 
+   procedure Usage;
+   --  Display the usage
+
    procedure Write_Usage;
-   --  Print a small help page for program usage
+   --  Print a small help page for program usage and exit program
 
    --------------------
    -- Parse_Cmd_Line --
    --------------------
 
    procedure Parse_Cmd_Line is
+
+      procedure Check_Version_And_Help is new Check_Version_And_Help_G (Usage);
+
+      --  Start of processing for Parse_Cmd_Line
+
    begin
+      --  First check for --version or --help
+
+      Check_Version_And_Help ("GNATFIND", "1998");
+
+      --  Now scan the other switches
+
+      GNAT.Command_Line.Initialize_Option_Scan;
+
       loop
          case
            GNAT.Command_Line.Getopt
-             ("a aI: aO: d e f g h I: nostdinc nostdlib p: r s t -RTS=")
+             ("a aI: aO: d e f g h I: nostdinc nostdlib p: r s t -RTS= -ext=")
          is
             when ASCII.NUL =>
                exit;
@@ -117,7 +134,7 @@ procedure Gnatfind is
             when 'n'    =>
                if GNAT.Command_Line.Full_Switch = "nostdinc" then
                   Opt.No_Stdinc := True;
-               elsif GNAT.Command_Line.Full_Switch = "nostlib" then
+               elsif GNAT.Command_Line.Full_Switch = "nostdlib" then
                   Opt.No_Stdlib := True;
                end if;
 
@@ -140,45 +157,74 @@ procedure Gnatfind is
 
             --  Only switch starting with -- recognized is --RTS
 
-            when '-'    =>
-               --  Check that it is the first time we see this switch
+            when '-' =>
+               if GNAT.Command_Line.Full_Switch = "-RTS" then
 
-               if RTS_Specified = null then
-                  RTS_Specified := new String'(GNAT.Command_Line.Parameter);
-
-               elsif RTS_Specified.all /= GNAT.Command_Line.Parameter then
-                  Osint.Fail ("--RTS cannot be specified multiple times");
-               end if;
-
-               Opt.No_Stdinc := True;
-               Opt.RTS_Switch := True;
-
-               declare
-                  Src_Path_Name : constant String_Ptr :=
-                                    Get_RTS_Search_Dir
-                                      (GNAT.Command_Line.Parameter, Include);
-                  Lib_Path_Name : constant String_Ptr :=
-                                    Get_RTS_Search_Dir
-                                      (GNAT.Command_Line.Parameter, Objects);
+                  --  Check that it is the first time we see this switch
 
-               begin
-                  if Src_Path_Name /= null and then Lib_Path_Name /= null then
-                     Add_Search_Dirs (Src_Path_Name, Include);
-                     Add_Search_Dirs (Lib_Path_Name, Objects);
-
-                  elsif Src_Path_Name = null and then Lib_Path_Name = null then
-                     Osint.Fail ("RTS path not valid: missing " &
-                                 "adainclude and adalib directories");
+                  if RTS_Specified = null then
+                     RTS_Specified := new String'(GNAT.Command_Line.Parameter);
+                  elsif RTS_Specified.all /= GNAT.Command_Line.Parameter then
+                     Osint.Fail ("--RTS cannot be specified multiple times");
+                  end if;
 
-                  elsif Src_Path_Name = null then
-                     Osint.Fail ("RTS path not valid: missing " &
-                                 "adainclude directory");
+                  Opt.No_Stdinc := True;
+                  Opt.RTS_Switch := True;
+
+                  declare
+                     Src_Path_Name : constant String_Ptr :=
+                                       Get_RTS_Search_Dir
+                                         (GNAT.Command_Line.Parameter,
+                                          Include);
+                     Lib_Path_Name : constant String_Ptr :=
+                                       Get_RTS_Search_Dir
+                                         (GNAT.Command_Line.Parameter,
+                                          Objects);
+
+                  begin
+                     if Src_Path_Name /= null
+                       and then Lib_Path_Name /= null
+                     then
+                        Add_Search_Dirs (Src_Path_Name, Include);
+                        Add_Search_Dirs (Lib_Path_Name, Objects);
+
+                     elsif Src_Path_Name = null
+                       and then Lib_Path_Name = null
+                     then
+                        Osint.Fail ("RTS path not valid: missing " &
+                                      "adainclude and adalib directories");
+
+                     elsif Src_Path_Name = null then
+                        Osint.Fail ("RTS path not valid: missing " &
+                                      "adainclude directory");
+
+                     elsif Lib_Path_Name = null then
+                        Osint.Fail ("RTS path not valid: missing " &
+                                      "adalib directory");
+                     end if;
+                  end;
+
+               --  Process -ext switch
+
+               elsif GNAT.Command_Line.Full_Switch = "-ext" then
+
+                  --  Check that it is the first time we see this switch
+
+                  if EXT_Specified = null then
+                     EXT_Specified := new String'(GNAT.Command_Line.Parameter);
+                  elsif EXT_Specified.all /= GNAT.Command_Line.Parameter then
+                     Osint.Fail ("--ext cannot be specified multiple times");
+                  end if;
 
-                  elsif Lib_Path_Name = null then
-                     Osint.Fail ("RTS path not valid: missing " &
-                                 "adalib directory");
+                  if
+                    EXT_Specified'Length = Osint.ALI_Default_Suffix'Length
+                  then
+                     Osint.ALI_Suffix := EXT_Specified.all'Access;
+                  else
+                     Osint.Fail ("--ext argument must have 3 characters");
                   end if;
-               end;
+
+               end if;
 
             when others =>
                Write_Usage;
@@ -232,14 +278,12 @@ procedure Gnatfind is
          Write_Usage;
    end Parse_Cmd_Line;
 
-   -----------------
-   -- Write_Usage --
-   -----------------
+   -----------
+   -- Usage --
+   -----------
 
-   procedure Write_Usage is
+   procedure Usage is
    begin
-      Put_Line ("GNATFIND " & Gnatvsn.Gnat_Version_String);
-      Put_Line ("Copyright 1998-2005, AdaCore");
       Put_Line ("Usage: gnatfind pattern[:sourcefile[:line[:column]]] "
                 & "[file1 file2 ...]");
       New_Line;
@@ -269,6 +313,7 @@ procedure Gnatfind is
                 & " directory");
       Put_Line ("   -nostdlib Don't look for library files in the system"
                 & " default directory");
+      Put_Line ("   --ext=xxx Specify alternate ali file extension");
       Put_Line ("   --RTS=dir specify the default source and object search"
                 & " path");
       Put_Line ("   -p file   Use file as the default project file");
@@ -276,8 +321,19 @@ procedure Gnatfind is
                 & " only)");
       Put_Line ("   -s        Print source line");
       Put_Line ("   -t        Print type hierarchy");
+   end Usage;
+
+   -----------------
+   -- Write_Usage --
+   -----------------
+
+   procedure Write_Usage is
+   begin
+      Display_Version ("GNATFIND", "1998");
       New_Line;
 
+      Usage;
+
       raise Usage_Error;
    end Write_Usage;
 
@@ -291,8 +347,8 @@ begin
    end if;
 
    --  Special case to speed things up: if the user has a command line of the
-   --  form 'gnatfind entity:file', ie has specified a file and only wants the
-   --  bodies and specs, then we can restrict the search to the .ali file
+   --  form 'gnatfind entity:file', i.e. has specified a file and only wants
+   --  the bodies and specs, then we can restrict the search to the .ali file
    --  associated with 'file'.
 
    if Has_File_In_Entity