2005-01-30 15:57:25 -05:00
|
|
|
! Copyright (C) 2003, 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
2004-07-16 02:26:21 -04:00
|
|
|
IN: stdio
|
2005-01-30 15:57:25 -05:00
|
|
|
USING: errors kernel lists namespaces streams generic strings ;
|
2004-11-28 21:56:58 -05:00
|
|
|
|
2004-11-29 23:14:12 -05:00
|
|
|
SYMBOL: stdio
|
|
|
|
|
|
|
|
: flush ( -- ) stdio get fflush ;
|
|
|
|
: read ( -- string ) stdio get freadln ;
|
|
|
|
: read1 ( count -- string ) stdio get fread1 ;
|
|
|
|
: read# ( count -- string ) stdio get fread# ;
|
|
|
|
: write ( string -- ) stdio get fwrite ;
|
|
|
|
: write-attr ( string style -- ) stdio get fwrite-attr ;
|
|
|
|
: print ( string -- ) stdio get fprint ;
|
2004-11-28 21:56:58 -05:00
|
|
|
: terpri ( -- ) "\n" write ;
|
2004-11-29 23:14:12 -05:00
|
|
|
: close ( -- ) stdio get fclose ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-08-30 20:24:19 -04:00
|
|
|
: write-icon ( resource -- )
|
|
|
|
#! Write an icon. Eg, /library/icons/File.png
|
2004-09-24 23:22:44 -04:00
|
|
|
"icon" swons unit "" swap write-attr ;
|
2004-08-30 20:24:19 -04:00
|
|
|
|
2004-07-16 02:26:21 -04:00
|
|
|
: with-stream ( stream quot -- )
|
2004-11-29 23:14:12 -05:00
|
|
|
[ swap stdio set [ close rethrow ] catch ] with-scope ;
|
2004-08-22 01:46:26 -04:00
|
|
|
|
|
|
|
: with-string ( quot -- str )
|
|
|
|
#! Execute a quotation, and push a string containing all
|
|
|
|
#! text printed by the quotation.
|
2005-01-30 15:57:25 -05:00
|
|
|
1024 <string-output> [
|
2004-11-29 23:14:12 -05:00
|
|
|
call stdio get stream>str
|
2004-08-22 01:46:26 -04:00
|
|
|
] with-stream ;
|
2004-10-17 19:01:16 -04:00
|
|
|
|
2005-02-09 22:35:11 -05:00
|
|
|
TUPLE: stdio-stream delegate ;
|
2004-11-28 21:56:58 -05:00
|
|
|
|
|
|
|
M: stdio-stream fauto-flush ( -- )
|
2005-01-30 15:57:25 -05:00
|
|
|
stdio-stream-delegate fflush ;
|
2004-11-28 21:56:58 -05:00
|
|
|
|
|
|
|
M: stdio-stream fclose ( -- )
|
2004-12-11 18:18:43 -05:00
|
|
|
drop ;
|