mirror of
https://github.com/nineties/planckforth
synced 2025-01-13 08:01:10 +01:00
Change semantics of read-line
This commit is contained in:
parent
f7a5562cc8
commit
af8fc4f57f
1 changed files with 7 additions and 6 deletions
13
bootstrap.fs
13
bootstrap.fs
|
@ -1714,19 +1714,20 @@ end-struct file%
|
|||
;
|
||||
|
||||
\ Read characters from 'file' to the buffer c-addr u1
|
||||
\ until reaches '\n' or end of file.
|
||||
\ '\0' is stored at the last and '\n' is not stored.
|
||||
\ until reaches '\n' or end of file, null character is
|
||||
\ stored at last.
|
||||
\ u2 is the number of characters written to the buffer.
|
||||
\ flag=true if it reaches '\n'.
|
||||
\ e is error code.
|
||||
: read-line ( c-addr u1 file -- u2 flag e )
|
||||
\ flag=true if it reads '\n'. e is error code.
|
||||
: read-line ( c-addr u1 file -- u2 e )
|
||||
over 1- 0 do
|
||||
2 pick i + 1 2 pick read-file
|
||||
dup 0< if false leave then
|
||||
drop
|
||||
( c-addr u1 file u2 )
|
||||
0= if i success false leave then \ EOF
|
||||
2 pick i + c@ '\n' = if i success true leave then
|
||||
2 pick i + c@ '\n' = if
|
||||
i 1+ success true leave
|
||||
then
|
||||
loop
|
||||
( c-addr u1 file u2 e flag )
|
||||
>r >r
|
||||
|
|
Loading…
Reference in a new issue