src/expatls.c:97:utf8tods: Character encoding error
src/expatls.c:449:start_fn:
src/dom.c:405:DOM_Element_normalize:
dump.c:30:main: Failed to process sample.xml
Note: As of version 0.9, this implementation no longer uses variadic macros -- it is strict standard C.
Additionally this module provides functions for managing error codes (or more generically message numbers) and associated messages across separate C libraries. This functionality is very similar to the com_err library but with runtime message registration. Each participating library registers a table of messages at runtime with the msgno_add_codes function. The msgno(3m) macros are provided to dispatch messages (e.g. print to stderr).
Note: The
The 9 Msgno Macros
Synopsis
Description
#include <mba/msgno.h> MMSG(fmt, ...) MMNO(msgno) MMNF(msgno, fmt, ...) /* Primary */ PMSG(fmt, ...) PMNO(msgno) PMNF(msgno, fmt, ...) /* Additional */ AMSG(fmt, ...) AMNO(msgno) AMNF(msgno, fmt, ...) extern int (*msgno_hdlr)(const char *fmt, ...); struct msgno_entry { unsigned int msgno; const char *msg; };
| Formatted String | Message Number | Message Number and Formatted String | |
|---|---|---|---|
| Primary message at the beginning of the message buffer | PMSG - The primary message macro writes formated printf like string to the beginning of the message buffer | PMNO - The primary message number macro accepts just a message number and writes the associated message the to the beginning of the message buffer | PMNF - The primary message number format macro accepts a message number and a formatted printf like string and writes both the message associated with the message number and the formatted output to the beginning of the message buffer |
| Additional message appended to the message buffer | AMSG - The additional message macro appends a formated printf like string to the message buffer | AMNO - The additional message number macro accepts just a message number and appends the associated message the to the message buffer | AMNF - The additional message number format macro accepts a message number and a formatted printf like string and appends both the message associated with the message number and the formatted output to the message buffer |
| Dispatched immediatedly to msgno_hdlr | MMSG - The message macro writes a formatted string to the registered msgno_hdlr | MMNO - THe message number macro writes the message associated with the provided number to the msgno_hdlr | MMNF - The message number format macro writes both the message associated with the message number and a formatted printf like string to the msgno_hdlr. |
The msgno macros are designed to be the least intrusive way to place debugging information within C source code. The following is an example of how and where these macros might be used to generate the example stack-trace-like output listed above.
if ((n = dec_mbsncpy(&s, sn, NULL, -1, -1, "UTF-8")) == (size_t)-1) {
PMNO(DOM_Exception = DOM_CHARACTER_ENC_ERR);
return -1;
}
...
if (utf8tods(atts[i], -1, ud) == (size_t)-1) {
AMSG("");
return;
}
...
if (DOM_DocumentLS_load(doc, argv[1]) == -1 ||
DOM_DocumentLS_fwrite(doc, stdout) == -1) {
MMSG("Failed to process %s", argv[1]);
return EXIT_FAILURE;
}
The msgno_add_codes function
Description
#include <mba/msgno.h> int msgno_add_codes(struct msgno_entry *list);
#define DOM_INDEX_SIZE_ERR dom_codes[0].msgno
#define DOM_DOMSTRING_SIZE_ERR dom_codes[1].msgno
struct msgno_entry dom_codes[] = {
{ 1, "The index specified was out of range" },
{ 0, "The text size is out of range" },
...
{ 0, NULL }
};
Returns
The msgno_msg function
Description
#include <mba/msgno.h> const char *msgno_msg(unsigned int msgno);
The msgno_hdlr_stderr function
Description
#include <mba/msgno.h> int msgno_hdlr_stderr(const char *fmt, ...);
Tip: If you are working on a Microsoft Windows MFC application, create a msgno_hdlr function like the one below that calls AfxMessageBox and set it to msgno_hdlr in InitInstance. This will permit your MFC application to report errors generated from within libmba.
static int
MessageBoxHdlr(const char *fmt, ...)
{
char mbs[4096];
wchar_t wcs[4096];
va_list ap;
va_start(ap, fmt);
_vsnprintf(mbs, 4096, fmt, ap);
if (mbstowcs(wcs, mbs, 4096) != (size_t)-1) {
AfxMessageBox(wcs);
}
va_end(ap);
return 0;
}
BOOL CWutApp::InitInstance()
{
...
msgno_hdlr = MessageBoxHdlr;
Returns