Several builtin functions and macros are defined to enable Prolog streams
to be manipulated in foreign code. This section lists each of these
functions. In this list, the character #
is used to denote a C macro,
which is defined in <quintus/quintus.h>
.
Full descriptions of each of these functions can be found in the
individual reference pages.
QP_fopen()
: open a text file or a binary file as a Prolog stream.
QP_fdopen()
: create a text stream or a binary stream from a file
descriptor.
QP_close()
: close a Prolog stream
QP_fclose()
: close a Prolog stream, same as QP_close()
.
#QP_getchar()
: get a character from the Prolog current input stream.
QP_getc()
: get a character from a Prolog input stream.
QP_fgetc()
: get a character from a Prolog input stream.
#QP_peekchar()
: look a character ahead from the Prolog current input
stream.
#QP_peekc()
: look a character ahead from a Prolog input stream.
QP_fpeekc()
: look a character ahead from a Prolog input stream.
QP_ungetc()
: unget the previous read character from a Prolog input
input stream.
#QP_skipline()
: skip the current input record of the Prolog current
input stream.
#QP_skipln()
: skip the current input record of a Prolog input stream.
QP_fskipln()
: skip the current input record of a Prolog input stream.
QP_fgets()
: get a string from a Prolog input stream.
QP_fread()
: read several items of data from a Prolog input stream.
#QP_putchar()
: put a character on the Prolog current output stream.
#QP_putc()
: put a character on a Prolog output stream.
QP_fputc()
: put a character on a Prolog output stream.
#QP_newline()
: terminates an output record for the Prolog current
output stream.
#QP_newln()
: terminates an output record for a Prolog output stream.
QP_fnewln()
: terminates an output record for a Prolog output stream.
QP_puts()
: put a character string on the Prolog current output stream.
QP_fputs()
: put a character string on a Prolog output stream.
QP_fwrite()
: write several items of data on a Prolog output stream.
QP_tab()
: put the specified character the number of times specified
on a Prolog output stream.
QP_tabto()
: put the specified character up to the specified line position
on a Prolog output stream.
QP_printf()
: print formatted output on the Prolog current output stream.
QP_fprintf()
: print formatted output on a Prolog output stream.
QP_vfprintf()
: print formatted output of a varargs argument list on
a Prolog output stream.
QP_flush()
: flush output on a Prolog output stream
QP_getpos()
: Get the current position for a Prolog stream.
QP_setpos()
: position a Prolog stream back to a previous read/written
position.
QP_rewind()
: reposition a Prolog stream back to the beginning
QP_seek()
: seek to a random position in a Prolog stream
#QP_char_count()
: obtain the character count for a Prolog stream.
#QP_line_count()
: obtain the line count for a Prolog stream.
#QP_line_position()
: obtain the line position for a Prolog stream.
#QP_eoln()
: test end of record condition for an input stream.
#QP_eof()
: test end of file condition for an input stream.
QP_setinput()
: set the Prolog current input stream.
QP_setoutput()
: set the Prolog current output stream.
QP_ferror()
: test error condition for a Prolog stream.
QP_clearerr()
: clear the previous error on a Prolog stream.
QP_errmsg()
: get the corresponding error message from a QP error
number.
QP_perror()
: print an error message based on a QP error number.
Finally, there are five global stream variables accessible in foreign code. These are streams, not file descriptors. It makes no sense to pass these to system calls that expect file descriptors. The values in these variables should not be changed by an assignment statement. These variables are:
QP_stream *QP_stdin
user_input
(or user
) in Prolog.
QP_stream *QP_stdout
user_output
(or user
) in Prolog.
QP_stream *QP_stderr
user_error
in Prolog.
QP_stream *QP_curin
QP_stream *QP_curout