mdll-fil.adb 3.25 KB
Newer Older
Richard Kenner committed
1 2 3 4 5 6 7 8
------------------------------------------------------------------------------
--                                                                          --
--                         GNAT COMPILER COMPONENTS                         --
--                                                                          --
--                            M D L L . F I L E S                           --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
Arnaud Charlet committed
9
--          Copyright (C) 1992-2007, Free Software Foundation, Inc.         --
Richard Kenner committed
10 11 12
--                                                                          --
-- 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- --
13
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
Richard Kenner committed
14 15 16 17
-- 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 --
18 19
-- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license.          --
Richard Kenner committed
20 21
--                                                                          --
-- GNAT was originally developed  by the GNAT team at  New York University. --
22
-- Extensive contributions were provided by Ada Core Technologies Inc.      --
Richard Kenner committed
23 24 25
--                                                                          --
------------------------------------------------------------------------------

26
--  Simple services used by GNATDLL to deal with Filename extension
Richard Kenner committed
27 28 29

with Ada.Strings.Fixed;

30
package body MDLL.Fil is
Richard Kenner committed
31 32 33 34 35 36 37

   use Ada;

   -------------
   -- Get_Ext --
   -------------

38
   function Get_Ext (Filename : String) return String is
Richard Kenner committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52
      use Strings.Fixed;
      I : constant Natural := Index (Filename, ".", Strings.Backward);
   begin
      if I = 0 then
         return "";
      else
         return Filename (I .. Filename'Last);
      end if;
   end Get_Ext;

   ------------
   -- Is_Ali --
   ------------

53
   function Is_Ali (Filename : String) return Boolean is
Richard Kenner committed
54 55 56 57 58 59 60 61
   begin
      return Get_Ext (Filename) = ".ali";
   end Is_Ali;

   ------------
   -- Is_Obj --
   ------------

62
   function Is_Obj (Filename : String) return Boolean is
Richard Kenner committed
63 64 65 66 67 68 69 70 71
      Ext : constant String := Get_Ext (Filename);
   begin
      return Ext = ".o" or else Ext = ".obj";
   end Is_Obj;

   ------------
   -- Ext_To --
   ------------

72 73 74 75
   function Ext_To
     (Filename : String;
      New_Ext  : String := No_Ext)
      return     String
Richard Kenner committed
76 77 78 79 80 81
   is
      use Strings.Fixed;
      I : constant Natural := Index (Filename, ".", Strings.Backward);
   begin
      if I = 0 then
         return Filename;
Arnaud Charlet committed
82

Richard Kenner committed
83 84
      else
         if New_Ext = "" then
Arnaud Charlet committed
85
            return Filename (Filename'First .. I - 1);
Richard Kenner committed
86
         else
Arnaud Charlet committed
87
            return Filename (Filename'First .. I - 1) & '.' & New_Ext;
Richard Kenner committed
88 89 90 91
         end if;
      end if;
   end Ext_To;

92
end MDLL.Fil;