Streams_Text_IO
Streams_Text_IO — A Text_IO-like interface to Ada streams.
History:
April 25th, 2007 - Initial release
Download:
http://solidrockdata.com/Software/Open-Source/streams_text_io.tar.bz2
Please send comments to Jesse Lang.
------------------------------------------------------------------------------ -- -- -- S T R E A M S _ T E X T _ I O -- -- -- -- S p e c -- -- -- -- Written by Jesse Lang (http://jesselang.com/) -- -- -- -- This is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 2, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- -- for more details. You should have received a copy of the GNU General -- -- Public License distributed with GNAT; see file COPYING. If not, write -- -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, -- -- MA 02111-1307, USA. -- -- -- -- As a special exception, if other files instantiate generics from this -- -- unit, or you link this unit with other files to produce an executable, -- -- this unit does not by itself cause the resulting executable to be -- -- covered by the GNU General Public License. This exception does not -- -- however invalidate any other reasons why the executable file might be -- -- covered by the GNU Public License. -- -- -- -- $LastChangedDate: 2006-07-20 03:44:24 -0500 (Thu, 20 Jul 2006) $ -- -- $Rev: 37 $ -- -- -- -- This package provides a Text_IO-like interface to Ada streams. -- ------------------------------------------------------------------------------ pragma License (Modified_GPL); with Ada.Streams; package Streams_Text_IO is End_Of_Stream : exception; -- End_Of_Stream is raised whenever an operation on a Text_Stream fails -- because the stream has ended. type Text_Stream is limited private; type Line_Terminator is (CR, LF, CR_LF); procedure Create (Stream : out Text_Stream; From : access Ada.Streams.Root_Stream_Type'Class; Line_Ending : in Line_Terminator); -- Creates a new Text_Stream in Stream, using the stream in From. procedure Skip_Line (Stream : in out Text_Stream; Spacing : in Positive := 1); -- Skips Spacing number of line terminator(s) read from Stream, -- and any characters in between. -- Raises End_Of_Stream when the end of Stream has been reached. procedure Get (Stream : in out Text_Stream; Item : out Character); -- After skipping any line terminators, reads the next character from Stream into Item. -- Raises End_Of_Stream when the end of Stream has been reached. procedure Get (Stream : in out Text_Stream; Item : out String; Last : out Natural); -- After skipping any line terminators, reads Item from Stream. -- Blocks until Item is full, or the stream ends. -- Sets Last to the last character in Item read from Stream. -- If Last < Item'Last, the stream has ended. -- Raises End_Of_Stream when the end of Stream has been reached. procedure Get_Line (Stream : in out Text_Stream; Item : out String; Last : out Natural); -- Reads Item from Stream. Returns when Item is full, in which -- case, Last = Item'Last. Otherwise, returns when a line terminator is reached, -- in which case, Last is set to the last character of Item before the line -- terminator. -- Raises End_Of_Stream when the end of Stream has been reached. procedure Put (Stream : in out Text_Stream; Item : in Character); -- Puts Item to Stream. procedure Put (Stream : in out Text_Stream; Item : in String); -- Puts Item to Stream. procedure New_Line (Stream : in out Text_Stream; Spacing : in Positive := 1); -- Puts Spacing number of line terminator(s) to Stream. procedure Put_Line (Stream : in out Text_Stream; Item : in String); -- Puts Item to Stream, followed by a line terminator private type Text_Stream is limited record Stream : access Ada.Streams.Root_Stream_Type'Class; Line_Ending : Line_Terminator; First_Element : Ada.Streams.Stream_Element; Read_First_Element : Boolean := False; end record; end Streams_Text_IO;