2009-10-01 Tobias Burnus <burnus@net-b.de>
[official-gcc/alias-decl.git] / gcc / ada / osint-b.adb
blobb66cebf2ac2c14a7b26a08f5847ae518f98c7722
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- O S I N T - B --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2001-2008, 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 Opt; use Opt;
27 with Targparm; use Targparm;
29 package body Osint.B is
31 -------------------------
32 -- Close_Binder_Output --
33 -------------------------
35 procedure Close_Binder_Output is
36 Status : Boolean;
37 begin
38 Close (Output_FD, Status);
40 if not Status then
41 Fail
42 ("error while closing generated file "
43 & Get_Name_String (Output_File_Name));
44 end if;
46 end Close_Binder_Output;
48 --------------------------
49 -- Create_Binder_Output --
50 --------------------------
52 procedure Create_Binder_Output
53 (Output_File_Name : String;
54 Typ : Character;
55 Bfile : out Name_Id)
57 File_Name : String_Ptr;
58 Findex1 : Natural;
59 Findex2 : Natural;
60 Flength : Natural;
62 Bind_File_Prefix_Len : Natural := 2;
63 -- Length of binder file prefix (normally set to 2 for b~, but gets
64 -- reset to 3 for VMS for b__).
66 begin
67 if Output_File_Name /= "" then
68 Name_Buffer (Output_File_Name'Range) := Output_File_Name;
69 Name_Buffer (Output_File_Name'Last + 1) := ASCII.NUL;
71 if Typ = 's' then
72 Name_Buffer (Output_File_Name'Last) := 's';
73 end if;
75 Name_Len := Output_File_Name'Last;
77 else
78 Name_Buffer (1) := 'b';
79 File_Name := File_Names (Current_File_Name_Index);
81 Findex1 := File_Name'First;
83 -- The ali file might be specified by a full path name. However,
84 -- the binder generated file should always be created in the
85 -- current directory, so the path might need to be stripped away.
86 -- In addition to the default directory_separator allow the '/' to
87 -- act as separator since this is allowed in MS-DOS and OS2 ports.
89 for J in reverse File_Name'Range loop
90 if File_Name (J) = Directory_Separator
91 or else File_Name (J) = '/'
92 then
93 Findex1 := J + 1;
94 exit;
95 end if;
96 end loop;
98 Findex2 := File_Name'Last;
99 while File_Name (Findex2) /= '.' loop
100 Findex2 := Findex2 - 1;
101 end loop;
103 Flength := Findex2 - Findex1;
105 if Maximum_File_Name_Length > 0 then
107 if OpenVMS_On_Target and then Typ /= 'c' then
108 Bind_File_Prefix_Len := 3;
109 end if;
111 -- Make room for the extra two characters in "b?"
113 while Int (Flength) >
114 Maximum_File_Name_Length - Nat (Bind_File_Prefix_Len)
115 loop
116 Findex2 := Findex2 - 1;
117 Flength := Findex2 - Findex1;
118 end loop;
119 end if;
121 Name_Buffer
122 (Bind_File_Prefix_Len + 1 .. Flength + Bind_File_Prefix_Len) :=
123 File_Name (Findex1 .. Findex2 - 1);
124 Name_Buffer (Flength + Bind_File_Prefix_Len + 1) := '.';
126 -- C bind file, name is b_xxx.c
128 if Typ = 'c' then
129 Name_Buffer (2) := '_';
130 Name_Buffer (Flength + 4) := 'c';
131 Name_Buffer (Flength + 5) := ASCII.NUL;
132 Name_Len := Flength + 4;
134 -- Ada bind file, name is b~xxx.adb or b~xxx.ads
135 -- (with __ instead of ~ in VMS)
137 else
138 if OpenVMS_On_Target then
139 Name_Buffer (2) := '_';
140 Name_Buffer (3) := '_';
141 else
142 Name_Buffer (2) := '~';
143 end if;
145 Name_Buffer (Flength + Bind_File_Prefix_Len + 2) := 'a';
146 Name_Buffer (Flength + Bind_File_Prefix_Len + 3) := 'd';
147 Name_Buffer (Flength + Bind_File_Prefix_Len + 4) := Typ;
148 Name_Buffer (Flength + Bind_File_Prefix_Len + 5) := ASCII.NUL;
149 Name_Len := Flength + Bind_File_Prefix_Len + 4;
150 end if;
151 end if;
153 Bfile := Name_Find;
155 Create_File_And_Check (Output_FD, Text);
156 end Create_Binder_Output;
158 --------------------
159 -- More_Lib_Files --
160 --------------------
162 function More_Lib_Files return Boolean renames More_Files;
164 ------------------------
165 -- Next_Main_Lib_File --
166 ------------------------
168 function Next_Main_Lib_File return File_Name_Type renames Next_Main_File;
170 ---------------------------------
171 -- Set_Current_File_Name_Index --
172 ---------------------------------
174 procedure Set_Current_File_Name_Index (To : Int) is
175 begin
176 Current_File_Name_Index := To;
177 end Set_Current_File_Name_Index;
179 -----------------------
180 -- Write_Binder_Info --
181 -----------------------
183 procedure Write_Binder_Info (Info : String) renames Write_Info;
185 begin
186 Set_Program (Binder);
187 end Osint.B;