OSDN Git Service

gcc/ada/
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-imgint.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT RUN-TIME COMPONENTS                         --
4 --                                                                          --
5 --                       S Y S T E M . I M G _ I N T                        --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2007, Free Software Foundation, Inc.         --
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 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.                                              --
21 --                                                                          --
22 -- As a special exception,  if other files  instantiate  generics from this --
23 -- unit, or you link  this unit with other files  to produce an executable, --
24 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
25 -- covered  by the  GNU  General  Public  License.  This exception does not --
26 -- however invalidate  any other reasons why  the executable file  might be --
27 -- covered by the  GNU Public License.                                      --
28 --                                                                          --
29 -- GNAT was originally developed  by the GNAT team at  New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 package body System.Img_Int is
35
36    -------------------
37    -- Image_Integer --
38    -------------------
39
40    procedure Image_Integer
41      (V : Integer;
42       S : in out String;
43       P : out Natural)
44    is
45       pragma Assert (S'First = 1);
46
47       procedure Set_Digits (T : Integer);
48       --  Set digits of absolute value of T, which is zero or negative. We work
49       --  with the negative of the value so that the largest negative number is
50       --  not a special case.
51
52       ----------------
53       -- Set_Digits --
54       ----------------
55
56       procedure Set_Digits (T : Integer) is
57       begin
58          if T <= -10 then
59             Set_Digits (T / 10);
60             P := P + 1;
61             S (P) := Character'Val (48 - (T rem 10));
62          else
63             P := P + 1;
64             S (P) := Character'Val (48 - T);
65          end if;
66       end Set_Digits;
67
68    --  Start of processing for Image_Integer
69
70    begin
71       P := 1;
72
73       if V >= 0 then
74          S (P) := ' ';
75          Set_Digits (-V);
76       else
77          S (P) := '-';
78          Set_Digits (V);
79       end if;
80    end Image_Integer;
81
82    -----------------------
83    -- Set_Image_Integer --
84    -----------------------
85
86    procedure Set_Image_Integer
87      (V : Integer;
88       S : in out String;
89       P : in out Natural)
90    is
91       procedure Set_Digits (T : Integer);
92       --  Set digits of absolute value of T, which is zero or negative. We work
93       --  with the negative of the value so that the largest negative number is
94       --  not a special case.
95
96       ----------------
97       -- Set_Digits --
98       ----------------
99
100       procedure Set_Digits (T : Integer) is
101       begin
102          if T <= -10 then
103             Set_Digits (T / 10);
104             P := P + 1;
105             S (P) := Character'Val (48 - (T rem 10));
106          else
107             P := P + 1;
108             S (P) := Character'Val (48 - T);
109          end if;
110       end Set_Digits;
111
112    --  Start of processing for Set_Image_Integer
113
114    begin
115       if V >= 0 then
116          Set_Digits (-V);
117       else
118          P := P + 1;
119          S (P) := '-';
120          Set_Digits (V);
121       end if;
122    end Set_Image_Integer;
123
124 end System.Img_Int;