Delete all lines containing "$Revision:".
[gcc.git] / gcc / ada / osint-b.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- O S I N T - B --
6 -- --
7 -- B o d y --
8 -- --
9 -- --
10 -- Copyright (C) 2001 Free Software Foundation, Inc. --
11 -- --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
22 -- --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
25 -- --
26 ------------------------------------------------------------------------------
27
28 with Hostparm;
29 with Namet; use Namet;
30 with Opt; use Opt;
31
32 package body Osint.B is
33
34 Binder_Output_Time_Stamps_Set : Boolean := False;
35
36 Old_Binder_Output_Time_Stamp : Time_Stamp_Type;
37 New_Binder_Output_Time_Stamp : Time_Stamp_Type;
38 Recording_Time_From_Last_Bind : Boolean := False;
39
40 -------------------------
41 -- Close_Binder_Output --
42 -------------------------
43
44 procedure Close_Binder_Output is
45 begin
46 Close (Output_FD);
47
48 if Recording_Time_From_Last_Bind then
49 New_Binder_Output_Time_Stamp := File_Stamp (Output_File_Name);
50 Binder_Output_Time_Stamps_Set := True;
51 end if;
52 end Close_Binder_Output;
53
54 --------------------------
55 -- Create_Binder_Output --
56 --------------------------
57
58 procedure Create_Binder_Output
59 (Output_File_Name : String;
60 Typ : Character;
61 Bfile : out Name_Id)
62 is
63 File_Name : String_Ptr;
64 Findex1 : Natural;
65 Findex2 : Natural;
66 Flength : Natural;
67
68 begin
69 if Output_File_Name /= "" then
70 Name_Buffer (Output_File_Name'Range) := Output_File_Name;
71 Name_Buffer (Output_File_Name'Last + 1) := ASCII.NUL;
72
73 if Typ = 's' then
74 Name_Buffer (Output_File_Name'Last) := 's';
75 end if;
76
77 Name_Len := Output_File_Name'Last;
78
79 else
80 Name_Buffer (1) := 'b';
81 File_Name := File_Names (Current_File_Name_Index);
82
83 Findex1 := File_Name'First;
84
85 -- The ali file might be specified by a full path name. However,
86 -- the binder generated file should always be created in the
87 -- current directory, so the path might need to be stripped away.
88 -- In addition to the default directory_separator allow the '/' to
89 -- act as separator since this is allowed in MS-DOS and OS2 ports.
90
91 for J in reverse File_Name'Range loop
92 if File_Name (J) = Directory_Separator
93 or else File_Name (J) = '/'
94 then
95 Findex1 := J + 1;
96 exit;
97 end if;
98 end loop;
99
100 Findex2 := File_Name'Last;
101 while File_Name (Findex2) /= '.' loop
102 Findex2 := Findex2 - 1;
103 end loop;
104
105 Flength := Findex2 - Findex1;
106
107 if Maximum_File_Name_Length > 0 then
108
109 -- Make room for the extra two characters in "b?"
110
111 while Int (Flength) > Maximum_File_Name_Length - 2 loop
112 Findex2 := Findex2 - 1;
113 Flength := Findex2 - Findex1;
114 end loop;
115 end if;
116
117 Name_Buffer (3 .. Flength + 2) := File_Name (Findex1 .. Findex2 - 1);
118 Name_Buffer (Flength + 3) := '.';
119
120 -- C bind file, name is b_xxx.c
121
122 if Typ = 'c' then
123 Name_Buffer (2) := '_';
124 Name_Buffer (Flength + 4) := 'c';
125 Name_Buffer (Flength + 5) := ASCII.NUL;
126 Name_Len := Flength + 4;
127
128 -- Ada bind file, name is b~xxx.adb or b~xxx.ads
129 -- (with $ instead of ~ in VMS)
130
131 else
132 if Hostparm.OpenVMS then
133 Name_Buffer (2) := '$';
134 else
135 Name_Buffer (2) := '~';
136 end if;
137
138 Name_Buffer (Flength + 4) := 'a';
139 Name_Buffer (Flength + 5) := 'd';
140 Name_Buffer (Flength + 6) := Typ;
141 Name_Buffer (Flength + 7) := ASCII.NUL;
142 Name_Len := Flength + 6;
143 end if;
144 end if;
145
146 Bfile := Name_Find;
147
148 if Recording_Time_From_Last_Bind then
149 Old_Binder_Output_Time_Stamp := File_Stamp (Bfile);
150 end if;
151
152 Create_File_And_Check (Output_FD, Text);
153 end Create_Binder_Output;
154
155 --------------------
156 -- More_Lib_Files --
157 --------------------
158
159 function More_Lib_Files return Boolean renames More_Files;
160
161 ------------------------
162 -- Next_Main_Lib_File --
163 ------------------------
164
165 function Next_Main_Lib_File return File_Name_Type renames Next_Main_File;
166
167 --------------------------------
168 -- Record_Time_From_Last_Bind --
169 --------------------------------
170
171 procedure Record_Time_From_Last_Bind is
172 begin
173 Recording_Time_From_Last_Bind := True;
174 end Record_Time_From_Last_Bind;
175
176 -------------------------
177 -- Time_From_Last_Bind --
178 -------------------------
179
180 function Time_From_Last_Bind return Nat is
181 Old_Y : Nat;
182 Old_M : Nat;
183 Old_D : Nat;
184 Old_H : Nat;
185 Old_Mi : Nat;
186 Old_S : Nat;
187 New_Y : Nat;
188 New_M : Nat;
189 New_D : Nat;
190 New_H : Nat;
191 New_Mi : Nat;
192 New_S : Nat;
193
194 type Month_Data is array (Int range 1 .. 12) of Int;
195 Cumul : constant Month_Data := (0, 0, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7);
196 -- Represents the difference in days from a period compared to the
197 -- same period if all months had 31 days, i.e:
198 --
199 -- Cumul (m) = 31x(m-1) - (number of days from 01/01 to m/01)
200
201 Res : Int;
202
203 begin
204 if not Recording_Time_From_Last_Bind
205 or else not Binder_Output_Time_Stamps_Set
206 or else Old_Binder_Output_Time_Stamp = Empty_Time_Stamp
207 then
208 return Nat'Last;
209 end if;
210
211 Split_Time_Stamp
212 (Old_Binder_Output_Time_Stamp,
213 Old_Y, Old_M, Old_D, Old_H, Old_Mi, Old_S);
214
215 Split_Time_Stamp
216 (New_Binder_Output_Time_Stamp,
217 New_Y, New_M, New_D, New_H, New_Mi, New_S);
218
219 Res := New_Mi - Old_Mi;
220
221 -- 60 minutes in an hour
222
223 Res := Res + 60 * (New_H - Old_H);
224
225 -- 24 hours in a day
226
227 Res := Res + 60 * 24 * (New_D - Old_D);
228
229 -- Almost 31 days in a month
230
231 Res := Res + 60 * 24 *
232 (31 * (New_M - Old_M) - Cumul (New_M) + Cumul (Old_M));
233
234 -- 365 days in a year
235
236 Res := Res + 60 * 24 * 365 * (New_Y - Old_Y);
237
238 return Res;
239 end Time_From_Last_Bind;
240
241 -----------------------
242 -- Write_Binder_Info --
243 -----------------------
244
245 procedure Write_Binder_Info (Info : String) renames Write_Info;
246
247 begin
248 Set_Program (Binder);
249 end Osint.B;