-
Notifications
You must be signed in to change notification settings - Fork 0
/
crexam.fth
66 lines (52 loc) · 1.86 KB
/
crexam.fth
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
\ Conditions and restarts --- Example
S" conres.fth" INCLUDED
\ An error is not a bug, but an unhandled one is
: DISPLAY-ERROR? ." error" ;
? CLONE ERROR? ? >UNHANDLED @ , ' DISPLAY-ERROR? ,
: I/O?-DEVICE ( i/o? -- i/o? dev# ) OVER ;
: DISPLAY-I/O?
." input/output error on device " I/O?-DEVICE . ;
ERROR? CLONE I/O? ( dev# -- i/o? ) ERROR? >UNHANDLED @ ,
' DISPLAY-I/O? ,
VARIABLE BUFFER
: (READ-BYTE) ( simulate an error and garbage data )
42 BUFFER ! 123 I/O? SIGNAL ;
HERE ," IGNORE?" DUP HERE SWAP -
: DESCRIBE-IGNORE? ." Ignore the error and proceed" ;
RESTART? CLONE IGNORE? RESTART? >UNHANDLED @ ,
RESTART? >DISPLAY @ , ( c-addr len ) , , ' DESCRIBE-IGNORE? ,
HERE ," RETRY?" DUP HERE SWAP -
: DESCRIBE-RETRY? ." Retry the operation" ;
RESTART? CLONE RETRY? RESTART? >UNHANDLED @ ,
RESTART? >DISPLAY @ , ( c-addr len ) , , ' DESCRIBE-RETRY? ,
: READ-BYTE
BEGIN
MARK
[: MARK ['] (READ-BYTE) IGNORE? RESTART TRIM ;]
RETRY? RESTART
WHILE
TRIM
REPEAT R> DROP ;
: APPLICATION READ-BYTE ." Read byte: " BUFFER @ . CR ;
HERE ," ABORT?" DUP HERE SWAP -
: DESCRIBE-ABORT? ." Stop and return to shell" ;
RESTART? CLONE ABORT? RESTART? >UNHANDLED @ ,
RESTART? >DISPLAY @ , ( c-addr len ) , , ' DESCRIBE-ABORT? ,
: SHELL
MARK
['] APPLICATION ABORT? RESTART IF ." Aborted " CR THEN
TRIM ;
: MORE-RESPONSES 0 @F ['] DEFAULT-RESPONSE <> ;
: NEXT-RESPONSE 1 @F ;
: RESTART-RESPONSE DUP 0 @F ['] (HANDLE) = ANDIF DUP 2 @F
RESTART? EXTENDS THEN ;
: RESTART. DUP >NAME 2@ TYPE ." -- " DESCRIBE DROP ;
: LIST-RESTARTS ." Restarts:" CR RESPONSE @ BEGIN
RESTART-RESPONSE IF DUP 2 @F 2 SPACES RESTART. CR THEN
DUP MORE-RESPONSES WHILE NEXT-RESPONSE REPEAT DROP ;
: SYSTEM
['] SHELL ? [:
( hf ) DROP ." Signalled " DISPLAY CR LIST-RESTARTS
PAD DUP 84 ACCEPT CR EVALUATE SIGNAL
;] HANDLE ;
CR SYSTEM