OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [gcc/] [ada/] [a-ztexio.ads] - Blame information for rev 859

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 281 jeremybenn
------------------------------------------------------------------------------
2
--                                                                          --
3
--                         GNAT RUN-TIME COMPONENTS                         --
4
--                                                                          --
5
--                A D A . W I D E _ W I D E _ T E X T _ I O                 --
6
--                                                                          --
7
--                                 S p e c                                  --
8
--                                                                          --
9
--          Copyright (C) 1992-2009, Free Software Foundation, Inc.         --
10
--                                                                          --
11
-- This specification is derived from the Ada Reference Manual for use with --
12
-- GNAT. The copyright notice above, and the license provisions that follow --
13
-- apply solely to the  contents of the part following the private keyword. --
14
--                                                                          --
15
-- GNAT is free software;  you can  redistribute it  and/or modify it under --
16
-- terms of the  GNU General Public License as published  by the Free Soft- --
17
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
18
-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
19
-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
20
-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
21
--                                                                          --
22
-- As a special exception under Section 7 of GPL version 3, you are granted --
23
-- additional permissions described in the GCC Runtime Library Exception,   --
24
-- version 3.1, as published by the Free Software Foundation.               --
25
--                                                                          --
26
-- You should have received a copy of the GNU General Public License and    --
27
-- a copy of the GCC Runtime Library Exception along with this program;     --
28
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
29
-- <http://www.gnu.org/licenses/>.                                          --
30
--                                                                          --
31
-- GNAT was originally developed  by the GNAT team at  New York University. --
32
-- Extensive contributions were provided by Ada Core Technologies Inc.      --
33
--                                                                          --
34
------------------------------------------------------------------------------
35
 
36
--  Note: the generic subpackages of Wide_Wide_Text_IO (Integer_IO, Float_IO,
37
--  Fixed_IO, Modular_IO, Decimal_IO and Enumeration_IO) appear as private
38
--  children in GNAT. These children are with'ed automatically if they are
39
--  referenced, so this rearrangement is invisible to user programs, but has
40
--  the advantage that only the needed parts of Wide_Wide_Text_IO are processed
41
--  and loaded.
42
 
43
with Ada.IO_Exceptions;
44
with Ada.Streams;
45
 
46
with Interfaces.C_Streams;
47
 
48
with System;
49
with System.File_Control_Block;
50
with System.WCh_Con;
51
 
52
package Ada.Wide_Wide_Text_IO is
53
 
54
   type File_Type is limited private;
55
   type File_Mode is (In_File, Out_File, Append_File);
56
 
57
   --  The following representation clause allows the use of unchecked
58
   --  conversion for rapid translation between the File_Mode type
59
   --  used in this package and System.File_IO.
60
 
61
   for File_Mode use
62
     (In_File     => 0,  -- System.FIle_IO.File_Mode'Pos (In_File)
63
      Out_File    => 2,  -- System.File_IO.File_Mode'Pos (Out_File)
64
      Append_File => 3); -- System.File_IO.File_Mode'Pos (Append_File)
65
 
66
   type Count is range 0 .. Natural'Last;
67
   --  The value of Count'Last must be large enough so that the assumption
68
   --  enough so that the assumption that the Line, Column and Page
69
   --  counts can never exceed this value is a valid assumption.
70
 
71
   subtype Positive_Count is Count range 1 .. Count'Last;
72
 
73
   Unbounded : constant Count := 0;
74
   --  Line and page length
75
 
76
   subtype Field is Integer range 0 .. 255;
77
   --  Note: if for any reason, there is a need to increase this value,
78
   --  then it will be necessary to change the corresponding value in
79
   --  System.Img_Real in file s-imgrea.adb.
80
 
81
   subtype Number_Base is Integer range 2 .. 16;
82
 
83
   type Type_Set is (Lower_Case, Upper_Case);
84
 
85
   ---------------------
86
   -- File Management --
87
   ---------------------
88
 
89
   procedure Create
90
     (File : in out File_Type;
91
      Mode : File_Mode := Out_File;
92
      Name : String := "";
93
      Form : String := "");
94
 
95
   procedure Open
96
     (File : in out File_Type;
97
      Mode : File_Mode;
98
      Name : String;
99
      Form : String := "");
100
 
101
   procedure Close  (File : in out File_Type);
102
   procedure Delete (File : in out File_Type);
103
   procedure Reset  (File : in out File_Type; Mode : File_Mode);
104
   procedure Reset  (File : in out File_Type);
105
 
106
   function Mode (File : File_Type) return File_Mode;
107
   function Name (File : File_Type) return String;
108
   function Form (File : File_Type) return String;
109
 
110
   function Is_Open (File : File_Type) return Boolean;
111
 
112
   ------------------------------------------------------
113
   -- Control of default input, output and error files --
114
   ------------------------------------------------------
115
 
116
   procedure Set_Input  (File : File_Type);
117
   procedure Set_Output (File : File_Type);
118
   procedure Set_Error  (File : File_Type);
119
 
120
   function Standard_Input  return File_Type;
121
   function Standard_Output return File_Type;
122
   function Standard_Error  return File_Type;
123
 
124
   function Current_Input  return File_Type;
125
   function Current_Output return File_Type;
126
   function Current_Error  return File_Type;
127
 
128
   type File_Access is access constant File_Type;
129
 
130
   function Standard_Input  return File_Access;
131
   function Standard_Output return File_Access;
132
   function Standard_Error  return File_Access;
133
 
134
   function Current_Input  return File_Access;
135
   function Current_Output return File_Access;
136
   function Current_Error  return File_Access;
137
 
138
   --------------------
139
   -- Buffer control --
140
   --------------------
141
 
142
   --  Note: The parameter file is in out in the RM, but as pointed out
143
   --  in <<95-5166.a Tucker Taft 95-6-23>> this is clearly an oversight.
144
 
145
   procedure Flush (File : File_Type);
146
   procedure Flush;
147
 
148
   --------------------------------------------
149
   -- Specification of line and page lengths --
150
   --------------------------------------------
151
 
152
   procedure Set_Line_Length (File : File_Type; To : Count);
153
   procedure Set_Line_Length (To : Count);
154
 
155
   procedure Set_Page_Length (File : File_Type; To : Count);
156
   procedure Set_Page_Length (To : Count);
157
 
158
   function Line_Length (File : File_Type) return Count;
159
   function Line_Length return Count;
160
 
161
   function Page_Length (File : File_Type) return Count;
162
   function Page_Length return Count;
163
 
164
   ------------------------------------
165
   -- Column, Line, and Page Control --
166
   ------------------------------------
167
 
168
   procedure New_Line (File : File_Type; Spacing : Positive_Count := 1);
169
   procedure New_Line (Spacing : Positive_Count := 1);
170
 
171
   procedure Skip_Line (File : File_Type; Spacing : Positive_Count := 1);
172
   procedure Skip_Line (Spacing : Positive_Count := 1);
173
 
174
   function End_Of_Line (File : File_Type) return Boolean;
175
   function End_Of_Line return Boolean;
176
 
177
   procedure New_Page (File : File_Type);
178
   procedure New_Page;
179
 
180
   procedure Skip_Page (File : File_Type);
181
   procedure Skip_Page;
182
 
183
   function End_Of_Page (File : File_Type) return Boolean;
184
   function End_Of_Page return Boolean;
185
 
186
   function End_Of_File (File : File_Type) return Boolean;
187
   function End_Of_File return Boolean;
188
 
189
   procedure Set_Col (File : File_Type;  To : Positive_Count);
190
   procedure Set_Col (To : Positive_Count);
191
 
192
   procedure Set_Line (File : File_Type; To : Positive_Count);
193
   procedure Set_Line (To : Positive_Count);
194
 
195
   function Col (File : File_Type) return Positive_Count;
196
   function Col return Positive_Count;
197
 
198
   function Line (File : File_Type) return Positive_Count;
199
   function Line return Positive_Count;
200
 
201
   function Page (File : File_Type) return Positive_Count;
202
   function Page return Positive_Count;
203
 
204
   ----------------------------
205
   -- Character Input-Output --
206
   ----------------------------
207
 
208
   procedure Get (File : File_Type; Item : out Wide_Wide_Character);
209
   procedure Get (Item : out Wide_Wide_Character);
210
   procedure Put (File : File_Type; Item : Wide_Wide_Character);
211
   procedure Put (Item : Wide_Wide_Character);
212
 
213
   procedure Look_Ahead
214
     (File        : File_Type;
215
      Item        : out Wide_Wide_Character;
216
      End_Of_Line : out Boolean);
217
 
218
   procedure Look_Ahead
219
     (Item        : out Wide_Wide_Character;
220
      End_Of_Line : out Boolean);
221
 
222
   procedure Get_Immediate
223
     (File : File_Type;
224
      Item : out Wide_Wide_Character);
225
 
226
   procedure Get_Immediate
227
     (Item : out Wide_Wide_Character);
228
 
229
   procedure Get_Immediate
230
     (File      : File_Type;
231
      Item      : out Wide_Wide_Character;
232
      Available : out Boolean);
233
 
234
   procedure Get_Immediate
235
     (Item      : out Wide_Wide_Character;
236
      Available : out Boolean);
237
 
238
   -------------------------
239
   -- String Input-Output --
240
   -------------------------
241
 
242
   procedure Get (File : File_Type; Item : out Wide_Wide_String);
243
   procedure Get (Item : out Wide_Wide_String);
244
   procedure Put (File : File_Type; Item : Wide_Wide_String);
245
   procedure Put (Item : Wide_Wide_String);
246
 
247
   procedure Get_Line
248
     (File : File_Type;
249
      Item : out Wide_Wide_String;
250
      Last : out Natural);
251
 
252
   function Get_Line (File : File_Type) return Wide_Wide_String;
253
   pragma Ada_05 (Get_Line);
254
 
255
   function Get_Line return Wide_Wide_String;
256
   pragma Ada_05 (Get_Line);
257
 
258
   procedure Get_Line
259
     (Item : out Wide_Wide_String;
260
      Last : out Natural);
261
 
262
   procedure Put_Line
263
     (File : File_Type;
264
      Item : Wide_Wide_String);
265
 
266
   procedure Put_Line
267
     (Item : Wide_Wide_String);
268
 
269
   ---------------------------------------
270
   -- Generic packages for Input-Output --
271
   ---------------------------------------
272
 
273
   --  The generic packages:
274
 
275
   --    Ada.Wide_Wide_Text_IO.Integer_IO
276
   --    Ada.Wide_Wide_Text_IO.Modular_IO
277
   --    Ada.Wide_Wide_Text_IO.Float_IO
278
   --    Ada.Wide_Wide_Text_IO.Fixed_IO
279
   --    Ada.Wide_Wide_Text_IO.Decimal_IO
280
   --    Ada.Wide_Wide_Text_IO.Enumeration_IO
281
 
282
   --  are implemented as separate child packages in GNAT, so the
283
   --  spec and body of these packages are to be found in separate
284
   --  child units. This implementation detail is hidden from the
285
   --  Ada programmer by special circuitry in the compiler that
286
   --  treats these child packages as though they were nested in
287
   --  Text_IO. The advantage of this special processing is that
288
   --  the subsidiary routines needed if these generics are used
289
   --  are not loaded when they are not used.
290
 
291
   ----------------
292
   -- Exceptions --
293
   ----------------
294
 
295
   Status_Error : exception renames IO_Exceptions.Status_Error;
296
   Mode_Error   : exception renames IO_Exceptions.Mode_Error;
297
   Name_Error   : exception renames IO_Exceptions.Name_Error;
298
   Use_Error    : exception renames IO_Exceptions.Use_Error;
299
   Device_Error : exception renames IO_Exceptions.Device_Error;
300
   End_Error    : exception renames IO_Exceptions.End_Error;
301
   Data_Error   : exception renames IO_Exceptions.Data_Error;
302
   Layout_Error : exception renames IO_Exceptions.Layout_Error;
303
 
304
private
305
 
306
   --  The following procedures have a File_Type formal of mode IN OUT because
307
   --  they may close the original file. The Close operation may raise an
308
   --  exception, but in that case we want any assignment to the formal to
309
   --  be effective anyway, so it must be passed by reference (or the caller
310
   --  will be left with a dangling pointer).
311
 
312
   pragma Export_Procedure
313
     (Internal  => Close,
314
      External  => "",
315
      Mechanism => Reference);
316
   pragma Export_Procedure
317
     (Internal  => Delete,
318
      External  => "",
319
      Mechanism => Reference);
320
   pragma Export_Procedure
321
     (Internal        => Reset,
322
      External        => "",
323
      Parameter_Types => (File_Type),
324
      Mechanism       => Reference);
325
   pragma Export_Procedure
326
     (Internal        => Reset,
327
      External        => "",
328
      Parameter_Types => (File_Type, File_Mode),
329
      Mechanism       => (File => Reference));
330
 
331
   package WCh_Con renames System.WCh_Con;
332
 
333
   -----------------------------------
334
   -- Handling of Format Characters --
335
   -----------------------------------
336
 
337
   --  Line marks are represented by the single character ASCII.LF (16#0A#).
338
   --  In DOS and similar systems, underlying file translation takes care
339
   --  of translating this to and from the standard CR/LF sequences used in
340
   --  these operating systems to mark the end of a line. On output there is
341
   --  always a line mark at the end of the last line, but on input, this
342
   --  line mark can be omitted, and is implied by the end of file.
343
 
344
   --  Page marks are represented by the single character ASCII.FF (16#0C#),
345
   --  The page mark at the end of the file may be omitted, and is normally
346
   --  omitted on output unless an explicit New_Page call is made before
347
   --  closing the file. No page mark is added when a file is appended to,
348
   --  so, in accordance with the permission in (RM A.10.2(4)), there may
349
   --  or may not be a page mark separating preexisting text in the file
350
   --  from the new text to be written.
351
 
352
   --  A file mark is marked by the physical end of file. In DOS translation
353
   --  mode on input, an EOF character (SUB = 16#1A#) gets translated to the
354
   --  physical end of file, so in effect this character is recognized as
355
   --  marking the end of file in DOS and similar systems.
356
 
357
   LM : constant := Character'Pos (ASCII.LF);
358
   --  Used as line mark
359
 
360
   PM : constant := Character'Pos (ASCII.FF);
361
   --  Used as page mark, except at end of file where it is implied
362
 
363
   ------------------------------------------
364
   -- Wide_Wide_Text_IO File Control Block --
365
   ------------------------------------------
366
 
367
   Default_WCEM : WCh_Con.WC_Encoding_Method := WCh_Con.WCEM_UTF8;
368
   --  This gets modified during initialization (see body) using the default
369
   --  value established in the call to Set_Globals.
370
 
371
   package FCB renames System.File_Control_Block;
372
 
373
   type Wide_Wide_Text_AFCB is new FCB.AFCB with record
374
      Page        : Count := 1;
375
      Line        : Count := 1;
376
      Col         : Count := 1;
377
      Line_Length : Count := 0;
378
      Page_Length : Count := 0;
379
 
380
      Self : aliased File_Type;
381
      --  Set to point to the containing Text_AFCB block. This is used to
382
      --  implement the Current_{Error,Input,Output} functions which return
383
      --  a File_Access, the file access value returned is a pointer to
384
      --  the Self field of the corresponding file.
385
 
386
      Before_LM : Boolean := False;
387
      --  This flag is used to deal with the anomalies introduced by the
388
      --  peculiar definition of End_Of_File and End_Of_Page in Ada. These
389
      --  functions require looking ahead more than one character. Since
390
      --  there is no convenient way of backing up more than one character,
391
      --  what we do is to leave ourselves positioned past the LM, but set
392
      --  this flag, so that we know that from an Ada point of view we are
393
      --  in front of the LM, not after it. A bit of a kludge, but it works!
394
 
395
      Before_LM_PM : Boolean := False;
396
      --  This flag similarly handles the case of being physically positioned
397
      --  after a LM-PM sequence when logically we are before the LM-PM. This
398
      --  flag can only be set if Before_LM is also set.
399
 
400
      WC_Method : WCh_Con.WC_Encoding_Method := Default_WCEM;
401
      --  Encoding method to be used for this file
402
 
403
      Before_Wide_Wide_Character : Boolean := False;
404
      --  This flag is set to indicate that a wide character in the input has
405
      --  been read by Wide_Wide_Text_IO.Look_Ahead. If it is set to True,
406
      --  then it means that the stream is logically positioned before the
407
      --  character but is physically positioned after it. The character
408
      --  involved must not be in the range 16#00#-16#7F#, i.e. if the flag is
409
      --  set, then we know the next character has a code greater than 16#7F#,
410
      --  and the value of this character is saved in
411
      --  Saved_Wide_Wide_Character.
412
 
413
      Saved_Wide_Wide_Character : Wide_Wide_Character;
414
      --  This field is valid only if Before_Wide_Wide_Character is set. It
415
      --  contains a wide character read by Look_Ahead. If Look_Ahead
416
      --  reads a character in the range 16#0000# to 16#007F#, then it
417
      --  can use ungetc to put it back, but ungetc cannot be called
418
      --  more than once, so for characters above this range, we don't
419
      --  try to back up the file. Instead we save the character in this
420
      --  field and set the flag Before_Wide_Wide_Character to indicate that
421
      --  we are logically positioned before this character even though
422
      --  the stream is physically positioned after it.
423
 
424
   end record;
425
 
426
   type File_Type is access all Wide_Wide_Text_AFCB;
427
 
428
   function AFCB_Allocate
429
     (Control_Block : Wide_Wide_Text_AFCB) return FCB.AFCB_Ptr;
430
 
431
   procedure AFCB_Close (File : not null access Wide_Wide_Text_AFCB);
432
   procedure AFCB_Free  (File : not null access Wide_Wide_Text_AFCB);
433
 
434
   procedure Read
435
     (File : in out Wide_Wide_Text_AFCB;
436
      Item : out Ada.Streams.Stream_Element_Array;
437
      Last : out Ada.Streams.Stream_Element_Offset);
438
   --  Read operation used when Wide_Wide_Text_IO file is treated as a Stream
439
 
440
   procedure Write
441
     (File : in out Wide_Wide_Text_AFCB;
442
      Item : Ada.Streams.Stream_Element_Array);
443
   --  Write operation used when Wide_Wide_Text_IO file is treated as a Stream
444
 
445
   ------------------------
446
   -- The Standard Files --
447
   ------------------------
448
 
449
   Standard_Err_AFCB : aliased Wide_Wide_Text_AFCB;
450
   Standard_In_AFCB  : aliased Wide_Wide_Text_AFCB;
451
   Standard_Out_AFCB : aliased Wide_Wide_Text_AFCB;
452
 
453
   Standard_Err : aliased File_Type := Standard_Err_AFCB'Access;
454
   Standard_In  : aliased File_Type := Standard_In_AFCB'Access;
455
   Standard_Out : aliased File_Type := Standard_Out_AFCB'Access;
456
   --  Standard files
457
 
458
   Current_In   : aliased File_Type := Standard_In;
459
   Current_Out  : aliased File_Type := Standard_Out;
460
   Current_Err  : aliased File_Type := Standard_Err;
461
   --  Current files
462
 
463
   procedure Initialize_Standard_Files;
464
   --  Initializes the file control blocks for the standard files. Called from
465
   --  the elaboration routine for this package, and from Reset_Standard_Files
466
   --  in package Ada.Wide_Wide_Text_IO.Reset_Standard_Files.
467
 
468
   -----------------------
469
   -- Local Subprograms --
470
   -----------------------
471
 
472
   --  These subprograms are in the private part of the spec so that they can
473
   --  be shared by the children of Ada.Text_IO.Wide_Wide_Text_IO.
474
 
475
   function Getc (File : File_Type) return Interfaces.C_Streams.int;
476
   --  Gets next character from file, which has already been checked for being
477
   --  in read status, and returns the character read if no error occurs. The
478
   --  result is EOF if the end of file was read.
479
 
480
   procedure Get_Character (File : File_Type; Item : out Character);
481
   --  This is essentially copy of Wide_Wide_Text_IO.Get. It obtains a single
482
   --  obtains a single character from the input file File, and places it in
483
   --  Item. This result may be the leading character of a Wide_Wide_Character
484
   --  sequence, but that is up to the caller to deal with.
485
 
486
   function Get_Wide_Wide_Char
487
     (C    : Character;
488
      File : File_Type) return Wide_Wide_Character;
489
   --  This function is shared by Get and Get_Immediate to extract a wide
490
   --  character value from the given File. The first byte has already been
491
   --  read and is passed in C. The wide character value is returned as the
492
   --  result, and the file pointer is bumped past the character.
493
 
494
   function Nextc (File : File_Type) return Interfaces.C_Streams.int;
495
   --  Returns next character from file without skipping past it (i.e. it is a
496
   --  combination of Getc followed by an Ungetc).
497
 
498
end Ada.Wide_Wide_Text_IO;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.