Top |
You can read Latin-1 or Unicode characters, buffers, or whole lines from any stream. The characters will be converted into the form in which you request them.
glsi32
glk_get_char_stream (strid_t str
);
Reads one character from the stream str
.
(There is no notion of a “current input stream.”)
It is illegal for str
to be NULL
, or an output-only stream.
The result will be between 0 and 255. As with all basic text functions, Glk assumes the Latin-1 encoding. See Character Encoding. If the end of the stream has been reached, the result will be -1.
Note that high-bit characters (128..255) are not returned as negative numbers.
If the stream contains Unicode data — for example, if it was created
with glk_stream_open_file_uni()
or glk_stream_open_memory_uni()
— then
characters beyond 255 will be returned as 0x3F ("?"
).
It is usually more efficient to read several characters at once with
glk_get_buffer_stream()
or glk_get_line_stream()
, as opposed to calling
glk_get_char_stream()
several times.
glui32 glk_get_buffer_stream (strid_t str
,char *buf
,glui32 len
);
Reads len
characters from str
, unless the end of stream is reached first.
No terminal null is placed in the buffer.
glui32 glk_get_line_stream (strid_t str
,char *buf
,glui32 len
);
Reads characters from str
, until either len
- 1 characters have
been read or a newline has been read.
It then puts a terminal null ('\0'
) character on the end.
It returns the number of characters actually read, including the newline (if
there is one) but not including the terminal null.
glsi32
glk_get_char_stream_uni (strid_t str
);
Reads one character from the stream str
. If the end of the stream has been
reached, the result will be -1.
glui32 glk_get_buffer_stream_uni (strid_t str
,glui32 *buf
,glui32 len
);
Reads len
Unicode characters from str
, unless the end of stream is reached
first. No terminal null is placed in the buffer.
glui32 glk_get_line_stream_uni (strid_t str
,glui32 *buf
,glui32 len
);
Reads Unicode characters from str
, until either len
- 1 Unicode characters
have been read or a newline has been read.
It then puts a terminal null (a zero value) on the end.