1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
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. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- Extensive contributions were provided by Ada Core Technologies Inc. --
26 ------------------------------------------------------------------------------
29 with Namet
; use Namet
;
30 with Osint
.C
; use Osint
.C
;
32 package body Lib
.Util
is
34 Max_Line
: constant Natural := 2 * Hostparm
.Max_Name_Length
+ 64;
35 Max_Buffer
: constant Natural := 1000 * Max_Line
;
37 Info_Buffer
: String (1 .. Max_Buffer
);
38 -- Info_Buffer used to prepare lines of library output
40 Info_Buffer_Len
: Natural := 0;
41 -- Number of characters stored in Info_Buffer
43 Info_Buffer_Col
: Natural := 1;
44 -- Column number of next character to be written.
45 -- Can be different from Info_Buffer_Len + 1
46 -- because of tab characters written by Write_Info_Tab.
52 procedure Write_Info_Char
(C
: Character) is
54 Info_Buffer_Len
:= Info_Buffer_Len
+ 1;
55 Info_Buffer
(Info_Buffer_Len
) := C
;
56 Info_Buffer_Col
:= Info_Buffer_Col
+ 1;
59 --------------------------
60 -- Write_Info_Char_Code --
61 --------------------------
63 procedure Write_Info_Char_Code
(Code
: Char_Code
) is
65 procedure Write_Info_Hex_Byte
(J
: Natural);
66 -- Write single hex digit
68 procedure Write_Info_Hex_Byte
(J
: Natural) is
69 Hexd
: String := "0123456789abcdef";
72 Write_Info_Char
(Hexd
(J
/ 16 + 1));
73 Write_Info_Char
(Hexd
(J
mod 16 + 1));
74 end Write_Info_Hex_Byte
;
76 -- Start of processing for Write_Info_Char_Code
79 if Code
in 16#
00#
.. 16#
7F#
then
80 Write_Info_Char
(Character'Val (Code
));
82 elsif Code
in 16#
80#
.. 16#FF#
then
83 Write_Info_Char
('U');
84 Write_Info_Hex_Byte
(Natural (Code
));
87 Write_Info_Char
('W');
88 Write_Info_Hex_Byte
(Natural (Code
/ 256));
89 Write_Info_Hex_Byte
(Natural (Code
mod 256));
91 end Write_Info_Char_Code
;
97 function Write_Info_Col
return Positive is
99 return Info_Buffer_Col
;
106 procedure Write_Info_EOL
is
109 or else Info_Buffer_Len
+ Max_Line
+ 1 > Max_Buffer
111 Write_Info_Terminate
;
113 -- Delete any trailing blanks
115 while Info_Buffer_Len
> 0
116 and then Info_Buffer
(Info_Buffer_Len
) = ' '
118 Info_Buffer_Len
:= Info_Buffer_Len
- 1;
121 Info_Buffer_Len
:= Info_Buffer_Len
+ 1;
122 Info_Buffer
(Info_Buffer_Len
) := ASCII
.LF
;
123 Info_Buffer_Col
:= 1;
127 -------------------------
128 -- Write_Info_Initiate --
129 -------------------------
131 procedure Write_Info_Initiate
(Key
: Character) renames Write_Info_Char
;
133 ---------------------
134 -- Write_Info_Name --
135 ---------------------
137 procedure Write_Info_Name
(Name
: Name_Id
) is
139 Get_Name_String
(Name
);
140 Info_Buffer
(Info_Buffer_Len
+ 1 .. Info_Buffer_Len
+ Name_Len
) :=
141 Name_Buffer
(1 .. Name_Len
);
142 Info_Buffer_Len
:= Info_Buffer_Len
+ Name_Len
;
143 Info_Buffer_Col
:= Info_Buffer_Col
+ Name_Len
;
150 procedure Write_Info_Nat
(N
: Nat
) is
153 Write_Info_Nat
(N
/ 10);
156 Write_Info_Char
(Character'Val (N
mod 10 + Character'Pos ('0')));
163 procedure Write_Info_Str
(Val
: String) is
165 Info_Buffer
(Info_Buffer_Len
+ 1 .. Info_Buffer_Len
+ Val
'Length)
167 Info_Buffer_Len
:= Info_Buffer_Len
+ Val
'Length;
168 Info_Buffer_Col
:= Info_Buffer_Col
+ Val
'Length;
175 procedure Write_Info_Tab
(Col
: Positive) is
179 if Col
<= Info_Buffer_Col
then
180 Write_Info_Str
(" ");
183 Next_Tab
:= 8 * ((Info_Buffer_Col
- 1) / 8) + 8 + 1;
184 exit when Col
< Next_Tab
;
185 Write_Info_Char
(ASCII
.HT
);
186 Info_Buffer_Col
:= Next_Tab
;
189 while Info_Buffer_Col
< Col
loop
190 Write_Info_Char
(' ');
195 --------------------------
196 -- Write_Info_Terminate --
197 --------------------------
199 procedure Write_Info_Terminate
is
201 -- Delete any trailing blanks
203 while Info_Buffer_Len
> 0
204 and then Info_Buffer
(Info_Buffer_Len
) = ' '
206 Info_Buffer_Len
:= Info_Buffer_Len
- 1;
209 -- Write_Library_Info adds the EOL
211 Write_Library_Info
(Info_Buffer
(1 .. Info_Buffer_Len
));
213 Info_Buffer_Len
:= 0;
214 Info_Buffer_Col
:= 1;
216 end Write_Info_Terminate
;