Compare commits
1 Commits
main
...
agent/w092
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f3a4c44d3 |
@@ -53,9 +53,9 @@ Progress
|
||||
<!-- progress:start -->
|
||||
| Decompiled | Matched | Linked | Data |
|
||||
|:---:|:---:|:---:|:---:|
|
||||
| 95.10% | 82.46% | 58.19% | 89.46% |
|
||||
| 95.27% | 82.59% | 58.19% | 89.46% |
|
||||
|
||||
units 777/1027 complete, functions 11956/12563 matched.
|
||||
units 777/1027 complete, functions 11961/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 -->
|
||||
|
||||
@@ -1051,75 +1051,75 @@ returnSpelling:
|
||||
|
||||
int Zi8Get1KeyPressCandidates(Zi8OneKeyParam *params,Zi8OneKeyOptions *options,Zi8OneKeyWork *work)
|
||||
{
|
||||
ziU8 entryFlags;
|
||||
ziU8 emitWords;
|
||||
ziU8 trackDuplicates;
|
||||
ziU8 matchFull;
|
||||
ziU8 includeTone;
|
||||
ziU8 requireFull;
|
||||
ziU8 prefixSearch;
|
||||
ziU8 mode;
|
||||
ziU8 result;
|
||||
Zi8UInt wordIndex;
|
||||
int index;
|
||||
ziU16 contextCharacter;
|
||||
ziU16 character;
|
||||
ziU8 optionsMask;
|
||||
ziU8 *recordCursor;
|
||||
Zi8UInt phoneticIndex;
|
||||
ziU8 contextRemaining;
|
||||
ziU8 contextIndex;
|
||||
ziU8 entryRemaining;
|
||||
ziU8 nibble;
|
||||
ziU8 wordLength;
|
||||
ziU8 phoneticLength;
|
||||
ziU8 candidateCount;
|
||||
ziU8 keyIndex;
|
||||
ziU8 elementIndex;
|
||||
ziU8 tone;
|
||||
ziU8 inputLimit;
|
||||
ziU8 inputLength;
|
||||
ziU8 characterSet;
|
||||
ziU8 languageMask;
|
||||
ziU16 unicodeCharacter;
|
||||
ziU16 userCharacter;
|
||||
ziU16 userOrdinal;
|
||||
ziU16 userCount;
|
||||
ziU16 phraseOrdinal;
|
||||
ziU16 ordinalIndex;
|
||||
ziU16 phoneticCount;
|
||||
ziU16 phraseCharacter;
|
||||
ziU16 firstOrdinal;
|
||||
ziU16 phoneticCode;
|
||||
ziU16 characterMask;
|
||||
ziU16 candidateCharacter;
|
||||
ziU16 candidateOrdinal;
|
||||
ziU16 tableIndex;
|
||||
ziU16 previousCharacter;
|
||||
ziU16 tableCursor;
|
||||
ziU16 ordinal;
|
||||
ziU16 remaining;
|
||||
ziU16 phoneticMask;
|
||||
ziU16 ordinalCount;
|
||||
ziU16 alternateCount;
|
||||
int duplicateIndex;
|
||||
ziU8 *userEntries;
|
||||
ziU8 *entryCursor;
|
||||
ziU16 *currentWord;
|
||||
ziU8 *phraseEntries;
|
||||
int outputLimit;
|
||||
int outputIndex;
|
||||
ziU16 *output;
|
||||
int totalCandidates;
|
||||
ziU8 keyMasks [8];
|
||||
ziU8 *phraseTable;
|
||||
ziU8 *phoneticTable;
|
||||
ziU8 *characterSetTable;
|
||||
ziU8 *ordinalTable;
|
||||
ziU8 *alternateTable;
|
||||
ziU8 *syllableTable;
|
||||
ziU16 spelling [8];
|
||||
ziU16 wordBuffer [64];
|
||||
ziU16 spelling [8];
|
||||
ziU8 *syllableTable;
|
||||
ziU8 *alternateTable;
|
||||
ziU8 *ordinalTable;
|
||||
ziU8 *characterSetTable;
|
||||
ziU8 *phoneticTable;
|
||||
ziU8 *phraseTable;
|
||||
ziU8 keyMasks [8];
|
||||
int totalCandidates;
|
||||
ziU16 *output;
|
||||
int outputIndex;
|
||||
int outputLimit;
|
||||
ziU8 *phraseEntries;
|
||||
ziU16 *currentWord;
|
||||
ziU8 *entryCursor;
|
||||
ziU8 *userEntries;
|
||||
int duplicateIndex;
|
||||
ziU16 alternateCount;
|
||||
ziU16 ordinalCount;
|
||||
ziU16 phoneticMask;
|
||||
ziU16 remaining;
|
||||
ziU16 ordinal;
|
||||
ziU16 tableCursor;
|
||||
ziU16 previousCharacter;
|
||||
ziU16 tableIndex;
|
||||
ziU16 candidateOrdinal;
|
||||
ziU16 candidateCharacter;
|
||||
ziU16 characterMask;
|
||||
ziU16 phoneticCode;
|
||||
ziU16 firstOrdinal;
|
||||
ziU16 phraseCharacter;
|
||||
ziU16 phoneticCount;
|
||||
ziU16 ordinalIndex;
|
||||
ziU16 phraseOrdinal;
|
||||
ziU16 userCount;
|
||||
ziU16 userOrdinal;
|
||||
ziU16 userCharacter;
|
||||
ziU16 unicodeCharacter;
|
||||
ziU8 languageMask;
|
||||
ziU8 characterSet;
|
||||
ziU8 inputLength;
|
||||
ziU8 inputLimit;
|
||||
ziU8 tone;
|
||||
ziU8 elementIndex;
|
||||
ziU8 keyIndex;
|
||||
ziU8 candidateCount;
|
||||
ziU8 phoneticLength;
|
||||
ziU8 wordLength;
|
||||
ziU8 nibble;
|
||||
ziU8 entryRemaining;
|
||||
ziU8 contextIndex;
|
||||
ziU8 contextRemaining;
|
||||
Zi8UInt phoneticIndex;
|
||||
ziU8 *recordCursor;
|
||||
ziU8 optionsMask;
|
||||
ziU16 character;
|
||||
ziU16 contextCharacter;
|
||||
int index;
|
||||
Zi8UInt wordIndex;
|
||||
ziU8 result;
|
||||
ziU8 mode;
|
||||
ziU8 prefixSearch;
|
||||
ziU8 requireFull;
|
||||
ziU8 includeTone;
|
||||
ziU8 matchFull;
|
||||
ziU8 trackDuplicates;
|
||||
ziU8 emitWords;
|
||||
ziU8 entryFlags;
|
||||
|
||||
ordinalTable = 0;
|
||||
characterSetTable = 0;
|
||||
|
||||
530
libs/RVLMiddleware/eZiText/src/clib/zi8cgetc.c
Normal file
530
libs/RVLMiddleware/eZiText/src/clib/zi8cgetc.c
Normal file
@@ -0,0 +1,530 @@
|
||||
#include <zi8clib/zi8cgetc.h>
|
||||
#include <zi8clib/zi8space.h>
|
||||
#include <zi8clib/zierror.h>
|
||||
|
||||
typedef unsigned int Zi8UInt;
|
||||
|
||||
extern Zi8UInt Zi8Ord2Ord(ziU16 ordinal, ziPtr work);
|
||||
extern ziU32 Zi8WCharCount(ziWChar* word, ziPtr work);
|
||||
|
||||
static Zi8UInt Zi8SetFindCand(ziU8* foundCandidates, Zi8UInt ordinal, ziPtr work) {
|
||||
Zi8UInt found;
|
||||
ordinal = Zi8Ord2Ord(ordinal, work);
|
||||
found = (ziU8)((1 << ((int)(ordinal & 0xffff) % 8)) &
|
||||
foundCandidates[(int)(ordinal & 0xffff) / 8]);
|
||||
foundCandidates[(int)(ordinal & 0xffff) / 8] |=
|
||||
1 << ((int)(ordinal & 0xffff) % 8);
|
||||
return found;
|
||||
}
|
||||
|
||||
ziWChar* ZiGetNextPhonetic(ziWChar* spelling, ziWChar* end ZI_NEED_WORK) {
|
||||
while (*spelling && *spelling != ZI_WORK->unk_0x1A && *spelling != 0xF360 && spelling < end) {
|
||||
++spelling;
|
||||
}
|
||||
if (!*spelling || spelling == end) {
|
||||
return ZI8_NULL;
|
||||
}
|
||||
++spelling;
|
||||
if (!*spelling || spelling == end) {
|
||||
return ZI8_NULL;
|
||||
}
|
||||
return spelling;
|
||||
}
|
||||
|
||||
int ZiPartialMatch(ziWChar* spelling, ziWChar* spellingEnd,
|
||||
ziWChar* candidate, ziWChar* candidateEnd,
|
||||
ziU16 phoneticIndex ZI_NEED_WORK) {
|
||||
if (spelling == spellingEnd || candidate == candidateEnd || !*spelling || !*candidate) {
|
||||
return 1;
|
||||
}
|
||||
while (*spelling != ZI_WORK->unk_0x1A && *spelling != 0xF360) {
|
||||
if (*candidate == ZI_WORK->unk_0x1A || *candidate == 0xF360) {
|
||||
break;
|
||||
}
|
||||
if (*spelling != *candidate) {
|
||||
return 0;
|
||||
}
|
||||
++spelling;
|
||||
++candidate;
|
||||
if (spelling == spellingEnd || candidate == candidateEnd || !*spelling || !*candidate) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ZiMatchZHSpelling(ziPtr dictionary, ziWChar* candidate, ziWChar* spelling,
|
||||
ziU8 spellingLength, ziU16 phoneticIndex ZI_NEED_WORK) {
|
||||
ziWChar* candidateCursor;
|
||||
ziWChar* spellingCursor;
|
||||
int index;
|
||||
int matches;
|
||||
int candidateLength;
|
||||
ziWChar spacedSpelling[64];
|
||||
ziWChar spacedCandidate[64];
|
||||
matches = 1;
|
||||
candidateLength = Zi8WCharCount(candidate, __zi8_work_data);
|
||||
if (!candidate || !spellingLength) {
|
||||
return matches;
|
||||
}
|
||||
for (index = 0; index < spellingLength; ++index) {
|
||||
if (!candidate[index] || candidate[index] != spelling[index]) {
|
||||
matches = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!matches) {
|
||||
spacedSpelling[0] = 0;
|
||||
spacedCandidate[0] = 0;
|
||||
if (!Zi8ZHaddSpace(spelling, spellingLength, spacedSpelling, 64, __zi8_work_data)) {
|
||||
return 0;
|
||||
}
|
||||
if (!Zi8ZHaddSpace(candidate, candidateLength, spacedCandidate, 64, __zi8_work_data)) {
|
||||
return 0;
|
||||
}
|
||||
spellingCursor = spacedSpelling;
|
||||
candidateCursor = spacedCandidate;
|
||||
while (phoneticIndex) {
|
||||
candidateCursor = ZiGetNextPhonetic(candidateCursor, spacedCandidate + 64, __zi8_work_data);
|
||||
if (!candidateCursor) {
|
||||
return 0;
|
||||
}
|
||||
--phoneticIndex;
|
||||
}
|
||||
matches = 1;
|
||||
while (spellingCursor && candidateCursor) {
|
||||
if (!ZiPartialMatch(spellingCursor, spacedSpelling + 64,
|
||||
candidateCursor, spacedCandidate + 64,
|
||||
phoneticIndex, __zi8_work_data)) {
|
||||
return 0;
|
||||
}
|
||||
spellingCursor = ZiGetNextPhonetic(spellingCursor, spacedSpelling + 64, __zi8_work_data);
|
||||
candidateCursor = ZiGetNextPhonetic(candidateCursor, spacedCandidate + 64, __zi8_work_data);
|
||||
}
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
typedef struct {
|
||||
ziU8 countOnly;
|
||||
ziU8 maxWordLength;
|
||||
ziU8 lookupMode;
|
||||
ziU8 dictionaryMode;
|
||||
ziWChar* dictionary;
|
||||
ziU32 dictionaryFlags;
|
||||
int maxResults;
|
||||
ziU16 capacity;
|
||||
} ZiChineseOptions;
|
||||
|
||||
typedef struct {
|
||||
ziU8 settings[0x1A];
|
||||
ziWChar separator;
|
||||
ziU8 state[4];
|
||||
ziWChar duplicateCharacters[64];
|
||||
ziWChar duplicateOrdinals[64];
|
||||
ziU8 duplicateIndex;
|
||||
} ZiChineseWork;
|
||||
|
||||
typedef struct {
|
||||
ziU8 flags;
|
||||
ziU8 phonetics[11];
|
||||
} ZiChineseRecord;
|
||||
|
||||
extern ziPtr Zi8GetTableAddress(ziU8 language, ziU8 table, ziPtr work);
|
||||
extern ziU16 Zi8GetTableCount(ziU8 language, ziU8 table, ziPtr work);
|
||||
extern ziU8 Zi8IsDupWChar(ziWChar character, ziPtr work);
|
||||
extern ziU8 Zi8IsDupWordW(ziWChar* word, ziU8 length, ziPtr work);
|
||||
extern ziWChar Zi8Ord2Uni(ziU16 ordinal, ziPtr work);
|
||||
extern ziU8 Zi8MatchPhonetic(ziU8* phonetics, ZiChineseRecord* records,
|
||||
ziPtr indexTable, ziU16 indexCount, ziPtr dictionary,
|
||||
ZiChineseRecord* record, ziU16* mask, ziU16* match,
|
||||
ziU16* length, ZiChineseRecord** matchedRecord,
|
||||
int* matchedIndex, ziU8 wordMode, ziU8 partial,
|
||||
ziU8 oneCharacter, ziU16 excludedMask,
|
||||
ziU16 excludedMatch, ziU8 charset, ziU8 options,
|
||||
ziU16 ordinal, ziU16* tone, ziU8 spellingOnly,
|
||||
ziPtr work);
|
||||
|
||||
static int Zi8NewMatchPhonetic(ziGetParam* request, ZiChineseRecord* records,
|
||||
ziPtr indexTable, ziU16 indexCount, ziPtr dictionary,
|
||||
ZiChineseOptions* options, ziU16 mask, ziU16 match, ziU16 excludedMask,
|
||||
ziU16 excludedMatch, ziU8 charset, ziU16 recordCount,
|
||||
ziU16* skipCount, int* resultCount, ziU8* candidateCount,
|
||||
int* outputCount, ziU8 wordMode, ziU8 useFoundCandidates,
|
||||
ziU8 pinyin, ziU8* charsetTable, ziU8* charsetEntry,
|
||||
ziU8 charsetFilter, ziWChar* output, ziPtr work) {
|
||||
ziU16* phoneticOffsets;
|
||||
ziU16* ordinalTable;
|
||||
ziU8* phonetics;
|
||||
int totalResults;
|
||||
int emittedCharacters;
|
||||
ZiChineseRecord* matchedRecord;
|
||||
ziU8* phoneticGroups;
|
||||
ziU8* candidateGroups;
|
||||
int matchedIndex;
|
||||
int capacity;
|
||||
ziU8* groupCandidates;
|
||||
ziU16 phoneticCount;
|
||||
ziU16 phoneticIndex;
|
||||
ziU16 candidateIndex;
|
||||
ziU16 character;
|
||||
ziU16 rangeBegin;
|
||||
ziU16 rangeEnd;
|
||||
ziU16 previousCharacter;
|
||||
ziU16 remainingSkip;
|
||||
ziU16 filteredMask;
|
||||
ziU16 filteredMatch;
|
||||
ziU16 matchedLength;
|
||||
ziU16 groupCount;
|
||||
ziU16 matchedTone;
|
||||
ziU16 groupOffset;
|
||||
ziU16 groupSize;
|
||||
ziU8 emittedCount;
|
||||
ziU8 stopAfterTone;
|
||||
|
||||
previousCharacter = 0;
|
||||
remainingSkip = *skipCount;
|
||||
totalResults = *resultCount;
|
||||
emittedCount = *candidateCount;
|
||||
emittedCharacters = *outputCount;
|
||||
stopAfterTone = 0;
|
||||
phoneticGroups = ZI8_NULL;
|
||||
candidateGroups = ZI8_NULL;
|
||||
capacity = options->capacity - 64;
|
||||
Zi8LogError(100, work);
|
||||
if ((mask & 7) == 7) {
|
||||
stopAfterTone = match & 7;
|
||||
}
|
||||
phoneticOffsets = Zi8GetTableAddress(1, 13, work);
|
||||
ordinalTable = Zi8GetTableAddress(1, 14, work);
|
||||
if (pinyin) {
|
||||
phonetics = Zi8GetTableAddress(1, 3, work);
|
||||
phoneticCount = Zi8GetTableCount(1, 3, work);
|
||||
phoneticGroups = Zi8GetTableAddress(1, 17, work);
|
||||
groupCount = Zi8GetTableCount(1, 17, work);
|
||||
candidateGroups = Zi8GetTableAddress(1, 18, work);
|
||||
} else {
|
||||
phonetics = Zi8GetTableAddress(1, 4, work);
|
||||
phoneticCount = Zi8GetTableCount(1, 4, work);
|
||||
phoneticGroups = Zi8GetTableAddress(1, 19, work);
|
||||
groupCount = Zi8GetTableCount(1, 19, work);
|
||||
candidateGroups = Zi8GetTableAddress(1, 20, work);
|
||||
}
|
||||
|
||||
if (groupCount) {
|
||||
groupOffset = 0;
|
||||
filteredMask = mask | 7;
|
||||
filteredMatch = match;
|
||||
for (phoneticIndex = 0; phoneticIndex < groupCount; ++phoneticIndex) {
|
||||
character = phoneticGroups[0] | (ziU16)phoneticGroups[1] << 8;
|
||||
groupSize = phoneticGroups[2] | (ziU16)phoneticGroups[3] << 8;
|
||||
if (excludedMatch == (character & excludedMask) ||
|
||||
filteredMatch != (character & filteredMask)) {
|
||||
groupOffset += groupSize;
|
||||
phoneticGroups += 4;
|
||||
continue;
|
||||
}
|
||||
groupCandidates = candidateGroups + groupOffset * 2;
|
||||
candidateIndex = 0;
|
||||
while (candidateIndex < groupSize) {
|
||||
character = groupCandidates[0] | (ziU16)groupCandidates[1] << 8;
|
||||
if (!(charset & records[character].flags)) {
|
||||
goto next_group_candidate;
|
||||
}
|
||||
if (charsetTable) {
|
||||
charsetEntry = charsetTable + character;
|
||||
if (!(*charsetEntry & charsetFilter)) {
|
||||
goto next_group_candidate;
|
||||
}
|
||||
}
|
||||
if (!wordMode) {
|
||||
if (useFoundCandidates) {
|
||||
if ((ziU8)Zi8SetFindCand(request->scratch, character, work)) {
|
||||
goto next_group_candidate;
|
||||
}
|
||||
} else if (Zi8IsDupWChar(character, work)) {
|
||||
goto next_group_candidate;
|
||||
}
|
||||
}
|
||||
((ZiChineseWork*)work)->duplicateOrdinals[((ZiChineseWork*)work)->duplicateIndex] = character;
|
||||
character = Zi8Ord2Uni(character, work);
|
||||
((ZiChineseWork*)work)->duplicateCharacters[((ZiChineseWork*)work)->duplicateIndex] = character;
|
||||
if (character == previousCharacter) {
|
||||
goto next_group_candidate;
|
||||
}
|
||||
previousCharacter = character;
|
||||
if (wordMode && Zi8IsDupWordW(&character, 1, work)) {
|
||||
goto next_group_candidate;
|
||||
}
|
||||
if (remainingSkip) {
|
||||
--remainingSkip;
|
||||
goto next_group_candidate;
|
||||
}
|
||||
++totalResults;
|
||||
if (!options->countOnly) {
|
||||
if (++((ZiChineseWork*)work)->duplicateIndex >= 64) {
|
||||
((ZiChineseWork*)work)->duplicateIndex = 0;
|
||||
}
|
||||
if (wordMode) {
|
||||
++emittedCount;
|
||||
output[emittedCharacters++] = character;
|
||||
output[emittedCharacters++] = 0x20;
|
||||
if (emittedCharacters > capacity) {
|
||||
*skipCount = remainingSkip;
|
||||
*resultCount = totalResults;
|
||||
*candidateCount = emittedCount;
|
||||
*outputCount = emittedCharacters;
|
||||
Zi8ReplaceLastError(0xB54, work);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
output[emittedCount++] = character;
|
||||
}
|
||||
if (emittedCount >= request->maxCandidates) {
|
||||
*skipCount = remainingSkip;
|
||||
*resultCount = totalResults;
|
||||
*candidateCount = emittedCount;
|
||||
*outputCount = emittedCharacters;
|
||||
Zi8ReplaceLastError(0xB55, work);
|
||||
return 0;
|
||||
}
|
||||
} else if (totalResults >= options->maxResults) {
|
||||
*skipCount = remainingSkip;
|
||||
*resultCount = totalResults;
|
||||
*candidateCount = emittedCount;
|
||||
*outputCount = emittedCharacters;
|
||||
Zi8ReplaceLastError(0xB56, work);
|
||||
return 0;
|
||||
}
|
||||
next_group_candidate:
|
||||
++candidateIndex;
|
||||
groupCandidates += 2;
|
||||
}
|
||||
if (stopAfterTone) {
|
||||
break;
|
||||
}
|
||||
groupOffset += groupSize;
|
||||
phoneticGroups += 4;
|
||||
}
|
||||
}
|
||||
filteredMask = mask & 0xFFF8;
|
||||
filteredMatch = match & 0xFFF8;
|
||||
for (phoneticIndex = 1; phoneticIndex < phoneticCount; ++phoneticIndex) {
|
||||
character = phonetics[phoneticIndex * 2] | (ziU16)phonetics[phoneticIndex * 2 + 1] << 8;
|
||||
if (filteredMatch != (character & filteredMask) ||
|
||||
excludedMatch == (character & excludedMask)) {
|
||||
continue;
|
||||
}
|
||||
rangeBegin = phoneticOffsets[phoneticIndex];
|
||||
rangeEnd = phoneticOffsets[phoneticIndex + 1];
|
||||
rangeBegin = ((ziU8)rangeBegin << 8) | ((rangeBegin >> 8) & 0xFF);
|
||||
rangeEnd = ((ziU8)rangeEnd << 8) | ((rangeEnd >> 8) & 0xFF);
|
||||
for (candidateIndex = rangeBegin; candidateIndex < rangeEnd; ++candidateIndex) {
|
||||
character = ordinalTable[candidateIndex];
|
||||
character = ((ziU8)character << 8) | ((character >> 8) & 0xFF);
|
||||
if (character >= recordCount || !(charset & records[character].flags)) {
|
||||
continue;
|
||||
}
|
||||
if (charsetTable) {
|
||||
charsetEntry = charsetTable + character;
|
||||
if (!(*charsetEntry & charsetFilter)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (stopAfterTone) {
|
||||
matchedRecord = records + character;
|
||||
matchedLength = 0;
|
||||
matchedIndex = 0;
|
||||
if (!Zi8MatchPhonetic(phonetics, records, indexTable, indexCount,
|
||||
dictionary, matchedRecord, &mask, &match,
|
||||
&matchedLength, &matchedRecord, &matchedIndex,
|
||||
wordMode, 1, 1, excludedMask, excludedMatch,
|
||||
charset, request->getOptions & 0x40, character,
|
||||
&matchedTone, 0, work)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!wordMode) {
|
||||
if (useFoundCandidates) {
|
||||
if ((ziU8)Zi8SetFindCand(request->scratch, character, work)) {
|
||||
continue;
|
||||
}
|
||||
} else if (Zi8IsDupWChar(character, work)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
((ZiChineseWork*)work)->duplicateOrdinals[((ZiChineseWork*)work)->duplicateIndex] = character;
|
||||
character = Zi8Ord2Uni(character, work);
|
||||
((ZiChineseWork*)work)->duplicateCharacters[((ZiChineseWork*)work)->duplicateIndex] = character;
|
||||
if (character == previousCharacter) {
|
||||
continue;
|
||||
}
|
||||
previousCharacter = character;
|
||||
if (wordMode && Zi8IsDupWordW(&character, 1, work)) {
|
||||
continue;
|
||||
}
|
||||
if (remainingSkip) {
|
||||
--remainingSkip;
|
||||
continue;
|
||||
}
|
||||
++totalResults;
|
||||
if (!options->countOnly) {
|
||||
if (++((ZiChineseWork*)work)->duplicateIndex >= 64) {
|
||||
((ZiChineseWork*)work)->duplicateIndex = 0;
|
||||
}
|
||||
if (wordMode) {
|
||||
++emittedCount;
|
||||
output[emittedCharacters++] = character;
|
||||
output[emittedCharacters++] = 0x20;
|
||||
if (emittedCharacters > capacity) {
|
||||
*skipCount = remainingSkip;
|
||||
*resultCount = totalResults;
|
||||
*candidateCount = emittedCount;
|
||||
*outputCount = emittedCharacters;
|
||||
Zi8ReplaceLastError(0xB54, work);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
output[emittedCount++] = character;
|
||||
}
|
||||
if (emittedCount >= request->maxCandidates) {
|
||||
*skipCount = remainingSkip;
|
||||
*resultCount = totalResults;
|
||||
*candidateCount = emittedCount;
|
||||
*outputCount = emittedCharacters;
|
||||
Zi8ReplaceLastError(0xB55, work);
|
||||
return 0;
|
||||
}
|
||||
} else if (totalResults >= options->maxResults) {
|
||||
*skipCount = remainingSkip;
|
||||
*resultCount = totalResults;
|
||||
*candidateCount = emittedCount;
|
||||
*outputCount = emittedCharacters;
|
||||
Zi8ReplaceLastError(0xB56, work);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
*skipCount = remainingSkip;
|
||||
*resultCount = totalResults;
|
||||
*candidateCount = emittedCount;
|
||||
*outputCount = emittedCharacters;
|
||||
return 1;
|
||||
}
|
||||
|
||||
ziU8 Zi8GetElementCount(ziWChar* elements, ziU8 elementCount, ziU8 charCount ZI_NEED_WORK) {
|
||||
ziU8 spacedIndex;
|
||||
ziU8 elementIndex;
|
||||
ziU8 count;
|
||||
ziWChar spacedElements[256];
|
||||
ziWChar savedSeparator = ZI_WORK->unk_0x1A;
|
||||
if (elementCount <= 1 || !charCount) {
|
||||
return elementCount;
|
||||
}
|
||||
for (spacedIndex = 0; spacedIndex < elementCount; ++spacedIndex) {
|
||||
if (elements[spacedIndex] != ';' &&
|
||||
(elements[spacedIndex] < 'a' || elements[spacedIndex] > 'z')) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (spacedIndex == elementCount) {
|
||||
return elementCount;
|
||||
}
|
||||
ZI_WORK->unk_0x1A = 0xF360;
|
||||
Zi8ZHaddSpace(elements, elementCount, spacedElements, 256, __zi8_work_data);
|
||||
ZI_WORK->unk_0x1A = savedSeparator;
|
||||
spacedIndex = elementIndex = count = 0;
|
||||
while (charCount && elementIndex < elementCount) {
|
||||
if (spacedElements[spacedIndex] == 0xF360) {
|
||||
--charCount;
|
||||
if (elements[elementIndex] != 0xF360) {
|
||||
goto next_spaced_element;
|
||||
}
|
||||
} else if (spacedElements[spacedIndex] >= 0xF331 && spacedElements[spacedIndex] <= 0xF335) {
|
||||
--charCount;
|
||||
if (elements[elementIndex + 1] == 0xF360) {
|
||||
++spacedIndex;
|
||||
++elementIndex;
|
||||
++count;
|
||||
}
|
||||
}
|
||||
++elementIndex;
|
||||
++count;
|
||||
next_spaced_element:
|
||||
++spacedIndex;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
extern int zi8InternalGetZH(ziGetParam* request, ZiChineseOptions* options, ziPtr work);
|
||||
|
||||
int Zi8GetChineseCandidates(ziGetParam* request, ZiChineseOptions* options, ziPtr work) {
|
||||
ziU8 savedCountOnly;
|
||||
int savedMaxResults;
|
||||
int length;
|
||||
ziGetParam suffixRequest;
|
||||
if (request->firstCandidate || request->elementCount <= 1) {
|
||||
get_candidates:
|
||||
return zi8InternalGetZH(request, options, work);
|
||||
}
|
||||
switch (request->getMode) {
|
||||
case 16:
|
||||
if (request->elements[request->elementCount - 1] == 0xF360) {
|
||||
goto get_candidates;
|
||||
}
|
||||
for (length = request->elementCount - 2; length > 0; --length) {
|
||||
if (request->elements[length] == 0xF360) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (length++ <= 0) {
|
||||
goto get_candidates;
|
||||
}
|
||||
break;
|
||||
case 12:
|
||||
case 13:
|
||||
switch (request->elements[request->elementCount - 1]) {
|
||||
case 0xF331:
|
||||
case 0xF332:
|
||||
case 0xF333:
|
||||
case 0xF334:
|
||||
case 0xF335:
|
||||
case 0xF360:
|
||||
break;
|
||||
default:
|
||||
goto get_candidates;
|
||||
}
|
||||
for (length = 1; length < 64; ++length) {
|
||||
if (Zi8GetElementCount(request->elements, request->elementCount, length, work) >= request->elementCount) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (length-- == 1) {
|
||||
goto get_candidates;
|
||||
}
|
||||
length = Zi8GetElementCount(request->elements, request->elementCount, length, work);
|
||||
break;
|
||||
default:
|
||||
goto get_candidates;
|
||||
}
|
||||
suffixRequest = *request;
|
||||
savedCountOnly = options->countOnly;
|
||||
savedMaxResults = options->maxResults;
|
||||
suffixRequest.elements = request->elements + length;
|
||||
suffixRequest.elementCount = (ziU8)(suffixRequest.elementCount - length);
|
||||
savedCountOnly = options->countOnly;
|
||||
options->countOnly = 1;
|
||||
savedMaxResults = options->maxResults;
|
||||
options->maxResults = 1;
|
||||
length = zi8InternalGetZH(&suffixRequest, options, work);
|
||||
options->countOnly = savedCountOnly;
|
||||
options->maxResults = savedMaxResults;
|
||||
if (!length) {
|
||||
Zi8LogError(0x1388, work);
|
||||
return 0;
|
||||
}
|
||||
return zi8InternalGetZH(request, options, work);
|
||||
}
|
||||
|
||||
const ziWChar ziTones[4] = {0x02CA, 0x02C7, 0x02CB, 0x02D9};
|
||||
const ziWChar ziPuncts[4] = {0xFF0C, 0x3002, 0xFF1F, 0xFF01};
|
||||
const ziWChar zi8tones[4];
|
||||
@@ -93,3 +93,13 @@ forbidden patterns added (net, per file): 0
|
||||
readability warnings (net, per file; must be 0 in the final result): 0
|
||||
GATE PASS
|
||||
```
|
||||
|
||||
## Follow-up matching attempts, 2026-09-30
|
||||
|
||||
Starting this continuation: 4/9 instruction-exact, code 2588/21460, data 1160/1388. Configuration stayed NonMatching throughout these attempts. All experiments were scoped to the named function, built as 43U and measured with ctxdiff. Rejected variants were restored.
|
||||
|
||||
- Zi8SpellingZY: reversed scalar declarations (123/123, ten differences); expressed the final-row access with pointer arithmetic (123/123, six differences); used a typed four-byte row structure (123/123, six differences). Retained the six-difference baseline.
|
||||
- Zi8SpellingPY: moved tone declaration first (158/157); used a signed tone (159/157); changed the spelling scans to postfix increments (158/157). None removed the register-held tone or restored the target stack slot.
|
||||
- MatchAltSound1Key: reversed scalar declarations (339/341); made the signed midpoint sum explicit (339/341); changed backward-search decrement to assignment (339/341). None fixed table-load/search ordering.
|
||||
- Zi8Get1KeyPressSpelling: unsigned terminator equality (1571/1700, 59.628235%); reverse local declarations (1572/1700, 59.968235%); integer expansion count and integer boolean conversions (1536/1700, 59.57353%). All scored below the starting 59.97%; retained the baseline.
|
||||
- Zi8Get1KeyPressCandidates: reverse local declarations (2775/2397, 53.831455%); while-form terminator trimming (2773/2397, 53.523155%); explicit unsigned charset result (2775/2397, 53.775135%). Retained the small fuzzy-score improvement from reversing the candidate function declarations; instruction count and the target stack-layout mismatch remain unchanged. This is a partial improvement, not an exact match. No additional exact function was found.
|
||||
|
||||
@@ -81,3 +81,24 @@ source name FrenchExcludePairs.
|
||||
|
||||
Restored NonMatching, rebuilt main.dol, and confirmed SHA1
|
||||
26116613f624061ba99c8d1a299aaa6efa85670d. configure.py has no final changes.
|
||||
|
||||
## Follow-up matching attempts, 2026-09-30
|
||||
|
||||
Starting this continuation: 10/12 instruction-exact, code 5704/21664, data 0/564. Configuration stayed NonMatching throughout these attempts. Experiments were scoped to the named function and rejected variants were restored.
|
||||
|
||||
Zi8ChangeWordCase:
|
||||
|
||||
1. Replace the case enum with an integer flag: 44/44 instructions, the same eight register differences.
|
||||
2. Use a byte flag: 44/44, the same eight register differences.
|
||||
3. Declare and assign the byte flag separately: 44/44, the same eight register differences.
|
||||
4. Typed work parameter: 44/44, eleven register differences.
|
||||
5. Local typed work alias: 41/44; compiler combines work loads differently from the target.
|
||||
6. Local word cursor: 45/44; extra cursor setup. Rejected. The original enum declaration remains.
|
||||
|
||||
Zi8AlphaGetCandidates:
|
||||
|
||||
1. Reverse local declarations: 4452/3946 instructions, 44.43538%.
|
||||
2. Recover five state flags as bytes: 4452/3946, 44.341106%.
|
||||
3. Explicit switch for phonetic separators F331 through F335: 4450/3946, 44.217434%.
|
||||
|
||||
All three candidate-engine scores were below the 44.43563% baseline. The stack frame remains 0x330 instead of 0x2B0, with branch, conversion and load differences throughout. No additional exact function was found; no source variant was retained.
|
||||
|
||||
64
tools/decomp-assist/zi8cgetc.attempts.md
Normal file
64
tools/decomp-assist/zi8cgetc.attempts.md
Normal file
@@ -0,0 +1,64 @@
|
||||
# zi8cgetc attempts
|
||||
|
||||
43U only. Starting source absent: 0/8 instruction-exact, 0/47816 objdiff code bytes, 0/536 data bytes. No shared headers or configuration changes.
|
||||
|
||||
The assembly is the authority. The first four functions were recovered in address order. The string pools contain no strings on either side.
|
||||
|
||||
- Zi8SetFindCand: signed integer remainder/division of the masked ordinal, as in the sibling unit. 50/50 instructions, diffs 0.
|
||||
- ZiGetNextPhonetic: preserve repeated character reads and boundary-check order. 31/31 instructions, diffs 0.
|
||||
- ZiPartialMatch: preserve the initial empty-range test, loop separator tests, and the repeated empty-range test after advancing both pointers. 51/51 instructions, diffs 0.
|
||||
|
||||
## ZiMatchZHSpelling
|
||||
|
||||
1. Two 64-character buffers, integer match/index, byte character count. 121/121 instructions, 29 register-choice differences, objdiff 98.80165%.
|
||||
2. Declare the character count first and assign it after initializing the result. Same 121/121 and 29 differences.
|
||||
3. Correct Zi8WCharCount's declaration to its actual 32-bit return, use an integer character count. Same 121/121 and 29 differences.
|
||||
4. Move match/count/index declarations before cursors and buffers. Same 121/121 and 29 differences.
|
||||
|
||||
Differences are the candidate/spelling/work/count/result register assignments. Branches, buffer offsets and instruction counts agree. No forced stack/register storage.
|
||||
|
||||
## Zi8NewMatchPhonetic
|
||||
|
||||
Read the assembly in address order: argument/limit initialization, table selection, grouped-candidate loop, phonetic-offset loop, result exits. Recovered each block separately in /tmp before assembling the complete C function. The source uses a local work layout and a 12-byte record structure. No shared ABI changes.
|
||||
|
||||
1. Complete block reconstruction: 755/755 instructions, 198 differences. Most differences were reversed local stack order.
|
||||
2. Reverse local declarations to restore stack slot order: 755/755, nine differences. Candidate-index/pointer increments were reversed and three byte swaps used arithmetic shifts.
|
||||
3. Move the counter increment into the loop body and cast shifted values to byte: 759/755; register allocation changed throughout. Rejected.
|
||||
4. Comma-expression increment in the for header and unsigned shift: 756/755, extra pointer temporary and shifted stack slots. Rejected.
|
||||
5. While loop with index increment before pointer increment, and masked high-byte shifts: 755/755 instructions, diffs 0.
|
||||
|
||||
## Zi8GetElementCount
|
||||
|
||||
1. Literal assembly reconstruction: 114/115 instructions. Saved separator retained in a register rather than its original stack slot; three separate zero assignments and an early continue also differed.
|
||||
2. Chained index/count initialization, common spaced-index update, and a 32-bit saved separator: 114/115. Control flow corrected; saved separator and associated buffer/register locations still differed.
|
||||
3. Reverse index declarations and chain initialization in the original assignment order: 113/115. Remaining differences are separator storage and dependent register/frame allocation.
|
||||
4. Const halfword separator: 115/115, 19 differences. It still remains in a register, with an extra conversion instead of the target stack store/load.
|
||||
5. Signed separator: 115/115, 20 differences, including wrong signed load. Rejected. Kept the unsigned separator and literal common loop exit.
|
||||
|
||||
## Zi8GetChineseCandidates
|
||||
|
||||
1. Switch reconstruction with direct returns: 180/155 instructions. Repeated early calls, larger frame and separate length/result registers.
|
||||
2. Shared early call exit and reverse local declarations: 150/155. Call exit was at the wrong end of the function; saved options registers were reversed.
|
||||
3. Put the shared call immediately after the initial conditional and reuse length for the internal result: 155/155, six saved-options register differences.
|
||||
4. Declare savedCountOnly before savedMaxResults: 155/155 instructions, diffs 0.
|
||||
5. Widen savedCountOnly to int: 156/155, redundant byte conversion. Rejected.
|
||||
|
||||
Added the two ordinary four-character tone/punctuation tables and the zero-initialized tone table from the assembly. Jump tables are not manually reproduced.
|
||||
|
||||
## Follow-up attempts, 2026-09-30
|
||||
|
||||
ZiMatchZHSpelling: reversing the complete local declaration order and using a typed work pointer did not improve the 121/121 instruction, 29-register-difference result. Restored the accepted declaration order.
|
||||
|
||||
Zi8GetElementCount: moving the separator declaration before the buffer and splitting its initialization did not improve the 113/115 instruction result. Restored the accepted source. The original stores the separator on the stack; the ordinary scalar remains in a saved register. No spill-forcing declaration was introduced.
|
||||
|
||||
## zi8InternalGetZH: initial-block research only
|
||||
|
||||
The 10676-instruction internal engine remains absent. The following are three compiled alternatives for its initial basic blocks, not three completed reconstructions. Each research variant is under /tmp and is not part of the source change.
|
||||
|
||||
Recovered the initial mode normalization and non-phrase input validation, charset setup, match preparation and output copying from the assembly in address order. The original first clears a 494-byte ZiMatchParam with 61 paired word stores plus the final word and halfword. Tested that layout with the actual 43U compiler:
|
||||
|
||||
1. Aggregate zero initializer: 245 instructions in the isolated prefix. Emits the original 61-iteration paired-word clear, but its frame and registers differ because the remaining engine is absent.
|
||||
2. Zi8Memset over the same structure: 240 prefix instructions. Produces a call rather than the target inline clear. Rejected.
|
||||
3. Explicit byte loop: 244 prefix instructions. Bytewise clearing differs from the original word loop. Rejected.
|
||||
|
||||
No incomplete public function or placeholder body was added. The phrase paths and subsequent dictionary/candidate loops are not reconstructed. These prefix experiments do not satisfy full-unit completion or establish a compiler plateau for the complete engine.
|
||||
Reference in New Issue
Block a user