OSDN Git Service

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