/usr/share/ada/adainclude/gmpada/gnu_multiple_precision-generic_text_io.adb is in libgmpada4-dev 0.0.20131223-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | -- GMPAda, binding to the Ada Language for the GNU MultiPrecision library.
-- Copyright (C) 2007-2010 Nicolas Boulenguez <nicolas.boulenguez@free.fr>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
with Ada.IO_Exceptions;
with GNU_Multiple_Precision.Aux; use GNU_Multiple_Precision.Aux;
package body GNU_Multiple_Precision.Generic_Text_IO is
procedure Skip_Blanks_And_Separators (File : in File_Type);
procedure Skip_Blanks_And_Separators (File : in File_Type)
is
Item : Maybe_Character;
End_Of_Line : Boolean;
begin
loop
Look_Ahead (File, Item, End_Of_Line);
if End_Of_Line then
Skip_Line (File);
if End_Of_Page (File) then
Skip_Page (File);
end if;
elsif Is_Blank (To_Character (Item, Unused_Character)) then
Get (File, Item);
else
exit;
end if;
end loop;
end Skip_Blanks_And_Separators;
procedure Get
(File : in File_Type;
Item : in out Big_Integer;
Width : in Field := 0)
is
Actual_Width : Field;
Count : Field := 0;
EOL : Boolean;
Next : Character;
procedure Consume;
procedure Consume is
Ignored : Maybe_Character;
Temp : Maybe_Character;
begin
pragma Assert (Count < Actual_Width
and not End_Of_Line (File));
Get (File, Ignored);
pragma Unreferenced (Ignored);
Count := Count + 1;
Look_Ahead (File, Temp, EOL);
if Count < Actual_Width and not EOL then
Next := To_Character (Temp, Unused_Character);
else
Next := Unused_Character;
end if;
end Consume;
package Scan is new Generic_Scan (Next, Consume);
Temp : Maybe_Character;
begin
if Width /= 0 then
Actual_Width := Width;
else
Skip_Blanks_And_Separators (File);
Actual_Width := Max_IO_Length;
end if;
Look_Ahead (File, Temp, EOL);
if not EOL then
Next := To_Character (Temp, Unused_Character);
else
Next := Unused_Character;
end if;
Scan.Get_Mpz_T (Item.Value, Actual_Width);
if Count < Integer (Actual_Width) and not End_Of_Line (File) then
raise Ada.IO_Exceptions.Data_Error;
end if;
end Get;
procedure Get
(Item : in out Big_Integer;
Width : in Field := 0)
is
begin
Get (Current_Input, Item, Width);
end Get;
procedure Get
(From : in Maybe_String;
Item : in out Big_Integer;
Last : out Positive)
is
Next : Character; -- = From (Last - 1) in normal cases
procedure Consume;
procedure Consume is
begin
if Last <= From'Last then
Next := To_Character (From (Last), Unused_Character);
else
pragma Assert (Last = From'Last + 1);
Next := Unused_Character;
end if;
Last := Last + 1;
end Consume;
package Scan is new Generic_Scan (Next, Consume);
begin
Last := From'First;
Consume;
Scan.Get_Mpz_T (Item.Value, From'Length);
Last := Last - 2;
end Get;
procedure Put
(File : in File_Type;
Item : in Big_Integer;
Width : in Field := Default_Width;
Base : in Number_Base := Default_Base)
is
procedure Put_Character (C : in Character);
procedure Put_Character (C : in Character)
is
begin
Put (File, To_Maybe_Character (C));
end Put_Character;
begin
Put (Put_Character'Access, Item.Value, Width, Base);
end Put;
procedure Put
(Item : in Big_Integer;
Width : in Field := Default_Width;
Base : in Number_Base := Default_Base)
is
begin
Put (Current_Output, Item, Width, Base);
end Put;
procedure Put
(To : out Maybe_String;
Item : in Big_Integer;
Base : in Number_Base := Default_Base)
is
Next : Positive := To'First;
procedure Put_Character (C : in Character);
procedure Put_Character (C : in Character)
is
begin
if Next > To'Last then
raise Ada.IO_Exceptions.Layout_Error;
end if;
To (Next) := To_Maybe_Character (C);
Next := Next + 1;
end Put_Character;
begin
Put (Put_Character'Access, Item.Value, To'Length, Base);
end Put;
procedure Put
(File : in File_Type;
Item : in Big_Rational;
Width : in Field := Default_Width;
Base : in Number_Base := Default_Base)
is
procedure Put_Character (C : in Character);
procedure Put_Character (C : in Character)
is
begin
Put (File, To_Maybe_Character (C));
end Put_Character;
begin
Put (Put_Character'Access, Item.Value, Width, Base);
end Put;
procedure Put
(Item : in Big_Rational;
Width : in Field := Default_Width;
Base : in Number_Base := Default_Base)
is
begin
Put (Current_Output, Item, Width, Base);
end Put;
procedure Put
(To : out Maybe_String;
Item : in Big_Rational;
Base : in Number_Base := Default_Base)
is
Next : Positive := To'First;
procedure Put_Character (C : in Character);
procedure Put_Character (C : in Character)
is
begin
if Next > To'Last then
raise Ada.IO_Exceptions.Layout_Error;
end if;
To (Next) := To_Maybe_Character (C);
Next := Next + 1;
end Put_Character;
begin
Put (Put_Character'Access, Item.Value, To'Length, Base);
end Put;
procedure Get (File : in File_Type;
Item : in out Big_Float;
Width : in Field := 0)
is
Actual_Width : Field;
Count : Field := 0;
EOL : Boolean;
Temp : Maybe_Character;
Next : Character;
procedure Consume;
procedure Consume is
begin
pragma Assert (Count < Actual_Width
and not End_Of_Line (File));
Get (File, Temp);
Count := Count + 1;
Look_Ahead (File, Temp, EOL);
if Count < Actual_Width and not EOL then
Next := To_Character (Temp, Unused_Character);
else
Next := Unused_Character;
end if;
end Consume;
package Scan is new Generic_Scan (Next, Consume);
begin
if Width /= 0 then
Actual_Width := Width;
else
Skip_Blanks_And_Separators (File);
Actual_Width := Max_IO_Length;
end if;
Look_Ahead (File, Temp, EOL);
if not EOL then
Next := To_Character (Temp, Unused_Character);
else
Next := Unused_Character;
end if;
Scan.Get_Mpf_T (Item.Value, Actual_Width);
if Count < Integer (Actual_Width) and not End_Of_Line (File) then
raise Ada.IO_Exceptions.Data_Error;
end if;
end Get;
procedure Get
(Item : in out Big_Float;
Width : in Field := 0)
is
begin
Get (Current_Input, Item, Width);
end Get;
procedure Get
(From : in Maybe_String;
Item : in out Big_Float;
Last : out Positive)
is
Next : Character; -- = From (Last - 1) in normal cases
procedure Consume;
procedure Consume is
begin
if Last <= From'Last then
Next := To_Character (From (Last), Unused_Character);
else
pragma Assert (Last = From'Last + 1);
Next := Unused_Character;
end if;
Last := Last + 1;
end Consume;
package Scan is new Generic_Scan (Next, Consume);
begin
Last := From'First;
Consume;
Scan.Get_Mpf_T (Item.Value, From'Length);
Last := Last - 2;
end Get;
procedure Put
(File : in File_Type;
Item : in Big_Float;
Fore : in Field := Default_Fore;
Aft : in Field := Default_Aft;
Exp : in Field := Default_Exp)
is
procedure Put_Character (C : in Character);
procedure Put_Character (C : in Character)
is
begin
Put (File, To_Maybe_Character (C));
end Put_Character;
begin
Put (Put_Character'Access, Item.Value, Fore, Aft, Exp);
end Put;
procedure Put
(Item : in Big_Float;
Fore : in Field := Default_Fore;
Aft : in Field := Default_Aft;
Exp : in Field := Default_Exp)
is
begin
Put (Current_Output, Item, Fore, Aft, Exp);
end Put;
procedure Put
(To : out Maybe_String;
Item : in Big_Float;
Aft : in Field := Default_Aft;
Exp : in Field := Default_Exp)
is
Next : Positive := To'First;
procedure Put_Character (C : in Character);
procedure Put_Character (C : in Character)
is
begin
if Next > To'Last then
raise Ada.IO_Exceptions.Layout_Error;
end if;
To (Next) := To_Maybe_Character (C);
Next := Next + 1;
end Put_Character;
begin
Put (Put_Character'Access, Item.Value, 0, Aft, Exp);
To := (Next .. To'Last => To_Maybe_Character (' '))
& To (To'First .. Next - 1);
end Put;
end GNU_Multiple_Precision.Generic_Text_IO;
|