in.sa


Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
 
---------------------------> Sather 1.1 source file <--------------------------
-- Copyright (C) International Computer Science Institute, 1994.  COPYRIGHT  --
-- NOTICE: This code is provided "AS IS" WITHOUT ANY WARRANTY and is subject --
-- to the terms of the SATHER LIBRARY GENERAL PUBLIC LICENSE contained in    --
-- the file "Doc/License" of the Sather distribution.  The license is also   --
-- available from ICSI, 1947 Center St., Suite 600, Berkeley CA 94704, USA.  --
--------> Please email comments to sather-bugs@icsi.berkeley.edu. <----------

-- in.sa: Input from stdin.


class IN

class IN is -- Direct access to stdin. create:SAME is return self end; get_char:INT is -- Retrieve a single character as an INT from stdin, negative for -- end of file. Built-in. builtin IN_GETCHAR; end; get_str:STR is -- A string containing the characters on stdin up to the next -- newline. return get_line.str; end; get_line:FSTR is -- A string buffer containing the characters on stdin up to the -- next newline. return append_line(void); end; private const size : INT := 256; append_line(s:FSTR):FSTR is -- Retrieve a string from stdin up to the next newline and append -- it to `s'. -- Implementation contributed by hikichi@srarc2.sra.co.jp -- (Nobuyuki Hikichi). bsize ::= size; loop buf ::= #FSTR(bsize); -- buffer to hold C string buf.loc := bsize - 1; get_str_sized(buf, bsize); m: INT := buf.index_of('\n'); if m >= 0 then buf.loc := m; return s + buf; end; n: INT := buf.index_of('\0'); if n = -1 then s := s + buf; bsize := bsize * 2; elsif n = 0 then return s; elsif n <= (bsize - 1) then buf.loc := n; return s + buf; else raise "IN::append_line, out of range [-1, bsize-1]"; end; -- if end; -- loop end; -- fstr (s:FSTR) private get_str_sized(buf:FSTR,sz:INT) is -- Read at most sz-1 characters and place them in buf, -- followed by trailing '\0'. Built-in. builtin IN_GET_STR_SIZED; end; error:BOOL is -- true if an error has been encountered. Cleared by "clear". return RUNTIME::ferror(FILE::stdin_macro); end; eof:BOOL is -- true if EOF has been encountered. Cleared by "clear". return RUNTIME::feof(FILE::stdin_macro); end; clear is -- resets end_seen and error status RUNTIME::clearerr(FILE::stdin_macro); end; end; -- class IN