1 /********************************************************************
2 * COPYRIGHT:
3 * Copyright (c) 2007-2012, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6
7 #include "udbgutil.h"
8 #include <string.h>
9 #include "ustr_imp.h"
10 #include "cstring.h"
11 #include "putilimp.h"
12 #include "unicode/ulocdata.h"
13 #include "unicode/ucnv.h"
14
15 /*
16 To add a new enum type
17 (For example: UShoeSize with values USHOE_WIDE=0, USHOE_REGULAR, USHOE_NARROW, USHOE_COUNT)
18
19 1. udbgutil.h: add UDBG_UShoeSize to the UDebugEnumType enum before UDBG_ENUM_COUNT
20 ( The subsequent steps involve this file, udbgutil.cpp )
21 2. Find the marker "Add new enum types above this line"
22 3. Before that marker, add a #include of any header file you need.
23 4. Each enum type has three things in this section: a #define, a count_, and an array of Fields.
24 It may help to copy and paste a previous definition.
25 5. In the case of the USHOE_... strings above, "USHOE_" is common to all values- six characters
26 " #define LEN_USHOE 6 "
27 6 characters will strip off "USHOE_" leaving enum values of WIDE, REGULAR, and NARROW.
28 6. Define the 'count_' variable, with the number of enum values. If the enum has a _MAX or _COUNT value,
29 that can be helpful for automatically defining the count. Otherwise define it manually.
30 " static const int32_t count_UShoeSize = USHOE_COUNT; "
31 7. Define the field names, in order.
32 " static const Field names_UShoeSize[] = {
33 " FIELD_NAME_STR( LEN_USHOE, USHOE_WIDE ),
34 " FIELD_NAME_STR( LEN_USHOE, USHOE_REGULAR ),
35 " FIELD_NAME_STR( LEN_USHOE, USHOE_NARROW ),
36 " };
37 ( The following command was usedfor converting ucol.h into partially correct entities )
38 grep "^[ ]*UCOL" < unicode/ucol.h |
39 sed -e 's%^[ ]*\([A-Z]*\)_\([A-Z_]*\).*% FIELD_NAME_STR( LEN_\1, \1_\2 ),%g'
40 8. Now, a bit farther down, add the name of the enum itself to the end of names_UDebugEnumType
41 ( UDebugEnumType is an enum, too!)
42 names_UDebugEnumType[] { ...
43 " FIELD_NAME_STR( LEN_UDBG, UDBG_UShoeSize ), "
44 9. Find the function _udbg_enumCount and add the count macro:
45 " COUNT_CASE(UShoeSize)
46 10. Find the function _udbg_enumFields and add the field macro:
47 " FIELD_CASE(UShoeSize)
48 11. verify that your test code, and Java data generation, works properly.
49 */
50
51 /**
52 * Structure representing an enum value
53 */
54 struct Field {
55 int32_t prefix; /**< how many characters to remove in the prefix - i.e. UCHAR_ = 5 */
56 const char *str; /**< The actual string value */
57 int32_t num; /**< The numeric value */
58 };
59
60 /**
61 * Calculate the size of an array.
62 */
63 #define DBG_ARRAY_COUNT(x) (sizeof(x)/sizeof(x[0]))
64
65 /**
66 * Define another field name. Used in an array of Field s
67 * @param y the common prefix length (i.e. 6 for "USHOE_" )
68 * @param x the actual enum value - it will be copied in both string and symbolic form.
69 * @see Field
70 */
71 #define FIELD_NAME_STR(y,x) { y, #x, x }
72
73
74 // TODO: Currently, this whole functionality goes away with UCONFIG_NO_FORMATTING. Should be split up.
75 #if !UCONFIG_NO_FORMATTING
76
77 // Calendar
78 #include "unicode/ucal.h"
79
80 // 'UCAL_' = 5
81 #define LEN_UCAL 5 /* UCAL_ */
82 static const int32_t count_UCalendarDateFields = UCAL_FIELD_COUNT;
83 static const Field names_UCalendarDateFields[] =
84 {
85 FIELD_NAME_STR( LEN_UCAL, UCAL_ERA ),
86 FIELD_NAME_STR( LEN_UCAL, UCAL_YEAR ),
87 FIELD_NAME_STR( LEN_UCAL, UCAL_MONTH ),
88 FIELD_NAME_STR( LEN_UCAL, UCAL_WEEK_OF_YEAR ),
89 FIELD_NAME_STR( LEN_UCAL, UCAL_WEEK_OF_MONTH ),
90 FIELD_NAME_STR( LEN_UCAL, UCAL_DATE ),
91 FIELD_NAME_STR( LEN_UCAL, UCAL_DAY_OF_YEAR ),
92 FIELD_NAME_STR( LEN_UCAL, UCAL_DAY_OF_WEEK ),
93 FIELD_NAME_STR( LEN_UCAL, UCAL_DAY_OF_WEEK_IN_MONTH ),
94 FIELD_NAME_STR( LEN_UCAL, UCAL_AM_PM ),
95 FIELD_NAME_STR( LEN_UCAL, UCAL_HOUR ),
96 FIELD_NAME_STR( LEN_UCAL, UCAL_HOUR_OF_DAY ),
97 FIELD_NAME_STR( LEN_UCAL, UCAL_MINUTE ),
98 FIELD_NAME_STR( LEN_UCAL, UCAL_SECOND ),
99 FIELD_NAME_STR( LEN_UCAL, UCAL_MILLISECOND ),
100 FIELD_NAME_STR( LEN_UCAL, UCAL_ZONE_OFFSET ),
101 FIELD_NAME_STR( LEN_UCAL, UCAL_DST_OFFSET ),
102 FIELD_NAME_STR( LEN_UCAL, UCAL_YEAR_WOY ),
103 FIELD_NAME_STR( LEN_UCAL, UCAL_DOW_LOCAL ),
104 FIELD_NAME_STR( LEN_UCAL, UCAL_EXTENDED_YEAR ),
105 FIELD_NAME_STR( LEN_UCAL, UCAL_JULIAN_DAY ),
106 FIELD_NAME_STR( LEN_UCAL, UCAL_MILLISECONDS_IN_DAY ),
107 FIELD_NAME_STR( LEN_UCAL, UCAL_IS_LEAP_MONTH ),
108 };
109
110
111 static const int32_t count_UCalendarMonths = UCAL_UNDECIMBER+1;
112 static const Field names_UCalendarMonths[] =
113 {
114 FIELD_NAME_STR( LEN_UCAL, UCAL_JANUARY ),
115 FIELD_NAME_STR( LEN_UCAL, UCAL_FEBRUARY ),
116 FIELD_NAME_STR( LEN_UCAL, UCAL_MARCH ),
117 FIELD_NAME_STR( LEN_UCAL, UCAL_APRIL ),
118 FIELD_NAME_STR( LEN_UCAL, UCAL_MAY ),
119 FIELD_NAME_STR( LEN_UCAL, UCAL_JUNE ),
120 FIELD_NAME_STR( LEN_UCAL, UCAL_JULY ),
121 FIELD_NAME_STR( LEN_UCAL, UCAL_AUGUST ),
122 FIELD_NAME_STR( LEN_UCAL, UCAL_SEPTEMBER ),
123 FIELD_NAME_STR( LEN_UCAL, UCAL_OCTOBER ),
124 FIELD_NAME_STR( LEN_UCAL, UCAL_NOVEMBER ),
125 FIELD_NAME_STR( LEN_UCAL, UCAL_DECEMBER ),
126 FIELD_NAME_STR( LEN_UCAL, UCAL_UNDECIMBER)
127 };
128
129 #include "unicode/udat.h"
130
131 #define LEN_UDAT 5 /* "UDAT_" */
132 static const int32_t count_UDateFormatStyle = UDAT_SHORT+1;
133 static const Field names_UDateFormatStyle[] =
134 {
135 FIELD_NAME_STR( LEN_UDAT, UDAT_FULL ),
136 FIELD_NAME_STR( LEN_UDAT, UDAT_LONG ),
137 FIELD_NAME_STR( LEN_UDAT, UDAT_MEDIUM ),
138 FIELD_NAME_STR( LEN_UDAT, UDAT_SHORT ),
139 /* end regular */
140 /*
141 * negative enums.. leave out for now.
142 FIELD_NAME_STR( LEN_UDAT, UDAT_NONE ),
143 FIELD_NAME_STR( LEN_UDAT, UDAT_PATTERN ),
144 */
145 };
146
147 #endif
148
149 #include "unicode/uloc.h"
150
151 #define LEN_UAR 12 /* "ULOC_ACCEPT_" */
152 static const int32_t count_UAcceptResult = 3;
153 static const Field names_UAcceptResult[] =
154 {
155 FIELD_NAME_STR( LEN_UAR, ULOC_ACCEPT_FAILED ),
156 FIELD_NAME_STR( LEN_UAR, ULOC_ACCEPT_VALID ),
157 FIELD_NAME_STR( LEN_UAR, ULOC_ACCEPT_FALLBACK ),
158 };
159
160 #if !UCONFIG_NO_COLLATION
161 #include "unicode/ucol.h"
162 #define LEN_UCOL 5 /* UCOL_ */
163 static const int32_t count_UColAttributeValue = UCOL_ATTRIBUTE_VALUE_COUNT;
164 static const Field names_UColAttributeValue[] = {
165 FIELD_NAME_STR( LEN_UCOL, UCOL_PRIMARY ),
166 FIELD_NAME_STR( LEN_UCOL, UCOL_SECONDARY ),
167 FIELD_NAME_STR( LEN_UCOL, UCOL_TERTIARY ),
168 // FIELD_NAME_STR( LEN_UCOL, UCOL_CE_STRENGTH_LIMIT ),
169 FIELD_NAME_STR( LEN_UCOL, UCOL_QUATERNARY ),
170 // gap
171 FIELD_NAME_STR( LEN_UCOL, UCOL_IDENTICAL ),
172 // FIELD_NAME_STR( LEN_UCOL, UCOL_STRENGTH_LIMIT ),
173 FIELD_NAME_STR( LEN_UCOL, UCOL_OFF ),
174 FIELD_NAME_STR( LEN_UCOL, UCOL_ON ),
175 // gap
176 FIELD_NAME_STR( LEN_UCOL, UCOL_SHIFTED ),
177 FIELD_NAME_STR( LEN_UCOL, UCOL_NON_IGNORABLE ),
178 // gap
179 FIELD_NAME_STR( LEN_UCOL, UCOL_LOWER_FIRST ),
180 FIELD_NAME_STR( LEN_UCOL, UCOL_UPPER_FIRST ),
181 };
182
183 #endif
184
185
186 #include "unicode/icuplug.h"
187
188 #define LEN_UPLUG_REASON 13 /* UPLUG_REASON_ */
189 static const int32_t count_UPlugReason = UPLUG_REASON_COUNT;
190 static const Field names_UPlugReason[] = {
191 FIELD_NAME_STR( LEN_UPLUG_REASON, UPLUG_REASON_QUERY ),
192 FIELD_NAME_STR( LEN_UPLUG_REASON, UPLUG_REASON_LOAD ),
193 FIELD_NAME_STR( LEN_UPLUG_REASON, UPLUG_REASON_UNLOAD ),
194 };
195
196 #define LEN_UPLUG_LEVEL 12 /* UPLUG_LEVEL_ */
197 static const int32_t count_UPlugLevel = UPLUG_LEVEL_COUNT;
198 static const Field names_UPlugLevel[] = {
199 FIELD_NAME_STR( LEN_UPLUG_LEVEL, UPLUG_LEVEL_INVALID ),
200 FIELD_NAME_STR( LEN_UPLUG_LEVEL, UPLUG_LEVEL_UNKNOWN ),
201 FIELD_NAME_STR( LEN_UPLUG_LEVEL, UPLUG_LEVEL_LOW ),
202 FIELD_NAME_STR( LEN_UPLUG_LEVEL, UPLUG_LEVEL_HIGH ),
203 };
204
205 #define LEN_UDBG 5 /* "UDBG_" */
206 static const int32_t count_UDebugEnumType = UDBG_ENUM_COUNT;
207 static const Field names_UDebugEnumType[] =
208 {
209 FIELD_NAME_STR( LEN_UDBG, UDBG_UDebugEnumType ),
210 #if !UCONFIG_NO_FORMATTING
211 FIELD_NAME_STR( LEN_UDBG, UDBG_UCalendarDateFields ),
212 FIELD_NAME_STR( LEN_UDBG, UDBG_UCalendarMonths ),
213 FIELD_NAME_STR( LEN_UDBG, UDBG_UDateFormatStyle ),
214 #endif
215 FIELD_NAME_STR( LEN_UDBG, UDBG_UPlugReason ),
216 FIELD_NAME_STR( LEN_UDBG, UDBG_UPlugLevel ),
217 FIELD_NAME_STR( LEN_UDBG, UDBG_UAcceptResult ),
218 #if !UCONFIG_NO_COLLATION
219 FIELD_NAME_STR( LEN_UDBG, UDBG_UColAttributeValue ),
220 #endif
221 };
222
223
224 // --- Add new enum types above this line ---
225
226 #define COUNT_CASE(x) case UDBG_##x: return (actual?count_##x:DBG_ARRAY_COUNT(names_##x));
227 #define COUNT_FAIL_CASE(x) case UDBG_##x: return -1;
228
229 #define FIELD_CASE(x) case UDBG_##x: return names_##x;
230 #define FIELD_FAIL_CASE(x) case UDBG_##x: return NULL;
231
232 // low level
233
234 /**
235 * @param type type of item
236 * @param actual TRUE: for the actual enum's type (UCAL_FIELD_COUNT, etc), or FALSE for the string count
237 */
_udbg_enumCount(UDebugEnumType type,UBool actual)238 static int32_t _udbg_enumCount(UDebugEnumType type, UBool actual) {
239 switch(type) {
240 COUNT_CASE(UDebugEnumType)
241 #if !UCONFIG_NO_FORMATTING
242 COUNT_CASE(UCalendarDateFields)
243 COUNT_CASE(UCalendarMonths)
244 COUNT_CASE(UDateFormatStyle)
245 #endif
246 COUNT_CASE(UPlugReason)
247 COUNT_CASE(UPlugLevel)
248 COUNT_CASE(UAcceptResult)
249 #if !UCONFIG_NO_COLLATION
250 COUNT_CASE(UColAttributeValue)
251 #endif
252 // COUNT_FAIL_CASE(UNonExistentEnum)
253 default:
254 return -1;
255 }
256 }
257
_udbg_enumFields(UDebugEnumType type)258 static const Field* _udbg_enumFields(UDebugEnumType type) {
259 switch(type) {
260 FIELD_CASE(UDebugEnumType)
261 #if !UCONFIG_NO_FORMATTING
262 FIELD_CASE(UCalendarDateFields)
263 FIELD_CASE(UCalendarMonths)
264 FIELD_CASE(UDateFormatStyle)
265 #endif
266 FIELD_CASE(UPlugReason)
267 FIELD_CASE(UPlugLevel)
268 FIELD_CASE(UAcceptResult)
269 // FIELD_FAIL_CASE(UNonExistentEnum)
270 #if !UCONFIG_NO_COLLATION
271 FIELD_CASE(UColAttributeValue)
272 #endif
273 default:
274 return NULL;
275 }
276 }
277
278 // implementation
279
udbg_enumCount(UDebugEnumType type)280 int32_t udbg_enumCount(UDebugEnumType type) {
281 return _udbg_enumCount(type, FALSE);
282 }
283
udbg_enumExpectedCount(UDebugEnumType type)284 int32_t udbg_enumExpectedCount(UDebugEnumType type) {
285 return _udbg_enumCount(type, TRUE);
286 }
287
udbg_enumName(UDebugEnumType type,int32_t field)288 const char * udbg_enumName(UDebugEnumType type, int32_t field) {
289 if(field<0 ||
290 field>=_udbg_enumCount(type,FALSE)) { // also will catch unsupported items
291 return NULL;
292 } else {
293 const Field *fields = _udbg_enumFields(type);
294 if(fields == NULL) {
295 return NULL;
296 } else {
297 return fields[field].str + fields[field].prefix;
298 }
299 }
300 }
301
udbg_enumArrayValue(UDebugEnumType type,int32_t field)302 int32_t udbg_enumArrayValue(UDebugEnumType type, int32_t field) {
303 if(field<0 ||
304 field>=_udbg_enumCount(type,FALSE)) { // also will catch unsupported items
305 return -1;
306 } else {
307 const Field *fields = _udbg_enumFields(type);
308 if(fields == NULL) {
309 return -1;
310 } else {
311 return fields[field].num;
312 }
313 }
314 }
315
udbg_enumByName(UDebugEnumType type,const char * value)316 int32_t udbg_enumByName(UDebugEnumType type, const char *value) {
317 if(type<0||type>=_udbg_enumCount(UDBG_UDebugEnumType, TRUE)) {
318 return -1; // type out of range
319 }
320 const Field *fields = _udbg_enumFields(type);
321 for(int32_t field = 0;field<_udbg_enumCount(type, FALSE);field++) {
322 if(!strcmp(value, fields[field].str + fields[field].prefix)) {
323 return fields[field].num;
324 }
325 }
326 // try with the prefix
327 for(int32_t field = 0;field<_udbg_enumCount(type, FALSE);field++) {
328 if(!strcmp(value, fields[field].str)) {
329 return fields[field].num;
330 }
331 }
332 // fail
333 return -1;
334 }
335
336 /* platform info */
337 /**
338 * Print the current platform
339 */
udbg_getPlatform(void)340 U_CAPI const char *udbg_getPlatform(void)
341 {
342 #if U_PLATFORM_HAS_WIN32_API
343 return "Windows";
344 #elif U_PLATFORM == U_PF_UNKNOWN
345 return "unknown";
346 #elif U_PLATFORM == U_PF_DARWIN
347 return "Darwin";
348 #elif U_PLATFORM == U_PF_QNX
349 return "QNX";
350 #elif U_PLATFORM == U_PF_LINUX
351 return "Linux";
352 #elif U_PLATFORM == U_PF_ANDROID
353 return "Android";
354 #elif U_PLATFORM == U_PF_CLASSIC_MACOS
355 return "MacOS (Classic)";
356 #elif U_PLATFORM == U_PF_OS390
357 return "IBM z";
358 #elif U_PLATFORM == U_PF_OS400
359 return "IBM i";
360 #else
361 return "Other (POSIX-like)";
362 #endif
363 }
364
365 struct USystemParams;
366
367 typedef int32_t U_CALLCONV USystemParameterCallback(const USystemParams *param, char *target, int32_t targetCapacity, UErrorCode *status);
368
369 struct USystemParams {
370 const char *paramName;
371 USystemParameterCallback *paramFunction;
372 const char *paramStr;
373 int32_t paramInt;
374 };
375
376 /* parameter types */
377 U_CAPI int32_t
paramEmpty(const USystemParams *,char * target,int32_t targetCapacity,UErrorCode * status)378 paramEmpty(const USystemParams * /* param */, char *target, int32_t targetCapacity, UErrorCode *status) {
379 if(U_FAILURE(*status))return 0;
380 return u_terminateChars(target, targetCapacity, 0, status);
381 }
382
383 U_CAPI int32_t
paramStatic(const USystemParams * param,char * target,int32_t targetCapacity,UErrorCode * status)384 paramStatic(const USystemParams *param, char *target, int32_t targetCapacity, UErrorCode *status) {
385 if(param->paramStr==NULL) return paramEmpty(param,target,targetCapacity,status);
386 if(U_FAILURE(*status))return 0;
387 int32_t len = uprv_strlen(param->paramStr);
388 if(target!=NULL) {
389 uprv_strncpy(target,param->paramStr,uprv_min(len,targetCapacity));
390 }
391 return u_terminateChars(target, targetCapacity, len, status);
392 }
393
394 static const char *nullString = "(null)";
395
stringToStringBuffer(char * target,int32_t targetCapacity,const char * str,UErrorCode * status)396 static int32_t stringToStringBuffer(char *target, int32_t targetCapacity, const char *str, UErrorCode *status) {
397 if(str==NULL) str=nullString;
398
399 int32_t len = uprv_strlen(str);
400 if (U_SUCCESS(*status)) {
401 if(target!=NULL) {
402 uprv_strncpy(target,str,uprv_min(len,targetCapacity));
403 }
404 } else {
405 const char *s = u_errorName(*status);
406 len = uprv_strlen(s);
407 if(target!=NULL) {
408 uprv_strncpy(target,s,uprv_min(len,targetCapacity));
409 }
410 }
411 return u_terminateChars(target, targetCapacity, len, status);
412 }
413
integerToStringBuffer(char * target,int32_t targetCapacity,int32_t n,int32_t radix,UErrorCode * status)414 static int32_t integerToStringBuffer(char *target, int32_t targetCapacity, int32_t n, int32_t radix, UErrorCode *status) {
415 if(U_FAILURE(*status)) return 0;
416 char str[300];
417 T_CString_integerToString(str,n,radix);
418 return stringToStringBuffer(target,targetCapacity,str,status);
419 }
420
421 U_CAPI int32_t
paramInteger(const USystemParams * param,char * target,int32_t targetCapacity,UErrorCode * status)422 paramInteger(const USystemParams *param, char *target, int32_t targetCapacity, UErrorCode *status) {
423 if(U_FAILURE(*status))return 0;
424 if(param->paramStr==NULL || param->paramStr[0]=='d') {
425 return integerToStringBuffer(target,targetCapacity,param->paramInt, 10,status);
426 } else if(param->paramStr[0]=='x') {
427 return integerToStringBuffer(target,targetCapacity,param->paramInt, 16,status);
428 } else if(param->paramStr[0]=='o') {
429 return integerToStringBuffer(target,targetCapacity,param->paramInt, 8,status);
430 } else if(param->paramStr[0]=='b') {
431 return integerToStringBuffer(target,targetCapacity,param->paramInt, 2,status);
432 } else {
433 *status = U_INTERNAL_PROGRAM_ERROR;
434 return 0;
435 }
436 }
437
438
439 U_CAPI int32_t
paramCldrVersion(const USystemParams *,char * target,int32_t targetCapacity,UErrorCode * status)440 paramCldrVersion(const USystemParams * /* param */, char *target, int32_t targetCapacity, UErrorCode *status) {
441 if(U_FAILURE(*status))return 0;
442 char str[200]="";
443 UVersionInfo icu;
444
445 ulocdata_getCLDRVersion(icu, status);
446 if(U_SUCCESS(*status)) {
447 u_versionToString(icu, str);
448 return stringToStringBuffer(target,targetCapacity,str,status);
449 } else {
450 return 0;
451 }
452 }
453
454
455 #if !UCONFIG_NO_FORMATTING
456 U_CAPI int32_t
paramTimezoneDefault(const USystemParams *,char * target,int32_t targetCapacity,UErrorCode * status)457 paramTimezoneDefault(const USystemParams * /* param */, char *target, int32_t targetCapacity, UErrorCode *status) {
458 if(U_FAILURE(*status))return 0;
459 UChar buf[100];
460 char buf2[100];
461 int32_t len;
462
463 len = ucal_getDefaultTimeZone(buf, 100, status);
464 if(U_SUCCESS(*status)&&len>0) {
465 u_UCharsToChars(buf, buf2, len+1);
466 return stringToStringBuffer(target,targetCapacity, buf2,status);
467 } else {
468 return 0;
469 }
470 }
471 #endif
472
473 U_CAPI int32_t
paramLocaleDefaultBcp47(const USystemParams *,char * target,int32_t targetCapacity,UErrorCode * status)474 paramLocaleDefaultBcp47(const USystemParams * /* param */, char *target, int32_t targetCapacity, UErrorCode *status) {
475 if(U_FAILURE(*status))return 0;
476 const char *def = uloc_getDefault();
477 return uloc_toLanguageTag(def,target,targetCapacity,FALSE,status);
478 }
479
480
481 /* simple 1-liner param functions */
482 #define STRING_PARAM(func, str) U_CAPI int32_t \
483 func(const USystemParams *, char *target, int32_t targetCapacity, UErrorCode *status) \
484 { return stringToStringBuffer(target,targetCapacity,(str),status); }
485
486 STRING_PARAM(paramIcudataPath, u_getDataDirectory())
487 STRING_PARAM(paramPlatform, udbg_getPlatform())
488 STRING_PARAM(paramLocaleDefault, uloc_getDefault())
489 #if !UCONFIG_NO_CONVERSION
490 STRING_PARAM(paramConverterDefault, ucnv_getDefaultName())
491 #endif
492
493 #if !UCONFIG_NO_FORMATTING
494 STRING_PARAM(paramTimezoneVersion, ucal_getTZDataVersion(status))
495 #endif
496
497 static const USystemParams systemParams[] = {
498 { "copyright", paramStatic, U_COPYRIGHT_STRING,0 },
499 { "product", paramStatic, "icu4c",0 },
500 { "product.full", paramStatic, "International Components for Unicode for C/C++",0 },
501 { "version", paramStatic, U_ICU_VERSION,0 },
502 { "version.unicode", paramStatic, U_UNICODE_VERSION,0 },
503 { "platform.number", paramInteger, "d",U_PLATFORM},
504 { "platform.type", paramPlatform, NULL ,0},
505 { "locale.default", paramLocaleDefault, NULL, 0},
506 { "locale.default.bcp47", paramLocaleDefaultBcp47, NULL, 0},
507 #if !UCONFIG_NO_CONVERSION
508 { "converter.default", paramConverterDefault, NULL, 0},
509 #endif
510 { "icudata.name", paramStatic, U_ICUDATA_NAME, 0},
511 { "icudata.path", paramIcudataPath, NULL, 0},
512
513 { "cldr.version", paramCldrVersion, NULL, 0},
514
515 #if !UCONFIG_NO_FORMATTING
516 { "tz.version", paramTimezoneVersion, NULL, 0},
517 { "tz.default", paramTimezoneDefault, NULL, 0},
518 #endif
519
520 { "cpu.bits", paramInteger, "d", (sizeof(void*))*8},
521 { "cpu.big_endian", paramInteger, "b", U_IS_BIG_ENDIAN},
522 { "os.wchar_width", paramInteger, "d", U_SIZEOF_WCHAR_T},
523 { "os.charset_family", paramInteger, "d", U_CHARSET_FAMILY},
524 #if defined (U_HOST)
525 { "os.host", paramStatic, U_HOST, 0},
526 #endif
527 #if defined (U_BUILD)
528 { "build.build", paramStatic, U_BUILD, 0},
529 #endif
530 #if defined (U_CC)
531 { "build.cc", paramStatic, U_CC, 0},
532 #endif
533 #if defined (U_CXX)
534 { "build.cxx", paramStatic, U_CXX, 0},
535 #endif
536 #if defined (CYGWINMSVC)
537 { "build.cygwinmsvc", paramInteger, "b", 1},
538 #endif
539 { "uconfig.internal_digitlist", paramInteger, "b", 1}, /* always 1 */
540 { "uconfig.have_parseallinput", paramInteger, "b", UCONFIG_HAVE_PARSEALLINPUT},
541 { "uconfig.format_fastpaths_49",paramInteger, "b", UCONFIG_FORMAT_FASTPATHS_49},
542
543
544 };
545
546 #define U_SYSPARAM_COUNT (sizeof(systemParams)/sizeof(systemParams[0]))
547
udbg_getSystemParameterNameByIndex(int32_t i)548 U_CAPI const char *udbg_getSystemParameterNameByIndex(int32_t i) {
549 if(i>=0 && i < (int32_t)U_SYSPARAM_COUNT) {
550 return systemParams[i].paramName;
551 } else {
552 return NULL;
553 }
554 }
555
556
udbg_getSystemParameterValueByIndex(int32_t i,char * buffer,int32_t bufferCapacity,UErrorCode * status)557 U_CAPI int32_t udbg_getSystemParameterValueByIndex(int32_t i, char *buffer, int32_t bufferCapacity, UErrorCode *status) {
558 if(i>=0 && i< (int32_t)U_SYSPARAM_COUNT) {
559 return systemParams[i].paramFunction(&(systemParams[i]),buffer,bufferCapacity,status);
560 } else {
561 return 0;
562 }
563 }
564
udbg_writeIcuInfo(FILE * out)565 U_CAPI void udbg_writeIcuInfo(FILE *out) {
566 char str[2000];
567 /* todo: API for writing DTD? */
568 fprintf(out, " <icuSystemParams type=\"icu4c\">\n");
569 const char *paramName;
570 for(int32_t i=0;(paramName=udbg_getSystemParameterNameByIndex(i))!=NULL;i++) {
571 UErrorCode status2 = U_ZERO_ERROR;
572 udbg_getSystemParameterValueByIndex(i, str,2000,&status2);
573 if(U_SUCCESS(status2)) {
574 fprintf(out," <param name=\"%s\">%s</param>\n", paramName,str);
575 } else {
576 fprintf(out," <!-- n=\"%s\" ERROR: %s -->\n", paramName, u_errorName(status2));
577 }
578 }
579 fprintf(out, " </icuSystemParams>\n");
580 }
581