6.6.1 Prolog Streams

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)
StreamCode is the C stream identifier (an integer) corresponding to the Prolog stream Stream. This predicate is only useful when streams are passed between Prolog and C.

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()
Read one byte from a binary stream.
SP_get_code()
Read one character code from a text stream.
SP_put_byte()
Write one byte to a binary stream.
SP_put_code()
Write one character code to a text stream.
SP_put_bytes()
Write multiple bytes to a binary stream.
SP_put_codes()
Write multiple character codes to a text stream.
SP_put_encoded_string()
Write a NUL terminated encoded string to a text stream.
SP_printf()

SP_fprintf()
Perform formatted output.
SP_flush_output()
Flush buffered data of an output stream.
SP_fclose()
Close a stream.

The following predefined streams are accessible from C:

SP_stdin
Standard input. Refers to the same stream as user_input in Prolog. Which stream is referenced by user_input is controlled by the Prolog flag user_input.
SP_stdout
Standard output. Refers to the same stream as user_output in Prolog. Which stream is referenced by user_output is controlled by the Prolog flag user_output.
SP_stderr
Standard error. Refers to the same stream as user_error in Prolog. Which stream is referenced by user_error is controlled by the flag user_error.
SP_curin
Current input. It is initially set equal to SP_stdin. It can be changed with the predicates see/1 and set_input/1.
SP_curout
Current output. It is initially set equal to SP_stdout. It can be changed with the predicates tell/1 and set_output/1.

Note that these variables are read only.


Send feedback on this subject.