factor/library/io/stdio.factor

35 lines
1.3 KiB
Factor
Raw Normal View History

2005-08-19 21:46:12 -04:00
! Copyright (C) 2003, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: io
USING: errors generic kernel lists namespaces strings styles ;
: flush ( -- ) stdio get stream-flush ;
: readln ( -- string/f ) stdio get stream-readln ;
: read1 ( -- char/f ) stdio get stream-read1 ;
: read ( count -- string ) stdio get stream-read ;
: write ( string -- ) stdio get stream-write ;
: write1 ( char -- ) stdio get stream-write1 ;
: format ( string style -- ) stdio get stream-format ;
: print ( string -- ) stdio get stream-print ;
: terpri ( -- ) stdio get stream-terpri ;
: close ( -- ) stdio get stream-close ;
: write-object ( string object -- )
presented swons unit format ;
2005-09-25 20:41:49 -04:00
: write-outliner ( string object quot -- )
outline swons >r presented swons r> 2list format terpri ;
2005-08-19 21:46:12 -04:00
: with-stream ( stream quot -- )
#! Close the stream no matter what happens.
2005-09-21 01:12:16 -04:00
[ swap stdio set [ close ] cleanup ] with-scope ; inline
2005-08-19 21:46:12 -04:00
: with-stream* ( stream quot -- )
#! Close the stream if there is an error.
2005-09-21 01:12:16 -04:00
[ swap stdio set [ close rethrow ] recover ] with-scope ;
inline
2005-08-19 21:46:12 -04:00
: contents ( stream -- string )
#! Read the entire stream into a string.
4096 <sbuf> [ stream-copy ] keep >string ;