|
|
#include <pfmt.h>int pfmt(FILE *stream, long flags, const char *format, . . . /* args */);
#include <pfmt.h>
int vpfmt(FILE *stream, long flags, const char *format, va_list ap);
vpfmt- display an error message in standard format; called with an argument list
To retrieve the
printf( )
format string from the message database,
the format argument must have the following structure:
[[catalog]:[msgnum]:]defmsg.
If archivename is specified, then pfmt( ) accesses the message database in an archive directory. The environment variable NLSPATH specifies the pathname for the message database, substituting filename for %N and archivename for %A. (See the explanation of NLSPATH, below.)
If you use the special syntax for catalog,
catalogname@archivename
then pfmt( ) accesses only archives. The environment variable NLSPATH is used with the archivename part of catalog substituted for %A (See environ(M)) Only the parts of the paths that contain %A are recognized.
If the message number is out of bounds, or if catalog does not exist in the locale (specified by the last call to setlocale(S-osr5) using the LC_ALL or LC_MESSAGES categories), pfmt( ) tries to retrieve the message from the C locale. If this second retrieval fails, pfmt( ) uses the defmsg part of the format argument.
The syntax for msgfilename is
filename[@archivename]
If NLSPATH does not exist in the environment, or if a message catalog can not be opened in any of the paths specified by NLSPATH, then the following default paths are used:
If catalog is omitted,
pfmt( )
tries to retrieve the string
from the default catalog specified by the last call to
setcat(S-osr5).
In this case, the format argument has the following structure:
msgnum:defmsg.
pfmt( ) outputs:
Message not found!!as the format string if:
The flags are composed of several groups, and can take the following values, one from each group:
Additional severities can be defined. Add-on severities can be defined with number-string pairs with numeric values from the range [5-255], using addsev(S-osr5). The numeric value ORed with other flags will generate the specified severity.
If the severity is not defined, pfmt( ) uses the string SEV=N where N is replaced by the integer severity value passed in flags.
Multiple severities passed in flags are not detected as an error. Any combination of severities is summed and the numeric value causes the display of either a severity string (if defined) or the string SEV=N (if undefined).
TO FIX
.
label: severity: textIf no label was defined by a call to setlabel(S-osr5), the message is displayed in the format:
severity: textIf pfmt( ) is called twice to display an error message and a helpful action or recovery message, the output can look like:
label: severity: text label: TO FIX: text
The file stdarg.h defines the type va_list and a set of macros for advancing through a list of arguments whose number and types may vary. The argument ap to vpfmt( ) is of type va_list. This argument is used with the stdarg.h header file macros va_start, va_arg and va_end (see varargs(S-osr5)). The examples below show their use.
The macro va_alist is used as the parameter list in a function definition as in the function called error in the example shown in the ``Examples'' section that follows. You must call the macro va_start(ap), where ap is of type va_list, before trying to traverse and access unnamed arguments. Calls to va_arg(ap atype) traverse the argument list. Each execution of va_arg expands to an expression with the value and type of the next argument in the list ap, which is the same object initialized by va_start. The argument atype is the type that the returned argument is expected to be.
The va_end(ap) macro is invoked when all desired arguments have been accessed. (The argument list in ap can be traversed again if va_start is called again after va_end.) In the example below, va_arg is executed first to retrieve the format string passed to error. The remaining error arguments, arg1, arg2, ..., are given to vpfmt( ) in the argument ap.
setlabel("SCO:test"); pfmt(stderr, MM_ERROR, "test:2:Cannot open file: %s\n", strerror(errno));displays the message:
SCO:test: ERROR: Cannot open file: No such file or directory
setlabel("SCO:test"); setcat("test"); pfmt(stderr, MM_ERROR, ":10:Syntax error\n"); pfmt(stderr, MM_ACTION, ":55:Usage ...\n");displays the message
SCO:test: ERROR: Syntax error SCO:test: TO FIX: Usage ...
#include <pfmt.h> #include <stdarg.h> . . . /* * error should be called like * error(format, arg1, ...); */ void error(const char *format, ...){ va_list ap;
va_start(ap, ); (void) vpfmt(stderr, MM_ERROR, format, ap); va_end(ap); (void) abort(); }