Compare commits
1 Commits
cleanup/co
...
agent/w092
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ea9b29edab |
@@ -987,7 +987,7 @@ config.libs = [
|
||||
Object(NonMatching, "clib/zi8alpha.c"),
|
||||
Object(Matching, "clib/zi8alts.c"),
|
||||
Object(NonMatching, "clib/zi8cgetc.c"),
|
||||
Object(NonMatching, "clib/zi8cinfo.c"),
|
||||
Object(Matching, "clib/zi8cinfo.c"),
|
||||
Object(Matching, "clib/zi8copy.c"),
|
||||
Object(NonMatching, "clib/zi8dawg.c"),
|
||||
Object(Matching, "clib/zi8getc.c"),
|
||||
|
||||
@@ -142,6 +142,9 @@ typedef struct ziFuzzyZYPairs {
|
||||
int rANDn : 1;
|
||||
int bANDp : 1;
|
||||
int gANDk : 1;
|
||||
int dANDt : 1;
|
||||
|
||||
int reserved : 20;
|
||||
} ziFuzzyZYPairs;
|
||||
|
||||
typedef struct _ziGetParam {
|
||||
|
||||
@@ -269,10 +269,10 @@ Zi8UInt Zi8SpellingZY(ziU16 *output,Zi8UInt key,ziU8 includeTone)
|
||||
|
||||
Zi8UInt Zi8SpellingPY(ziU16 *output,Zi8UInt key,ziU8 includeTone)
|
||||
{
|
||||
Zi8UInt length = 0;
|
||||
ziU16 initialIndex = (ziU16)(((key & 0xffff) >> 9) & 0x3f);
|
||||
ziU16 finalIndex = (ziU16)(((key & 0xffff) >> 3) & 0x3f);
|
||||
ziU16 tone = (ziU16)(key & 7);
|
||||
Zi8UInt length = 0;
|
||||
volatile ziU16 tone = (ziU16)(key & 7);
|
||||
|
||||
output[0] = zi8PYinitialSpelling[initialIndex][0];
|
||||
output[1] = zi8PYinitialSpelling[initialIndex][1];
|
||||
|
||||
@@ -643,7 +643,7 @@ ziU32 Zi8GetSInfo(ziU8* strokes, ziU8* extraStrokes, ziWChar* outputBuffer, ziU8
|
||||
{
|
||||
int strokeIndex;
|
||||
int outputCount;
|
||||
int extraCount;
|
||||
volatile int extraCount;
|
||||
|
||||
outputCount = 0;
|
||||
Zi8LogError(100, work);
|
||||
@@ -660,8 +660,7 @@ ziU32 Zi8GetSInfo(ziU8* strokes, ziU8* extraStrokes, ziWChar* outputBuffer, ziU8
|
||||
goto lowStroke;
|
||||
}
|
||||
badStroke:
|
||||
outputCount--;
|
||||
outputBuffer[(ziU8)outputCount] = 0;
|
||||
outputBuffer[(ziU8)--outputCount] = 0;
|
||||
return outputCount;
|
||||
lowStroke:
|
||||
outputBuffer[(ziU8)outputCount] = zi8StrokeCode(strokes[strokeIndex] & 0xf, work);
|
||||
|
||||
@@ -89,7 +89,12 @@ ziU32 Zi8MatchPUDdata_ZHS(ziWChar* pattern, ziU8 length, ziU8 language, ziWChar*
|
||||
ZI_WORK->unk_0x310 = (ziU32)table + section->offset[0] * 0x100 + section->offset[1];
|
||||
ZI_WORK->unk_0x318 = 0;
|
||||
}
|
||||
while ((entry = (ziU8*)ZI_WORK->unk_0x310) != 0) {
|
||||
for (;;) {
|
||||
entry = (ziU8*)ZI_WORK->unk_0x310;
|
||||
if (entry == 0) {
|
||||
Zi8LogError(0x4B3, __zi8_work_data);
|
||||
return 0;
|
||||
}
|
||||
while ((ziS32)ZI_WORK->unk_0x318 < (ziS32)ZI_WORK->unk_0x314) {
|
||||
word = entry + 1;
|
||||
wordSize = *entry;
|
||||
@@ -158,8 +163,6 @@ next:
|
||||
fallback = 1;
|
||||
ZI_WORK->unk_0x318 = 0;
|
||||
}
|
||||
Zi8LogError(0x4B3, __zi8_work_data);
|
||||
return 0;
|
||||
}
|
||||
ziU32 Zi8MatchPUDdata(ziWChar* pattern, ziU8 length, ziU8 language, ziWChar* output, ziU16 capacity, ziU8 complete, ziU8 continuation ZI_NEED_WORK) {
|
||||
ziU32 result;
|
||||
@@ -167,11 +170,12 @@ ziU32 Zi8MatchPUDdata(ziWChar* pattern, ziU8 length, ziU8 language, ziWChar* out
|
||||
for (;;) {
|
||||
result = Zi8_8147FD7C(pattern, length, language, output, capacity, complete, continuation, __zi8_work_data);
|
||||
if ((ziU8)result != 0) break;
|
||||
if ((ZI_WORK->pudCount = ZI_WORK->pudCount + 1) > 16) {
|
||||
if (++ZI_WORK->pudCount <= 16) {
|
||||
continuation = 0;
|
||||
} else {
|
||||
ZI_WORK->pudCount = 1;
|
||||
break;
|
||||
}
|
||||
continuation = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ ziBool Zi8_81480224(ziUserWord* word ZI_NEED_WORK) {
|
||||
if (candidate->length == length) {
|
||||
position = 0;
|
||||
while (position < length) {
|
||||
if ((ziU8)candidate->text[position] != (ziU8)word->text[position]) break;
|
||||
if (candidate->text[position] != word->text[position]) break;
|
||||
position++;
|
||||
}
|
||||
if (position == length) {
|
||||
@@ -56,8 +56,7 @@ ziBool Zi8_81480224(ziUserWord* word ZI_NEED_WORK) {
|
||||
previous = current;
|
||||
current = current->next;
|
||||
}
|
||||
length = ZI_WORK->uwdCount;
|
||||
ZI_WORK->uwdCount = length + 1;
|
||||
length = ZI_WORK->uwdCount++;
|
||||
added = &ZI_WORK->uwdNodes[length];
|
||||
if (previous == 0) {
|
||||
ZI_WORK->uwdList = added;
|
||||
@@ -91,8 +90,11 @@ ziU8 Zi8MatchUWDdata(ziWChar* pattern, ziU8 length, ziWChar* currentWord, ziU16
|
||||
ziWChar folded;
|
||||
int fallback = 0;
|
||||
int visited = 0;
|
||||
int position, prefixLength, previousOffset;
|
||||
ziU32 size, entryLanguage, entryLength;
|
||||
int prefixLength;
|
||||
int position, previousOffset;
|
||||
ziU32 size;
|
||||
ziU8 entryLanguage;
|
||||
ziU32 entryLength;
|
||||
ziU8* cursor;
|
||||
ziU8* begin;
|
||||
ziU8* boundary;
|
||||
@@ -103,18 +105,33 @@ ziU8 Zi8MatchUWDdata(ziWChar* pattern, ziU8 length, ziWChar* currentWord, ziU16
|
||||
ziUserDictionary* dictionary;
|
||||
int firstSegment;
|
||||
Zi8LogError(100, __zi8_work_data);
|
||||
if (!(ZI_WORK->unk_0x138 < 3 && ZI_WORK->unk_0x138 != 0 && ZI_WORK->unk_0x130[ZI_WORK->unk_0x138 - 1] != 0)) {
|
||||
if (!(ZI_WORK->unk_0x138 <= 2 && ZI_WORK->unk_0x138 != 0 && ZI_WORK->unk_0x130[ZI_WORK->unk_0x138 - 1] != 0)) {
|
||||
Zi8ReplaceLastError(0x19C, __zi8_work_data);
|
||||
return 0;
|
||||
}
|
||||
dictionary = ZI_WORK->unk_0x130[ZI_WORK->unk_0x138 - 1];
|
||||
if (continuation == 0) {
|
||||
if (continuation != 0) {
|
||||
result = Zi8_814803F4(__zi8_work_data);
|
||||
entryLength = 0;
|
||||
if (result != 0) {
|
||||
entryLanguage = result->language;
|
||||
entryLength = result->length;
|
||||
if (entryLength >= capacity) {
|
||||
Zi8_8148047C(__zi8_work_data);
|
||||
return 0;
|
||||
}
|
||||
for (position = 0; position < (ziS32)entryLength; position++) output[position] = Zi8ConvertUC2WC(result->text[position], entryLanguage, __zi8_work_data);
|
||||
}
|
||||
return entryLength;
|
||||
}
|
||||
{
|
||||
Zi8_8148047C(__zi8_work_data);
|
||||
ZI_WORK->unk_0x13C = 0;
|
||||
if (currentWord == 0 || currentLength == 0 || currentWord[currentLength - 1] != 0x20) ZI_WORK->unk_0x140 = 0;
|
||||
else {
|
||||
prefixLength = 0;
|
||||
for (position = currentLength - 2; position >= 0 && currentWord[position] != 0x20; position--) prefixLength++;
|
||||
for (position = currentLength - 2; currentWord[position] != 0x20 && position >= 0; position--) prefixLength++;
|
||||
position++;
|
||||
if (prefixLength == 0 || prefixLength > 63) ZI_WORK->unk_0x140 = 0;
|
||||
else {
|
||||
ZI_WORK->unk_0x140 = 1;
|
||||
@@ -123,7 +140,7 @@ ziU8 Zi8MatchUWDdata(ziWChar* pattern, ziU8 length, ziWChar* currentWord, ziU16
|
||||
ZI_WORK->unk_0x141[1] = language;
|
||||
ZI_WORK->unk_0x141[2] = prefixLength;
|
||||
previousOffset = 4;
|
||||
for (; ++position, prefixLength > 0; prefixLength--) {
|
||||
for (; prefixLength > 0; prefixLength--, position++) {
|
||||
folded = currentWord[position];
|
||||
ZI_WORK->unk_0x141[previousOffset] = Zi8ConvertWC2UC(folded, language, __zi8_work_data);
|
||||
ZI_WORK->unk_0x184[previousOffset] = 0;
|
||||
@@ -131,12 +148,10 @@ ziU8 Zi8MatchUWDdata(ziWChar* pattern, ziU8 length, ziWChar* currentWord, ziU16
|
||||
if (!Zi8ChangeCharCase(1, &folded, language, __zi8_work_data)) Zi8ChangeCharCase(0, &folded, language, __zi8_work_data);
|
||||
ZI_WORK->unk_0x184[previousOffset] = Zi8ConvertWC2UC(folded, language, __zi8_work_data);
|
||||
}
|
||||
if (ZI_WORK->unk_0x141[previousOffset] == 0) {
|
||||
if (ZI_WORK->unk_0x141[previousOffset++] == 0) {
|
||||
ZI_WORK->unk_0x140 = 0;
|
||||
previousOffset++;
|
||||
break;
|
||||
}
|
||||
previousOffset++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -146,7 +161,8 @@ rescan:
|
||||
boundary = (ziU8*)dictionary + dictionary->boundary + 7;
|
||||
end = (ziU8*)dictionary + dictionary->end + 7;
|
||||
cursor = begin;
|
||||
firstSegment = begin < boundary;
|
||||
if (begin < boundary) firstSegment = 1;
|
||||
else firstSegment = 0;
|
||||
while (firstSegment ? cursor < boundary : cursor < end) {
|
||||
size = *cursor;
|
||||
candidate = (ziUserWord*)cursor;
|
||||
@@ -185,7 +201,7 @@ next:
|
||||
visited = 0;
|
||||
goto rescan;
|
||||
}
|
||||
if (complete != 0 && length == 1) {
|
||||
if (complete == 1 && length != 0 && continuation == 0) {
|
||||
complete = 0;
|
||||
fallback = 1;
|
||||
visited = 0;
|
||||
|
||||
@@ -22,7 +22,8 @@ ziU32 ZiDAWGGetChild(ziU32 node) {
|
||||
node += offset;
|
||||
if (((ziU32)header & 2) != 0) {
|
||||
if ((*(ziU8*)node & 0x80) != 0) {
|
||||
offset = *((ziU8*)node + 2) + ((*(ziU8*)node & 0x7f) * 0x10000 + ((ziU32)*((ziU8*)node + 1) & 0xffff) * 0x100 + 0x8000);
|
||||
offset = (*(ziU8*)node & 0x7f) * 0x10000 + ((ziU32)*((ziU8*)node + 1) & 0xffff) * 0x100 + 0x8000;
|
||||
offset += *((ziU8*)node + 2);
|
||||
} else {
|
||||
offset = ((ziU32)*(ziU8*)node & 0xffff) * 0x100;
|
||||
offset += (ziU32)*((ziU8*)node + 1);
|
||||
@@ -43,7 +44,7 @@ ziU32 ZiDAWGGetChild(ziU32 node) {
|
||||
|
||||
ziU8* ZiDAWGGetSibling(ziU8* node) {
|
||||
ziU16 header;
|
||||
ziU8* cursor;
|
||||
ziU8* cursor = node;
|
||||
ziS32 depth;
|
||||
ziS32 offset;
|
||||
|
||||
@@ -53,29 +54,29 @@ ziU8* ZiDAWGGetSibling(ziU8* node) {
|
||||
if ((header & 4) == 0) {
|
||||
node = 0;
|
||||
} else {
|
||||
cursor = node;
|
||||
if ((header & 8) != 0) {
|
||||
if ((node[0] & 0xf) == 0xf) {
|
||||
cursor = node + 2;
|
||||
node += 2;
|
||||
} else {
|
||||
cursor = node + 1;
|
||||
node += 1;
|
||||
}
|
||||
|
||||
if ((header & 2) != 0) {
|
||||
if ((*cursor & 0x80) == 0) {
|
||||
cursor += 2;
|
||||
if ((*node & 0x80) == 0) {
|
||||
node += 2;
|
||||
} else {
|
||||
cursor += 3;
|
||||
node += 3;
|
||||
}
|
||||
}
|
||||
|
||||
if ((*cursor & 0x80) == 0) {
|
||||
node += (ziU32)cursor[1] + (ziU32)*cursor * 0x100;
|
||||
if ((*node & 0x80) != 0) {
|
||||
node += (*node & 0x7f) * 0x10000 + (ziU32)node[1] * 0x100 +
|
||||
(ziU32)node[2] + 0x8000;
|
||||
} else {
|
||||
node += (*cursor & 0x7f) * 0x10000 + (ziU32)cursor[1] * 0x100 +
|
||||
0x8000 + (ziU32)cursor[2];
|
||||
node += (ziU16)*node * 0x100 + (ziU32)node[1];
|
||||
}
|
||||
} else {
|
||||
cursor = node;
|
||||
do {
|
||||
header = nodeHeaderTable[cursor[0] >> 4];
|
||||
if ((cursor[0] & 0xf) == 0xf) {
|
||||
@@ -89,24 +90,24 @@ ziU8* ZiDAWGGetSibling(ziU8* node) {
|
||||
if ((header & 1) != 0) {
|
||||
if ((header & 2) == 0) {
|
||||
depth++;
|
||||
} else if ((*cursor & 0x80) == 0) {
|
||||
cursor += 2;
|
||||
offset += 2;
|
||||
} else {
|
||||
} else if ((*cursor & 0x80) != 0) {
|
||||
cursor += 3;
|
||||
offset += 3;
|
||||
} else {
|
||||
cursor += 2;
|
||||
offset += 2;
|
||||
}
|
||||
}
|
||||
|
||||
if ((header & 4) == 0) {
|
||||
depth--;
|
||||
} else if ((header & 8) != 0) {
|
||||
if ((*cursor & 0x80) == 0) {
|
||||
cursor += 2;
|
||||
offset += 2;
|
||||
} else {
|
||||
if ((*cursor & 0x80) != 0) {
|
||||
cursor += 3;
|
||||
offset += 3;
|
||||
} else {
|
||||
cursor += 2;
|
||||
offset += 2;
|
||||
}
|
||||
depth--;
|
||||
}
|
||||
@@ -163,16 +164,10 @@ ziU32 ZiDAWGGetGraphInfo(zi8DawgCtx* context, ziU8* entry, ziU16* keys) {
|
||||
result = 0;
|
||||
pair = (((ziU16)entry[0] << 8) + entry[1]);
|
||||
if (pair != 0) {
|
||||
goto graph_invalid;
|
||||
return 0;
|
||||
}
|
||||
pair = (((ziU16)entry[2] << 8) + entry[3]);
|
||||
if (pair == 0) {
|
||||
goto graph_valid;
|
||||
}
|
||||
graph_invalid:
|
||||
result = 0;
|
||||
goto graph_done;
|
||||
graph_valid:
|
||||
end = (ziU32)(entry + (((ziU16)entry[4] << 8) + entry[5] + 1) * 10);
|
||||
entry += 10;
|
||||
depth = 0;
|
||||
@@ -182,19 +177,18 @@ graph_valid:
|
||||
}
|
||||
|
||||
while (1) {
|
||||
if (*keys == (ziU16)(entry[3] + ((ziU16)entry[2] << 8))) {
|
||||
if (*keys == (ziS32)(entry[3] + ((ziU16)entry[2] << 8))) {
|
||||
break;
|
||||
}
|
||||
entry += (entry[1] + ((ziU16)entry[0] << 8)) * 10 + 10;
|
||||
if ((end <= (ziU32)entry) ||
|
||||
(*keys == (ziU16)(entry[3] + ((ziU16)entry[2] << 8)))) {
|
||||
if (((ziU32)entry >= end) ||
|
||||
(*keys == (ziS32)(entry[3] + ((ziU16)entry[2] << 8)))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (end <= (ziU32)entry) {
|
||||
result = 0;
|
||||
break;
|
||||
if ((ziU32)entry >= end) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
result = graph + (ziU32)entry[4] * 0x10000 + ((ziU16)entry[5] << 8) +
|
||||
@@ -215,8 +209,7 @@ graph_valid:
|
||||
depth++;
|
||||
keys++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
graph_done:
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ typedef struct ziUserKeys {
|
||||
typedef struct ziChineseEntry {
|
||||
ziU8 data[9];
|
||||
ziU8 offsetHigh;
|
||||
ziU16 offsetLow;
|
||||
ziU8 offsetLow[2];
|
||||
} ziChineseEntry;
|
||||
|
||||
ziU8 Zi8GetCandidatesOrCount(ziGetParam*, ziSearchState* ZI_NEED_WORK);
|
||||
@@ -26,19 +26,22 @@ ziPtr Zi8GetTableAddress(ziU8, ziU8 ZI_NEED_WORK);
|
||||
ziU16 Zi8Uni2Ord(ziWChar ZI_NEED_WORK);
|
||||
|
||||
ziBool Zi8IsWordW(ziWChar* word, ziU8 language ZI_NEED_WORK) {
|
||||
ziU8 remaining, group;
|
||||
ziU16 value = 0;
|
||||
int count;
|
||||
int offset;
|
||||
ziU8 group;
|
||||
ziU8 remaining;
|
||||
ziU16 value;
|
||||
ziWChar* cursor;
|
||||
ziU8 formats[8] = {1, 5, 0, 0, 0, 0, 0, 0};
|
||||
ziSearchState search;
|
||||
ziGetParam request;
|
||||
ziWChar ordinals[65];
|
||||
ziU32 savedFormats = ZI_WORK->unk_0x1410;
|
||||
ziU8 savedCount = ZI_WORK->unk_0x1418;
|
||||
int length, count, offset;
|
||||
int length;
|
||||
int unmatched;
|
||||
ziChineseEntry* entry;
|
||||
ziU8* data;
|
||||
ziU8 formats[8] = {1, 5, 0, 0, 0, 0, 0, 0};
|
||||
ziU32 savedFormats = ZI_WORK->unk_0x1410;
|
||||
ziU8 savedCount = ZI_WORK->unk_0x1418;
|
||||
search.flags = 0;
|
||||
search.word = 0;
|
||||
search.length = 0;
|
||||
@@ -52,7 +55,7 @@ ziBool Zi8IsWordW(ziWChar* word, ziU8 language ZI_NEED_WORK) {
|
||||
}
|
||||
if (language != 1) {
|
||||
for (length = 0; word[length] != 0; length++) {
|
||||
if (word[length] > 0xEFF0 || length == 64) return 0;
|
||||
if (word[length] >= 0xEFF1 || length == 64) return 0;
|
||||
}
|
||||
((ziU8*)&search.length)[0] = length;
|
||||
((ziU8*)&search.flags)[2] = 1;
|
||||
@@ -91,21 +94,34 @@ ziBool Zi8IsWordW(ziWChar* word, ziU8 language ZI_NEED_WORK) {
|
||||
if (language == 1) {
|
||||
length = 0;
|
||||
do {
|
||||
if (word[length] == 0) {
|
||||
count = length - 1;
|
||||
ordinals[length] = Zi8Uni2Ord(word[length], __zi8_work_data);
|
||||
if (ordinals[length] == 0xFFFF) return 0;
|
||||
length++;
|
||||
if (length == 64) return 0;
|
||||
} while (word[length] != 0);
|
||||
{
|
||||
if (length == 1) return 1;
|
||||
count = --length;
|
||||
ordinals[count] |= 0x8000;
|
||||
ZI_WORK->unk_0x16 = Zi8GetFormatVersion(1, __zi8_work_data) & 2;
|
||||
entry = (ziChineseEntry*)Zi8GetTableAddress(1, 0, __zi8_work_data) + ordinals[0];
|
||||
data = (ziU8*)Zi8GetTableAddress(1, 1, __zi8_work_data) + ((entry->offsetHigh & 15) << 16 | entry->offsetLow);
|
||||
data = (ziU8*)Zi8GetTableAddress(1, 1, __zi8_work_data) + ((entry->offsetHigh & 15) << 16 | ((entry->offsetLow[0] << 8) | entry->offsetLow[1]));
|
||||
if (ZI_WORK->unk_0x16 != 0) {
|
||||
group = *data & 7;
|
||||
if (group == 5) offset = 4;
|
||||
else if (group < 5) {
|
||||
if (group == 2) offset = 2;
|
||||
else if (group < 2) offset = 1;
|
||||
else offset = 3;
|
||||
} else offset = 1;
|
||||
switch (*data & 7) {
|
||||
case 2:
|
||||
offset = 2;
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
offset = 3;
|
||||
break;
|
||||
case 5:
|
||||
offset = 4;
|
||||
break;
|
||||
default:
|
||||
offset = 1;
|
||||
break;
|
||||
}
|
||||
data += offset;
|
||||
}
|
||||
if ((*data & 0x80) == 0) return 0;
|
||||
@@ -134,11 +150,7 @@ ziBool Zi8IsWordW(ziWChar* word, ziU8 language ZI_NEED_WORK) {
|
||||
}
|
||||
Zi8LogError(0x2BD, __zi8_work_data);
|
||||
return 0;
|
||||
}
|
||||
ordinals[length] = Zi8Uni2Ord(word[length], __zi8_work_data);
|
||||
if (ordinals[length] == 0xFFFF) return 0;
|
||||
length++;
|
||||
} while (length != 64);
|
||||
}
|
||||
} else Zi8ReplaceLastError(0x26C, __zi8_work_data);
|
||||
return 0;
|
||||
}
|
||||
@@ -156,10 +168,9 @@ ziWChar Zi8ConvertUC2UserKey(ziChar character, ziU8 language ZI_NEED_WORK) {
|
||||
}
|
||||
}
|
||||
found:
|
||||
if (key < 32) {
|
||||
if (key == 0) return 0xEFFA;
|
||||
if (key >= 1 && key <= 9) return key + 0xEFF0;
|
||||
if (key <= 31) return key + 0xEFF1;
|
||||
}
|
||||
if (key >= 32) return 0;
|
||||
if (key == 0) return 0xEFFA;
|
||||
if (key >= 1 && key <= 9) return key + 0xEFF0;
|
||||
if (key <= 31) return key + 0xEFF1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -44,13 +44,12 @@ static ziU8 ziNumKeysWithChars(ziU8 language, ziPtr __zi8_work_data) {
|
||||
}
|
||||
|
||||
ziBool Zi8getKeyLayout(ziU8 language, ziWChar key, ziWChar* chars, ziU8 mode, ziPtr __zi8_work_data) {
|
||||
ziU8 numKeys;
|
||||
ziU16 tableCount;
|
||||
ziU8 numKeys;
|
||||
ziU8* dataAddress;
|
||||
ziUserKeyMap* customTable;
|
||||
ziU32 totalCharacters;
|
||||
ziU16 charCount;
|
||||
ziU32 keyIndex;
|
||||
ziU16 keyIndex;
|
||||
ziWChar* keyChars;
|
||||
|
||||
dataAddress = 0;
|
||||
@@ -93,15 +92,15 @@ tables_ready:
|
||||
return 0;
|
||||
}
|
||||
|
||||
totalCharacters = 0;
|
||||
keyIndex = totalCharacters;
|
||||
tableCount = 0;
|
||||
keyIndex = tableCount;
|
||||
for (; (ziU16)keyIndex < key; keyIndex++) {
|
||||
totalCharacters += dataAddress[(ziU16)keyIndex];
|
||||
tableCount += dataAddress[(ziU16)keyIndex];
|
||||
}
|
||||
if ((charCount = (ziU8)dataAddress[key]) == 0) {
|
||||
return 0;
|
||||
}
|
||||
dataAddress = dataAddress + numKeys + ((totalCharacters & 0xffff) * 2);
|
||||
dataAddress = dataAddress + numKeys + (tableCount * 2);
|
||||
keyIndex = 0;
|
||||
for (; (ziU16)keyIndex < charCount; keyIndex++) {
|
||||
chars[(ziU16)keyIndex] = (ziU16)dataAddress[(ziU16)keyIndex * 2] |
|
||||
|
||||
@@ -23,48 +23,60 @@ ziU8 Zi8DetachOEMdata(ziU8 id ZI_NEED_WORK) {
|
||||
}
|
||||
ziU8 Zi8MatchOEMdata(ziWChar* pattern, ziU8 length, ziU8 language, ziWChar* word, ziU16 capacity, ziBool complete, ziBool continuation ZI_NEED_WORK) {
|
||||
ziWChar folded;
|
||||
ziU8 fallback = 0;
|
||||
ziU32 index;
|
||||
ziS32 index;
|
||||
ziU32 position;
|
||||
ziU32 fallback = 0;
|
||||
if (!continuation) ZI_WORK->oemIdx = 0;
|
||||
index = ZI_WORK->oemIdx;
|
||||
if ((ziS32)index >= ZI_WORK->oemLen || ZI_WORK->oemMatch == 0) goto noMatch;
|
||||
if ((ziS32)index >= ZI_WORK->oemLen) goto failed;
|
||||
if (ZI_WORK->oemMatch == 0) goto failed;
|
||||
capacity--;
|
||||
if (length >= capacity) goto noMatch;
|
||||
word[capacity] = 0;
|
||||
word[length] = complete ? 1 : 0;
|
||||
for (;;) {
|
||||
if ((ziS32)index >= ZI_WORK->oemLen || !ZI_WORK->oemMatch(index, word, capacity, ZI_WORK->oemData)) {
|
||||
if (length != 1 || !complete || continuation) goto noMatch;
|
||||
complete = 0;
|
||||
fallback = 1;
|
||||
index = 0;
|
||||
continue;
|
||||
}
|
||||
position = 0;
|
||||
if ((complete && word[length] == 0) || (!complete && word[length] != 0)) {
|
||||
for (; (ziS32)position < length; position++) {
|
||||
if (pattern[position] < 0xEFF1 || pattern[position] > 0xF37F) {
|
||||
if (word[position] != pattern[position]) {
|
||||
if (!ZI_WORK->unk_0x1F || language == 1) break;
|
||||
folded = pattern[position];
|
||||
if (!Zi8ChangeCharCase(1, &folded, language, __zi8_work_data) || folded != word[position]) break;
|
||||
}
|
||||
} else if (pattern[position] != Zi8ConvertWC2Key(word[position], language, __zi8_work_data)) break;
|
||||
}
|
||||
}
|
||||
if ((ziS32)position >= length) {
|
||||
if (fallback) {
|
||||
*word = *pattern;
|
||||
return 1;
|
||||
}
|
||||
ZI_WORK->oemIdx = index + 1;
|
||||
while (word[position] != 0) position++;
|
||||
return position;
|
||||
}
|
||||
word[length] = complete ? 1 : 0;
|
||||
index++;
|
||||
if ((ziS32)length >= (ziS32)capacity) {
|
||||
failed:
|
||||
return 0;
|
||||
}
|
||||
noMatch:
|
||||
word[capacity] = 0;
|
||||
if (complete) word[length] = 1; else word[length] = 0;
|
||||
goto matchRetry;
|
||||
posEntry:
|
||||
position = 0;
|
||||
if ((complete && word[length] == 0) || (!complete && word[length] != 0)) {
|
||||
for (; (ziS32)position < length; position++) {
|
||||
if (pattern[position] >= 0xEFF1 && pattern[position] <= 0xF37F) {
|
||||
if (pattern[position] == Zi8ConvertWC2Key(word[position], language, __zi8_work_data)) continue;
|
||||
break;
|
||||
} else if (word[position] != pattern[position]) {
|
||||
if (!ZI_WORK->unk_0x1F || language == 1) break;
|
||||
folded = pattern[position];
|
||||
if (!Zi8ChangeCharCase(1, &folded, language, __zi8_work_data) || folded != word[position]) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((ziS32)position < length) {
|
||||
if (complete) word[length] = 1; else word[length] = 0;
|
||||
index++;
|
||||
if ((ziS32)index >= ZI_WORK->oemLen) goto oemFailed;
|
||||
goto matchRetry;
|
||||
}
|
||||
if (fallback) {
|
||||
index = 0;
|
||||
*word = *pattern;
|
||||
return 1;
|
||||
}
|
||||
index++;
|
||||
ZI_WORK->oemIdx = index;
|
||||
while (word[position] != 0) position++;
|
||||
return position;
|
||||
matchRetry:
|
||||
if ((ziS32)index >= ZI_WORK->oemLen) goto oemFailed;
|
||||
if (!ZI_WORK->oemMatch(index, word, capacity, ZI_WORK->oemData)) goto oemFailed;
|
||||
goto posEntry;
|
||||
oemFailed:
|
||||
if (length != 1 || !complete || continuation) goto tail0;
|
||||
complete = 0;
|
||||
fallback = 1;
|
||||
index = 0;
|
||||
goto matchRetry;
|
||||
tail0:
|
||||
return 0;
|
||||
}
|
||||
|
||||
52
tools/decomp-assist/clib.attempts.md
Normal file
52
tools/decomp-assist/clib.attempts.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# clib leaf — round-2 findings (agent/w0929/clib)
|
||||
|
||||
## Solved this round
|
||||
|
||||
- **zi8cinfo → Matching (whole-unit 100%)**. `Zi8GetSInfo` needed two levers
|
||||
together: `volatile int extraCount;` (forces the stack stw/lwz orig has)
|
||||
and the fused decrement `outputBuffer[(ziU8)--outputCount] = 0;` (lets MWCC
|
||||
schedule `li r3,0` before the `subi` — orig's order). 133/133 insn-identical.
|
||||
- **zi8getc2 all data sections 100%** (`ziFuzzyZYPairs` struct sizing): orig's
|
||||
`Zi8ZYdefaultFuzzyPairs` object is 8B, not 4B — the struct has 12 real bit
|
||||
fields (added `dANDt`) plus `reserved : 20`. By-value param codegen
|
||||
unchanged (verified instruction-identical); no regression on the ~20 other
|
||||
units including zitypes.h.
|
||||
- **zidawg1 GetGraphInfo 80.8 → ~95+**: three real levers —
|
||||
(a) u16 pair compares must be `int`/`ziS32`-typed on the RHS cast (orig uses
|
||||
`cmpw`, not `cmplw` + `clrlwi`);
|
||||
(b) `entry >= end` operand order (orig `cmplw entry,end;bge`);
|
||||
(c) early exits are `return 0` (orig emits `li r3,0` direct-return blocks),
|
||||
not `result=0; goto done`.
|
||||
Residual: `||` block layout + regalloc, ~4 insns.
|
||||
- **zidawg1 GetChild 93.3 → ~97+**: orig folds `+0x8000` as `addis +1` /
|
||||
`addi -0x8000` applied to `(hi<<16 + mid<<8)` BEFORE adding `b2` — the
|
||||
two-statement form `offset = ... + 0x8000; offset += b2;` reproduces it.
|
||||
Residual: pure regname/scheduling.
|
||||
|
||||
## Extraction artifacts (no source lever)
|
||||
|
||||
- **zikorean .data 17.2%**: orig's extracted zikorean.o contains a THIRD
|
||||
jumptable at .data+0xf8 (10 entries) whose relocs target `Zi8_81483118` —
|
||||
a zkokeyp function. orig's zkokeyp.o has NO .data at all. The table bytes
|
||||
were attributed to zikorean's slice by the extractor; cannot be emitted
|
||||
from zikorean.c (its 3 fns are already 100%).
|
||||
- **extab/extabindex ~92-97% residuals** on several units — symbol-extent
|
||||
artifacts (byte-identical content where comparable).
|
||||
|
||||
## Systematic tie-break family (documented, unfixed)
|
||||
|
||||
- **Callee-reg home shift**: orig homes the loop counter/local in the FIRST
|
||||
callee reg (r26) and args after (r27+); MWCC homes args first. Recurs in
|
||||
zi8dawg MatchROMdata1, zmtkey, zi8getc2 (2 fns), zoemdata Zi8MatchOEMdata
|
||||
(4-way swap, 192/192 insn-identical otherwise), zi8match, zkokeyp fns.
|
||||
- zi8alpha Zi8AlphaGetCandidates (3946 insns): mostly uniform +4 stack-slot
|
||||
shift (orig has one more 4-byte local slot) + a few bound-form diffs
|
||||
(`>0xF010` vs `>=0xF011`, `<=1` vs `<2`) + one missing subf-rewind block.
|
||||
- ziswordw Zi8IsWordW 83.3: orig homes call result in callee reg + keeps a
|
||||
selector var in r27; mine spills via ziU8 narrowing — needs deeper decode.
|
||||
|
||||
## Old-tip adoption notes
|
||||
|
||||
Old leaf tip f2afe0e8 beat upstream on: zoemdata +34.2, ziswordw +10.5,
|
||||
zi8uwd +7.3, zidawg1 +1.7, zi8pud2 +0.7, zi81key/zmtkey marginal.
|
||||
Upstream won on: zi8alpha +4.5, zi8cgetc +16, zconvert +0.4, zkokeyp +0.1.
|
||||
Reference in New Issue
Block a user