From ce309aa5a9c1f813f6bdf152221f9bff88c4d3e1 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 26 Nov 2012 17:20:15 +0000 Subject: add message retrival of error codes ensuring there are messages for all codes --- utils/messages.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) (limited to 'utils/messages.c') diff --git a/utils/messages.c b/utils/messages.c index 5b62912a6..8ae616b86 100644 --- a/utils/messages.c +++ b/utils/messages.c @@ -200,3 +200,99 @@ const char *messages_get(const char *key) { return messages_get_ctx(key, messages_hash); } + + +/** + * lookup of a message by errorcode from the standard Messages hash. + * + * \param code errorcode of message + * \return message text + */ + +const char *messages_get_errorcode(nserror code) +{ + switch (code) { + case NSERROR_OK: + /**< No error */ + return messages_get_ctx("OK", messages_hash); + + case NSERROR_NOMEM: + /**< Memory exhaustion */ + return messages_get_ctx("NoMemory", messages_hash); + + case NSERROR_NO_FETCH_HANDLER: + /**< No fetch handler for URL scheme */ + return messages_get_ctx("NoHandler", messages_hash); + + case NSERROR_NOT_FOUND: + /**< Requested item not found */ + return messages_get_ctx("NotFound", messages_hash); + + case NSERROR_SAVE_FAILED: + /**< Failed to save data */ + return messages_get_ctx("SaveFailed", messages_hash); + + case NSERROR_CLONE_FAILED: + /**< Failed to clone handle */ + return messages_get_ctx("CloneFailed", messages_hash); + + case NSERROR_INIT_FAILED: + /**< Initialisation failed */ + return messages_get_ctx("InitFailed", messages_hash); + + case NSERROR_MNG_ERROR: + /**< An MNG error occurred */ + return messages_get_ctx("MNGError", messages_hash); + + case NSERROR_BAD_ENCODING: + /**< The character set is unknown */ + return messages_get_ctx("BadEncoding", messages_hash); + + case NSERROR_NEED_DATA: + /**< More data needed */ + return messages_get_ctx("NeedData", messages_hash); + + case NSERROR_ENCODING_CHANGE: + /**< The character set encoding change was unhandled */ + return messages_get_ctx("EncodingChanged", messages_hash); + + case NSERROR_BAD_PARAMETER: + /**< Bad Parameter */ + return messages_get_ctx("BadParameter", messages_hash); + + case NSERROR_INVALID: + /**< Invalid data */ + return messages_get_ctx("Invalid", messages_hash); + + case NSERROR_BOX_CONVERT: + /**< Box conversion failed */ + return messages_get_ctx("BoxConvert", messages_hash); + + case NSERROR_STOPPED: + /**< Content conversion stopped */ + return messages_get_ctx("Stopped", messages_hash); + + case NSERROR_DOM: + /**< DOM call returned error */ + return messages_get_ctx("ParsingFail", messages_hash); + + case NSERROR_CSS: + /**< CSS call returned error */ + return messages_get_ctx("CSSGeneric", messages_hash); + + case NSERROR_CSS_BASE: + /**< CSS base sheet failed */ + return messages_get_ctx("CSSBase", messages_hash); + + case NSERROR_BAD_URL: + /**< Bad URL */ + return messages_get_ctx("BadURL", messages_hash); + + default: + case NSERROR_UNKNOWN: + break; + } + + /**< Unknown error */ + return messages_get_ctx("Unknown", messages_hash); +} -- cgit v1.2.3