1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
27 with Osint
.C
; use Osint
.C
;
29 package body Lib
.Util
is
31 Max_Line
: constant Natural := 2 * Hostparm
.Max_Name_Length
+ 64;
32 Max_Buffer
: constant Natural := 1000 * Max_Line
;
34 Info_Buffer
: String (1 .. Max_Buffer
);
35 -- Info_Buffer used to prepare lines of library output
37 Info_Buffer_Len
: Natural := 0;
38 -- Number of characters stored in Info_Buffer
40 Info_Buffer_Col
: Natural := 1;
41 -- Column number of next character to be written.
42 -- Can be different from Info_Buffer_Len + 1
43 -- because of tab characters written by Write_Info_Tab.
49 procedure Write_Info_Char
(C
: Character) is
51 Info_Buffer_Len
:= Info_Buffer_Len
+ 1;
52 Info_Buffer
(Info_Buffer_Len
) := C
;
53 Info_Buffer_Col
:= Info_Buffer_Col
+ 1;
56 --------------------------
57 -- Write_Info_Char_Code --
58 --------------------------
60 procedure Write_Info_Char_Code
(Code
: Char_Code
) is
62 procedure Write_Info_Hex_Byte
(J
: Natural);
63 -- Write single hex digit
65 procedure Write_Info_Hex_Byte
(J
: Natural) is
66 Hexd
: constant String := "0123456789abcdef";
69 Write_Info_Char
(Hexd
(J
/ 16 + 1));
70 Write_Info_Char
(Hexd
(J
mod 16 + 1));
71 end Write_Info_Hex_Byte
;
73 -- Start of processing for Write_Info_Char_Code
78 if Code
<= 16#
7F#
then
79 Write_Info_Char
(Character'Val (Code
));
83 elsif Code
<= 16#FF#
then
84 Write_Info_Char
('U');
85 Write_Info_Hex_Byte
(Natural (Code
));
90 Write_Info_Char
('W');
91 Write_Info_Hex_Byte
(Natural (Code
/ 256));
92 Write_Info_Hex_Byte
(Natural (Code
mod 256));
94 end Write_Info_Char_Code
;
100 function Write_Info_Col
return Positive is
102 return Info_Buffer_Col
;
109 procedure Write_Info_EOL
is
112 or else Info_Buffer_Len
+ Max_Line
+ 1 > Max_Buffer
114 Write_Info_Terminate
;
116 -- Delete any trailing blanks
118 while Info_Buffer_Len
> 0
119 and then Info_Buffer
(Info_Buffer_Len
) = ' '
121 Info_Buffer_Len
:= Info_Buffer_Len
- 1;
124 Info_Buffer_Len
:= Info_Buffer_Len
+ 1;
125 Info_Buffer
(Info_Buffer_Len
) := ASCII
.LF
;
126 Info_Buffer_Col
:= 1;
130 -------------------------
131 -- Write_Info_Initiate --
132 -------------------------
134 procedure Write_Info_Initiate
(Key
: Character) renames Write_Info_Char
;
136 ---------------------
137 -- Write_Info_Name --
138 ---------------------
140 procedure Write_Info_Name
(Name
: Name_Id
) is
142 Get_Name_String
(Name
);
143 Info_Buffer
(Info_Buffer_Len
+ 1 .. Info_Buffer_Len
+ Name_Len
) :=
144 Name_Buffer
(1 .. Name_Len
);
145 Info_Buffer_Len
:= Info_Buffer_Len
+ Name_Len
;
146 Info_Buffer_Col
:= Info_Buffer_Col
+ Name_Len
;
149 procedure Write_Info_Name
(Name
: File_Name_Type
) is
151 Write_Info_Name
(Name_Id
(Name
));
154 procedure Write_Info_Name
(Name
: Unit_Name_Type
) is
156 Write_Info_Name
(Name_Id
(Name
));
163 procedure Write_Info_Nat
(N
: Nat
) is
166 Write_Info_Nat
(N
/ 10);
169 Write_Info_Char
(Character'Val (N
mod 10 + Character'Pos ('0')));
176 procedure Write_Info_Str
(Val
: String) is
178 Info_Buffer
(Info_Buffer_Len
+ 1 .. Info_Buffer_Len
+ Val
'Length)
180 Info_Buffer_Len
:= Info_Buffer_Len
+ Val
'Length;
181 Info_Buffer_Col
:= Info_Buffer_Col
+ Val
'Length;
188 procedure Write_Info_Tab
(Col
: Positive) is
192 if Col
<= Info_Buffer_Col
then
193 Write_Info_Str
(" ");
196 Next_Tab
:= 8 * ((Info_Buffer_Col
- 1) / 8) + 8 + 1;
197 exit when Col
< Next_Tab
;
198 Write_Info_Char
(ASCII
.HT
);
199 Info_Buffer_Col
:= Next_Tab
;
202 while Info_Buffer_Col
< Col
loop
203 Write_Info_Char
(' ');
208 --------------------------
209 -- Write_Info_Terminate --
210 --------------------------
212 procedure Write_Info_Terminate
is
214 -- Delete any trailing blanks
216 while Info_Buffer_Len
> 0
217 and then Info_Buffer
(Info_Buffer_Len
) = ' '
219 Info_Buffer_Len
:= Info_Buffer_Len
- 1;
222 -- Write_Library_Info adds the EOL
224 Write_Library_Info
(Info_Buffer
(1 .. Info_Buffer_Len
));
226 Info_Buffer_Len
:= 0;
227 Info_Buffer_Col
:= 1;
229 end Write_Info_Terminate
;