]> gitweb.factorcode.org Git - factor.git/blob - core/io/backend/backend.factor
Merge branch 'master' into experimental
[factor.git] / core / io / backend / backend.factor
1 ! Copyright (C) 2007, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: init kernel system namespaces io io.encodings
4 io.encodings.utf8 init assocs splitting alien io.streams.null ;
5 IN: io.backend
6
7 SYMBOL: io-backend
8
9 SINGLETON: c-io-backend
10
11 io-backend global [ c-io-backend or ] change-at
12
13 HOOK: init-io io-backend ( -- )
14
15 HOOK: (init-stdio) io-backend ( -- stdin stdout stderr ? )
16
17 : set-stdio ( input-handle output-handle error-handle -- )
18     [ input-stream set-global ]
19     [ output-stream set-global ]
20     [ error-stream set-global ] tri* ;
21
22 : init-stdio ( -- )
23     (init-stdio) [
24         [ utf8 <decoder> ]
25         [ utf8 <encoder> ]
26         [ utf8 <encoder> ] tri*
27     ] [
28         3drop
29         null-reader null-writer null-writer
30     ] if set-stdio ;
31
32 HOOK: io-multiplex io-backend ( us -- )
33
34 HOOK: normalize-directory io-backend ( str -- newstr )
35
36 HOOK: normalize-path io-backend ( str -- newstr )
37
38 M: object normalize-directory normalize-path ;
39
40 : set-io-backend ( io-backend -- )
41     io-backend set-global init-io init-stdio
42     "io.files" init-hooks get at call ;
43
44 ! Note that we have 'alien' in our using list so that the alien
45 ! init hook runs before this one.
46 [ init-io embedded? [ init-stdio ] unless ]
47 "io.backend" add-init-hook