OSDN Git Service

New Language: Ada
[pf3gnuchains/gcc-fork.git] / gcc / ada / fname-sf.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             F N A M E . S F                              --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --                            $Revision: 1.1 $
10 --                                                                          --
11 --          Copyright (C) 1992-2000 Free Software Foundation, 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 with Casing;   use Casing;
30 with Fname;    use Fname;
31 with Fname.UF; use Fname.UF;
32 with SFN_Scan; use SFN_Scan;
33 with Namet;    use Namet;
34 with Osint;    use Osint;
35 with Types;    use Types;
36
37 with Unchecked_Conversion;
38
39 package body Fname.SF is
40
41    subtype Big_String is String (Positive);
42    type Big_String_Ptr is access all Big_String;
43
44    function To_Big_String_Ptr is new Unchecked_Conversion
45      (Source_Buffer_Ptr, Big_String_Ptr);
46
47    ----------------------
48    -- Local Procedures --
49    ----------------------
50
51    procedure Set_File_Name (Typ : Character; U : String; F : String);
52    --  This is a transfer function that is called from Scan_SFN_Pragmas,
53    --  and reformats its parameters appropriately for the version of
54    --  Set_File_Name found in Fname.SF.
55
56    procedure Set_File_Name_Pattern
57      (Pat : String;
58       Typ : Character;
59       Dot : String;
60       Cas : Character);
61    --  This is a transfer function that is called from Scan_SFN_Pragmas,
62    --  and reformats its parameters appropriately for the version of
63    --  Set_File_Name_Pattern found in Fname.SF.
64
65    -----------------------------------
66    -- Read_Source_File_Name_Pragmas --
67    -----------------------------------
68
69    procedure Read_Source_File_Name_Pragmas is
70       Src : Source_Buffer_Ptr;
71       Hi  : Source_Ptr;
72       BS  : Big_String_Ptr;
73       SP  : String_Ptr;
74
75    begin
76       Name_Buffer (1 .. 8) := "gnat.adc";
77       Name_Len := 8;
78       Read_Source_File (Name_Enter, 0, Hi, Src);
79
80       if Src /= null then
81          BS := To_Big_String_Ptr (Src);
82          SP := BS (1 .. Natural (Hi))'Unrestricted_Access;
83          Scan_SFN_Pragmas
84            (SP.all,
85             Set_File_Name'Access,
86             Set_File_Name_Pattern'Access);
87       end if;
88    end Read_Source_File_Name_Pragmas;
89
90    -------------------
91    -- Set_File_Name --
92    -------------------
93
94    procedure Set_File_Name (Typ : Character; U : String; F : String) is
95       Unm : Unit_Name_Type;
96       Fnm : File_Name_Type;
97
98    begin
99       Name_Buffer (1 .. U'Length) := U;
100       Name_Len := U'Length;
101       Set_Casing (All_Lower_Case);
102       Name_Buffer (Name_Len + 1) := '%';
103       Name_Buffer (Name_Len + 2) := Typ;
104       Name_Len := Name_Len + 2;
105       Unm := Name_Find;
106       Name_Buffer (1 .. F'Length) := F;
107       Name_Len := F'Length;
108       Fnm := Name_Find;
109       Fname.UF.Set_File_Name (Unm, Fnm);
110    end Set_File_Name;
111
112    ---------------------------
113    -- Set_File_Name_Pattern --
114    ---------------------------
115
116    procedure Set_File_Name_Pattern
117      (Pat : String;
118       Typ : Character;
119       Dot : String;
120       Cas : Character)
121    is
122       Ctyp : Casing_Type;
123       Patp : constant String_Ptr := new String'(Pat);
124       Dotp : constant String_Ptr := new String'(Dot);
125
126    begin
127       if Cas = 'l' then
128          Ctyp := All_Lower_Case;
129       elsif Cas = 'u' then
130          Ctyp := All_Upper_Case;
131       else -- Cas = 'm'
132          Ctyp := Mixed_Case;
133       end if;
134
135       Fname.UF.Set_File_Name_Pattern (Patp, Typ, Dotp, Ctyp);
136    end Set_File_Name_Pattern;
137
138 end Fname.SF;