PR c++/3637
[official-gcc.git] / gcc / ada / mlib-fil.adb
blobeac9c1deb038868ce25430c799c8e8dd23c3cebc
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 ------------------------------------------------------------------------------
29 -- This package provides a set of routines to deal with file extensions
31 with Ada.Strings.Fixed;
32 with MLib.Tgt;
34 package body MLib.Fil is
36 use Ada;
38 package Target renames MLib.Tgt;
40 ------------
41 -- Ext_To --
42 ------------
44 function Ext_To
45 (Filename : String;
46 New_Ext : String := "")
47 return String
49 use Strings.Fixed;
50 J : constant Natural :=
51 Index (Source => Filename,
52 Pattern => ".",
53 Going => Strings.Backward);
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;
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;
72 -------------
73 -- Get_Ext --
74 -------------
76 function Get_Ext (Filename : in String) return String is
77 use Strings.Fixed;
79 J : constant Natural :=
80 Index (Source => Filename,
81 Pattern => ".",
82 Going => Strings.Backward);
84 begin
85 if J = 0 then
86 return "";
87 else
88 return Filename (J .. Filename'Last);
89 end if;
90 end Get_Ext;
92 ----------------
93 -- Is_Archive --
94 ----------------
96 function Is_Archive (Filename : String) return Boolean is
97 Ext : constant String := Get_Ext (Filename);
99 begin
100 return Target.Is_Archive_Ext (Ext);
101 end Is_Archive;
103 ----------
104 -- Is_C --
105 ----------
107 function Is_C (Filename : in String) return Boolean is
108 Ext : constant String := Get_Ext (Filename);
110 begin
111 return Target.Is_C_Ext (Ext);
112 end Is_C;
114 ------------
115 -- Is_Obj --
116 ------------
118 function Is_Obj (Filename : in String) return Boolean is
119 Ext : constant String := Get_Ext (Filename);
121 begin
122 return Target.Is_Object_Ext (Ext);
123 end Is_Obj;
125 end MLib.Fil;