2
**********************************************************************
3
* Copyright (C) 1998-2000, International Business Machines Corporation
4
* and others. All Rights Reserved.
5
**********************************************************************
9
* Modification History:
11
* Date Name Description
12
* 06/14/99 stephen Creation.
13
*******************************************************************************
16
#include "unicode/ucnv.h"
17
#include "unicode/ustring.h"
18
#include "unicode/umsg.h"
19
#include "unicode/uwmsg.h"
20
#include "unicode/ures.h"
30
/* Print a ustring to the specified FILE* in the default codepage */
32
uprint(const UChar *s,
38
UConverter *converter;
40
const UChar *mySource;
41
const UChar *mySourceEnd;
47
/* set up the conversion parameters */
49
mySourceEnd = mySource + sourceLen;
53
/* open a default converter */
54
converter = ucnv_open(0, status);
56
/* if we failed, clean up and exit */
57
if(U_FAILURE(*status)) goto finish;
59
/* perform the conversion */
61
/* reset the error code */
62
*status = U_ZERO_ERROR;
64
/* perform the conversion */
65
ucnv_fromUnicode(converter, &myTarget, myTarget + arraySize,
66
&mySource, mySourceEnd, NULL,
69
/* Write the converted data to the FILE* */
70
fwrite(buf, sizeof(char), myTarget - buf, f);
72
/* update the conversion parameters*/
76
while(*status == U_BUFFER_OVERFLOW_ERROR);
80
/* close the converter */
81
ucnv_close(converter);
84
static const char *gPath = 0;
85
static UResourceBundle *gBundle = NULL;
87
U_CAPI UResourceBundle *u_wmsg_setPath(const char *path, UErrorCode *err)
96
*err = U_ILLEGAL_ARGUMENT_ERROR;
101
UResourceBundle *b = NULL;
102
b = ures_open(path, NULL, err);
104
gPath = uprv_strdup(path);
111
/* Format a message and print it's output to stderr */
112
U_CAPI void u_wmsg(const char *tag, ... )
116
UErrorCode err = U_ZERO_ERROR;
119
int32_t resultLength = 4096;
123
fprintf(stderr, "u_wmsg: No path set!!\n"); /* FIXME: codepage?? */
127
msg = ures_getStringByKey(gBundle, tag, &msgLen, &err);
131
fprintf(stderr, "u_wmsg: failed to load tag [%s] [%s] [%s]!!\n", tag, u_errorName(err), gPath);
137
resultLength = u_vformatMessage(uloc_getDefault(), msg, msgLen, result, resultLength, ap, &err);
143
fprintf(stderr, "u_wmsg: failed to format %s:%s, err %s\n",
149
uprint(msg,msgLen, stderr, &err);
153
uprint(result, resultLength, stderr, &err);
157
fprintf(stderr, "u_wmsg: failed to print %s:%s, err %s\n",
165
/* these will break if the # of messages change. simply add or remove 0's .. */
166
UChar * gInfoMessages[U_ERROR_WARNING_LIMIT-U_ERROR_WARNING_START] =
169
UChar * gErrMessages[U_ERROR_LIMIT] =
170
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
172
static const UChar *fetchErrorName(UErrorCode err)
175
return gErrMessages[err];
177
return gInfoMessages[err-U_ERROR_WARNING_START];
180
U_CAPI const UChar *u_wmsg_errorName(UErrorCode err)
184
UErrorCode subErr = U_ZERO_ERROR;
185
const char *textMsg = NULL;
188
msg = (UChar*)fetchErrorName(err);
201
const char *errname = u_errorName(err);
203
msg = (UChar*)ures_getStringByKey(gBundle, errname, &msgLen, &subErr);
204
if(U_FAILURE(subErr))
211
if(msg == NULL) /* Couldn't find it anywhere.. */
214
textMsg = u_errorName(err);
216
sprintf(error, "UNDOCUMENTED ICU ERROR %d", err);
219
msg = (UChar*)malloc((strlen(textMsg)+1)*sizeof(msg[0]));
220
u_charsToUChars(textMsg, msg, strlen(textMsg)+1);
224
gErrMessages[err] = msg;
226
gInfoMessages[err-U_ERROR_WARNING_START] = msg;