| 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-2025, 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 |
------------------------------------------------------------------------------ |
| 25 |
|
| 26 |
with Casing; use Casing; |
| 27 |
with Fname.UF; use Fname.UF; |
| 28 |
with SFN_Scan; use SFN_Scan; |
| 29 |
with Osint; use Osint; |
| 30 |
with Types; use Types; |
| 31 |
with System.OS_Lib; use System.OS_Lib; |
| 32 |
|
| 33 |
package body Fname.SF is |
| 34 |
|
| 35 |
---------------------- |
| 36 |
-- Local Procedures -- |
| 37 |
---------------------- |
| 38 |
|
| 39 |
procedure Set_File_Name |
| 40 |
(Typ : Character; |
| 41 |
U : String; |
| 42 |
F : String; |
| 43 |
Index : Natural); |
| 44 |
-- This is a transfer function that is called from Scan_SFN_Pragmas, |
| 45 |
-- and reformats its parameters appropriately for the version of |
| 46 |
-- Set_File_Name found in Fname.SF. |
| 47 |
|
| 48 |
procedure Set_File_Name_Pattern |
| 49 |
(Pat : String; |
| 50 |
Typ : Character; |
| 51 |
Dot : String; |
| 52 |
Cas : Character); |
| 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_Pattern found in Fname.SF. |
| 56 |
|
| 57 |
----------------------------------- |
| 58 |
-- Read_Source_File_Name_Pragmas -- |
| 59 |
----------------------------------- |
| 60 |
|
| 61 |
procedure Read_Source_File_Name_Pragmas is |
| 62 |
FD : File_Descriptor; |
| 63 |
Src : Source_Buffer_Ptr; |
| 64 |
Hi : Source_Ptr; |
| 65 |
|
| 66 |
begin |
| 67 |
Read_Source_File (Name_Enter ("gnat.adc"), 1, Hi, Src, FD); |
| 68 |
|
| 69 |
if not Null_Source_Buffer_Ptr (Src) then |
| 70 |
-- We need to strip off the trailing EOF that was added by |
| 71 |
-- Read_Source_File, because there might be another EOF in |
| 72 |
-- the file, and two in a row causes Scan_SFN_Pragmas to give |
| 73 |
-- errors. |
| 74 |
|
| 75 |
pragma Assert (Src (Hi) = EOF); |
| 76 |
Scan_SFN_Pragmas |
| 77 |
(String (Src (1 .. Hi - 1)), |
| 78 |
Set_File_Name'Access, |
| 79 |
Set_File_Name_Pattern'Access); |
| 80 |
end if; |
| 81 |
end Read_Source_File_Name_Pragmas; |
| 82 |
|
| 83 |
------------------- |
| 84 |
-- Set_File_Name -- |
| 85 |
------------------- |
| 86 |
|
| 87 |
procedure Set_File_Name |
| 88 |
(Typ : Character; |
| 89 |
U : String; |
| 90 |
F : String; |
| 91 |
Index : Natural) |
| 92 |
is |
| 93 |
Unm : Unit_Name_Type; |
| 94 |
Fnm : File_Name_Type; |
| 95 |
begin |
| 96 |
Name_Buffer (1 .. U'Length) := U; |
| 97 |
Name_Len := U'Length; |
| 98 |
Set_Casing (All_Lower_Case); |
| 99 |
Name_Buffer (Name_Len + 1) := '%'; |
| 100 |
Name_Buffer (Name_Len + 2) := Typ; |
| 101 |
Name_Len := Name_Len + 2; |
| 102 |
Unm := Name_Find; |
| 103 |
Name_Buffer (1 .. F'Length) := F; |
| 104 |
Name_Len := F'Length; |
| 105 |
Fnm := Name_Find; |
| 106 |
Fname.UF.Set_File_Name (Unm, Fnm, Nat (Index)); |
| 107 |
end Set_File_Name; |
| 108 |
|
| 109 |
--------------------------- |
| 110 |
-- Set_File_Name_Pattern -- |
| 111 |
--------------------------- |
| 112 |
|
| 113 |
procedure Set_File_Name_Pattern |
| 114 |
(Pat : String; |
| 115 |
Typ : Character; |
| 116 |
Dot : String; |
| 117 |
Cas : Character) |
| 118 |
is |
| 119 |
Ctyp : Casing_Type; |
| 120 |
Patp : constant String_Ptr := new String'(Pat); |
| 121 |
Dotp : constant String_Ptr := new String'(Dot); |
| 122 |
|
| 123 |
begin |
| 124 |
if Cas = 'l' then |
| 125 |
Ctyp := All_Lower_Case; |
| 126 |
elsif Cas = 'u' then |
| 127 |
Ctyp := All_Upper_Case; |
| 128 |
else -- Cas = 'm' |
| 129 |
Ctyp := Mixed_Case; |
| 130 |
end if; |
| 131 |
|
| 132 |
Fname.UF.Set_File_Name_Pattern (Patp, Typ, Dotp, Ctyp); |
| 133 |
end Set_File_Name_Pattern; |
| 134 |
|
| 135 |
end Fname.SF; |