[SLOF] [PATCH v4 2/2] resolve ihandle and xt handle in the input command (like for the output)
Laurent Vivier
lvivier at redhat.com
Fri Mar 23 21:15:30 AEDT 2018
Signed-off-by: Laurent Vivier <lvivier at redhat.com>
---
slof/fs/term-io.fs | 87 ++++++++++++++++++++++++++++--------------------------
1 file changed, 45 insertions(+), 42 deletions(-)
diff --git a/slof/fs/term-io.fs b/slof/fs/term-io.fs
index d1a27aa..022ef2f 100644
--- a/slof/fs/term-io.fs
+++ b/slof/fs/term-io.fs
@@ -10,10 +10,17 @@
\ * IBM Corporation - initial implementation
\ ****************************************************************************/
+0 VALUE read-xt
0 VALUE write-xt
+VARIABLE stdin
VARIABLE stdout
+: set-stdin ( ihandle -- )
+ dup stdin !
+ encode-int s" stdin" set-chosen
+;
+
: set-stdout ( ihandle -- )
dup stdout !
encode-int s" stdout" set-chosen
@@ -21,12 +28,18 @@ VARIABLE stdout
: input ( dev-str dev-len -- )
open-dev ?dup IF
- \ Close old stdin:
- s" stdin" get-chosen IF
- decode-int nip nip ?dup IF close-dev THEN
+ \ find new ihandle and xt handle
+ dup s" read" rot ihandle>phandle find-method
+ 0= IF
+ drop
+ cr ." Cannot find the read method for the given input console " cr
+ EXIT
THEN
+ \ Close old stdin:
+ stdin @ ?dup IF close-dev THEN
\ Now set the new stdin:
- encode-int s" stdin" set-chosen
+ to read-xt
+ set-stdin
THEN
;
@@ -64,17 +77,12 @@ VARIABLE stdout
' term-io-emit to emit
: term-io-key ( -- char )
- s" stdin" get-chosen IF
- decode-int nip nip dup 0= IF 0 EXIT THEN
- >r BEGIN
- (term-io-char-buf) 1 s" read" r@ $call-method
- 0 >
- UNTIL
- (term-io-char-buf) c@
- r> drop
- ELSE
- [ ' key behavior compile, ]
- THEN
+ read-xt 0= IF 0 EXIT THEN
+ BEGIN
+ (term-io-char-buf) 1 read-xt stdin @ call-package
+ 0 >
+ UNTIL
+ (term-io-char-buf) c@
;
' term-io-key to key
@@ -85,35 +93,30 @@ VARIABLE stdout
\ - if it's an hv console, use hvterm-key?
\ otherwise it will always return false
: term-io-key? ( -- true|false )
- s" stdin" get-chosen IF
- decode-int nip nip dup 0= IF drop 0 EXIT THEN \ return false and exit if no stdin set
- >r \ store ihandle on return stack
- s" device_type" r@ ihandle>phandle ( propstr len phandle )
- get-property ( true | data dlen false )
- IF
- \ device_type not found, return false and exit
- false
- ELSE
- 1 - \ remove 1 from length to ignore null-termination char
- \ device_type found, check wether it is serial or keyboard
- 2dup s" serial" str= IF
- 2drop serial-key? r> drop EXIT
- THEN \ call serial-key, cleanup return-stack, exit
- 2dup s" keyboard" str= IF
- 2drop ( )
- \ keyboard found, check for key-available? method, execute it or return false
- s" key-available?" r@ ihandle>phandle find-method IF
- drop s" key-available?" r@ $call-method
- ELSE
- false
- THEN
- r> drop EXIT \ cleanup return-stack, exit
+ stdin @ ?dup 0= IF false EXIT THEN \ stdin not set, return false
+ >r \ store ihandle on return stack
+ s" device_type" r@ ihandle>phandle ( propstr len phandle )
+ get-property ( true | data dlen false )
+ IF
+ \ device_type not found, return false and exit
+ false
+ ELSE
+ 1 - \ remove 1 from length to ignore null-termination char
+ \ device_type found, check wether it is serial or keyboard
+ 2dup s" serial" str= IF
+ 2drop serial-key? r> drop EXIT
+ THEN \ call serial-key, cleanup return-stack, exit
+ 2dup s" keyboard" str= IF
+ 2drop ( )
+ \ keyboard found, check for key-available? method, execute it or return false
+ s" key-available?" r@ ihandle>phandle find-method IF
+ drop s" key-available?" r@ $call-method
+ ELSE
+ false
THEN
- 2drop r> drop false EXIT \ unknown device_type cleanup return-stack, return false
+ r> drop EXIT \ cleanup return-stack, exit
THEN
- ELSE
- \ stdin not set, return false
- false
+ 2drop r> drop false EXIT \ unknown device_type cleanup return-stack, return false
THEN
;
--
2.14.3
More information about the SLOF
mailing list