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 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. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
28 with Osint.C; use Osint.C;
30 package body Lib.Util is
32 Max_Line : constant Natural := 2 * Hostparm.Max_Name_Length + 64;
33 Max_Buffer : constant Natural := 1000 * Max_Line;
35 Info_Buffer : String (1 .. Max_Buffer);
36 -- Info_Buffer used to prepare lines of library output
38 Info_Buffer_Len : Natural := 0;
39 -- Number of characters stored in Info_Buffer
41 Info_Buffer_Col : Natural := 1;
42 -- Column number of next character to be written.
43 -- Can be different from Info_Buffer_Len + 1
44 -- because of tab characters written by Write_Info_Tab.
50 procedure Write_Info_Char (C : Character) is
52 Info_Buffer_Len := Info_Buffer_Len + 1;
53 Info_Buffer (Info_Buffer_Len) := C;
54 Info_Buffer_Col := Info_Buffer_Col + 1;
57 --------------------------
58 -- Write_Info_Char_Code --
59 --------------------------
61 procedure Write_Info_Char_Code (Code : Char_Code) is
63 procedure Write_Info_Hex_Byte (J : Natural);
64 -- Write single hex digit
66 procedure Write_Info_Hex_Byte (J : Natural) is
67 Hexd : constant String := "0123456789abcdef";
70 Write_Info_Char (Hexd (J / 16 + 1));
71 Write_Info_Char (Hexd (J mod 16 + 1));
72 end Write_Info_Hex_Byte;
74 -- Start of processing for Write_Info_Char_Code
79 if Code <= 16#7F# then
80 Write_Info_Char (Character'Val (Code));
84 elsif Code <= 16#FF# then
85 Write_Info_Char ('U');
86 Write_Info_Hex_Byte (Natural (Code));
91 Write_Info_Char ('W');
92 Write_Info_Hex_Byte (Natural (Code / 256));
93 Write_Info_Hex_Byte (Natural (Code mod 256));
95 end Write_Info_Char_Code;
101 function Write_Info_Col return Positive is
103 return Info_Buffer_Col;
110 procedure Write_Info_EOL is
113 or else Info_Buffer_Len + Max_Line + 1 > Max_Buffer
115 Write_Info_Terminate;
117 -- Delete any trailing blanks
119 while Info_Buffer_Len > 0
120 and then Info_Buffer (Info_Buffer_Len) = ' '
122 Info_Buffer_Len := Info_Buffer_Len - 1;
125 Info_Buffer_Len := Info_Buffer_Len + 1;
126 Info_Buffer (Info_Buffer_Len) := ASCII.LF;
127 Info_Buffer_Col := 1;
131 -------------------------
132 -- Write_Info_Initiate --
133 -------------------------
135 procedure Write_Info_Initiate (Key : Character) renames Write_Info_Char;
137 ---------------------
138 -- Write_Info_Name --
139 ---------------------
141 procedure Write_Info_Name (Name : Name_Id) is
143 Get_Name_String (Name);
144 Info_Buffer (Info_Buffer_Len + 1 .. Info_Buffer_Len + Name_Len) :=
145 Name_Buffer (1 .. Name_Len);
146 Info_Buffer_Len := Info_Buffer_Len + Name_Len;
147 Info_Buffer_Col := Info_Buffer_Col + Name_Len;
150 procedure Write_Info_Name (Name : File_Name_Type) is
152 Write_Info_Name (Name_Id (Name));
155 procedure Write_Info_Name (Name : Unit_Name_Type) is
157 Write_Info_Name (Name_Id (Name));
164 procedure Write_Info_Nat (N : Nat) is
167 Write_Info_Nat (N / 10);
170 Write_Info_Char (Character'Val (N mod 10 + Character'Pos ('0')));
177 procedure Write_Info_Str (Val : String) is
179 Info_Buffer (Info_Buffer_Len + 1 .. Info_Buffer_Len + Val'Length)
181 Info_Buffer_Len := Info_Buffer_Len + Val'Length;
182 Info_Buffer_Col := Info_Buffer_Col + Val'Length;
189 procedure Write_Info_Tab (Col : Positive) is
193 if Col <= Info_Buffer_Col then
194 Write_Info_Str (" ");
197 Next_Tab := 8 * ((Info_Buffer_Col - 1) / 8) + 8 + 1;
198 exit when Col < Next_Tab;
199 Write_Info_Char (ASCII.HT);
200 Info_Buffer_Col := Next_Tab;
203 while Info_Buffer_Col < Col loop
204 Write_Info_Char (' ');
209 --------------------------
210 -- Write_Info_Terminate --
211 --------------------------
213 procedure Write_Info_Terminate is
215 -- Delete any trailing blanks
217 while Info_Buffer_Len > 0
218 and then Info_Buffer (Info_Buffer_Len) = ' '
220 Info_Buffer_Len := Info_Buffer_Len - 1;
223 -- Write_Library_Info adds the EOL
225 Write_Library_Info (Info_Buffer (1 .. Info_Buffer_Len));
227 Info_Buffer_Len := 0;
228 Info_Buffer_Col := 1;
230 end Write_Info_Terminate;