File : g-io-zfp.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- G N A T . I O --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1995-2011, AdaCore --
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 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. --
17 -- --
18 -- --
19 -- --
20 -- --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
31
32 package body GNAT.IO is
33
34 procedure Put (C : Character) is separate;
35
36 --------------
37 -- New_Line --
38 --------------
39
40 procedure New_Line (Spacing : Positive := 1) is
41 begin
42 for J in 1 .. Spacing loop
43 Put (ASCII.LF);
44 end loop;
45 end New_Line;
46
47 ---------
48 -- Put --
49 ---------
50
51 procedure Put (X : Integer) is
52 Int : Integer;
53 S : String (1 .. Integer'Width);
54 First : Natural := S'Last + 1;
55 Val : Integer;
56
57 begin
58 -- Work on negative values to avoid overflows
59 Int := (if X < 0 then X else -X);
60
61 loop
62 -- Cf RM 4.5.5 Multiplying Operators. The rem operator will return
63 -- negative values for negative values of Int.
64 Val := Int rem 10;
65 Int := (Int - Val) / 10;
66 First := First - 1;
67 S (First) := Character'Val (Character'Pos ('0') - Val);
68 exit when Int = 0;
69 end loop;
70
71 if X < 0 then
72 First := First - 1;
73 S (First) := '-';
74 end if;
75
76 Put (S (First .. S'Last));
77 end Put;
78
79 ---------
80 -- Put --
81 ---------
82
83 procedure Put (S : String) is
84 begin
85 for J in S'Range loop
86 Put (S (J));
87 end loop;
88 end Put;
89
90 --------------
91 -- Put_Line --
92 --------------
93
94 procedure Put_Line (S : String) is
95 begin
96 Put (S);
97 New_Line;
98 end Put_Line;
99
100 end GNAT.IO;