factor/library/io/stdio.factor

37 lines
1.2 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
2005-11-29 23:49:59 -05:00
USING: errors hashtables generic kernel namespaces strings
styles ;
2005-08-19 21:46:12 -04:00
2005-12-16 21:12:35 -05:00
SYMBOL: stdio
: close ( -- ) stdio get stream-close ;
2005-08-19 21:46:12 -04:00
: readln ( -- string/f ) stdio get stream-readln ;
2005-12-16 21:12:35 -05:00
: read1 ( -- char/f ) stdio get stream-read1 ;
: read ( count -- string ) stdio get stream-read ;
: write1 ( char -- ) stdio get stream-write1 ;
: write ( string -- ) stdio get stream-write ;
: flush ( -- ) stdio get stream-flush ;
: break ( -- ) stdio get stream-break ;
: terpri ( -- ) stdio get stream-terpri ;
2005-08-19 21:46:12 -04:00
: format ( string style -- ) stdio get stream-format ;
2005-12-16 21:12:35 -05:00
: with-nesting ( style quot -- ) stdio get with-nested-stream ;
: print ( string -- ) stdio get stream-print ;
2005-08-19 21:46:12 -04:00
2005-09-25 20:41:49 -04:00
: write-outliner ( string object quot -- )
2005-11-29 23:49:59 -05:00
[ outline set presented set ] make-hash format terpri ;
2005-09-25 20:41:49 -04:00
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