OSDN Git Service

2005-06-15 Andrew Pinski <pinskia@physics.uc.edu>
[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-2004 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,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, 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 Namet;    use Namet;
32 with Osint;    use Osint;
33 with Types;    use Types;
34
35 with Unchecked_Conversion;
36
37 package body Fname.SF is
38
39    subtype Big_String is String (Positive);
40    type Big_String_Ptr is access all Big_String;
41
42    function To_Big_String_Ptr is new Unchecked_Conversion
43      (Source_Buffer_Ptr, Big_String_Ptr);
44
45    ----------------------
46    -- Local Procedures --
47    ----------------------
48
49    procedure Set_File_Name
50      (Typ   : Character;
51       U     : String;
52       F     : String;
53       Index : Natural);
54    --  This is a transfer function that is called from Scan_SFN_Pragmas,
55    --  and reformats its parameters appropriately for the version of
56    --  Set_File_Name found in Fname.SF.
57
58    procedure Set_File_Name_Pattern
59      (Pat : String;
60       Typ : Character;
61       Dot : String;
62       Cas : Character);
63    --  This is a transfer function that is called from Scan_SFN_Pragmas,
64    --  and reformats its parameters appropriately for the version of
65    --  Set_File_Name_Pattern found in Fname.SF.
66
67    -----------------------------------
68    -- Read_Source_File_Name_Pragmas --
69    -----------------------------------
70
71    procedure Read_Source_File_Name_Pragmas is
72       Src : Source_Buffer_Ptr;
73       Hi  : Source_Ptr;
74       BS  : Big_String_Ptr;
75       SP  : String_Ptr;
76
77    begin
78       Name_Buffer (1 .. 8) := "gnat.adc";
79       Name_Len := 8;
80       Read_Source_File (Name_Enter, 0, Hi, Src);
81
82       if Src /= null then
83          BS := To_Big_String_Ptr (Src);
84          SP := BS (1 .. Natural (Hi))'Unrestricted_Access;
85          Scan_SFN_Pragmas
86            (SP.all,
87             Set_File_Name'Access,
88             Set_File_Name_Pattern'Access);
89       end if;
90    end Read_Source_File_Name_Pragmas;
91
92    -------------------
93    -- Set_File_Name --
94    -------------------
95
96    procedure Set_File_Name
97      (Typ   : Character;
98       U     : String;
99       F     : String;
100       Index : Natural)
101    is
102       Unm : Unit_Name_Type;
103       Fnm : File_Name_Type;
104    begin
105       Name_Buffer (1 .. U'Length) := U;
106       Name_Len := U'Length;
107       Set_Casing (All_Lower_Case);
108       Name_Buffer (Name_Len + 1) := '%';
109       Name_Buffer (Name_Len + 2) := Typ;
110       Name_Len := Name_Len + 2;
111       Unm := Name_Find;
112       Name_Buffer (1 .. F'Length) := F;
113       Name_Len := F'Length;
114       Fnm := Name_Find;
115       Fname.UF.Set_File_Name (Unm, Fnm, Nat (Index));
116    end Set_File_Name;
117
118    ---------------------------
119    -- Set_File_Name_Pattern --
120    ---------------------------
121
122    procedure Set_File_Name_Pattern
123      (Pat : String;
124       Typ : Character;
125       Dot : String;
126       Cas : Character)
127    is
128       Ctyp : Casing_Type;
129       Patp : constant String_Ptr := new String'(Pat);
130       Dotp : constant String_Ptr := new String'(Dot);
131
132    begin
133       if Cas = 'l' then
134          Ctyp := All_Lower_Case;
135       elsif Cas = 'u' then
136          Ctyp := All_Upper_Case;
137       else -- Cas = 'm'
138          Ctyp := Mixed_Case;
139       end if;
140
141       Fname.UF.Set_File_Name_Pattern (Patp, Typ, Dotp, Ctyp);
142    end Set_File_Name_Pattern;
143
144 end Fname.SF;