remove vestigial special-case code for input from 'terminal' (stdin)
This commit is contained in:
parent
35c6641a21
commit
1d930672bc
82
startup.4th
82
startup.4th
|
|
@ -2073,60 +2073,6 @@ FORTH DEFINITIONS
|
|||
: PRESERVED ( i*x xt addr -- j*x )
|
||||
DUP @ >R >R CATCH 2R> ! RETHROW ;
|
||||
|
||||
SYSTEM DEFINITIONS
|
||||
|
||||
\ The size of this buffer will determine the maximum line length
|
||||
4096 CONSTANT TERMINAL-BUFFER-BYTES
|
||||
TERMINAL-BUFFER-BYTES BUFFER: TERMINAL-BUFFER
|
||||
|
||||
\ If we read more than one line then these will refer to the rest of the data
|
||||
2VARIABLE TIB-LEFTOVER
|
||||
NULL 0 TIB-LEFTOVER 2!
|
||||
|
||||
\ Placeholder for later support for input from files
|
||||
DEFER REFILL-FROM-FILE
|
||||
' FALSE IS REFILL-FROM-FILE
|
||||
|
||||
FORTH DEFINITIONS
|
||||
|
||||
\ Attempt to replace the parse area with the next line from the current source
|
||||
\ Return TRUE if the parse area was refilled, or FALSE otherwise
|
||||
\ REFILL always fails if the current source is a string (from EVALUATE)
|
||||
:FINALIZE REFILL ( -- flag )
|
||||
SOURCE-ID -1 = IF FALSE EXIT THEN
|
||||
SOURCE-ID 0> IF REFILL-FROM-FILE EXIT THEN
|
||||
\ Shift any leftover characters after the previous line to the start of the buffer
|
||||
TIB-LEFTOVER 2@ TERMINAL-BUFFER SWAP DUP >R CMOVE
|
||||
\ Look for the linefeed character which marks the end of the first line
|
||||
R> 0 BEGIN
|
||||
\ If at the end with room in the buffer, read more from the file descriptor
|
||||
2DUP = IF
|
||||
DUP TERMINAL-BUFFER-BYTES U< IF
|
||||
STDIN OVER TERMINAL-BUFFER TERMINAL-BUFFER-BYTES ROT /STRING
|
||||
( S: length idx src-id buff buff-size )
|
||||
SYS_READ SYSCALL3-RETRY DUP 0< IF EXCP-FILE-IO THROW THEN
|
||||
( S: length idx u-read )
|
||||
\ Add the amount of data read to the length; index is unchanged
|
||||
ROT + SWAP
|
||||
THEN
|
||||
THEN
|
||||
\ At this point if index equals length then buffer is full or read returned 0
|
||||
\ Either way, we won't be reading any more into the buffer
|
||||
2DUP <>
|
||||
WHILE
|
||||
\ Check if the next character is a linefeed
|
||||
1+ DUP 1- TERMINAL-BUFFER + C@ LF =
|
||||
UNTIL
|
||||
( S: length idx )
|
||||
\ idx is the next location after the linefeed, if found, or else equal to length
|
||||
\ Save the rest, if any, for the next REFILL
|
||||
TUCK - >R TERMINAL-BUFFER OVER + R> TIB-LEFTOVER 2!
|
||||
( S: idx )
|
||||
\ The new input buffer is the first idx characters of the terminal buffer
|
||||
TERMINAL-BUFFER OVER INPUT-BUFFER 2!
|
||||
DUP IF 0 >IN ! THEN
|
||||
0<> ;
|
||||
|
||||
UTILITY DEFINITIONS
|
||||
|
||||
\ Parse up to limit digits in the given base, appending them to u1 to produce u2.
|
||||
|
|
@ -2836,6 +2782,7 @@ SYSTEM DEFINITIONS
|
|||
STRUCT
|
||||
AA-NODE% FIELD FILE>NODE
|
||||
CELL% FIELD FILE>FD
|
||||
CELL% FIELD FILE>FLAGS
|
||||
CELL% FIELD FILE>BUFFER
|
||||
2CELL% FIELD FILE>LEFTOVER
|
||||
2CELL% FIELD FILE>POSITION
|
||||
|
|
@ -2875,6 +2822,7 @@ O_RDWR CONSTANT R/W ( -- fam )
|
|||
-ROT MAKE-CSTRING ▪ FILE% %ALLOCATE ▪ NULL
|
||||
LOCALS| fam name file open-how |
|
||||
open_how% %ALLOCA open-how!
|
||||
fam file FILE>FLAGS !
|
||||
NULL file FILE>BUFFER !
|
||||
file CLEAR-LEFTOVER
|
||||
0# file FILE>POSITION 2!
|
||||
|
|
@ -2954,6 +2902,11 @@ UTILITY DEFINITIONS
|
|||
THEN
|
||||
RDROP ;
|
||||
|
||||
: RAW-FILE-POSITION ( fileid -- ud )
|
||||
DUP FD>FILE DROP ▪ signed-long-long% %ALLOCA >R
|
||||
0# SWAP ▪ R@ ▪ SEEK_CUR ▪ SYS__LLSEEK SYSCALL5-RETRY
|
||||
0<> IF EXCP-FILE-IO THROW THEN ▪ R> 2@ SWAP ;
|
||||
|
||||
FORTH DEFINITIONS
|
||||
|
||||
: READ-FILE ( c-addr u1 fileid -- u2 )
|
||||
|
|
@ -2984,6 +2937,17 @@ FORTH DEFINITIONS
|
|||
|
||||
UTILITY DEFINITIONS
|
||||
|
||||
: OPEN-FD ( fd fam -- fileid )
|
||||
FILE% %ALLOCATE
|
||||
TUCK FILE>FLAGS !
|
||||
NULL OVER FILE>BUFFER !
|
||||
DUP CLEAR-LEFTOVER
|
||||
DUP NULL 0 ROT FILE>SOURCE 2!
|
||||
2DUP FILE>FD !
|
||||
DUP FILES AA-INSERT
|
||||
OVER [[ ' RAW-FILE-POSITION ]] CATCH IF DROP 0# THEN
|
||||
ROT FILE>POSITION 2! ;
|
||||
|
||||
: REFILL-FILE ( fileid -- t=refilled )
|
||||
FD>FILE >R
|
||||
R@ ENSURE-SOURCE
|
||||
|
|
@ -2992,8 +2956,8 @@ UTILITY DEFINITIONS
|
|||
|
||||
SYSTEM DEFINITIONS
|
||||
|
||||
:FINALIZE REFILL-FROM-FILE ( -- t=refilled )
|
||||
SOURCE-ID DUP 0< "not a valid file source" ?FAIL
|
||||
: REFILL-FROM-FILE ( -- t=refilled )
|
||||
SOURCE-ID
|
||||
DUP [[ ' REFILL-FILE ]] CATCH ?DUP IF
|
||||
DUP EXCP-FILE-IO <> IF RETHROW THEN
|
||||
DROP 2DROP FALSE EXIT
|
||||
|
|
@ -3001,6 +2965,8 @@ SYSTEM DEFINITIONS
|
|||
DUP IF ▪ OVER FD>FILE FILE>SOURCE 2@ ▪ INPUT-BUFFER 2! ▪ 0 >IN ! ▪ THEN
|
||||
NIP ;
|
||||
|
||||
{ SOURCE-ID 0>= IF REFILL-FROM-FILE ELSE DEFERS REFILL THEN } IS REFILL
|
||||
|
||||
FORTH DEFINITIONS
|
||||
|
||||
: WRITE-FILE ( c-addr u fileid -- )
|
||||
|
|
@ -3045,6 +3011,10 @@ FORTH DEFINITIONS
|
|||
|
||||
SYSTEM DEFINITIONS
|
||||
|
||||
0 R/O OPEN-FD DROP
|
||||
1 W/O OPEN-FD DROP
|
||||
2 W/O OPEN-FD DROP
|
||||
|
||||
{
|
||||
ONLY FORTH DEFINITIONS
|
||||
ARGC 2 U>= IF
|
||||
|
|
|
|||
Loading…
Reference in New Issue