The most of compilers report error messages for incorrect program. Here the package `errors' which serves to output one-pass or multi-pass compiler messages of various modes (errors, warnings, fatal, system errors and appended messages) in Unix style or for traditional listing is suggested. The package also permits adequate error reporting for included files.
The package uses packages `vlobject', `objstack', `position' which use package `allocate'. Therefore package `position' have to be initiated before any work with this package. The interface part of the package is file `errors.h'. The implementation part is file `errors.c'. The maximum length of generated error message is suggested to be not greater then `MAX_ERROR_MESSAGE_LENGTH'. The default value (150) of this macro can be redefined with corresponding C compiler option `-DMAX_ERROR_MESSAGE_LENGTH=...' during compilation of file `errors.c'. The interface contains the following external definitions:
have values which are number of correspondingly errors and warnings fixed after the most recent package initiation.
has value which is maximum number of errors which will be fixed. If an error is fixed with number equals to `maximum_number_of_errors' then special fatal error `fatal error -- too many errors' with position of given error is fixed instead of the error. And all following errors are ignored. Zero value of the variable means that the special fatal error will never fixed.
defines originally value of variable `maximum_number_of_errors'. The constant value is `50'.
contains pointer to function without parameters which will be called after fixing a fatal error. The fatal error function is suggested to do not return the control back.
defines originally value of variable `fatal_error_function'. The function only calls `exit (1)'.
`void default_fatal_error_function (void)'
initiates the package in regime depending on parameter value. If the parameter value is nonzero than all fixed messages are output immediately. Otherwise the compiler messages are stored until function `output_errors' are called.
`void initiate_errors (int immediate_output_flag)'
frees all memory allocated during package work.
`void finish_errors (void)'
sorts (stable sorting) all fixed messages by their positions, outputs ones, and deletes ones. Appended messages will be output after corresponding error or warning. This function should be used only in regime of storing messages.
`void output_errors (void)'
fixes error (fatal error if the first parameter value is nonzero) at the position given as the second parameter. If the error is fatal than functions `output_errors' and `*fatal_error_function' are called. The diagnostic messages are formed analogous to output of function `printf'. For example,
`void error (int fatal_error_flag, position_t position, const char *format, ...)'
error (1, current_position, "fatal error - no memory");
is analogous to the previous but is used to fix a warning.
`void warning (position_t position, const char *format, ...)'
When regime of immediately output of fixed message is on this function is analogous to the previous (except for incrementing variable `number_of_warnings'). In opposite case the appended message will be output with the most recent fixed error or warning independently from value of the first parameter. Of course the previously fixed error or warning must exist.
`void append_message (position_t position, const char *format, ...)'
For example, this function may be used for generation of messages of type
`<file>:<line>:<position-1>: repeated declaration'
Description of function `default_output_error_function' contains explanation why decremented position is output.
`<file>:<line>:<position-1>: previous declaration'.
is analogous to function `error' but serves to fix a system error. The current system message without head blanks (given by standard function `strerror') is placed after the message formed by the function parameters. For example, the following call may be used when a file is not opened
`void system_error (int fatal_error_flag, position_t position, const char *format, ...)'
system_error (1, current_position, "fatal error - %s:", new_file_name);
contains pointer to function which is used to output error message. The function has three parameters -- flag of appended message, message position and message itself.
Originally value of variable `output_error_function' is equal to this function. The function is oriented to output in Unix style according to GNU standard. To output a listing the value of variable `output_error_function' should be changed. The function output message in the following formats:
`void default_output_error_function (int appended_message_flag, position_t position, const char *message)'
After that the function outputs newline. The function also outputs additional messages `in file processed from ...' if given message is not appended message and corresponds to file different from one of previous output error. This message reflects path of the message position (see package `position'), i.e. reflects positions of corresponding include-clauses. Decremented column number is output in order to be in concordance with editor Emacs in which positions start with 0.
MESSAGE (NULL file name) FILE_NAME:1: MESSAGE (zero line number) FILE_NAME:LINE_NUMBER: MESSAGE (zero column number) FILE_NAME:LINE_NUMBER:COLUMN_NUMBER-1: MESSAGE (all other cases)