OSDN Git Service

2007-08-31 Robert Dewar <dewar@adacore.com>
[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 --          Copyright (C) 2001-2007, 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 ------------------------------------------------------------------------------
26
27 with Opt;      use Opt;
28 with Targparm; use Targparm;
29
30 package body Osint.B is
31
32    -------------------------
33    -- Close_Binder_Output --
34    -------------------------
35
36    procedure Close_Binder_Output is
37       Status : Boolean;
38    begin
39       Close (Output_FD, Status);
40
41       if not Status then
42          Fail
43            ("error while closing generated file ",
44             Get_Name_String (Output_File_Name));
45       end if;
46
47    end Close_Binder_Output;
48
49    --------------------------
50    -- Create_Binder_Output --
51    --------------------------
52
53    procedure Create_Binder_Output
54      (Output_File_Name : String;
55       Typ              : Character;
56       Bfile            : out Name_Id)
57    is
58       File_Name : String_Ptr;
59       Findex1   : Natural;
60       Findex2   : Natural;
61       Flength   : Natural;
62
63       Bind_File_Prefix_Len : Natural := 2;
64       --  Length of binder file prefix (normally set to 2 for b~, but gets
65       --  reset to 3 for VMS for b__).
66
67    begin
68       if Output_File_Name /= "" then
69          Name_Buffer (Output_File_Name'Range) := Output_File_Name;
70          Name_Buffer (Output_File_Name'Last + 1) := ASCII.NUL;
71
72          if Typ = 's' then
73             Name_Buffer (Output_File_Name'Last) := 's';
74          end if;
75
76          Name_Len := Output_File_Name'Last;
77
78       else
79          Name_Buffer (1) := 'b';
80          File_Name := File_Names (Current_File_Name_Index);
81
82          Findex1 := File_Name'First;
83
84          --  The ali file might be specified by a full path name. However,
85          --  the binder generated file should always be created in the
86          --  current directory, so the path might need to be stripped away.
87          --  In addition to the default directory_separator allow the '/' to
88          --  act as separator since this is allowed in MS-DOS and OS2 ports.
89
90          for J in reverse File_Name'Range loop
91             if File_Name (J) = Directory_Separator
92               or else File_Name (J) = '/'
93             then
94                Findex1 := J + 1;
95                exit;
96             end if;
97          end loop;
98
99          Findex2 := File_Name'Last;
100          while File_Name (Findex2) /=  '.' loop
101             Findex2 := Findex2 - 1;
102          end loop;
103
104          Flength := Findex2 - Findex1;
105
106          if Maximum_File_Name_Length > 0 then
107
108             if OpenVMS_On_Target and then Typ /= 'c' then
109                Bind_File_Prefix_Len := 3;
110             end if;
111
112             --  Make room for the extra two characters in "b?"
113
114             while Int (Flength) >
115               Maximum_File_Name_Length - Nat (Bind_File_Prefix_Len)
116             loop
117                Findex2 := Findex2 - 1;
118                Flength := Findex2 - Findex1;
119             end loop;
120          end if;
121
122          Name_Buffer
123            (Bind_File_Prefix_Len + 1 .. Flength + Bind_File_Prefix_Len) :=
124               File_Name (Findex1 .. Findex2 - 1);
125          Name_Buffer (Flength + Bind_File_Prefix_Len + 1) := '.';
126
127          --  C bind file, name is b_xxx.c
128
129          if Typ = 'c' then
130             Name_Buffer (2) := '_';
131             Name_Buffer (Flength + 4) := 'c';
132             Name_Buffer (Flength + 5) := ASCII.NUL;
133             Name_Len := Flength + 4;
134
135          --  Ada bind file, name is b~xxx.adb or b~xxx.ads
136          --  (with __ instead of ~ in VMS)
137
138          else
139             if OpenVMS_On_Target then
140                Name_Buffer (2) := '_';
141                Name_Buffer (3) := '_';
142             else
143                Name_Buffer (2) := '~';
144             end if;
145
146             Name_Buffer (Flength + Bind_File_Prefix_Len + 2) := 'a';
147             Name_Buffer (Flength + Bind_File_Prefix_Len + 3) := 'd';
148             Name_Buffer (Flength + Bind_File_Prefix_Len + 4) := Typ;
149             Name_Buffer (Flength + Bind_File_Prefix_Len + 5) := ASCII.NUL;
150             Name_Len := Flength + Bind_File_Prefix_Len + 4;
151          end if;
152       end if;
153
154       Bfile := Name_Find;
155
156       Create_File_And_Check (Output_FD, Text);
157    end Create_Binder_Output;
158
159    --------------------
160    -- More_Lib_Files --
161    --------------------
162
163    function More_Lib_Files return Boolean renames  More_Files;
164
165    ------------------------
166    -- Next_Main_Lib_File --
167    ------------------------
168
169    function Next_Main_Lib_File return File_Name_Type renames Next_Main_File;
170
171    -----------------------
172    -- Write_Binder_Info --
173    -----------------------
174
175    procedure Write_Binder_Info (Info : String) renames Write_Info;
176
177 begin
178    Set_Program (Binder);
179 end Osint.B;