| OLD | NEW |
| 1 /* | 1 /* |
| 2 ********************************************************************** | 2 ********************************************************************** |
| 3 * Copyright (C) 1998-2012, International Business Machines Corporation | 3 * Copyright (C) 1998-2014, International Business Machines Corporation |
| 4 * and others. All Rights Reserved. | 4 * and others. All Rights Reserved. |
| 5 ********************************************************************** | 5 ********************************************************************** |
| 6 * | 6 * |
| 7 * File uwmsg.c | 7 * File uwmsg.c |
| 8 * | 8 * |
| 9 * Modification History: | 9 * Modification History: |
| 10 * | 10 * |
| 11 * Date Name Description | 11 * Date Name Description |
| 12 * 06/14/99 stephen Creation. | 12 * 06/14/99 stephen Creation. |
| 13 ******************************************************************************* | 13 ******************************************************************************* |
| 14 */ | 14 */ |
| 15 | 15 |
| 16 #include "unicode/ucnv.h" | 16 #include "unicode/ucnv.h" |
| 17 #include "unicode/ustring.h" | 17 #include "unicode/ustring.h" |
| 18 #include "unicode/umsg.h" | 18 #include "unicode/umsg.h" |
| 19 #include "unicode/uwmsg.h" | 19 #include "unicode/uwmsg.h" |
| 20 #include "unicode/ures.h" | 20 #include "unicode/ures.h" |
| 21 #include "unicode/putil.h" | 21 #include "unicode/putil.h" |
| 22 #include "cstring.h" | 22 #include "cstring.h" |
| 23 | 23 |
| 24 #include <stdlib.h> | 24 #include <stdlib.h> |
| 25 #include <stdarg.h> | 25 #include <stdarg.h> |
| 26 #include <stdio.h> | 26 #include <stdio.h> |
| 27 #include <string.h> | 27 #include <string.h> |
| 28 | 28 |
| 29 #define LENGTHOF(array) (sizeof(array)/sizeof((array)[0])) | |
| 30 | |
| 31 #define BUF_SIZE 128 | 29 #define BUF_SIZE 128 |
| 32 | 30 |
| 33 /* Print a ustring to the specified FILE* in the default codepage */ | 31 /* Print a ustring to the specified FILE* in the default codepage */ |
| 34 static void | 32 static void |
| 35 uprint(const UChar *s, | 33 uprint(const UChar *s, |
| 36 int32_t sourceLen, | 34 int32_t sourceLen, |
| 37 FILE *f, | 35 FILE *f, |
| 38 UErrorCode *status) | 36 UErrorCode *status) |
| 39 { | 37 { |
| 40 /* converter */ | 38 /* converter */ |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 /* Format a message and print it's output to fp */ | 118 /* Format a message and print it's output to fp */ |
| 121 U_CFUNC int u_wmsg(FILE *fp, const char *tag, ... ) | 119 U_CFUNC int u_wmsg(FILE *fp, const char *tag, ... ) |
| 122 { | 120 { |
| 123 const UChar *msg; | 121 const UChar *msg; |
| 124 int32_t msgLen; | 122 int32_t msgLen; |
| 125 UErrorCode err = U_ZERO_ERROR; | 123 UErrorCode err = U_ZERO_ERROR; |
| 126 #if !UCONFIG_NO_FORMATTING | 124 #if !UCONFIG_NO_FORMATTING |
| 127 va_list ap; | 125 va_list ap; |
| 128 #endif | 126 #endif |
| 129 UChar result[4096]; | 127 UChar result[4096]; |
| 130 int32_t resultLength = LENGTHOF(result); | 128 int32_t resultLength = UPRV_LENGTHOF(result); |
| 131 | 129 |
| 132 if(gBundle == NULL) | 130 if(gBundle == NULL) |
| 133 { | 131 { |
| 134 #if 0 | 132 #if 0 |
| 135 fprintf(stderr, "u_wmsg: No path set!!\n"); /* FIXME: codepage?? */ | 133 fprintf(stderr, "u_wmsg: No path set!!\n"); /* FIXME: codepage?? */ |
| 136 #endif | 134 #endif |
| 137 return -1; | 135 return -1; |
| 138 } | 136 } |
| 139 | 137 |
| 140 msg = ures_getStringByKey(gBundle, tag, &msgLen, &err); | 138 msg = ures_getStringByKey(gBundle, tag, &msgLen, &err); |
| 141 | 139 |
| 142 if(U_FAILURE(err)) | 140 if(U_FAILURE(err)) |
| 143 { | 141 { |
| 144 return -1; | 142 return -1; |
| 145 } | 143 } |
| 146 | 144 |
| 147 #if UCONFIG_NO_FORMATTING | 145 #if UCONFIG_NO_FORMATTING |
| 148 resultLength = sizeof(gNoFormatting) / U_SIZEOF_UCHAR; | 146 resultLength = sizeof(gNoFormatting) / U_SIZEOF_UCHAR; |
| 149 if((msgLen + resultLength) <= LENGTHOF(result)) { | 147 if((msgLen + resultLength) <= UPRV_LENGTHOF(result)) { |
| 150 memcpy(result, msg, msgLen * U_SIZEOF_UCHAR); | 148 memcpy(result, msg, msgLen * U_SIZEOF_UCHAR); |
| 151 memcpy(result + msgLen, gNoFormatting, resultLength); | 149 memcpy(result + msgLen, gNoFormatting, resultLength); |
| 152 resultLength += msgLen; | 150 resultLength += msgLen; |
| 153 uprint(result, resultLength, fp, &err); | 151 uprint(result, resultLength, fp, &err); |
| 154 } else { | 152 } else { |
| 155 uprint(msg,msgLen, fp, &err); | 153 uprint(msg,msgLen, fp, &err); |
| 156 } | 154 } |
| 157 #else | 155 #else |
| 158 va_start(ap, tag); | 156 va_start(ap, tag); |
| 159 | 157 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 u_charsToUChars(textMsg, msg, (int32_t)(strlen(textMsg)+1)); | 253 u_charsToUChars(textMsg, msg, (int32_t)(strlen(textMsg)+1)); |
| 256 } | 254 } |
| 257 | 255 |
| 258 if(err>=0) | 256 if(err>=0) |
| 259 gErrMessages[err] = msg; | 257 gErrMessages[err] = msg; |
| 260 else | 258 else |
| 261 gInfoMessages[err-U_ERROR_WARNING_START] = msg; | 259 gInfoMessages[err-U_ERROR_WARNING_START] = msg; |
| 262 | 260 |
| 263 return msg; | 261 return msg; |
| 264 } | 262 } |
| OLD | NEW |