The default values in the fields of QP_stream part
of the user-defined stream are set
through the QU_stream_param() function.
The declaration of QU_stream_param() is given as:
void QU_stream_param(filename, mode, format, option)
char *filename;
int mode;
int format;
QP_stream *option;
If the stream does not have a filename, the empty string "" should be used.
The parameter mode can be one of QP_READ, QP_WRITE or QP_APPEND.
The parameter format can be one of the format types listed in
fli-ios-sst-fmt.
The default version of QU_stream_param() source code is shipped with
Quintus Prolog (see cfu-ref-QU_stream_param also lists the source).
The fields in the QP_stream structure can then be modified based on
the desired features of the user-defined stream. All the fields
described in the Stream Structure section can be modified
(see fli-ios-sst),
but often the only modified fields are
max_reclen, seek_type and bottom layer function fields.
In our example, the format QP_VAR_LEN is chosen for non-tty
files, and the line_border field is reset so that
the middle layer functions do not alter any of the input/output records.
The fields max_reclen and seek_type are set to
the right values for our stream. The bottom layer function fields are
set based on the mode and the
seek_type of the stream. If the stream is opened for append,
the file pointer of the stream is moved to the end of file and
the magic field is updated (magic.byteno is used since it is
a UNIX file).
option = &stream->qpinfo;
QU_stream_param(filename, mode, QP_VAR_LEN, option);
option->max_reclen = Buffer_Size;
option->line_border = QP_NOLB;
if (isatty(fd)) {
option->format = QP_DELIM_TTY;
option->seek_type = QP_SEEK_ERROR;
} else {
option->seek_type = QP_SEEK_BYTE;
option->seek = bin_seek;
}
if (mode != QP_READ) {
option->write = bin_write;
option->flush = bin_write;
} else
option->read = bin_read;
if (option->mode == QP_APPEND &&
option->format != QP_DELIM_TTY) {
if ((option->magic.byteno=lseek(fd,0L,L_XTND)) < 0) {
(void) close(fd);
*error_num = errno;
return QP_NULL_STREAM;
}
}
option->close = bin_close;