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