From the Prolog level there is a unique number that identifies a stream. This identifier can be converted from/to a Prolog stream:
stream_code(
?Stream,
?StreamCode)
The StreamCode is a Prolog integer representing an
SP_stream *
pointer.
To read or write on a Prolog stream from C, the following functions and macros can be used:
SP_get_byte()
SP_get_code()
SP_put_byte()
SP_put_code()
SP_put_bytes()
SP_put_codes()
SP_put_encoded_string()
NUL
terminated encoded string to a text stream.
SP_printf()
SP_fprintf()
SP_flush_output()
SP_fclose()
The following predefined streams are accessible from C:
SP_stdin
user_input
in
Prolog. Which stream is referenced by user_input
is
controlled by the Prolog flag user_input
.
SP_stdout
user_output
in Prolog. Which stream is referenced by user_output
is
controlled by the Prolog flag user_output
.
SP_stderr
user_error
in
Prolog. Which stream is referenced by user_error
is
controlled by the flag user_error
.
SP_curin
SP_stdin
. It can be
changed with the predicates see/1
and set_input/1
.
SP_curout
SP_stdout
. It can
be changed with the predicates tell/1
and
set_output/1
.
Note that these variables are read only.