iostream.sa


Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
 
------------------------->  GNU Sather - sourcefile  <-------------------------
-- Copyright (C) 2003 by K Kodama
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute  and/or modify it under the terms of the GNU Library General --
-- Public  License (LGPL)  as published  by the  Free  Software  Foundation; --
-- either version 2 of the license, or (at your option) any later version.   --
-- This  library  is distributed  in the  hope that it will  be  useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details.       --
-- The license text is also available from:  Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     --
-------------->  Please email comments to <bug-sather@gnu.org>  <--------------



abstract class $OSTREAM

abstract class $OSTREAM is plus(s: STR); -- Append the string "s" to the stream plus(s: STR): SAME; -- Append the string "s" to the stream and return self end;

class OUTSTREAM < $OSTREAM

class OUTSTREAM < $OSTREAM is attr chan : REFERENCE; -- channel for output. the OS file handle create(fyle : REFERENCE): SAME is -- fyle: channel for output / the OS file handle reply:SAME:=new; reply.chan:=fyle; return reply; end; create(name : STR) : SAME pre (name.size > 0) is mode::=FILE_MODES::Write_Binary; reply:SAME:=new; reply.chan:=FILE_SYS::create_file(name,mode); return reply; end; clear is -- This routine clears any error condition for the cursor and associated file. FILE_SYS::clearerr(chan); end; close is FILE_SYS::close(chan); chan:=void; end; flush is FILE_SYS::flush(chan); end; error:BOOL is return void(chan) or FILE_SYS::error(chan) end; stdout:SAME is s::=STD_CHANS::stdout; return #SAME(s.chan); end; plus(s:BINSTR) is count : CARD := s.size ; success : BOOL := FILE_SYS::file_write(s,1,inout count,chan) ; end; plus(s:BINSTR):SAME is plus(s); return self; end; --plus(s:OCTET):SAME is file+s; return self; end; --plus(s:OCTET) is file+s; end; plus(s:STR) is plus(s.binstr); end; plus(s:STR):SAME is plus(s); return self; end; --plus(s:CHAR):SAME is file+#OCTET(s); return self; end; --plus(s:CHAR) is file+#OCTET(s); end; end;

class INSTREAM

class INSTREAM is attr file : BIN_FILE_CURSOR; create(fyle : REFERENCE): SAME is reply:SAME:=new; reply.file:=BIN_FILE_CURSOR::create(fyle,10000,true,false); return reply; end; create(name : STR) : SAME pre (name.size > 0) is f ::=BIN_FILE::open_for_read(name); if void(f) then return void; end; reply:SAME:=new; reply.file:=f.cursor(10000); return reply; end; close is -- Close the file corresponding to self. file:=void; end; stdin:SAME is s::=STD_CHANS::stdin; return #SAME(s.chan); end; seek(pos:CARD) pre ~void(file) is -- go to the position in file. dummy::=file.position(pos); end; position:CARD is -- return current position in file. return file.position; end; error:BOOL is return file.error; end; clear is -- This routine clears any error condition for the cursor and associated file. file.clear; end; eof:BOOL pre ~void(self) is -- true if EOF has been encountered. return file.at_end; end; get(n:CARD):FBINSTR is -- get n octet. return file.get(n); end; get_octet:OCTET is return file.get(1).aget(0); end; get_line:FBINSTR is res::=#FBINSTR; loop if eof then return res end; c:OCTET:=get_octet; if (c=#OCTET('\n')) then return res; end; res:=res.push(c); end; end; get_str:STR is bs:FBINSTR:=get_line; return bs.str; end; end;