michael@0: /******************************************************************** michael@0: * COPYRIGHT: michael@0: * Copyright (c) 2007-2013, International Business Machines Corporation and michael@0: * others. All Rights Reserved. michael@0: ********************************************************************/ michael@0: michael@0: #include "udbgutil.h" michael@0: #include michael@0: #include "ustr_imp.h" michael@0: #include "cstring.h" michael@0: #include "putilimp.h" michael@0: #include "unicode/ulocdata.h" michael@0: #include "unicode/ucnv.h" michael@0: #include "unicode/unistr.h" michael@0: michael@0: /* michael@0: To add a new enum type michael@0: (For example: UShoeSize with values USHOE_WIDE=0, USHOE_REGULAR, USHOE_NARROW, USHOE_COUNT) michael@0: michael@0: 1. udbgutil.h: add UDBG_UShoeSize to the UDebugEnumType enum before UDBG_ENUM_COUNT michael@0: ( The subsequent steps involve this file, udbgutil.cpp ) michael@0: 2. Find the marker "Add new enum types above this line" michael@0: 3. Before that marker, add a #include of any header file you need. michael@0: 4. Each enum type has three things in this section: a #define, a count_, and an array of Fields. michael@0: It may help to copy and paste a previous definition. michael@0: 5. In the case of the USHOE_... strings above, "USHOE_" is common to all values- six characters michael@0: " #define LEN_USHOE 6 " michael@0: 6 characters will strip off "USHOE_" leaving enum values of WIDE, REGULAR, and NARROW. michael@0: 6. Define the 'count_' variable, with the number of enum values. If the enum has a _MAX or _COUNT value, michael@0: that can be helpful for automatically defining the count. Otherwise define it manually. michael@0: " static const int32_t count_UShoeSize = USHOE_COUNT; " michael@0: 7. Define the field names, in order. michael@0: " static const Field names_UShoeSize[] = { michael@0: " FIELD_NAME_STR( LEN_USHOE, USHOE_WIDE ), michael@0: " FIELD_NAME_STR( LEN_USHOE, USHOE_REGULAR ), michael@0: " FIELD_NAME_STR( LEN_USHOE, USHOE_NARROW ), michael@0: " }; michael@0: ( The following command was usedfor converting ucol.h into partially correct entities ) michael@0: grep "^[ ]*UCOL" < unicode/ucol.h | michael@0: sed -e 's%^[ ]*\([A-Z]*\)_\([A-Z_]*\).*% FIELD_NAME_STR( LEN_\1, \1_\2 ),%g' michael@0: 8. Now, a bit farther down, add the name of the enum itself to the end of names_UDebugEnumType michael@0: ( UDebugEnumType is an enum, too!) michael@0: names_UDebugEnumType[] { ... michael@0: " FIELD_NAME_STR( LEN_UDBG, UDBG_UShoeSize ), " michael@0: 9. Find the function _udbg_enumCount and add the count macro: michael@0: " COUNT_CASE(UShoeSize) michael@0: 10. Find the function _udbg_enumFields and add the field macro: michael@0: " FIELD_CASE(UShoeSize) michael@0: 11. verify that your test code, and Java data generation, works properly. michael@0: */ michael@0: michael@0: /** michael@0: * Structure representing an enum value michael@0: */ michael@0: struct Field { michael@0: int32_t prefix; /**< how many characters to remove in the prefix - i.e. UCHAR_ = 5 */ michael@0: const char *str; /**< The actual string value */ michael@0: int32_t num; /**< The numeric value */ michael@0: }; michael@0: michael@0: /** michael@0: * Calculate the size of an array. michael@0: */ michael@0: #define DBG_ARRAY_COUNT(x) (sizeof(x)/sizeof(x[0])) michael@0: michael@0: /** michael@0: * Define another field name. Used in an array of Field s michael@0: * @param y the common prefix length (i.e. 6 for "USHOE_" ) michael@0: * @param x the actual enum value - it will be copied in both string and symbolic form. michael@0: * @see Field michael@0: */ michael@0: #define FIELD_NAME_STR(y,x) { y, #x, x } michael@0: michael@0: michael@0: // TODO: Currently, this whole functionality goes away with UCONFIG_NO_FORMATTING. Should be split up. michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: // Calendar michael@0: #include "unicode/ucal.h" michael@0: michael@0: // 'UCAL_' = 5 michael@0: #define LEN_UCAL 5 /* UCAL_ */ michael@0: static const int32_t count_UCalendarDateFields = UCAL_FIELD_COUNT; michael@0: static const Field names_UCalendarDateFields[] = michael@0: { michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_ERA ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_YEAR ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_MONTH ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_WEEK_OF_YEAR ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_WEEK_OF_MONTH ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_DATE ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_DAY_OF_YEAR ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_DAY_OF_WEEK ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_DAY_OF_WEEK_IN_MONTH ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_AM_PM ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_HOUR ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_HOUR_OF_DAY ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_MINUTE ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_SECOND ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_MILLISECOND ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_ZONE_OFFSET ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_DST_OFFSET ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_YEAR_WOY ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_DOW_LOCAL ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_EXTENDED_YEAR ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_JULIAN_DAY ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_MILLISECONDS_IN_DAY ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_IS_LEAP_MONTH ), michael@0: }; michael@0: michael@0: michael@0: static const int32_t count_UCalendarMonths = UCAL_UNDECIMBER+1; michael@0: static const Field names_UCalendarMonths[] = michael@0: { michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_JANUARY ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_FEBRUARY ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_MARCH ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_APRIL ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_MAY ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_JUNE ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_JULY ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_AUGUST ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_SEPTEMBER ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_OCTOBER ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_NOVEMBER ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_DECEMBER ), michael@0: FIELD_NAME_STR( LEN_UCAL, UCAL_UNDECIMBER) michael@0: }; michael@0: michael@0: #include "unicode/udat.h" michael@0: michael@0: #define LEN_UDAT 5 /* "UDAT_" */ michael@0: static const int32_t count_UDateFormatStyle = UDAT_SHORT+1; michael@0: static const Field names_UDateFormatStyle[] = michael@0: { michael@0: FIELD_NAME_STR( LEN_UDAT, UDAT_FULL ), michael@0: FIELD_NAME_STR( LEN_UDAT, UDAT_LONG ), michael@0: FIELD_NAME_STR( LEN_UDAT, UDAT_MEDIUM ), michael@0: FIELD_NAME_STR( LEN_UDAT, UDAT_SHORT ), michael@0: /* end regular */ michael@0: /* michael@0: * negative enums.. leave out for now. michael@0: FIELD_NAME_STR( LEN_UDAT, UDAT_NONE ), michael@0: FIELD_NAME_STR( LEN_UDAT, UDAT_PATTERN ), michael@0: */ michael@0: }; michael@0: michael@0: #endif michael@0: michael@0: #include "unicode/uloc.h" michael@0: michael@0: #define LEN_UAR 12 /* "ULOC_ACCEPT_" */ michael@0: static const int32_t count_UAcceptResult = 3; michael@0: static const Field names_UAcceptResult[] = michael@0: { michael@0: FIELD_NAME_STR( LEN_UAR, ULOC_ACCEPT_FAILED ), michael@0: FIELD_NAME_STR( LEN_UAR, ULOC_ACCEPT_VALID ), michael@0: FIELD_NAME_STR( LEN_UAR, ULOC_ACCEPT_FALLBACK ), michael@0: }; michael@0: michael@0: #if !UCONFIG_NO_COLLATION michael@0: #include "unicode/ucol.h" michael@0: #define LEN_UCOL 5 /* UCOL_ */ michael@0: static const int32_t count_UColAttributeValue = UCOL_ATTRIBUTE_VALUE_COUNT; michael@0: static const Field names_UColAttributeValue[] = { michael@0: FIELD_NAME_STR( LEN_UCOL, UCOL_PRIMARY ), michael@0: FIELD_NAME_STR( LEN_UCOL, UCOL_SECONDARY ), michael@0: FIELD_NAME_STR( LEN_UCOL, UCOL_TERTIARY ), michael@0: // FIELD_NAME_STR( LEN_UCOL, UCOL_CE_STRENGTH_LIMIT ), michael@0: FIELD_NAME_STR( LEN_UCOL, UCOL_QUATERNARY ), michael@0: // gap michael@0: FIELD_NAME_STR( LEN_UCOL, UCOL_IDENTICAL ), michael@0: // FIELD_NAME_STR( LEN_UCOL, UCOL_STRENGTH_LIMIT ), michael@0: FIELD_NAME_STR( LEN_UCOL, UCOL_OFF ), michael@0: FIELD_NAME_STR( LEN_UCOL, UCOL_ON ), michael@0: // gap michael@0: FIELD_NAME_STR( LEN_UCOL, UCOL_SHIFTED ), michael@0: FIELD_NAME_STR( LEN_UCOL, UCOL_NON_IGNORABLE ), michael@0: // gap michael@0: FIELD_NAME_STR( LEN_UCOL, UCOL_LOWER_FIRST ), michael@0: FIELD_NAME_STR( LEN_UCOL, UCOL_UPPER_FIRST ), michael@0: }; michael@0: michael@0: #endif michael@0: michael@0: michael@0: #include "unicode/icuplug.h" michael@0: michael@0: #define LEN_UPLUG_REASON 13 /* UPLUG_REASON_ */ michael@0: static const int32_t count_UPlugReason = UPLUG_REASON_COUNT; michael@0: static const Field names_UPlugReason[] = { michael@0: FIELD_NAME_STR( LEN_UPLUG_REASON, UPLUG_REASON_QUERY ), michael@0: FIELD_NAME_STR( LEN_UPLUG_REASON, UPLUG_REASON_LOAD ), michael@0: FIELD_NAME_STR( LEN_UPLUG_REASON, UPLUG_REASON_UNLOAD ), michael@0: }; michael@0: michael@0: #define LEN_UPLUG_LEVEL 12 /* UPLUG_LEVEL_ */ michael@0: static const int32_t count_UPlugLevel = UPLUG_LEVEL_COUNT; michael@0: static const Field names_UPlugLevel[] = { michael@0: FIELD_NAME_STR( LEN_UPLUG_LEVEL, UPLUG_LEVEL_INVALID ), michael@0: FIELD_NAME_STR( LEN_UPLUG_LEVEL, UPLUG_LEVEL_UNKNOWN ), michael@0: FIELD_NAME_STR( LEN_UPLUG_LEVEL, UPLUG_LEVEL_LOW ), michael@0: FIELD_NAME_STR( LEN_UPLUG_LEVEL, UPLUG_LEVEL_HIGH ), michael@0: }; michael@0: michael@0: #define LEN_UDBG 5 /* "UDBG_" */ michael@0: static const int32_t count_UDebugEnumType = UDBG_ENUM_COUNT; michael@0: static const Field names_UDebugEnumType[] = michael@0: { michael@0: FIELD_NAME_STR( LEN_UDBG, UDBG_UDebugEnumType ), michael@0: #if !UCONFIG_NO_FORMATTING michael@0: FIELD_NAME_STR( LEN_UDBG, UDBG_UCalendarDateFields ), michael@0: FIELD_NAME_STR( LEN_UDBG, UDBG_UCalendarMonths ), michael@0: FIELD_NAME_STR( LEN_UDBG, UDBG_UDateFormatStyle ), michael@0: #endif michael@0: FIELD_NAME_STR( LEN_UDBG, UDBG_UPlugReason ), michael@0: FIELD_NAME_STR( LEN_UDBG, UDBG_UPlugLevel ), michael@0: FIELD_NAME_STR( LEN_UDBG, UDBG_UAcceptResult ), michael@0: #if !UCONFIG_NO_COLLATION michael@0: FIELD_NAME_STR( LEN_UDBG, UDBG_UColAttributeValue ), michael@0: #endif michael@0: }; michael@0: michael@0: michael@0: // --- Add new enum types above this line --- michael@0: michael@0: #define COUNT_CASE(x) case UDBG_##x: return (actual?count_##x:DBG_ARRAY_COUNT(names_##x)); michael@0: #define COUNT_FAIL_CASE(x) case UDBG_##x: return -1; michael@0: michael@0: #define FIELD_CASE(x) case UDBG_##x: return names_##x; michael@0: #define FIELD_FAIL_CASE(x) case UDBG_##x: return NULL; michael@0: michael@0: // low level michael@0: michael@0: /** michael@0: * @param type type of item michael@0: * @param actual TRUE: for the actual enum's type (UCAL_FIELD_COUNT, etc), or FALSE for the string count michael@0: */ michael@0: static int32_t _udbg_enumCount(UDebugEnumType type, UBool actual) { michael@0: switch(type) { michael@0: COUNT_CASE(UDebugEnumType) michael@0: #if !UCONFIG_NO_FORMATTING michael@0: COUNT_CASE(UCalendarDateFields) michael@0: COUNT_CASE(UCalendarMonths) michael@0: COUNT_CASE(UDateFormatStyle) michael@0: #endif michael@0: COUNT_CASE(UPlugReason) michael@0: COUNT_CASE(UPlugLevel) michael@0: COUNT_CASE(UAcceptResult) michael@0: #if !UCONFIG_NO_COLLATION michael@0: COUNT_CASE(UColAttributeValue) michael@0: #endif michael@0: // COUNT_FAIL_CASE(UNonExistentEnum) michael@0: default: michael@0: return -1; michael@0: } michael@0: } michael@0: michael@0: static const Field* _udbg_enumFields(UDebugEnumType type) { michael@0: switch(type) { michael@0: FIELD_CASE(UDebugEnumType) michael@0: #if !UCONFIG_NO_FORMATTING michael@0: FIELD_CASE(UCalendarDateFields) michael@0: FIELD_CASE(UCalendarMonths) michael@0: FIELD_CASE(UDateFormatStyle) michael@0: #endif michael@0: FIELD_CASE(UPlugReason) michael@0: FIELD_CASE(UPlugLevel) michael@0: FIELD_CASE(UAcceptResult) michael@0: // FIELD_FAIL_CASE(UNonExistentEnum) michael@0: #if !UCONFIG_NO_COLLATION michael@0: FIELD_CASE(UColAttributeValue) michael@0: #endif michael@0: default: michael@0: return NULL; michael@0: } michael@0: } michael@0: michael@0: // implementation michael@0: michael@0: int32_t udbg_enumCount(UDebugEnumType type) { michael@0: return _udbg_enumCount(type, FALSE); michael@0: } michael@0: michael@0: int32_t udbg_enumExpectedCount(UDebugEnumType type) { michael@0: return _udbg_enumCount(type, TRUE); michael@0: } michael@0: michael@0: const char * udbg_enumName(UDebugEnumType type, int32_t field) { michael@0: if(field<0 || michael@0: field>=_udbg_enumCount(type,FALSE)) { // also will catch unsupported items michael@0: return NULL; michael@0: } else { michael@0: const Field *fields = _udbg_enumFields(type); michael@0: if(fields == NULL) { michael@0: return NULL; michael@0: } else { michael@0: return fields[field].str + fields[field].prefix; michael@0: } michael@0: } michael@0: } michael@0: michael@0: int32_t udbg_enumArrayValue(UDebugEnumType type, int32_t field) { michael@0: if(field<0 || michael@0: field>=_udbg_enumCount(type,FALSE)) { // also will catch unsupported items michael@0: return -1; michael@0: } else { michael@0: const Field *fields = _udbg_enumFields(type); michael@0: if(fields == NULL) { michael@0: return -1; michael@0: } else { michael@0: return fields[field].num; michael@0: } michael@0: } michael@0: } michael@0: michael@0: int32_t udbg_enumByName(UDebugEnumType type, const char *value) { michael@0: if(type<0||type>=_udbg_enumCount(UDBG_UDebugEnumType, TRUE)) { michael@0: return -1; // type out of range michael@0: } michael@0: const Field *fields = _udbg_enumFields(type); michael@0: for(int32_t field = 0;field<_udbg_enumCount(type, FALSE);field++) { michael@0: if(!strcmp(value, fields[field].str + fields[field].prefix)) { michael@0: return fields[field].num; michael@0: } michael@0: } michael@0: // try with the prefix michael@0: for(int32_t field = 0;field<_udbg_enumCount(type, FALSE);field++) { michael@0: if(!strcmp(value, fields[field].str)) { michael@0: return fields[field].num; michael@0: } michael@0: } michael@0: // fail michael@0: return -1; michael@0: } michael@0: michael@0: /* platform info */ michael@0: /** michael@0: * Print the current platform michael@0: */ michael@0: U_CAPI const char *udbg_getPlatform(void) michael@0: { michael@0: #if U_PLATFORM_HAS_WIN32_API michael@0: return "Windows"; michael@0: #elif U_PLATFORM == U_PF_UNKNOWN michael@0: return "unknown"; michael@0: #elif U_PLATFORM == U_PF_DARWIN michael@0: return "Darwin"; michael@0: #elif U_PLATFORM == U_PF_BSD michael@0: return "BSD"; michael@0: #elif U_PLATFORM == U_PF_QNX michael@0: return "QNX"; michael@0: #elif U_PLATFORM == U_PF_LINUX michael@0: return "Linux"; michael@0: #elif U_PLATFORM == U_PF_ANDROID michael@0: return "Android"; michael@0: #elif U_PLATFORM == U_PF_CLASSIC_MACOS michael@0: return "MacOS (Classic)"; michael@0: #elif U_PLATFORM == U_PF_OS390 michael@0: return "IBM z"; michael@0: #elif U_PLATFORM == U_PF_OS400 michael@0: return "IBM i"; michael@0: #else michael@0: return "Other (POSIX-like)"; michael@0: #endif michael@0: } michael@0: michael@0: struct USystemParams; michael@0: michael@0: typedef int32_t U_CALLCONV USystemParameterCallback(const USystemParams *param, char *target, int32_t targetCapacity, UErrorCode *status); michael@0: michael@0: struct USystemParams { michael@0: const char *paramName; michael@0: USystemParameterCallback *paramFunction; michael@0: const char *paramStr; michael@0: int32_t paramInt; michael@0: }; michael@0: michael@0: /* parameter types */ michael@0: U_CAPI int32_t michael@0: paramEmpty(const USystemParams * /* param */, char *target, int32_t targetCapacity, UErrorCode *status) { michael@0: if(U_FAILURE(*status))return 0; michael@0: return u_terminateChars(target, targetCapacity, 0, status); michael@0: } michael@0: michael@0: U_CAPI int32_t michael@0: paramStatic(const USystemParams *param, char *target, int32_t targetCapacity, UErrorCode *status) { michael@0: if(param->paramStr==NULL) return paramEmpty(param,target,targetCapacity,status); michael@0: if(U_FAILURE(*status))return 0; michael@0: int32_t len = uprv_strlen(param->paramStr); michael@0: if(target!=NULL) { michael@0: uprv_strncpy(target,param->paramStr,uprv_min(len,targetCapacity)); michael@0: } michael@0: return u_terminateChars(target, targetCapacity, len, status); michael@0: } michael@0: michael@0: static const char *nullString = "(null)"; michael@0: michael@0: static int32_t stringToStringBuffer(char *target, int32_t targetCapacity, const char *str, UErrorCode *status) { michael@0: if(str==NULL) str=nullString; michael@0: michael@0: int32_t len = uprv_strlen(str); michael@0: if (U_SUCCESS(*status)) { michael@0: if(target!=NULL) { michael@0: uprv_strncpy(target,str,uprv_min(len,targetCapacity)); michael@0: } michael@0: } else { michael@0: const char *s = u_errorName(*status); michael@0: len = uprv_strlen(s); michael@0: if(target!=NULL) { michael@0: uprv_strncpy(target,s,uprv_min(len,targetCapacity)); michael@0: } michael@0: } michael@0: return u_terminateChars(target, targetCapacity, len, status); michael@0: } michael@0: michael@0: static int32_t integerToStringBuffer(char *target, int32_t targetCapacity, int32_t n, int32_t radix, UErrorCode *status) { michael@0: if(U_FAILURE(*status)) return 0; michael@0: char str[300]; michael@0: T_CString_integerToString(str,n,radix); michael@0: return stringToStringBuffer(target,targetCapacity,str,status); michael@0: } michael@0: michael@0: U_CAPI int32_t michael@0: paramInteger(const USystemParams *param, char *target, int32_t targetCapacity, UErrorCode *status) { michael@0: if(U_FAILURE(*status))return 0; michael@0: if(param->paramStr==NULL || param->paramStr[0]=='d') { michael@0: return integerToStringBuffer(target,targetCapacity,param->paramInt, 10,status); michael@0: } else if(param->paramStr[0]=='x') { michael@0: return integerToStringBuffer(target,targetCapacity,param->paramInt, 16,status); michael@0: } else if(param->paramStr[0]=='o') { michael@0: return integerToStringBuffer(target,targetCapacity,param->paramInt, 8,status); michael@0: } else if(param->paramStr[0]=='b') { michael@0: return integerToStringBuffer(target,targetCapacity,param->paramInt, 2,status); michael@0: } else { michael@0: *status = U_INTERNAL_PROGRAM_ERROR; michael@0: return 0; michael@0: } michael@0: } michael@0: michael@0: michael@0: U_CAPI int32_t michael@0: paramCldrVersion(const USystemParams * /* param */, char *target, int32_t targetCapacity, UErrorCode *status) { michael@0: if(U_FAILURE(*status))return 0; michael@0: char str[200]=""; michael@0: UVersionInfo icu; michael@0: michael@0: ulocdata_getCLDRVersion(icu, status); michael@0: if(U_SUCCESS(*status)) { michael@0: u_versionToString(icu, str); michael@0: return stringToStringBuffer(target,targetCapacity,str,status); michael@0: } else { michael@0: return 0; michael@0: } michael@0: } michael@0: michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: U_CAPI int32_t michael@0: paramTimezoneDefault(const USystemParams * /* param */, char *target, int32_t targetCapacity, UErrorCode *status) { michael@0: if(U_FAILURE(*status))return 0; michael@0: UChar buf[100]; michael@0: char buf2[100]; michael@0: int32_t len; michael@0: michael@0: len = ucal_getDefaultTimeZone(buf, 100, status); michael@0: if(U_SUCCESS(*status)&&len>0) { michael@0: u_UCharsToChars(buf, buf2, len+1); michael@0: return stringToStringBuffer(target,targetCapacity, buf2,status); michael@0: } else { michael@0: return 0; michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: U_CAPI int32_t michael@0: paramLocaleDefaultBcp47(const USystemParams * /* param */, char *target, int32_t targetCapacity, UErrorCode *status) { michael@0: if(U_FAILURE(*status))return 0; michael@0: const char *def = uloc_getDefault(); michael@0: return uloc_toLanguageTag(def,target,targetCapacity,FALSE,status); michael@0: } michael@0: michael@0: michael@0: /* simple 1-liner param functions */ michael@0: #define STRING_PARAM(func, str) U_CAPI int32_t \ michael@0: func(const USystemParams *, char *target, int32_t targetCapacity, UErrorCode *status) \ michael@0: { return stringToStringBuffer(target,targetCapacity,(str),status); } michael@0: michael@0: STRING_PARAM(paramIcudataPath, u_getDataDirectory()) michael@0: STRING_PARAM(paramPlatform, udbg_getPlatform()) michael@0: STRING_PARAM(paramLocaleDefault, uloc_getDefault()) michael@0: #if !UCONFIG_NO_CONVERSION michael@0: STRING_PARAM(paramConverterDefault, ucnv_getDefaultName()) michael@0: #endif michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: STRING_PARAM(paramTimezoneVersion, ucal_getTZDataVersion(status)) michael@0: #endif michael@0: michael@0: static const USystemParams systemParams[] = { michael@0: { "copyright", paramStatic, U_COPYRIGHT_STRING,0 }, michael@0: { "product", paramStatic, "icu4c",0 }, michael@0: { "product.full", paramStatic, "International Components for Unicode for C/C++",0 }, michael@0: { "version", paramStatic, U_ICU_VERSION,0 }, michael@0: { "version.unicode", paramStatic, U_UNICODE_VERSION,0 }, michael@0: { "platform.number", paramInteger, "d",U_PLATFORM}, michael@0: { "platform.type", paramPlatform, NULL ,0}, michael@0: { "locale.default", paramLocaleDefault, NULL, 0}, michael@0: { "locale.default.bcp47", paramLocaleDefaultBcp47, NULL, 0}, michael@0: #if !UCONFIG_NO_CONVERSION michael@0: { "converter.default", paramConverterDefault, NULL, 0}, michael@0: #endif michael@0: { "icudata.name", paramStatic, U_ICUDATA_NAME, 0}, michael@0: { "icudata.path", paramIcudataPath, NULL, 0}, michael@0: michael@0: { "cldr.version", paramCldrVersion, NULL, 0}, michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: { "tz.version", paramTimezoneVersion, NULL, 0}, michael@0: { "tz.default", paramTimezoneDefault, NULL, 0}, michael@0: #endif michael@0: michael@0: { "cpu.bits", paramInteger, "d", (sizeof(void*))*8}, michael@0: { "cpu.big_endian", paramInteger, "b", U_IS_BIG_ENDIAN}, michael@0: { "os.wchar_width", paramInteger, "d", U_SIZEOF_WCHAR_T}, michael@0: { "os.charset_family", paramInteger, "d", U_CHARSET_FAMILY}, michael@0: #if defined (U_HOST) michael@0: { "os.host", paramStatic, U_HOST, 0}, michael@0: #endif michael@0: #if defined (U_BUILD) michael@0: { "build.build", paramStatic, U_BUILD, 0}, michael@0: #endif michael@0: #if defined (U_CC) michael@0: { "build.cc", paramStatic, U_CC, 0}, michael@0: #endif michael@0: #if defined (U_CXX) michael@0: { "build.cxx", paramStatic, U_CXX, 0}, michael@0: #endif michael@0: #if defined (CYGWINMSVC) michael@0: { "build.cygwinmsvc", paramInteger, "b", 1}, michael@0: #endif michael@0: { "uconfig.internal_digitlist", paramInteger, "b", 1}, /* always 1 */ michael@0: { "uconfig.have_parseallinput", paramInteger, "b", UCONFIG_HAVE_PARSEALLINPUT}, michael@0: { "uconfig.format_fastpaths_49",paramInteger, "b", UCONFIG_FORMAT_FASTPATHS_49}, michael@0: michael@0: michael@0: }; michael@0: michael@0: #define U_SYSPARAM_COUNT (sizeof(systemParams)/sizeof(systemParams[0])) michael@0: michael@0: U_CAPI const char *udbg_getSystemParameterNameByIndex(int32_t i) { michael@0: if(i>=0 && i < (int32_t)U_SYSPARAM_COUNT) { michael@0: return systemParams[i].paramName; michael@0: } else { michael@0: return NULL; michael@0: } michael@0: } michael@0: michael@0: michael@0: U_CAPI int32_t udbg_getSystemParameterValueByIndex(int32_t i, char *buffer, int32_t bufferCapacity, UErrorCode *status) { michael@0: if(i>=0 && i< (int32_t)U_SYSPARAM_COUNT) { michael@0: return systemParams[i].paramFunction(&(systemParams[i]),buffer,bufferCapacity,status); michael@0: } else { michael@0: return 0; michael@0: } michael@0: } michael@0: michael@0: U_CAPI void udbg_writeIcuInfo(FILE *out) { michael@0: char str[2000]; michael@0: /* todo: API for writing DTD? */ michael@0: fprintf(out, " \n"); michael@0: const char *paramName; michael@0: for(int32_t i=0;(paramName=udbg_getSystemParameterNameByIndex(i))!=NULL;i++) { michael@0: UErrorCode status2 = U_ZERO_ERROR; michael@0: udbg_getSystemParameterValueByIndex(i, str,2000,&status2); michael@0: if(U_SUCCESS(status2)) { michael@0: fprintf(out," %s\n", paramName,str); michael@0: } else { michael@0: fprintf(out," \n", paramName, u_errorName(status2)); michael@0: } michael@0: } michael@0: fprintf(out, " \n"); michael@0: } michael@0: michael@0: #define ICU_TRAC_URL "http://bugs.icu-project.org/trac/ticket/" michael@0: #define CLDR_TRAC_URL "http://unicode.org/cldr/trac/ticket/" michael@0: #define CLDR_TICKET_PREFIX "cldrbug:" michael@0: michael@0: U_CAPI char *udbg_knownIssueURLFrom(const char *ticket, char *buf) { michael@0: if( ticket==NULL ) { michael@0: return NULL; michael@0: } michael@0: michael@0: if( !strncmp(ticket, CLDR_TICKET_PREFIX, strlen(CLDR_TICKET_PREFIX)) ) { michael@0: strcpy( buf, CLDR_TRAC_URL ); michael@0: strcat( buf, ticket+strlen(CLDR_TICKET_PREFIX) ); michael@0: } else { michael@0: strcpy( buf, ICU_TRAC_URL ); michael@0: strcat( buf, ticket ); michael@0: } michael@0: return buf; michael@0: } michael@0: michael@0: michael@0: #if !U_HAVE_STD_STRING michael@0: const char *warning = "WARNING: Don't have std::string (STL) - known issue logs will be deficient."; michael@0: michael@0: U_CAPI void *udbg_knownIssue_openU(void *ptr, const char *ticket, char *where, const UChar *msg, UBool *firstForTicket, michael@0: UBool *firstForWhere) { michael@0: if(ptr==NULL) { michael@0: puts(warning); michael@0: } michael@0: printf("%s\tKnown Issue #%s\n", where, ticket); michael@0: michael@0: return (void*)warning; michael@0: } michael@0: michael@0: U_CAPI void *udbg_knownIssue_open(void *ptr, const char *ticket, char *where, const char *msg, UBool *firstForTicket, michael@0: UBool *firstForWhere) { michael@0: if(ptr==NULL) { michael@0: puts(warning); michael@0: } michael@0: if(msg==NULL) msg = ""; michael@0: printf("%s\tKnown Issue #%s \"%s\n", where, ticket, msg); michael@0: michael@0: return (void*)warning; michael@0: } michael@0: michael@0: U_CAPI UBool udbg_knownIssue_print(void *ptr) { michael@0: puts(warning); michael@0: return FALSE; michael@0: } michael@0: michael@0: U_CAPI void udbg_knownIssue_close(void *ptr) { michael@0: // nothing to do michael@0: } michael@0: #else michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: class KnownIssues { michael@0: public: michael@0: KnownIssues(); michael@0: ~KnownIssues(); michael@0: void add(const char *ticket, const char *where, const UChar *msg, UBool *firstForTicket, UBool *firstForWhere); michael@0: void add(const char *ticket, const char *where, const char *msg, UBool *firstForTicket, UBool *firstForWhere); michael@0: UBool print(); michael@0: private: michael@0: std::map< std::string, michael@0: std::map < std::string, std::set < std::string > > > fTable; michael@0: }; michael@0: michael@0: KnownIssues::KnownIssues() michael@0: : fTable() michael@0: { michael@0: } michael@0: michael@0: KnownIssues::~KnownIssues() michael@0: { michael@0: } michael@0: michael@0: void KnownIssues::add(const char *ticket, const char *where, const UChar *msg, UBool *firstForTicket, UBool *firstForWhere) michael@0: { michael@0: if(fTable.find(ticket) == fTable.end()) { michael@0: if(firstForTicket!=NULL) *firstForTicket = TRUE; michael@0: fTable[ticket] = std::map < std::string, std::set < std::string > >(); michael@0: } else { michael@0: if(firstForTicket!=NULL) *firstForTicket = FALSE; michael@0: } michael@0: if(where==NULL) return; michael@0: michael@0: if(fTable[ticket].find(where) == fTable[ticket].end()) { michael@0: if(firstForWhere!=NULL) *firstForWhere = TRUE; michael@0: fTable[ticket][where] = std::set < std::string >(); michael@0: } else { michael@0: if(firstForWhere!=NULL) *firstForWhere = FALSE; michael@0: } michael@0: if(msg==NULL || !*msg) return; michael@0: michael@0: std::string str; michael@0: fTable[ticket][where].insert(icu::UnicodeString(msg).toUTF8String(str)); michael@0: } michael@0: michael@0: void KnownIssues::add(const char *ticket, const char *where, const char *msg, UBool *firstForTicket, UBool *firstForWhere) michael@0: { michael@0: if(fTable.find(ticket) == fTable.end()) { michael@0: if(firstForTicket!=NULL) *firstForTicket = TRUE; michael@0: fTable[ticket] = std::map < std::string, std::set < std::string > >(); michael@0: } else { michael@0: if(firstForTicket!=NULL) *firstForTicket = FALSE; michael@0: } michael@0: if(where==NULL) return; michael@0: michael@0: if(fTable[ticket].find(where) == fTable[ticket].end()) { michael@0: if(firstForWhere!=NULL) *firstForWhere = TRUE; michael@0: fTable[ticket][where] = std::set < std::string >(); michael@0: } else { michael@0: if(firstForWhere!=NULL) *firstForWhere = FALSE; michael@0: } michael@0: if(msg==NULL || !*msg) return; michael@0: michael@0: std::string str(msg); michael@0: fTable[ticket][where].insert(str); michael@0: } michael@0: michael@0: UBool KnownIssues::print() michael@0: { michael@0: if(fTable.empty()) { michael@0: return FALSE; michael@0: } michael@0: michael@0: std::cout << "KNOWN ISSUES" << std::endl; michael@0: for( std::map< std::string, michael@0: std::map < std::string, std::set < std::string > > >::iterator i = fTable.begin(); michael@0: i != fTable.end(); michael@0: i++ ) { michael@0: char URL[1024]; michael@0: std::cout << '#' << (*i).first << " <" << udbg_knownIssueURLFrom( (*i).first.c_str(), URL ) << ">" << std::endl; michael@0: michael@0: for( std::map< std::string, std::set < std::string > >::iterator ii = (*i).second.begin(); michael@0: ii != (*i).second.end(); michael@0: ii++ ) { michael@0: std::cout << " " << (*ii).first << std::endl; michael@0: for ( std::set < std::string >::iterator iii = (*ii).second.begin(); michael@0: iii != (*ii).second.end(); michael@0: iii++ ) { michael@0: std::cout << " " << '"' << (*iii) << '"' << std::endl; michael@0: } michael@0: } michael@0: } michael@0: return TRUE; michael@0: } michael@0: michael@0: U_CAPI void *udbg_knownIssue_openU(void *ptr, const char *ticket, char *where, const UChar *msg, UBool *firstForTicket, michael@0: UBool *firstForWhere) { michael@0: KnownIssues *t = static_cast(ptr); michael@0: if(t==NULL) { michael@0: t = new KnownIssues(); michael@0: } michael@0: michael@0: t->add(ticket, where, msg, firstForTicket, firstForWhere); michael@0: michael@0: return static_cast(t); michael@0: } michael@0: michael@0: U_CAPI void *udbg_knownIssue_open(void *ptr, const char *ticket, char *where, const char *msg, UBool *firstForTicket, michael@0: UBool *firstForWhere) { michael@0: KnownIssues *t = static_cast(ptr); michael@0: if(t==NULL) { michael@0: t = new KnownIssues(); michael@0: } michael@0: michael@0: t->add(ticket, where, msg, firstForTicket, firstForWhere); michael@0: michael@0: return static_cast(t); michael@0: } michael@0: michael@0: U_CAPI UBool udbg_knownIssue_print(void *ptr) { michael@0: KnownIssues *t = static_cast(ptr); michael@0: if(t==NULL) { michael@0: return FALSE; michael@0: } else { michael@0: t->print(); michael@0: return TRUE; michael@0: } michael@0: } michael@0: michael@0: U_CAPI void udbg_knownIssue_close(void *ptr) { michael@0: KnownIssues *t = static_cast(ptr); michael@0: delete t; michael@0: } michael@0: michael@0: #endif