Imported GNU Classpath 0.90
[official-gcc.git] / gcc / ada / osint-b.adb
blob2dc070ebd7e72103a4dc7b033d1ca76f7251b22e
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-2005 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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 ------------------------------------------------------------------------------
27 with Namet; use Namet;
28 with Opt; use Opt;
29 with Targparm; use Targparm;
31 package body Osint.B is
33 Binder_Output_Time_Stamps_Set : Boolean := False;
35 Old_Binder_Output_Time_Stamp : Time_Stamp_Type;
36 New_Binder_Output_Time_Stamp : Time_Stamp_Type;
37 Recording_Time_From_Last_Bind : Boolean := False;
39 -------------------------
40 -- Close_Binder_Output --
41 -------------------------
43 procedure Close_Binder_Output is
44 Status : Boolean;
45 begin
46 Close (Output_FD, Status);
48 if not Status then
49 Fail
50 ("error while closing generated file ",
51 Get_Name_String (Output_File_Name));
52 end if;
54 if Recording_Time_From_Last_Bind then
55 New_Binder_Output_Time_Stamp := File_Stamp (Output_File_Name);
56 Binder_Output_Time_Stamps_Set := True;
57 end if;
58 end Close_Binder_Output;
60 --------------------------
61 -- Create_Binder_Output --
62 --------------------------
64 procedure Create_Binder_Output
65 (Output_File_Name : String;
66 Typ : Character;
67 Bfile : out Name_Id)
69 File_Name : String_Ptr;
70 Findex1 : Natural;
71 Findex2 : Natural;
72 Flength : Natural;
74 Bind_File_Prefix_Len : Natural := 2;
75 -- Length of binder file prefix (normally set to 2 for b~, but gets
76 -- reset to 3 for VMS for b__).
78 begin
79 if Output_File_Name /= "" then
80 Name_Buffer (Output_File_Name'Range) := Output_File_Name;
81 Name_Buffer (Output_File_Name'Last + 1) := ASCII.NUL;
83 if Typ = 's' then
84 Name_Buffer (Output_File_Name'Last) := 's';
85 end if;
87 Name_Len := Output_File_Name'Last;
89 else
90 Name_Buffer (1) := 'b';
91 File_Name := File_Names (Current_File_Name_Index);
93 Findex1 := File_Name'First;
95 -- The ali file might be specified by a full path name. However,
96 -- the binder generated file should always be created in the
97 -- current directory, so the path might need to be stripped away.
98 -- In addition to the default directory_separator allow the '/' to
99 -- act as separator since this is allowed in MS-DOS and OS2 ports.
101 for J in reverse File_Name'Range loop
102 if File_Name (J) = Directory_Separator
103 or else File_Name (J) = '/'
104 then
105 Findex1 := J + 1;
106 exit;
107 end if;
108 end loop;
110 Findex2 := File_Name'Last;
111 while File_Name (Findex2) /= '.' loop
112 Findex2 := Findex2 - 1;
113 end loop;
115 Flength := Findex2 - Findex1;
117 if Maximum_File_Name_Length > 0 then
119 if OpenVMS_On_Target and then Typ /= 'c' then
120 Bind_File_Prefix_Len := 3;
121 end if;
123 -- Make room for the extra two characters in "b?"
125 while Int (Flength) >
126 Maximum_File_Name_Length - Nat (Bind_File_Prefix_Len)
127 loop
128 Findex2 := Findex2 - 1;
129 Flength := Findex2 - Findex1;
130 end loop;
131 end if;
133 Name_Buffer
134 (Bind_File_Prefix_Len + 1 .. Flength + Bind_File_Prefix_Len) :=
135 File_Name (Findex1 .. Findex2 - 1);
136 Name_Buffer (Flength + Bind_File_Prefix_Len + 1) := '.';
138 -- C bind file, name is b_xxx.c
140 if Typ = 'c' then
141 Name_Buffer (2) := '_';
142 Name_Buffer (Flength + 4) := 'c';
143 Name_Buffer (Flength + 5) := ASCII.NUL;
144 Name_Len := Flength + 4;
146 -- Ada bind file, name is b~xxx.adb or b~xxx.ads
147 -- (with __ instead of ~ in VMS)
149 else
150 if OpenVMS_On_Target then
151 Name_Buffer (2) := '_';
152 Name_Buffer (3) := '_';
153 else
154 Name_Buffer (2) := '~';
155 end if;
157 Name_Buffer (Flength + Bind_File_Prefix_Len + 2) := 'a';
158 Name_Buffer (Flength + Bind_File_Prefix_Len + 3) := 'd';
159 Name_Buffer (Flength + Bind_File_Prefix_Len + 4) := Typ;
160 Name_Buffer (Flength + Bind_File_Prefix_Len + 5) := ASCII.NUL;
161 Name_Len := Flength + Bind_File_Prefix_Len + 4;
162 end if;
163 end if;
165 Bfile := Name_Find;
167 if Recording_Time_From_Last_Bind then
168 Old_Binder_Output_Time_Stamp := File_Stamp (Bfile);
169 end if;
171 Create_File_And_Check (Output_FD, Text);
172 end Create_Binder_Output;
174 --------------------
175 -- More_Lib_Files --
176 --------------------
178 function More_Lib_Files return Boolean renames More_Files;
180 ------------------------
181 -- Next_Main_Lib_File --
182 ------------------------
184 function Next_Main_Lib_File return File_Name_Type renames Next_Main_File;
186 --------------------------------
187 -- Record_Time_From_Last_Bind --
188 --------------------------------
190 procedure Record_Time_From_Last_Bind is
191 begin
192 Recording_Time_From_Last_Bind := True;
193 end Record_Time_From_Last_Bind;
195 -------------------------
196 -- Time_From_Last_Bind --
197 -------------------------
199 function Time_From_Last_Bind return Nat is
200 Old_Y : Nat;
201 Old_M : Nat;
202 Old_D : Nat;
203 Old_H : Nat;
204 Old_Mi : Nat;
205 Old_S : Nat;
206 New_Y : Nat;
207 New_M : Nat;
208 New_D : Nat;
209 New_H : Nat;
210 New_Mi : Nat;
211 New_S : Nat;
213 type Month_Data is array (Int range 1 .. 12) of Int;
214 Cumul : constant Month_Data := (0, 0, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7);
215 -- Represents the difference in days from a period compared to the
216 -- same period if all months had 31 days, i.e:
218 -- Cumul (m) = 31x(m-1) - (number of days from 01/01 to m/01)
220 Res : Int;
222 begin
223 if not Recording_Time_From_Last_Bind
224 or else not Binder_Output_Time_Stamps_Set
225 or else Old_Binder_Output_Time_Stamp = Empty_Time_Stamp
226 then
227 return Nat'Last;
228 end if;
230 Split_Time_Stamp
231 (Old_Binder_Output_Time_Stamp,
232 Old_Y, Old_M, Old_D, Old_H, Old_Mi, Old_S);
234 Split_Time_Stamp
235 (New_Binder_Output_Time_Stamp,
236 New_Y, New_M, New_D, New_H, New_Mi, New_S);
238 Res := New_Mi - Old_Mi;
240 -- 60 minutes in an hour
242 Res := Res + 60 * (New_H - Old_H);
244 -- 24 hours in a day
246 Res := Res + 60 * 24 * (New_D - Old_D);
248 -- Almost 31 days in a month
250 Res := Res + 60 * 24 *
251 (31 * (New_M - Old_M) - Cumul (New_M) + Cumul (Old_M));
253 -- 365 days in a year
255 Res := Res + 60 * 24 * 365 * (New_Y - Old_Y);
257 return Res;
258 end Time_From_Last_Bind;
260 -----------------------
261 -- Write_Binder_Info --
262 -----------------------
264 procedure Write_Binder_Info (Info : String) renames Write_Info;
266 begin
267 Set_Program (Binder);
268 end Osint.B;