diff -r 8cbc438cc298 -r 48204dea0b9f librazor/error.c --- a/librazor/error.c Thu Feb 16 17:33:47 2012 +0000 +++ b/librazor/error.c Sat Aug 23 11:13:48 2014 +0100 @@ -27,18 +27,73 @@ #include "razor.h" #include "razor-internal.h" +const char *razor_error_get_path_str(struct razor_error *error) +{ + if (error->path_str) + return error->path_str; + + if (error->path) { + error->path_str = razor_concat(error->path, ": ", + error->str, NULL); + return error->path_str; + } + + return error->str; +} + +/** + * razor_error_get_primary_text: + * + * Retrieves the basic information about an error. If a summary has been set + * then this will be returned. Otherwise the error string possibly prefixed + * by the path will be returned instead. + * + * Returns: Primary text of error. + **/ +RAZOR_EXPORT const char * +razor_error_get_primary_text(struct razor_error *error) +{ + if (error->summary) + return error->summary; + + return razor_error_get_path_str(error); +} + +/** + * razor_error_get_secondary_text: + * + * Retrieves more detailed information about an error, if any. If a summary + * has been set the error string possibly prefixed by the path will be + * returned. Otherwise NULL will be returned. + * + * Returns: Secondary text of error or NULL. + **/ +RAZOR_EXPORT const char * +razor_error_get_secondary_text(struct razor_error *error) +{ + if (!error->summary) + return NULL; + + return razor_error_get_path_str(error); +} + RAZOR_EXPORT const char * razor_error_get_msg(struct razor_error *error) { - if (!error->msg) { - if (error->path) - error->msg = razor_concat(error->path, ": ", error->str, - NULL); - else - error->msg = strdup(error->str); - } + const char *primary, *secondary; - return error->msg; + if (error->msg) + return error->msg; + + primary = razor_error_get_primary_text(error); + + secondary = razor_error_get_secondary_text(error); + + if (secondary) { + error->msg = razor_concat(primary, "\n", secondary, NULL); + return error->msg; + } else + return primary; } #ifdef MSWIN_API @@ -94,11 +149,34 @@ return error; } +RAZOR_EXPORT struct razor_error * +razor_error_dup(struct razor_error *src, const char *summary) +{ + struct razor_error *error; + + error = zalloc(sizeof *error); + + if (summary) + error->summary = strdup(summary); + else if (src->summary) + error->summary = strdup(src->summary); + + if (src->path) + error->path = strdup(src->path); + + if (src->str) + error->str = strdup(src->str); + + return error; +} + RAZOR_EXPORT void razor_error_free(struct razor_error *error) { free(error->path); free(error->str); + free(error->path_str); + free(error->summary); free(error->msg); free(error); }