add message retrival of error codes ensuring there are messages for all codes

This commit is contained in:
Vincent Sanders 2012-11-26 17:20:15 +00:00
parent 2fef76db15
commit ce309aa5a9
5 changed files with 112 additions and 93 deletions

View File

@ -1195,99 +1195,7 @@ browser_window_callback_errorcode(hlcache_handle *c,
{
const char* message;
switch (code) {
case NSERROR_OK:
/**< No error */
message = messages_get("OK");
break;
case NSERROR_NOMEM:
/**< Memory exhaustion */
message = messages_get("NoMemory");
break;
case NSERROR_NO_FETCH_HANDLER:
/**< No fetch handler for URL scheme */
message = messages_get("NoHandler");
break;
case NSERROR_NOT_FOUND:
/**< Requested item not found */
message = messages_get("NotFound");
break;
case NSERROR_SAVE_FAILED:
/**< Failed to save data */
message = messages_get("SaveFailed");
break;
case NSERROR_CLONE_FAILED:
/**< Failed to clone handle */
message = messages_get("CloneFailed");
break;
case NSERROR_INIT_FAILED:
/**< Initialisation failed */
message = messages_get("InitFailed");
break;
case NSERROR_MNG_ERROR:
/**< An MNG error occurred */
message = messages_get("MNGError");
break;
case NSERROR_BAD_ENCODING:
/**< The character set is unknown */
message = messages_get("BadEncoding");
break;
case NSERROR_NEED_DATA:
/**< More data needed */
message = messages_get("NeedData");
break;
case NSERROR_ENCODING_CHANGE:
/**< The character set encoding change was unhandled */
message = messages_get("EncodingChanged");
break;
case NSERROR_BAD_PARAMETER:
/**< Bad Parameter */
message = messages_get("BadParameter");
break;
case NSERROR_INVALID:
/**< Invalid data */
message = messages_get("Invalid");
break;
case NSERROR_BOX_CONVERT:
/**< Box conversion failed */
message = messages_get("BoxConvert");
break;
case NSERROR_STOPPED:
/**< Content conversion stopped */
message = messages_get("Stopped");
break;
case NSERROR_DOM:
/**< DOM call returned error */
message = messages_get("ParsingFail");
break;
case NSERROR_BAD_URL:
/**< Bad URL */
message = messages_get("BadURL");
break;
default:
case NSERROR_UNKNOWN:
/**< Unknown error */
message = messages_get("Unknown");
break;
}
message = messages_get_errorcode(code);
browser_window_set_status(bw, message);

View File

@ -2787,6 +2787,8 @@ de.all.ParsingFail:Dokumentparsing ist fehlgeschlagen.
fr.all.ParsingFail:L'analyse syntaxique du document a échoué.
it.all.ParsingFail:Analisi del documento fallita.
nl.all.ParsingFail:fout bij ontleden van dit document.
en.all.CSSGeneric:Error processing CSS
en.all.CSSBase:Base stylesheet failed to load
en.all.BadGIF:Reading GIF failed.
de.all.BadGIF:Lesen einer GIF Datei fehlgeschlagen.
fr.all.BadGIF:Erreur de lecture de GIF.

View File

@ -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;

View File

@ -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);
}

View File

@ -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.
*