[gcc/testsuite]
[official-gcc.git] / gcc / ada / fname-sf.adb
blobbe115bca0b717dbb964be568815a354b008988a6
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-2017, 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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Casing; use Casing;
27 with Fname; use Fname;
28 with Fname.UF; use Fname.UF;
29 with SFN_Scan; use SFN_Scan;
30 with Osint; use Osint;
31 with Types; use Types;
33 with Unchecked_Conversion;
35 package body Fname.SF is
37 ----------------------
38 -- Local Procedures --
39 ----------------------
41 procedure Set_File_Name
42 (Typ : Character;
43 U : String;
44 F : String;
45 Index : Natural);
46 -- This is a transfer function that is called from Scan_SFN_Pragmas,
47 -- and reformats its parameters appropriately for the version of
48 -- Set_File_Name found in Fname.SF.
50 procedure Set_File_Name_Pattern
51 (Pat : String;
52 Typ : Character;
53 Dot : String;
54 Cas : Character);
55 -- This is a transfer function that is called from Scan_SFN_Pragmas,
56 -- and reformats its parameters appropriately for the version of
57 -- Set_File_Name_Pattern found in Fname.SF.
59 -----------------------------------
60 -- Read_Source_File_Name_Pragmas --
61 -----------------------------------
63 procedure Read_Source_File_Name_Pragmas is
64 Src : Source_Buffer_Ptr;
65 Hi : Source_Ptr;
67 begin
68 Read_Source_File (Name_Enter ("gnat.adc"), 1, Hi, Src);
70 if not Null_Source_Buffer_Ptr (Src) then
71 -- We need to strip off the trailing EOF that was added by
72 -- Read_Source_File, because there might be another EOF in
73 -- the file, and two in a row causes Scan_SFN_Pragmas to give
74 -- errors.
76 pragma Assert (Src (Hi) = EOF);
77 Scan_SFN_Pragmas
78 (String (Src (1 .. Hi - 1)),
79 Set_File_Name'Access,
80 Set_File_Name_Pattern'Access);
81 end if;
82 end Read_Source_File_Name_Pragmas;
84 -------------------
85 -- Set_File_Name --
86 -------------------
88 procedure Set_File_Name
89 (Typ : Character;
90 U : String;
91 F : String;
92 Index : Natural)
94 Unm : Unit_Name_Type;
95 Fnm : File_Name_Type;
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, Nat (Index));
108 end Set_File_Name;
110 ---------------------------
111 -- Set_File_Name_Pattern --
112 ---------------------------
114 procedure Set_File_Name_Pattern
115 (Pat : String;
116 Typ : Character;
117 Dot : String;
118 Cas : Character)
120 Ctyp : Casing_Type;
121 Patp : constant String_Ptr := new String'(Pat);
122 Dotp : constant String_Ptr := new String'(Dot);
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;
133 Fname.UF.Set_File_Name_Pattern (Patp, Typ, Dotp, Ctyp);
134 end Set_File_Name_Pattern;
136 end Fname.SF;