diff options
Diffstat (limited to 'Build/source/libs/icu-xetex/tools/gencnval/gencnval.c')
-rw-r--r-- | Build/source/libs/icu-xetex/tools/gencnval/gencnval.c | 93 |
1 files changed, 74 insertions, 19 deletions
diff --git a/Build/source/libs/icu-xetex/tools/gencnval/gencnval.c b/Build/source/libs/icu-xetex/tools/gencnval/gencnval.c index bc38e9ca69b..83eebd9cc4e 100644 --- a/Build/source/libs/icu-xetex/tools/gencnval/gencnval.c +++ b/Build/source/libs/icu-xetex/tools/gencnval/gencnval.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1999-2004, International Business Machines +* Copyright (C) 1999-2006, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -84,7 +84,7 @@ static const UDataInfo dataInfo={ 0, {0x43, 0x76, 0x41, 0x6c}, /* dataFormat="CvAl" */ - {3, 0, 0, 0}, /* formatVersion */ + {3, 0, 1, 0}, /* formatVersion */ {1, 4, 2, 0} /* dataVersion */ }; @@ -137,6 +137,11 @@ static UBool standardTagsUsed = FALSE; static UBool verbose = FALSE; static int lineNum = 1; +static UConverterAliasOptions tableOptions = { + UCNV_IO_STD_NORMALIZED, + 1 /* containsCnvOptionInfo */ +}; + /* prototypes --------------------------------------------------------------- */ static void @@ -663,19 +668,7 @@ addAlias(const char *alias, uint16_t standard, uint16_t converter, UBool default } } - /* Check for duplicates in a tag/converter combination */ - for (idx = 0; idx < aliasList->aliasCount; idx++) { - uint16_t aliasNum = tags[standard].aliasList[converter].aliases[idx]; - if (aliasNum && ucnv_compareNames(alias, GET_ALIAS_STR(aliasNum)) == 0 && standard != ALL_TAG_NUM) - { - fprintf(stderr, "warning(line %d): duplicate alias %s and %s found for standard %s\n", - lineNum, alias, GET_ALIAS_STR(aliasNum), GET_TAG_STR(tags[standard].tag)); - dupFound = TRUE; - break; - } - } - - if (!dupFound && standard != ALL_TAG_NUM) { + if (standard != ALL_TAG_NUM) { /* Check for duplicate aliases for this tag on all converters */ for (idx = 0; idx < converterCount; idx++) { for (idx2 = 0; idx2 < tags[standard].aliasList[idx].aliasCount; idx2++) { @@ -683,8 +676,25 @@ addAlias(const char *alias, uint16_t standard, uint16_t converter, UBool default if (aliasNum && ucnv_compareNames(alias, GET_ALIAS_STR(aliasNum)) == 0) { - fprintf(stderr, "warning(line %d): duplicate alias %s found for standard tag %s between converter %s and converter %s\n", - lineNum, alias, GET_TAG_STR(tags[standard].tag), GET_ALIAS_STR(converters[converter].converter), GET_ALIAS_STR(converters[idx].converter)); + if (idx == converter) { + /* + * (alias, standard) duplicates are harmless if they map to the same converter. + * Only print a warning in verbose mode, or if the alias is a precise duplicate, + * not just a lenient-match duplicate. + */ + if (verbose || 0 == uprv_strcmp(alias, GET_ALIAS_STR(aliasNum))) { + fprintf(stderr, "warning(line %d): duplicate aliases %s and %s found for standard %s and converter %s\n", + lineNum, alias, GET_ALIAS_STR(aliasNum), + GET_TAG_STR(tags[standard].tag), + GET_ALIAS_STR(converters[converter].converter)); + } + } else { + fprintf(stderr, "warning(line %d): duplicate aliases %s and %s found for standard tag %s between converter %s and converter %s\n", + lineNum, alias, GET_ALIAS_STR(aliasNum), + GET_TAG_STR(tags[standard].tag), + GET_ALIAS_STR(converters[converter].converter), + GET_ALIAS_STR(converters[idx].converter)); + } dupFound = TRUE; break; } @@ -860,6 +870,9 @@ resolveAliases(uint16_t *uniqueAliasArr, uint16_t *uniqueAliasToConverterArr, ui oldTagNum = currTagNum; /*printf("%s -> %s\n", GET_ALIAS_STR(knownAliases[idx]), GET_ALIAS_STR(converters[currConvNum].converter));*/ } + if (uprv_strchr(GET_ALIAS_STR(converters[currConvNum].converter), UCNV_OPTION_SEP_CHAR) != NULL) { + uniqueAliasToConverterArr[uniqueAliasIdx-1] |= UCNV_CONTAINS_OPTION_BIT; + } } return uniqueAliasIdx; } @@ -906,6 +919,26 @@ createOneAliasList(uint16_t *aliasArrLists, uint32_t tag, uint32_t converter, ui } static void +createNormalizedAliasStrings(char *normalizedStrings, const char *origStringBlock, int32_t stringBlockLength) { + int32_t currStrLen; + uprv_memcpy(normalizedStrings, origStringBlock, stringBlockLength); + while ((currStrLen = (int32_t)uprv_strlen(origStringBlock)) < stringBlockLength) { + int32_t currStrSize = currStrLen + 1; + if (currStrLen > 0) { + int32_t normStrLen; + ucnv_io_stripForCompare(normalizedStrings, origStringBlock); + normStrLen = uprv_strlen(normalizedStrings); + if (normStrLen > 0) { + uprv_memset(normalizedStrings + normStrLen, 0, currStrSize - normStrLen); + } + } + stringBlockLength -= currStrSize; + normalizedStrings += currStrSize; + origStringBlock += currStrSize; + } +} + +static void writeAliasTable(UNewDataMemory *out) { uint32_t i, j; uint32_t uniqueAliasesSize; @@ -928,7 +961,12 @@ writeAliasTable(UNewDataMemory *out) { } /* Write the size of the TOC */ - udata_write32(out, 8); + if (tableOptions.stringNormalizationType == UCNV_IO_UNNORMALIZED) { + udata_write32(out, 8); + } + else { + udata_write32(out, 9); + } /* Write the sizes of each section */ /* All sizes are the number of uint16_t units, not bytes */ @@ -938,8 +976,11 @@ writeAliasTable(UNewDataMemory *out) { udata_write32(out, uniqueAliasesSize); /* The preresolved form of mapping an untagged the alias to a converter */ udata_write32(out, tagCount * converterCount); udata_write32(out, aliasListsSize + 1); - udata_write32(out, 0); /* Reserved space. */ + udata_write32(out, sizeof(tableOptions) / sizeof(uint16_t)); udata_write32(out, (tagBlock.top + stringBlock.top) / sizeof(uint16_t)); + if (tableOptions.stringNormalizationType != UCNV_IO_UNNORMALIZED) { + udata_write32(out, (tagBlock.top + stringBlock.top) / sizeof(uint16_t)); + } /* write the table of converters */ /* Think of this as the column headers */ @@ -973,12 +1014,26 @@ writeAliasTable(UNewDataMemory *out) { /* Write the lists */ udata_writeBlock(out, (const void *)aliasLists, aliasListsSize * sizeof(uint16_t)); + /* Write any options for the alias table. */ + udata_writeBlock(out, (const void *)&tableOptions, sizeof(tableOptions)); + /* write the tags strings */ udata_writeString(out, tagBlock.store, tagBlock.top); /* write the aliases strings */ udata_writeString(out, stringBlock.store, stringBlock.top); + /* write the normalized aliases strings */ + if (tableOptions.stringNormalizationType != UCNV_IO_UNNORMALIZED) { + char *normalizedStrings = (char *)uprv_malloc(tagBlock.top + stringBlock.top); + createNormalizedAliasStrings(normalizedStrings, tagBlock.store, tagBlock.top); + createNormalizedAliasStrings(normalizedStrings + tagBlock.top, stringBlock.store, stringBlock.top); + + /* Write out the complete normalized array. */ + udata_writeString(out, normalizedStrings, tagBlock.top + stringBlock.top); + uprv_free(normalizedStrings); + } + uprv_free(aliasArrLists); uprv_free(uniqueAliases); } |