OSDN Git Service

./:
[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 --          Copyright (C) 1992-2007, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
19 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
20 -- Boston, MA 02110-1301, USA.                                              --
21 --                                                                          --
22 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
26
27 with Casing;   use Casing;
28 with Fname;    use Fname;
29 with Fname.UF; use Fname.UF;
30 with SFN_Scan; use SFN_Scan;
31 with Osint;    use Osint;
32 with Types;    use Types;
33
34 with Unchecked_Conversion;
35
36 package body Fname.SF is
37
38    subtype Big_String is String (Positive);
39    type Big_String_Ptr is access all Big_String;
40
41    function To_Big_String_Ptr is new Unchecked_Conversion
42      (Source_Buffer_Ptr, Big_String_Ptr);
43
44    ----------------------
45    -- Local Procedures --
46    ----------------------
47
48    procedure Set_File_Name
49      (Typ   : Character;
50       U     : String;
51       F     : String;
52       Index : Natural);
53    --  This is a transfer function that is called from Scan_SFN_Pragmas,
54    --  and reformats its parameters appropriately for the version of
55    --  Set_File_Name found in Fname.SF.
56
57    procedure Set_File_Name_Pattern
58      (Pat : String;
59       Typ : Character;
60       Dot : String;
61       Cas : Character);
62    --  This is a transfer function that is called from Scan_SFN_Pragmas,
63    --  and reformats its parameters appropriately for the version of
64    --  Set_File_Name_Pattern found in Fname.SF.
65
66    -----------------------------------
67    -- Read_Source_File_Name_Pragmas --
68    -----------------------------------
69
70    procedure Read_Source_File_Name_Pragmas is
71       Src : Source_Buffer_Ptr;
72       Hi  : Source_Ptr;
73       BS  : Big_String_Ptr;
74       SP  : String_Ptr;
75
76    begin
77       Name_Buffer (1 .. 8) := "gnat.adc";
78       Name_Len := 8;
79       Read_Source_File (Name_Enter, 0, Hi, Src);
80
81       if Src /= null then
82          BS := To_Big_String_Ptr (Src);
83          SP := BS (1 .. Natural (Hi))'Unrestricted_Access;
84          Scan_SFN_Pragmas
85            (SP.all,
86             Set_File_Name'Access,
87             Set_File_Name_Pattern'Access);
88       end if;
89    end Read_Source_File_Name_Pragmas;
90
91    -------------------
92    -- Set_File_Name --
93    -------------------
94
95    procedure Set_File_Name
96      (Typ   : Character;
97       U     : String;
98       F     : String;
99       Index : Natural)
100    is
101       Unm : Unit_Name_Type;
102       Fnm : File_Name_Type;
103    begin
104       Name_Buffer (1 .. U'Length) := U;
105       Name_Len := U'Length;
106       Set_Casing (All_Lower_Case);
107       Name_Buffer (Name_Len + 1) := '%';
108       Name_Buffer (Name_Len + 2) := Typ;
109       Name_Len := Name_Len + 2;
110       Unm := Name_Find;
111       Name_Buffer (1 .. F'Length) := F;
112       Name_Len := F'Length;
113       Fnm := Name_Find;
114       Fname.UF.Set_File_Name (Unm, Fnm, Nat (Index));
115    end Set_File_Name;
116
117    ---------------------------
118    -- Set_File_Name_Pattern --
119    ---------------------------
120
121    procedure Set_File_Name_Pattern
122      (Pat : String;
123       Typ : Character;
124       Dot : String;
125       Cas : Character)
126    is
127       Ctyp : Casing_Type;
128       Patp : constant String_Ptr := new String'(Pat);
129       Dotp : constant String_Ptr := new String'(Dot);
130
131    begin
132       if Cas = 'l' then
133          Ctyp := All_Lower_Case;
134       elsif Cas = 'u' then
135          Ctyp := All_Upper_Case;
136       else -- Cas = 'm'
137          Ctyp := Mixed_Case;
138       end if;
139
140       Fname.UF.Set_File_Name_Pattern (Patp, Typ, Dotp, Ctyp);
141    end Set_File_Name_Pattern;
142
143 end Fname.SF;