X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b75a7d8f3b4adbae880cab104ce2c6a50eee4db2..f3c0d7a59d99c2a94c6b8822291f0e42be3773c9:/icuSources/extra/uconv/uwmsg.c diff --git a/icuSources/extra/uconv/uwmsg.c b/icuSources/extra/uconv/uwmsg.c index 4769d3cc..d5b0f627 100644 --- a/icuSources/extra/uconv/uwmsg.c +++ b/icuSources/extra/uconv/uwmsg.c @@ -1,6 +1,8 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /* ********************************************************************** -* Copyright (C) 1998-2000, International Business Machines Corporation +* Copyright (C) 1998-2016, International Business Machines Corporation * and others. All Rights Reserved. ********************************************************************** * @@ -18,6 +20,8 @@ #include "unicode/umsg.h" #include "unicode/uwmsg.h" #include "unicode/ures.h" +#include "unicode/putil.h" +#include "cmemory.h" #include "cstring.h" #include @@ -25,8 +29,6 @@ #include #include -#define LENGTHOF(array) (sizeof(array)/sizeof((array)[0])) - #define BUF_SIZE 128 /* Print a ustring to the specified FILE* in the default codepage */ @@ -83,12 +85,11 @@ finish: ucnv_close(converter); } -static const char *gPath = 0; static UResourceBundle *gBundle = NULL; U_STRING_DECL(gNoFormatting, " (UCONFIG_NO_FORMATTING see uconfig.h)", 38); -U_CAPI UResourceBundle *u_wmsg_setPath(const char *path, UErrorCode *err) +U_CFUNC UResourceBundle *u_wmsg_setPath(const char *path, UErrorCode *err) { if(U_FAILURE(*err)) { @@ -109,7 +110,6 @@ U_CAPI UResourceBundle *u_wmsg_setPath(const char *path, UErrorCode *err) return 0; } - gPath = uprv_strdup(path); gBundle = b; U_STRING_INIT(gNoFormatting, " (UCONFIG_NO_FORMATTING see uconfig.h)", 38); @@ -119,7 +119,7 @@ U_CAPI UResourceBundle *u_wmsg_setPath(const char *path, UErrorCode *err) } /* Format a message and print it's output to fp */ -U_CAPI int u_wmsg(FILE *fp, const char *tag, ... ) +U_CFUNC int u_wmsg(FILE *fp, const char *tag, ... ) { const UChar *msg; int32_t msgLen; @@ -128,7 +128,7 @@ U_CAPI int u_wmsg(FILE *fp, const char *tag, ... ) va_list ap; #endif UChar result[4096]; - int32_t resultLength = LENGTHOF(result); + int32_t resultLength = UPRV_LENGTHOF(result); if(gBundle == NULL) { @@ -142,15 +142,12 @@ U_CAPI int u_wmsg(FILE *fp, const char *tag, ... ) if(U_FAILURE(err)) { -#if 0 - fprintf(stderr, "u_wmsg: failed to load tag [%s] [%s] [%s]!!\n", tag, u_errorName(err), gPath); -#endif return -1; } #if UCONFIG_NO_FORMATTING - resultLength = sizeof(gNoFormatting) / U_SIZEOF_UCHAR; - if((msgLen + resultLength) <= LENGTHOF(result)) { + resultLength = UPRV_LENGTHOF(gNoFormatting); + if((msgLen + resultLength) <= UPRV_LENGTHOF(result)) { memcpy(result, msg, msgLen * U_SIZEOF_UCHAR); memcpy(result + msgLen, gNoFormatting, resultLength); resultLength += msgLen; @@ -196,21 +193,27 @@ U_CAPI int u_wmsg(FILE *fp, const char *tag, ... ) } /* these will break if the # of messages change. simply add or remove 0's .. */ -UChar * gInfoMessages[U_ERROR_WARNING_LIMIT-U_ERROR_WARNING_START] = - { 0,0 }; +UChar **gInfoMessages = NULL; -UChar * gErrMessages[U_ERROR_LIMIT] = - { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; +UChar **gErrMessages = NULL; static const UChar *fetchErrorName(UErrorCode err) { + if (!gInfoMessages) { + gInfoMessages = (UChar **)malloc((U_ERROR_WARNING_LIMIT-U_ERROR_WARNING_START)*sizeof(UChar*)); + memset(gInfoMessages, 0, (U_ERROR_WARNING_LIMIT-U_ERROR_WARNING_START)*sizeof(UChar*)); + } + if (!gErrMessages) { + gErrMessages = (UChar **)malloc(U_ERROR_LIMIT*sizeof(UChar*)); + memset(gErrMessages, 0, U_ERROR_LIMIT*sizeof(UChar*)); + } if(err>=0) return gErrMessages[err]; else return gInfoMessages[err-U_ERROR_WARNING_START]; } -U_CAPI const UChar *u_wmsg_errorName(UErrorCode err) +U_CFUNC const UChar *u_wmsg_errorName(UErrorCode err) { UChar *msg; int32_t msgLen;