[fpc-devel] Questions regarding m68k-atari target
Tomas Hajny
XHajT03 at hajny.biz
Tue Feb 1 10:55:46 CET 2022
On 2022-02-01 06:02, Thorsten Otto via fpc-devel wrote:
> On Samstag, 29. Januar 2022 16:03:32 CET Tomas Hajny via fpc-devel
> wrote:
>
>> does it return individual characters, or does it
>> return the whole line at once (the latter being the case for other FPC
>> targets as far as I know)?
>
> Just tried with a small test program, and the behaviour is a bit
> strange. Fread(0, count, buf) returns when you either press return, or
> the count has been reached. However, if you press return, the return
> value does not include the CR, nor is that CR written to the buffer.
Right, I expected something like that based on the described behaviour.
Is the pressed CR never returned then, or is it returned in a following
fread call?
> The Window ReadFile function behaves totally differently there. It
> only returns when you press enter, and the buffer and count includes a
> CR/LF.
Indeed, that's what I already mentioned. Moreover, the ReadFile function
on Windows (and similarly the respective equivalents on various other
platforms) doesn't even allow the user to enter more characters than the
buffer length _minus_space_for_the_terminating_end_of_line_marker_ when
reading from console (not necessarily when reading from standard input -
if the standard input is redirected and gets input from a file, more
characters are accepted). In other words, reading characters (pressed
keys) stops when reaching character 253 and nothing except the Enter key
is accepted (and the Enter key is then stored as #13 and #10 to the end
of the buffer as correctly mentioned by you). I'm afraid that the
observed behaviour of fread suggests that you need to modify the do_read
implementation for atari to do the same if reading from console - in
other words, you need to call fread with one less character in "len" in
that case (and add it to the end of the buffer being returned from
do_read afterwards).
BTW, be careful about distinction between the standard input handle and
input from console unless either no redirection of input is possible, or
the handle of such an input changes to a different value in that case
(as of now, the implementation of do_isdevice for atari works only with
the handle number rather than checking what the handle refers to using
some special API function, but that may not be correct).
Tomas
More information about the fpc-devel
mailing list