/*
*******************************************************************************
*
-* Copyright (C) 2003-2006, International Business Machines
+* Copyright (C) 2003-2007, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
CnvExtData *extData;
extData=(CnvExtData *)uprv_malloc(sizeof(CnvExtData));
- if(extData!=NULL) {
- uprv_memset(extData, 0, sizeof(CnvExtData));
+ if(extData==NULL) {
+ printf("out of memory\n");
+ exit(U_MEMORY_ALLOCATION_ERROR);
+ }
+ uprv_memset(extData, 0, sizeof(CnvExtData));
- extData->ucm=ucm; /* aliased, not owned */
+ extData->ucm=ucm; /* aliased, not owned */
- extData->newConverter.close=CnvExtClose;
- extData->newConverter.isValid=CnvExtIsValid;
- extData->newConverter.addTable=CnvExtAddTable;
- extData->newConverter.write=CnvExtWrite;
- }
+ extData->newConverter.close=CnvExtClose;
+ extData->newConverter.isValid=CnvExtIsValid;
+ extData->newConverter.addTable=CnvExtAddTable;
+ extData->newConverter.write=CnvExtWrite;
return &extData->newConverter;
}
extData->ucm->baseName[length++]=0;
}
- headerSize=sizeof(header)+length;
+ headerSize=MBCS_HEADER_V4_LENGTH*4+length;
/* fill the header */
header.version[0]=4;
header.flags=(uint32_t)((headerSize<<8)|MBCS_OUTPUT_EXT_ONLY);
/* write the header and the base table name */
- udata_writeBlock(pData, &header, sizeof(header));
+ udata_writeBlock(pData, &header, MBCS_HEADER_V4_LENGTH*4);
udata_writeBlock(pData, extData->ucm->baseName, length);
}
/*
* Remove fromUnicode fallbacks and SUB mappings which are irrelevant for
* the toUnicode table.
+ * This includes mappings with MBCS_FROM_U_EXT_FLAG which were suitable
+ * for the base toUnicode table but not for the base fromUnicode table.
* The table must be sorted.
- * Destroys previous data in the reverseMap.
+ * Modifies previous data in the reverseMap.
*/
static int32_t
reduceToUMappings(UCMTable *table) {
/* step 2: allocate the section; set count, section */
count=(high-low)+1;
- if(unitIndex==0 || uniqueCount>=(3*count)/4) {
+ if(count<0x100 && (unitIndex==0 || uniqueCount>=(3*count)/4)) {
/*
* for the root table and for fairly full tables:
* allocate for direct, linear array access
* by keeping count, to write an entry for each unit value
* from low to high
+ * exception: use a compact table if count==0x100 because
+ * that cannot be encoded in the length byte
*/
} else {
count=uniqueCount;
}
+ if(count>=0x100) {
+ fprintf(stderr, "error: toUnicode extension table section overflow: %ld section entries\n", (long)count);
+ return FALSE;
+ }
+
/* allocate the section: 1 entry for the header + count for the items */
section=(uint32_t *)utm_allocN(extData->toUTable, 1+count);
/*
* Remove toUnicode fallbacks and non-<subchar1> SUB mappings
* which are irrelevant for the fromUnicode extension table.
+ * Remove MBCS_FROM_U_EXT_FLAG bits.
* Overwrite the reverseMap with an index array to the relevant mappings.
* Modify the code point sequences to a generator-friendly format where
* the first code points remains unchanged but the following are recoded
for(i=j=0; i<count; ++m, ++i) {
flag=m->f;
+ if(flag>=0) {
+ flag&=MBCS_FROM_U_EXT_MASK;
+ m->f=flag;
+ }
if(flag==0 || flag==1 || (flag==2 && m->bLen==1)) {
map[j++]=i;
makeToUTable(extData, table) &&
makeFromUTable(extData, table);
}
-