1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . W I D E _ W I D E _ T E X T _ I O . G E N E R I C _ A U X --
9 -- Copyright (C) 1992-2005 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 -- 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. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 -- This package contains a set of auxiliary routines used by Wide_Wide_Text_IO
35 -- generic children, including for reading and writing numeric strings.
37 -- Note: although this is the Wide version of the package, the interface here
38 -- is still in terms of Character and String rather than Wide_Wide_Character
39 -- and Wide_Wide_String, since all numeric strings are composed entirely of
40 -- characters in the range of type Standard.Character, and the basic
41 -- conversion routines work with Character rather than Wide_Wide_Character.
43 package Ada
.Wide_Wide_Text_IO
.Generic_Aux
is
45 -- Note: for all the Load routines, File indicates the file to be read,
46 -- Buf is the string into which data is stored, Ptr is the index of the
47 -- last character stored so far, and is updated if additional characters
48 -- are stored. Data_Error is raised if the input overflows Buf. The only
49 -- Load routines that do a file status check are Load_Skip and Load_Width
50 -- so one of these two routines must be called first.
52 procedure Check_End_Of_Field
57 -- This routine is used after doing a get operations on a numeric value.
58 -- Buf is the string being scanned, and Stop is the last character of
59 -- the field being scanned. Ptr is as set by the call to the scan routine
60 -- that scanned out the numeric value, i.e. it points one past the last
61 -- character scanned, and Width is the width parameter from the Get call.
63 -- There are two cases, if Width is non-zero, then a check is made that
64 -- the remainder of the field is all blanks. If Width is zero, then it
65 -- means that the scan routine scanned out only part of the field. We
66 -- have already scanned out the field that the ACVC tests seem to expect
67 -- us to read (even if it does not follow the syntax of the type being
68 -- scanned, e.g. allowing negative exponents in integers, and underscores
69 -- at the end of the string), so we just raise Data_Error.
71 procedure Check_On_One_Line
(File
: File_Type
; Length
: Integer);
72 -- Check to see if item of length Integer characters can fit on
73 -- current line. Call New_Line if not, first checking that the
74 -- line length can accommodate Length characters, raise Layout_Error
75 -- if item is too large for a single line.
77 function Is_Blank
(C
: Character) return Boolean;
78 -- Determines if C is a blank (space or tab)
84 Ptr
: in out Integer);
85 -- Loads exactly Width characters, unless a line mark is encountered first
87 procedure Load_Skip
(File
: File_Type
);
88 -- Skips leading blanks and line and page marks, if the end of file is
89 -- read without finding a non-blank character, then End_Error is raised.
90 -- Note: a blank is defined as a space or horizontal tab (RM A.10.6(5)).
97 Loaded
: out Boolean);
98 -- If next character is Char, loads it, otherwise no characters are loaded
99 -- Loaded is set to indicate whether or not the character was found.
104 Ptr
: in out Integer;
106 -- Same as above, but no indication if character is loaded
111 Ptr
: in out Integer;
114 Loaded
: out Boolean);
115 -- If next character is Char1 or Char2, loads it, otherwise no characters
116 -- are loaded. Loaded is set to indicate whether or not one of the two
117 -- characters was found.
122 Ptr
: in out Integer;
125 -- Same as above, but no indication if character is loaded
127 procedure Load_Digits
130 Ptr
: in out Integer;
131 Loaded
: out Boolean);
132 -- Loads a sequence of zero or more decimal digits. Loaded is set if
133 -- at least one digit is loaded.
135 procedure Load_Digits
138 Ptr
: in out Integer);
139 -- Same as above, but no indication if character is loaded
141 procedure Load_Extended_Digits
144 Ptr
: in out Integer;
145 Loaded
: out Boolean);
146 -- Like Load_Digits, but also allows extended digits a-f and A-F
148 procedure Load_Extended_Digits
151 Ptr
: in out Integer);
152 -- Same as above, but no indication if character is loaded
154 procedure Put_Item
(File
: File_Type
; Str
: String);
155 -- This routine is like Wide_Wide_Text_IO.Put, except that it checks for
156 -- overflow of bounded lines, as described in (RM A.10.6(8)). It is used
157 -- for all output of numeric values and of enumeration values. Note that
158 -- the buffer is of type String. Put_Item deals with converting this to
159 -- Wide_Wide_Characters as required.
165 Ptr
: in out Integer);
166 -- Store a single character in buffer, checking for overflow and
167 -- adjusting the column number in the file to reflect the fact
168 -- that a character has been acquired from the input stream.
169 -- The pos value of the character to store is in ch on entry.
171 procedure String_Skip
(Str
: String; Ptr
: out Integer);
172 -- Used in the Get from string procedures to skip leading blanks in the
173 -- string. Ptr is set to the index of the first non-blank. If the string
174 -- is all blanks, then the excption End_Error is raised, Note that blank
175 -- is defined as a space or horizontal tab (RM A.10.6(5)).
177 procedure Ungetc
(ch
: Integer; File
: File_Type
);
178 -- Pushes back character into stream, using ungetc. The caller has
179 -- checked that the file is in read status. Device_Error is raised
180 -- if the character cannot be pushed back. An attempt to push back
181 -- an end of file (EOF) is ignored.
184 pragma Inline
(Is_Blank
);
186 end Ada
.Wide_Wide_Text_IO
.Generic_Aux
;