Compare commits

...

1 Commits

Author SHA1 Message Date
coah
f9dd365034 eZiText: zi8match, zi8getc2, zikorean, zi8dawg (worker 1f628177) 2026-09-30 05:54:02 +00:00
9 changed files with 2580 additions and 2 deletions

View File

@@ -53,9 +53,9 @@ Progress
<!-- progress:start -->
| Decompiled | Matched | Linked | Data |
|:---:|:---:|:---:|:---:|
| 88.96% | 79.07% | 56.95% | 88.24% |
| 89.61% | 79.32% | 56.95% | 88.27% |
units 758/1027 complete, functions 11493/12563 matched.
units 758/1027 complete, functions 11514/12563 matched.
decompiled = code with a C/C++ implementation (objdiff fuzzy), matched = byte-exact code, linked = code actually linked into the DOL, data = byte-exact data
<!-- progress:end -->

View File

@@ -0,0 +1,430 @@
#include <zi8clib/zitypes.h>
#include <zi8clib/zierror.h>
#include <zi8clib/zconvert.h>
ziU32 Zi8GetTableSize(ziU8 language, ziU8 table, ziPtr work);
ziU32 Zi8GetTableAddress(ziU8 language, ziU8 table, ziPtr work);
ziU16 Zi8GetTableCount(ziU8 language, ziU8 table, ziPtr work);
ziU8* ZiDAWGGetGraph(zi8DawgCtx* context);
ziU8* ZiDAWGGetGraphInfo(zi8DawgCtx* context, ziU8* table, ziS16* keys);
ziU32 ZiDAWGgetCHARattribute(zi8DawgCtx* context, ziU8* graph, ziPtr work);
ziU8 ZiDAWGgetEOWattribute(ziU8* graph);
ziU8* ZiDAWGGetChild(ziU8* graph);
ziU8* ZiDAWGGetSibling(ziU8* graph);
ziU32 Zi8MatchROMdata0(ziWChar* elements, ziU32 count, ziU8 language,
ziWChar* output, ziU16 capacity, ziU8 mode, ziU8 status,
ziU8 graphTable, ziU8 keyTable, ziU8 acceptPrefix,
ziU8* prefixLength, zi8DawgCtx* context, ziU8* search,
ziPtr __zi8_work_data) {
ziBool searching;
ziS32 tableSize;
ziU8* graph;
ziS16 key;
ziU8 endOfWord;
zi8DawgRec* current;
ziU16 index;
ziU16 depth;
zi8DawgRec* records = context->recs;
ziU8 result = 0;
ziU32 keyCount;
ziU8* table;
ziS16 keys[3];
if (language != context->lang || graphTable != context->key) {
records[0].key = 0;
}
if ((ziU8)count != 1 || mode == 0 || graphTable != 0xe) {
if (status != 0) {
if (records[context->cnt - 1].node == (ziU8*)context->unk_0x338) goto finish_graph;
for (index = 0; (ziU16)index < (ziU8)count; index++) {
if (records[(ziU16)index].key != elements[(ziU16)index] &&
(records[(ziU16)index].attr & 0xffff) != elements[(ziU16)index]) goto finish_graph;
}
if (mode == 1) acceptPrefix = 0;
} else {
if (ZI_WORK->unk_0x141E == 0 || graphTable != 0xc ||
(tableSize = Zi8GetTableSize(language, ZI_WORK->unk_0x141E, ZI_WORK)) == 0) {
tableSize = Zi8GetTableSize(language, graphTable, ZI_WORK);
if (tableSize == 0) {
Zi8LogError(0x961, ZI_WORK);
goto finish_graph;
}
table = (ziU8*)Zi8GetTableAddress(language, graphTable, ZI_WORK);
} else {
table = (ziU8*)Zi8GetTableAddress(language, ZI_WORK->unk_0x141E, ZI_WORK);
keyTable = ZI_WORK->unk_0x141E + 1;
}
context->table = table;
context->cap = (((ziU16)context->table[2] << 8) + (ziU16)context->table[3]) / 3;
context->p08 = context->table + 4;
context->p0C = context->table + context->cap * 2 + 4;
context->lang = language;
context->key = graphTable;
index = 0;
while ((ziU16)index < (ziU8)count && records[(ziU16)index].key == elements[(ziU16)index]) {
index++;
}
if ((ziU16)index < 2) {
key = Zi8GetTableSize(language, keyTable, ZI_WORK);
if (key == 0 || ZI_WORK->userKeys[language] != 0) {
graph = ZiDAWGGetGraph(context);
records[0].node = graph;
context->unk_0x338 = 0;
context->p14 = 0;
} else {
index = 0;
while (1) {
if ((ziU8)count < 2) keyCount = (ziU8)count;
else keyCount = 2;
if (keyCount <= (ziU16)index) break;
key = Zi8ConvertWC2Key(elements[(ziU16)index], language, ZI_WORK);
keys[(ziU16)index] = key;
if (keys[(ziU16)index] == 0) keys[(ziU16)index] = elements[(ziU16)index];
index++;
}
keys[(ziU16)index] = 0;
table = (ziU8*)Zi8GetTableAddress(language, keyTable, ZI_WORK);
context->p14 = table + 2;
records[0].node = ZiDAWGGetGraphInfo(context, table + context->cap * 2 + 2, keys);
}
records[0].key = 0;
if (records[0].node == 0) goto finish_graph;
} else {
records[0].node = records[(ziU16)index - 1].back;
}
context->cnt = 1;
search[1] = count;
search[0] = 0;
if (mode == 1) {
search[0] = 1;
acceptPrefix = 0;
} else if (mode == 0 && acceptPrefix == 0) {
search[1]++;
}
}
searching = 1;
depth = context->cnt;
while ((current = &records[depth - 1], searching) && context->cnt != 0 &&
current->node != (ziU8*)context->unk_0x338 && context->cnt <= capacity) {
current->attr = ZiDAWGgetCHARattribute(context, current->node, ZI_WORK);
if ((ziU8)count < context->cnt) {
check_word:
if (context->cnt < search[1]) goto descend;
if (search[0] == 0 || context->cnt <= search[1]) {
if (acceptPrefix != 0 || (endOfWord = ZiDAWGgetEOWattribute(current->node)) != 0) {
for (depth = 0; depth < context->cnt; depth++) {
output[depth] = records[depth].attr;
}
result = context->cnt;
searching = 0;
if (acceptPrefix != 0) goto next_sibling;
}
if (search[0] == 0 || context->cnt < search[1]) goto descend;
}
next_sibling:
while (context->cnt != 0) {
graph = ZiDAWGGetSibling(records[context->cnt - 1].node);
records[context->cnt - 1].node = graph;
if (records[context->cnt - 1].node != 0) break;
context->cnt--;
}
} else {
if (context->p14 == 0) {
key = Zi8ConvertWC2Key(current->attr & 0xffff, language, ZI_WORK);
} else {
key = (ziU16)context->p14[(current->attr >> 24) * 2] * 0x100 +
(ziU16)context->p14[(current->attr >> 24) * 2 + 1];
}
if (key != elements[context->cnt - 1] &&
(current->attr & 0xffff) != elements[context->cnt - 1]) goto next_sibling;
if (current->key != elements[context->cnt - 1]) {
current->key = elements[context->cnt - 1];
current->back = records[0].node;
depth = context->cnt;
records[depth].key = 0;
}
if (prefixLength != 0 && *prefixLength < context->cnt &&
(endOfWord = ZiDAWGgetEOWattribute(current->node)) != 0) {
*prefixLength = context->cnt;
for (depth = 0; depth < context->cnt; depth++) output[depth] = records[depth].attr;
}
if ((ziU8)count <= context->cnt) goto check_word;
descend:
graph = ZiDAWGGetChild(records[context->cnt - 1].node);
records[context->cnt].node = graph;
if (records[context->cnt].node == 0) goto next_sibling;
context->cnt++;
if (ZI_WORK->unk_0x141F < context->cnt) ZI_WORK->unk_0x141F = context->cnt;
}
depth = context->cnt;
}
}
finish_graph:
return result;
}
ziU8* NextDawgGroup(ziU8* group, ziU8 language, ziPtr __zi8_work_data)
{
if (Zi8GetTableSize(language,0x1c,ZI_WORK) != 0) {
if (group == 0) {
group = (ziU8*)Zi8GetTableAddress(language,0x1c,ZI_WORK);
if (group == 0) {
Zi8LogError(0x962,ZI_WORK);
return 0;
}
if (ZI_WORK->unk_0x141D == 0) {
return group;
}
}
while (group[0] != 0xff || group[1] != 0xff) {
group = group + 1;
}
group = group + 2;
if (group[0] == 0xff) {
Zi8LogError(0x963,ZI_WORK);
return 0;
}
return group;
}
Zi8LogError(0x961,ZI_WORK);
return 0;
}
unsigned int Zi8MatchROMdata1(ziWChar *elements, ziU8 count, ziU8 language, ziWChar *output, ziU16 capacity, ziU8 mode, unsigned int status, ziU32 groupIndex, char *group, ziU8 acceptPrefix, ziPtr __zi8_work_data)
{
unsigned int result;
ziU32 tableAddress;
result = 0;
if ((status & 0xff) == 0) {
ZI_WORK->unk_0x1764 = (ziU8*)group;
if (ZI_WORK->unk_0x1764 == 0) {
if (Zi8GetTableSize(language & 0xff,0xb,ZI_WORK) != 0) {
tableAddress = Zi8GetTableAddress(language & 0xff,0xb,ZI_WORK);
ZI_WORK->unk_0x1764 = (ziU8*)tableAddress;
}
}
if (ZI_WORK->unk_0x1764 != 0) {
for (; (*ZI_WORK->unk_0x1764 != 0xff && ((groupIndex & 0xff) != 0));
groupIndex = groupIndex - 1) {
while (*ZI_WORK->unk_0x1764 != 0xff) {
ZI_WORK->unk_0x1764 += 2;
}
ZI_WORK->unk_0x1764++;
}
}
}
if (ZI_WORK->unk_0x1764 == 0) {
result = Zi8MatchROMdata0(elements,count,language & 0xff,output,capacity & 0xffff,
mode & 0xff,status & 0xff,0,1,acceptPrefix,0,&ZI_WORK->dawgCtx,
ZI_WORK->unk_0x1760,ZI_WORK);
}
else {
while (*ZI_WORK->unk_0x1764 != 0xff) {
result = Zi8MatchROMdata0(elements,count,language & 0xff,output,
capacity & 0xffff,mode & 0xff,status & 0xff,
*ZI_WORK->unk_0x1764,
ZI_WORK->unk_0x1764[1],acceptPrefix,0,
&ZI_WORK->dawgCtx,ZI_WORK->unk_0x1760,ZI_WORK);
if ((result & 0xff) != 0) break;
ZI_WORK->unk_0x1764 += 2;
status = 0;
}
}
return result;
}
unsigned int Zi8MatchROMdata2(ziWChar *elements, unsigned int count, unsigned int language, ziWChar *output, unsigned int capacity, unsigned int mode, unsigned int status, ziU8 reservedMode, ziU8 *group, ziU8 acceptPrefix, ziPtr __zi8_work_data)
{
ziU16 character;
unsigned int result;
ziU8 prefixCount;
unsigned int index;
unsigned int remaining;
result = 0;
if (reservedMode != 0) return 0;
if ((status & 0xff) == 0) {
ZI_WORK->unk_0x1768 = 0;
ZI_WORK->unk_0x17EA = 0;
if ((((group == 0) || (*group != '\f')) || ((language & 0xff) != 10)) ||
(ZI_WORK->unk_0x141C == '\0')) {
ZI_WORK->unk_0x141E = 0;
}
else {
ZI_WORK->unk_0x141E = 0x10;
}
}
search_segment:
ZI_WORK->unk_0x141F = 1;
result = Zi8MatchROMdata1(elements + (unsigned int)ZI_WORK->unk_0x17EA,
count - ZI_WORK->unk_0x17EA & 0xff,language & 0xff,
&ZI_WORK->unk_0x17F4[ZI_WORK->unk_0x17EA],
capacity & 0xffff,mode & 0xff,status & 0xff,
ZI_WORK->unk_0x1768,(char *)group,acceptPrefix,ZI_WORK);
if ((result & 0xff) == 0) {
if ((((status & 0xff) != 0) || ((count & 0xff) == 1)) ||
(((mode & 0xff) == 1 &&
((ZI_WORK->unk_0x1768 == 0 &&
(prefixCount = Zi8MatchROMdata1(elements + (unsigned int)ZI_WORK->unk_0x17EA,
count - ZI_WORK->unk_0x17EA & 0xff,language & 0xff,
&ZI_WORK->unk_0x17F4[ZI_WORK->unk_0x17EA],
capacity & 0xffff,0,status & 0xff,
ZI_WORK->unk_0x1768,(char *)group,acceptPrefix,ZI_WORK),
prefixCount != '\0')))))) goto finish_segments;
index = Zi8GetTableCount(language & 0xff,0x1f,ZI_WORK);
if ((index & 4) == 0) {
for (index = 0; (index & 0xff) < (count & 0xff); index = index + 1) {
if (elements[index & 0xff] == 0xeff1) goto finish_segments;
}
}
if ((capacity & 0xffff) < (unsigned int)ZI_WORK->unk_0x141F) goto finish_segments;
prefixCount = ZI_WORK->unk_0x141F;
for (; prefixCount != 0; prefixCount--) {
result = Zi8MatchROMdata1(elements + (unsigned int)ZI_WORK->unk_0x17EA,prefixCount,
language & 0xff,
&ZI_WORK->unk_0x17F4[ZI_WORK->unk_0x17EA],
capacity & 0xffff,1,0,ZI_WORK->unk_0x1768,(char *)group,
acceptPrefix,ZI_WORK);
if ((result & 0xff) != 0) break;
}
if (prefixCount == 0) goto finish_segments;
ZI_WORK->unk_0x17EA = ZI_WORK->unk_0x17EA + ((ziU16)result & 0xff);
if ((unsigned int)ZI_WORK->unk_0x17EA == (count & 0xff)) {
result = 0;
goto finish_segments;
}
ZI_WORK->unk_0x1768 = ZI_WORK->unk_0x1768 + 1;
status = 0;
ZI_WORK->unk_0x141E = 0;
if ((ZI_WORK->dawgCtx.key == 0) && ((language & 0xff) == 10)) {
for (result = 0; (result & 0xff) < (unsigned int)ZI_WORK->unk_0x17EA; result = result + 1) {
character = ZI_WORK->unk_0x17F4[result & 0xff];
if (character == 0x6f) {
select_vowel_table:
ZI_WORK->unk_0x141E = 0x10;
break;
}
if (character < 0x6f) {
if (character == 0x61) goto select_vowel_table;
}
else if (character == 0x75) goto select_vowel_table;
}
}
goto search_segment;
}
for (remaining = ZI_WORK->unk_0x17EA + result & 0xff; (remaining & 0xff) != 0;
remaining = remaining - 1) {
output[(remaining & 0xff) - 1] = ZI_WORK->unk_0x17F4[(remaining & 0xff) - 1];
}
result = result + ZI_WORK->unk_0x17EA & 0xff;
finish_segments:
return result;
}
ziU8 Zi8MatchROMdata(ziWChar *elements, ziU8 count, ziU8 language, ziWChar *output, ziU16 capacity, ziU8 mode, ziU8 status, ziU8 reservedMode, ziU8 acceptPrefix, ziPtr __zi8_work_data)
{
ziU16 *input;
ziU8* group;
int tableSize;
ziU8 found;
unsigned int elementCount;
unsigned int result;
input = (ziU16 *)elements;
elementCount = (unsigned int)count;
result = 0;
if ((capacity & 0xffff) < (elementCount & 0xff)) {
Zi8LogError(0x321,ZI_WORK);
}
else if ((status & 0xff) == 2) {
Zi8LogError(100,ZI_WORK);
}
else {
if ((status & 0xff) == 0) {
ZI_WORK->unk_0x17EC = 0;
group = NextDawgGroup(0,language & 0xff,ZI_WORK);
ZI_WORK->unk_0x17F0 = group;
}
else if (ZI_WORK->unk_0x17EC != '\0') {
Zi8LogError(100,ZI_WORK);
goto finish_match;
}
tableSize = Zi8GetTableSize(language & 0xff,0x1c,ZI_WORK);
if (tableSize == 0) {
result = Zi8MatchROMdata2(input,elementCount & 0xff,language & 0xff,output,capacity & 0xffff,
mode & 0xff,status & 0xff,reservedMode & 0xff,0,acceptPrefix,ZI_WORK);
}
else {
while (((ZI_WORK->unk_0x17F0 != 0 &&
(result = Zi8MatchROMdata2(input,elementCount & 0xff,language & 0xff,output,capacity & 0xffff,
mode & 0xff,status & 0xff,reservedMode & 0xff,
(ziU8 *)ZI_WORK->unk_0x17F0,acceptPrefix,ZI_WORK),
(result & 0xff) == 0)) &&
((status = 0, 1 < (elementCount & 0xff) || ((language & 0xff) != 0x36))))) {
group = NextDawgGroup(ZI_WORK->unk_0x17F0,language & 0xff,ZI_WORK);
ZI_WORK->unk_0x17F0 = group;
}
}
if (((((result & 0xff) == 0) && ((status & 0xff) == 0)) && ((mode & 0xff) == 1)) &&
(((elementCount & 0xff) == 1 && ((capacity & 0xffff) != 0)))) {
ZI_WORK->unk_0x17EC = 1;
if (tableSize == 0) {
found = Zi8MatchROMdata2(input,elementCount & 0xff,language & 0xff,output,capacity & 0xffff,0,
status & 0xff,reservedMode & 0xff,0,acceptPrefix,ZI_WORK);
if (found != '\0') {
*output = *input;
result = 1;
}
}
else {
group = NextDawgGroup(0,language & 0xff,ZI_WORK);
ZI_WORK->unk_0x17F0 = group;
while (ZI_WORK->unk_0x17F0 != 0) {
found = Zi8MatchROMdata2(input,elementCount & 0xff,language & 0xff,output,capacity & 0xffff,0,
status & 0xff,reservedMode & 0xff,(ziU8 *)ZI_WORK->unk_0x17F0,
acceptPrefix,ZI_WORK);
if (found != '\0') {
*output = *input;
result = 1;
break;
}
group = NextDawgGroup(ZI_WORK->unk_0x17F0,language & 0xff,ZI_WORK);
ZI_WORK->unk_0x17F0 = group;
}
}
}
Zi8LogError(100,ZI_WORK);
}
finish_match:
return (ziU8)result;
}
void Zi8SyllablesROMdata(ziWChar *elements, ziU8 count, ziU8 language, ziWChar *output, ziU16 capacity, ziU8 status, ziU8* prefixLength, ziU8 reverseOrder, ziPtr __zi8_work_data)
{
ziU32 keyTable;
ziU8 graphTable;
graphTable = 0x1a;
keyTable = 0x1b;
if (prefixLength != 0) {
*prefixLength = 0;
}
if (reverseOrder != 0) {
graphTable = 0x18;
keyTable = 0x19;
}
if (Zi8GetTableSize(language & 0xff,graphTable,ZI_WORK) == 0) {
if (graphTable == 0x1a) {
graphTable = 0x18;
keyTable = 0x19;
}
else {
graphTable = 0x1a;
keyTable = 0x1b;
}
}
Zi8MatchROMdata0(elements,count,language & 0xff,output,capacity,1,status,graphTable,keyTable,0,(ziU8 *)prefixLength,
&ZI_WORK->dawgCtx,ZI_WORK->unk_0x1760,ZI_WORK);
return;
}

View File

@@ -0,0 +1,735 @@
#include <zi8clib/zitypes.h>
#include <zi8clib/zierror.h>
#include <zi8clib/zi8getc2.h>
typedef struct {
ziU8 countOnly;
ziU8 maxWordLength;
ziU8 lookupMode;
ziU8 suffixOnly;
ziU8 controls[8];
ziU32 maxCount;
ziU16 capacity;
ziU8 minWordLength;
ziU8 flags;
ziU16 candidateCapacity;
ziU8 checkOnly;
ziU8 reserved;
} ZiCandidateOptions;
const ziU8 Zi8SOdefaultArray[16] = {1, 4, 3, 2, 1, 8, 7, 6, 5, 0};
const ziFuzzyPYPairs Zi8PYdefaultFuzzyPairs = {0, 1, 1, 1, 1, 1, 1};
const ziFuzzyZYPairs Zi8ZYdefaultFuzzyPairs = {0};
ziU8 Zi8GetFormatVersion(ziU8 language, ziPtr work);
ziU32 Zi8GetTableAddress(ziU8 language, ziU8 table, ziPtr work);
ziU16 Zi8GetTableCount(ziU8 language, ziU8 table, ziPtr work);
ziU16 Zi8GetVersion(ziPtr work);
ziU16 Zi8GetOEMID(ziPtr work);
ziU16 Zi8GetBuildID(ziPtr work);
void Zi8Memcpy(ziU8* destination, ziU8* source, ziS32 count);
ziU32 Zi8GetCandidatesOrCount(ziGetParam* parameters, ZiCandidateOptions* options, ziPtr work);
ziBool Zi8ZHsetPYfuzzyPairs(ziFuzzyPYPairs pairs ZI_NEED_WORK) {
if (pairs.ziDefault) {
ZI_WORK->unk_0x1B28.word = *(const ziU32*)&Zi8PYdefaultFuzzyPairs;
} else {
ZI_WORK->unk_0x1B28.word = *(ziU32*)&pairs;
}
return 1;
}
ziBool Zi8ZHsetZYfuzzyPairs(ziFuzzyZYPairs pairs ZI_NEED_WORK) {
if (pairs.ziDefault) {
ZI_WORK->unk_0x1B2C.word = *(const ziU32*)&Zi8ZYdefaultFuzzyPairs;
} else {
ZI_WORK->unk_0x1B2C.word = *(ziU32*)&pairs;
}
return 1;
}
ziBool Zi8SetLatinSearchOrder(ziU8* searchArray, ziU8 searchSize ZI_NEED_WORK) {
if (searchArray == 0 || *searchArray == 0) {
ZI_WORK->unk_0x1410 = (ziU32)Zi8SOdefaultArray;
ZI_WORK->unk_0x1418 = 9;
} else {
ZI_WORK->unk_0x1410 = (ziU32)searchArray;
ZI_WORK->unk_0x1418 = searchSize;
}
return 1;
}
ziU16 Zi8GetGlobalDataSize(void) {
return sizeof(struct __zi8_work_data_s);
}
static ziU16 Zi8GetDataSignature(ziU8* destination, ziU16 capacity, ziU8 language, ziPtr work) {
ziU8* signature;
ziU16 length;
if (language == 1) {
if (Zi8GetFormatVersion(1, work) < 8) {
Zi8LogError(0x26f, work);
return 0;
}
length = 0x1e;
} else {
length = 3;
}
signature = (ziU8*)Zi8GetTableAddress(language, (ziU8)length, work);
length = Zi8GetTableCount(language, (ziU8)length, work);
if (length == 0 || length > capacity) {
Zi8LogError(0x961, work);
return 0;
}
Zi8Memcpy(destination, signature, length);
destination[length] = 0;
Zi8LogError(100, work);
return length;
}
static ziU16 Zi8GetEngineSignature(ziU8* destination, ziPtr work) {
ziU16 index = 0;
ziU16 major;
ziU16 minor;
ziU16 number;
destination[index++] = 'v';
major = (Zi8GetVersion(work) & 0xff00) >> 8;
minor = Zi8GetVersion(work) & 0xff;
destination[index++] = (ziU8)(major / 10 + '0');
destination[index++] = (ziU8)(major % 10 + '0');
destination[index++] = (ziU8)(minor / 10 + '0');
destination[index++] = (ziU8)(minor % 10 + '0');
destination[index++] = 'o';
number = Zi8GetOEMID(work);
destination[index++] = (ziU8)(number / 100 + '0');
destination[index++] = (ziU8)((number % 100) / 10 + '0');
destination[index++] = (ziU8)((number % 100) % 10 + '0');
destination[index++] = 'b';
number = Zi8GetBuildID(work);
destination[index++] = (ziU8)(number / 100 + '0');
destination[index++] = (ziU8)((number % 100) / 10 + '0');
destination[index++] = (ziU8)((number % 100) % 10 + '0');
destination[index] = 0;
return index;
}
static ziBool Zi8AlphaSignature(ziGetParam* parameters, ziBool countOnly ZI_NEED_WORK) {
ziU16 secondLength;
ziU16 firstLength;
ziU8* second;
ziU8* first;
ziU8 engine[32];
ziU8 dictionary[56];
ziU16 length;
ziU16 candidateCount;
ziWChar* output = parameters->candidates;
second = 0;
firstLength = 0;
secondLength = 0;
Zi8LogError(100, ZI_WORK);
parameters->letters = 0;
length = Zi8GetDataSignature(dictionary, 0x20, parameters->language, ZI_WORK);
if (length == 0 || length < parameters->elementCount) {
first = engine;
} else {
first = dictionary;
second = engine;
firstLength = length;
}
length = Zi8GetEngineSignature(engine, ZI_WORK);
if (length < parameters->elementCount) {
if (firstLength == 0) {
Zi8ReplaceLastError(500, ZI_WORK);
return 0;
}
second = 0;
candidateCount = 1;
} else if (firstLength == 0) {
candidateCount = 1;
firstLength = length;
} else {
candidateCount = 2;
secondLength = length;
}
if (parameters->firstCandidate < candidateCount) {
candidateCount -= parameters->firstCandidate;
if (!countOnly) {
if (parameters->maxCandidates < candidateCount) {
candidateCount = parameters->maxCandidates;
}
parameters->letters = candidateCount;
if (!(parameters->getOptions & 0x80)) {
ZI_WORK->unk_0x538 = parameters->language;
parameters->candidates[0] = 0xfff0;
output = (ziWChar*)&ZI_WORK->unk_0x338;
}
if (parameters->firstCandidate != 0) {
first = second;
firstLength = secondLength;
}
if (ZI_WORK->unk_0x0A < firstLength) {
firstLength = ZI_WORK->unk_0x0A;
}
if ((parameters->elementCount < ZI_WORK->unk_0x140C[0] ||
(parameters->getOptions & 0x7e) == 2) &&
parameters->elementCount < firstLength) {
firstLength = parameters->elementCount;
}
while (firstLength-- != 0) {
*output++ = *first++;
}
*output++ = 0;
if (parameters->letters == 2) {
if (ZI_WORK->unk_0x0A < secondLength) {
secondLength = ZI_WORK->unk_0x0A;
}
if ((parameters->elementCount < ZI_WORK->unk_0x140C[0] ||
(parameters->getOptions & 0x7e) == 2) &&
parameters->elementCount < secondLength) {
secondLength = parameters->elementCount;
}
while (secondLength-- != 0) {
*output++ = *second++;
}
*output++ = 0;
}
*output = 0;
ZI_WORK->unk_0x0A = 0xff;
return 1;
}
parameters->letters = candidateCount;
ZI_WORK->unk_0x0A = 0xff;
return 1;
}
Zi8ReplaceLastError(501, ZI_WORK);
return 0;
}
static ziBool Zi8ZhSignature(ziGetParam* parameters, ziBool countOnly ZI_NEED_WORK) {
ziWChar* output = parameters->candidates;
ziU8* current = 0;
ziU16 copied;
ziU8 engine[32];
ziU8 dictionary[64];
ziU16 dataLength;
ziU32 engineLength;
ziU32 candidateCount;
ziU8 available;
Zi8LogError(100, ZI_WORK);
parameters->letters = 0;
dataLength = Zi8GetDataSignature(dictionary, 0x20, parameters->language, ZI_WORK);
engineLength = Zi8GetEngineSignature(engine, ZI_WORK);
if (!(parameters->context & 0x10)) {
candidateCount = dataLength + engineLength;
} else {
candidateCount = dataLength != 0;
if (engineLength != 0) candidateCount++;
}
if (parameters->firstCandidate < candidateCount) {
available = candidateCount - parameters->firstCandidate;
if (!countOnly) {
if (parameters->maxCandidates < (ziU16)(candidateCount - parameters->firstCandidate)) {
available = parameters->maxCandidates;
}
parameters->letters = available;
if (!(parameters->context & 0x10)) {
copied = 0;
if (dataLength != 0) {
if (parameters->firstCandidate < dataLength) {
candidateCount = dataLength - parameters->firstCandidate;
current = dictionary + parameters->firstCandidate;
} else {
candidateCount = 0;
}
if (parameters->letters < candidateCount) candidateCount = parameters->letters;
copied = candidateCount;
while (candidateCount-- != 0) *output++ = *current++;
}
current = engine;
if (dataLength <= parameters->firstCandidate) {
dataLength += engineLength - parameters->firstCandidate;
current += engineLength - dataLength;
engineLength = dataLength;
}
if ((int)(parameters->letters - copied) < (int)engineLength) {
engineLength = parameters->letters - copied;
}
while (engineLength-- != 0) *output++ = *current++;
} else {
if (parameters->firstCandidate == 0 && dataLength != 0) {
current = dictionary;
} else {
if (parameters->firstCandidate != 0 && dataLength == 0) {
Zi8ReplaceLastError(500, ZI_WORK);
return 0;
}
current = engine;
dataLength = engineLength;
}
while (dataLength-- != 0) *output++ = *current++;
*output = 0x20;
if (parameters->letters == 2) {
current = engine;
while (++output, engineLength-- != 0) *output = *current++;
*output = 0x20;
}
}
return 1;
}
parameters->letters = available;
ZI_WORK->unk_0x0A = 0xff;
return 1;
}
Zi8ReplaceLastError(502, ZI_WORK);
return 0;
}
ziU8 _Zi8GetCandidates(ziGetParam* parameters ZI_NEED_WORK) {
ZiCandidateOptions options = {0};
options.capacity = ZI_WORK->unk_0x141A;
return Zi8GetCandidatesOrCount(parameters, &options, ZI_WORK);
}
ziU8 _Zi8CheckCandidates(ziGetParam* parameters ZI_NEED_WORK) {
ZiCandidateOptions options = {0};
options.capacity = ZI_WORK->unk_0x141A;
options.flags = 1;
return Zi8GetCandidatesOrCount(parameters, &options, ZI_WORK);
}
ziU8 Zi8LangSupported(ziU8 language, ziPtr work);
ziBool Zi8IsCharacter(ziWChar character, ziPtr work);
ziU8 Zi8GetCharInfo(ziWChar character, ziWChar* output, ziU8 capacity, ziU8 type, ziPtr work);
ziU8 Zi8GetKOcandidates(ziGetParam* parameters, ziPtr options, ziPtr work);
ziU8 Zi8GetKoreanCandidates(ziGetParam* parameters, ziPtr options, ziPtr work);
ziU8 Zi8Punctuation(ziGetParam* parameters, ziPtr options, ziPtr work);
ziU8 Zi8GetChineseCandidates(ziGetParam* parameters, ziPtr options, ziPtr work);
ziU8 Zi8Get1KeyPressCandidates(ziGetParam* parameters, ziPtr options, ziPtr work);
ziU8 Zi8Get1KeyPressSpelling(ziGetParam* parameters, ziPtr options, ziPtr work);
ziU8 Zi8GetSyllablesCandidates(ziGetParam* parameters, ziPtr options, ziPtr work);
ziU8 Zi8AlphaGetCandidates(ziGetParam* parameters, ziPtr options, ziPtr work);
ziU32 Zi8GetCandidatesOrCount(ziGetParam* parameters, ZiCandidateOptions* options ZI_NEED_WORK) {
ziU8 savedElementCount;
ziU16 savedCharacter;
ziWChar* savedElements;
ziBool restoreCandidates;
char signatureFound;
ziU8 elementCount;
int error;
unsigned int candidateCount;
ziU8 savedOptions;
ziWChar* savedCandidates;
ziU16 characterInfo [32];
error = 0;
savedOptions = 0;
savedCandidates = 0;
restoreCandidates = 0;
if (options->lookupMode == '\0') {
if (((ZI_WORK->unk_0x00 == '\t') && (parameters->elementCount != 0)) &&
((((ziS16)parameters->elements[parameters->elementCount - 1] == -0x1008 &&
(signatureFound = Zi8AlphaSignature(parameters,options->countOnly,ZI_WORK), signatureFound != '\0')) ||
(((ziS16)parameters->elements[parameters->elementCount - 1] == -0x10fc &&
(signatureFound = Zi8ZhSignature(parameters,options->countOnly,ZI_WORK), signatureFound != '\0')))))) {
candidateCount = (unsigned int)parameters->letters;
if (options->countOnly != '\0') {
parameters->letters = 0;
}
Zi8LogError(100,ZI_WORK);
goto finishCandidates;
}
if ((parameters->elementCount == 1) && (parameters->firstCandidate == 0)) {
elementCount = parameters->language;
if (elementCount == 0x11) goto latinSequence;
if (elementCount < 0x11) {
if (elementCount == 1) {
if ((ZI_WORK->unk_0x00 == '\0') || (ZI_WORK->unk_0x01 == options->countOnly)) {
switch(ZI_WORK->unk_0x00) {
case '\0':
if ((ziS16)parameters->elements[0] == -0x10fc) {
ZI_WORK->unk_0x01 = options->countOnly;
ZI_WORK->unk_0x00 = '\x01';
}
break;
case '\x01':
case '\x03':
case '\x05':
case '\a':
if ((ziS16)parameters->elements[0] == -0x10ff) {
ZI_WORK->unk_0x00 = ZI_WORK->unk_0x00 + '\x01';
}
else {
ZI_WORK->unk_0x00 = '\0';
}
break;
case '\x02':
case '\x04':
case '\x06':
if ((ziS16)parameters->elements[0] == -0x10fc) {
ZI_WORK->unk_0x00 = ZI_WORK->unk_0x00 + '\x01';
}
else {
ZI_WORK->unk_0x00 = '\0';
}
break;
case '\b':
case '\t':
if (((ziS16)parameters->elements[0] == -0x10fc) &&
(signatureFound = Zi8ZhSignature(parameters,options->countOnly,ZI_WORK), signatureFound != '\0')) {
ZI_WORK->unk_0x00 = '\t';
candidateCount = (unsigned int)parameters->letters;
if (options->countOnly != '\0') {
parameters->letters = 0;
}
Zi8LogError(100,ZI_WORK);
goto finishCandidates;
}
default:
ZI_WORK->unk_0x00 = '\0';
}
if ((ZI_WORK->unk_0x00 == '\0') && ((ziS16)parameters->elements[0] == -0x10fc)) {
ZI_WORK->unk_0x00 = '\x01';
}
}
}
else if ((elementCount == 0) || (elementCount < 0x10)) goto latinSequence;
}
else if (elementCount < 0x77) {
if (0x12 < elementCount) {
latinSequence:
if ((ZI_WORK->unk_0x00 == '\0') || (ZI_WORK->unk_0x01 == options->countOnly)) {
switch(ZI_WORK->unk_0x00) {
case '\0':
if ((ziS16)parameters->elements[0] == -0x100e) {
ZI_WORK->unk_0x01 = options->countOnly;
ZI_WORK->unk_0x00 = '\x01';
}
break;
case '\x01':
if ((ziS16)parameters->elements[0] == -0x100d) {
ZI_WORK->unk_0x00 = '\x02';
}
else {
ZI_WORK->unk_0x00 = '\0';
}
break;
case '\x02':
if ((ziS16)parameters->elements[0] == -0x100b) {
ZI_WORK->unk_0x00 = '\x03';
}
else {
ZI_WORK->unk_0x00 = '\0';
}
break;
case '\x03':
if ((ziS16)parameters->elements[0] == -0x1009) {
ZI_WORK->unk_0x00 = '\x04';
}
else {
ZI_WORK->unk_0x00 = '\0';
}
break;
case '\x04':
if ((ziS16)parameters->elements[0] == -0x1008) {
ZI_WORK->unk_0x00 = '\x05';
}
else {
ZI_WORK->unk_0x00 = '\0';
}
break;
case '\x05':
if ((ziS16)parameters->elements[0] == -0x1007) {
ZI_WORK->unk_0x00 = '\x06';
}
else {
ZI_WORK->unk_0x00 = '\0';
}
break;
case '\x06':
if ((ziS16)parameters->elements[0] == -0x100e) {
ZI_WORK->unk_0x00 = '\a';
}
else {
ZI_WORK->unk_0x00 = '\0';
}
break;
case '\a':
if ((ziS16)parameters->elements[0] == -0x100b) {
ZI_WORK->unk_0x00 = '\b';
}
else {
ZI_WORK->unk_0x00 = '\0';
}
break;
case '\b':
case '\t':
if (((ziS16)parameters->elements[0] == -0x1008) &&
(signatureFound = Zi8AlphaSignature(parameters,options->countOnly,ZI_WORK), signatureFound != '\0')) {
ZI_WORK->unk_0x00 = '\t';
candidateCount = (unsigned int)parameters->letters;
if (options->countOnly != '\0') {
parameters->letters = 0;
}
Zi8LogError(100,ZI_WORK);
goto finishCandidates;
}
default:
ZI_WORK->unk_0x00 = '\0';
}
if ((ZI_WORK->unk_0x00 == '\0') && ((ziS16)parameters->elements[0] == -0x100e)) {
ZI_WORK->unk_0x00 = '\x01';
}
}
}
}
else if (0x7d < elementCount) goto latinSequence;
}
else if (1 < parameters->elementCount) {
ZI_WORK->unk_0x00 = '\0';
}
}
ZI_WORK->unk_0x18 = parameters->subLanguage;
elementCount = Zi8GetFormatVersion(1,ZI_WORK);
ZI_WORK->unk_0x16 = elementCount & 2;
options->maxCount = ZI_WORK->unk_0x10;
options->maxWordLength = ZI_WORK->unk_0x0A;
ZI_WORK->unk_0x0A = -1;
signatureFound = Zi8LangSupported(parameters->language,ZI_WORK);
if (signatureFound == '\0') {
Zi8LogError(0x163,ZI_WORK);
candidateCount = 0;
}
else {
if (parameters->language == 0x10) {
error = 0x2c1;
candidateCount = 0;
}
else if (parameters->language == 0x12) {
if ((parameters->elementCount == 0) || (0xeff0 < parameters->elements[0])) {
candidateCount = Zi8GetKOcandidates(parameters,options,ZI_WORK);
}
else {
candidateCount = Zi8GetKoreanCandidates(parameters,options,ZI_WORK);
}
}
else if ((parameters->language == 1) && ((parameters->context & 8) != 0)) {
candidateCount = Zi8Punctuation(parameters,options,ZI_WORK);
error = 100;
}
else if ((parameters->language == 1) &&
((((parameters->getOptions & 0xbf) == 4 && (parameters->elementCount != 0)) &&
(signatureFound = Zi8IsCharacter(parameters->elements[0],ZI_WORK), signatureFound != '\0')))) {
elementCount = Zi8GetCharInfo(parameters->elements[0],characterInfo,0x10,1,ZI_WORK);
if (elementCount == 0) {
parameters->unk_0x20 = 0;
parameters->count = 0;
parameters->letters = 0;
candidateCount = 0;
error = 900;
}
else {
if ((0xf330 < characterInfo[elementCount - 1]) && (characterInfo[elementCount - 1] < 0xf336)) {
characterInfo[elementCount - 1] = 0xf360;
}
savedElements = parameters->elements;
parameters->elements = characterInfo;
savedElementCount = parameters->elementCount;
parameters->elementCount = elementCount;
elementCount = parameters->getMode;
parameters->getMode = 1;
candidateCount = Zi8GetChineseCandidates(parameters,options,ZI_WORK);
parameters->elements = savedElements;
parameters->elementCount = savedElementCount;
parameters->getMode = elementCount;
parameters->count = 1;
}
}
else if ((parameters->language == 1) && (parameters->getMode == 0xf)) {
error = 0x2d0;
candidateCount = 0;
}
else if ((parameters->language == 1) && ((parameters->getMode == 3 || (parameters->getMode == 4)))) {
if ((parameters->getOptions & 0x80) == 0) {
if (parameters->elementCount == 0) {
candidateCount = Zi8GetChineseCandidates(parameters,options,ZI_WORK);
}
else {
candidateCount = Zi8Get1KeyPressCandidates(parameters,options,ZI_WORK);
}
}
else {
candidateCount = Zi8Get1KeyPressSpelling(parameters,options,ZI_WORK);
}
}
else if ((parameters->language == 1) &&
((((parameters->getMode == 7 || (parameters->getMode == 8)) || (parameters->getMode == 10)) || (parameters->getMode == 9)))) {
if (ZI_WORK->unk_0x16 == '\0') {
error = 0x708;
candidateCount = 0;
}
else {
candidateCount = Zi8GetChineseCandidates(parameters,options,ZI_WORK);
}
}
else if ((parameters->language == 1) && ((parameters->getMode == 0xb || (parameters->getMode == 0xe)))) {
error = 0x2ee;
candidateCount = 0;
}
else if (parameters->language == 1) {
candidateCount = Zi8GetChineseCandidates(parameters,options,ZI_WORK);
if ((((candidateCount == 0) && ((parameters->getOptions & 0x20) == 0)) && ((parameters->getMode == 1 && (parameters->elementCount != 0))))
&& ((((ziS16)parameters->elements[parameters->elementCount - 1] == -0xc86 ||
((ziS16)parameters->elements[parameters->elementCount - 1] == -0xc9d)) ||
((ziS16)parameters->elements[parameters->elementCount - 1] == -0xc8d)))) {
savedCharacter = parameters->elements[parameters->elementCount];
elementCount = parameters->elementCount;
parameters->elements[elementCount] = 0xf368;
parameters->elementCount = elementCount + 1;
candidateCount = Zi8GetChineseCandidates(parameters,options,ZI_WORK);
elementCount = parameters->elementCount;
parameters->elementCount = elementCount - 1;
parameters->elements[(ziU8)(elementCount - 1)] = savedCharacter;
}
}
else {
ZI_WORK->unk_0x538 = parameters->language;
restoreCandidates = (parameters->getOptions & 0x80) == 0;
if (restoreCandidates) {
savedOptions = parameters->getOptions;
savedCandidates = parameters->candidates;
parameters->getOptions = parameters->getOptions | 0x81;
parameters->candidates = (ziWChar*)&ZI_WORK->unk_0x338;
options->capacity = 0x100;
}
if (parameters->getMode == 2) {
candidateCount = Zi8GetTableCount(parameters->language,0x1f,ZI_WORK);
if ((candidateCount & 0x200) == 0) {
error = 0x44c;
candidateCount = 0;
}
else {
candidateCount = Zi8GetSyllablesCandidates(parameters,options,ZI_WORK);
}
}
else {
candidateCount = Zi8AlphaGetCandidates(parameters,options,ZI_WORK);
}
}
if (restoreCandidates) {
parameters->getOptions = savedOptions;
parameters->candidates = savedCandidates;
for (elementCount = 0; elementCount < parameters->letters; elementCount = elementCount + 1) {
parameters->candidates[elementCount] = elementCount - 0x10;
}
}
if (error != 0) {
Zi8LogError(error,ZI_WORK);
}
}
finishCandidates:
return candidateCount;
}
void Zi8InitDupWordBuf(ziPtr __zi8_work_data) {
ZI_WORK->unk_0x539 = 0;
}
ziBool Zi8IsDupWChar(ziWChar character ZI_NEED_WORK) {
ziBool duplicate = 0;
ziU16* buffer = ZI_WORK->unk_0x57A;
unsigned int index;
ziU16 position;
if (ZI_WORK->unk_0x539 == 0) {
buffer[0] = 2;
buffer[1] = character;
ZI_WORK->unk_0x539 = 1;
Zi8LogError(0x8fd, ZI_WORK);
return 0;
}
for (index = ZI_WORK->unk_0x539; index != 0; index--) {
if (character == buffer[index]) {
duplicate = 1;
break;
}
}
ZI_WORK->unk_0x539++;
position = *buffer;
buffer[position] = character;
*buffer = ++position;
if (*buffer > 100) {
*buffer = 2;
buffer[1] = character;
ZI_WORK->unk_0x539 = 1;
}
Zi8LogError(100, ZI_WORK);
return duplicate;
}
ziBool Zi8IsDupWordW(ziWChar* word, ziU8 length ZI_NEED_WORK) {
ziU8 slot;
ziU32 duplicate = 0;
unsigned int position;
int index;
int character;
if (word == 0 || length == 0) {
Zi8LogError(300, ZI_WORK);
return 0;
}
if (length > 20) {
word += length - 20;
length = 20;
}
for (index = 0; index < ZI_WORK->unk_0x539; index++) {
slot = ZI_WORK->unk_0x53A[index];
for (character = 0; character < length; character++) {
if (word[character] != ZI_WORK->unk_0x57A[slot * 21 + character]) break;
}
if (character >= length && ZI_WORK->unk_0x57A[slot * 21 + character] == 0) {
duplicate = 1;
break;
}
}
if (!duplicate) {
if (ZI_WORK->unk_0x539 < 64) {
position = ZI_WORK->unk_0x539;
ZI_WORK->unk_0x53A[ZI_WORK->unk_0x539] = ZI_WORK->unk_0x539;
ZI_WORK->unk_0x539++;
} else {
slot = ZI_WORK->unk_0x53A[0];
position = slot;
for (index = 1; index < ZI_WORK->unk_0x539; index++) {
ZI_WORK->unk_0x53A[index - 1] = ZI_WORK->unk_0x53A[index];
}
ZI_WORK->unk_0x53A[index - 1] = slot;
}
} else {
slot = ZI_WORK->unk_0x53A[index];
position = slot;
for (; index < ZI_WORK->unk_0x539 - 1; index++) {
ZI_WORK->unk_0x53A[index] = ZI_WORK->unk_0x53A[index + 1];
}
ZI_WORK->unk_0x53A[index] = slot;
}
for (index = 0; index < length; index++) {
ZI_WORK->unk_0x57A[position * 21 + index] = word[index];
}
ZI_WORK->unk_0x57A[position * 21 + index] = 0;
Zi8LogError(100, ZI_WORK);
return duplicate;
}
void Zi8Memset(ziU8* destination, ziU32 value, ziS32 count) {
ziS32 index;
for (index = 0; index < count; index++) destination[index] = (ziU8)value;
}
void Zi8Memcpy(ziU8* destination, ziU8* source, ziS32 count) {
ziS32 index;
for (index = 0; index < count; index++) destination[index] = source[index];
}
ziBool Zi8SetMaxWordLength(ziU8 length ZI_NEED_WORK) {
ZI_WORK->unk_0x0A = length;
return 1;
}

View File

@@ -0,0 +1,876 @@
#include <zi8clib/zierror.h>
#include <zi8clib/zitypes.h>
extern ziU32 Zi8GetTableAddress(ziU8 lang, ziU8 tableIdx ZI_NEED_WORK);
const ziU8 Zi8PinyinInitials[0x1C] = {
0x00, 0x3C, 0x98, 0x02, 0x00, 0x38, 0x34, 0x3B, 0x00, 0x06, 0x37, 0x2B,
0x0C, 0x26, 0x00, 0x3F, 0x09, 0x2C, 0x9A, 0x05, 0x00, 0x00, 0x11, 0x0A,
0x0D, 0x9C, 0x00, 0x00
};
const ziU8 Zi8BpmfInitials[0x24] = {
0x3C, 0x3F, 0x0C, 0x38, 0x02, 0x05, 0x26, 0x2B, 0x34, 0x37, 0x3B, 0x06,
0x09, 0x0A, 0x1D, 0x19, 0x1B, 0x2C, 0x1C, 0x18, 0x1A, 0x01, 0x02, 0x03,
0x05, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0E, 0x0D, 0x0F, 0x04, 0x00, 0x00
};
const ziU8 Zi8PinyinFinals[0x36][8] = {
{0x0F, 0xFF, 0x00, 0x00, 0x3C, 0x28, 0x00, 0x00},
{0x0F, 0x00, 0x00, 0x00, 0x3F, 0x2B, 0x00, 0x00},
{0x0F, 0x0E, 0xFF, 0x00, 0x3F, 0x28, 0x00, 0x00},
{0x0F, 0x0E, 0x07, 0x00, 0x3F, 0x28, 0x00, 0x00},
{0x0F, 0x15, 0x00, 0x00, 0x3F, 0x2A, 0x00, 0x00},
{0x09, 0xFF, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00},
{0x09, 0x00, 0x00, 0x00, 0x3F, 0x08, 0x00, 0x00},
{0x09, 0x01, 0xFF, 0x00, 0x38, 0x00, 0x00, 0x00},
{0x09, 0x01, 0x00, 0x00, 0x3F, 0x04, 0x00, 0x00},
{0x09, 0x01, 0x0F, 0x00, 0x3F, 0x01, 0x00, 0x00},
{0x09, 0x01, 0x0E, 0xFF, 0x3E, 0x02, 0x00, 0x00},
{0x09, 0x01, 0x0E, 0x00, 0x3F, 0x02, 0x00, 0x00},
{0x09, 0x01, 0x0E, 0x07, 0x3F, 0x03, 0x00, 0x00},
{0x09, 0x05, 0x00, 0x00, 0x3F, 0x09, 0x00, 0x00},
{0x09, 0x15, 0x00, 0x00, 0x3F, 0x0B, 0x00, 0x00},
{0x09, 0x0E, 0xFF, 0x00, 0x3E, 0x0C, 0x00, 0x00},
{0x09, 0x0E, 0x00, 0x00, 0x3F, 0x0C, 0x00, 0x00},
{0x09, 0x0E, 0x07, 0x00, 0x3F, 0x0D, 0x00, 0x00},
{0x09, 0x0F, 0xFF, 0x00, 0x3E, 0x0E, 0x00, 0x00},
{0x09, 0x0F, 0x15, 0x00, 0x3F, 0x0E, 0x00, 0x00},
{0x09, 0x0F, 0x0E, 0xFF, 0x3F, 0x0F, 0x00, 0x00},
{0x09, 0x0F, 0x0E, 0x07, 0x3F, 0x0F, 0x00, 0x00},
{0x15, 0xFF, 0x00, 0x00, 0x30, 0x10, 0x00, 0x00},
{0x15, 0x00, 0x00, 0x00, 0x3F, 0x18, 0x00, 0x00},
{0x15, 0x01, 0xFF, 0x00, 0x38, 0x10, 0x00, 0x00},
{0x15, 0x01, 0x00, 0x00, 0x3F, 0x17, 0x00, 0x00},
{0x15, 0x01, 0x0E, 0xFF, 0x3E, 0x10, 0x00, 0x00},
{0x15, 0x01, 0x0E, 0x00, 0x3F, 0x10, 0x00, 0x00},
{0x15, 0x01, 0x0E, 0x07, 0x3F, 0x11, 0x00, 0x00},
{0x15, 0x01, 0x09, 0x00, 0x3F, 0x13, 0x00, 0x00},
{0x15, 0x0E, 0x00, 0x00, 0x3F, 0x1C, 0x00, 0x00},
{0x15, 0x09, 0x00, 0x00, 0x3F, 0x1D, 0x00, 0x00},
{0x15, 0x0F, 0x00, 0x00, 0x3F, 0x1E, 0x00, 0x00},
{0x15, 0x05, 0x00, 0x00, 0x3F, 0x1F, 0x00, 0x00},
{0x01, 0xFF, 0x00, 0x00, 0x38, 0x20, 0x00, 0x00},
{0x01, 0x00, 0x00, 0x00, 0x3F, 0x23, 0x00, 0x00},
{0x01, 0x0E, 0xFF, 0x00, 0x3E, 0x20, 0x00, 0x00},
{0x01, 0x0E, 0x00, 0x00, 0x3F, 0x20, 0x00, 0x00},
{0x01, 0x0E, 0x07, 0x00, 0x3F, 0x21, 0x00, 0x00},
{0x01, 0x09, 0x00, 0x00, 0x3F, 0x25, 0x00, 0x00},
{0x01, 0x0F, 0x00, 0x00, 0x3F, 0x26, 0x00, 0x00},
{0x05, 0xFF, 0x00, 0x00, 0x38, 0x30, 0x00, 0x00},
{0x05, 0x00, 0x00, 0x00, 0x3F, 0x34, 0x00, 0x00},
{0x05, 0x0E, 0xFF, 0x00, 0x3E, 0x30, 0x00, 0x00},
{0x05, 0x0E, 0x00, 0x00, 0x3F, 0x30, 0x00, 0x00},
{0x05, 0x0E, 0x07, 0x00, 0x3F, 0x31, 0x00, 0x00},
{0x05, 0x09, 0x00, 0x00, 0x3F, 0x35, 0x00, 0x00},
{0x05, 0x12, 0x00, 0x00, 0x3F, 0x33, 0x00, 0x00},
{0x16, 0xFF, 0x00, 0x00, 0x3C, 0x38, 0x00, 0x00},
{0x16, 0x00, 0x00, 0x00, 0x3F, 0x38, 0x00, 0x00},
{0x16, 0x01, 0xFF, 0x00, 0x3F, 0x39, 0x00, 0x00},
{0x16, 0x01, 0x0E, 0x00, 0x3F, 0x39, 0x00, 0x00},
{0x16, 0x05, 0x00, 0x00, 0x3F, 0x1F, 0x00, 0x00},
{0x16, 0x0E, 0x00, 0x00, 0x3F, 0x3B, 0x00, 0x00}
};
const ziU8 nodeHeaderTable[0x20] = {
0x00, 0x10, 0x00, 0x01, 0x00, 0x03, 0x00, 0x14, 0x00, 0x05, 0x00, 0x07,
0x00, 0x1C, 0x00, 0x0D, 0x00, 0x0F, 0x00, 0x11, 0x00, 0x13, 0x00, 0x15,
0x00, 0x17, 0x00, 0x1D, 0x00, 0x1F, 0x00, 0x35
};
ziBool Zi8PriMatchNextChar(ziU8* node, ziU8 mask0, ziU8 value0, ziU8 mask1, ziU8 value1, ziU8 mask2, ziU8 value2, ziU8 mask3, ziU8 value3, ziU16* count, ziU8** result, ziU16* code ZI_NEED_WORK) {
ziU16 remaining = *count;
while (remaining-- != 0) {
if ((value0 == (node[0] & mask0)) && (value3 == (node[3] & mask3)) && (value2 == (node[2] & mask2)) && (value1 == (node[1] & mask1))) {
*result = node;
*code = ((ziU16)node[6] << 8) + (ziU16)node[7];
*count = remaining;
Zi8LogError(0x64, ZI_WORK);
return 1;
}
node += 0xC;
}
Zi8LogError(0x12E, ZI_WORK);
return 0;
}
ziBool Zi8ExactMatchNextChar(ziU8* node, ziU8 mask0, ziU8 value0, ziU8 mask1, ziU8 value1, ziU8 mask2, ziU8 value2, ziU8 mask3, ziU8 value3, ziU16* count, ziU8** result, ziU16* code ZI_NEED_WORK) {
ziU16 remaining = *count;
ziU8* current = node;
while (remaining-- != 0) {
if ((value0 == (current[0] & mask0)) && (value3 == (current[3] & mask3)) && (value2 == (current[2] & mask2)) && (value1 == (current[1] & mask1))) {
*result = current;
*code = ((ziU16)current[6] << 8) + (ziU16)current[7];
*count = remaining;
Zi8LogError(0x64, ZI_WORK);
return 1;
}
current += 0xC;
}
Zi8LogError(0x12E, ZI_WORK);
return 0;
}
ziU32 Zi8SecMatchChar(ziPtr nodeAddress, ziU8* dictionaryAddress, ziMatchParam* match, ziU16* code ZI_NEED_WORK) {
ziBool isPartial = 0;
ziU16 matchCode;
ziU8* data;
ziU8 value;
struct {
ziU8 remaining;
ziU8 dataIndex;
ziU16 targetCode;
} state;
if (match->field22 != 0) {
state.targetCode = match->field22;
matchCode = ((ziU16)(((ziU8*)nodeAddress)[4] & 3) << 8) | ((ziU8*)nodeAddress)[5];
value = 0;
while (value++ < 6) {
if (state.targetCode == matchCode) {
break;
}
matchCode = ((ziU16)(*(dictionaryAddress + matchCode * 8 + 6) & 3) << 8) | *(dictionaryAddress + matchCode * 8 + 7);
if (matchCode == 0) {
break;
}
}
if (state.targetCode != matchCode) {
return 0;
}
}
data = (ziU8*)Zi8GetTableAddress(1, 1, ZI_WORK);
data += ((ziU8*)nodeAddress)[0xB] + (((ziU8*)nodeAddress)[0xA] << 8) + ((((ziU8*)nodeAddress)[9] & 0xF) << 16);
if (ZI_WORK->unk_0x16 != 0) {
switch (data[0] & 7) {
case 2:
data += 2;
break;
case 3:
case 4:
data += 3;
break;
case 5:
data += 4;
break;
default:
data++;
break;
}
}
value = data[0];
value = (value >> 4) & 7;
if (value * 2 + 10 < match->length) {
return 0;
}
if (match->length < 9) {
if (match->length == 8) {
if ((data[0] & 0xF) == 0xF) {
isPartial = 1;
}
} else if ((match->length & 1) != 0) {
if ((((ziU8*)nodeAddress)[match->length >> 1] & 0xF) == 0xF) {
isPartial = 1;
}
} else {
if ((((ziU8*)nodeAddress)[match->length >> 1] & 0xF0) == 0xF0) {
isPartial = 1;
}
}
if (match->length > 2) {
if ((match->length & 1) != 0) {
if (((((ziU8*)nodeAddress)[(match->length - 1) >> 1] & 0xF0) == 0) || ((((ziU8*)nodeAddress)[(match->length - 1) >> 1] & 0xF0) == 0xF0)) {
return 0;
}
} else {
if (((((ziU8*)nodeAddress)[(match->length - 1) >> 1] & 0xF) == 0) || ((((ziU8*)nodeAddress)[(match->length - 1) >> 1] & 0xF) == 0xF)) {
return 0;
}
}
}
if (code != 0) {
*code = ((ziU16)((ziU8*)nodeAddress)[6] << 8) + (ziU16)((ziU8*)nodeAddress)[7];
}
if (isPartial) {
return 2;
}
return 1;
}
if ((match->length & 1) != 0) {
if (((data[((match->length - 1) >> 1) - 4] & 0xF0) == 0) || ((data[((match->length - 1) >> 1) - 4] & 0xF0) == 0xF0)) {
return 0;
}
} else {
if (((data[((match->length - 1) >> 1) - 4] & 0xF) == 0) || ((data[((match->length - 1) >> 1) - 4] & 0xF) == 0xF)) {
return 0;
}
}
state.dataIndex = 4;
state.remaining = ((match->length + 1) >> 1) - 4;
if (((ziU8)value + 1) < (int)state.remaining) {
return 0;
}
if ((match->length & 1) != 0) {
if ((data[(match->length >> 1) - 4] & 0xF) == 0xF) {
isPartial = 1;
}
} else {
if ((data[(match->length >> 1) - 4] & 0xF0) == 0xF0) {
isPartial = 1;
}
}
if (match->count == 0) {
while (state.remaining != 0) {
if ((data[0] & match->arr1[state.dataIndex]) != match->arrD[state.dataIndex]) {
return 0;
}
state.dataIndex++;
state.remaining--;
data++;
}
}
if (code != 0) {
*code = ((ziU16)((ziU8*)nodeAddress)[6] << 8) + (ziU16)((ziU8*)nodeAddress)[7];
}
if (isPartial) {
return 2;
}
return 1;
}
ziBool Zi8PriMatchNextComp(ziU8* node, ziU8 mask0, ziU8 value0, ziU8 mask1, ziU8 value1, ziU8 mask2, ziU8 value2, ziU8 mask3, ziU8 value3, ziU16* count, ziU8** result ZI_NEED_WORK) {
ziU16 remaining = *count;
while (remaining-- != 0) {
if ((value0 == (node[0] & mask0)) && (value1 == (node[1] & mask1)) && (value2 == (node[2] & mask2)) && (value3 == (node[3] & mask3))) {
*result = node;
*count = remaining;
Zi8LogError(0x64, ZI_WORK);
return 1;
}
node += 8;
}
Zi8LogError(0x12E, ZI_WORK);
return 0;
}
ziBool Zi8SecMatchComp(ziPtr nodeAddress, ziMatchParam* matchAddress, ziPtr dictionaryAddress) {
int chainIndex;
ziU16 matchCode;
ziU16 targetCode;
if (matchAddress->field22 != 0) {
targetCode = matchAddress->field22;
matchCode = ((ziU16)(((ziU8*)nodeAddress)[6] & 3) << 8) | ((ziU8*)nodeAddress)[7];
chainIndex = 0;
while (chainIndex++ < 6) {
if (targetCode == matchCode) {
break;
}
matchCode = ((ziU16)(*((ziU8*)dictionaryAddress + matchCode * 8 + 6) & 3) << 8) | *((ziU8*)dictionaryAddress + matchCode * 8 + 7);
if (matchCode == 0) {
break;
}
}
if (targetCode != matchCode) {
return 0;
}
}
if (matchAddress->length > 8) {
if ((int)((ziU8*)nodeAddress)[5] < (int)(matchAddress->length - 2)) {
return 0;
}
} else if ((int)((ziU8*)nodeAddress)[5] < (int)(matchAddress->length - 1)) {
return 0;
}
return 1;
}
extern ziU16 Zi8MatchAltSound(ziPtr soundTable, ziU16 soundCode, ziPtr pCodeTable, ziU16 index, ziU16 mask, ziU16 value, ziU8 flag ZI_NEED_WORK);
ziU16 Zi8GetPCode(ziU8* table, ziU8* node);
ziBool Zi8MatchPhonetic(ziPtr pCodeTable, ziPtr dictionary, ziPtr soundTable, ziU16 soundCode, ziU32 tableAddress, ziU8* node, ziU16* masks, ziU16* values, ziU16* count, ziU8** resultNode, ziU8** stringOffset, ziS8 partialMode, ziU8 strictMode, ziU8 numParts, ziU16 partMask, ziU16 partValue, ziU8 flag, ziU8 altMode, ziU16 initialCode, ziU16* resultCode, ziU8 lastMode ZI_NEED_WORK) {
ziBool hasString;
ziU32 matchedParts;
ziU32 altModeActive;
ziU8 partCode;
ziU8 partCount;
ziU8 partIndex;
ziU16 soundIndex;
ziU16 remaining;
ziU16 code;
ziU16 dictionaryIndex;
ziU8 nextCode;
ziU8* sound;
ziU8* nextPart;
if (*stringOffset != 0) {
hasString = 1;
} else {
hasString = 0;
}
if (*count == 0) {
remaining = 1;
} else {
remaining = *count;
}
matchedParts = 0;
altModeActive = altMode;
if ((lastMode != 0) && (numParts > 1)) {
altModeActive = 1;
}
while (remaining-- != 0) {
if ((node[0] & flag) != 0) {
code = Zi8GetPCode((ziU8*)pCodeTable, node);
if ((*values != (code & *masks)) && (altModeActive == 0) && ((node[0] & 0x80) != 0)) {
if (*count != 0) {
soundIndex = (initialCode - remaining) - 1;
} else {
soundIndex = initialCode;
}
code = Zi8MatchAltSound(soundTable, soundCode, pCodeTable, soundIndex, *masks, *values, flag, ZI_WORK);
}
if ((*values == (code & *masks)) && (partValue != (code & partMask))) {
matchedParts = 1;
sound = (ziU8*)((tableAddress + ((node[9] & 0xF) * 0x10000)) + node[0xB] + node[0xA] * 0x100);
if (ZI_WORK->unk_0x16 != 0) {
switch (sound[0] & 7) {
case 2:
sound += 2;
break;
case 3:
case 4:
sound += 3;
break;
case 5:
sound += 4;
break;
default:
sound++;
break;
}
}
if ((sound[0] & 0x80) != 0) {
sound += ((sound[0] & 0x7F) >> 4) + 1;
} else if (numParts > 1) {
goto next_node;
}
if (((ziU8)matchedParts == numParts) || (numParts == 0)) {
*resultNode = node;
*resultCode = ((ziU16)node[6] << 8) + node[7];
*count = remaining;
return 1;
}
do {
nextCode = *sound++;
partCount = nextCode & 0xF;
if ((nextCode & flag) == 0) {
for (; partCount != 0; partCount--) {
for (sound++; (*sound & 0x80) == 0; sound += 2) {
}
sound++;
}
}
for (; partCount != 0; partCount--) {
partIndex = 1;
if (hasString && (*stringOffset < sound)) {
hasString = 0;
}
nextPart = sound;
if (!hasString) {
*stringOffset = sound;
}
do {
partCode = nextPart[1];
dictionaryIndex = ((ziU16)partCode << 8) | nextPart[0];
sound = nextPart + 2;
if (hasString) {
goto phonetic_skip;
}
code = Zi8GetPCode((ziU8*)pCodeTable, (ziU8*)dictionary + (dictionaryIndex & 0x7FFF) * 0xC);
if (((code & masks[partIndex]) != values[partIndex]) && (altModeActive == 0) && (((ziU8*)dictionary)[(dictionaryIndex & 0x7FFF) * 0xC] & 0x80) != 0) {
code = Zi8MatchAltSound(soundTable, soundCode, pCodeTable, dictionaryIndex & 0x7FFF, masks[partIndex], values[partIndex], flag, ZI_WORK);
}
if ((code & masks[partIndex]) != values[partIndex]) {
goto phonetic_skip;
}
partIndex++;
if (partIndex == numParts) {
if ((partialMode != 0) && ((strictMode == 0 && (partCode & 0x80) != 0) || (strictMode != 0 && (partCode & 0x80) == 0))) {
goto phonetic_skip;
}
*resultNode = node;
code = ((ziU16)node[6] << 8) + node[7];
*resultCode = code;
*count = remaining;
return 1;
}
nextPart = sound;
} while ((partCode & 0x80) == 0);
continue;
phonetic_skip:
if ((partCode & 0x80) == 0) {
nextPart += 3;
while ((*nextPart & 0x80) == 0) {
nextPart += 2;
}
sound = nextPart + 1;
}
}
} while ((nextCode & 0x80) == 0);
}
}
next_node:
node += 0xC;
}
return 0;
}
ziBool Zi8GetPyFinal(ziU8* pinyin, ziU8* initial, ziU8* final);
ziU8 Zi8GetPyPhonetic(ziWChar* text, ziU8 count, ziU16* initial, ziU16* final, ziU8* resultCount, ziU16* bestInitial, ziU16* bestFinal ZI_NEED_WORK) {
ziU8 firstInitial;
ziU8 pyFinal;
ziU8 pyInitial;
ziU8 convertedCount;
ziBool partial;
ziU8 result;
ziU8 outputIndex;
ziU8 partCount;
ziU16 value;
ziU8 index;
ziWChar converted[256];
ziWChar* current;
ziU8 pinyin[12];
current = converted;
result = 0;
*resultCount = 0;
if (count == 0) {
Zi8LogError(0x135, ZI_WORK);
return 0;
}
convertedCount = 0;
for (index = 0; index < count; index++) {
if (((text[index] >= 0xF341) && (text[index] <= 0xF35A)) || ((text[index] >= 0x41) && (text[index] <= 0x5A))) {
if ((convertedCount != 0) && (current[convertedCount - 1] != 0xF360) && (current[convertedCount - 1] != 0x27)) {
current[convertedCount] = 0x27;
convertedCount++;
}
current[convertedCount] = (text[index] & 0xFF) + 0x20;
} else {
current[convertedCount] = text[index];
}
convertedCount++;
}
count = convertedCount;
outputIndex = 0;
*bestInitial = 0;
*bestFinal = 0;
while ((outputIndex < 0x10) && (count != 0)) {
initial[outputIndex] = 0;
final[outputIndex] = 0;
value = *current;
if (value < 0x61) {
goto check_pinyin_extension;
}
if (value <= 0x7A) {
goto pinyin_ascii;
}
check_pinyin_extension:
if (value < 0xF361) {
goto invalid_pinyin;
}
if (value <= 0xF37A) {
value += 0xC9F;
goto pinyin_initial;
}
invalid_pinyin:
initial[0] = 0xFFFF;
final[0] = 0xFFFF;
*bestInitial = 0xFFFF;
*bestFinal = 0xFFFF;
return 1;
pinyin_ascii:
value -= 0x61;
pinyin_initial:
firstInitial = Zi8PinyinInitials[value];
if (firstInitial != 0) {
if (outputIndex == 0) {
*resultCount = *resultCount + 1;
}
result++;
initial[outputIndex] = 0x7E00;
final[outputIndex] = (ziU16)firstInitial << 9;
*bestInitial = initial[outputIndex];
*bestFinal = final[outputIndex];
count--;
if (count == 0) {
break;
}
current += 1;
if (((firstInitial & 0x80) != 0) && ((current[0] == 0x68) || (current[0] == 0xF368))) {
if (outputIndex == 0) {
*resultCount = *resultCount + 1;
}
final[outputIndex] += 0x200;
*bestInitial = initial[outputIndex];
*bestFinal = final[outputIndex];
count--;
if (count == 0) {
break;
}
current += 1;
}
} else if ((*current == 0xF369) || (*current == 0x69)) {
goto invalid_pinyin;
}
partial = 0;
for (index = 0; index < 4; index++) {
pinyin[index] = 0;
}
index = 0;
do {
while (1) {
if (index > 3) {
goto finish_final;
}
value = *current;
if ((value == 0x27) || (value == 0xF360) || (value == 0x20)) {
if (index != 0) {
partial = 1;
}
goto finish_final;
}
if ((value > 0xF330) && (value < 0xF336)) {
if (index != 0) {
partial = 1;
}
goto finish_final;
}
if ((value < 0x61) || (value > 0x7A)) {
if (value < 0xF361) {
goto finish_final;
}
value += 0xC9F;
if (value > 0x19) {
if (outputIndex == 0) {
*resultCount = *resultCount + 1;
}
goto finish_final;
}
} else {
value -= 0x61;
}
pinyin[index] = (ziU8)value + 1;
if (Zi8GetPyFinal(pinyin, &pyInitial, &pyFinal) == 0) {
break;
}
if (outputIndex == 0) {
*resultCount = *resultCount + 1;
}
current++;
index++;
count--;
if (count == 0) {
goto finish_final;
}
}
if (index > 2) {
pinyin[index] = 0;
partial = 1;
break;
}
pinyin[index + 1] = 0xFF;
if (Zi8GetPyFinal(pinyin, &pyInitial, &pyFinal) == 0) {
pinyin[index + 1] = 0;
pinyin[index] = 0;
partial = 1;
break;
}
if (outputIndex == 0) {
*resultCount = *resultCount + 1;
}
pinyin[index + 1] = 0;
current++;
index++;
count--;
} while (count != 0);
finish_final:
if ((index > 3) && (count != 0) && ((*current == 0x27) || (*current == 0xF360) || (*current == 0x20))) {
if (outputIndex == 0) {
*resultCount = *resultCount + 1;
}
current++;
count--;
}
if (index > 3) {
partial = 1;
}
if (!partial) {
pinyin[index] = 0xFF;
if (Zi8GetPyFinal(pinyin, &pyInitial, &pyFinal) == 0) {
pinyin[index] = 0;
if (Zi8GetPyFinal(pinyin, &pyInitial, &pyFinal) != 0) {
if (firstInitial == 0) {
result++;
initial[outputIndex] = 0x7E00;
final[outputIndex] = 0x200;
}
initial[outputIndex] |= (ziU16)pyInitial << 3;
final[outputIndex] |= (ziU16)pyFinal << 3;
*bestInitial = initial[outputIndex];
*bestFinal = final[outputIndex];
}
} else {
if (firstInitial == 0) {
result++;
initial[outputIndex] = 0x7E00;
final[outputIndex] = 0x200;
}
initial[outputIndex] |= (ziU16)pyInitial << 3;
final[outputIndex] |= (ziU16)pyFinal << 3;
*bestInitial = initial[outputIndex];
*bestFinal = final[outputIndex];
if ((outputIndex == 0) && (count == 0)) {
pinyin[index] = 0;
if (Zi8GetPyFinal(pinyin, &pyInitial, &pyFinal) != 0) {
if (firstInitial == 0) {
*bestInitial = 0x7E00;
*bestFinal = 0x200;
}
*bestInitial |= (ziU16)pyInitial << 3;
*bestFinal |= (ziU16)pyFinal << 3;
}
}
}
} else {
if (Zi8GetPyFinal(pinyin, &pyInitial, &pyFinal) != 0) {
if (firstInitial == 0) {
result++;
initial[outputIndex] = 0x7E00;
final[outputIndex] = 0x200;
}
initial[outputIndex] |= (ziU16)pyInitial << 3;
final[outputIndex] |= (ziU16)pyFinal << 3;
*bestInitial = initial[outputIndex];
*bestFinal = final[outputIndex];
} else {
if ((index != 0) && (count != 0)) {
goto invalid_pinyin;
}
}
}
convertedCount = count;
if (count != 0) {
value = *current;
if ((value == 0x27) || (value == 0xF360) || (value == 0x20)) {
current++;
convertedCount = count - 1;
if (outputIndex == 0) {
*resultCount = *resultCount + 1;
}
} else if ((value > 0xF330) && ((ziU16)(value + 0xCCF) < 5)) {
initial[outputIndex] |= 7;
final[outputIndex] |= value + 0xCD0;
*bestInitial = initial[outputIndex];
*bestFinal = final[outputIndex];
convertedCount = count - 1;
current++;
if (outputIndex == 0) {
*resultCount = *resultCount + 1;
}
if ((convertedCount != 0) && ((*current == 0x27) || (*current == 0xF360) || (*current == 0x20))) {
convertedCount = count - 2;
current++;
if (outputIndex == 0) {
*resultCount = *resultCount + 1;
}
}
}
}
count = convertedCount;
outputIndex++;
}
if ((*resultCount > 1) && (text[*resultCount - 1] > 0xF340) && (text[*resultCount - 1] < 0xF35B)) {
*resultCount = *resultCount - 1;
}
return result;
}
ziBool Zi8GetPyFinal(ziU8* pinyin, ziU8* initial, ziU8* final) {
ziU8 index = 0;
ziU8 row;
row = 0;
goto check_row;
scan_row:
while (index < 4) {
if (pinyin[index] != Zi8PinyinFinals[row][index]) {
break;
}
index++;
}
if (index < 4) {
goto next_row;
}
*initial = Zi8PinyinFinals[row][4];
*final = Zi8PinyinFinals[row][5];
return 1;
next_row:
row++;
index = 0;
check_row:
if (row < 0x36) {
goto scan_row;
}
return 0;
}
ziS32 Zi8GetBpmfPhonetic(ziWChar* text, ziU8 count, ziU16* initial, ziU16* final, ziU16* bestInitial, ziU16* bestFinal ZI_NEED_WORK) {
ziU16 value;
ziU32 resultCount = 0;
Zi8LogError(0x64, ZI_WORK);
if (count == 0) {
Zi8ReplaceLastError(0x135, ZI_WORK);
return 0;
}
value = text[0];
if (value < 0xF305) {
Zi8ReplaceLastError(0x154, ZI_WORK);
return 0;
}
value -= 0xF305;
if (value >= 0x25) {
Zi8ReplaceLastError(0x154, ZI_WORK);
return 0;
}
if (value < 0x15) {
*initial = 0x7E00;
*final = ((ziU16)Zi8BpmfInitials[value] & 0x7F) << 9;
resultCount++;
count--;
if (count == 0) {
*bestInitial = *initial;
*bestFinal = *final;
if ((value >= 0xE) && (value <= 0x14)) {
*bestInitial |= 0x1F8;
*bestFinal |= 0x38;
}
return resultCount;
}
text++;
if (*text == 0xF360) {
resultCount++;
count--;
if (count == 0) {
return resultCount;
}
Zi8ReplaceLastError(0x156, ZI_WORK);
return 0;
}
} else {
*initial = 0x7E00;
*final = 0x200;
}
value = *text - 0xF305;
switch ((ziS32)value) {
case 0x22:
goto bpmf_value_22;
case 0x23:
goto bpmf_value_23;
case 0x24:
goto bpmf_value_24;
default:
goto set_bpmf_initial;
}
bpmf_value_22:
*final |= 0x80;
*initial |= 0x180;
resultCount++;
count--;
if (count == 0) {
*bestInitial = *initial | 0x78;
*bestFinal = *final | 0x38;
return resultCount;
}
text++;
goto after_bpmf_initial;
bpmf_value_23:
*final |= 0x100;
*initial |= 0x180;
resultCount++;
count--;
if (count == 0) {
*bestInitial = *initial | 0x78;
*bestFinal = *final | 0x38;
return resultCount;
}
text++;
goto after_bpmf_initial;
bpmf_value_24:
*final |= 0x180;
*initial |= 0x180;
resultCount++;
count--;
if (count == 0) {
*bestInitial = *initial | 0x78;
*bestFinal = *final | 0x38;
return resultCount;
}
text++;
goto after_bpmf_initial;
set_bpmf_initial:
if ((*text < 0xF331) || (*text > 0xF335)) {
*initial |= 0x180;
}
after_bpmf_initial:
value = *text - 0xF305;
if ((value > 0x14) && (value < 0x22)) {
*final |= (ziU16)Zi8BpmfInitials[value] << 3;
*initial |= 0x78;
resultCount++;
count--;
if (count == 0) {
*bestInitial = *initial;
*bestFinal = *final;
return resultCount;
}
text++;
} else if ((*text < 0xF331) || (*text > 0xF335) || ((*initial & 0x180) == 0x180)) {
*final |= 0x38;
*initial |= 0x78;
}
value = *text;
if (value < 0xF331) {
Zi8ReplaceLastError(0x155, ZI_WORK);
return 0;
}
value -= 0xF330;
if (value > 5) {
Zi8ReplaceLastError(0x155, ZI_WORK);
return 0;
}
*initial |= 7;
*final |= value;
*bestInitial = *initial;
*bestFinal = *final;
resultCount++;
count--;
if (count != 0) {
Zi8ReplaceLastError(0x157, ZI_WORK);
return 0;
}
return resultCount;
}
ziU16 Zi8GetPCode(ziU8* table, ziU8* node) {
ziU16 index = ((ziU16)node[8] << 2) | (((ziU16)node[9] & 0x80) >> 6);
return ((((ziU16)node[9] >> 4) & 7) | (ziU16)table[index] | ((ziU16)table[index + 1] << 8));
}

View File

@@ -0,0 +1,423 @@
#include <zi8clib/zierror.h>
#include <zi8clib/zitypes.h>
ziU32 Zi8GetTableAddress(ziU8 lang, ziU8 tableIdx, ziPtr workData);
ziU16 Zi8GetTableCount(ziU8 lang, ziU8 tableIdx, ziPtr workData);
ziU8 Zi8_814813FC(ziWChar character, ziU8* result, ziU16* index, ziPtr workData) {
ziU16 i;
ziU8* table;
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 5, workData);
i = 0;
while (table[i] != 0) {
if (character == table[i]) {
*index = i;
*result = table[i];
Zi8LogError(0x64, workData);
return 1;
}
i++;
}
Zi8LogError(0x2A8, workData);
return 0;
}
ziU8 Zi8_81481E6C(ziU16* resultIndex, ziU16* input, ziU8 type, ziU16 count, ziPtr workData);
ziU8 Zi8GetKoreanCandidates(ziGetParam* params, ziU8* argument,
ziPtr workData) {
struct {
ziU8 characterIndex;
ziU8 matched;
ziU8 elementIndex;
ziU8 reserved;
ziU16 index;
ziU16 currentCandidate;
ziU16 inputIndex;
ziU16 nextIndex;
ziU16 tableCount31;
ziU16 tableCount6;
ziU16 tableCount3;
ziU16 tableCount0;
ziU8* table31;
ziU8* table2;
ziU8* table1;
} state;
ziU16 buffer[100];
ziU8 result;
ziU16 currentCharacter;
ziU8* selectedTable;
state.nextIndex = 0;
result = 0;
state.characterIndex = 0xFF;
state.currentCandidate = params->firstCandidate;
params->unk_0x20 = 0;
params->count = 0;
params->letters = 0;
if ((argument != 0) && (*argument != 0)) {
Zi8LogError(0x7D0, workData);
return 0;
}
if ((params->elementCount == 0) || (params->elementCount > 100)) {
Zi8LogError(0x64, workData);
return 0;
}
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 4, workData);
state.table1 = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 1, workData);
state.table2 = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 2, workData);
state.table31 = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x31, workData);
state.tableCount0 = Zi8GetTableCount(ZI8_LANG_KO, 0, workData);
state.tableCount3 = Zi8GetTableCount(ZI8_LANG_KO, 3, workData);
state.tableCount6 = Zi8GetTableCount(ZI8_LANG_KO, 6, workData);
state.tableCount31 = Zi8GetTableCount(ZI8_LANG_KO, 0x31, workData);
for (state.elementIndex = 0; state.elementIndex < params->elementCount;
state.elementIndex++) {
currentCharacter = params->elements[state.elementIndex];
if ((currentCharacter >= 0x61) && (currentCharacter <= 0x7A)) {
buffer[state.elementIndex] = state.table1[(currentCharacter - 0x61) * 2];
} else if ((currentCharacter >= 0x41) && (currentCharacter <= 0x5A)) {
buffer[state.elementIndex] = state.table1[(currentCharacter - 0x41) * 2 + 1];
} else {
state.matched = 0;
for (; state.table2[state.matched * 3] != 0; state.matched++) {
if (currentCharacter == state.table2[state.matched * 3]) break;
}
if (state.table2[(state.matched * 3)] == 0) {
Zi8LogError(0x161, workData);
return 0;
}
buffer[state.elementIndex] =
(state.table2[(state.matched * 3) + 1] << 8) |
state.table2[(state.matched * 3) + 2];
}
}
for (currentCharacter = 0; currentCharacter < state.elementIndex; currentCharacter++) {
state.inputIndex = 0;
if (Zi8_814813FC(buffer[currentCharacter], (ziU8*)&state.characterIndex,
(ziU16*)&state.inputIndex, workData) == 0) {
state.matched = 0;
} else {
state.matched = Zi8_81481E6C((ziU16*)&state.nextIndex,
&buffer[currentCharacter + 1],
state.characterIndex,
(state.elementIndex - currentCharacter) - 1,
workData);
if ((((struct __zi8_work_data_s*)workData)->unk_0x1B30 == 1) && (state.characterIndex < 0x1F)) {
switch (state.characterIndex) {
case 1:
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x1E, workData);
break;
case 2:
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x1F, workData);
break;
case 4:
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x20, workData);
break;
case 7:
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x21, workData);
break;
case 8:
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x22, workData);
break;
case 9:
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x23, workData);
break;
case 0x11:
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x24, workData);
break;
case 0x12:
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x25, workData);
break;
case 0x13:
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x26, workData);
break;
case 0x15:
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x27, workData);
break;
case 0x16:
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x28, workData);
break;
case 0x17:
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x29, workData);
break;
case 0x18:
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x2A, workData);
break;
case 0x19:
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x2B, workData);
break;
case 0x1A:
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x2C, workData);
break;
case 0x1B:
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x2D, workData);
break;
case 0x1C:
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x2E, workData);
break;
case 0x1D:
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x2F, workData);
break;
case 0x1E:
selectedTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x30, workData);
break;
default:
break;
}
}
}
if (state.matched == 0) {
if (state.currentCandidate == 0) {
for (state.index = 0; state.index < state.tableCount31; state.index++) {
if (((ziU16)state.table31[(state.index * 3)] == buffer[currentCharacter]) &&
((ziU16)state.table31[(state.index * 3) + 1] == buffer[currentCharacter + 1])) {
if (currentCharacter == 0) {
params->count = 1;
}
params->candidates[result] =
state.tableCount0 + state.table31[(state.index * 3) + 2];
result++;
currentCharacter++;
break;
}
}
if (state.index == state.tableCount31) {
params->candidates[result] = buffer[currentCharacter];
if (buffer[currentCharacter] < 0xFF) {
if (currentCharacter == 0) {
params->count = 1;
}
params->candidates[result] += state.tableCount0;
result++;
}
}
} else {
state.index = 0;
while ((state.index < state.tableCount31) &&
(((ziU16)state.table31[(state.index * 3)] != buffer[currentCharacter]) ||
((ziU16)state.table31[(state.index * 3) + 1] != buffer[currentCharacter + 1]))) {
state.index++;
}
if (state.index == state.tableCount31) {
state.currentCandidate--;
}
if (currentCharacter == 0) {
params->count = 1;
}
}
} else {
if (state.tableCount6 == 0) {
state.nextIndex += state.inputIndex * state.tableCount3;
}
if (state.currentCandidate == 0) {
params->candidates[result] =
(selectedTable[state.nextIndex * 2] << 8) | selectedTable[state.nextIndex * 2 + 1];
if ((state.tableCount6 != 0) && (((struct __zi8_work_data_s*)workData)->unk_0x1B30 == 0)) {
params->candidates[result] += state.inputIndex * state.tableCount3;
}
result++;
} else {
state.currentCandidate--;
}
if (currentCharacter == 0) {
params->count = state.matched + 1;
}
currentCharacter += state.matched;
}
if (result >= params->maxCandidates) {
break;
}
}
params->letters = result;
Zi8LogError(0x64, workData);
return result;
}
ziU8 Zi8_81481E6C(ziU16* resultIndex, ziU16* input, ziU8 type, ziU16 count, ziPtr workData) {
ziU16 nestedScratch;
ziU16 nestedIndexStorage;
ziU16 index1;
ziU16 index2;
ziU16 index3;
ziU16 index4;
ziU16 firstCharacter;
ziU16 tableCount;
ziU8 mappedCharacter;
ziU8* table;
firstCharacter = input[0];
mappedCharacter = 0xFF;
if (((struct __zi8_work_data_s*)workData)->unk_0x1B30 == 0) {
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 3, workData);
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 3, workData);
} else {
switch (type) {
case 1:
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0xB, workData);
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0xB, workData);
break;
case 2:
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0xC, workData);
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0xC, workData);
break;
case 4:
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0xD, workData);
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0xD, workData);
break;
case 7:
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0xE, workData);
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0xE, workData);
break;
case 8:
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0xF, workData);
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0xF, workData);
break;
case 9:
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x10, workData);
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x10, workData);
break;
case 0x11:
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x11, workData);
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x11, workData);
break;
case 0x12:
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x12, workData);
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x12, workData);
break;
case 0x13:
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x13, workData);
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x13, workData);
break;
case 0x15:
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x14, workData);
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x14, workData);
break;
case 0x16:
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x15, workData);
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x15, workData);
break;
case 0x17:
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x16, workData);
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x16, workData);
break;
case 0x18:
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x17, workData);
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x17, workData);
break;
case 0x19:
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x18, workData);
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x18, workData);
break;
case 0x1A:
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x19, workData);
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x19, workData);
break;
case 0x1B:
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x1A, workData);
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x1A, workData);
break;
case 0x1C:
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x1B, workData);
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x1B, workData);
break;
case 0x1D:
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x1C, workData);
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x1C, workData);
break;
case 0x1E:
table = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 0x1D, workData);
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 0x1D, workData);
break;
}
}
*resultIndex = 0;
if ((count < 1) || (firstCharacter >= 0xFF)) {
return 0;
}
index1 = *resultIndex;
for (; index1 < tableCount; index1++) {
if (table[index1 * 4] >= firstCharacter) {
break;
}
}
if ((index1 >= tableCount) || (firstCharacter != table[index1 * 4])) {
return 0;
}
if ((count < 2) || ((firstCharacter = input[1]) >= 0xFF)) {
*resultIndex = index1;
return 1;
}
index2 = index1;
for (; index2 < tableCount; index2++) {
if ((table + index2 * 4)[1] >= firstCharacter) {
break;
}
}
if ((index2 >= tableCount) || (firstCharacter != (table + index2 * 4)[1]) ||
(input[0] != table[index2 * 4])) {
*resultIndex = index1;
return 1;
}
if ((count < 3) || ((firstCharacter = input[2]) >= 0xFF)) {
*resultIndex = index2;
return 2;
}
index3 = index2;
for (; index3 < tableCount; index3++) {
if ((table + index3 * 4)[2] >= firstCharacter) {
break;
}
}
if ((index3 >= tableCount) || (firstCharacter != (table + index3 * 4)[2]) ||
(input[1] != (table + index3 * 4)[1]) || (input[0] != table[index3 * 4])) {
if ((Zi8_814813FC(input[1], &mappedCharacter, &nestedScratch, workData) != 0) &&
(Zi8_81481E6C(&nestedIndexStorage, input + 2, mappedCharacter, 1, workData) != 0)) {
*resultIndex = index1;
return 1;
}
*resultIndex = index2;
return 2;
}
if ((count < 4) || ((firstCharacter = input[3]) >= 0xFF)) {
*resultIndex = index3;
return 3;
}
index4 = index3;
for (; index4 < tableCount; index4++) {
if ((table + index4 * 4)[3] >= firstCharacter) {
break;
}
}
if ((index4 >= tableCount) || (firstCharacter != (table + index4 * 4)[3]) ||
(input[2] != (table + index4 * 4)[2]) || (input[1] != (table + index4 * 4)[1]) ||
(input[0] != table[index4 * 4])) {
if ((Zi8_814813FC(input[2], &mappedCharacter, &nestedScratch, workData) != 0) &&
(Zi8_81481E6C(&nestedIndexStorage, input + 3, mappedCharacter, 1, workData) != 0)) {
*resultIndex = index2;
return 2;
}
*resultIndex = index3;
return 3;
}
if ((count < 5) || ((firstCharacter = input[4]) >= 0xFF)) {
*resultIndex = index4;
return 4;
}
if ((Zi8_814813FC(input[3], &mappedCharacter, &nestedScratch, workData) != 0) &&
(Zi8_81481E6C(&nestedIndexStorage, input + 4, mappedCharacter, 1, workData) != 0)) {
*resultIndex = index3;
return 3;
}
*resultIndex = index4;
return 4;
}

View File

@@ -0,0 +1,33 @@
Reconstructed all six functions. NextDawgGroup matches 68/68 instructions;
Zi8SyllablesROMdata matches 66/66. Neither unit has a .data string pool;
pool_diff.py raises KeyError, and the gate confirms identical empty pools.
Zi8MatchROMdata0:
1. Three-key buffer, full-width incoming count: 30.915709%, 537/522 instructions.
2. Status branch inversion and common failure exit: 44.220306%, 531/522.
3. U16 path index and explicit header byte composition: 45.16092%, 533/522.
Retained attempt 3. Graph traversal, field access and register allocation differ.
The key buffer holds at most two converted keys and a terminator, not the
forty entries inferred by Ghidra from neighboring stack storage.
Zi8MatchROMdata1:
1. Byte-sized group index: 98.203125%, 130/128 instructions.
2. Assign returned table address directly to the workspace: 98.47656%, 127/128.
3. Scalar table address local with pointer conversion at assignment: 99.765625%,
128/128, 5 differences. Retained attempt 3; r26/r27 allocation differs.
Zi8MatchROMdata2:
1. Narrow count/language/capacity/mode/status parameters: 258/236 instructions.
2. Byte-sized result and output count: 265/236.
3. Full-width parameters and a counted prefix loop: 249/236.
Objdiff reports no fuzzy percentage for this function in all three builds.
Retained attempt 3. Instruction count, segment control flow and allocation differ.
Corrected the unsigned wide-character sentinel comparison to 0xeff1.
Zi8MatchROMdata:
1. Unsigned candidate result from the segment helper: 65.77665%, 225/197.
2. Full-width entry point result: 65.34518%, 225/197.
3. Full-width incoming count, remove its alias: 61.335026%, 234/197.
Retained the attempt 1 body. With the retained full-width segment-helper
signature it measures 58.106598%, 237/197 instructions. Group iteration and
fallback control flow differ.

View File

@@ -0,0 +1,46 @@
Reconstructed all 17 functions in target order. Empty string pools are identical.
Exact: fuzzy setters, Latin search order, global size, both candidate wrappers,
duplicate-buffer initialization, memset, memcpy and maximum word length.
Zi8GetDataSignature:
1. length > capacity instead of capacity < length: 99.05797%, 69/69 instructions.
2. Reuse table selector as U16 length: 99.347824%, 69/69, 9 differences.
3. Reorder locals and widen return: 98.478264%, 69/69, 10 differences.
Retained attempt 2. Only saved register assignment differs.
Zi8GetEngineSignature:
1. Separate OEM/build locals: 95.85268%, 219/224 instructions.
2. Explicit quotient/remainder arithmetic: 95.71875%, 219/224.
3. Reordered major/minor locals and reused identifier value: 95.58036%, 219/224.
Retained reconstruction, 95.95982%; minor version is held in a register instead
of a stack slot, with a different saved-register frame.
Zi8AlphaSignature:
1. Counted for loops instead of postdecrement while: 63.64706%, 191/204.
2. U32 candidate count: 63.887257%, 188/204.
3. Widen helper return types and restore U16 candidate count: 63.32353%, 189/204.
Retained reconstruction, 67.61275%, 188/204; stack locals and control flow differ.
Zi8ZhSignature:
1. U32 candidate count: 25.711538%, 209/208.
2. U32 engine length: 29.216347%, 202/208.
3. Widen helper returns and restore U16 lengths: 22.509615%, 212/208.
Retained attempt 2; integer promotion, loops and allocation differ.
Zi8GetCandidatesOrCount:
1. Unsigned signature result: 74.48703%, 760/694.
2. U8 result count: 74.85447%, 764/694.
3. Restore full-width count with widened signature helper returns: 75.452446%, 756/694.
Retained reconstruction, 75.64553%, 754/694; branch layout and allocation differ.
Zi8IsDupWChar:
1. U16 position increment: 99.20635%, 63/63, 9 differences.
2. Signed position with explicit U16 index: 96.666664%, 64/63.
3. U32 position and signed duplicate flag: 96.666664%, 64/63.
Retained attempt 1; character, duplicate and position register allocation differs.
Zi8IsDupWordW:
1. Unsigned duplicate flag: 85.76259%, 140/139.
2. Explicit loop break: 90.22302%, 140/139.
3. U8 cache position: 88.78417%, 142/139.
Retained attempt 2; loop layout and cache index allocation differ.

View File

@@ -0,0 +1,25 @@
Zi8PriMatchNextChar, Zi8ExactMatchNextChar, Zi8SecMatchChar,
Zi8PriMatchNextComp, Zi8SecMatchComp and Zi8GetPCode match on reconstruction.
The unit has no .data string pool; pool_diff.py raises KeyError, gate confirms identical empty pools.
Zi8MatchPhonetic: reconstructed dictionary index separately from phonetic code.
1. Byte-sized match/alternate state: 359/363 instructions, 77.62259%.
2. Inverted remaining-count initialization: 359/363, 77.242424%.
3. Direct alternate parameter and numParts == 1: 348/363, 72.46832%.
Retained 359/363, 77.66942%; stack layout, control flow and allocation differ.
Zi8GetPyPhonetic:
1. Four-byte pinyin buffer: 726/718, 75.158775%.
2. U16 spelling index: 726/718, 74.785515%.
3. Int spelling index: 701/718, 72.214485%.
Retained 726/718, 75.160164%; branch structure and allocation differ.
Zi8GetPyFinal:
1. Shared final-row pointer: 58/53, 62.28302%.
2. Reordered index/row declarations: 53/53, 99.245285%, 8 instruction differences.
3. U16 row index: 53/53, 98.86793%, 12 differences.
Retained 53/53, 99.245285%; r6/r7 allocation in result loads differs.
Zi8GetBpmfPhonetic:
1. Deferred result initialization: 309/309, 99.23948%.
2. Unsigned result counter and direct text subtraction: 309/309, 100%, diffs 0.

View File

@@ -0,0 +1,10 @@
Both table helpers match exactly on reconstruction: Zi8_814813FC 49/49
instructions, Zi8_81481E6C 629/629. Both have ctxdiff diffs 0.
The string pools are empty and identical.
Zi8GetKoreanCandidates:
1. For loop with an explicit break in character mapping: 68.13893%, 629/619 instructions.
2. Full-width result and character index: 67.34895%, 600/619.
3. Typed three-byte character/sequence records: 66.96769%, 629/619.
Retained attempt 1. The main routine still differs in stack state, loop structure
and register allocation. No register/volatile keywords were retained.