From c253cd854a44078df02c7eaa84445773530d63ad Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 29 Jan 2009 18:33:19 -0600 Subject: [PATCH] move null streams to core and make them not depend on io.styles and io.timeouts, initialize the std streams to null-streams on windows in win32 mode --- basis/io/backend/windows/nt/nt.factor | 5 ++++- basis/io/timeouts/timeouts.factor | 4 +++- core/io/backend/backend.factor | 21 +++++++++++++++------ core/io/streams/c/c.factor | 2 +- {basis => core}/io/streams/null/authors.txt | 0 {basis => core}/io/streams/null/null-docs.factor | 0 {basis => core}/io/streams/null/null-tests.factor | 0 {basis => core}/io/streams/null/null.factor | 12 +++--------- 8 files changed, 26 insertions(+), 18 deletions(-) mode change 100644 => 100755 basis/io/timeouts/timeouts.factor rename {basis => core}/io/streams/null/authors.txt (100%) rename {basis => core}/io/streams/null/null-docs.factor (100%) rename {basis => core}/io/streams/null/null-tests.factor (100%) rename {basis => core}/io/streams/null/null.factor (62%) diff --git a/basis/io/backend/windows/nt/nt.factor b/basis/io/backend/windows/nt/nt.factor index 493a735f7f..b114cefdc0 100755 --- a/basis/io/backend/windows/nt/nt.factor +++ b/basis/io/backend/windows/nt/nt.factor @@ -120,6 +120,9 @@ M: winnt (wait-to-read) ( port -- ) tri ] with-destructors ; -M: winnt (init-stdio) init-c-stdio ; +: console-app? ( -- ? ) GetConsoleWindow ; + +M: winnt (init-stdio) + console-app? [ f f f f ] [ init-c-stdio t ] if ; winnt set-io-backend diff --git a/basis/io/timeouts/timeouts.factor b/basis/io/timeouts/timeouts.factor old mode 100644 new mode 100755 index fd1b14de19..8e69983e9c --- a/basis/io/timeouts/timeouts.factor +++ b/basis/io/timeouts/timeouts.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Slava Pestov, Doug Coleman ! See http://factorcode.org/license.txt for BSD license. USING: kernel calendar alarms io io.encodings accessors -namespaces fry ; +namespaces fry io.streams.null ; IN: io.timeouts GENERIC: timeout ( obj -- dt/f ) @@ -27,3 +27,5 @@ GENERIC: cancel-operation ( obj -- ) : timeouts ( dt -- ) [ input-stream get set-timeout ] [ output-stream get set-timeout ] bi ; + +M: null-stream set-timeout 2drop ; diff --git a/core/io/backend/backend.factor b/core/io/backend/backend.factor index 322a603144..fd5567cfa2 100644 --- a/core/io/backend/backend.factor +++ b/core/io/backend/backend.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2007, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: init kernel system namespaces io io.encodings -io.encodings.utf8 init assocs splitting alien ; +io.encodings.utf8 init assocs splitting alien io.streams.null ; IN: io.backend SYMBOL: io-backend @@ -12,13 +12,22 @@ io-backend global [ c-io-backend or ] change-at HOOK: init-io io-backend ( -- ) -HOOK: (init-stdio) io-backend ( -- stdin stdout stderr ) +HOOK: (init-stdio) io-backend ( -- stdin stdout stderr ? ) + +: set-stdio ( input-handle output-handle error-handle -- ) + [ input-stream set-global ] + [ output-stream set-global ] + [ error-stream set-global ] tri* ; : init-stdio ( -- ) - (init-stdio) - [ utf8 input-stream set-global ] - [ utf8 output-stream set-global ] - [ utf8 error-stream set-global ] tri* ; + (init-stdio) [ + [ utf8 ] + [ utf8 ] + [ utf8 ] tri* + ] [ + 3drop + null-reader null-writer null-writer + ] if set-stdio ; HOOK: io-multiplex io-backend ( us -- ) diff --git a/core/io/streams/c/c.factor b/core/io/streams/c/c.factor index 71c9ffd7d9..a93602533d 100755 --- a/core/io/streams/c/c.factor +++ b/core/io/streams/c/c.factor @@ -65,7 +65,7 @@ M: c-io-backend init-io ; stdout-handle stderr-handle ; -M: c-io-backend (init-stdio) init-c-stdio ; +M: c-io-backend (init-stdio) init-c-stdio t ; M: c-io-backend io-multiplex 60 60 * 1000 * 1000 * or (sleep) ; diff --git a/basis/io/streams/null/authors.txt b/core/io/streams/null/authors.txt similarity index 100% rename from basis/io/streams/null/authors.txt rename to core/io/streams/null/authors.txt diff --git a/basis/io/streams/null/null-docs.factor b/core/io/streams/null/null-docs.factor similarity index 100% rename from basis/io/streams/null/null-docs.factor rename to core/io/streams/null/null-docs.factor diff --git a/basis/io/streams/null/null-tests.factor b/core/io/streams/null/null-tests.factor similarity index 100% rename from basis/io/streams/null/null-tests.factor rename to core/io/streams/null/null-tests.factor diff --git a/basis/io/streams/null/null.factor b/core/io/streams/null/null.factor similarity index 62% rename from basis/io/streams/null/null.factor rename to core/io/streams/null/null.factor index a2224ef306..98729c7abd 100644 --- a/basis/io/streams/null/null.factor +++ b/core/io/streams/null/null.factor @@ -1,13 +1,13 @@ ! Copyright (C) 2007, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel io io.timeouts io.styles destructors ; +USING: kernel io destructors io.streams.plain ; IN: io.streams.null SINGLETONS: null-reader null-writer ; UNION: null-stream null-reader null-writer ; +INSTANCE: null-writer plain-writer M: null-stream dispose drop ; -M: null-stream set-timeout 2drop ; M: null-reader stream-readln drop f ; M: null-reader stream-read1 drop f ; @@ -16,16 +16,10 @@ M: null-reader stream-read 2drop f ; M: null-writer stream-write1 2drop ; M: null-writer stream-write 2drop ; -M: null-writer stream-nl drop ; M: null-writer stream-flush drop ; -M: null-writer stream-format 3drop ; -M: null-writer make-span-stream nip ; -M: null-writer make-block-stream nip ; -M: null-writer make-cell-stream nip ; -M: null-writer stream-write-table 3drop ; : with-null-reader ( quot -- ) null-reader swap with-input-stream* ; inline : with-null-writer ( quot -- ) - null-writer swap with-output-stream* ; inline \ No newline at end of file + null-writer swap with-output-stream* ; inline -- 2.11.4.GIT