From: Tim Vaughan Date: Sun, 2 Oct 2016 00:12:42 +0000 (+1300) Subject: Added READ-LINE X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=d7ff8db7577277539dcc447df305cdf44e816d5f;p=forth.jl.git Added READ-LINE --- diff --git a/src/forth.jl b/src/forth.jl index d911e21..aa93c2d 100644 --- a/src/forth.jl +++ b/src/forth.jl @@ -665,6 +665,22 @@ CLOSE_FILES_CFA = defPrimWord("CLOSE-FILES", () -> begin end) READ_LINE_CFA = defPrimWord("READ-LINE", () -> begin + fid = popPS() + maxSize = popPS() + addr = popPS() + + fh = openFiles[fid] + line = readline(fh) + + eofFlag = endswith(line, '\n') ? 0 : -1 + line = chomp(line) + + putString(line, addr, maxSize) + + pushPS(length(line)) + pushPS(eofFlag) + pushPS(0) + return NEXT end)