LINE INPUT & FORMAT$ V13
LINE INPUT #n, var$ V13 rework
Syntax:
V13 change: Reworked from bulk ReadFile to CR/LF-aware one-byte loop
LINE INPUT #n, stringvar$V13 change: Reworked from bulk ReadFile to CR/LF-aware one-byte loop
Reads an entire line from an open file into a string variable, discarding the trailing CR/LF. In V13, the implementation was reworked from a single bulk ReadFile call to a character-by-character read loop that correctly handles CR, LF, and CRLF line endings.
Example
#COMPILE EXE
#DIM ALL
FUNCTION PBMAIN() AS LONG
LOCAL ln AS STRING
OPEN "data.txt" FOR INPUT AS #1
WHILE NOT EOF(1)
LINE INPUT #1, ln
PRINT ln
WEND
CLOSE #1
FUNCTION = 0
END FUNCTION
LINE INPUT Behavior
| File Content | Result in var$ |
|---|---|
Hello\r\n | "Hello" |
World\n | "World" |
Line\r | "Line" |
NoNewline | "NoNewline" |
V13 Implementation (One-Byte Loop)
; Read one byte at a time until CR, LF, or EOF __pb_liread_loop: mov rcx, [rbp - handle_offset] lea rdx, [rbp - one_byte_temp] mov r8, 1 ; read 1 byte lea r9, [rbp - bytes_read] mov [rsp + 32], 0 call [__imp_ReadFile] cmp rax, 0 je __pb_liread_eof mov al, byte [rbp - one_byte_temp] cmp al, 13 ; CR je __pb_liread_check_lf cmp al, 10 ; LF je __pb_liread_done ; Store byte in buffer, increment position jmp __pb_liread_loop __pb_liread_check_lf: ; Peek ahead for LF after CR (CRLF handling) ; If LF follows, consume it __pb_liread_done: ; NUL-terminate buffer
FORMAT$ (Numeric) V13 helpers
Syntax:
Runtime:
result$ = FORMAT$(numeric)Runtime:
pb_str64_format_i64, pb_str64_format_d (pb_string64.c)V13 adds runtime helper functions for numeric formatting (pb_str64_format_i64 for integers, pb_str64_format_d for doubles). These provide a practical numeric-to-string conversion subset. Full PB picture/mask formatting remains future work.
Example
LOCAL s AS STRING LOCAL n AS LONG n = 12345 s = FORMAT$(n) ' "12345"
LOF() / EOF() V12+ carry-forward
Syntax:
LOF(#n) | EOF(#n)Both use GetFileSize internally. EOF compares current file pointer position against total size. File number must be a constant 1..15.