mirror of
https://github.com/nineties/planckforth
synced 2025-01-14 08:01:27 +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
|
\ Read characters from 'file' to the buffer c-addr u1
|
||||||
\ until reaches '\n' or end of file.
|
\ until reaches '\n' or end of file, null character is
|
||||||
\ '\0' is stored at the last and '\n' is not stored.
|
\ stored at last.
|
||||||
\ u2 is the number of characters written to the buffer.
|
\ u2 is the number of characters written to the buffer.
|
||||||
\ flag=true if it reaches '\n'.
|
\ flag=true if it reads '\n'. e is error code.
|
||||||
\ e is error code.
|
: read-line ( c-addr u1 file -- u2 e )
|
||||||
: read-line ( c-addr u1 file -- u2 flag e )
|
|
||||||
over 1- 0 do
|
over 1- 0 do
|
||||||
2 pick i + 1 2 pick read-file
|
2 pick i + 1 2 pick read-file
|
||||||
dup 0< if false leave then
|
dup 0< if false leave then
|
||||||
drop
|
drop
|
||||||
( c-addr u1 file u2 )
|
( c-addr u1 file u2 )
|
||||||
0= if i success false leave then \ EOF
|
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
|
loop
|
||||||
( c-addr u1 file u2 e flag )
|
( c-addr u1 file u2 e flag )
|
||||||
>r >r
|
>r >r
|
||||||
|
|
Loading…
Reference in a new issue