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/errors.h | 4 +++ utils/messages.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ utils/messages.h | 9 ++++++ 3 files changed, 109 insertions(+) (limited to 'utils') diff --git a/utils/errors.h b/utils/errors.h index 9ad613da6..7fcb5bd09 100644 --- a/utils/errors.h +++ b/utils/errors.h @@ -61,6 +61,10 @@ typedef enum { NSERROR_DOM, /**< DOM call returned error */ + NSERROR_CSS, /**< CSS call returned error */ + + NSERROR_CSS_BASE, /**< CSS base sheet failed */ + NSERROR_BAD_URL /**< Bad URL */ } nserror; 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); +} diff --git a/utils/messages.h b/utils/messages.h index 2b78d07ee..81c380515 100644 --- a/utils/messages.h +++ b/utils/messages.h @@ -33,6 +33,7 @@ #ifndef _NETSURF_UTILS_MESSAGES_H_ #define _NETSURF_UTILS_MESSAGES_H_ +#include "utils/errors.h" #include "utils/hashtable.h" void messages_load(const char *path); @@ -40,6 +41,14 @@ struct hash_table *messages_load_ctx(const char *path, struct hash_table *ctx); const char *messages_get_ctx(const char *key, struct hash_table *ctx); const char *messages_get(const char *key); +/** + * 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); + /** * Formatted message from a key in the global message hash. * -- cgit v1.2.3