OSDN Git Service

Fix copyright problems reported by Doug Evans.
[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-2000 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 (Typ : Character; U : String; F : String);
50    --  This is a transfer function that is called from Scan_SFN_Pragmas,
51    --  and reformats its parameters appropriately for the version of
52    --  Set_File_Name found in Fname.SF.
53
54    procedure Set_File_Name_Pattern
55      (Pat : String;
56       Typ : Character;
57       Dot : String;
58       Cas : Character);
59    --  This is a transfer function that is called from Scan_SFN_Pragmas,
60    --  and reformats its parameters appropriately for the version of
61    --  Set_File_Name_Pattern found in Fname.SF.
62
63    -----------------------------------
64    -- Read_Source_File_Name_Pragmas --
65    -----------------------------------
66
67    procedure Read_Source_File_Name_Pragmas is
68       Src : Source_Buffer_Ptr;
69       Hi  : Source_Ptr;
70       BS  : Big_String_Ptr;
71       SP  : String_Ptr;
72
73    begin
74       Name_Buffer (1 .. 8) := "gnat.adc";
75       Name_Len := 8;
76       Read_Source_File (Name_Enter, 0, Hi, Src);
77
78       if Src /= null then
79          BS := To_Big_String_Ptr (Src);
80          SP := BS (1 .. Natural (Hi))'Unrestricted_Access;
81          Scan_SFN_Pragmas
82            (SP.all,
83             Set_File_Name'Access,
84             Set_File_Name_Pattern'Access);
85       end if;
86    end Read_Source_File_Name_Pragmas;
87
88    -------------------
89    -- Set_File_Name --
90    -------------------
91
92    procedure Set_File_Name (Typ : Character; U : String; F : String) is
93       Unm : Unit_Name_Type;
94       Fnm : File_Name_Type;
95
96    begin
97       Name_Buffer (1 .. U'Length) := U;
98       Name_Len := U'Length;
99       Set_Casing (All_Lower_Case);
100       Name_Buffer (Name_Len + 1) := '%';
101       Name_Buffer (Name_Len + 2) := Typ;
102       Name_Len := Name_Len + 2;
103       Unm := Name_Find;
104       Name_Buffer (1 .. F'Length) := F;
105       Name_Len := F'Length;
106       Fnm := Name_Find;
107       Fname.UF.Set_File_Name (Unm, Fnm);
108    end Set_File_Name;
109
110    ---------------------------
111    -- Set_File_Name_Pattern --
112    ---------------------------
113
114    procedure Set_File_Name_Pattern
115      (Pat : String;
116       Typ : Character;
117       Dot : String;
118       Cas : Character)
119    is
120       Ctyp : Casing_Type;
121       Patp : constant String_Ptr := new String'(Pat);
122       Dotp : constant String_Ptr := new String'(Dot);
123
124    begin
125       if Cas = 'l' then
126          Ctyp := All_Lower_Case;
127       elsif Cas = 'u' then
128          Ctyp := All_Upper_Case;
129       else -- Cas = 'm'
130          Ctyp := Mixed_Case;
131       end if;
132
133       Fname.UF.Set_File_Name_Pattern (Patp, Typ, Dotp, Ctyp);
134    end Set_File_Name_Pattern;
135
136 end Fname.SF;