OSDN Git Service

* sem_ch3.adb (Find_Type_Of_Subtype_Indic): If subtype indication
[pf3gnuchains/gcc-fork.git] / gcc / ada / mlib-fil.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                            M L I B . F I L                               --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --                            $Revision: 1.2 $
10 --                                                                          --
11 --              Copyright (C) 2001, Ada Core Technologies, Inc.             --
12 --                                                                          --
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.                                                      --
23 --                                                                          --
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). --
26 --                                                                          --
27 ------------------------------------------------------------------------------
28
29 --  This package provides a set of routines to deal with file extensions
30
31 with Ada.Strings.Fixed;
32 with MLib.Tgt;
33
34 package body MLib.Fil is
35
36    use Ada;
37
38    package Target renames MLib.Tgt;
39
40    ------------
41    -- Ext_To --
42    ------------
43
44    function Ext_To
45      (Filename : String;
46       New_Ext  : String := "")
47       return     String
48    is
49       use Strings.Fixed;
50       J : constant Natural :=
51             Index (Source  =>  Filename,
52                    Pattern => ".",
53                    Going   => Strings.Backward);
54
55    begin
56       if J = 0 then
57          if New_Ext = "" then
58             return Filename;
59          else
60             return Filename & "." & New_Ext;
61          end if;
62
63       else
64          if New_Ext = "" then
65             return Head (Filename, J - 1);
66          else
67             return Head (Filename, J - 1) & '.' & New_Ext;
68          end if;
69       end if;
70    end Ext_To;
71
72    -------------
73    -- Get_Ext --
74    -------------
75
76    function Get_Ext (Filename : in String) return String is
77       use Strings.Fixed;
78
79       J : constant Natural :=
80             Index (Source  =>  Filename,
81                    Pattern => ".",
82                    Going   => Strings.Backward);
83
84    begin
85       if J = 0 then
86          return "";
87       else
88          return Filename (J .. Filename'Last);
89       end if;
90    end Get_Ext;
91
92    ----------------
93    -- Is_Archive --
94    ----------------
95
96    function Is_Archive (Filename : String) return Boolean is
97       Ext : constant String := Get_Ext (Filename);
98
99    begin
100       return Target.Is_Archive_Ext (Ext);
101    end Is_Archive;
102
103    ----------
104    -- Is_C --
105    ----------
106
107    function Is_C (Filename : in String) return Boolean is
108       Ext : constant String := Get_Ext (Filename);
109
110    begin
111       return Target.Is_C_Ext (Ext);
112    end Is_C;
113
114    ------------
115    -- Is_Obj --
116    ------------
117
118    function Is_Obj (Filename : in String) return Boolean is
119       Ext : constant String := Get_Ext (Filename);
120
121    begin
122       return Target.Is_Object_Ext (Ext);
123    end Is_Obj;
124
125 end MLib.Fil;