1------------------------------------------------------------------------------
2--                                                                          --
3--                         GNAT RUNTIME COMPONENTS                          --
4--                                                                          --
5--              A D A . T E X T _ I O . G E N E R I C _ A U X               --
6--                                                                          --
7--                                 S p e c                                  --
8--                                                                          --
9--          Copyright (C) 1992-2003 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,  59 Temple Place - Suite 330,  Boston, --
20-- MA 02111-1307, 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--  This package contains a set of auxiliary routines used by the Text_IO
35--  generic children, including for reading and writing numeric strings.
36
37private package Ada.Text_IO.Generic_Aux is
38
39   --  Note: for all the Load routines, File indicates the file to be read,
40   --  Buf is the string into which data is stored, Ptr is the index of the
41   --  last character stored so far, and is updated if additional characters
42   --  are stored. Data_Error is raised if the input overflows Buf. The only
43   --  Load routines that do a file status check are Load_Skip and Load_Width
44   --  so one of these two routines must be called first.
45
46   procedure Check_End_Of_Field
47     (Buf   : String;
48      Stop  : Integer;
49      Ptr   : Integer;
50      Width : Field);
51   --  This routine is used after doing a get operations on a numeric value.
52   --  Buf is the string being scanned, and Stop is the last character of
53   --  the field being scanned. Ptr is as set by the call to the scan routine
54   --  that scanned out the numeric value, i.e. it points one past the last
55   --  character scanned, and Width is the width parameter from the Get call.
56   --
57   --  There are two cases, if Width is non-zero, then a check is made that
58   --  the remainder of the field is all blanks. If Width is zero, then it
59   --  means that the scan routine scanned out only part of the field. We
60   --  have already scanned out the field that the ACVC tests seem to expect
61   --  us to read (even if it does not follow the syntax of the type being
62   --  scanned, e.g. allowing negative exponents in integers, and underscores
63   --  at the end of the string), so we just raise Data_Error.
64
65   procedure Check_On_One_Line (File : File_Type; Length : Integer);
66   --  Check to see if item of length Integer characters can fit on
67   --  current line. Call New_Line if not, first checking that the
68   --  line length can accommodate Length characters, raise Layout_Error
69   --  if item is too large for a single line.
70
71   function Getc (File : File_Type) return Integer;
72   --  Gets next character from file, which has already been checked for
73   --  being in read status, and returns the character read if no error
74   --  occurs. The result is EOF if the end of file was read. Note that
75   --  the Col value is not bumped, so it is the caller's responsibility
76   --  to bump it if necessary.
77
78   function Is_Blank (C : Character) return Boolean;
79   --  Determines if C is a blank (space or tab)
80
81   procedure Load_Width
82     (File  : File_Type;
83      Width : in Field;
84      Buf   : out String;
85      Ptr   : in out Integer);
86   --  Loads exactly Width characters, unless a line mark is encountered first
87
88   procedure Load_Skip (File  : File_Type);
89   --  Skips leading blanks and line and page marks, if the end of file is
90   --  read without finding a non-blank character, then End_Error is raised.
91   --  Note: a blank is defined as a space or horizontal tab (RM A.10.6(5)).
92
93   procedure Load
94     (File   : File_Type;
95      Buf    : out String;
96      Ptr    : in out Integer;
97      Char   : Character;
98      Loaded : out Boolean);
99   --  If next character is Char, loads it, otherwise no characters are loaded
100   --  Loaded is set to indicate whether or not the character was found.
101
102   procedure Load
103     (File   : File_Type;
104      Buf    : out String;
105      Ptr    : in out Integer;
106      Char   : Character);
107   --  Same as above, but no indication if character is loaded
108
109   procedure Load
110     (File   : File_Type;
111      Buf    : out String;
112      Ptr    : in out Integer;
113      Char1  : Character;
114      Char2  : Character;
115      Loaded : out Boolean);
116   --  If next character is Char1 or Char2, loads it, otherwise no characters
117   --  are loaded. Loaded is set to indicate whether or not one of the two
118   --  characters was found.
119
120   procedure Load
121     (File   : File_Type;
122      Buf    : out String;
123      Ptr    : in out Integer;
124      Char1  : Character;
125      Char2  : Character);
126   --  Same as above, but no indication if character is loaded
127
128   procedure Load_Digits
129     (File   : File_Type;
130      Buf    : out String;
131      Ptr    : in out Integer;
132      Loaded : out Boolean);
133   --  Loads a sequence of zero or more decimal digits. Loaded is set if
134   --  at least one digit is loaded.
135
136   procedure Load_Digits
137     (File   : File_Type;
138      Buf    : out String;
139      Ptr    : in out Integer);
140   --  Same as above, but no indication if character is loaded
141
142   procedure Load_Extended_Digits
143     (File   : File_Type;
144      Buf    : out String;
145      Ptr    : in out Integer;
146      Loaded : out Boolean);
147   --  Like Load_Digits, but also allows extended digits a-f and A-F
148
149   procedure Load_Extended_Digits
150     (File   : File_Type;
151      Buf    : out String;
152      Ptr    : in out Integer);
153   --  Same as above, but no indication if character is loaded
154
155   function Nextc (File : File_Type) return Integer;
156   --  Like Getc, but includes a call to Ungetc, so that the file
157   --  pointer is not moved by the call.
158
159   procedure Put_Item (File : File_Type; Str : String);
160   --  This routine is like Text_IO.Put, except that it checks for overflow
161   --  of bounded lines, as described in (RM A.10.6(8)). It is used for
162   --  all output of numeric values and of enumeration values.
163
164   procedure Store_Char
165     (File : File_Type;
166      ch   : Integer;
167      Buf  : out String;
168      Ptr  : in out Integer);
169   --  Store a single character in buffer, checking for overflow and
170   --  adjusting the column number in the file to reflect the fact
171   --  that a character has been acquired from the input stream. If
172   --  the character will not fit in the buffer it is stored in the
173   --  last character position of the buffer and Ptr is unchanged.
174   --  No exception is raised in this case, it is the caller's job
175   --  to raise Data_Error if the buffer fills up, so typically the
176   --  caller will make the buffer one character longer than needed.
177
178   procedure String_Skip (Str : String; Ptr : out Integer);
179   --  Used in the Get from string procedures to skip leading blanks in the
180   --  string. Ptr is set to the index of the first non-blank. If the string
181   --  is all blanks, then the excption End_Error is raised, Note that blank
182   --  is defined as a space or horizontal tab (RM A.10.6(5)).
183
184   procedure Ungetc (ch : Integer; File : File_Type);
185   --  Pushes back character into stream, using ungetc. The caller has
186   --  checked that the file is in read status. Device_Error is raised
187   --  if the character cannot be pushed back. An attempt to push back
188   --  an end of file (EOF) is ignored.
189
190private
191   pragma Inline (Is_Blank);
192
193end Ada.Text_IO.Generic_Aux;
194