All output is done in SLP be calling a function in this module. So this the only module which has to be changed, if messages in another language should be produced.
This module can produce HTML-output or ASCII-output,
so SLP can run as a CGI-Program or can be directly called under UNIX
(it also runs as a Windows Console application).
The kind of output depends on the compile-time parameter
VER_CGI
.
If this macro is defined during compilation,
HTML output is produced,
otherwise ASCII output.
Of course,
it would be possible to have both options compiled into the executable
program,
but CGI programs need additional security checks.
So it would anyway not be possible to use the same binary
as local command and as CGI-program.
Currently, this module is realized as a class out_c with lots of class functions. It is not possible to create instances of this class. This module contains only straightforward code. However, it is ensured that no function crashes if it gets a NIL-pointer for a string parameter.
Of course,
open
should be called before any of the other functions.
However,
the implementation is robust and calls open
implictly if necessary.
void open()
;VER_CGI
is defined).
void close(void)
;VER_CGI
is defined,
this function prints the HTML closing sequence.
static void assertion_failed(str_t filename, int line,
str_t msg)
;msg
,
and a contact email address.
static void exception(int sig_no, str_t sig_name)
;assertion_failed
.
The name and the number of the signal are printed
(the name can be "unexpected signal" if no more specific name
is available).
static void open_failed(str_t filename, str_t syserr)
;filename
cannot be opened.
syserr
is the explanation
returned by the operating system,
e.g. "no such file or directory".
static void read_failed(str_t filename, str_t syserr)
;static void close_failed(str_t filename, str_t syserr)
;static void null_char(str_t filename, int lineno)
;STR_NIL
(e.g. for CGI-input),
only the line number is printed.
static void line_too_long(str_t filename, int lineno)
;STR_NIL
(e.g. for CGI-input),
only the line number is printed.
static void mem_limit(int max_kilobytes)
;max_kilobytes
contains the current limit of the memory manager.
static void insufficient_memory(int allocated_kilobytes)
;
malloc
has failed.
The parameter allocated_kilobytes
contains the size of the already allocated dynamic memory.
static void too_many_args(void)
;static void too_many_head_lit(int max)
;VER_MAX_HEAD_LIT
in ver.h higher,
recompile the program, and try it again.
The parameter max
is the current setting for
VER_MAX_HEAD_LIT
.
The reason why I used a fixed size array here
is that generated conditional facts must first be tested
for redundancy,
and often they will be immediately thrown away.
I felt that this is not worth the effort of dynamic memory management,
or at least it can be deferred to a later version.
The decision is not so clear,
because a conditional fact may also later turn out to be redundant.
static void too_many_cond_neg(int max)
;VER_MAX_COND_NEG
in ver.h higher,
recompile the program, and try it again.
The parameter max
is the current setting for
VER_MAX_COND_NEG
.
static void too_many_neg_lit(int max)
;VER_MAX_NEG_SIZE
in ver.h and should be easy to change.
The parameter max
is simply the current setting
for VER_MAX_NEG_SIZE
.
Note that each default negation counts one and each negated literal
also counts one.
So if the max
is e.g. 256,
there could be at most 128 default negations
of one literal each.
static void too_many_compar(long max)
;VER_MAX_COMPAR
in ver.h and should be easy to change.
The parameter max
is simply the current setting
for VER_MAX_COMPAR
.
static void too_many_crit_neg(int max)
;VER_MAX_CRIT_NEG
in ver.h and should be easy to change
(up to the limit of 32).
The parameter max
is simply the current setting
for VER_MAX_CRIT_NEG
.
static void backtrack_point_stack_overflow(int max)
;VER_BACKTRACK_POINTS
in ver.h and should be easy to change.
The parameter max
is simply the current setting
for VER_BACKTRACK_POINTS
.
static void comp_ax_too_large(int max)
;p
contains one literal from each conditional fact
in which p
appears in the head.
A array of size VER_MAX_CAX_LIT
is used during the generation of the completion axiom.
This message is printed when the array is too small,
i.e. a fact appears in too many conditional facts.
The array size VER_MAX_CAX_LIT
is defined
in ver.h and should be easy to change.
The parameter max
is simply the current setting
for VER_MAX_CAX_LIT
.
This function is only defined if VER_SEM_STABLE
is defined.
static void cgi_security(str_t filename)
;/etc/passwd
.
This error message is printed if the input file is not allowed.
static void bad_request_method(void)
;REQUEST_METHOD
is either not defined or doesn't have the value "POST
".
static void bad_content_type(void)
;CONTENT_TYPE
is either not defined or doesn't have the value
"application/x-www-form-urlencoded
".
static void bad_content_length(void)
;CONTENT_LENGTH
is either not defined or is not a non-negative number.
static void bad_cgi_hex(void)
;static void cgi_premature_eof(void)
;static void cgi_null_char(void)
;%00
"),
but SLP cannot work with null characters in the input.
static void cgi_field_not_terminated(void)
;=
',
but this was not found.
static void cgi_duplicate_program(void)
;program
-field was contained
in the CGI input.
static void cgi_no_program(void)
;program
-field was contained in the input.
These functions are used to print lines from the user's input file
(usually in syntax error messages).
The main purpose is to switch to <pre>
if we are running as a cgi-program.
static void show_input(void)
;static void show_char(char c)
;show_input
must have been called before.
static void show_newline(void)
;static void show_eof(void)
;static void show_end(void)
;static void err_begin(void)
;static void err_end(int num_errs)
;err_begin
was called earlier.
In CGI mode,
it closes the unordered list.
It can also print a summary:
num_errs
is the number of errors.
The value -1
means that there were
too many errors, so the parsing was aborted.
static void err_syntax(str_t file, int line,
out_syn_t msg)
;err_newline
(see below).
In this way,
arguments of the error message can be added.
After err_newline
,
ussually the show
-functions are called to
print the current input line.
The parameter msg
determines the detailed message for a syntax error,
e.g. "term expected".
Since there are quite a lot of different such messages,
there is an enumeration type for syntax error messages defined
in this module
(remember that all other modules,
including the parser,
should be language-independent).
The enumeration type out_syn_t
has the following
values:
OUT_ILLEGAL_CHAR
:
"Illegal character"
OUT_BAD_LESS
:
"< is only legal as first character of <-"
OUT_BAD_GREATER
:
"> is only legal in -> or <->"
OUT_BAD_MINUS
:
"- must be followed by > or digits"
OUT_MISSING_QUOTE
:
"Missing quote (quoted atom is not closed)"
OUT_EMPTY_ATOM
:
"The empty atom is not allowed"
OUT_MISSING_SPACE
:
"A space or newline is required after '.'"
OUT_INT_OVERFLOW
:
"Integer constant too large"
OUT_RESERVED_PRED
:
"Illegal use of reserved predicate"
OUT_EMPTY_CMD
:
"Illegal empty command"
OUT_UNKNOWN_CMD
:
"Unknown command"
OUT_PRED_EXPECTED
:
"Atom (predicate) expected"
OUT_TERM_EXPECTED
:
"Term (predicate argument) expected"
OUT_COMMA_OR_RPAREN_EXPECTED
:
"',' or ')' expected"
OUT_ARGLIST_BINOP_OR_FULLSTOP_EXPECTED
:
"Argument list/binary operator/'.' expected"
OUT_ARGLIST_BINOP_OR_RPAREN_EXPECTED
:
"Argument list/binary operator/')' expected"
OUT_RPAREN_EXPECTED
:
"')' expected"
OUT_BINOP_OR_RPAREN_EXPECTED
:
"Binary operator or ')' expected"
OUT_BINOP_OR_FULLSTOP_EXPECTED
:
"Binary operator or '.' expected"
OUT_FORMULA_EXPECTED
:
"Formula expected"
OUT_FORMULA_OR_VARLIST_EXPECTED
:
"Query formula or variable list expected"
OUT_COMMA_OR_COLON_EXPECTED
:
"Comma or colon expected"
OUT_VAR_EXPECTED
:
"Variable expected"
OUT_STACK_OVERFLOW
:
"Formula too complicated, operator stack overflow"
OUT_OPERATOR_NOT_ASSOCIATIVE
:
"Operator not associative, use parentheses"
OUT_NOT_CANNOT_BE_NESTED
:
"Default negation cannot be nested"
OUT_OP_ILLEGAL_WITHIN_NOT
:
"Only & and | can be used inside default negation"
OUT_ANON_WITHIN_NOT
:
"Anonymous variables are not allowed inside not"
OUT_NO_OPS_INSIDE_NOT
:
"With $a, not can be applied only to atoms"
(defined only for VER_SEM_STABLE
)
OUT_OPS_INSIDE_NOT_WERE_USED
:
"not was already applied to structured formulas"
(defined only for VER_SEM_STABLE
)
OUT_FULLSTOP_EXPECTED
:
"Fullstop expected ('.' followed by white space)"
OUT_TOO_MANY_VARS
:
"Too many non-anonymous variables in formula"
OUT_TOO_MANY_ARGS
:
"Too many arguments of atomic formula (literal)"
OUT_OVERFLOW_DURING_CONVERSION
:
"Array overflow during conversion into clause form"
OUT_TOO_MANY_HEAD_LITS
:
"Clause contains too many head literals"
OUT_TOO_MANY_BODY_LITS
:
"Clause contains too many positive body literals"
OUT_TOO_MANY_NEG_LITS
:
"Clause contains too many/too large default negations"
OUT_ONLY_ONE_QUERY_PERMITTED
:
"The input can contain only one query"
static void err_note_v(void)
;err_note_v
.
static void err_anon_head(str_t filename,
int line_no)
;err_newline
.
static void err_neg_head(str_t filename, int line_no)
;err_newline
.
static void err_unbound_var(str_t filename,
int line_no)
;err_newline
.
static void err_newline(void)
;err_syntax
(see above).
The two functions are divided because some syntax error messages
have parameters
(such as a head literal containing anonymous variables).
These parameters cannot be directly passed to functions of the
module out_c
since this would generate cycles
in the dependency relation between the modules.
static void err_input_empty(void)
;The functions in this section are used for printing data, e.g. formulas. Data originates from the input, and does not have to be translated if SLP is translated to another language. So it would be a mistake to use the following functions for printing error messages etc.
static void print_str(str_t str)
;str
.
In CGI mode,
the characters < >, and & are replaced
by the corresponding entity references.
static void print_char(char c)
;c
.
In CGI mode,
the characters < >, and & are replaced
by the corresponding entity references.
static void print_int(int i)
;i
.
static void print_bool(int b)
;b
(true or false).
static void print_nl(void)
;static void input_formulas(void)
;static void list_begin(void)
;static void list_item(void)
;static void list_end(void)
;list_begin
.
In CGI-Mode,
it prints "</UL>".
In normal mode,
it does nothing.
static void initial_cond_facts(void)
;static void hyperres_verbose(void)
;static void hyperres_round(int round)
;round
.
It is used in the verbose output for the hyperresolution.
static void no_match(void)
;static void hyperres_curr_cf(void)
;static void hyperres_fixpoint(void)
;static void residual_program(void)
;static void no_cond_facts(void)
;static void rules(void)
;static void no_rules(void)
;static void no_default_neg(void)
;static void no_disjunctions(void)
;static void inconsistent(void)
;static void empty_defneg_interpretation(void)
;static void fixpoint_computation(int round)
;static void fixpoint_case(int no)
;static void result(void)
;static void defneg_interpretation(void)
;static void disjunctions(void)
;static void minimal_model(void)
;static void no_min_mod(void)
;static void static_fixpoint(void)
;static void completion(void)
;VER_SEM_STABLE
is defined.
static void stable_models(void)
;VER_SEM_STABLE
is defined.
static void stable_model_no(int no)
;VER_SEM_STABLE
is defined.
static void all_facts_are_false(void)
;VER_SEM_STABLE
is defined.
static void no_stable_models(void)
;VER_SEM_STABLE
is defined.
static void prompt(void)
;SLP>
").
Currently, there is only one prompt,
but later we should make a difference whether
a new command is expected or a continuation for an incomplete
command.
static void input_is_inconsistent(void)
;Input is inconsistent.
"
is printed as a second-level headline.
static void static_is_inconsistent(void)
;Program is inconsistent under the Static semantics.
"
is printed as a second-level headline.
static void answer(void)
;static void not_provable(void)
;Not provable.
"
is printed in boldface.
static void yes(void)
;Yes (query proven).
"
is printed in boldface.
static void print_or(void)
; or
"
between parts of a disjunctive answer.