BYTE CharacterInfoTable::GetUnicodeCategory(WCHAR wch) { // Access the 8:4:4 table. The compiler should be smart enough to remove the redundant locals in the following code. // These locals are added so that we can debug this easily from the debug build. BYTE index1 = m_pLevel1ByteIndex[GET8(wch)]; WORD offset = m_pLevel2WordOffset[index1].offset[GETHI4(wch)]; BYTE result = m_pByteData[offset+GETLO4(wch)]; return (result); }
int Insert844Map( P844_ARRAY pArr, PCT_MAP pMap, WORD WChar, WORD Value1, WORD Value2, WORD Value3, int *cbBuf2, int *cbBuf3) { register int Index; // index into array P844_ARRAY pTbl2; // pointer to second array PCT_MAP_VALUE pTbl3; // pointer to third array // // Use the "8" index to get to the second table. // Allocate it if necessary. // Index = GET8(WChar); if ((pTbl2 = (P844_ARRAY)(pArr[Index])) == NULL) { // // Allocate second table - 16 pointers + 1 word. // The additional 1 word will be used when writing this table // to avoid duplicates of the same table. // if ((pTbl2 = (P844_ARRAY)malloc( (TABLE_SIZE_4 + 1) * sizeof(P844_ARRAY) )) == NULL) { printf("Error: Can't allocate second 8:4:4 buffer.\n"); return (1); } memset(pTbl2, 0, (TABLE_SIZE_4 + 1) * sizeof(P844_ARRAY)); pArr[Index] = pTbl2; // // Keep track of how many "second buffer" allocations were made. // (*cbBuf2)++; } // // Use the "high 4" index to get to the third table. // Allocate it if necessary. // Index = GETHI4(WChar); if ((pTbl3 = pTbl2[Index]) == NULL) { // // Allocate third table - 16 + 2 bytes. // The 2 extra bytes will be used when writing the table. // if ((pTbl3 = (PCT_MAP_VALUE)malloc( (TABLE_SIZE_4 + 2) * (sizeof(CT_MAP_VALUE)) )) == NULL) { printf("Error: Can't allocate third 8:4:4 buffer.\n"); return (1); } // // The last field of the third table is used when writing to the // data file to ensure that each table is written only ONCE // (with muliple pointers to it). This field takes 1 WORD // (2 bytes) and is initialized to 0. // memset(pTbl3, 0, (TABLE_SIZE_4 + 2) * (sizeof(CT_MAP_VALUE))); pTbl2[Index] = pTbl3; // // Keep track of how many "third buffer" allocations were made. // (*cbBuf3)++; } // // Use the "low 4" value to index into the third table. // Save the values at this spot. // Index = GETLO4(WChar); // // Map 3 WORD CType trio to 1 BYTE value. // pTbl3[Index] = MapTrioToByte( pMap, Value1, Value2, Value3 ); // // Make sure the number of entries in the mapping table is // not greater than MAX_CT_MAP_TBL_SIZE. // if (pMap->Length >= MAX_CT_MAP_TBL_SIZE) { printf("Error: CTYPE Mapping Table Too Large.\n"); return (1); } // // Return success. // return (0); }
int Insert844( P844_ARRAY pArr, WORD WChar, DWORD Value, int *cbBuf2, int *cbBuf3, int Size) { register int Index; // index into array P844_ARRAY pTbl2; // pointer to second array P844_ARRAY pTbl3; // pointer to third array // // Use the "8" index to get to the second table. // Allocate it if necessary. // Index = GET8(WChar); if ((pTbl2 = (P844_ARRAY)(pArr[Index])) == NULL) { // // Allocate second table - 16 pointers. // if ((pTbl2 = (P844_ARRAY)malloc( TABLE_SIZE_4 * sizeof(P844_ARRAY) )) == NULL) { printf("Error: Can't allocate second 8:4:4 buffer.\n"); return (1); } memset(pTbl2, 0, TABLE_SIZE_4 * sizeof(P844_ARRAY)); pArr[Index] = pTbl2; // // Keep track of how many "second buffer" allocations were made. // (*cbBuf2)++; } // // Use the "high 4" index to get to the third table. // Allocate it if necessary. // Index = GETHI4(WChar); if ((pTbl3 = pTbl2[Index]) == NULL) { // // Allocate third table - 16 words. // if ((pTbl3 = (P844_ARRAY)malloc(TABLE_SIZE_4 * Size)) == NULL) { printf("Error: Can't allocate third 8:4:4 buffer.\n"); return (1); } memset(pTbl3, 0, TABLE_SIZE_4 * Size); pTbl2[Index] = pTbl3; // // Keep track of how many "third buffer" allocations were made. // (*cbBuf3)++; } // // Use the "low 4" value to index into the third table. // Save the value at this spot. // Index = GETLO4(WChar); if (Size == sizeof(WORD)) { ((WORD *)pTbl3)[Index] = (WORD)Value; } else if (Size == sizeof(DWORD)) { ((DWORD *)pTbl3)[Index] = (DWORD)Value; } else { printf("Code Error: Bad 'Size' parameter for Insert844 Table.\n"); return (1); } // // Return success. // return (0); }