+// © 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.
**********************************************************************
*
#include "unicode/umsg.h"
#include "unicode/uwmsg.h"
#include "unicode/ures.h"
+#include "unicode/putil.h"
+#include "cmemory.h"
#include "cstring.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#define LENGTHOF(array) (sizeof(array)/sizeof((array)[0]))
-
#define BUF_SIZE 128
/* Print a ustring to the specified FILE* in the default codepage */
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))
{
return 0;
}
- gPath = uprv_strdup(path);
gBundle = b;
U_STRING_INIT(gNoFormatting, " (UCONFIG_NO_FORMATTING see uconfig.h)", 38);
}
/* 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;
va_list ap;
#endif
UChar result[4096];
- int32_t resultLength = LENGTHOF(result);
+ int32_t resultLength = UPRV_LENGTHOF(result);
if(gBundle == NULL)
{
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;
}
/* 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;