Quintus Prolog Manual
m-1: Return Values and Errors
Quintus Prolog C functions return the following:
- integer
- one of
- QP_SUCCESS
- (0)
- QP_FAILURE
- (-1)
- QP_ERROR
- (-2)
- boolean
- true (1), false (0)
- pointer
- a pointer or null (0)
In some error situations, a global variable, QP_errno may also
be set to give more information about the error condition. Those I/O related
predicates which take a Prolog stream argument do not set the error code
in QP_errno. Instead, they set the errno field of the stream. There
are two QP_ functions provided to help diagnose error conditions
from error numbers:
- QP_perror(): prints out a user message, together with a short
error message describing the last error encountered that set QP_errno.
This function is similar to the UNIX function perror(3).
- QP_error_message(): returns a pointer to the diagnostic message
corresponding to a specified error number.
In addition, the error number is sometimes reported in the message field
of exception terms, as in
existence_error(Goal, _,_,_,errno(<error number>))
See {manual(REFPAGE-CONV)} for a description of the conventions observed
in the Reference Pages for Prolog predicates. 'C' function Reference Pages
differ primarily in the synopsis.
m-2: Topical List of C Functions
Following is a complete list of Quintus-supplied C functions. They fall
into two categories: built-in and user-redefinable. The user-redefinable
functions are used in embedding Prolog sub-programs (see {manual(i-2)}).
Quintus provides default definitions for these functions, and for most
purposes it is unneccessary to even know about them. However, it is possible
to redefine any of these to make Quintus Prolog programs behave appropriately
when embedded in C code. Changi these default definitions means replacing
them with your own code, not adding clauses. By convention these functions
are named to be recognizable as C functions, and as belonging to one or
the other of these categories: Regular C builtins are prefixed with QP_
and user-redefinable ones with QU_.
m-2-1: C Errors
A') mpg.c-chapter.html#mpg.c-builtinsC_Errors">') ')
- QP_perror() prints an error message based on a QP error number
- QP_error_message() gets the corresponding error message from
a QP error number
- QU_error_message() as QP_error_message(), but user-redefinable
m-2-2: Character I/O
A') mpg.c-chapter.html#mpg.c-builtinsCharacter_I/O">') ')
- QP_char_count() obtains the character count for a Prolog stream
- QP_fgetc() gets a character from a Prolog input stream
- QP_fgets() gets a string from a Prolog input stream
- QP_fpeekc() looks a character ahead from a Prolog input stream
- QP_fprintf() prints formatted output on a Prolog output stream
- QP_fputc() puts a character on a Prolog output stream
- QP_fputs() puts a character string on a Prolog output stream
- QP_fskipln() skips the current input record of a Prolog input
stream
- QP_getc() gets a character from a Prolog input stream
- QP_getchar() gets a character from the Prolog current input
stream
- QP_newln() terminates an output record for a Prolog output
stream
- QP_newline() terminates an output record for the Prolog current
output stream
- QP_peekc() looks a character ahead from a Prolog input stream
- QP_peekchar() looks a character ahead from the Prolog current
input stream
- QP_putc() puts a character on a Prolog output stream
- QP_putchar() puts a character on the Prolog current output
stream
- QP_puts() puts a character string on the Prolog current output
stream
- QP_skipline() skips the current input record of the Prolog
current input stream
- QP_skipln() skips the current input record of a Prolog input
stream
- QP_tab() puts the specified character the number of times
specified on a Prolog output stream
- QP_tabto() puts the specified character up to the specified
line position on a Prolog output stream
- QP_ungetc() "unget"s the previous read character
from a Prolog input input stream
m-2-3: Exceptions
A') mpg.c-chapter.html#mpg.c-builtinsExceptions">') ')
- QP_exception_term() fetches the Prolog term representing the
most recently raised exception
m-2-4: Files and Streams
A') mpg.c-chapter.html#mpg.c-builtinsFiles_and_Streams">') ')
- QP_add_tty() registers a created Prolog stream as a tty stream
group
- QP_clearerr() clears the previous error on a Prolog stream
- QP_close() closes a Prolog stream
- QP_eof() tests for the end of file on an input stream
- QP_eoln() tests for the end of record on an input stream
- QP_fclose() closes a Prolog stream
- QP_fdopen() creates a text stream or a binary stream from
UNIX file descriptor
- QP_ferror() tests error condition for a Prolog stream
- QP_flush() flushes output on a Prolog output stream
- QP_fnewln() terminates an output record for a Prolog output
stream
- QP_fopen() opens a text file or a binary file as a Prolog
stream
- QP_getpos() gets the current position for a Prolog stream
- QP_line_count() obtains the line count for a Prolog stream
- QP_line_position() obtains the line position for a Prolog
stream
- QP_prepare_stream() initializes internal fields of a QP_stream
structure
- QP_register_stream() registers a created Prolog stream
- QP_rewind() repositions a Prolog stream back to the beginning
- QP_seek() seeks to a random position in a Prolog stream
- QP_setinput() sets the Prolog current input stream
- QP_setoutput() sets the Prolog current output stream
- QP_setpos() positions a Prolog stream back to a previous read/written
position
- QU_fdopen() creates streams opened by QP_fdopen()
on UNIX platform.
- QU_initio() creates three Prolog initial streams
- QU_open() creates streams opened by open/[3,4]
- QU_stream_param() sets up default field values in a QP_stream
stream structure
m-2-5: Foreign Interface
A') mpg.c-chapter.html#mpg.c-builtinsForeign_Interface">') ')
- QP_atom_from_padded_string() returns the Prolog atom corresponding
to a blank-padded string; used with FORTRAN & Pascal
- QP_atom_from_string() returns the Prolog atom corresponding
to a null-terminated string
- QP_close_query() closes a Prolog query opened from C by QP_open_query()
- QP_cons_functor() creates a Prolog compound term from C
- QP_cons_list() creates a Prolog list from C
- QP_cut_query() terminates a nondeterminate Prolog query opened
from C
- QP_exception_term() returns the Prolog term to C corresponding
to the most recent Prolog error
- QP_get_arg() fetches a specified argument of a compound term
in a Prolog term reference
- QP_get_atom() fetches an atom from a Prolog term reference
- QP_get_float() fetches a floating point number from a Prolog
term reference
- QP_get_functor() fetches the name and arity of a term in a
Prolog term reference
- QP_get_head() fetches the head of a list in a Prolog term
reference
- QP_get_integer() fetches an integer in a Prolog term reference
- QP_get_list() fetches the head and tail of a list in a Prolog
term reference
- QP_get_tail() fetches the tail of a list in a Prolog term
reference
- QP_next_solution() gets the next solution, if any, to an open
Prolog query
- QP_open_query() opens a Prolog query from C
- QP_padded_string_from_atom() returns the blank-padded string
corresponding to a Prolog atom; used with FORTRAN & Pascal
- QP_pred() fetches an identifier for a Prolog predicate
- QP_predicate() fetches an identifier a Prolog predicate
- QP_put_atom() assigns an atom to a Prolog term reference
- QP_put_float() assigns a floating point number to a Prolog
term reference
- QP_put_functor() assigns a new compound term to a Prolog term
reference
- QP_put_integer() assigns a Prolog integer to a Prolog term
reference
- QP_put_list() assigns a new list to a Prolog term reference
- QP_put_term() assigns a Prolog term reference to another Prolog
term reference
- QP_put_variable() assigns a Prolog variable to a Prolog term
reference
- QP_query() makes a determinate query to a Prolog predicate
- QP_string_from_atom() returns a null-terminated string corresponding
to a Prolog atom atom
m-2-6: Input Services
A') mpg.c-chapter.html#mpg.c-builtinsInput_Services">') ')
- QP_add_input() registers a function to be called when input
occurs on a file descriptor
- QP_add_output() registers a function to be called when output
occurs on a file descriptor
- QP_add_exception() registers a function to be called when
an exception condition occurs on a file descriptor
- QP_add_timer() arranges for a function to be called after
a period of time
- QP_add_absolute_timer() arranges for a function to be called
at a given time
- QP_remove_input() removes any input callbacks registered on
a file descriptor
- QP_remove_output() removes any output callbacks registered
on a file descriptor
- QP_remove_exception() removes any exception callbacks registered
on a file descriptor
- QP_remove_timer() removes a timer callback
- QP_select() waits until I/O is ready on any of a set of file
descriptors, or a timeout period occurs
- QP_wait_input() waits until input is ready on a file descriptor
or a timeout period occurs
m-2-7: main()
A') mpg.c-chapter.html#mpg.c-builtinsmain__">') ") ')
- QP_initialize() initializes Prolog default
- QP_toplevel() in a development system, calls the Prolog 'read-prove'
loop; in a runtime system, calls runtime_entry/1.
m-2-8: Memory Management
A') mpg.c-chapter.html#mpg.c-builtinsMemory_Management">') ')
- QP_register_atom() prevents an atom from being discarded by
atom garbage collection even if not referenced by Prolog code
- QP_trimcore() asks Prolog to purge all memory not in use
- QP_unregister_atom() enables an atom to be discarded during
atom garbage collection if not referenced by Prolog code
- QU_alloc_init_mem() user-redefinable function to allocate
memory for Prolog
- QU_alloc_mem() user-redefinable function to allocate memory
for Prolog
- QU_free_mem() user-redefinable function to free memory from
Prolog
m-2-9: Signal Handling
A') mpg.c-chapter.html#mpg.c-builtinsSignal_Handling">') ')
- QP_action() requests certain kinds of Prolog action
m-2-10: Terms in C
A') mpg.c-chapter.html#mpg.c-builtinsTerms_in_C">') ')
- QP_compare() compares two terms using Prolog's standard term
order
- QP_new_term_ref() returns a reference which can be used to
hold a Prolog term in C
- QP_unify() unifies two Prolog terms
m-2-11: Term I/O
A') mpg.c-chapter.html#mpg.c-builtinsTerm_I/O">') ')
- QP_fread() reads several items of data from a Prolog input
stream
- QP_fwrite() writes several items of data on a Prolog output
stream
- QP_printf() prints formatted output on the Prolog current
output stream
- QP_vfprintf() prints formatted output of a varargs argument
list on a Prolog output stream
m-2-12: Type Tests
A') mpg.c-chapter.html#mpg.c-builtinsType_Tests">') ')
- QP_is_atom() tests whether a Prolog term reference contains
an atom
- QP_is_atomic() tests whether a Prolog term reference contains
an atomic term
- QP_is_compound() tests whether a Prolog term reference contains
a compound term
- QP_is_float() tests whether a Prolog term reference contains
a floating point number
- QP_is_integer() tests whether a Prolog term reference contains
a Prolog integer
- QP_is_list() tests whether a Prolog term reference contains
a list
- QP_is_number() tests whether a Prolog term reference contains
an integer or a floating point number
- QP_is_variable() tests whether a Prolog term reference contains
a Prolog variable
- QP_term_type() returns the type of the term in a Prolog term
reference
m-3: C Functions
m-3-0:
The following reference pages, alphabetically arranged, describe the
Quintus Prolog built-in C functions. For a functional grouping of these
functions including brief descriptions, see {manual(m-2)}. For information
about return values and errors, see {manual(m-1)}
QP_action()
- Synopsis:
- #include <quintus/quintus.h>
int QP_action(action)
int action;
- Called to request certain actions of Prolog.
- Arguments:
- action is one of:
QP_ABORT *Abort to the current break level
QP_REALLY_ABORT *Abort to top level
QP_STOP Stop (suspend) process
QP_IGNORE Do nothing
QP_EXIT Exit Prolog immediately
QP_MENU Present action menu
QP_TRACE Turn on trace mode
QP_DEBUG Turn on debugging
QP_ARITH *Print an arithmetic error and abort
(obsolete)
- Description:
- This function allows the user to make Prolog abort, exit, suspend execution,
turn on debugging, or prompt for the desired action.
- Calls to QP_action() from an interrupt handler must be viewed
as requests. They are requests that will definitely be honored,
but not always at the time of the call to QP_action(). If Prolog
is in a critical region the action might be delayed to when it has exitted
the critical region.
- Return Value:
- QP_ERROR, QP_SUCCESS
- Errors:
- For systems that do not have a toplevel, the actions marked with an
asterisk (*) will have no effect other than to make QP_action()
return QP_ERROR.
- Examples:
- For a full discussion of QP_action() and examples of its use,
see {manual(g-11-2)}
QP_add_*()
- Synopsis:
- #include <quintus/quintus.h>
int QP_add_input(id,fn,data,flush_fn, flush_data)
int id;
void (*fn)();
char *data;
void (*flush_fn)();
char *flush_data;
int QP_add_output(id,fn,data,flush_fn,flush_data)
int id;
void (*fn)();
char *data;
void (*flush_fn)();
char *flush_data;
int QP_add_exception(id,fn,data,flush_fn,flush_data)
int id;
void (*fn)();
char *data;
void (*flush_fn)();
char *flush_data;
int QP_add_timer(msecs,fn,data)
int msecs;
void (*fn)();
char *data;
int QP_add_absolute_timer(timeo,fn,data)
struct timeval *timeo;
void (*fn)();
char *data;
- These C functions register callback functions to be called on input/output
or timing events.
- Description:
- QP_add_input() arranges for a function to be called when input
becomes available on the file descriptor id. The callback function
fn is called with two arguments: the file descriptor id and
the specified call data data.
- Before the function is called, the callback is disabled so that the
function will not be inadvertently reentered while it is running. The callback
will be enabled automatically after the callback function returns.
- If the flush function flush_fn is not NULL then it
is called whenever Prolog needs to wait for input. This is useful when
you communicate with another process using bidirectional buffered connections,
where you must flush the output before you wait for input, lest your process
waits for a response to a message which is still buffered in your output
queue.
- QP_add_output() is like QP_add_input() except that
the callback function is called if output is ready on file descriptor id.
QP_add_exception() is like QP_add_input() except that
the callback function is called if an exception condition occurs on file
descriptor id.
- QP_add_timer() arranges for a function to be called in msecs
milliseconds time with two arguments: the actual time waited and the specified
call data data. This timer does not repeat automatically; if you
want a repeating timer, you should call QP_add_timer() within
the callback function explicitly.
- QP_add_absolute_timer() is like QP_add_timer() except
that an absolute time is specified by the timeval structure timeo.
This structure is described in the UNIX manual for gettimeofday(2).
- Return Values:
- QP_add_timer() and QP_add_absolute_time() return
a
- timerid if successful. Other functions return QP_SUCCESS.
- All functions return QP_ERROR if an error occurs.
- Tips:
- Often your code will maintain a buffer associated with an input connection.
If this is the case, then your flush function must check for this buffered
input, and as long as it finds some, it should repeatedly call your callback
function directly. If you don't do this, then your callback function may
not be called, even though you have pending input, since the operating
system isn't aware of your buffer.
- See Also:
- QP_wait_input(), QP_select(), QP_remove_*()
QP_add_tty()
- Synopsis:
- #include <quintus/quintus.h>
int QP_add_tty(stream, tty_id)
QP_stream *stream;
char *tty_id;
- Register a created Prolog stream to a tty stream group.
- Arguments:
- stream
- a pointer to a valid stream structure
- tty_id
- an identification string for a tty group
- Description:
- This function is used to register a stream to a tty group. All the
streams in a tty group share a single stream position (see the reference
pages for line_count/2, line_position/2 and character_count/2).
When input is requested on one of the streams and the shared line position
is 0, a prompt is output on one of the output streams.
- See Also:
- {manual(i-5-4)}
QP_atom_from_string(), QP_atom_from_padded_string()
- Synopsis:
- #include <quintus/quintus.h>
QP_atom QP_atom_from_string(string)
char *string;
- Returns the canonical representation of the atom whose printed representation
is the (null-terminated) string string.
int
QP_atom_from_padded_string(p_atom, p_string, p_length)
QP_atom *p_atom;
char *p_string;
int *p_length;
- Returns the canonical representation of the atom whose printed representation
is the (blank-padded) string p_string in a character array of length
p_length.
- Description:
- QP_atom_from_string() returns the canonical representation
of the atom whose printed representation is string. string
must be a valid null-terminated string. The string is copied and internalised
by Prolog and the foreign function can reuse the string and its space.
- QP_atom_from_padded_string() is useful for Pascal and FORTRAN
and can be used with any language that has a C-compatible calling convention
for passing integers and pointers (on the user's platform). e.g. some Pascal
and FORTRAN compilers running under UNIX. p_string is a pointer
to a character array and p_length is a pointer to an integer specifying
the length of the array. QP_atom_from_padded_string() sets the
atom referenced by p_atom to the canonical representation of the
atom whose printed representation is the string (less any trailing blanks)
in the character array. It returns the length of the resulting atom (not
the character array's length) as the function value.
- Examples:
- rev_atom() is a C function that takes an atom and returns an atom whose
string representation is the reverse of the string representation of the
atom passed in.
- IN THE PROLOG CODE:
foreign(rev_atom, c, rev_atom(+atom, [-atom])).
- IN THE C CODE:
- QP_atom rev_atom(atom) QP_atom atom; { char *string[MAX_ATOM_LEN];
strcpy(string, QP_string_from_atom(atom)); reverse(string); /* reverses
string in place */ return QP_atom_from_string(string); }
- Giving:
- | ?- rev_atom(draw, X). X = ward yes | ?-
- See Also:
- QP_string_from_atom(), QP_padded_string_from_atom()
- {manual(i-3-7)}
QP_char_count()
- Synopsis:
- #include <quintus/quintus.h>
int QP_char_count(stream)
QP_stream *stream;
- Obtains the current character count for the Prolog stream stream.
QP_char_count() is a macro.
- Arguments:
- stream
- a pointer to a valid Prolog stream structure
- See Also:
- QP_get_pos(), QP_line_count(), QP_line_position(),
character_count/2, QP_getpos(), QP_setpos(),
QP_seek(), stream_position/[2,3]
- {manual(i-5)}
QP_clearerr()
- Synopsis:
- #include <quintus/quintus.h>
void QP_clearerr(stream)
QP_stream *stream;
- Resets the error indication and EOF indication to zero on the named
stream.
- QP_clearerr() is similar to the UNIX C library function clearerr(3V),
however the return values differ and stream is a Prolog stream
rather than a stdio stream.
- Return Value:
- QP_SUCCESS
- If function succeeds
- QP_ERROR
- Otherwise
- See Also:
- {manual(i-5)}
QP_close_query()
- Synopsis:
- #include <quintus/quintus.h>
int QP_close_query(qid)
QP_qid qid;
- Equivalent to the Prolog call:
!, fail.
- Description:
- The cut renders the current computation determinate, removing the possibility
of future backtracking. The following call to fail/0 then initiates
backtracking to the first parent goal with outstanding alternatives. In
doing so it pops the Prolog heap to its state when the parent goal succeeded,
in effect throwing away any terms created since that parent goal.
- In the context of calling Prolog from foreign languages, terminating
a query using QP_close_query() generally means throwing away the
last solution that was calculated, unless that solution has been copied
into a more permanent place. (Of course, any previous solutions must also
be assumed to have been overwritten by subsequent solutions unless copied
elsewhere!) The converse of this behavior is that closing a query using
QP_close_query() automatically frees up the Prolog memory that
holds the last solution.
- Return Values:
- QP_SUCCESS
- Query was closed successfully
- QP_ERROR
- either the query could not be closed or an exception was signalled
from Prolog but not caught
- See Also:
- QP_cut_query(), QP_open_query(), QP_query(),
QP_next_solution(), QP_pred(), QP_predicate(),
{manual(i-4)}
QP_compare()
- Synopsis:
- #include <quintus/quintus.h>
int QP_compare(term1, term2)
QP_term_ref term1;
QP_term_ref term2;
- Compares the two terms referenced by term1 and term2.
Both arguments are term1 before term2
- Description:
- The comparison uses the standard total ordering of Prolog terms (also
used by the built-in Prolog predicate compare/3).
In Standard Order: Ret Value
term1 before term2 -1
term1 = term2 0
term1 after term2 1
- Examples:
- c_compare(term1, term2) is an equivalent C version of the Prolog builtin
compare/3:
- foreign(c_compare, c, c_compare(+term, +term, +term)). #include <quintus/quintus.h>
int c_compare(t1, t2, t3) QP_term_ref t1, t2; { int res; QP_term_ref l_than
= QP_new_term_ref(); QP_term_ref equal = QP_new_term_ref(); QP_term_ref
g_than = QP_new_term_ref(); QP_put_atom(l_than, QP_atom_from_string("<"));
QP_put_atom(equal, QP_atom_from_string("=")); QP_put_atom(g_than,
QP_atom_from_string(">")); res = QP_compare(t2, t3); if (
res < 0) { return QP_unify(t1, l_than); } else if (res == 0) { return
QP_unify(t1, equal); } else if (res > 0) { return QP_unify(t1, g_than);
} }
- See Also::
- QP_unify(), compare/3
QP_cons_*()
- Synopsis:
- #include <quintus/quintus.h>
void QP_cons_list(term, head, tail)
QP_term_ref term;
QP_term_ref head;
QP_term_ref tail;
void QP_cons_functor(term, name, arity,
arg1, ... ,arg_arity)
QP_term_ref term;
QP_atom name;
int arity;
QP_term_ref arg1, ... , arg_arity;
- Description:
- These are C functions that can be used to create new Prolog terms from
C.
- QP_cons_list() assigns to term a reference to a list
whose head is the term referred to by head and whose tail is the
term referred to by tail.
- QP_cons_functor() assigns to term a reference to a
compound term whose functor is the atom represented by name and
whose arity is the integer arity. The arguments of the compound
term are terms referred to by arg1, arg2, etc. The call to
this function should make sure that the number of arguments passed is equal
to the arity of the compound term. Note that the following are equivalent:
QP_cons_list(term, head, tail)
dot = QP_atom_from_string(".");
QP_cons_functor(term, dot, 2, head, tail)
However, the former is likely to be more efficient.
- Examples:
- float_to_chars() is a C function that converts a floating point number
to a list of characters. Note the use of QP_put_integer().
- foreign(flt_to_chars, flt_to_chars(+float, -term)). #include <quintus/quintus.h>
void flt_to_chars(flt, chars) float flt; QP_term_ref chars; { char buffer[28],
*p; int len; QP_term_ref term_char = QP_new_term_ref(); QP_put_nil(chars);
sprintf( buffer , "%.17e" , flt ); /* move to end of buffer */
for (p=buffer, len=0; *p; p++, len++); while ( len-- ) { QP_put_integer(term_char,
*--p); QP_cons_list(chars, term_char, chars); } }
- See Also::
- QP_term_type(), QP_get_*(), QP_new_term_ref()
QP_cut_query()
- Synopsis:
- #include <quintus/quintus.h>
int QP_cut_query(qid)
QP_qid qid;
- Equivalent to just calling "!" in Prolog.
- Description:
- The computation is rendered determinate, but as it is not failed over
the Prolog heap is not popped. Thus when terminating a query using QP_cut_query()
more space may be retained, but so is the last solution.
- Return Values:
- QP_SUCCESS
- QP_ERROR
- either something is wrong with the QP_qid or Prolog has not
been initialized
- See Also:
- QP_query(), QP_close_query(), QP_next_solution(),
QP_open_query(), QP_pred(), QP_predicate()
- {manual(i-4)}
QP_error_message()
- Synopsis:
- #include <quintus/quintus.h>
int QP_error_message(errno, is_qp_error, error_string)
int errno;
int *is_qp_error;
char **error_string;
- Arguments:
- errno
- the error number in question
- is_qp_error
- set to:
- 0
- if it is not an error number created by Quintus.
- 1
- if it is an error number created by Quintus.
- error_string
- the text of the error message.
- Description:
- This function supplies the text corresponding to the error number errno.
The output parameter is_qp_error can be used to determine if the
error number was one created by Quintus or is a UNIX error number.
- Typically, the error number of interest is the one in the global variable
QP_errno. This variable is discussed in the man pages for QP_perror().
- Return Value:
- QP_SUCCESS
- Examples:
- The following fragment takes the status value returned by some function
that returns C calling Prolog style status values and prints out the corresponding
error.
#include <quintus/quintus.h>
...
int is_qp_error;
char *error_message;
...
status = some_function();
switch(status) {
case QP_ERROR:
(void) QP_error_message(QP_errno, &is_qp_error,
&error_message);
if(is_qp_error)
(void) QP_fputs("prolog error: ", QP_stderr);
else (void) QP_fputs("UNIX error: ", QP_stderr);
(void) QP_fputs(error_message, QP_stderr);
(void) QP_fnewln(QP_stderr);
...
- See Also:
- QP_perror()
QP_exception_term()
- Synopsis:
- #include <quintus/quintus.h >
int QP_exception(term)
QP_term_ref term;
- A function that users can call when their call to Prolog signals an
error. If QP_query() returns QP_ERROR then users can call QP_exception_term()
to get at the exception term signalled.
- Description:
- If C calls Prolog and the Prolog goal raises an exception, QP_query()
(or QP_next_solution()) returns the value QP_ERROR. If
the user wants to get at the exception term that has been raised, they
can call the function QP_exception_term(). QP_exception_term()
takes a QP_term_ref as argument and returns a Prolog term.
- Example:
- IN THE PROLOG CODE:
:- extern(error).
error :- raise_exception(error_term(from_prolog)).
- IN THE C CODE:
QP_pred_ref pred;
if ((pred = QP_predicate("error",0,"user")) !=
(QP_pred_ref) QP_ERROR) {
if (QP_query(pred) == QP_ERROR) {
QP_term_ref err_term = QP_new_term_ref();
QP_exception_term(err_term);
}
}
- Once you get err_term, you can use functions such as the QP_get_*()
family to take apart the error term or to print it.
- See Also:
- QP_query(), QP_next_solution(), raise_exception/3
- {manual(g-19)}
QP_fclose()
- Synopsis:
- #include <quintus/quintus.h>
int QP_fclose(stream)
QP_stream *stream;
- Writes out any buffered data for the named stream, and closes the named
stream.
- QP_fclose() is similar to the UNIX C library function fclose(3S),
however the return values differ and stream is a Prolog stream
rather than a stdio stream.
- Return Value:
- QP_SUCCESS
- If function succeeds
- QP_ERROR
- Otherwise
- See Also:
- QP_fopen()
- {manual(i-5)}
QP_fdopen()
- Synopsis:
- #include <quintus/quintus.h>
QP_stream *QP_fdopen(fildes, type)
int fildes;
char *type;
- Associates a stream with the file descriptor files. File descriptors
are obtained from calls like the UNIX open(2V), dup(2), creat(2), or pipe(2),
which open files but do not return streams. Streams are necessary input
for many of the UNIX Section 3S library routines. The type of the stream
must agree with the mode of the open file.
- QP_fdopen() is similar to the UNIX C library function fdopen(3V),
however the return values differ and the normal return value is a Prolog
stream rather than a stdio stream.
- Return Value:
- QP_SUCCESS
- If function succeeds
- QP_ERROR
- Otherwise
- See Ablso:
- QP_fclose(), QP_fopen(), QP_prepare_stream/[3,4]
- {manual(i-5)}
QP_ferror()
- Synopsis:
- #include <quintus/quintus.h>
int QP_ferror(stream)
QP_stream *stream;
- Returns non-zero when an error has occurred reading from or writing
to the named stream, otherwise zero.
- QP_ferror() is similar to the UNIX C library function ferror(3V),
however the return values differ and stream is a Prolog stream
rather than a stdio stream.
- Return Value:
- QP_SUCCESS
- If function succeeds
- QP_ERROR
- Otherwise
- See Also:
- QP_fopen()
- {manual(i-5)}
QP_fgetc()
- Synopsis:
- #include <quintus/quintus.h>
int QP_fgetc(stream)
QP_stream *stream;
- Behaves like QP_getc(), but is a function rather than a macro.
- QP_fgetc() is similar to UNIX C library function fgetc(3V),
however the return values differ and stream is a Prolog stream
rather than a stdio stream.
- Return Value:
- QP_SUCCESS
- If function succeeds
- QP_ERROR
- Otherwise
- See Also:
- QP_ferror(), QP_fopen(), QP_fread(), QP_putc(),
QP_ungetc()
- {manual(i-5)}
QP_fgets()
- Synopsis:
- #include <quintus/quintus.h>
char *QP_fgets(s, n, stream)
char *s;
int n;
QP_stream *stream;
- Reads characters from the stream into the array pointed to by s, until
n-1 characters are read, a NEWLINE character is read and transferred to
s, or an EOF condition is encountered. The string is then terminated with
a NULL character.
- QP_fgets() is similar to the UNIX C library function fgets(3S),
however the return values differ and stream is a Prolog stream
rather than a stdio stream.
- Return Value:
- QP_SUCCESS
- If function succeeds
- QP_ERROR
- Otherwise
- See Also:
- {manual(i-5)}
QP_flush()
- Synopsis:
- #include <quintus/quintus.h>
int QP_flush(stream)
QP_stream *stream;
- Forces the buffered output of the stream stream to be sent to
the associated device.
- Arguments:
- stream
- pointer to a valid stream structure.
- Description:
- Calls the bottom layer flushing function of Stream to write
out the current buffered output of the stream. The output is usually written
out to a disk or a tty device.
- Return Value:
- QP_SUCCESS
- The function succeeds
- QP_ERROR
- There is an error in the function call, the error number is stored
in both QP_errno and stream-->errno.
- Errors:
- QP_E_PERMISSION stream is not an output stream or it
does not permit flushing.
- QP_E_CANT_WRITE Unknown error in the bottom layer of flush
function of stream
- Errors from host operating system
- See Also:
- flush_output/1.
QP_fnewln()
- Synopsis:
- #include <quintus/quintus.h>
int QP_fnewln(stream)
QP_stream *stream;
- Terminates an output record for a Prolog output stream.
- Arguments:
- stream
- pointer to a valid stream structure
- See Also:
- QP_newline(), QP_newln(), nl/[0,1]
- {manual(i-5)}
QP_fopen()
- Synopsis:
- #include <quintus/quintus.h>
QP_stream *QP_fopen(filename, type)
unsigned char *filename;
char *type;
- Opens the file named by filename and associates a stream with it.
- QP_fopen() is similar to the UNIX C library function fopen(3V),
however the return values differ and stream is a Prolog stream
rather than a stdio stream.
- Return Value:
- QP_SUCCESS
- If function succeeds
- QP_ERROR
- Otherwise
- See Also:
- QP_fopen(), QP_fdopen(), QP_prepare_stream/[3,4]
- {manual(i-5)}
QP_fpeekc()
- Synopsis:
- #include <quintus/quintus.h>
int QP_fpeekc(stream)
QP_stream *stream;
- Look ahead for the next character to be read in from a Prolog input
stream.
- Arguments:
- stream
- pointer to a valid stream structure
- Return Value:
- Character code or QP_ERROR.
- See Also:
- QP_peekc(), QP_peekchar(), peek_char/[1,2]
QP_fprintf()
- Synopsis:
- #include <quintus/quintus.h>
int QP_fprintf(stream, format [ , arg ]...)
QP_stream *stream;
char *format;
- Places output onto the Prolog output stream stream.
- QP_fprintf() is similar to the UNIX C library function fprintf(3V),
however the return values differ and stream is a Prolog stream
rather than a stdio stream.
- Return Value:
- QP_SUCCESS
- If function succeeds
- QP_ERROR
- Otherwise
- See Also:
- QP_printf(), QP_putc()
- {manual(i-5)}
QP_fputc()
- Synopsis:
- #include <quintus/quintus.h>
int QP_fputc(c, stream)
int c;
QP_stream *stream;
- Behaves like QP_putc(), but is a function rather than a macro.
- QP_fputc() is similar to the UNIX C library function fputc(3S),
however the return values differ and stream is a Prolog stream
rather than a stdio stream.
- Return Value:
- QP_SUCCESS
- If function succeeds
- QP_ERROR
- Otherwise
- See Also:
- QP_fclose(), QP_ferror(), QP_fopen(), QP_fread(),
QP_getc(), QP_printf(), QP_puts()
- {manual(i-5)}
QP_fputs()
- Synopsis:
- #include <quintus/quintus.h>
int QP_fputs(s, stream)
unsigned char *s;
QP_stream *stream;
- Writes the NULL-terminated string pointed to by s to the named
output stream.
- QP_fputs() is similar to the UNIX C library function fputs(3S),
however the return values differ and stream is a Prolog stream
rather than a stdio stream.
- Return Value:
- QP_SUCCESS
- If function succeeds
- QP_ERROR
- Otherwise
- See Also:
- QP_ferror(), QP_fopen(), QP_fread(), QP_printf(),
QP_putc()
- {manual(i-5)}
QP_fread()
- Synopsis:
- #include <quintus/quintus.h>
int QP_fread (ptr, size, nitems, stream)
char *ptr;
int size;
int nitems;
QP_stream *stream;
- Reads, into a block pointed to by ptr, nitems items of data from the
named input stream stream, where an item of data is a sequence of bytes
(not necessarily terminated by a NULL byte) of length size.
- QP_fread() is similar to the UNIX C library function fread(3S),
however the return values differ slightly and stream is a Prolog
stream rather than a stdio stream.
- Return Value:
- If the function succeeds it returns the number of items
- read.
- QP_ERROR
- Otherwise
- See Also:
- QP_fopen(), QP_getc(), QP_gets(), QP_putc(),
QP_puts(), QP_printf()
- {manual(i-5)}
QP_fskipln()
- Synopsis:
- #include <quintus/quintus.h>
int QP_fskipln(stream)
QP_stream *stream;
- Skip the current input record of a Prolog input stream
- Return Value:
- QP_SUCCESS, or QP_ERROR
- Errors:
- When QP_ERROR is returned, QP_errno contains an error
code.
- See Also:
- skip_line/[0,1]
- {manual(i-5)}
QP_fwrite()
- Synopsis:
- #include <quintus/quintus.h>
int QP_fwrite(ptr, size, nitems, stream)
char *ptr;
int size;
int nitems;
QP_stream *stream;
- Writes at most nitems items of data from the block pointed to
by ptr to the named Prolog output stream. QP_fwrite() stops
writing when it has written nitems of date or if an error condition
is encountered on stream.
- QP_fwrite() is similar to the UNIX C library function fwrite().
- Return Value:
- If the function succeeds it returns the number of items
- written.
- QP_ERROR
- Otherwise
- See Also:
- QP_fopen(), QP_getc(), QP_gets(), QP_putc(),
QP_puts(), QP_printf()
- {manual(i-5)}
QP_get_*( )
- Synopsis:
- #include <quintus/quintus.h>
int QP_get_atom(term, atom)
QP_term_ref term;
QP_atom *atom;
int QP_get_integer(term, integer)
QP_term_ref term;
long int *integer;
int QP_get_float(term, float)
QP_term_ref term;
double *float;
int QP_get_functor(term, name, arity)
QP_term_ref term;
QP_atom *name;
int *arity;
int QP_get_arg(argnum, term, arg)
int argnum;
QP_term_ref term;
QP_term_ref arg;
int QP_get_list(term, head, tail)
QP_term_ref term;
QP_term_ref head;
QP_term_ref tail;
int QP_get_head(term, head)
QP_term_ref term;
QP_term_ref head;
int QP_get_tail(term, tail)
QP_term_ref term;
QP_term_ref tail;
int QP_get_nil(term)
QP_term_ref term;
int QP_get_db_reference(term, ref)
QP_term_ref term;
QP_db_reference *ref;
- These C functions can be used to test and access Prolog terms passed
to C through the foreign interface.
- Description:
- If term refers to an atom then QP_get_atom() assigns
to *atom the unsigned integer representing that atom and returns
1. Else QP_get_atom() returns 0. To get at the string corresponding
to the atom, use QP_string_from_atom().
- If term refers to a Prolog integer then QP_get_integer()
assigns that integer to *integer and returns 1. Else QP_get_integer()
returns 0.
- If term refers to a floating point number then QP_get_float()
assigns that number to *float and returns 1. Else QP_get_float()
returns 0.
- If term refers to a compound term then QP_get_functor()
assigns to *name the unsigned integer representing the name of the
functor, assigns to *arity the arity of the functor and returns
1. If term refers to an atom, then QP_get_functor() assigns
to *name that atom, assigns 0 to *arity and returns 1. If
term does not refer to a compound term or an atom then QP_get_functor()
returns 0. Note that a list is a compound term with functor '.' and arity
2.
- If term refers to a compound term and argnum is between
1 and the arity of the compound term then QP_get_arg() assigns
to arg a reference to the argnum argument of the compound
term and returns 1. If term does not refer to a compound term QP_get_arg()
returns 0. Note that QP_get_arg() is similar to the Prolog builtin
arg/3 with its first and second arguments bound and its third
argument unbound. QP_get_arg() differs from the other QP_get
functions in that it does not have term as its first argument. This
is to make it consistent with arg/3.
- If term refers to a list then QP_get_list() assigns
to head a reference to the head of that list, assigns to tail
a reference to the tail of the list and returns 1. If term does
not refer to a list then QP_get_list() returns 0.
- If term refers to a list then QP_get_head() assigns
to head a reference to the head of that list and returns 1. If term
does not refer to a list then QP_get_head() returns 0.
- If term refers to a list then QP_get_tail() assigns
to tail a reference to the tail of that list and returns 1. If term
does not refer to a list then QP_get_tail() returns 0.
- If term refers to the atom '[]' then QP_get_nil() returns
1. Else it returns 0.
- If term refers to a database reference (e.g. returned by asserta/3
or recorda/3) then QP_get_db_reference() assigns to *ref
that reference and returns 1. If term does not refer to a database
reference then QP_get_db_reference() returns 0.
- Examples:
- write_term() is a C function that writes out a Prolog term passed to
it.
- IN THE PROLOG CODE:
foreign(write_term, c, write_term(+term)).
- IN THE C CODE:
#include <quintus/quintus.h>
void write_term(term)
QP_term_ref term;
{
QP_atom a;
long int i;
double d;
switch (QP_term_type(term)) {
case QP_VARIABLE:
QP_printf("_");
break;
case QP_INTEGER:
QP_get_integer(term, &i);
QP_printf("%d", i);
break;
case QP_FLOAT:
QP_get_float(term, &d);
QP_printf("%f", d);
break;
case QP_ATOM:
QP_get_atom(term, &a);
QP_printf("%s", QP_string_from_atom(a));
break;
case QP_DB_REFERENCE:
QP_printf("'$ref'()");
break;
case QP_COMPOUND:
if (QP_is_list(term)) {
write_list(term);
} else {
write_compound(term);
}
break;
}
}
void write_list(term)
QP_term_ref term;
{
QP_term_ref head = QP_new_term_ref();
QP_term_ref tail = QP_new_term_ref();
QP_atom a;
QP_printf("[");
QP_get_list(term, head, tail);
write_term(head);
while (QP_is_list(tail)) {
QP_printf(",");
QP_get_list(tail, head, tail);
write_term(head);
}
if (QP_get_nil(tail)) {
QP_printf("]");
} else {
QP_printf("|");
write_term(tail);
QP_printf("]");
}
}
void write_compound(term)
QP_term_ref term;
{
int i, arity;
QP_atom name;
QP_term_ref arg = QP_new_term_ref();
QP_get_functor(term, &name, &arity);
QP_printf("%s(", QP_string_from_atom(name));
for (i = 1; i < arity; i++) {
QP_get_arg(i, term, arg);
write_term(arg);
QP_printf(",");
}
QP_get_arg(i, term, arg);
write_term(arg);
QP_printf(")");
}
- See Also:
- QP_term_type(), QP_put_*(), QP_new_term_ref()
QP_getchar()
- Synopsis:
- #include <quintus/quintus.h>
int QP_getchar()
- Defined as QP_getc(QP_curin).
- QP_getchar() is similar to the UNIX C library function getchar(3V),
however it operates on the Prolog current input stream rather than the
UNIX standard input stream stdin. Like getchar(3V), QP_getchar()
is a macro.
- Return Value:
- QP_SUCCESS
- If function succeeds
- QP_ERROR
- Otherwise
- See Also:
- QP_ferror(), QP_fopen(), QP_fread(), QP_gets(),
QP_putc(), QP_ungetc()
- {manual(i-5)}
QP_getpos()
- Synopsis:
- #include <quintus/quintus.h>
int QP_getpos(stream, pos)
QP_stream *stream;
QP_position *pos;
- Get the current position for a Prolog stream
- Arguments:
- stream
- pointer to a valid stream structure
- pos
- pointer to a QP_position structure
- Description:
- Upon successful return of this function call, the char_count, line_count,
line_position and magic member of the QP_position structure pointed to
by pos have the valid values indicating the current character count,
line count, line position and system-dependent position. The pos
can be passed as the second argument to QP_setpos() for seeking
back to the current position later.
- Return Value:
- Always returns QP_SUCCESS.
- See Also:
- QP_setpos(), QP_seek(), stream_position/[2,3],
QP_char_count(), QP_line_count(), QP_line_position()
- {manual(i-5)}
QP_initialize()
- Synopsis:
- #include <quintus/quintus.h>
int QP_initialize(argc, argv)
int argc;
char **argv;
- Initializes Prolog's memory management, I/O, symbol table, etc.
- Arguments:
- argc
- number of command line arguments (or 0)
- argv
- list of command line arguments (or NULL)
- Description:
- You can ignore QP_initialize() if you aren't redefining main().
- Must be called before any other QP_ functions if you are redefining
main() (in which case your top-level view of Prolog is via QP_predicate()
and QP_query()).
- Summary of functionality: Initializes memory, I/O; sets up command
line arguments; initializes file search paths, file tables and symbol tables;
do initializations and start up hooks associated with a statically linked
component in qof files; do any necessary restores, and any initlization
and start up hooks associated with the restored files.
- QP_initialize() also sets up signal handlers so that users
can interrupt the execution of a start-up goal or initialization with a
Control-c. If users chose the 'a' option after a Control-c (or if the builtin
abort/0 is called) when initializations are run, then QP_initialize()
returns. In a default system, (where main() hasnt been redefined) this
means that QP_toplevel() gets called. QP_toplevel() executes
the toplevel read-prove loop in a development system. In a runtime system,
it results in runtime_entry(start) being called.
- argc and argv are necessary for Prolog to execute the builtin unix/1
(e.g. unix(argv()) etc) properly, as well as for restoring saved states.
- Can be safely called any number of times.
NOTE: The first call to QP_initialize() with non-null arguments
will determine the command line arguments as seen by Prolog.
- Return Value:
- QP_SUCCESS
- Prolog was successfully initialized.
- QP_FAILURE
- otherwise
- Examples:
- In Quintus Prolog the default implementation of main() looks like this:
#include <quintus/quintus.h>
main(argc, argv)
int argc;
char **argv;
{
int status;
status = QP_initialize(argc, argv);
if (status == QP_SUCCESS) QP_toplevel();
}
The user can choose not to have the default main() and the default
toplevel loop. Here is an example of how the user can call a Prolog predicate
with their own main(). IN PROLOG CODE: File hello.pl defining hi/1
:- extern(hi(+atom)).
hi(X) :-
format('Hello world from ~a to Prolog~n',[X]).
IN C CODE: File main.c defining main()
#include <quintus/quintus.h>
main(argc, argv)
int argc;
char **argv;
{
int status;
QP_pred_ref pred;
status = QP_initialize(argc, argv);
if (status == QP_SUCCESS) {
pred = QP_predicate("hi", 1, "user");
if (pred != QP_BAD_PREDREF) {
status = QP_query(pred,
QP_atom_from_string("C"));
if (status == QP_FAILURE) {
printf("hi/1 failed\n");
exit(1);
} else if (status == QP_ERROR) {
printf("hi/1 raised exception\n");
/* Use QP_exception_term to get
the error term signaled */
exit(1);
}
} else {
printf("hi/1 doesn't exist or ");
printf("doesn't have an extern ");
printf("declaration\n");
exit(1);
}
} else {
printf("QP_initialize didn't succeed\n");
exit(1);
}
}
AT THE COMMAND LEVEL: Steps to produce the executable
- Compile hello.pl using qpc -c hello.pl
- Compile main.c using cc -c main.c
- Link the two using qld -Dd hello.qof main.o -o qtest
- Run qtest. The output should be: Hello from C to Prolog
See Also::
runtime_entry/1, unix/1, QP_predicate(),
QP_query(), QP_toplevel()
{manual(i-2)}
QP_is_*( )
- Synopsis:
- #include <quintus/quintus.h>
int QP_is_variable(term)
QP_term_ref term;
int QP_is_atom(term)
QP_term_ref term;
int QP_is_integer(term)
QP_term_ref term;
int QP_is_float(term)
QP_term_ref term;
int QP_is_compound(term)
QP_term_ref term;
int QP_is_list(term)
QP_term_ref term;
int QP_is_db_reference(term)
QP_term_ref term;
int QP_is_atomic(term)
QP_term_ref term;
int QP_is_number(term)
QP_term_ref term;
- These C functions and macros can be used to test the type of the Prolog
terms passed to C through the foreign interface.
- Description:
- QP_is_variable()
- (macro) returns a nonzero value if its argument is a Prolog variable;
zero otherwise.
- QP_is_atom()
- (macro) returns a nonzero value if its argument is an atom; zero otherwise.
- QP_is_integer()
- (macro) returns a nonzero value if its argument is a Prolog integer;
zero otherwise.
- QP_is_float()
- (macro) returns a nonzero value if its argument is a float; zero otherwise.
- QP_is_compound()
- (macro) returns a nonzero value if its argument is a compound Prolog
term; zero otherwise.
- QP_is_list()
- (function) returns a nonzero value if its argument is a Prolog list;
zero otherwise.
- QP_is_db_reference()
- (macro) returns a nonzero value if its argument is a database reference;
zero otherwise.
- QP_is_atomic()
- (function) returns a nonzero value if its argument is an atomic Prolog
object; zero otherwise.
- QP_is_number()
- (function) returns a nonzero value if its argument is a Prolog integer
or float; zero otherwise.
- Examples:
- print_type() is a C function that prints the type of the Prolog term
passed to it.
- IN THE PROLOG CODE:
foreign(print_type, c, print_type(+term)).
- IN THE C CODE:
- #include <quintus/quintus.h> void print_type(term) QP_term_ref
term; { if (QP_is_atom(term)) { QP_printf("Term is an atom\n");
} else if (QP_is_integer(term)) { QP_printf("Term is an integer\n");
} else if (QP_is_float(term)) { QP_printf("Term is a float\n");
} else if (QP_is_variable(term)) { QP_printf("Term is a variable\n");
} else if (QP_is_db_reference(term)) { QP_printf("Term is a database
reference\n"); } else if (QP_is_compound(term)) { if (QP_is_list(term))
{ QP_printf("Term is a list\n"); } else { QP_printf("Term
is a compound term\n"); } } else { QP_printf("Unrecognized term\n");
} }
- See Also:
- QP_get_*(), QP_put_*(), QP_new_term_ref()
QP_line_count()
- Synopsis:
- #include <quintus/quintus.h>
int QP_line_count(stream)
QP_stream *stream;
- Obtains the line count for a Prolog stream. QP_line_count()
is a macro.
- Arguments:
- stream
- pointer to a valid stream structure
- See Also:
- QP_getpos(), QP_setpos(), QP_seek(), stream_position/[2,3]
QP_char_count(), QP_line_position()
- {manual(i-5)}
QP_line_position()
- Synopsis:
- #include <quintus/quintus.h>
int QP_line_position(stream)
QP_stream *stream;
- Obtains the line position for a Prolog stream. QP_line_position()
is a macro.
- Arguments:
- stream
- pointer to a valid stream structure
- See Also:
- QP_getpos(), QP_setpos(), QP_seek(), stream_position/[2,3]
QP_char_count(), QP_line_count(),
- {manual(i-5)}
QP_new_term_ref()
- Synopsis:
- #include <quintus/quintus.h>
QP_term_ref QP_new_term_ref()
- Description:
- QP_new_term_ref() returns an initialized QP_term_ref.
Every QP_term_ref declared has to be initialized with a call to
this function. A QP_term_ref can be considered as a reference
to a Prolog term. Calling this function initialises that reference to a
location where terms can be stored. The actual term that the reference
points to is initialized to '[]'.
- Example:
- create_term() is a simple C function that returns different types of
Prolog terms depending on its first argument.
- foreign(create_term, create_term(+integer,[-term])) #include <quintus/quintus.h>
QP_term_ref create_term(kind); int kind; { QP_term_ref new = QP_new_term_ref();
switch (kind) { case 1: QP_put_integer(new, 23); break; case 2: QP_put_atom(new,
QP_atom_from_string("Ayn")); break; case 3: QP_put_float(new,
1.1); break; default: QP_put_nil(new); break; } return new; }
- See Also::
- QP_put_*(), QP_term_type(), QP_get_*()
QP_newline()
- Synopsis:
- #include <quintus/quintus.h>
int QP_newline()
- Terminates the current output record for the Prolog current output
stream. QP_newline() is a macro.
- Arguments:
- stream
- pointer to a valid stream structure
- Description:
- Calling QP_newline() is equivalent to call QP_newln(QP_stdout).
- Return Value:
- a line border character or QP_ERROR
- See Also:
- QP_newln(), QP_error_message(), nl/[0,1]
- {manual(i-5)}
QP_newln()
- Synopsis:
- #include <quintus/quintus.h>
int QP_newln(stream)
QP_stream *stream;
- Terminates the current output record for a specified Prolog output
stream. QP_newln() is a macro.
- Arguments:
- stream
- pointer to a valid stream structure
- Return Value:
- a line border character or QP_ERROR
- See Also:
- QP_newline(), QP_error_message(), nl/[0,1]
- {manual(i-5)}
QP_next_solution()
- Synopsis:
- #include <quintus/quintus.h>
int QP_next_solution(qid)
QP_qid qid;
- Returns the next solution (if any) from an open nondeterminate Prolog
query.
- Description:
- Solutions are computed on demand, and multiple solutions are returned
in the normal Prolog order. QP_next_solution() is passed the QP_qid
returned by QP_open_query() when the nondeterminate query was
opened. No additional input or output parameters are passed: after a call
to QP_open_query(), Prolog manages inputs itself, and has been
told where storage for outputs has been reserved.
- Each time QP_next_solution() computes a new solution it writes
it on the output storage for the foreign function to use as it likes. Each
new solution overwrites the old memory, destroying the previous solution,
so it is important that the foreign function copies solutions elsewhere
if it wants to accumulate them.
- Comment:
- An important restriction: only the innermost, i.e. the most recent,
open query can be asked to compute a solution. A new nondeterminate query
can be made at any point whether or not other queries are open; however,
while the new query remains open only it will be able to return solutions.
Of course, determinate queries can be made at any time.
- Return Values:
- QP_SUCCESS
- Solution found
- QP_FAILURE
- No solution found
- QP_ERROR
- See Also:
- QP_cut_query(), QP_close_query(), QP_query(),
QP_open_query(), QP_pred(), QP_predicate(),
- {manual(i-4)}
QP_open_query()
- Synopsis:
- #include <quintus/quintus.h>
QP_qid QP_open_query(pred_ref, arg1,...,arg255)
QP_pred_ref pred_ref;
- Initiates a nondeterminate Prolog query.
- Description:
- The first argument passed to QP_query() is a reference to
the Prolog predicate to be called. QP_query() accepts between
0 and 255 arguments after its first argument. Any arguments after the first
represent parameters to be passed to and from the Prolog predicate. For
the types of arguments that may be passed between C and Prolog predicates,
see {manual(i-4)}.
- The arguments passed to QP_open_query() are identical to those
that would be passed to QP_query(); however, QP_open_query()
does not compute a solution to the query. Its effect is to prepare Prolog
for the computation of solutions to the query, which must be initiated
using QP_next_solution(). For consistency checking, QP_open_query()
returns a QP_qid, which represents the Prolog query. The type
definition for QP_qid is found in the file #include <quintus/quintus.h>.
- The QP_qid returned by a call to QP_open_query()
must be passed to each call to QP_next_solution() for that query,
as well as to QP_cut_query() or QP_close_query() when
terminating the query.
- When requesting solutions from an open non-determinate query, input
and output parameters are NOT passed. The effect of QP_open_query()
is to pass inputs to Prolog, which subsequently maintains them. It also
tells Prolog where storage for outputs has been reserved. This storage
will be written to when solutions are returned.
- Return Value:
- QP_qid
- query was opened successfully
- QP_ERROR
- an error occurred when attempting to open the query and the query was
automatically terminated
- See Also:
- QP_cut_query(), QP_close_query(), QP_query(),
QP_next_solution(), QP_pred(), QP_predicate(),
- {manual(i-4)}
QP_peekc()
- Synopsis:
- #include <quintus/quintus.h>
int QP_peekc(stream)
QP_stream *stream;
- Look a character ahead from a specified Prolog input stream. QP_peekc()
is a macro.
- Arguments:
- stream
- pointer to a valid stream structure
- Return Value:
- Character code or QP_ERROR.
- See Also:
- QP_peekchar(), QP_fpeekc(), peek_char/[1,2]
- {manual(i-5)}
QP_peekchar()
- Synopsis:
- #include <quintus/quintus.h>
int QP_peekchar()
- Look a character ahead from the Prolog current input stream. QP_peekchar()
is a macro.
- Description:
- QP_peekchar() is equvalent to QP_peekc(QP_stdin).
- Return Values:
- Character code or QP_ERROR.
- See Also:
- QP_peekc(), QP_fpeekc(), peek_char/[2,3]
- {manual(i-5)}
QP_perror()
- Synopsis:
- #include <quintus/quintus.h>
void QP_perror(s)
char *s;
- Description:
- QP_perror() produces a short error message on the stream user_error
describing the last error encountered. If s is not a NULL pointer
and does not point to a null string, the string it points to is printed,
followed by a colon, followed by a space, followed by the message and a
NEWLINE. If s is a NULL pointer or points to a null string, just
the message is printed, followed by a NEWLINE. To be of most use, the argument
string should include the name of the program that incurred the error.
The error number is taken from the external variable QP_errno (see
{manual(m-1)}), which is set when errors occur but not cleared when non-erroneous
calls are made.
- This function is modeled on the UNIX function perror(3).
- See Also:
- QP_error_message()
QP_pred()
- Synopsis:
- #include <quintus/quintus.h>
QP_pred_ref QP_pred(name_atom, arity, module_atom)
QP_atom name_atom;
int arity;
QP_atom module_atom;
- Looks up a callable Prolog predicate.
- QP_pred() is faster, but less convenient, than QP_predicate()
- Description:
- Differences from QP_predicate():
- Name and module arguments passed as Prolog atoms. These may have been
returned to C from Prolog, or may have been built in the foreign language
using QP_atom_from_string().
- The name passed is NOT the name of the Prolog predicate to be called,
but rather the name of the interface predicate constructed when the Prolog
predicate was made callable from foreign code (see {manual(i-4-2)}).
- Much of the cost of QP_predicate() is from having to look
up Prolog atoms for its name and module arguments. By avoiding doing this
unnecessarily, what QP_pred() gives up in convenience is returned
in performance.
- Return Value:
- QP_pred_ref
- a valid predicate reference
- QP_ERROR
- if the predicate called hasn't been declared callable or doesn't exist
- See Also:
- QP_predicate(), QP_query(), QP_open_query(),
QP_next_solution(), QP_cut_query(), QP_close_query(),
{manual(i-4)}
QP_predicate()
- Synopsis:
- #include <quintus/quintus.h>
QP_pred_ref QP_predicate(name_string, arity,
module_string)
char *name_string;
int arity;
char *module_string;
- Description:
- Before a Prolog predicate can be called from a foreign language it
must be looked up. The C functions QP_predicate() and QP_pred()
perform this function. The lookup step could have been folded into the
functions that make the query, but if a predicate was to be called many
times the redundant, if hidden, predicate lookup would be a source of unnecessary
overhead. Instead, QP_predicate() or QP_pred() can be
called just once per predicate. The result can then be stored in a variable
and used as necessary.
- Both QP_predicate() and QP_pred() return a QP_pred_ref(),
which represents a Prolog predicate.
- QP_predicate() is the most convenient way of looking up a
callable Prolog predicate. It is simply passed the name and module of the
predicate to be called as strings, the arity as an integer, and returns
a QP_pred_ref() which is used to make the actual call to Prolog.
- QP_predicate() can only be used to look up predicates that
have been declared callable from foreign code. If some other predicate,
or a predicate that does not exist, is looked up, QP_ERROR is
returned. This protects you from attempting to call a predicate that isn't
yet ready to be called.
- Return Value:
- QP_pred_ref
- a valid predicate reference
- QP_ERROR
- if the predicate called hasn't been declared callable or doesn't exist
- See Also:
- QP_pred(), QP_query(), QP_open_query(),
QP_next_solution(), QP_cut_query(), QP_close_query()
- {manual(i-4)}
QP_prepare_stream()
- Synopsis:
- #include <quintus/quintus.h>
void QP_prepare_stream(stream, buffer)
QP_stream *stream;
unsigned char *buffer;
- Initialize internal fields of a QP_stream structure.
- Arguments:
- stream
- pointer to a valid stream structure
- buffer
- pointer to a buffer
- Description:
- QP_prepare_stream() should be called after other fields in
QP_stream are properly set up.
- The first parameter is a pointer to QP_stream and the second
parameter is the address of the input/output buffer for the stream. Here
&stream->qpinfo is used to get the corresponding QP_stream
pointer from stream although a casting operation of QP_stream
*stream will have the same effect.
- Example:
- QP_prepare_stream(&stream->qpinfo, stream->buffer);
- See Also:
- QP_fdopen(), QP_fopen(), open/[3,4],
- {manual(i-5-5-6)}
QP_printf()
- Synopsis:
- #include <quintus/quintus.h>
int QP_printf(format [ , arg ] ... )
char *format;
- Places output onto the current Prolog output stream.
- QP_printf() is similar to the UNIX C library function printf(3V),
however the return values differ it puts its output on the current Prolog
output stream (QP_curout) rather than a stdio stream.
- Return Value:
- If the function succeeds it returns the number characters
- written.
- QP_ERROR
- Otherwise
- See Also:
- QP_putc()
- {manual(i-5)}
QP_put_*()
- Synopsis:
- These C functions can be used to create new Prolog terms from C.
- #include <quintus/quintus.h>
void QP_put_variable(term)
QP_term_ref term;
void QP_put_atom(term, atom)
QP_term_ref term;
QP_atom atom;
void QP_put_integer(term, integer)
QP_term_ref term;
long int integer;
void QP_put_float(term, float)
QP_term_ref term;
double float;
void QP_put_functor(term, name, arity)
QP_term_ref term;
QP_atom name;
int arity;
void QP_put_list(term)
QP_term_ref term;
void QP_put_nil(term)
QP_term_ref term;
void QP_put_term(term1, term2)
QP_term_ref term1;
QP_term_ref term2;
void QP_put_db_reference(term, ref)
QP_term_ref term1;
QP_db_reference ref;
- Description:
- QP_put_variable() assigns to term a reference to a
- new unbound Prolog variable.
- QP_put_atom() assigns to term a reference to the
- atom represented by atom. atom is assumed to be the canonical
representation of a Prolog atom, either obtained from Prolog or returned
by QP_atom_from_string().
- QP_put_integer() assigns to term a reference to
- integer tagged as a Prolog term.
- QP_put_float() assigns to term a reference to the
- floating point number float tagged as a Prolog term.
- QP_put_functor() assigns to term a reference to a
- new compound term whose functor is the atom represented by name
and whose arity is arity. All the args of the compound term are
unbound. This is similar to the Prolog builtin functor/3 with
its first argument unbound and its second and third argument bound.
- QP_put_list() assigns to term a reference to a new
- list whose head and tail are both unbound.
- QP_put_nil() assigns to term a reference to the
- atom '[]'.
- QP_put_term() assigns to term1 a reference to the
- term that term2 references. Any reference to another term that
term1 contained is lost.
- QP_put_db_reference() assigns to term a reference
- to the Prolog database reference represented by ref. ref
must have been a reference obtained through QP_get_db_reference().
Any reference to another term that term1 contained is lost.
- Examples:
- flt_to_chars() is a C function that converts a floating point number
to a list of characters. Note the use of QP_put_integer().
- IN THE PROLOG CODE:
- foreign(flt_to_chars, flt_to_chars(+float, -term)).
- IN THE C CODE:
- #include <quintus/quintus.h> void flt_to_chars(flt, chars) float
flt; QP_term_ref chars; { char buffer[28], *p; int len; QP_term_ref term_char
= QP_new_term_ref(); QP_put_nil(chars); sprintf( buffer , "%.17e"
, flt ); /* move to end of buffer */ for (p=buffer, len=0; *p; p++, len++);
while ( len-- ) { QP_put_integer(term_char, *--p); QP_cons_list(chars,
term_char, chars); } }
- See Also:
- QP_term_type(), QP_get_*(), QP_new_term_ref()
QP_puts()
- Synopsis:
- #include <quintus/quintus.h>
int QP_puts(s)
unsigned char *s;
- Writes the NULL-terminated string pointed to by s, followed
by a NEWLINE character, to the Prolog current output stream QP_curout.
- QP_puts() is similar to the UNIX C library function puts(3S),
however it operates on the Prolog current output stream rather than the
UNIX standard output stream stdout.
- Return Value:
- QP_SUCCESS
- If function succeeds
- QP_ERROR
- Otherwise
- See Also:
- QP_ferror(), QP_fopen(), QP_fread(), QP_printf(),
QP_putc()
- {manual(i-5)}
QP_query()
- Synopsis:
- #include <quintus/quintus.h>
int QP_query(pred_ref, arg1,...,arg255)
QP_pred_ref pred_ref;
- Make a determinate query in a single C function call.
- Description:
- The first argument passed to QP_query() is a reference to
the Prolog predicate to be called. QP_query() accepts between
0 and 255 arguments after its first argument. Any arguments after the first
represent parameters to be passed to and from the Prolog predicate. For
the types of arguments that may be passed between C and Prolog predicates,
see {manual(i-4)}.
- The foreign language interface will interpret arguments passed to the
Prolog predicate according to the call specification given when the predicate
was made callable. Hence, it is important that the arguments to be passed
to and from the Prolog predicate should correspond with that call specification.
In certain cases (passing Prolog atoms in canonical form) it is possible
to detect inconsistencies between data supplied to QP_query()
and the call specification, but for the most part this is impossible. Calls
that are inconsistent with their call specifications will produce undefined
results.
- Only when the return value is QP_SUCCESS are the values in
variables passed as outputs from Prolog valid. Otherwise, their contents
are undefined.
- Return Value:
- QP_SUCCESS
- query was made and a solution to the query was computed
- QP_FAILURE
- query was made but no solution could be found
- QP_ERROR
- either the query could not be made, or that an exception was signaled
from Prolog but not caught.
- See Also:
- QP_cut_query(), QP_close_query(), QP_next_solution(),
QP_open_query(), QP_pred(), QP_predicate(),
{manual(i-4)}
QP_register_atom(), QP_unregister_atom()
- Synopsis:
- #include <quintus/quintus.h>
int QP_register_atom(atom)
QP_atom atom;
int QP_unregister_atom(atom)
QP_atom atom;
- Description:
- garbage_collect_atoms/0 is able to locate all atoms accessible
from Prolog code, but cannot trace atoms that are only accessible from
foreign code.
- QP_register_atom() registers an atom as referenced from foreign
code so that if garbage_collect_atoms/0 is called, the atom will
not be reclaimed. QP_unregister_atom() unregisters the atom, so
that if no other code (Prolog or foreign) refers to it, then it is a candidate
for atom garbage collection.
- These functions use a reference counting mechanism to keep track of
atoms that have been registered. As a result, it is safe to combine different
libraries that register and unregister atoms multiple times; the atoms
will not be reclaimed until everyone has unregistered them.
- Return Value:
- the current reference count of the atom or QP_ERROR if an
error occurs.
- Tips:
- Atoms do not normally need to be registered when calling foreign code.
The only situation where this is needed is when the atom is being stored
in a global or static data structure before returning to Prolog code, to
be accessed subsequently by later calls to the foreign code.
- See Also:
- garbage_collect_atoms/0
QP_register_stream()
- Synopsis:
- #include <quintus/quintus.h>
long QP_register_stream(stream)
QP_stream *stream;
- Register a created Prolog stream.
- Arguments:
- stream
- pointer to a valid stream structure
- Description:
- A customized Prolog stream must be registered via a call to QP_register_stream()
before it can be accessed in Prolog code.
- See Also:
- stream_code/2
- {manual(i-5-5-6)}
QP_remove_*()
- Synopsis:
- #include <quintus/quintus.h>
int QP_remove_input(id)
int id;
int QP_remove_output(id)
int id;
int QP_remove_exception(id)
int id;
int QP_remove_timer(timerid)
int timerid;
- These C functions remove registered input/output or timing callback
functions.
- Description:
- QP_remove_input() removes any input callback functions registrations
for the file descriptor id. Similarly, QP_remove_output()
and QP_remove_exception() remove output and exception callbacks
respectively.
- QP_remove_timer() removes timer callback identified by timerid
which is the value returned by QP_add_timer() or QP_add_absolute_timer().
- Return Values:
- QP_SUCCESS if the callback is removed
- QP_ERROR otherwise
- See Also:
- QP_add_*(), QP_select(), QP_wait_input()
QP_rewind()
- Synopsis:
- #include <quintus/quintus.h>
int QP_rewind(stream)
QP_stream *stream;
- QP_rewind() is similar to the UNIX C library function rewind(3S),
however the return values differ and stream is a Prolog stream
rather than a stdio stream.
- Return Value:
- QP_SUCCESS
- If function succeeds
- QP_ERROR
- Otherwise
- See Also:
- QP_fopen(), QP_ungetc()
- {manual(i-5)}
QP_seek()
- Synopsis:
- #include <quintus/quintus.h>
int QP_seek(stream, offset, whence)
QP_stream *stream;
long int offset;
int whence;
- Seeks to an arbitrary byte position on the stream.
- Arguments:
- stream
- pointer to a valid stream structure.
- offset
- the offset in bytes to seek relative to whence specified.
- whence
- specifies where to start seeking. It is one of the following.
- QP_BEGINNING
- seek from beginning of the file stream. The new position of the file
stream is set to offset bytes.
- QP_CURRENT
- seek from current position of the file stream. The new position of
the file stream is set to its current location plus offset.
- QP_END
- seek from end of the file stream. The new position of the file stream
is set to the size of the file plus offset.
- Description:
- The new position in bytes from the beginning of the file stream is
stored in magic field of stream. It is stream-->magic.byteno
on UNIX.
- If stream is an output stream permitting flushing output, the
characters in the buffer of the stream is flushed through QP_flush()
before seek is performed. If the stream does not permit flushing
output and there are characters remaining in the output buffer, it is an
error to seek. If stream is an input stream, the characters in the
input buffer of the stream are discarded before seek is performed. The
input buffer is empty when QP_seek() returns.
- Return Value:
- QP_SUCCESS
- The function succeeds
- QP_ERROR
- There is an error in function call, the error number is stored in both
QP_errno and stream-->errno.
- Errors:
- QP_E_INVAL whence is not one of QP_BEGINNING,
QP_CURRENT, or QP_END.
- QP_E_CANT_SEEK Unknown error in the bottom layer of seek function
of stream
- Errors from QP_flush()
- Errors from host operating system
- Tips:
- QP_seek(stream, 0L, QP_CURRENT) sets the current position
to the magic field of stream. It does not change the position of
stream, but the side effect of flushing output and clearing buffer
also takes place.
- Comments:
- The seek type in stream must permits seeking by bytes, i.e.
the seek_type field in stream is QP_SEEK_BYTE. So stream
is created by defining a private stream and setting seek_type field to
QP_SEEK_BYTE, opening a Prolog stream with seek(byte) option in
open/4, or opening a binary stream through QP_fopen()
or QP_fdopen() on UNIX.
- Examples:
- Get the current byte offset from beginning of the file stream.
if (QP_seek(stream, 0L, QP_CURRENT) != QP_SUCCESS)
QP_perror(stream-->errno, "QP_seek");
else
location = stream-->magic.byteno;
- See Also:
- QP_getpos(), QP_setpos(), QP_rewind(), QP_flush().
- {manual(i-5)}
QP_select()
- Synopsis:
- #include <quintus/quintus.h>
int QP_select(wid,read_fds,write_fds,except_fds,timeo)
int wid;
fd_set *read_fds;
fd_set *write_fds;
fd_set *except_fds;
struct timeval *timeo;
- Wait until I/O is ready on a file descriptor or until a timeout occurs
- Description:
- This is a more general version of QP_wait_input(), which is
compatible with the UNIX system call select(2). It waits for any of read_fds
to be ready for reading, or write_fds to be ready for writing, or
except_fds to have an exceptional command pending, or for the timeout
period timeo to elapse, whichever comes first. See the UNIX manual
page for further details on select(2). Callbacks on other descriptors are
handled while waiting. However, no callbacks on any of the desciptors specified
in read_fds, write_fds, and except_fds are called,
rather QP_select() returns immediately.
- Return Values:
- the number of descriptors in the bit mask, QP_SUCCESS if a
timeout occurred or QP_ERROR if an error occurred.
- See Also:
- QP_wait_input(), QP_add_*()
QP_setinput()
- Synopsis:
- #include <quintus/quintus.h>
QP_stream *QP_setinput(stream)
QP_stream *stream;
- Set the Prolog current input stream to a specified value stream.
- Arguments:
- stream
- pointer to a valid input stream
- Description:
- This function sets an input stream stream to be the current
Prolog input stream and returns the previous current Prolog input stream.
- See Also:
- set_input/1, QP_setoutput()
- {manual(i-5)}
QP_setoutput()
- Synopsis:
- #include <quintus/quintus.h>
QP_stream *QP_setoutput(stream)
QP_stream *stream;
- Set the Prolog current output stream to a specified value stream.
- Arguments:
- stream
- pointer to a valid Prolog output stream
- Description:
- This function sets the current Prolog outpout stream to stream
and returns the previous current Prolog output stream before the operation.
- See Also:
- set_ouptut/1, QP_setinput()
- {manual(i-5)}
QP_setpos()
- Synopsis:
- #include <quintus/quintus.h>
int QP_setpos(stream, pos)
QP_stream *stream;
QP_position *pos;
- Reset a specified Prolog stream back to a previous read/written position.
- Arguments:
- stream
- pointer to a valid stream structure
- pos
- pointer to a QP_position structure.
- The stream count is set the system-dependent file position to be reposition
char_count, line_count, line_position and magic member of the QP_position
structure pointed by pos have the valid values indicating the current
character count, line count, line position and system-dependent position.
- Description:
- Upon successful return of this function call, the stream is
repositioned to the value specified in the magic member pointed to by pos.
The character, line and line position counts of stream are also
reset to the values specified in char_count, line_count and line_position
members in pos.
- The specified stream must have the permission to seek back to
a previous read/written position. Typically, the value of pos is
obtained through a previous QP_getpos() call.
- See Also:
- QP_getpos(), QP_seek(), stream_position/[2,3]
QP_char_count(), QP_line_count(), QP_line_position()
- {manual(i-5)}
QP_skipline()
- Synopsis:
- #include <quintus/quintus.h>
int QP_skipline()
- Skip the current input record of the current Prolog input stream. QP_skipline()
is a macro.
- Description:
- QP_skipline() is equivalent to QP_skipln(QP_curin).
- See Also:
- QP_skipln()
- {manual(i-5)}
QP_skipln()
- Synopsis:
- #include <quintus/quintus.h>
int QP_skipln(stream)
QP_stream *stream;
- Skip the current input record of a Prolog input stream. QP_skipln()
is a macro.
- Arguments:
- stream
- pointer to a valid Prolog input stream
- See Also:
- QP_skipline(), QP_fskipln()
- {manual(i-5)}
QP_string_from_atom(), QP_padded_string_from_atom()
- Synopsis:
char *QP_string_from_atom(atom)
QP_atom atom;
int
QP_padded_string_from_atom(p_atom, p_string, p_length)
QP_atom *p_atom;
char *p_string;
int *p_length;
- Description:
- QP_string_from_atom() returns a pointer to a string representing
atom. This string should not be overwritten by the foreign function.
- QP_padded_string_from_atom() is useful for and and can be
used for any language that has a C-compatible calling convention for passing
integers and pointers (on the users platform). This is true for for many
Pascal and FORTRAN compilers running under UNIX.
- p_atom and p_length can be seen as integers passed by
reference. Fills in the character array of length length with the
string representation of atom. The string is truncated or blank-padded
to length. The length of the atom (not length) is returned
as the function value. In the above description atom refers to the
argument passed by reference corresponding to the declared argument p_atom
and similarly for p_string and p_length.
- Examples:
- rev_atom() is a C function that takes an atom and returns an atom whose
string representation is the reverse of the string representation of the
atom passed in.
foreign(rev_atom, c, rev_atom(+atom, [-atom])).
QP_atom rev_atom(atom)
QP_atom atom;
{
char * string[MAX_ATOM_LEN];
strcpy(string, QP_string_from_atom(atom));
reverse(string); /* reverses string in place */
return QP_atom_from_string(string);
}
| ?- rev_atom(draw, X).
X = ward
yes
| ?-
- See Also:
- QP_atom_from_string(), QP_atom_from_padded_string()
- {manual(i-3-7)}
QP_tab()
- Synopsis:
- #include <quintus/quintus.h>
int QP_tab(stream, count, c)
QP_stream *stream;
int count;
int c;
- Output count number of the character c on Prolog output
stream stream.
- Arguments:
- stream
- pointer to a valid Prolog output stream
- count
- how many characters of c to be output
- c
- character to be written out
- Examples:
- QP_tab(QP_curout, 5, ' ') puts 5 blank characters to the current
output stream.
- See Also:
- QP_tabto()
QP_tabto()
- Synopsis:
- #include <quintus/quintus.h>
int QP_tabto(stream, line_pos, c)
QP_stream *stream;
int line_pos;
int c;
- Pad the character c up to the specified line position line_pos
on Prolog output stream stream.
- Arguments:
- stream
- pointer to a valid Prolog output stream
- line_pos
- line position to be padded to.
- c
- character used for padding
- See Also:
- QP_tab()
QP_term_type()
- Synopsis:
- #include <quintus/quintus.h>
int QP_term_type(term)
QP_term_ref term;
- Tests the type of Prolog terms in C.
- Description:
- QP_term_type() returns the type of a Prolog term which is
passed to it as argument. The returned value is one of the following constants
defined in the file #include <quintus/quintus.h>: QP_VARIABLE,
QP_INTEGER, QP_ATOM, QP_FLOAT or QP_COMPOUND.
- Examples:
- print_type() is a C function that prints the type of the Prolog term
passed to it.
- IN THE PROLOG CODE:
foreign(print_type, c, print_type(+term)).
- In The C Code:
- #include <quintus/quintus.h> void print_type(term) QP_term_ref
term; { switch (QP_term_type(term)) { case QP_VARIABLE: QP_printf("Term
is a variable\n"); break; case QP_INTEGER: QP_printf("Term is
an integer\n"); break; case QP_FLOAT: QP_printf("Term is a float\n");
break; case QP_ATOM: QP_printf("Term is an atom\n"); break; case
QP_COMPOUND: if (QP_is_list(term)) { QP_printf("Term is a list\n");
} else { QP_printf("Term is a compound term\n"); } break; } }
- See Also:
- QP_is_*(), QP_get_*(), QP_put_*(), QP_new_term_ref()
QP_toplevel()
- Synopsis:
- #include <quintus/quintus.h>
int QP_toplevel()
- Description:
- Invokes Prolog's default top level read-prove loop.
- For runtime systems, QP_toplevel() immediately transfers control
to the definition of the Prolog predicate runtime_entry/1.
- QP_toplevel() takes no arguments. QP_query() and
related predicates should be used for calling specific Prolog predicates.
- One of the effects of calling this function is that the default signal
handling for Prolog is enabled. Upon return, the old signal handlers are
restored.
- The built-in predicate break/0 calls this function. Nested
calls to this function are equivalent to calling the Prolog predicate break/0.
- This function returns when an end-of-file character is read.
- Return Value:
- QP_SUCCESS QP_FAILURE QP_ERROR.
- See Also:
- QP_initialize(), break/0.
QP_trimcore()
- Synopsis:
int QP_trimcore()
- QP_trimcore() is the C equivalent of Prolog's trimcore/0.
- Description:
- trimcore/0 is usually called by Prolog when you return to
top level after each query. But if you have an embedded application without
Prolog's top level or a runtime system then you can call QP_trimcore()
explicitly to ask Prolog to consolidate all its free memory and free as
much as possible back to the operating system.
- Like trimcore/0 it should be used judiciously, as overuse
can result in unnecessary time being spent in memory expansion and contraction.
However, it can be used when Prolog is to be dormant for a period, or as
much free memory as possible is desired.
- See Also:
- trimcore/0
- {manual(i-2)}
QP_ungetc()
- Synopsis:
- #include <quintus/quintus.h>
int QP_ungetc(c, stream)
int c;
QP_stream *stream;
- Pushes the character c back onto Prolog input stream stream.
- QP_ungetc() is similar to the UNIX C library function ungetc(3S),
however the return values differ and stream is a Prolog stream
rather than a stdio stream.
- Return Value:
- QP_SUCCESS
- If function succeeds
- QP_ERROR
- Otherwise
- See Also:
- QP_fseek(), QP_getc()
- {manual(i-5)}
QP_unify()
- Synopsis:
- #include <quintus/quintus.h>
int QP_unify(term1, term2)
QP_term_ref term1;
QP_term_ref term2;
- Unify two Prolog terms.
- Description:
- QP_unify() unifies the two terms referenced by term1
and term2. Both should be initialized references. If the unification
succeeds, the function returns QP_SUCCESS, otherwise it returns
QP_FAILURE. If the unification results in any bindings then the
bindings are trailed. If Prolog backtracks over the foreign function that
called QP_unify() then the bindings are undone.
- Examples:
- c_unify(term1, term2) is equivalent to the usual Prolog builtin =/2,
but it returns a third argument which is an integer indicating success
or failure.
- IN THE PROLOG CODE:
- foreign(c_unify, c, c_unify(+term, +term, [-integer]))
- IN THE C CODE:
- #include <quintus/quintus.h> int c_unify(t1, t2); QP_term_ref
t1, t2; { return QP_unify(t1, t2); }
- See Also:
- =/2
QP_vfprintf()
- Synopsis:
- #include <quintus/quintus.h>
int QP_vfprintf(stream, format, ap)
QP_stream *stream;
char *format;
va_list ap;
- Places output onto the Prolog output stream stream.
- QP_vfprintf() is also similar to the UNIX C library function
vfprintf(3V), however the return values differ and stream is a
Prolog stream rather than a stdio stream. It also resembles QP_fprintf()
except that rather than being called with a variable number of arguments,
it is called with an argument list as defined by varargs(3).
- Return Value:
- QP_SUCCESS
- If function succeeds
- QP_ERROR
- Otherwise
- See Also:
- QP_printf(), QP_fprintf()
- {manual(i-5)}
QP_wait_input()
- Synopsis:
- #include <quintus/quintus.h>
int QP_wait_input(id,timeout)
int id;
int *timeout;
- Wait until I/O is ready on a file descriptor or until a timeout occurs
- Description:
- QP_wait_input() waits until input is ready on file descriptor
id or until timeout milliseconds pass. If timeout is QP_NO_TIMEOUT,
it waits indefinitely for input to arrive on id. While waiting,
QP_wait_input() makes sure that registered callbacks are called
when input is ready on other file descriptors. However, no callback will
be called when input is ready on id even if one is registered, rather
QP_wait_input() returns immediately.
- Return Values:
- QP_SUCCESS
- if input arrived on id
- QP_FAILURE
- if a timeout occurred
- QP_ERROR
- if an error occurs
- See Also:
- QP_select(), QP_add_*()
QU_alloc_mem(), QU_alloc_init_mem(), QU_free_mem()
- Synopsis:
char *QU_alloc_mem(size, alignment, actualsize)
unsigned long size;
unsigned long alignment;
unsigned long *actualsize;
- The primitive function that Prolog calls to get memory
char *QU_alloc_init_mem(size, alignment, actualsize)
unsigned long size;
unsigned long alignment;
unsigned long *actualsize;
Called when Prolog needs memory for the first time
int QU_free_mem(mem, size)
char *mem;
unsigned long size;
The primitive function called when Prolog wants to free memory.
- Description:
- These are the primitive functions on which the all of Prolog's sophisticated
memory management is built. If Prolog is to be embedded into an application
which would like to provide its own memory management routines then the
user can redefine these functions and link it with the Prolog system.
- QU_alloc_mem() must allocate a piece of memory that has at
least size bytes aligned at alignment in it and return a
pointer to it. The memory returned itself need not be aligned at alignment.
The alignment argument is guaranteed to be a power of 2. The actual
size of the piece of memory returned should be stored in *actualsize.
Prolog uses all the memory given to it; there is no memory wasted when
actualsize is greater than size. QU_alloc_mem()
should return 0 if it cannot allocate any more memory.
- QU_alloc_init_mem() is a special case of QU_alloc_mem().
It can do whatever initialization that this layer of memory management
wants to do.
- QU_free_mem() is called with a pointer to the memory that
is to be freed and the size of the memory to be freed. If QU_free_mem()
was not able to free this piece of memory then this function should return
0. In this case Prolog will continue using the memory as if it was not
freed.
- The default definitions for these functions look at the environment
variables PROLOGINITSIZE, PROLOGINCSIZE, PROLOGKEEPSIZE and PROLOGMAXSIZE.
These environment variables are useful to customize the default memory
manager. If users redefine this layer of memory management they can choose
to ignore these environment variables.
- Examples:
- Here is a simple example of the embeddable layer of memory management
based on malloc(3) and free(3). This example is far from ideal because
you might be over-allocating memory to ensure the required size of aligned
memory, but demonstrates the capability. The C file mem.c defines QU_alloc_mem(),
QU_alloc_init_mem() and QU_free_mem().
- IN THE C CODE: mem.c:
- unsigned long IncSize = 0x100000; /* 1M */ unsigned long InitSize =
0x100000; /* 1M */ unsigned long MaxSize = 0x1000000; /* 16 M */ unsigned
long KeepSize = 0x100000; /* 1M */ unsigned long MemTotal; char * QU_alloc_mem(size,
align, actualsize) unsigned long size; /* in bytes */ unsigned long align;
/* power of 2 */ unsigned long *actualsize; { char *mem, *malloc(); size
= size + align; if (size <= IncSize) size = IncSize; if ((size + MemTotal)
> MaxSize) return 0; mem = malloc(size); *actualsize = size; MemTotal
+= (mem == 0 ? 0 : size); return mem; } char * QU_alloc_init_mem(size,
align, actualsize) unsigned long size; /* in bytes */ unsigned long align;
/* power of 2 */ unsigned long *actualsize; { char *mem, *str, *malloc(),
*getenv(); str = getenv("PROLOGINCSIZE"); if (str) sscanf(str,
"%u", &IncSize); str = getenv("PROLOGINITSIZE");
if (str) sscanf(str, "%u", &InitSize); str = getenv("PROLOGMAXSIZE");
if (str) sscanf(str, "%u", &MaxSize); str = getenv("PROLOGKEEPSIZE");
if (str) sscanf(str, "%u", &KeepSize); MemTotal = 0; return
QU_alloc_mem(size, align, actualsize); } int QU_free_mem(mem, size) char
* mem; unsigned long size; { if ((MemTotal - size) < KeepSize) return
0; free(size); MemTotal = MemTotal - size; return 1; }
- AT THE COMMAND LEVEL: To build an Prolog development system based on
the functions defined in mem.c:
1. cc -c mem.c
2. qld -D mem.o -o prolog_on_my_mm_fns
- See Also:
- {manual(i-2)}
QU_fdopen() user-redefinable
- Synopsis:
QP_stream *QU_fdopen(stream_option, system_option,
error_number, file_des)
QP_stream *stream_option;
char *system_option;
int *error_number;
int file_des;
- The embedding function for creating a stream opened through open/[3,4]
or QP_fopen(). Creates a stream and returns the QP_stream
pointer for that stream.
- Description:
- QU_fdopen() is similar to QU_open() except that the
file stream is already opened and the opened UNIX file descriptor is passed
through the parameter file_des.
- Examples:
- See the example in the manual page for QU_open().
- See Also:
- QU_open(), {manual(i-5)}
QU_free_mem() user-redefinable
- Described in reference page for QU_alloc_mem().
QU_initio() user-redefinable
- Synopsis:
- #include <quintus/quintus.h>
int QU_initio(user_input, user_output, user_error,
act_astty, error_num)
QP_stream **user_input;
QP_stream **user_output;
QP_stream **user_error;
int act_astty;
int *error_num;
- Initializes Prolog input/output system. Returns QP_SUCCESS
upon success and QP_ERROR upon failure.
- Description:
- The three Prolog initial stream are created in QU_initio().
The Prolog standard input stream is returned through user_input,
the standard output stream is returned through user_output, and
the standard error stream is returned through user_error. The created
streams are accessed in the Prolog system as user_input (QP_stdin), user_output
(QP_stdout), and user_error (QP_stderr).
- If act_astty is non-zero, the Prolog system requests QU_initio()
to initialize the three initial streams as tty streams even if they are
not really connected to a tty. One example of such a request is that Prolog
is running under remote shell.
- The parameter error_num stores the error code if QU_initio()
returns QP_ERROR. The error code can be any of the host operating
system error numbers, QP error numbers or a user-defined error number.
- Tip:
- The process required to create these three initial streams is similar
to that of implementing a customized Prolog stream. (see {manual(i-5-5)}).
However, these three initial streams should not be registered. Calling
QP_register_stream() to register any of the three streams created
by QU_initio() may cause an error when Prolog starts up.
- Examples:
- The following is the source code for an implementation of QU_initio()
function in C language.
#include <sys/types.h>
#include <sys/stat.h>
#include "quintus.h"
#define TTY_BUFSIZ 128
#define MAX_FIFO_BUFSIZ 4096
extern QP_stream *QU_fdopen();
/*
* This I/O initialization function only handles three possible
* types of file, a tty file , a pipe and an ordinary file
*/
int QU_initio(user_input, user_output, user_error, act_astty,
error_num)
QP_stream **user_input, **user_output, **user_error;
int act_astty, *error_num;
{
int fd, is_tty;
struct stat statbuf;
QP_stream option, *streams[3], *prompt_stream;
extern char *ttyname();
for (fd=2; fd >= 0 ; --fd) {
is_tty = isatty(fd);
QU_stream_param((is_tty) ? "/dev/tty" : "",
(fd) ? QP_WRITE : QP_READ, &option);
if (is_tty || act_astty) {
/* make sure other parameters are right */
option.format = QP_DELIM_TTY;
option.max_reclen = TTY_BUFSIZ;
option.seek_type = QP_SEEK_ERROR;
if (fd == 0)
option.peof_act = QP_PASTEOF_RESET;
} else {
if (fstat(fd, &statbuf) < 0)
return QP_ERROR;
if ((statbuf.st_mode & S_IFIFO) == S_IFIFO) {
option.max_reclen = MAX_FIFO_BUFSIZ;
option.seek_type = QP_SEEK_ERROR;
} else
option.max_reclen = statbuf.st_blksize;
}
option.mode = (fd) ? QP_WRITE : QP_READ;
if ((streams[fd]=QU_fdopen(&option,"",error_num,fd))
==QP_NULL_STREAM)
return QP_ERROR;
if (is_tty) {
char *tty_id;
if (! (tty_id = ttyname(fd)) )
tty_id = "/PROLOG DEFAULT TTYS";
(void) QP_add_tty(streams[fd], tty_id);
} else if (act_astty)
(void) QP_add_tty(streams[fd],
"/PROLOG INITAIL STREAMS");
}
(streams[0])->filename="USER$INPUT";
*user_input = streams[0];
(streams[1])->filename="USER$OUTPUT";
*user_output = streams[1];
(streams[2])->filename="USER$ERROR";
*user_error = streams[2];
if ((streams[0])->format == QP_DELIM_TTY
&& (streams[1])->format != QP_DELIM_TTY
&& (streams[2])->format != QP_DELIM_TTY) {
char *tty_id;
/* create an output stream for prompt */
QU_stream_param(isatty(0) ? "/dev/tty" : "", QP_WRITE,
&option);
option.format = QP_DELIM_TTY;
option.max_reclen = TTY_BUFSIZ;
option.seek_type = QP_SEEK_ERROR;
if ((prompt_stream = QU_fdopen(&option, "", error_num,
0)) == QP_NULL_STREAM)
return QP_ERROR;
(void) QP_register_stream(prompt_stream);
if (! (tty_id = ttyname(0)) )
tty_id = "/PROLOG DEFAULT TTYS";
(void) QP_add_tty(prompt_stream, tty_id);
}
return QP_SUCCESS;
}
QU_open() user-redefinable
- Synopsis:
- #include <quintus/quintus.h>
QP_stream *QU_open(stream_option, system_option,
error_number)
QP_stream *stream_option;
char *system_option;
int *error_number;
- The embedding function for creating a stream opened through open/[3,4]
or QP_fopen().
- Creates a stream and returns the QP_stream pointer for that stream.
- Description:
- stream_option specifies the options for the stream to be created.
- system_option specifies the system-dependent stream option specified
in the option of system(<option>) in open/4. If there is
no system-dependent option, the system_option field is the empty
string, "".
- The functionality of QU_open() is illustrated in these steps
open/4 uses to create a Prolog stream:
- Set up the default stream options through QU_stream_param().
- Changes the stream options obtained in the previous step based on the
options specified in open/4.
- Calls QU_open() with the stream options resulted in the previous
two steps to create the stream.
- Register the stream created by QU_open() through QP_register_stream().
- Converts the stream pointer returned by QU_open() to the Prolog
representation of the stream through stream_code/2.
- The process required to implement QU_open() is similar to
implementing a customized Prolog stream. (see {manual(i-5-5)}). There are
only a few differences.
- The stream options are specified as a parameter in a call to QU_open(),
so QU_open() does not need to call QU_stream_param().
- QU_open() may need to parse system_option string to
recognize the option specified in that string. Notice that the core Prolog
system itself does not make use of any information specified in system_option.
It simply takes the string specified in open/4 and passes it to
QU_open() without any alteration.
- QU_open() does not need to register the stream it creates.
The caller of QU_open() will register it.
- Implementation of QU_fdopen() is similar to QU_open()
except that the file stream is already opened and the opened UNIX file
descriptor is passed through the parameter file_des.
- Return Value:
- If any error occurs during the creation of the stream, QP_NULL_STREAM
is returned and the error code for the error condition is set in the third
parameter, error_number. The error code could be any of the host
operating system error numbers, QP error numbers or a user-defined error
number. QU_fdopen() is only defined for the Prolog system running
under UNIX operating system. It requires an addition parameter, file_des,
which is the opened file descriptor for the stream to be created.
- Examples:
- The following is the source code for an implementation of QU_open()
function and QU_fdopen() function in C.
#include <fcntl.h>
#include <errno.h>
#include <sys/file.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifndef L_SET
#define L_SET 0
#endif
#ifndef L_INCR
#define L_INCR 1
#endif
#ifndef L_XTND
#define L_XTND 2
#endif
#include "quintus.h"
extern char *ttyname();
QP_stream *
QU_fdopen(option, sys_option, error_num, file_des)
QP_stream *option;
char *sys_option;
int *error_num, file_des;
{
QP_stream *stream;
extern long lseek();
extern QP_stream *QU_tty_open(), *QU_text_open(),
*QU_raw_open();
if (sys_option && *sys_option != '\0') {
*error_num = QP_E_SYS_OPTION;
return QP_NULL_STREAM;
}
*error_num = 0;
if (option->format == QP_FMT_UNKNOWN) {
if (option->line_border==QP_NOLB &&
option->trim==0)
option->format = QP_VAR_LEN;
/* binary file */
else
option->format = QP_DELIM_LF;
}
switch (option->mode) {
case QP_READ:
case QP_WRITE:
option->magic.byteno = 0;
if (option->seek_type != QP_SEEK_ERROR) {
struct stat statbuf;
if (fstat(file_des, &statbuf) == 0 &&
(statbuf.st_mode & S_IFMT) == S_IFREG)
if ((option->magic.byteno =
lseek(file_des,0L,L_INCR))==-1) {
*error_num = errno;
return QP_NULL_STREAM;
}
}
break;
case QP_APPEND:
if ((option->magic.byteno =
lseek(file_des,0L,L_XTND)) == -1)
{
*error_num = errno;
return QP_NULL_STREAM;
}
break;
default:
*error_num = QP_E_BAD_MODE;
return QP_NULL_STREAM;
}
switch (option->format) {
case QP_DELIM_TTY:
stream = QU_tty_open(option, error_num,
file_des);
break;
case QP_DELIM_LF:
stream = QU_text_open(option, error_num,
file_des);
break;
case QP_VAR_LEN:
stream = QU_raw_open(option, error_num,
file_des);
break;
default:
*error_num = QP_E_BAD_FORMAT;
return QP_NULL_STREAM;
}
return stream;
}
QP_stream *
QU_open(option, sys_option, error_num)
QP_stream *option;
char *sys_option; /* not useful in this
version */
int *error_num;
{
QP_stream *stream;
int fd;
char *filename;
struct stat statbuf;
*error_num = 0;
if (! (filename = option->filename)) {
*error_num = QP_E_FILENAME;
return QP_NULL_STREAM;
}
switch (option->mode) {
case QP_READ:
fd = open(filename, O_RDONLY, 0000);
break;
case QP_WRITE:
fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC,
0666);
break;
case QP_APPEND:
fd = open(filename, O_WRONLY|O_CREAT, 0666);
break;
default:
*error_num = QP_E_BAD_MODE;
return QP_NULL_STREAM;
}
if (fstat(fd, &statbuf) == 0) {
if ((statbuf.st_mode & S_IFMT) == S_IFDIR) {
(void) close(fd);
*error_num = QP_E_DIRECTORY;
return QP_NULL_STREAM;
}
}
if (fd < 0) {
*error_num = errno;
return QP_NULL_STREAM;
}
if (option->format == QP_DELIM_TTY &&
!(isatty(fd)) ) {
*error_num = QP_E_BAD_FORMAT;
(void) close(fd);
return QP_NULL_STREAM;
}
if ((stream=QU_fdopen(option, sys_option,
error_num, fd))
== QP_NULL_STREAM) {
(void) close(fd);
return QP_NULL_STREAM;
}
if (stream->format == QP_DELIM_TTY) {
char *tty_id;
if (! (tty_id = ttyname(fd)) )
tty_id = "/PROLOG DEFAULT TTYS";
(void) QP_add_tty(stream, tty_id);
}
return stream;
}
The following is the source code for the implementation of QU_tty_open()
in C. QU_tty_open() is called in the QU_fdopen() source
code listed above. (QU_text_open() and QU_raw_open()
are also called in QU_fdopen(). The source code for these two
functions is not listed here, but they are shipped with Quintus Prolog.)
#include <fcntl.h>
#include <errno.h>
#include "quintus.h"
extern char *QP_malloc();
#define Min_Buffer_Size 4
struct TtyStream
{
QP_stream qpinfo;
int fd;
unsigned char buffer[Min_Buffer_Size];
};
#define CoerceTtyStream(x) ((struct TtyStream *)(x))
static int
tty_read(stream, bufptr, sizeptr)
QP_stream *stream;
unsigned char **bufptr;
long int *sizeptr;
{
int n;
extern int errno;
register struct TtyStream
*u = CoerceTtyStream(stream);
n = read(u->fd, (char*)u->buffer,
(int)u->qpinfo.max_reclen);
if (n > 0) {
*bufptr = u->buffer;
*sizeptr = n;
if (u->buffer[n-1] == '\n')
return QP_FULL;
else
return QP_PART;
} else if (n == 0) {
*sizeptr = 0;
return QP_EOF;
} else {
u->qpinfo.errno = errno;
return QP_ERROR;
}
}
static int
tty_write(stream, bufptr, sizeptr)
QP_stream *stream;
unsigned char **bufptr;
long int *sizeptr;
{
struct TtyStream *u = CoerceTtyStream(stream);
int n, len=(int) *sizeptr;
char *buf = (char *) *bufptr;
if (len==0) { /* be sure to set *sizeptr
and *bufptr */
*sizeptr = u->qpinfo.max_reclen;
*bufptr = u->buffer;
return QP_SUCCESS;
}
while ((n = write(u->fd, buf, len)) > 0 && n
< len) {
buf += n;
len -= n;
}
if (n >= 0) {
*sizeptr = u->qpinfo.max_reclen;
*bufptr = u->buffer;
return QP_SUCCESS;
} else {
u->qpinfo.errno = errno;
return QP_ERROR;
}
}
static int
tty_close(stream)
QP_stream *stream;
{
struct TtyStream *u = CoerceTtyStream(stream);
int fd = u->fd;
QP_free(stream);
if (close(fd) < 0)
return QP_ERROR;
return QP_SUCCESS;
}
QP_stream *
QU_tty_open(option, error_num, fd)
register QP_stream *option;
int *error_num, fd;
{
struct TtyStream *stream;
if (option->seek_type != QP_SEEK_ERROR) {
*error_num = QP_E_SEEK_TYPE;
return QP_NULL_STREAM;
}
stream = (struct TtyStream *)
QP_malloc(sizeof(*stream) +
((option->max_reclen <= Min_Buffer_Size) ? 0
: option->max_reclen - Min_Buffer_Size) );
stream->qpinfo = *option;
QP_prepare_stream(&stream->qpinfo, stream->buffer);
stream->fd = fd;
stream->qpinfo.close = tty_close;
if (option->mode != QP_READ) {
stream->qpinfo.write =
stream->qpinfo.flush = tty_write;
} else
stream->qpinfo.read = tty_read;
return (QP_stream *) stream;
}
- See Also:
- open/4, QU_fdopen()
- {manual(i-5)}
QU_stream_param() user-redefinable
- Synopsis:
- #include <quintus/quintus.h>
void QU_stream_param(filename, mode, format, option)
char *filename;
int mode;
unsigned char format;
QP_stream *option;
- Embedding function which sets up default values of user-accessible
fields in a Prolog stream structure.
- Arguments:
- filename
- name of the file to be opened. If the stream does not have a file name,
the filename is the empty string, "". If the filename
is "/dev/tty", the caller requests QU_stream_param()
to set the field values as a tty stream.
- mode
- QP_READ for an input stream. QP_WRITE for an output
stream QP_APPEND for an output stream opened in append mode.
- format
- format of the stream, which could have one of the following values:
- QP_DELIM_LF
- QP_DELIM_CR,
- QP_DELIM_CRLF
- QP_FIX_LEN
- QP_VAR_LEN,
- QP_DELIM_RMS
- QP_DELIM_TTY
- QP_FMT_UNKNOWN.
- option
- pointer to a QP_stream structure whose fields are to be set
up.
- Description: The format is used in assisting QU_stream_param()
to
- determine the best values for the other member fields of the QP_stream
structure.
- All of the fields listed below of the QP_stream structure,
described in the Stream Structure section of Input/Output chapter
({manual(i-5-3)}), are set by QU_stream_param(). On UNIX, they
are given the indicated values:
- field
- value
- <Courier>
- <Helvetica>
- filename
- filename argument to QU_stream_param()
- mode
- mode argument to QU_stream_param()
- format
- format argument to QU_stream_param()
- max_reclen
- 8192 bytes for a file, 256 bytes for a tty
- line_border
- QP_LF
- file_border
- QP_EOF
- peof_act
- QP_PASTEOF_ERROR
- prompt
- "" (empty string)
- trim
- 0
- seek_type
- QP_SEEK_PREVIOUS for a file QP_SEEK_ERROR for a tty
- flush_type
- QP_FLUSH_FLUSH
- overflow
- QP_OV_FLUSH
- errno
- 0
- magic
- (byteno) 0
- read
- "bad_read" - a function that returns QP_ERROR
- write
- "bad_write" - a function that returns QP_ERROR
- flush
- "bad_flush" - a function that returns QP_ERROR
- seek
- "bad_seek" - a function that returns QP_ERROR
- close
- "bad_close" - a function that returns QP_ERROR
n: Command Reference Pages
Copyright (C) 1997 AI International
Ltd
contact: product
support sales information