From 893803fd2fe4a3de8864210c7325a9b51335ba40 Mon Sep 17 00:00:00 2001 From: coah <100182500+coah80@users.noreply.github.com> Date: Wed, 30 Sep 2026 13:54:05 +0000 Subject: [PATCH] zi81key and zi8alpha: big functions fully written (60/54/44% -> 97/95/82%) (worker 092b8946) --- README.md | 2 +- libs/RVLMiddleware/eZiText/src/clib/zi81key.c | 1663 ++++++++--------- .../RVLMiddleware/eZiText/src/clib/zi8alpha.c | 1252 ++++++------- tools/decomp-assist/zi81key.attempts.md | 35 + tools/decomp-assist/zi8alpha.attempts.md | 30 + 5 files changed, 1407 insertions(+), 1575 deletions(-) diff --git a/README.md b/README.md index 282fa092..002690ec 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Progress | Decompiled | Matched | Linked | Data | |:---:|:---:|:---:|:---:| -| 97.17% | 83.64% | 58.20% | 89.94% | +| 97.59% | 83.64% | 58.20% | 89.94% | units 778/1027 complete, functions 12026/12563 matched. diff --git a/libs/RVLMiddleware/eZiText/src/clib/zi81key.c b/libs/RVLMiddleware/eZiText/src/clib/zi81key.c index 08f3fb57..f1346a2a 100644 --- a/libs/RVLMiddleware/eZiText/src/clib/zi81key.c +++ b/libs/RVLMiddleware/eZiText/src/clib/zi81key.c @@ -216,8 +216,8 @@ extern ziU8 Zi8IsDupWordW(); extern ziU8 Zi8GetFormatVersion(ziU8,ziPtr); extern ziU16 Zi8Uni2Ord(ziWChar,ziPtr); extern ziU16 Zi8GetPCode(ziU8 *,ziU8 *); -extern int Zi8MatchOEMdata(); -extern int Zi8MatchPUDdata(); +extern ziU8 Zi8MatchOEMdata(ziWChar *,ziU8,ziU8,ziWChar *,ziU16,ziU8,ziU8,ziPtr); +extern ziU8 Zi8MatchPUDdata(ziWChar *,ziU8,ziU8,ziWChar *,ziU16,ziU8,ziU8,ziPtr); extern ziWChar Zi8Ord2Uni(ziU16,ziPtr); extern Zi8UInt Zi8GetZHuwdPtr(ziU8 **,ziU16 *,ziPtr); extern int Zi8GetPyPhonetic(); @@ -269,15 +269,11 @@ Zi8UInt Zi8SpellingZY(ziU16 *output,Zi8UInt key,ziU8 includeTone) Zi8UInt Zi8SpellingPY(ziU16 *output,Zi8UInt key,ziU8 includeTone) { - ziU16 initialIndex; - ziU16 finalIndex; - ziU16 tone; - Zi8UInt length; + ziU16 initialIndex = (ziU16)(((key & 0xffff) >> 9) & 0x3f); + ziU16 finalIndex = (ziU16)(((key & 0xffff) >> 3) & 0x3f); + ziU16 tone = (ziU16)(key & 7); + Zi8UInt length = 0; - length = 0; - initialIndex = (ziU16)(((key & 0xffff) >> 9) & 0x3f); - finalIndex = (ziU16)(((key & 0xffff) >> 3) & 0x3f); - tone = (ziU16)(key & 7); output[0] = zi8PYinitialSpelling[initialIndex][0]; output[1] = zi8PYinitialSpelling[initialIndex][1]; output[2] = 0; @@ -315,7 +311,7 @@ Zi8UInt Zi8SpellingPY(ziU16 *output,Zi8UInt key,ziU8 includeTone) return length; } -Zi8UInt Zi8IsMatch1Key(ziU16 *input,Zi8UInt inputLength,Zi8UInt key,ziU8 requireFull,ziU8 usePinyin,Zi8UInt tone) +ziU8 Zi8IsMatch1Key(ziU16 *input,Zi8UInt inputLength,Zi8UInt key,ziU8 requireFull,ziU8 usePinyin,Zi8UInt tone) { ziU16 spelling[16]; Zi8UInt spellingLength; @@ -356,7 +352,7 @@ Zi8UInt Zi8IsMatch1Key(ziU16 *input,Zi8UInt inputLength,Zi8UInt key,ziU8 require return 1; } -Zi8UInt MatchAltSound1Key(ziU16 *spelling,Zi8UInt spellingLength,Zi8UInt requireFull,Zi8AltSoundRecord *records,Zi8UInt recordCount,const ziU8 *phoneticTableBase,Zi8UInt key,Zi8UInt usePinyin,ziU8 tone,ziU8 modifierFlags,Zi8OneKeyWork *context) +ziU8 MatchAltSound1Key(ziU16 *spelling,Zi8UInt spellingLength,Zi8UInt requireFull,Zi8AltSoundRecord *records,Zi8UInt recordCount,const ziU8 *phoneticTableBase,Zi8UInt key,Zi8UInt usePinyin,ziU8 tone,ziU8 modifierFlags,Zi8OneKeyWork *context) { int searchIndex; ziU8 keyHigh; @@ -399,8 +395,7 @@ PROCESS: (context->phoneticEnabled[(ziU16)phoneticOffset] != '\0')) { phoneticOffset = (ziU16)(phoneticOffset << 1); phoneticCode = (ziU16)(((records[recordIndex].flags & 0xf0) >> 4) | - CONCAT11_LOW_FIRST(phoneticTableBase[phoneticOffset], - phoneticTableBase[phoneticOffset + 1])); + (phoneticTableBase[(ziU16)phoneticOffset] | ((ziU16)phoneticTableBase[(ziU16)phoneticOffset + 1] << 8))); if ((ziU8)Zi8IsMatch1Key(spelling,spellingLength & 0xff,phoneticCode, requireFull & 0xff,usePinyin & 0xff,tone) != '\0') { return 1; @@ -422,8 +417,7 @@ BACKWARD_PROCESS: (context->phoneticEnabled[(ziU16)phoneticOffset] != '\0')) { phoneticOffset = (ziU16)(phoneticOffset << 1); phoneticCode = (ziU16)(((records[recordIndex].flags & 0xf0) >> 4) | - CONCAT11_LOW_FIRST(phoneticTableBase[phoneticOffset], - phoneticTableBase[phoneticOffset + 1])); + (phoneticTableBase[(ziU16)phoneticOffset] | ((ziU16)phoneticTableBase[(ziU16)phoneticOffset + 1] << 8))); if ((ziU8)Zi8IsMatch1Key(spelling,spellingLength & 0xff,phoneticCode, requireFull & 0xff,usePinyin & 0xff,tone) != '\0') { return 1; @@ -440,51 +434,32 @@ BACKWARD_TEST: goto BACKWARD_PROCESS; BINARY_SEARCH: - while (true) { - if ((keyHigh == records[searchIndex].keyHigh) && - (keyLow == records[searchIndex].keyLow)) { - recordIndex = searchIndex; - goto PROCESS; - } - if ((int)CONCAT11(records[searchIndex].keyHigh, - records[searchIndex].keyLow) <= (int)(key & 0xffff)) { - midpoint = ((int)searchIndex + recordIndex) / 2; - if (midpoint == (int)searchIndex) { - return 0; - } - if ((int)CONCAT11(records[midpoint].keyHigh, - records[midpoint].keyLow) < (int)(key & 0xffff)) { - searchIndex = midpoint; - } else { - recordIndex = midpoint; - for (;;) { - if ((keyHigh == records[recordIndex].keyHigh) && - (keyLow == records[recordIndex].keyLow)) { - searchIndex = recordIndex; - goto PROCESS; - } - if ((int)CONCAT11(records[recordIndex].keyHigh, - records[recordIndex].keyLow) >= (int)(key & 0xffff)) { - midpoint = ((int)searchIndex + recordIndex) / 2; - if (midpoint == (int)searchIndex) { - return 0; - } - if ((int)CONCAT11(records[midpoint].keyHigh, - records[midpoint].keyLow) < (int)(key & 0xffff)) { - searchIndex = midpoint; - break; - } - recordIndex = midpoint; - } else { - return 0; - } - } - } - } else { - return 0; - } + if ((keyHigh == records[searchIndex].keyHigh) && + (keyLow == records[searchIndex].keyLow)) goto START_PROCESS; + if (((ziU16)records[searchIndex].keyHigh << 8 | (ziU16)records[searchIndex].keyLow) > (int)(key & 0xffff)) return 0; + midpoint = (searchIndex + recordIndex) / 2; + if (midpoint == searchIndex) return 0; + if (((ziU16)records[midpoint].keyHigh << 8 | (ziU16)records[midpoint].keyLow) >= (int)(key & 0xffff)) { + recordIndex = midpoint; + } else { + searchIndex = midpoint; + goto BINARY_SEARCH; } - +BACKWARD_SEARCH: + if ((keyHigh == records[recordIndex].keyHigh) && + (keyLow == records[recordIndex].keyLow)) { + searchIndex = recordIndex; + goto START_PROCESS; + } + if (((ziU16)records[recordIndex].keyHigh << 8 | (ziU16)records[recordIndex].keyLow) < (int)(key & 0xffff)) return 0; + midpoint = (searchIndex + recordIndex) / 2; + if (midpoint == searchIndex) return 0; + if (((ziU16)records[midpoint].keyHigh << 8 | (ziU16)records[midpoint].keyLow) >= (int)(key & 0xffff)) { + recordIndex = midpoint; + goto BACKWARD_SEARCH; + } + searchIndex = midpoint; + goto BINARY_SEARCH; } } static Zi8UInt Zi8SetFindCand(ziU8 *foundCandidates,Zi8UInt ordinal,ziPtr work) @@ -533,33 +508,29 @@ LAB_return_false: Zi8UInt Zi8Get1KeyPressSpelling(Zi8OneKeyParam *params,Zi8OneKeyOptions *options,Zi8OneKeyWork *work) { + ziU8 candidateCount; ziBool exactLength; - ziU8 optionsMask; - ziU8 mode; - ziU8 savedSearchCount; - ziU8 savedSearchFlags; - ziU8 *savedSearchOrder; - ziU16 phoneticIndex; - ziU16 phoneticCode; ziU8 usePinyin; ziU8 languageMask; - ziU16 tableCount; - int characterIndex; - ziU8 duplicate; - ziU16 expansionCount; - ziU16 firstElement; - ziU8 inputLength; ziU8 entryLength; - ziU8 characterSet; - ziU8 candidateCount; - ziU16 remaining; - ziU16 spellingLength; + ziU8 inputLength; + ziU8 optionsMask; + ziU8 savedSearchCount; + ziBool convertedInput; + ziU8 savedSearchFlags; + ziU16 tableCount; ziU16 spellingIndex; - ziU16 *output; - ziU8 *phoneticTable; - ziU8 *spellingEntry; + ziU16 phoneticIndex; + ziU16 phoneticCount; + ziU16 remaining; + ziU16 character; + ziU16 tableIndex; Zi8UInt totalCandidates; - ziU16 spellingBuffer [8]; + ziU8 *spellingEntry; + ziU8 *phoneticTable; + ziU16 *output; + ziU8 *savedSearchOrder; + ziU16 spellingBuffer[8]; Zi8OneKeyParam searchParams; candidateCount = 0; @@ -573,224 +544,281 @@ Zi8UInt Zi8Get1KeyPressSpelling(Zi8OneKeyParam *params,Zi8OneKeyOptions *options if (options->maxSpellingLength == '\0') { params->count = 0; Zi8LogError(100,work); - totalCandidates = 0; - goto returnSpelling; + return 0; } if (((params->subLanguage & 0x80) != 0) || ((params->subLanguage & 0x40) != 0)) { - characterSet = 1; + languageMask = 1; } else if ((params->subLanguage & 8) != 0) { - characterSet = 4; + languageMask = 4; } else if (((params->subLanguage & 0x20) != 0) || ((params->subLanguage & 0x10) != 0)) { - characterSet = 2; + languageMask = 2; } else { - characterSet = params->subLanguage; + languageMask = params->subLanguage; } - languageMask = characterSet << 4; + languageMask = languageMask << 4; remaining = params->firstCandidate; - if (options->countOnly == '\0') { - output = params->candidates; - } - else { + if (options->countOnly != 0) { output = spellingBuffer; + } else { + output = params->candidates; } tableCount = Zi8GetTableCount(1,0xc,work); if (((((((languageMask & 0x10) == 0) || (params->getMode != '\x03')) || ((params->context & 0x10) == 0)) || - (characterIndex = ZiIsSupportedPhonetic(0x7c,work), characterIndex == 0)) && + ZiIsSupportedPhonetic(0x7c,work) == 0) && ((((languageMask & 0x10) == 0 || (params->getMode != '\x0f')) || - (characterIndex = ZiIsSupportedPhonetic(0x7b,work), characterIndex == 0)))) && + ZiIsSupportedPhonetic(0x7b,work) == 0))) && (((((languageMask & 0x20) == 0 || (params->getMode != '\x04')) || (((params->context & 0x10) == 0 || - (characterIndex = ZiIsSupportedPhonetic(0x7d,work), characterIndex == 0)))) && (tableCount == 0)))) + ZiIsSupportedPhonetic(0x7d,work) == 0))) && (tableCount == 0)))) goto finishSpelling; - mode = params->getMode; - if (mode == 4) { + switch (params->getMode) { + case 3: + case 15: + phoneticTable = (ziU8 *)Zi8GetTableAddress(1,3,work); + phoneticCount = Zi8GetTableCount(1,3,work); + usePinyin = true; + break; + case 4: phoneticTable = (ziU8 *)Zi8GetTableAddress(1,4,work); - Zi8GetTableCount(1,4,work); + phoneticCount = Zi8GetTableCount(1,4,work); usePinyin = false; -prepareInput: + break; + default: + goto finishSpelling; + } inputLength = params->elementCount; - while ((inputLength != 0 && ((ziS16)params->elements[(inputLength - 1)] == -0x10f7))) { - inputLength = inputLength - 1; + while (inputLength != 0) { + if (params->elements[inputLength - 1] != 0xef09) break; + --inputLength; } - exactLength = inputLength != 0; - firstElement = params->elements[0]; - if ((((inputLength == 1) && ((optionsMask & 0x81) == 0x80)) && (0xeff0 < firstElement)) && (firstElement < 0xf011)) { + if (inputLength != 0) exactLength = true; + else exactLength = false; + character = params->elements[0]; + if ((((inputLength == 1) && ((optionsMask & 0x81) == 0x80)) && (0xeff1 <= character)) && (character <= 0xf010)) { + tableIndex = 0; if (usePinyin) { - if (firstElement == 0xeff2) { - spellingBuffer[0] = 0xf361; + if (character == 0xeff2) { + spellingBuffer[tableIndex++] = 0xf361; } - expansionCount = (unsigned long long)(firstElement == 0xeff2); - if (firstElement == 0xeff2) { - spellingBuffer[1] = 0xf362; - expansionCount = 3; - spellingBuffer[2] = 0xf363; + if (character == 0xeff2) { + spellingBuffer[tableIndex++] = 0xf362; } - if (firstElement == 0xeff3) { - characterIndex = (int)expansionCount; - spellingBuffer[expansionCount] = 0xf364; - spellingBuffer[characterIndex + 1] = 0xf365; - expansionCount = expansionCount + 3; - spellingBuffer[characterIndex + 2] = 0xf366; + if (character == 0xeff2) { + spellingBuffer[tableIndex++] = 0xf363; } - if (firstElement == 0xeff4) { - characterIndex = (int)expansionCount; - spellingBuffer[expansionCount] = 0xf367; - spellingBuffer[characterIndex + 1] = 0xf368; - expansionCount = expansionCount + 3; - spellingBuffer[characterIndex + 2] = 0xf369; + if (character == 0xeff3) { + spellingBuffer[tableIndex++] = 0xf364; } - if (firstElement == 0xeff5) { - characterIndex = (int)expansionCount; - spellingBuffer[expansionCount] = 0xf36a; - spellingBuffer[characterIndex + 1] = 0xf36b; - expansionCount = expansionCount + 3; - spellingBuffer[characterIndex + 2] = 0xf36c; + if (character == 0xeff3) { + spellingBuffer[tableIndex++] = 0xf365; } - if (firstElement == 0xeff6) { - characterIndex = (int)expansionCount; - spellingBuffer[expansionCount] = 0xf36d; - spellingBuffer[characterIndex + 1] = 0xf36e; - expansionCount = expansionCount + 3; - spellingBuffer[characterIndex + 2] = 0xf36f; + if (character == 0xeff3) { + spellingBuffer[tableIndex++] = 0xf366; } - if (firstElement == 0xeff7) { - characterIndex = (int)expansionCount; - spellingBuffer[expansionCount] = 0xf370; - spellingBuffer[characterIndex + 1] = 0xf371; - spellingBuffer[characterIndex + 2] = 0xf372; - expansionCount = expansionCount + 4; - spellingBuffer[characterIndex + 3] = 0xf373; + if (character == 0xeff4) { + spellingBuffer[tableIndex++] = 0xf367; } - if (firstElement == 0xeff8) { - characterIndex = (int)expansionCount; - spellingBuffer[expansionCount] = 0xf374; - spellingBuffer[characterIndex + 1] = 0xf375; - expansionCount = expansionCount + 3; - spellingBuffer[characterIndex + 2] = 0xf376; + if (character == 0xeff4) { + spellingBuffer[tableIndex++] = 0xf368; } - if (firstElement == 0xeff9) { - characterIndex = (int)expansionCount; - spellingBuffer[expansionCount] = 0xf377; - spellingBuffer[characterIndex + 1] = 0xf378; - spellingBuffer[characterIndex + 2] = 0xf379; - expansionCount = expansionCount + 4; - spellingBuffer[characterIndex + 3] = 0xf37a; + if (character == 0xeff4) { + spellingBuffer[tableIndex++] = 0xf369; + } + if (character == 0xeff5) { + spellingBuffer[tableIndex++] = 0xf36a; + } + if (character == 0xeff5) { + spellingBuffer[tableIndex++] = 0xf36b; + } + if (character == 0xeff5) { + spellingBuffer[tableIndex++] = 0xf36c; + } + if (character == 0xeff6) { + spellingBuffer[tableIndex++] = 0xf36d; + } + if (character == 0xeff6) { + spellingBuffer[tableIndex++] = 0xf36e; + } + if (character == 0xeff6) { + spellingBuffer[tableIndex++] = 0xf36f; + } + if (character == 0xeff7) { + spellingBuffer[tableIndex++] = 0xf370; + } + if (character == 0xeff7) { + spellingBuffer[tableIndex++] = 0xf371; + } + if (character == 0xeff7) { + spellingBuffer[tableIndex++] = 0xf372; + } + if (character == 0xeff7) { + spellingBuffer[tableIndex++] = 0xf373; + } + if (character == 0xeff8) { + spellingBuffer[tableIndex++] = 0xf374; + } + if (character == 0xeff8) { + spellingBuffer[tableIndex++] = 0xf375; + } + if (character == 0xeff8) { + spellingBuffer[tableIndex++] = 0xf376; + } + if (character == 0xeff9) { + spellingBuffer[tableIndex++] = 0xf377; + } + if (character == 0xeff9) { + spellingBuffer[tableIndex++] = 0xf378; + } + if (character == 0xeff9) { + spellingBuffer[tableIndex++] = 0xf379; + } + if (character == 0xeff9) { + spellingBuffer[tableIndex++] = 0xf37a; + } + } else { + if (character == 0xeff1) { + spellingBuffer[tableIndex++] = 0xf305; + } + if (character == 0xeff1) { + spellingBuffer[tableIndex++] = 0xf306; + } + if (character == 0xeff1) { + spellingBuffer[tableIndex++] = 0xf307; + } + if (character == 0xeff1) { + spellingBuffer[tableIndex++] = 0xf308; + } + if (character == 0xeff2) { + spellingBuffer[tableIndex++] = 0xf309; + } + if (character == 0xeff2) { + spellingBuffer[tableIndex++] = 0xf30a; + } + if (character == 0xeff2) { + spellingBuffer[tableIndex++] = 0xf30b; + } + if (character == 0xeff2) { + spellingBuffer[tableIndex++] = 0xf30c; + } + if (character == 0xeff3) { + spellingBuffer[tableIndex++] = 0xf30d; + } + if (character == 0xeff3) { + spellingBuffer[tableIndex++] = 0xf30e; + } + if (character == 0xeff3) { + spellingBuffer[tableIndex++] = 0xf30f; + } + if (character == 0xeff4) { + spellingBuffer[tableIndex++] = 0xf310; + } + if (character == 0xeff4) { + spellingBuffer[tableIndex++] = 0xf311; + } + if (character == 0xeff4) { + spellingBuffer[tableIndex++] = 0xf312; + } + if (character == 0xeff5) { + spellingBuffer[tableIndex++] = 0xf313; + } + if (character == 0xeff5) { + spellingBuffer[tableIndex++] = 0xf314; + } + if (character == 0xeff5) { + spellingBuffer[tableIndex++] = 0xf315; + } + if (character == 0xeff5) { + spellingBuffer[tableIndex++] = 0xf316; + } + if (character == 0xeff6) { + spellingBuffer[tableIndex++] = 0xf317; + } + if (character == 0xeff6) { + spellingBuffer[tableIndex++] = 0xf318; + } + if (character == 0xeff6) { + spellingBuffer[tableIndex++] = 0xf319; + } + if (character == 0xeff7) { + spellingBuffer[tableIndex++] = 0xf31a; + } + if (character == 0xeff7) { + spellingBuffer[tableIndex++] = 0xf31b; + } + if (character == 0xeff7) { + spellingBuffer[tableIndex++] = 0xf31c; + } + if (character == 0xeff7) { + spellingBuffer[tableIndex++] = 0xf31d; + } + if (character == 0xeff8) { + spellingBuffer[tableIndex++] = 0xf31e; + } + if (character == 0xeff8) { + spellingBuffer[tableIndex++] = 0xf31f; + } + if (character == 0xeff8) { + spellingBuffer[tableIndex++] = 0xf320; + } + if (character == 0xeff8) { + spellingBuffer[tableIndex++] = 0xf321; + } + if (character == 0xeff9) { + spellingBuffer[tableIndex++] = 0xf322; + } + if (character == 0xeff9) { + spellingBuffer[tableIndex++] = 0xf323; + } + if (character == 0xeff9) { + spellingBuffer[tableIndex++] = 0xf324; + } + if (character == 0xeff9) { + spellingBuffer[tableIndex++] = 0xf325; + } + if (character == 0xeff9) { + spellingBuffer[tableIndex++] = 0xf326; + } + if (character == 0xeffa) { + spellingBuffer[tableIndex++] = 0xf327; + } + if (character == 0xeffa) { + spellingBuffer[tableIndex++] = 0xf328; + } + if (character == 0xeffa) { + spellingBuffer[tableIndex++] = 0xf329; } } - else { - if (firstElement == 0xeff1) { - spellingBuffer[0] = 0xf305; - } - expansionCount = (unsigned long long)(firstElement == 0xeff1); - if (firstElement == 0xeff1) { - spellingBuffer[1] = 0xf306; - spellingBuffer[2] = 0xf307; - expansionCount = 4; - spellingBuffer[3] = 0xf308; - } - if (firstElement == 0xeff2) { - characterIndex = (int)expansionCount; - spellingBuffer[expansionCount] = 0xf309; - spellingBuffer[characterIndex + 1] = 0xf30a; - spellingBuffer[characterIndex + 2] = 0xf30b; - expansionCount = expansionCount + 4; - spellingBuffer[characterIndex + 3] = 0xf30c; - } - if (firstElement == 0xeff3) { - characterIndex = (int)expansionCount; - spellingBuffer[expansionCount] = 0xf30d; - spellingBuffer[characterIndex + 1] = 0xf30e; - expansionCount = expansionCount + 3; - spellingBuffer[characterIndex + 2] = 0xf30f; - } - if (firstElement == 0xeff4) { - characterIndex = (int)expansionCount; - spellingBuffer[expansionCount] = 0xf310; - spellingBuffer[characterIndex + 1] = 0xf311; - expansionCount = expansionCount + 3; - spellingBuffer[characterIndex + 2] = 0xf312; - } - if (firstElement == 0xeff5) { - characterIndex = (int)expansionCount; - spellingBuffer[expansionCount] = 0xf313; - spellingBuffer[characterIndex + 1] = 0xf314; - spellingBuffer[characterIndex + 2] = 0xf315; - expansionCount = expansionCount + 4; - spellingBuffer[characterIndex + 3] = 0xf316; - } - if (firstElement == 0xeff6) { - characterIndex = (int)expansionCount; - spellingBuffer[expansionCount] = 0xf317; - spellingBuffer[characterIndex + 1] = 0xf318; - expansionCount = expansionCount + 3; - spellingBuffer[characterIndex + 2] = 0xf319; - } - if (firstElement == 0xeff7) { - characterIndex = (int)expansionCount; - spellingBuffer[expansionCount] = 0xf31a; - spellingBuffer[characterIndex + 1] = 0xf31b; - spellingBuffer[characterIndex + 2] = 0xf31c; - expansionCount = expansionCount + 4; - spellingBuffer[characterIndex + 3] = 0xf31d; - } - if (firstElement == 0xeff8) { - characterIndex = (int)expansionCount; - spellingBuffer[expansionCount] = 0xf31e; - spellingBuffer[characterIndex + 1] = 0xf31f; - spellingBuffer[characterIndex + 2] = 0xf320; - expansionCount = expansionCount + 4; - spellingBuffer[characterIndex + 3] = 0xf321; - } - if (firstElement == 0xeff9) { - characterIndex = (int)expansionCount; - spellingBuffer[expansionCount] = 0xf322; - spellingBuffer[characterIndex + 1] = 0xf323; - spellingBuffer[characterIndex + 2] = 0xf324; - spellingBuffer[characterIndex + 3] = 0xf325; - expansionCount = expansionCount + 5; - spellingBuffer[characterIndex + 4] = 0xf326; - } - if (firstElement == 0xeffa) { - characterIndex = (int)expansionCount; - spellingBuffer[expansionCount] = 0xf327; - spellingBuffer[characterIndex + 1] = 0xf328; - expansionCount = expansionCount + 3; - spellingBuffer[characterIndex + 2] = 0xf329; - } - } - for (spellingIndex = 0; spellingIndex < expansionCount; spellingIndex = spellingIndex + 1) { - if (remaining == 0) { - totalCandidates = totalCandidates + 1; + for (spellingIndex = 0; spellingIndex < tableIndex; spellingIndex++) { + if (remaining != 0) { + remaining--; + } else { + totalCandidates++; if (options->countOnly == '\0') { - *output = spellingBuffer[spellingIndex]; - output[1] = 0; - output = output + 2; - candidateCount = candidateCount + 1; + *output++ = spellingBuffer[spellingIndex]; + *output++ = 0; + candidateCount++; } - else if (options->maxCount <= (int)totalCandidates) break; - if (params->maxCandidates <= candidateCount) break; - } - else { - remaining = remaining + -1; + else if ((int)totalCandidates >= options->maxCount) goto finishSpelling; + if (candidateCount >= params->maxCandidates) goto finishSpelling; } } } else { if ((((((languageMask & 0x10) != 0) && (params->getMode == '\x03')) && (((params->context & 0x10) != 0 && - (characterIndex = ZiIsSupportedPhonetic(0x7c,work), characterIndex != 0)))) || + ZiIsSupportedPhonetic(0x7c,work) != 0))) || ((((languageMask & 0x10) != 0 && (params->getMode == '\x0f')) && - (characterIndex = ZiIsSupportedPhonetic(0x7b,work), characterIndex != 0)))) || + ZiIsSupportedPhonetic(0x7b,work) != 0))) || (((((languageMask & 0x20) != 0 && (params->getMode == '\x04')) && ((params->context & 0x10) != 0)) && - (characterIndex = ZiIsSupportedPhonetic(0x7d,work), characterIndex != 0)))) { + ZiIsSupportedPhonetic(0x7d,work) != 0))) { savedSearchOrder = work->searchOrder; savedSearchCount = work->searchOrderCount; - usePinyin = false; + convertedInput = false; savedSearchFlags = work->searchFlags; Zi8Memset(&searchParams,0,0x2c); searchParams.getMode = 0; @@ -798,7 +826,7 @@ prepareInput: searchParams.context = 1; searchParams.getOptions = 0x81; if (((params->getOptions & 0x10) != 0) || ((params->getOptions & 0xe) == 2)) { - searchParams.getOptions = 0x83; + searchParams.getOptions |= 2; } searchParams.elements = params->elements; searchParams.elementCount = params->elementCount; @@ -811,74 +839,62 @@ prepareInput: else if (params->getMode == '\x03') { searchParams.language = ZI8_LANG_PY2; if (((params->context & 0xf) == 1) || ((params->context & 0xf) == 3)) { - duplicate = Zi8LangSupported(0x77,work); - if (duplicate == '\0') { - duplicate = Zi8LangSupported(0x78,work); - if (duplicate != '\0') { + if (Zi8LangSupported(0x77,work) != 0) { + searchParams.language = ZI8_LANG_PYP; + } else { + if (Zi8LangSupported(0x78,work) != 0) { searchParams.language = ZI8_LANG_PYS; } } - else { - searchParams.language = ZI8_LANG_PYP; - } } if (((params->context & 0xf) == 1) || ((params->context & 0xf) == 5)) { - duplicate = Zi8LangSupported(0x78,work); - if (duplicate == '\0') { - duplicate = Zi8LangSupported(0x77,work); - if (duplicate != '\0') { + if (Zi8LangSupported(0x78,work) != 0) { + searchParams.subLanguage = ZI8_LANG_PYS; + } else { + if (Zi8LangSupported(0x77,work) != 0) { searchParams.subLanguage = ZI8_LANG_PYP; } } - else { - searchParams.subLanguage = ZI8_LANG_PYS; - } } if ((searchParams.language == ZI8_LANG_PY2) && (searchParams.subLanguage != 0x80)) { searchParams.language = searchParams.subLanguage; searchParams.subLanguage = 0x80; } - for (tableCount = 0; tableCount < params->elementCount; tableCount = tableCount + 1) { - if ((ziS16)params->elements[(Zi8UInt)tableCount] == -0xca0) { - params->elements[(Zi8UInt)tableCount] = 0x27; - usePinyin = true; + for (tableIndex = 0; tableIndex < params->elementCount; tableIndex++) { + if (params->elements[(Zi8UInt)tableIndex] == 0xf360) { + params->elements[(Zi8UInt)tableIndex] = 0x27; + convertedInput = true; } } } else { searchParams.language = ZI8_LANG_ZY2; if (((params->context & 0xf) == 1) || ((params->context & 0xf) == 3)) { - duplicate = Zi8LangSupported(0x79,work); - if (duplicate == '\0') { - duplicate = Zi8LangSupported(0x7a,work); - if (duplicate != '\0') { + if (Zi8LangSupported(0x79,work) != 0) { + searchParams.language = ZI8_LANG_ZYP; + } else { + if (Zi8LangSupported(0x7a,work) != 0) { searchParams.language = ZI8_LANG_ZYS; } } - else { - searchParams.language = ZI8_LANG_ZYP; - } } if (((params->context & 0xf) == 1) || ((params->context & 0xf) == 5)) { - duplicate = Zi8LangSupported(0x7a,work); - if (duplicate == '\0') { - duplicate = Zi8LangSupported(0x79,work); - if (duplicate != '\0') { + if (Zi8LangSupported(0x7a,work) != 0) { + searchParams.subLanguage = ZI8_LANG_ZYS; + } else { + if (Zi8LangSupported(0x79,work) != 0) { searchParams.subLanguage = ZI8_LANG_ZYP; } } - else { - searchParams.subLanguage = ZI8_LANG_ZYS; - } } if ((searchParams.language == ZI8_LANG_ZY2) && (searchParams.subLanguage != 0x80)) { searchParams.language = searchParams.subLanguage; searchParams.subLanguage = 0x80; } - for (tableCount = 0; tableCount < params->elementCount; tableCount = tableCount + 1) { - if ((ziS16)params->elements[(Zi8UInt)tableCount] == 0x27) { - params->elements[(Zi8UInt)tableCount] = 0xf360; - usePinyin = true; + for (tableIndex = 0; tableIndex < params->elementCount; tableIndex++) { + if (params->elements[(Zi8UInt)tableIndex] == 0x27) { + params->elements[(Zi8UInt)tableIndex] = 0xf360; + convertedInput = true; } } } @@ -897,155 +913,116 @@ prepareInput: } work->searchFlags = 0; work->spellingSearch = 1; - totalCandidates = _Zi8GetCandidates(&searchParams,work); - totalCandidates = totalCandidates & 0xff; + totalCandidates = (ziU8)_Zi8GetCandidates(&searchParams,work); work->spellingSearch = 0; work->searchFlags = savedSearchFlags; work->searchOrder = savedSearchOrder; work->searchOrderCount = savedSearchCount; params->count = searchParams.count; work->spellingOnly = 0; - if (usePinyin) { + if (convertedInput) { if (params->getMode == '\x03') { - for (tableCount = 0; tableCount < params->elementCount; tableCount = tableCount + 1) { - if ((ziS16)params->elements[(Zi8UInt)tableCount] == 0x27) { - params->elements[(Zi8UInt)tableCount] = 0xf360; + for (tableIndex = 0; tableIndex < params->elementCount; tableIndex++) { + if (params->elements[(Zi8UInt)tableIndex] == 0x27) { + params->elements[(Zi8UInt)tableIndex] = 0xf360; } } } else { - for (tableCount = 0; tableCount < params->elementCount; tableCount = tableCount + 1) { - if ((ziS16)params->elements[(Zi8UInt)tableCount] == -0xca0) { - params->elements[(Zi8UInt)tableCount] = 0x27; + for (tableIndex = 0; tableIndex < params->elementCount; tableIndex++) { + if (params->elements[(Zi8UInt)tableIndex] == 0xf360) { + params->elements[(Zi8UInt)tableIndex] = 0x27; } } } } if ((options->countOnly == '\0') && (params->getMode == '\x03')) { - for (tableCount = 0; tableCount < params->count; tableCount = tableCount + 1) { + for (tableIndex = 0; tableIndex < params->count;) { while (*output != 0) { - if (*output == 0x27) { - *output = 0xf360; - output = output + 1; - } - else { - *output = *output | 0xf300; - output = output + 1; + if (*output != 0x27) { + *output++ |= 0xf300; + } else { + *output++ = 0xf360; } } - output = output + 1; + output++; } } Zi8LogError(100,work); - goto returnSpelling; + return totalCandidates; } if (params->getMode == '\x0f') { Zi8LogError(1000,work); - totalCandidates = 0; - goto returnSpelling; + return 0; } Zi8InitDupWordBuf(work); - while (tableCount != 0) { + for (;;) { + if (tableCount == 0) break; spellingEntry = (ziU8 *)Zi8GetTableAddress(1,0xc,work); - for (firstElement = 0; firstElement < tableCount; firstElement = firstElement + 1) { + for (tableIndex = 0; tableIndex < tableCount; tableIndex++) { if ((*spellingEntry & languageMask) != 0) { - if (usePinyin) { - entryLength = *spellingEntry; - } - else { - entryLength = spellingEntry[1]; - } - entryLength = entryLength & 0xf; + if (usePinyin) entryLength = *spellingEntry & 0xf; + else entryLength = spellingEntry[1] & 0xf; if (exactLength) { - if (entryLength == inputLength) { -appendSpelling: - phoneticIndex = (spellingEntry[1] & 0xf0) << 4 | (ziU16)spellingEntry[2]; - phoneticCode = CONCAT11(phoneticTable[(Zi8UInt)phoneticIndex * 2 + 1], - phoneticTable[(Zi8UInt)phoneticIndex * 2]); - if (usePinyin) { - Zi8SpellingPY(output,phoneticCode,0); + if (entryLength != inputLength) goto nextSpelling; + } else { + if (inputLength != 0 && entryLength <= inputLength) goto nextSpelling; + } + phoneticIndex = (((ziU16)spellingEntry[1] & 0xf0) << 4) | spellingEntry[2]; + character = phoneticTable[phoneticIndex * 2] | + ((ziU16)phoneticTable[phoneticIndex * 2 + 1] << 8); + if (usePinyin) phoneticIndex = (ziU8)Zi8SpellingPY(output,character,0); + else phoneticIndex = (ziU8)Zi8SpellingZY(output,character,0); + for (spellingIndex = 0; spellingIndex < inputLength; spellingIndex++) { + if (params->elements[spellingIndex] < 0xf305 && + (ziU16)output[spellingIndex] != params->elements[spellingIndex]) break; + } + if (inputLength == 0 || spellingIndex >= inputLength) { + if (usePinyin) phoneticIndex = (ziU8)Zi8GetPInfo(character,output,8,work); + else phoneticIndex = (ziU8)Zi8GetZInfo(character,output,8,work); + if (phoneticIndex != 0) { + for (spellingIndex = 0; spellingIndex < inputLength; spellingIndex++) { + if (params->elements[spellingIndex] >= 0xf305 && + (ziU16)output[spellingIndex] != params->elements[spellingIndex]) break; } - else { - Zi8SpellingZY(output,phoneticCode,0); - } - for (spellingIndex = 0; - (spellingIndex < inputLength && - ((0xf304 < params->elements[(Zi8UInt)spellingIndex] || - (output[spellingIndex] == params->elements[(Zi8UInt)spellingIndex])) - )); spellingIndex = spellingIndex + 1) { - } - if ((inputLength == 0) || (inputLength <= spellingIndex)) { - if (usePinyin) { - spellingLength = Zi8GetPInfo(phoneticCode,output,8,work); + if (inputLength == 0 || spellingIndex >= inputLength) { + if (phoneticIndex > options->maxSpellingLength) { + phoneticIndex = options->maxSpellingLength; + output[phoneticIndex] = 0; } - else { - spellingLength = Zi8GetZInfo(phoneticCode,output,8,work); + if (((params->getOptions & 0x10) != 0 || + (params->getOptions & 0xe) == 2 || + work->maxWordLength > params->elementCount) && + params->elementCount != 0 && phoneticIndex > params->elementCount) { + phoneticIndex = params->elementCount; + output[phoneticIndex] = 0; } - spellingLength = spellingLength & 0xff; - if (spellingLength != 0) { - for (spellingIndex = 0; - (spellingIndex < inputLength && - ((params->elements[(Zi8UInt)spellingIndex] < 0xf305 || - (output[spellingIndex] == - params->elements[(Zi8UInt)spellingIndex])))); - spellingIndex = spellingIndex + 1) { - } - if ((inputLength == 0) || (inputLength <= spellingIndex)) { - if ((ziU8)options->maxSpellingLength < spellingLength) { - spellingLength = (ziU16)(ziU8)options->maxSpellingLength; - output[spellingLength] = 0; - } - if (((((params->getOptions & 0x10) != 0) || - ((params->getOptions & 0xe) == 2)) || - (params->elementCount < work->maxWordLength)) && - ((params->elementCount != '\0' && (params->elementCount < spellingLength))) - ) { - spellingLength = (ziU16)params->elementCount; - output[spellingLength] = 0; - } - duplicate = Zi8IsDupWordW(output,spellingLength,work); - if (duplicate == '\0') { - if (remaining == 0) { - totalCandidates = totalCandidates + 1; - if (options->countOnly == '\0') { - output = output + spellingLength + 1; - candidateCount = candidateCount + 1; - } - else if (options->maxCount <= (int)totalCandidates) goto finishSpelling; - if (params->maxCandidates <= candidateCount) goto finishSpelling; - } - else { - remaining = remaining + -1; - } - } + if (Zi8IsDupWordW(output,(ziU8)phoneticIndex,work) == 0) { + if (remaining == 0) { + totalCandidates++; + if (options->countOnly == 0) { + output += phoneticIndex + 1; + candidateCount++; + } else if ((int)totalCandidates >= options->maxCount) goto finishSpelling; + if (candidateCount >= params->maxCandidates) goto finishSpelling; + } else { + remaining--; } } } } } - else if ((inputLength == 0) || (inputLength < entryLength)) goto appendSpelling; } - spellingEntry = spellingEntry + 3; +nextSpelling: + spellingEntry += 3; } - if (!exactLength) break; + if (exactLength == false) break; exactLength = false; } } - } - else if (mode < 4) { - if (2 < mode) { -preparePinyinSpelling: - phoneticTable = (ziU8 *)Zi8GetTableAddress(1,3,work); - Zi8GetTableCount(1,3,work); - usePinyin = true; - goto prepareInput; - } - } - else if (mode == 0xf) goto preparePinyinSpelling; finishSpelling: params->count = candidateCount; Zi8LogError(100,work); -returnSpelling: return totalCandidates; } @@ -1059,7 +1036,8 @@ int Zi8Get1KeyPressCandidates(Zi8OneKeyParam *params,Zi8OneKeyOptions *options,Z ziU8 *characterSetTable; ziU8 *phoneticTable; ziU8 *phraseTable; - ziU8 keyMasks [8]; + ziU8 keyValues[4]; + ziU8 keyMasks[4]; int totalCandidates; ziU16 *output; int outputIndex; @@ -1090,6 +1068,8 @@ int Zi8Get1KeyPressCandidates(Zi8OneKeyParam *params,Zi8OneKeyOptions *options,Z ziU16 userOrdinal; ziU16 userCharacter; ziU16 unicodeCharacter; + int index; + ziU8 languageMask; ziU8 characterSet; ziU8 inputLength; @@ -1098,28 +1078,22 @@ int Zi8Get1KeyPressCandidates(Zi8OneKeyParam *params,Zi8OneKeyOptions *options,Z ziU8 elementIndex; ziU8 keyIndex; ziU8 candidateCount; + ziU8 matchFull; + ziU8 includeTone; + ziU8 trackDuplicates; + ziU8 entryFlags; ziU8 phoneticLength; ziU8 wordLength; + ziU8 optionsMask; + ziU8 requireFull; + ziU8 prefixSearch; + ziU8 alternateSearch; + ziU8 emitWords; ziU8 nibble; + ziU8 validPhonetic; 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; @@ -1140,67 +1114,49 @@ int Zi8Get1KeyPressCandidates(Zi8OneKeyParam *params,Zi8OneKeyOptions *options,Z outputLimit = options->candidateBufferSize - 0x40; requireFull = optionsMask & 0x40; prefixSearch = optionsMask & 0x10; + alternateSearch = optionsMask & 0x20; optionsMask = optionsMask & ~0x10; optionsMask = optionsMask & ~0x20; optionsMask = optionsMask & ~0x40; - if (((params->subLanguage & 0x80) == 0) && ((params->subLanguage & 0x40) == 0)) { - if ((params->subLanguage & 8) == 0) { - if (((params->subLanguage & 0x20) != 0) || ((params->subLanguage & 0x10) != 0)) { - languageMask = 2; - } - } - else { - languageMask = 4; - } - } - else { + if ((params->subLanguage & 0x80) != 0 || (params->subLanguage & 0x40) != 0) { languageMask = 1; + } else if ((params->subLanguage & 8) != 0) { + languageMask = 4; + } else if ((params->subLanguage & 0x20) != 0 || (params->subLanguage & 0x10) != 0) { + languageMask = 2; } - if (languageMask == 0) { + if (languageMask != 0) { + if (Zi8GetFormatVersion(1,work) >= 4) characterSetTable = (ziU8 *)Zi8GetTableAddress(1,0x15,work); + else characterSetTable = 0; + if (characterSetTable != 0) characterSet = params->subLanguage; + switch (languageMask) { + case 1: + if ((params->subLanguage & 0x40) != 0 || (Zi8GetZHCharSet(work) & 1) != 0) characterSetTable = 0; + break; + case 2: + if ((params->subLanguage & 0x10) != 0 || (Zi8GetZHCharSet(work) & 0x10) != 0) characterSetTable = 0; + break; + case 4: + if ((params->subLanguage & 0x10) != 0) characterSetTable = 0; + break; + default: + break; + } + } else { languageMask = params->subLanguage; } - else { - mode = Zi8GetFormatVersion(1,work); - if (mode < 4) { - characterSetTable = 0; - } - else { - characterSetTable = (ziU8 *)Zi8GetTableAddress(1,0x15,work); - } - if (characterSetTable != 0) { - characterSet = params->subLanguage; - } - if (languageMask != 3) { - if (languageMask < 3) { - if (languageMask == 1) { - if (((params->subLanguage & 0x40) != 0) || - (wordIndex = Zi8GetZHCharSet(work), (wordIndex & 1) != 0)) { - characterSetTable = 0; - } - } - else if ((languageMask != 0) && - (((params->subLanguage & 0x10) != 0 || - (wordIndex = Zi8GetZHCharSet(work), (wordIndex & 0x10) != 0)))) { - characterSetTable = 0; - } - } - else if ((languageMask < 5) && ((params->subLanguage & 0x10) != 0)) { - characterSetTable = 0; - } - } - } languageMask = languageMask << 4; remaining = params->firstCandidate; params->count = 0; params->letters = 0; inputLength = params->elementCount; if (inputLength != 0) { - do { + while (inputLength != 0) { if (params->elements[(inputLength - 1)] != 0xef09) { break; } - inputLength = inputLength - 1; - } while (inputLength != 0); + inputLength--; + } } index = inputLength; if (inputLength != 0) { @@ -1209,12 +1165,10 @@ int Zi8Get1KeyPressCandidates(Zi8OneKeyParam *params,Zi8OneKeyOptions *options,Z else { inputLimit = 0; } - for (keyIndex = 0; keyIndex < 4; keyIndex = keyIndex + 1) { - keyMasks[keyIndex + 4] = 0; - keyMasks[keyIndex] = 0; + for (keyIndex = 0; keyIndex < 4; keyIndex++) { + keyMasks[keyIndex] = keyValues[keyIndex] = 0; } - for (keyIndex = 1; (index < (int)(Zi8UInt)inputLength && ((Zi8UInt)((int)(Zi8UInt)keyIndex >> 1) < 4)); - keyIndex = keyIndex + 1) { + for (keyIndex = 1; index < inputLength && (int)keyIndex / 2 < 4;) { switch(params->elements[index]) { case 0xef02: nibble = 0; @@ -1243,52 +1197,49 @@ int Zi8Get1KeyPressCandidates(Zi8OneKeyParam *params,Zi8OneKeyOptions *options,Z case 0xef0b: nibble = 8; break; - default: - nibble = 0; - break; case 0xef0a: nibble = 4; + break; + default: + nibble = 0; } - if ((keyIndex & 1) == 0) { - keyMasks[((int)(Zi8UInt)keyIndex >> 1) + 4] = - keyMasks[((int)(Zi8UInt)keyIndex >> 1) + 4] | nibble << 4; + if ((keyIndex & 1) != 0) { + keyValues[(keyIndex >> 1)] |= nibble; if (params->elements[index] == 0xef0b) { - keyMasks[(int)(Zi8UInt)keyIndex >> 1] = keyMasks[(int)(Zi8UInt)keyIndex >> 1] | 0x80; + keyMasks[keyIndex >> 1] |= 8; } else if (params->elements[index] == 0xef0a) { - keyMasks[(int)(Zi8UInt)keyIndex >> 1] = keyMasks[(int)(Zi8UInt)keyIndex >> 1] | 0x40; + keyMasks[keyIndex >> 1] |= 4; } else if (params->elements[index] != 0xef00) { - keyMasks[(int)(Zi8UInt)keyIndex >> 1] = keyMasks[(int)(Zi8UInt)keyIndex >> 1] | 0x70; + keyMasks[keyIndex >> 1] |= 7; } - } - else { - keyMasks[((int)(Zi8UInt)keyIndex >> 1) + 4] = - keyMasks[((int)(Zi8UInt)keyIndex >> 1) + 4] | nibble; + } else { + keyValues[(keyIndex >> 1)] |= nibble << 4; if (params->elements[index] == 0xef0b) { - keyMasks[(int)(Zi8UInt)keyIndex >> 1] = keyMasks[(int)(Zi8UInt)keyIndex >> 1] | 8; + keyMasks[keyIndex >> 1] |= 0x80; } else if (params->elements[index] == 0xef0a) { - keyMasks[(int)(Zi8UInt)keyIndex >> 1] = keyMasks[(int)(Zi8UInt)keyIndex >> 1] | 4; + keyMasks[keyIndex >> 1] |= 0x40; } else if (params->elements[index] != 0xef00) { - keyMasks[(int)(Zi8UInt)keyIndex >> 1] = keyMasks[(int)(Zi8UInt)keyIndex >> 1] | 7; + keyMasks[keyIndex >> 1] |= 0x70; } } - index = index + 1; + keyIndex++; + index++; } keyIndex--; syllableTable = (ziU8 *)Zi8GetTableAddress(1,0,work); ordinalCount = Zi8GetTableCount(1,0,work); alternateTable = (ziU8 *)Zi8GetTableAddress(1,5,work); phoneticMask = Zi8GetTableCount(1,5,work); - if ((((params->context & 0x40) != 0) && - (result = Zi8GetFormatVersion(1,work), result != '\0')) && - (characterMask = Zi8GetTableCount(1,0xf,work), characterMask != 0)) { - ordinalCount = characterMask; + if ((params->context & 0x40) != 0 && Zi8GetFormatVersion(1,work) >= 1) { + characterMask = Zi8GetTableCount(1,0xf,work); + if (characterMask != 0) ordinalCount = characterMask; } if (((params->context & 0x80) != 0) && (params->scratch != 0)) { - Zi8Memset(params->scratch,0,(int)(ordinalCount + 7) >> 3); + Zi8Memset(params->scratch,0,(ordinalCount + 7) / 8); trackDuplicates = true; } if ((params->context & 0x10) != 0) { @@ -1296,17 +1247,19 @@ int Zi8Get1KeyPressCandidates(Zi8OneKeyParam *params,Zi8OneKeyOptions *options,Z Zi8InitDupWordBuf(work); emitWords = true; } - mode = params->getMode; - if (mode == 4) { - phoneticTable = (ziU8 *)Zi8GetTableAddress(1,4,work); - alternateCount = Zi8GetTableCount(1,4,work); - tone = 0; - } - else { - if ((3 < mode) || (mode < 3)) goto finishCandidates; + switch (params->getMode) { + case 3: phoneticTable = (ziU8 *)Zi8GetTableAddress(1,3,work); alternateCount = Zi8GetTableCount(1,3,work); tone = 1; + break; + case 4: + phoneticTable = (ziU8 *)Zi8GetTableAddress(1,4,work); + alternateCount = Zi8GetTableCount(1,4,work); + tone = 0; + break; + default: + goto finishCandidates; } if ((params->context & 0xf) == 2) { ordinalTable = (ziU8 *)Zi8GetTableAddress(1,8,work); @@ -1320,355 +1273,291 @@ int Zi8Get1KeyPressCandidates(Zi8OneKeyParam *params,Zi8OneKeyOptions *options,Z params->wordCandidates = 0; goto finishCandidates; } - for (index = 0; index < (int)(Zi8UInt)inputLimit; index = index + 1) { + for (index = 0; index < (int)(Zi8UInt)inputLimit; index++) { spelling[index] = params->elements[index]; } work->phoneticFilter = 0; if (inputLimit != 0) { - entryFlags = false; + validPhonetic = false; work->phoneticFilter = 1; Zi8Memset(work->phoneticEnabled,0,0x200); - for (phoneticIndex = 0; index = (int)phoneticIndex, index < (int)(Zi8UInt)alternateCount; phoneticIndex = phoneticIndex + 1) { - phoneticCode = CONCAT11(phoneticTable[(int)(phoneticIndex << 1) + 1], - phoneticTable[(int)(phoneticIndex << 1)]); - result = Zi8IsMatch1Key(spelling,inputLimit,phoneticCode,0,tone,0); - if (result == '\0') { + for (index = 0; index < alternateCount; index++) { + phoneticCode = phoneticTable[index * 2] | ((ziU16)phoneticTable[index * 2 + 1] << 8); + if ((ziU8)Zi8IsMatch1Key(spelling,inputLimit,phoneticCode,(ziU8)0,tone,(ziU8)0) == 0) { work->phoneticEnabled[index] = 0; } else { work->phoneticEnabled[index] = 1; - entryFlags = true; + validPhonetic = true; } } - if (!entryFlags) goto finishCandidates; + if (!validPhonetic) goto finishCandidates; } if ((((options->countOnly == '\0') || (optionsMask == 5)) && - ((optionsMask != 5 || ((ziS8)params->wordCharCount != '\0')))) && - (((ziS8)params->wordCharCount == '\0' || - (result = Zi8IsCharacter(params->currentWord[0],work), result != '\0')))) { + ((optionsMask != 5 || (params->wordCharCount != '\0')))) && + ((params->wordCharCount == '\0' || + Zi8IsCharacter(params->currentWord[0],work) != 0))) { phoneticLength = 0; -nextOEMword: - do { - do { - do { - result = Zi8MatchOEMdata(params->currentWord,params->wordCharCount,1 - ,wordBuffer,0x40,0,phoneticLength,work); - if (result == '\0') goto searchUserWords; - phoneticLength = 1; - candidateCharacter = wordBuffer[params->wordCharCount]; - } while ((candidateCharacter == previousCharacter) || - (result = Zi8IsCharacter(candidateCharacter,work), result == '\0')); - previousCharacter = candidateCharacter; - candidateOrdinal = Zi8Uni2Ord(candidateCharacter,work); - phraseTable = syllableTable + (Zi8UInt)candidateOrdinal * 0xc; - entryFlags = false; - if (keyIndex != 1) { - for (index = 0; index < 4; index = index + 1) { - if (keyMasks[index + 4] != (keyMasks[index] & phraseTable[index])) { - entryFlags = true; - break; - } + while (Zi8MatchOEMdata(params->currentWord,params->wordCharCount,1, + wordBuffer,0x40,0,phoneticLength,work) != 0) { + phoneticLength = 1; + candidateCharacter = wordBuffer[params->wordCharCount]; + if (candidateCharacter == previousCharacter) continue; + if (Zi8IsCharacter(candidateCharacter,work) == 0) continue; + previousCharacter = candidateCharacter; + candidateOrdinal = Zi8Uni2Ord(candidateCharacter,work); + phraseTable = syllableTable + candidateOrdinal * 12; + entryFlags = false; + if (keyIndex != 0) { + for (index = 0; index < 4; index++) { + if (keyValues[index] != (keyMasks[index] & phraseTable[index])) { + entryFlags = true; + break; } } - } while (entryFlags); - character = Zi8GetPCode(phoneticTable,phraseTable); - elementIndex = Zi8IsMatch1Key(spelling,inputLimit,character,matchFull,tone,includeTone); - if (((elementIndex == '\0') && (requireFull == 0)) && ((*phraseTable & 0x80) != 0)) { - elementIndex = MatchAltSound1Key(spelling,inputLimit,matchFull,(Zi8AltSoundRecord *)alternateTable,phoneticMask,phoneticTable,candidateOrdinal, - tone,includeTone,languageMask,work); } - } while (elementIndex == '\0'); - if (emitWords) { - wordLength = 0; - for (wordIndex = (Zi8UInt)params->wordCharCount; wordBuffer[wordIndex] != 0; wordIndex = wordIndex + 1) { - wordLength = wordLength + 1; + if (entryFlags) continue; + elementIndex = Zi8IsMatch1Key(spelling,inputLimit, + Zi8GetPCode(phoneticTable,phraseTable),matchFull,tone,includeTone); + if (elementIndex == 0 && requireFull == 0 && (*phraseTable & 0x80) != 0) { + elementIndex = MatchAltSound1Key(spelling,inputLimit,matchFull, + (Zi8AltSoundRecord *)alternateTable,phoneticMask,phoneticTable, + candidateOrdinal,tone,includeTone,languageMask,work); } - if ((prefixSearch != 0) || ((ziS8)params->elementCount != '\0')) { - wordLength = 1; - } - result = Zi8IsDupWordW(wordBuffer + params->wordCharCount,wordLength,work); - if (result != '\0') goto nextOEMword; - wordBuffer[(Zi8UInt)params->wordCharCount + (Zi8UInt)wordLength] = 0; - } - else { - if ((trackDuplicates) && - (result = Zi8SetFindCand(params->scratch,candidateOrdinal,work), result != '\0') - ) goto nextOEMword; - for (index = 0; - (index < (int)(Zi8UInt)candidateCount && (candidateCharacter != output[index])); - index = index + 1) { - } - if (index < (int)(Zi8UInt)candidateCount) goto nextOEMword; - } - if (optionsMask == 5) { - totalCandidates = totalCandidates + 1; - if (options->maxCount <= totalCandidates) goto finishCandidates; - } - else if (remaining == 0) { - totalCandidates = totalCandidates + 1; - candidateCount = candidateCount + 1; - if (emitWords) { - for (wordIndex = (Zi8UInt)params->wordCharCount; wordBuffer[wordIndex] != 0; wordIndex = wordIndex + 1) { - output[outputIndex] = wordBuffer[wordIndex]; - outputIndex = outputIndex + 1; + if (elementIndex == 0) continue; + if (!emitWords) { + if (trackDuplicates && Zi8SetFindCand(params->scratch,candidateOrdinal,work) != 0) continue; + for (index = 0; index < candidateCount; index++) { + if (candidateCharacter == output[index]) break; } - output[outputIndex] = 0x20; + if (index < candidateCount) continue; + } else { + wordLength = 0; + for (index = params->wordCharCount; wordBuffer[index] != 0;) { + index++; + wordLength++; + } + if (prefixSearch != 0 || params->elementCount != 0) wordLength = 1; + if (Zi8IsDupWordW(wordBuffer + params->wordCharCount,wordLength,work) != 0) continue; + wordBuffer[params->wordCharCount + wordLength] = 0; } - else { - output[outputIndex] = candidateCharacter; + if (optionsMask == 5) { + totalCandidates++; + if (totalCandidates >= options->maxCount) goto finishCandidates; + } else if (remaining == 0) { + totalCandidates++; + candidateCount++; + if (emitWords) { + for (index = params->wordCharCount; wordBuffer[index] != 0; index++) { + output[outputIndex++] = wordBuffer[index]; + } + output[outputIndex++] = 0x20; + } else { + output[outputIndex++] = candidateCharacter; + } + if (candidateCount >= params->maxCandidates || outputIndex > outputLimit) { + params->wordCandidates = candidateCount; + goto finishCandidates; + } + } else { + remaining--; } - outputIndex = outputIndex + 1; - if ((params->maxCandidates <= candidateCount) || (outputLimit < outputIndex)) goto finishOEMwords; } - else { - remaining = remaining + -1; - } - goto nextOEMword; } -searchUserWords: - if ((((options->countOnly == '\0') || (optionsMask == 5)) && ((ziS8)params->wordCharCount != '\0')) && - (result = Zi8IsCharacter(params->currentWord[0],work), result != '\0')) { + if ((((options->countOnly == '\0') || (optionsMask == 5)) && (params->wordCharCount != '\0')) && + Zi8IsCharacter(params->currentWord[0],work) != 0) { phoneticLength = 0; -nextUserWord: - do { - do { - do { - wordIndex = Zi8MatchPUDdata(params->currentWord,params->wordCharCount,1, - wordBuffer,0x40,0,phoneticLength,work); - if ((wordIndex & 0xff) == 0) goto searchPhrases; - phoneticLength = 1; - wordBuffer[wordIndex & 0xff] = 0; - candidateCharacter = wordBuffer[params->wordCharCount]; - } while (candidateCharacter == previousCharacter); - previousCharacter = candidateCharacter; - candidateOrdinal = Zi8Uni2Ord(candidateCharacter,work); - phraseTable = syllableTable + (Zi8UInt)candidateOrdinal * 0xc; - entryFlags = false; - if (keyIndex != 1) { - for (index = 0; index < 4; index = index + 1) { - if (keyMasks[index + 4] != (keyMasks[index] & phraseTable[index])) { - entryFlags = true; - break; - } + while ((index = Zi8MatchPUDdata(params->currentWord,params->wordCharCount,1, + wordBuffer,0x40,0,phoneticLength,work)) != 0) { + phoneticLength = 1; + wordBuffer[index] = 0; + candidateCharacter = wordBuffer[params->wordCharCount]; + if (candidateCharacter == previousCharacter) continue; + previousCharacter = candidateCharacter; + candidateOrdinal = Zi8Uni2Ord(candidateCharacter,work); + phraseTable = syllableTable + candidateOrdinal * 12; + entryFlags = false; + if (keyIndex != 0) { + for (index = 0; index < 4; index++) { + if (keyValues[index] != (keyMasks[index] & phraseTable[index])) { + entryFlags = true; + break; } } - } while (entryFlags); - character = Zi8GetPCode(phoneticTable,phraseTable); - elementIndex = Zi8IsMatch1Key(spelling,inputLimit,character,matchFull,tone,includeTone); - if (((elementIndex == '\0') && (requireFull == 0)) && ((*phraseTable & 0x80) != 0)) { - elementIndex = MatchAltSound1Key(spelling,inputLimit,matchFull,(Zi8AltSoundRecord *)alternateTable,phoneticMask,phoneticTable,candidateOrdinal, - tone,includeTone,languageMask,work); } - } while (elementIndex == '\0'); - if (emitWords) { - wordLength = 0; - for (wordIndex = (Zi8UInt)params->wordCharCount; wordBuffer[wordIndex] != 0; wordIndex = wordIndex + 1) { - wordLength = wordLength + 1; + if (entryFlags) continue; + elementIndex = Zi8IsMatch1Key(spelling,inputLimit, + Zi8GetPCode(phoneticTable,phraseTable),matchFull,tone,includeTone); + if (elementIndex == 0 && requireFull == 0 && (*phraseTable & 0x80) != 0) { + elementIndex = MatchAltSound1Key(spelling,inputLimit,matchFull, + (Zi8AltSoundRecord *)alternateTable,phoneticMask,phoneticTable, + candidateOrdinal,tone,includeTone,languageMask,work); } - if ((prefixSearch != 0) || ((ziS8)params->elementCount != '\0')) { - wordLength = 1; - } - result = Zi8IsDupWordW(wordBuffer + params->wordCharCount,wordLength,work); - if (result != '\0') goto nextUserWord; - wordBuffer[(Zi8UInt)params->wordCharCount + (Zi8UInt)wordLength] = 0; - } - else { - if ((trackDuplicates) && - (result = Zi8SetFindCand(params->scratch,candidateOrdinal,work), result != '\0') - ) goto nextUserWord; - for (index = 0; - (index < (int)(Zi8UInt)candidateCount && (candidateCharacter != output[index])); - index = index + 1) { - } - if (index < (int)(Zi8UInt)candidateCount) goto nextUserWord; - } - if (optionsMask == 5) { - totalCandidates = totalCandidates + 1; - if (options->maxCount <= totalCandidates) goto finishCandidates; - } - else if (remaining == 0) { - totalCandidates = totalCandidates + 1; - candidateCount = candidateCount + 1; - if (emitWords) { - for (wordIndex = (Zi8UInt)params->wordCharCount; wordBuffer[wordIndex] != 0; wordIndex = wordIndex + 1) { - output[outputIndex] = wordBuffer[wordIndex]; - outputIndex = outputIndex + 1; + if (elementIndex == 0) continue; + if (!emitWords) { + if (trackDuplicates && Zi8SetFindCand(params->scratch,candidateOrdinal,work) != 0) continue; + for (index = 0; index < candidateCount; index++) { + if (candidateCharacter == output[index]) break; } - output[outputIndex] = 0x20; + if (index < candidateCount) continue; + } else { + wordLength = 0; + for (index = params->wordCharCount; wordBuffer[index] != 0;) { + index++; + wordLength++; + } + if (prefixSearch != 0 || params->elementCount != 0) wordLength = 1; + if (Zi8IsDupWordW(wordBuffer + params->wordCharCount,wordLength,work) != 0) continue; + wordBuffer[params->wordCharCount + wordLength] = 0; } - else { - output[outputIndex] = candidateCharacter; + if (optionsMask == 5) { + totalCandidates++; + if (totalCandidates >= options->maxCount) goto finishCandidates; + } else if (remaining == 0) { + totalCandidates++; + candidateCount++; + if (emitWords) { + for (index = params->wordCharCount; wordBuffer[index] != 0; index++) { + output[outputIndex++] = wordBuffer[index]; + } + output[outputIndex++] = 0x20; + } else { + output[outputIndex++] = candidateCharacter; + } + if (candidateCount >= params->maxCandidates || outputIndex > outputLimit) { + params->wordCandidates = candidateCount; + goto finishCandidates; + } + } else { + remaining--; } - outputIndex = outputIndex + 1; - if ((params->maxCandidates <= candidateCount) || (outputLimit < outputIndex)) goto finishUserWords; } - else { - remaining = remaining + -1; - } - goto nextUserWord; } -searchPhrases: if ((((options->countOnly == '\0') || (optionsMask == 5)) && (tableCursor == 0)) && - (((ziS8)params->wordCharCount != '\0' && - (result = Zi8IsCharacter(params->currentWord[0],work), result != '\0')))) { + ((params->wordCharCount != '\0' && + Zi8IsCharacter(params->currentWord[0],work) != 0))) { firstOrdinal = Zi8Uni2Ord(params->currentWord[0],work); if (firstOrdinal != 0xffff) { phraseTable = syllableTable + (Zi8UInt)firstOrdinal * 0xc; - index = Zi8GetTableAddress(1,1,work); - phraseEntries = (ziU8 *)(index + ((phraseTable[9] & 0xf) << 0x10 | (Zi8UInt)((Zi8PhraseRecord *)phraseTable)->phraseOffset)); - if ((ziS8)work->phraseEnabled != '\0') { - mode = *phraseEntries & 7; - if (mode == 5) { - phraseEntries = phraseEntries + 4; - } - else if (mode < 5) { - if (mode == 2) { - phraseEntries = phraseEntries + 2; - } - else { - if (mode < 2) goto skipPhraseHeader; - phraseEntries = phraseEntries + 3; - } - } - else { -skipPhraseHeader: - phraseEntries = phraseEntries + 1; + phraseEntries = (ziU8 *)Zi8GetTableAddress(1,1,work); + phraseEntries += ((phraseTable[9] & 0xf) << 16) | (phraseTable[11] | (phraseTable[10] << 8)); + if (work->phraseEnabled != '\0') { + switch (*phraseEntries & 7) { + case 2: phraseEntries += 2; break; + case 3: + case 4: phraseEntries += 3; break; + case 5: phraseEntries += 4; break; + default: phraseEntries++; break; } } - if ((*phraseEntries & 0x80) == 0) { - entryRemaining = 0x80; - } - else { + if ((*phraseEntries & 0x80) != 0) { entryRemaining = 0; phraseEntries = phraseEntries + ((int)(*phraseEntries & 0x7f) >> 4) + 1; + } else { + entryRemaining = 0x80; } while ((entryRemaining & 0x80) == 0) { - recordCursor = phraseEntries + 1; - entryRemaining = *phraseEntries; + entryRemaining = *phraseEntries++; contextIndex = entryRemaining & 0xf; - phraseEntries = recordCursor; if ((entryRemaining & languageMask) == 0) { - for (; contextIndex != 0; contextIndex = contextIndex - 1) { - for (phraseEntries = phraseEntries + 1; (*phraseEntries & 0x80) == 0; phraseEntries = phraseEntries + 2) { + for (; contextIndex != 0; contextIndex--) { + for (phraseEntries++; (*phraseEntries & 0x80) == 0; phraseEntries += 2) { } - phraseEntries = phraseEntries + 1; + phraseEntries++; } } - for (; contextIndex != 0; contextIndex = contextIndex - 1) { + for (; contextIndex != 0; contextIndex--) { phoneticCount = 0; currentWord = params->currentWord; - contextRemaining = params->wordCharCount; - do { - contextRemaining = contextRemaining + -1; - if (contextRemaining == '\0') break; - recordCursor = phraseEntries + 1; - phoneticCount = CONCAT11(*recordCursor,*phraseEntries); - phraseEntries = phraseEntries + 2; - if ((*recordCursor & 0x80) != 0) break; - contextCharacter = Zi8Ord2Uni(phoneticCount,work); - currentWord = currentWord + 1; - } while (*currentWord == contextCharacter); - if (contextRemaining == '\0') { - phoneticCount = CONCAT11(phraseEntries[1],*phraseEntries); + contextRemaining = params->wordCharCount - 1; + while (contextRemaining != 0) { + phoneticCount = ((ziU16)phraseEntries[1] << 8) | *phraseEntries; + phraseEntries += 2; + if ((phoneticCount & 0x8000) != 0) break; + if (*++currentWord != Zi8Ord2Uni(phoneticCount,work)) break; + contextRemaining--; + } + if (contextRemaining == 0) { + phoneticCount = ((ziU16)phraseEntries[1] << 8) | *phraseEntries; entryCursor = phraseEntries; - recordCursor = phraseEntries + 2; + phraseEntries += 2; if (characterSetTable != 0) { index = 0; - while( true ) { - phraseCharacter = CONCAT11(phraseEntries[index + 1],phraseEntries[index]); - if ((characterSet & characterSetTable[phraseCharacter & 0x7fff]) == 0) break; - if ((phraseEntries[index + 1] & 0x80) != 0) goto finishPhraseContext; - index = index + 2; + while (true) { + phraseCharacter = ((ziU16)entryCursor[index + 1] << 8) | entryCursor[index]; + if ((characterSet & characterSetTable[phraseCharacter & 0x7fff]) == 0) { + phraseCharacter = 0; + break; + } + if ((phraseCharacter & 0x8000) != 0) break; + index += 2; } - phraseCharacter = 0; -finishPhraseContext: - phraseEntries = recordCursor; if ((phraseCharacter & 0x8000) == 0) goto nextPhrase; } phraseCharacter = phoneticCount & 0x7fff; - phraseEntries = recordCursor; - firstOrdinal = Zi8Ord2Uni(phraseCharacter,work); + firstOrdinal = Zi8Ord2Uni(phraseCharacter,work); phraseTable = syllableTable + (Zi8UInt)phraseCharacter * 0xc; - if (keyIndex != 1) { - for (index = 0; index < 4; index = index + 1) { - if (keyMasks[index + 4] != (keyMasks[index] & phraseTable[index])) goto nextPhrase; + if (keyIndex != 0) { + for (index = 0; index < 4; index++) { + if (keyValues[index] != (keyMasks[index] & phraseTable[index])) goto nextPhrase; } } entryFlags = false; - if (((ziS8)work->phoneticFilter != '\0') && - (tableIndex = (ziU16)phraseTable[8] << 1 | (ziU16)((int)(phraseTable[9] & 0x80) >> 7), - work->phoneticEnabled[(Zi8UInt)tableIndex] == '\0')) { - entryFlags = true; + if (work->phoneticFilter != 0) { + tableIndex = (ziU16)phraseTable[8] << 1 | (((ziU16)phraseTable[9] & 0x80) >> 7); + if (work->phoneticEnabled[tableIndex] == 0) entryFlags = true; } - if (entryFlags) { - elementIndex = '\0'; - } - else { - character = Zi8GetPCode(phoneticTable,phraseTable); - elementIndex = Zi8IsMatch1Key(spelling,inputLimit,character,matchFull,tone,includeTone); + if (!entryFlags) { + elementIndex = Zi8IsMatch1Key(spelling,inputLimit,Zi8GetPCode(phoneticTable,phraseTable),matchFull,tone,includeTone); + } else { + elementIndex = 0; } if (((elementIndex == '\0') && (requireFull == 0)) && ((*phraseTable & 0x80) != 0)) { elementIndex = MatchAltSound1Key(spelling,inputLimit,matchFull,(Zi8AltSoundRecord *)alternateTable,phoneticMask,phoneticTable, phraseCharacter,tone,includeTone,languageMask,work); } - if (elementIndex != '\0') { + if (elementIndex == 0) goto nextPhrase; + if (!emitWords) { + if (trackDuplicates && Zi8SetFindCand(params->scratch,phraseCharacter,work) != 0) goto nextPhrase; + for (index = 0; index < candidateCount; index++) { + if (firstOrdinal == output[index]) goto nextPhrase; + } + } else { + wordLength = 0; + do { + phraseCharacter = ((ziU16)entryCursor[1] << 8) | *entryCursor; + entryCursor += 2; + output[outputIndex + wordLength++] = Zi8Ord2Uni(phraseCharacter & 0x7fff,work); + } while ((phraseCharacter & 0x8000) == 0); + if (prefixSearch != 0 || params->elementCount != 0) wordLength = 1; + if (Zi8IsDupWordW(output + outputIndex,wordLength,work) != 0) goto nextPhrase; + output[outputIndex + wordLength] = 0; + } + if (optionsMask == 5) { + totalCandidates++; + if (totalCandidates >= options->maxCount) goto finishCandidates; + } else if (remaining == 0) { + totalCandidates++; + candidateCount++; if (emitWords) { - wordLength = 0; - do { - phraseCharacter = CONCAT11(entryCursor[1],*entryCursor); - entryCursor = entryCursor + 2; - character = Zi8Ord2Uni(phraseCharacter & 0x7fff,work); - wordIndex = (Zi8UInt)wordLength; - wordLength = wordLength + 1; - output[(outputIndex + wordIndex)] = character; - } while ((phraseCharacter & 0x8000) == 0); - if ((prefixSearch != 0) || ((ziS8)params->elementCount != '\0')) { - wordLength = 1; - } - result = Zi8IsDupWordW(output + outputIndex,wordLength,work); - if (result == '\0') { - output[(outputIndex + (Zi8UInt)wordLength)] = 0; - goto appendPhrase; - } + outputIndex += wordLength; + output[outputIndex++] = 0x20; + } else { + output[outputIndex++] = firstOrdinal; } - else if ((!trackDuplicates) || - (result = Zi8SetFindCand(params->scratch,phraseCharacter,work), - result == '\0')) { - for (index = 0; index < (int)(Zi8UInt)candidateCount; index = index + 1) { - if (firstOrdinal == output[index]) goto nextPhrase; - } -appendPhrase: - if (optionsMask == 5) { - totalCandidates = totalCandidates + 1; - if (options->maxCount <= totalCandidates) goto finishCandidates; - } - else if (remaining == 0) { - totalCandidates = totalCandidates + 1; - candidateCount = candidateCount + 1; - if (emitWords) { - outputIndex = outputIndex + (Zi8UInt)wordLength; - output[outputIndex] = 0x20; - } - else { - output[outputIndex] = firstOrdinal; - } - outputIndex = outputIndex + 1; - if ((params->maxCandidates <= candidateCount) || (outputLimit < outputIndex)) { - params->wordCandidates = candidateCount; - goto finishCandidates; - } - } - else { - remaining = remaining + -1; - } + if (candidateCount >= params->maxCandidates || outputIndex > outputLimit) { + params->wordCandidates = candidateCount; + goto finishCandidates; } + } else { + remaining--; } } nextPhrase: if ((phoneticCount & 0x8000) == 0) { - for (phraseEntries = phraseEntries + 1; (*phraseEntries & 0x80) == 0; phraseEntries = phraseEntries + 2) { + for (phraseEntries++; (*phraseEntries & 0x80) == 0; phraseEntries = phraseEntries + 2) { } - phraseEntries = phraseEntries + 1; + phraseEntries++; } } } @@ -1677,239 +1566,183 @@ nextPhrase: } else { finishPhrases: - if ((ziS8)params->wordCharCount != '\0') { + if (params->wordCharCount != '\0') { params->wordCandidates = candidateCount; } } if ((options->countOnly == '\0') && (tableCursor != 0)) { - for (ordinalIndex = 0; ordinalIndex < tableCursor; ordinalIndex = ordinalIndex + 1) { + for (ordinalIndex = 0; ordinalIndex < tableCursor; ordinalIndex++) { ordinal = (ziU16)ordinalTable[(Zi8UInt)ordinalIndex * 2] * 0x100 + (ziU16)ordinalTable[(Zi8UInt)ordinalIndex * 2 + 1]; phraseTable = syllableTable + (Zi8UInt)ordinal * 0xc; if (((*phraseTable & languageMask) != 0) && ((characterSetTable == 0 || ((characterSet & characterSetTable[(Zi8UInt)ordinal]) != 0)))) { - if (keyIndex != 1) { - for (index = 0; - (index < 4 && (keyMasks[index + 4] == (keyMasks[index] & phraseTable[index]))); - index = index + 1) { + if (keyIndex != 0) { + for (index = 0; index < 4; index++) { + if (keyValues[index] != (keyMasks[index] & phraseTable[index])) break; } if (index < 4) goto nextSortedOrdinal; } entryFlags = false; - if (((ziS8)work->phoneticFilter != '\0') && - (tableIndex = (ziU16)phraseTable[8] << 1 | (ziU16)((int)(phraseTable[9] & 0x80) >> 7), - work->phoneticEnabled[(Zi8UInt)tableIndex] == '\0')) { - entryFlags = true; + if (work->phoneticFilter != 0) { + tableIndex = (ziU16)phraseTable[8] << 1 | (((ziU16)phraseTable[9] & 0x80) >> 7); + if (work->phoneticEnabled[tableIndex] == 0) entryFlags = true; } - if (entryFlags) { - elementIndex = '\0'; - } - else { - character = Zi8GetPCode(phoneticTable,phraseTable); - elementIndex = Zi8IsMatch1Key(spelling,inputLimit,character,matchFull,tone,includeTone); + if (!entryFlags) { + elementIndex = Zi8IsMatch1Key(spelling,inputLimit,Zi8GetPCode(phoneticTable,phraseTable),matchFull,tone,includeTone); + } else { + elementIndex = 0; } if (((elementIndex == '\0') && (requireFull == 0)) && ((syllableTable[(Zi8UInt)ordinal * 0xc] & 0x80) != 0)) { elementIndex = MatchAltSound1Key(spelling,inputLimit,matchFull,(Zi8AltSoundRecord *)alternateTable,phoneticMask,phoneticTable,ordinal, tone,includeTone,languageMask,work); } - if (elementIndex != '\0') { - if (emitWords) { - ordinal = Zi8Ord2Uni(ordinal,work); - result = Zi8IsDupWordW(&ordinal,1,work); - if (result == '\0') { -appendSortedOrdinal: - if (remaining == 0) { - totalCandidates = totalCandidates + 1; - if (options->countOnly == '\0') { - candidateCount = candidateCount + 1; - output[outputIndex] = ordinal; - index = outputIndex + 1; - if (emitWords) { - output[(outputIndex + 1)] = 0x20; - index = outputIndex + 2; - } - } - else { - index = outputIndex; - if (options->maxCount <= totalCandidates) goto finishCandidates; - } - outputIndex = index; - if ((params->maxCandidates <= candidateCount) || (outputLimit < outputIndex)) - goto finishCandidates; - } - else { - remaining = remaining + -1; - } - } + if (elementIndex == 0) goto nextSortedOrdinal; + if (!emitWords) { + if (trackDuplicates && Zi8SetFindCand(params->scratch,ordinal,work) != 0) goto nextSortedOrdinal; + ordinal = Zi8Ord2Uni(ordinal,work); + for (index = 0; index < candidateCount; index++) { + if (ordinal == output[index]) break; } - else if ((!trackDuplicates) || - (result = Zi8SetFindCand(params->scratch,ordinal,work), - result == '\0')) { - ordinal = Zi8Ord2Uni(ordinal,work); - for (index = 0; - (index < (int)(Zi8UInt)candidateCount && (ordinal != output[index])); - index = index + 1) { - } - if ((int)(Zi8UInt)candidateCount <= index) goto appendSortedOrdinal; + if (index < candidateCount) goto nextSortedOrdinal; + } else { + ordinal = Zi8Ord2Uni(ordinal,work); + if (Zi8IsDupWordW(&ordinal,1,work) != 0) goto nextSortedOrdinal; + } + if (remaining == 0) { + totalCandidates++; + if (options->countOnly == 0) { + candidateCount++; + output[outputIndex++] = ordinal; + if (emitWords) output[outputIndex++] = 0x20; + } else { + if (totalCandidates >= options->maxCount) goto finishCandidates; } + if (candidateCount >= params->maxCandidates || outputIndex > outputLimit) goto finishCandidates; + } else { + remaining--; } } nextSortedOrdinal: ; } } - if ((options->countOnly == '\0') && (result = Zi8GetZHuwdPtr(&userEntries,&userCount,work), result != '\0')) + if ((options->countOnly == '\0') && Zi8GetZHuwdPtr(&userEntries,&userCount,work) != 0) { - for (phraseOrdinal = 0; phraseOrdinal < userCount; phraseOrdinal = phraseOrdinal + 1) { - if (((ziS8)params->elementCount == '\0') || ((userEntries[1] & 0x80) != 0)) { + for (phraseOrdinal = 0; phraseOrdinal < userCount;) { + if ((params->elementCount == '\0') || ((userEntries[1] & 0x80) != 0)) { userOrdinal = (userEntries[1] & 0x7f) << 8 | (ziU16)userEntries[2]; phraseTable = syllableTable + (Zi8UInt)userOrdinal * 0xc; if (((*phraseTable & languageMask) != 0) && ((characterSetTable == 0 || ((characterSet & characterSetTable[(Zi8UInt)userOrdinal]) != 0)))) { - if (keyIndex != 1) { + if (keyIndex != 0) { entryFlags = false; - for (duplicateIndex = 0; duplicateIndex < 4; duplicateIndex = duplicateIndex + 1) { - if (keyMasks[duplicateIndex + 4] != (keyMasks[duplicateIndex] & phraseTable[duplicateIndex])) { + for (duplicateIndex = 0; duplicateIndex < 4; duplicateIndex++) { + if (keyValues[duplicateIndex] != (keyMasks[duplicateIndex] & phraseTable[duplicateIndex])) { entryFlags = true; break; } } if (entryFlags) goto nextUserOrdinal; } - character = Zi8GetPCode(phoneticTable,phraseTable); - elementIndex = Zi8IsMatch1Key(spelling,inputLimit,character,matchFull,tone,includeTone); + elementIndex = Zi8IsMatch1Key(spelling,inputLimit,Zi8GetPCode(phoneticTable,phraseTable),matchFull,tone,includeTone); if (((elementIndex == '\0') && (requireFull == 0)) && ((*phraseTable & 0x80) != 0)) { elementIndex = MatchAltSound1Key(spelling,inputLimit,matchFull,(Zi8AltSoundRecord *)alternateTable,phoneticMask,phoneticTable,userOrdinal, tone,includeTone,languageMask,work); } - if (elementIndex != '\0') { - if (emitWords) { - userCharacter = Zi8Ord2Uni(userOrdinal,work); - result = Zi8IsDupWordW(&userCharacter,1,work); - if (result == '\0') { -appendUserOrdinal: - if (remaining == 0) { - totalCandidates = totalCandidates + 1; - candidateCount = candidateCount + 1; - output[outputIndex] = userCharacter; - index = outputIndex + 1; - if (emitWords) { - output[(outputIndex + 1)] = 0x20; - index = outputIndex + 2; - } - outputIndex = index; - if ((params->maxCandidates <= candidateCount) || (outputLimit < outputIndex)) - goto finishCandidates; - } - else { - remaining = remaining + -1; - } - } - } - else if ((!trackDuplicates) || - (result = Zi8SetFindCand(params->scratch,userOrdinal,work), - result == '\0')) { - userCharacter = Zi8Ord2Uni(userOrdinal,work); - for (duplicateIndex = 0; - (duplicateIndex < (int)(Zi8UInt)candidateCount && - (userCharacter != output[duplicateIndex])); duplicateIndex = duplicateIndex + 1) { - } - if ((int)(Zi8UInt)candidateCount <= duplicateIndex) goto appendUserOrdinal; + if (elementIndex == 0) goto nextUserOrdinal; + if (!emitWords) { + if (trackDuplicates && Zi8SetFindCand(params->scratch,userOrdinal,work) != 0) goto nextUserOrdinal; + userCharacter = Zi8Ord2Uni(userOrdinal,work); + for (duplicateIndex = 0; duplicateIndex < candidateCount; duplicateIndex++) { + if (userCharacter == output[duplicateIndex]) break; } + if (duplicateIndex < candidateCount) goto nextUserOrdinal; + } else { + userCharacter = Zi8Ord2Uni(userOrdinal,work); + if (Zi8IsDupWordW(&userCharacter,1,work) != 0) goto nextUserOrdinal; + } + if (remaining == 0) { + totalCandidates++; + candidateCount++; + output[outputIndex++] = userCharacter; + if (emitWords) output[outputIndex++] = 0x20; + if (candidateCount >= params->maxCandidates || outputIndex > outputLimit) goto finishCandidates; + } else { + remaining--; } } } nextUserOrdinal: + phraseOrdinal++; userEntries = userEntries + 3; } } phraseTable = syllableTable; previousCharacter = 0; - for (ordinal = 0; ordinal < ordinalCount; ordinal = ordinal + 1) { + for (ordinal = 0; ordinal < ordinalCount;) { if (((*phraseTable & languageMask) != 0) && ((characterSetTable == 0 || ((characterSet & characterSetTable[(Zi8UInt)ordinal]) != 0)))) { - if (keyIndex != 1) { - for (index = 0; (index < 4 && (keyMasks[index + 4] == (keyMasks[index] & phraseTable[index]))); - index = index + 1) { + if (keyIndex != 0) { + for (index = 0; index < 4; index++) { + if (keyValues[index] != (keyMasks[index] & phraseTable[index])) break; } if (index < 4) goto nextOrdinal; } entryFlags = false; - if (((ziS8)work->phoneticFilter != '\0') && - (tableIndex = (ziU16)phraseTable[8] << 1 | (ziU16)((int)(phraseTable[9] & 0x80) >> 7), - work->phoneticEnabled[(Zi8UInt)tableIndex] == '\0')) { - entryFlags = true; + if (work->phoneticFilter != 0) { + tableIndex = (ziU16)phraseTable[8] << 1 | (((ziU16)phraseTable[9] & 0x80) >> 7); + if (work->phoneticEnabled[tableIndex] == 0) entryFlags = true; } - if (entryFlags) { - elementIndex = '\0'; - } - else { - character = Zi8GetPCode(phoneticTable,phraseTable); - elementIndex = Zi8IsMatch1Key(spelling,inputLimit,character,matchFull,tone,includeTone); + if (!entryFlags) { + elementIndex = Zi8IsMatch1Key(spelling,inputLimit,Zi8GetPCode(phoneticTable,phraseTable),matchFull,tone,includeTone); + } else { + elementIndex = 0; } if (((elementIndex == '\0') && (requireFull == 0)) && ((*phraseTable & 0x80) != 0)) { elementIndex = MatchAltSound1Key(spelling,inputLimit,matchFull,(Zi8AltSoundRecord *)alternateTable,phoneticMask,phoneticTable,ordinal, tone,includeTone,languageMask,work); } - if ((elementIndex != '\0') && - (unicodeCharacter = (ziU16)phraseTable[6] * 0x100 + (ziU16)phraseTable[7], unicodeCharacter != previousCharacter)) { - previousCharacter = unicodeCharacter; - if (emitWords) { - result = Zi8IsDupWordW(&unicodeCharacter,1,work); - if (result == '\0') { -appendOrdinal: - if (remaining == 0) { - totalCandidates = totalCandidates + 1; - if (options->countOnly == '\0') { - candidateCount = candidateCount + 1; - output[outputIndex] = unicodeCharacter; - index = outputIndex + 1; - if (emitWords) { - output[(outputIndex + 1)] = 0x20; - index = outputIndex + 2; - } - } - else { - index = outputIndex; - if (options->maxCount <= totalCandidates) break; - } - outputIndex = index; - if ((params->maxCandidates <= candidateCount) || (outputLimit < outputIndex)) break; - } - else { - remaining = remaining + -1; - } - } + if (elementIndex == 0) goto nextOrdinal; + unicodeCharacter = (ziU16)phraseTable[6] * 0x100 + (ziU16)phraseTable[7]; + if (unicodeCharacter == previousCharacter) goto nextOrdinal; + previousCharacter = unicodeCharacter; + if (!emitWords) { + if (trackDuplicates && Zi8SetFindCand(params->scratch,ordinal,work) != 0) goto nextOrdinal; + for (index = 0; index < candidateCount; index++) { + if (unicodeCharacter == output[index]) break; } - else if ((!trackDuplicates) || - (result = Zi8SetFindCand(params->scratch,ordinal,work), - result == '\0')) { - for (index = 0; - (index < (int)(Zi8UInt)candidateCount && (unicodeCharacter != output[index])); - index = index + 1) { - } - if ((int)(Zi8UInt)candidateCount <= index) goto appendOrdinal; + if (index < candidateCount) goto nextOrdinal; + } else { + if (Zi8IsDupWordW(&unicodeCharacter,1,work) != 0) goto nextOrdinal; + } + if (remaining == 0) { + totalCandidates++; + if (options->countOnly == 0) { + candidateCount++; + output[outputIndex++] = unicodeCharacter; + if (emitWords) output[outputIndex++] = 0x20; + } else { + if (totalCandidates >= options->maxCount) break; } + if (candidateCount >= params->maxCandidates || outputIndex > outputLimit) break; + } else { + remaining--; } } nextOrdinal: + ordinal++; phraseTable = phraseTable + 0xc; } finishCandidates: if ((emitWords) && (outputIndex != 0)) { output[outputIndex] = 0; - outputIndex = outputIndex + 1; + outputIndex++; } params->count = candidateCount; Zi8LogError(100,work); return totalCandidates; -finishOEMwords: - params->wordCandidates = candidateCount; - goto finishCandidates; -finishUserWords: - params->wordCandidates = candidateCount; - goto finishCandidates; } Zi8UInt Zi8ZHCheckSpelling(ziU16 *input,ziU16 *spelling,Zi8UInt inputLength,char *work) diff --git a/libs/RVLMiddleware/eZiText/src/clib/zi8alpha.c b/libs/RVLMiddleware/eZiText/src/clib/zi8alpha.c index 6c8efd3a..5d84d59e 100644 --- a/libs/RVLMiddleware/eZiText/src/clib/zi8alpha.c +++ b/libs/RVLMiddleware/eZiText/src/clib/zi8alpha.c @@ -297,127 +297,124 @@ void Zi8ChangeWordCase(ziWChar* word, ziU8 language, ziPtr work) { ziU32 Zi8DeTokenization(ziWChar* word, ziU32 length, ziU16 capacity, ziU16 language); ziU32 Zi8GetTableAddress(ziU8 language, ziU8 table, ziPtr work); -ziU32 Zi8GetTableCount(ziU8 language, ziU8 table, ziPtr work); +ziU16 Zi8GetTableCount(ziU8 language, ziU8 table, ziPtr work); void Zi8InitDupWordBuf(ziPtr work); ziBool Zi8IsDupWordW(ziWChar* word, ziU8 length, ziPtr work); -ziBool Zi8IsZicorpSignature(ziWChar* word, ziU8 length, ziPtr work); +ziBool Zi8IsZicorpSignature(ziWChar* word, ziU16 length, ziPtr work); ziU8 Zi8LangSupported(ziU8 language, ziPtr work); ziU8 Zi8MatchOEMdata(ziWChar* elements, ziU8 count, ziU8 language, ziWChar* word, ziU16 capacity, ziU8 mode, ziU8 status, ziPtr work); ziU8 Zi8MatchPUDdata(ziWChar* elements, ziU8 count, ziU8 language, ziWChar* word, ziU16 capacity, ziU8 mode, ziU8 status, ziPtr work); ziU8 Zi8MatchROMdata(ziWChar* elements, ziU8 count, ziU8 language, ziWChar* word, ziU16 capacity, ziU8 mode, ziU8 status, ziBool reservedMode, ziBool exactLength, ziPtr work); ziU8 Zi8MatchUWDdata(ziWChar* elements, ziU8 count, ziWChar* currentWord, ziU8 currentLength, ziU8 language, ziWChar* word, ziU16 capacity, ziU8 mode, ziU8 status, ziPtr work); -void Zi8Memset(ziPtr destination, ziU8 value, ziU32 count); +void Zi8Memset(ziPtr destination, ziU32 value, ziU32 count); ziU16 Zi8WCharCount(ziWChar* word, ziPtr work); ziBool Zi8ZHCheckSpelling(ziWChar* word, ziWChar* elements, ziU8 count, ziPtr work); ziU8 Zi8getKeyLayout(ziU8 language, ziWChar key, ziWChar* characters, ziU8 capacity, ziPtr work); -ziU8 Zi8AlphaGetCandidates(ziGetParam* parameters, ziPtr optionData, ziPtr workData) +int Zi8AlphaGetCandidates(ziGetParam* parameters, ziPtr optionData, ziPtr workData) { - int contextEnabled; - ziU8 characterCount; - int primaryCompletionAllowed; - int secondaryCompletionAllowed; - ziU8 prefixCharacterCount; - int phoneticInput; - int phoneticSeparator; - int vowelRestriction; - int completionAllowed; - int secondLanguagePass; - int punctuationCandidate; - ziBool retryPunctuation; - int switchedLanguage; - int secondaryVowelRestriction; - ziBool prefixActive; - ziU16 primaryMatched; - ziU16 secondaryMatched; - unsigned int primaryTableFlags; - ziBool matched; - unsigned int candidateLength; - ziU16 character; - ziS16 key; - ziU8 encodedCharacter; - ziU8 outputCharacter; - ziU16 convertedCharacter; - int index; - ziChar* encodedWord; - ziU8 *encodedCursor; ziU16 *wordCursor; - unsigned int characterIndex; - ziU8 keyLayoutCount; - ziU8 outputLanguage; - ziU8 language; - ziU8 *keyLayoutCursor; - ziU8 *keyLayout; - int candidateCount; - unsigned int elementCount; - unsigned int firstCandidate; - ziU16 *elements; - ziU16 *punctuationCursor; - unsigned int wordLength; - int remainingCapacity; - unsigned int wordCapacity; - int exactLengthOnly; - int dictionaryExact; - int matchMode; - unsigned int elementIndex; - unsigned int dictionaryKind; - unsigned int dictionaryIndex = 0; - ziU8 *encodedOutput; - unsigned int countIndex; - int alternateSingleCharacter; - int languagePassCount; + int index; + int retryPunctuation; + int primaryMatched; + int secondaryMatched; + int prefixPrepared; + int prefixCount; + int secondaryCompletionAllowed; + int secondaryVowelRestriction; + int primaryCompletionAllowed; + int primaryVowelRestriction; + int completionAllowed; + int currentVowelRestriction; + int prefixVowelRestriction; int apostropheIndex; - unsigned int prefixCount; - ziU8 candidateBytes [64]; - unsigned int dictionaryStatus [14]; - ziU16 normalizedElements [64]; + int languagePassCount; + int secondLanguagePass; + int alternateSingleCharacter; + int countIndex; + ziU8 *encodedOutput; + int dictionaryIndex; + int dictionaryKind; + int elementIndex; + int matchMode; + int dictionaryExact; + int exactLengthOnly; + int wordCapacity; + int remainingCapacity; + int wordLength; + ziWChar *punctuationCursor; + ziWChar *elements; + int firstCandidate; + int elementCount; + int punctuationCandidate; + int candidateCount; + ziU8 *keyLayout; + ziU8 *keyLayoutCursor; + ziU16 prefixTableFlags; + ziU16 prefixVowelFlags; + ziU8 prefixMode; + ziU8 prefixLength; + ziU8 switchedLanguage; + ziU8 language; + ziU8 outputLanguage; + ziU8 contextEnabled; + ziU8 keyLayoutCount; + ziU8 candidateCharacterCount; + ziU8 phoneticInput; + ziU8 phoneticSeparator; + ziU16 candidateWord[65]; ziWChar punctuationBuffer[48]; - ziU16 candidateWord [64]; + ziU16 normalizedElements[64]; + unsigned int dictionaryStatus[14]; + ziU8 candidateBytes[64]; - retryPunctuation = ZI8_FALSE; - primaryMatched = ZI8_FALSE; - secondaryMatched = ZI8_FALSE; - prefixActive = ZI8_FALSE; + prefixMode = 0; + prefixTableFlags = 0; + prefixVowelFlags = 0; + prefixLength = 0; + retryPunctuation = 0; + primaryMatched = 0; + secondaryMatched = 0; + prefixPrepared = 0; prefixCount = 0; - secondaryVowelRestriction = ZI8_TRUE; - vowelRestriction = ZI8_FALSE; + secondaryCompletionAllowed = 1; + secondaryVowelRestriction = 1; + primaryCompletionAllowed = 1; + primaryVowelRestriction = 1; + completionAllowed = 1; + currentVowelRestriction = 1; + prefixVowelRestriction = 0; + apostropheIndex = 0; languagePassCount = 2; - secondLanguagePass = ZI8_FALSE; + secondLanguagePass = 0; alternateSingleCharacter = 0; - switchedLanguage = ZI8_FALSE; + switchedLanguage = 0; + punctuationCursor = punctuationBuffer; elements = parameters->elements; - firstCandidate = (unsigned int)parameters->firstCandidate; - characterCount = parameters->elementCount; - elementCount = (unsigned int)characterCount; - punctuationCandidate = ZI8_FALSE; - dictionaryStatus[0] = 0; - dictionaryStatus[1] = 0; - dictionaryStatus[2] = 0; - dictionaryStatus[3] = 0; - dictionaryStatus[4] = 0; - dictionaryStatus[5] = 0; - dictionaryStatus[6] = 0; - dictionaryStatus[7] = 0; - dictionaryStatus[8] = 0; - dictionaryStatus[9] = 0; - dictionaryStatus[10] = 0; - dictionaryStatus[0xb] = 0; - dictionaryStatus[0xc] = 0; - dictionaryStatus[0xd] = 0; + firstCandidate = parameters->firstCandidate; + elementCount = parameters->elementCount; + punctuationCandidate = 0; + dictionaryStatus[13] = dictionaryStatus[12] = dictionaryStatus[11] = + dictionaryStatus[10] = dictionaryStatus[9] = dictionaryStatus[8] = + dictionaryStatus[7] = dictionaryStatus[6] = dictionaryStatus[5] = + dictionaryStatus[4] = dictionaryStatus[3] = dictionaryStatus[2] = + dictionaryStatus[1] = dictionaryStatus[0] = 0; candidateCount = 0; language = parameters->language; outputLanguage = 0; - keyLayout = (ziU8 *)0x0; - phoneticInput = ZI8_FALSE; - phoneticSeparator = ZI8_FALSE; + contextEnabled = 0; + keyLayoutCount = 0; + keyLayout = 0; + phoneticInput = 0; + phoneticSeparator = 0; if ((((((language == 0x7c) || (language == 0x7d)) || (language == 0x7b)) || ((language == 0x77 || (language == 0x78)))) || (language == 0x79)) || (language == 0x7a)) { phoneticInput = ZI8_TRUE; - for (elementIndex = 0; (int)elementIndex < (int)elementCount; elementIndex = elementIndex + 1) { + for (elementIndex = 0; elementIndex < elementCount; elementIndex++) { normalizedElements[elementIndex] = elements[elementIndex]; - if ((elements[elementIndex] < 0xf336) && (0xf330 < elements[elementIndex])) { + if ((int)elements[elementIndex] < 0xf336 && (int)elements[elementIndex] >= 0xf331) { phoneticSeparator = ZI8_TRUE; phoneticInput = ZI8_FALSE; if ((language == 0x7d) || ((language == 0x79 || (language == 0x7a)))) { @@ -430,19 +427,19 @@ ziU8 Zi8AlphaGetCandidates(ziGetParam* parameters, ziPtr optionData, ziPtr workD } elements = normalizedElements; } - contextEnabled = ((ZiAlphaWork*)workData)->context != '\0'; + if (((ZiAlphaWork*)workData)->context != 0) contextEnabled = 1; if ((((parameters->elementCount != 0) && (((ZiAlphaWork*)workData)->normalizeCase != '\0')) && (!phoneticInput)) && (!phoneticSeparator)) { - primaryCompletionAllowed = ZI8_FALSE; - for (elementIndex = 0; (int)elementIndex < (int)(unsigned int)parameters->elementCount; elementIndex = elementIndex + 1) { + index = 0; + for (elementIndex = index; (int)elementIndex < (int)(unsigned int)parameters->elementCount; elementIndex = elementIndex + 1) { normalizedElements[elementIndex] = parameters->elements[elementIndex]; if (((parameters->elements[elementIndex] < 0xeff1) || (0xf37f < parameters->elements[elementIndex])) && - (matched = Zi8ChangeCharCase(0,normalizedElements + elementIndex,language,workData), matched != '\0')) + ((Zi8ChangeCharCase(0,normalizedElements + elementIndex,language,workData)) != '\0')) { - primaryCompletionAllowed = ZI8_TRUE; + index = 1; } } - if (primaryCompletionAllowed) { + if (index) { elements = normalizedElements; } } @@ -450,40 +447,37 @@ ziU8 Zi8AlphaGetCandidates(ziGetParam* parameters, ziPtr optionData, ziPtr workD (((ZiAlphaOptions*)optionData)->lookupMode == '\0')) { ZiprocessHighlightedW(parameters->elementCount,workData); } - if (((((ZiAlphaOptions*)optionData)->lookupMode == '\0') && (parameters->elementCount < 2)) && (parameters->firstCandidate == 0)) { + if (((((ZiAlphaOptions*)optionData)->lookupMode == '\0') && (parameters->elementCount <= 1)) && (parameters->firstCandidate == 0)) { ((ZiAlphaWork*)workData)->highlightedWord[0] = 0; } - primaryTableFlags = Zi8GetTableCount(parameters->language,0x1f,workData); - if (((primaryTableFlags & 0x80) != 0) && (parameters->subLanguage == 0x80)) { + if (((Zi8GetTableCount(parameters->language,0x1f,workData) & 0x80) != 0) && (parameters->subLanguage == 0x80)) { contextEnabled = ZI8_TRUE; } - if (((((ZiAlphaOptions*)optionData)->lookupMode == '\0') && (parameters->subLanguage != 7)) && + if (!(((((ZiAlphaOptions*)optionData)->lookupMode == '\0') && (parameters->subLanguage != 7)) && ((parameters->subLanguage != language && ((((parameters->subLanguage != 0 && (parameters->subLanguage != 1)) && (parameters->subLanguage != 2)) && - ((parameters->subLanguage != 0x80 && (matched = Zi8LangSupported(parameters->subLanguage,workData), matched != '\0')))))))) - { - if (((parameters->elementCount == 1) && (0xeff0 < *parameters->elements)) && - (*parameters->elements < 0xf011)) { - contextEnabled = ZI8_FALSE; - matched = Zi8MatchROMdata(parameters->elements,1,language,candidateWord,2,1,0,0,0, - workData); - if (matched == '\0') { - language = parameters->subLanguage; - } - else { - matched = Zi8MatchROMdata(parameters->elements,1,parameters->subLanguage,candidateWord,2,1,0,0,0, - workData); - if ((matched != '\0') && (candidateWord[0] != *parameters->elements)) { - alternateSingleCharacter = 1; - } - } - } - } - else { + ((parameters->subLanguage != 0x80 && ((Zi8LangSupported(parameters->subLanguage,workData)) != '\0'))))))))) { languagePassCount = 0; if (((ZiAlphaWork*)workData)->language != parameters->language) { ((ZiAlphaWork*)workData)->language = 0; } + } else { + if (((parameters->elementCount == 1) && (*parameters->elements >= 0xeff1)) && + (*parameters->elements <= 0xf010)) { + contextEnabled = ZI8_FALSE; + wordLength = (ziU8)Zi8MatchROMdata(parameters->elements,1,language,candidateWord,2,1,0,0,0, + workData); + if (wordLength == 0) { + language = parameters->subLanguage; + } + else { + wordLength = (ziU8)Zi8MatchROMdata(parameters->elements,1,parameters->subLanguage,candidateWord,2,1,0,0,0, + workData); + if ((wordLength != 0) && (candidateWord[0] != *parameters->elements)) { + alternateSingleCharacter = 1; + } + } + } } if ((parameters->elementCount == 1) && (((ZiAlphaOptions*)optionData)->lookupMode == '\0')) { if (((parameters->wordCharCount < 3) || @@ -498,36 +492,40 @@ ziU8 Zi8AlphaGetCandidates(ziGetParam* parameters, ziPtr optionData, ziPtr workD } } if (((elementCount != 0) && (((ZiAlphaOptions*)optionData)->lookupMode == '\0')) && (((ZiAlphaOptions*)optionData)->countOnly == '\0')) { - matched = Zi8IsAlphaPunct(elements[elementCount - 1]); - if (matched == '\0') { - ((ZiAlphaWork*)workData)->rememberedCount = characterCount; + index = Zi8IsAlphaPunct(elements[elementCount - 1]); + if (index == '\0') { + ((ZiAlphaWork*)workData)->rememberedCount = elementCount; } else if (elementCount < ((ZiAlphaWork*)workData)->rememberedCount) { - ((ZiAlphaWork*)workData)->rememberedCount = characterCount - 1; + ((ZiAlphaWork*)workData)->rememberedCount = elementCount - 1; } } - if ((((ZiAlphaWork*)workData)->usePrefixAsElements == '\x01') && - (elements = ((ZiAlphaWork*)workData)->prefix, ((ZiAlphaWork*)workData)->prefixCount < parameters->elementCount)) { - for (primaryTableFlags = (unsigned int)((ZiAlphaWork*)workData)->prefixCount; (int)primaryTableFlags < (int)(unsigned int)parameters->elementCount; - primaryTableFlags = primaryTableFlags + 1) { - ((ZiAlphaWork*)workData)->prefix[primaryTableFlags] = - parameters->elements[primaryTableFlags]; + if (((ZiAlphaWork*)workData)->usePrefixAsElements == 1) { + elements = ((ZiAlphaWork*)workData)->prefix; + if (parameters->elementCount > ((ZiAlphaWork*)workData)->prefixCount) { + for (index = (unsigned int)((ZiAlphaWork*)workData)->prefixCount; (int)index < (int)(unsigned int)parameters->elementCount; + index = index + 1) { + ((ZiAlphaWork*)workData)->prefix[index] = + parameters->elements[index]; + } + ((ZiAlphaWork*)workData)->prefix[index] = 0; + ((ZiAlphaWork*)workData)->prefixCount = (ziU8)index; + elementCount = ((ZiAlphaWork*)workData)->prefixCount; } - ((ZiAlphaWork*)workData)->prefix[primaryTableFlags] = 0; - ((ZiAlphaWork*)workData)->prefixCount = (char)primaryTableFlags; - elementCount = (unsigned int)((ZiAlphaWork*)workData)->prefixCount; } - primaryTableFlags = Zi8GetTableCount(parameters->language,0x1f,workData); - primaryCompletionAllowed = (primaryTableFlags & 4) == 0; - primaryTableFlags = Zi8GetTableCount(parameters->language,0x1f,workData); + if ((Zi8GetTableCount(parameters->language,0x1f,workData) & 4) != 0) { + primaryVowelRestriction = currentVowelRestriction = 0; + } + if ((Zi8GetTableCount(parameters->language,0x1f,workData) & 2) != 0) { + primaryCompletionAllowed = completionAllowed = 0; + } encodedOutput = (ziChar*)parameters->candidates; - if ((((ZiAlphaOptions*)optionData)->countOnly == '\0') && ((parameters->getOptions & 0xfd) == 0x81)) { - wordCursor = parameters->candidates; - wordCapacity = ((ZiAlphaOptions*)optionData)->capacity - 1; - } - else { + if ((((ZiAlphaOptions*)optionData)->countOnly != '\0') || ((parameters->getOptions & 0xfd) != 0x81)) { wordCursor = candidateWord; wordCapacity = 0x3f; + } else { + wordCursor = parameters->candidates; + wordCapacity = ((ZiAlphaOptions*)optionData)->capacity - 1; } remainingCapacity = ((ZiAlphaOptions*)optionData)->capacity - 1; if ((elementCount < ((ZiAlphaWork*)workData)->exactLengthThreshold) || ((parameters->getOptions & 0x7e) == 2)) { @@ -539,161 +537,74 @@ ziU8 Zi8AlphaGetCandidates(ziGetParam* parameters, ziPtr optionData, ziPtr workD if (phoneticSeparator) { exactLengthOnly = 1; } - if (languagePassCount == 0) { - secondaryCompletionAllowed = ZI8_FALSE; - secondaryVowelRestriction = ZI8_FALSE; - } - else { - candidateLength = Zi8GetTableCount(parameters->subLanguage,0x1f,workData); - secondaryCompletionAllowed = (candidateLength & 4) == 0; - candidateLength = Zi8GetTableCount(parameters->subLanguage,0x1f,workData); - if ((candidateLength & 2) != 0) { - secondaryVowelRestriction = ZI8_FALSE; - } + if (languagePassCount != 0) { + if ((Zi8GetTableCount(parameters->subLanguage,0x1f,workData) & 4) != 0) secondaryVowelRestriction = 0; + if ((Zi8GetTableCount(parameters->subLanguage,0x1f,workData) & 2) != 0) secondaryCompletionAllowed = 0; + } else { + secondaryVowelRestriction = 0; + secondaryCompletionAllowed = 0; } Zi8InitDupWordBuf(workData); + dictionaryIndex = 0; if ((((((ZiAlphaOptions*)optionData)->lookupMode == '\0') && (!phoneticInput)) && (!phoneticSeparator)) && ((((parameters->getOptions & 0xfd) != 0x80 && (parameters->elementCount != 0)) && ((parameters->elements[parameters->elementCount - 1] != 0xEFF1 && - (matched = Zi8IsAlphaPunct(parameters->elements[parameters->elementCount - 1]), - matched != '\0')))))) { - for (elementIndex = 0; - ((int)elementIndex < (int)(parameters->elementCount - 1) && - (((ZiAlphaWork*)workData)->highlightedWord[elementIndex] == - parameters->elements[elementIndex])); elementIndex = elementIndex + 1) { + ((Zi8IsAlphaPunct(parameters->elements[parameters->elementCount - 1])) != '\0')))))) { + for (elementIndex = 0; elementIndex < parameters->elementCount - 1; elementIndex++) { + if (((ZiAlphaWork*)workData)->highlightedWord[elementIndex] != parameters->elements[elementIndex]) break; wordCursor[elementIndex] = ((ZiAlphaWork*)workData)->highlightedWord[elementIndex]; } wordCursor[elementIndex] = parameters->elements[elementIndex]; - candidateLength = elementIndex + 1; - if (parameters->elementCount == 1) { - ((ZiAlphaWork*)workData)->singleCharacter = *wordCursor; - } - if ((candidateLength == parameters->elementCount) && ((firstCandidate == 0 || (((ZiAlphaWork*)workData)->reuseHighlightedWord != '\0')))) { - for (index = 0; index < (int)(unsigned int)((ZiAlphaWork*)workData)->dictionaryCount; index = index + 1) { - characterCount = ((ZiAlphaWork*)workData)->dictionaryKinds[index]; - if ((characterCount == 9) || ((characterCount < 9 && (characterCount == 1)))) break; - } - if ((firstCandidate == 0) && (((ZiAlphaWork*)workData)->highlightedWord[elementIndex] != 0)) { - if (((ZiAlphaWork*)workData)->requiredLength < parameters->elementCount) { - ((ZiAlphaWork*)workData)->reuseHighlightedWord = 0; + elementIndex++; + if (parameters->elementCount == 1) ((ZiAlphaWork*)workData)->singleCharacter = *wordCursor; + if (elementIndex == parameters->elementCount && + (firstCandidate == 0 || ((ZiAlphaWork*)workData)->reuseHighlightedWord != 0)) { + for (index = 0; index < ((ZiAlphaWork*)workData)->dictionaryCount; index++) { + switch ((int)((ZiAlphaWork*)workData)->dictionaryKinds[index]) { + case 1: + case 9: + goto foundHighlightedDictionary; } } - else { +foundHighlightedDictionary: + if (firstCandidate == 0 && ((ZiAlphaWork*)workData)->highlightedWord[elementIndex - 1] != 0) { + if (((ZiAlphaWork*)workData)->requiredLength < parameters->elementCount) + ((ZiAlphaWork*)workData)->reuseHighlightedWord = 0; + } else { ((ZiAlphaWork*)workData)->reuseHighlightedWord = 1; } - if (((index < (int)(unsigned int)((ZiAlphaWork*)workData)->dictionaryCount) && - (((ZiAlphaWork*)workData)->reuseHighlightedWord != '\0')) && - (matched = Zi8IsDupWordW(wordCursor,candidateLength & 0xff,workData), matched == '\0')) { - if (firstCandidate == 0) { + if (index < ((ZiAlphaWork*)workData)->dictionaryCount && + ((ZiAlphaWork*)workData)->reuseHighlightedWord != 0 && + Zi8IsDupWordW(wordCursor,elementIndex,workData) == 0) { + if (firstCandidate != 0) { + firstCandidate--; + } else { candidateCount = 1; - if (((ZiAlphaOptions*)optionData)->countOnly == '\0') { - elementIndex = candidateLength; - if (((ZiAlphaOptions*)optionData)->suffixOnly != '\0') { - for (elementIndex = 0; (int)(parameters->elementCount + elementIndex) < (int)candidateLength; - elementIndex = elementIndex + 1) { - wordCursor[elementIndex] = wordCursor[elementIndex + parameters->elementCount]; + if (((ZiAlphaOptions*)optionData)->countOnly == 0) { + if (((ZiAlphaOptions*)optionData)->suffixOnly != 0) { + for (index = 0; parameters->elementCount + index < elementIndex; index++) { + wordCursor[index] = wordCursor[index + parameters->elementCount]; } + elementIndex = index; } - wordCursor[elementIndex] = 0; - index = elementIndex + 1; - if (((ZiAlphaWork*)workData)->caseMode != '\0') { - if (((ZiAlphaWork*)workData)->suffixMode == '\0') { + wordCursor[elementIndex++] = 0; + if (((ZiAlphaWork*)workData)->caseMode != 0) { + if (((ZiAlphaWork*)workData)->suffixMode == 0) Zi8ChangeWordCase(wordCursor,language,workData); - } - else { + else Zi8ChangeWordCase(wordCursor,((ZiAlphaWork*)workData)->language,workData); - } - } - wordCursor = wordCursor + index; - wordCapacity = wordCapacity - index; - remainingCapacity = remainingCapacity - index; - if ((parameters->maxCandidates == 1) || (remainingCapacity <= (int)(unsigned int)parameters->elementCount)) { -finishCandidates: - ((ZiAlphaWork*)workData)->usePrefixAsElements = 0; - characterCount = (ziU8)candidateCount; - if (((ZiAlphaOptions*)optionData)->countOnly == '\0') { - parameters->letters = characterCount; - } - else { - parameters->letters = 0; - } - wordCursor[-prefixCount] = 0; - if (((((ZiAlphaOptions*)optionData)->countOnly == '\0') && (((ZiAlphaOptions*)optionData)->lookupMode == '\0')) && (parameters->elementCount != 0)) { - elementIndex = parameters->elementCount - 1; - if (((primaryCompletionAllowed) || (secondaryCompletionAllowed)) && - ((((ZiAlphaWork*)workData)->prefixEnabled < 2 || - (parameters->elements[elementIndex] == 0xEFF1)))) { - index = 0; - for (; (-1 < (int)elementIndex && - (parameters->elements[elementIndex] == 0xEFF1)); - elementIndex = elementIndex + -1) { - index = index + 1; - } - if (index == 0) { - if (candidateCount != 0) { - ((ZiAlphaWork*)workData)->prefixEnabled = 0; - ((ZiAlphaWork*)workData)->requiredLength = 0; - } - } - else { - ((ZiAlphaWork*)workData)->prefixEnabled = (char)index; - } - ((ZiAlphaWork*)workData)->requiredLength = parameters->elementCount; - } - if ((parameters->letters != 0) && (parameters->maxCandidates == 1)) { - if ((parameters->getOptions & 0x81) == 0x81) { - wordCursor = parameters->candidates; - } - else if (outputLanguage == 0) { - wordCursor = (ziU16 *)0x0; - } - else { - encodedWord = (ziChar*)parameters->candidates; - wordCursor = candidateWord; - for (characterIndex = 0; encodedWord[characterIndex] != '\0'; characterIndex = characterIndex + 1) { - convertedCharacter = Zi8ConvertUC2WC(encodedWord[characterIndex],outputLanguage, - workData); - wordCursor[characterIndex] = convertedCharacter; - } - wordCursor[characterIndex] = 0; - } - if (wordCursor != (ziU16 *)0x0) { - Zi8SetHighlightedWordW(wordCursor,parameters->language,parameters->subLanguage,workData); - } - } - } - if (((ZiAlphaWork*)workData)->dictionaryCounts != 0) { - if ((int)dictionaryIndex < (int)(unsigned int)((ZiAlphaWork*)workData)->dictionaryCount) { - ((ZiAlphaWork*)workData)->dictionaryCounts[dictionaryIndex] = characterCount; - } - else { - ((ZiAlphaWork*)workData)->dictionaryCounts[((ZiAlphaWork*)workData)->dictionaryCount - 1] = - characterCount; - } - countIndex = dictionaryIndex; - if ((int)(unsigned int)((ZiAlphaWork*)workData)->dictionaryCount <= (int)dictionaryIndex) { - countIndex = ((ZiAlphaWork*)workData)->dictionaryCount - 1; - } - for (; 0 < (int)countIndex; countIndex = countIndex - 1) { - ((ZiAlphaWork*)workData)->dictionaryCounts[countIndex] = - ((ZiAlphaWork*)workData)->dictionaryCounts[countIndex] - - ((ZiAlphaWork*)workData)->dictionaryCounts[countIndex - 1]; - } - } - Zi8LogError(100,workData); - return candidateCount; } + wordCursor += elementIndex; + wordCapacity -= elementIndex; + remainingCapacity -= elementIndex; + if (parameters->maxCandidates == 1 || remainingCapacity <= parameters->elementCount) goto finishCandidates; } } - else { - firstCandidate = firstCandidate - 1; - } } } } - completionAllowed = primaryCompletionAllowed; if (((ZiAlphaOptions*)optionData)->lookupMode == '\0') { - if ((parameters->elementCount < 2) && (parameters->firstCandidate == 0)) { + if ((parameters->elementCount <= 1) && (parameters->firstCandidate == 0)) { ((ZiAlphaWork*)workData)->prefixEnabled = 0; ((ZiAlphaWork*)workData)->requiredLength = 0; ((ZiAlphaWork*)workData)->previousPrefixCount = 0; @@ -707,9 +618,9 @@ finishCandidates: ((ZiAlphaWork*)workData)->suffixCount = 0; } if (((((ZiAlphaWork*)workData)->suffixLocked != '\0') && (parameters->elementCount <= ((ZiAlphaWork*)workData)->suffixElementCount)) && - (matched = ZiIsLetterHyphen(((ZiAlphaWork*)workData)->suffix[(((ZiAlphaWork*)workData)->suffixCount - 1)], - workData), matched != '\0')) { - ((ZiAlphaWork*)workData)->suffixCount = ((ZiAlphaWork*)workData)->suffixCount + -1; + ((ZiIsLetterHyphen(((ZiAlphaWork*)workData)->suffix[(((ZiAlphaWork*)workData)->suffixCount - 1)], + workData)) != '\0')) { + ((ZiAlphaWork*)workData)->suffixCount--; ((ZiAlphaWork*)workData)->suffixElementCount = ((ZiAlphaWork*)workData)->previousSuffixCount; } if (parameters->elementCount <= ((ZiAlphaWork*)workData)->suffixElementCount) { @@ -717,15 +628,15 @@ finishCandidates: } if (((ZiAlphaWork*)workData)->suffixMode != '\0') { if ((parameters->elementCount <= ((ZiAlphaWork*)workData)->prefixElementCount) && - (matched = ZiIsLetterHyphen(((ZiAlphaWork*)workData)->prefix[((ZiAlphaWork*)workData)->prefixCount - 1], - workData), matched != '\0')) { - ((ZiAlphaWork*)workData)->prefixCount = ((ZiAlphaWork*)workData)->prefixCount + -1; + ((ZiIsLetterHyphen(((ZiAlphaWork*)workData)->prefix[((ZiAlphaWork*)workData)->prefixCount - 1], + workData)) != '\0')) { + ((ZiAlphaWork*)workData)->prefixCount--; ((ZiAlphaWork*)workData)->prefixElementCount = ((ZiAlphaWork*)workData)->previousPrefixCount; } if ((elementCount == ((ZiAlphaWork*)workData)->prefixCount) && - (matched = ZiIsLetterHyphen(((ZiAlphaWork*)workData)->prefix[((ZiAlphaWork*)workData)->prefixCount - 1], - workData), matched != '\0')) { - ((ZiAlphaWork*)workData)->prefixCount = ((ZiAlphaWork*)workData)->prefixCount + -1; + ((ZiIsLetterHyphen(((ZiAlphaWork*)workData)->prefix[((ZiAlphaWork*)workData)->prefixCount - 1], + workData)) != '\0')) { + ((ZiAlphaWork*)workData)->prefixCount--; } if ((elementCount <= ((ZiAlphaWork*)workData)->prefixCount) && (((ZiAlphaOptions*)optionData)->countOnly == '\0')) { ((ZiAlphaWork*)workData)->suffixMode = 0; @@ -736,54 +647,91 @@ finishCandidates: ((ZiAlphaWork*)workData)->alternatePrefixCount = 0; } } -prepareDictionaryOrder: - ((ZiAlphaWork*)workData)->dictionaryOrder[0] = 0; - candidateLength = Zi8GetTableCount(language,0x1f,workData); - if ((candidateLength & 0x20) == 0) { - ((ZiAlphaWork*)workData)->dictionaryOrder[1] = 0; - } - else if ((((parameters->currentWord == 0) || (parameters->wordCharCount == 0)) || - (parameters->currentWord[parameters->wordCharCount - 1] == 0x20)) || - ((0xfe < parameters->currentWord[parameters->wordCharCount - 1] || - (key = Zi8ConvertWC2Key(parameters->currentWord[parameters->wordCharCount - 1], - language,workData), (ziWChar)key == 0xEFF1)))) { - ((ZiAlphaWork*)workData)->dictionaryOrder[1] = 1; + goto prepareDictionaryOrder; +preparePrefix: + prefixMode = ((ZiAlphaWork*)workData)->suffixMode; + prefixTableFlags = Zi8GetTableCount(language,0x1f,workData); + prefixVowelFlags = prefixTableFlags & 0x10; + if (((((language == 0x3f) || (language == 4)) || + ((language == 0x40 || ((language == 0x58 || (language == 0x2f)))))) && (prefixMode != 0) + ) && (prefixVowelFlags != 0)) { + prefixVowelRestriction = ZI8_TRUE; } else { - ((ZiAlphaWork*)workData)->dictionaryOrder[1] = 0; - if ((language == 10) && (parameters->wordCharCount != 0)) { - elementIndex = (unsigned int)parameters->wordCharCount; -scanFinnishWord: - while (elementIndex = elementIndex - 1, -1 < (int)elementIndex) { - character = parameters->currentWord[elementIndex]; - if (character == 0x6f) goto useFinnishVowelOrder; - if (0x6e < character) goto checkFinnishVowel; - if (character == 0x61) goto useFinnishVowelOrder; - if ((character < 0x61) && (character == 0x20)) goto finishFinnishScan; + prefixVowelRestriction = ZI8_FALSE; + } + if (((ZiAlphaWork*)workData)->suffixMode != '\0') { + secondLanguagePass = ZI8_FALSE; + if ((((ZiAlphaOptions*)optionData)->countOnly != '\0') || ((parameters->getOptions & 0xfd) != 0x81)) { + wordCursor = candidateWord; + wordCapacity = 0x40; + } + for (index = 0; index < 0xe; index = index + 1) { + dictionaryStatus[index] = 0; + } + for (index = 0; index < (int)(unsigned int)((ZiAlphaWork*)workData)->prefixCount; index = index + 1) { + wordCursor[index] = ((ZiAlphaWork*)workData)->prefix[index]; + if ((elements[index] != wordCursor[index]) && + (elements[index] != (ziU16)Zi8ConvertWC2Key(wordCursor[index],language,workData))) goto finishCandidates; + } + wordCursor = wordCursor + ((ZiAlphaWork*)workData)->prefixCount; + elements = elements + ((ZiAlphaWork*)workData)->prefixCount; + elementCount = elementCount - ((ZiAlphaWork*)workData)->prefixCount; + wordCapacity = wordCapacity - ((ZiAlphaWork*)workData)->prefixCount; + prefixCount = (unsigned int)((ZiAlphaWork*)workData)->prefixCount; + if (((ZiAlphaWork*)workData)->suffixLocked != '\0') { + for (index = 0; index < (int)(unsigned int)((ZiAlphaWork*)workData)->suffixCount; index = index + 1) { + wordCursor[index] = ((ZiAlphaWork*)workData)->suffix[index]; + if ((elements[index] != wordCursor[index]) && + (elements[index] != (ziU16)Zi8ConvertWC2Key(wordCursor[index],language,workData))) goto finishCandidates; } + wordCursor = wordCursor + ((ZiAlphaWork*)workData)->suffixCount; + elements = elements + ((ZiAlphaWork*)workData)->suffixCount; + elementCount = elementCount - ((ZiAlphaWork*)workData)->suffixCount; + wordCapacity = wordCapacity - ((ZiAlphaWork*)workData)->suffixCount; + prefixCount = prefixCount + ((ZiAlphaWork*)workData)->suffixCount; + } + if ((prefixVowelRestriction) && (wordCursor[-1] != 0x27)) { + prefixVowelRestriction = ZI8_FALSE; } } - goto prepareDictionaries; -checkFinnishVowel: - if (character == 0x75) { -useFinnishVowelOrder: - ((ZiAlphaWork*)workData)->dictionaryOrder[0] = 1; -finishFinnishScan: - elementIndex = 0; + goto prepareDictionaryOrder; +prepareDictionaryOrder: + ((ZiAlphaWork*)workData)->dictionaryOrder[0] = 0; + if ((Zi8GetTableCount(language,0x1f,workData) & 0x20) != 0) { + if (parameters->currentWord == 0 || parameters->wordCharCount == 0 || + parameters->currentWord[parameters->wordCharCount - 1] == 0x20 || + parameters->currentWord[parameters->wordCharCount - 1] > 0xfe || + Zi8ConvertWC2Key(parameters->currentWord[parameters->wordCharCount - 1],language,workData) == 0xEFF1) { + ((ZiAlphaWork*)workData)->dictionaryOrder[1] = 1; + } else { + ((ZiAlphaWork*)workData)->dictionaryOrder[1] = 0; + if (language == 10 && parameters->wordCharCount != 0) { + for (elementIndex = parameters->wordCharCount - 1; elementIndex >= 0; elementIndex--) { + switch ((int)parameters->currentWord[elementIndex]) { + case 0x61: + case 0x6f: + case 0x75: + ((ZiAlphaWork*)workData)->dictionaryOrder[0] = 1; + case 0x20: + elementIndex = 0; + } + } + } + } + } else { + ((ZiAlphaWork*)workData)->dictionaryOrder[1] = 0; } - goto scanFinnishWord; prepareDictionaries: apostropheIndex = 0; - candidateLength = Zi8GetTableCount(language,0x1f,workData); - if (((candidateLength & 0x10) != 0) && (2 < parameters->elementCount)) { - for (index = 0; - (index < (int)(unsigned int)parameters->elementCount && - (parameters->elements[index] < 0xeff1)); index = index + 1) { + if (((Zi8GetTableCount(language,0x1f,workData) & 0x10) != 0) && (2 < parameters->elementCount)) { + for (index = 0; index < parameters->elementCount; index++) { + if (parameters->elements[index] >= 0xeff1) break; if ((apostropheIndex == 0) && (parameters->elements[index] == 0x27)) { apostropheIndex = index; } } - if ((int)(unsigned int)parameters->elementCount <= apostropheIndex + 1) { + if (apostropheIndex + 1 >= parameters->elementCount) { apostropheIndex = 0; } if (apostropheIndex != 0) { @@ -792,8 +740,8 @@ prepareDictionaries: } if ((((completionAllowed) && (languagePassCount != 2)) && (parameters->elementCount == 2)) && ((parameters->elements[1] == 0xEFF1 && (((ZiAlphaWork*)workData)->singleCharacter != 0)))) { - matched = Zi8getKeyLayout(language,0xeff1,&punctuationBuffer[0],1,workData); - if (matched == '\0') { + index = Zi8getKeyLayout(language,0xeff1,&punctuationBuffer[0],1,workData); + if (index == '\0') { punctuationBuffer[0] = 0; } } @@ -811,80 +759,36 @@ prepareDictionaries: for (dictionaryIndex = 0; (int)dictionaryIndex <= (int)(unsigned int)((ZiAlphaWork*)workData)->dictionaryCount; dictionaryIndex = dictionaryIndex + 1) { if (((ZiAlphaWork*)workData)->dictionaryCounts != 0) { - if (dictionaryIndex == 0) { + if (dictionaryIndex != 0) { + ((ZiAlphaWork*)workData)->dictionaryCounts[dictionaryIndex - 1] = (ziU8)candidateCount; + } else { Zi8Memset(((ZiAlphaWork*)workData)->dictionaryCounts,0,((ZiAlphaWork*)workData)->dictionaryCount); } - else { - ((ZiAlphaWork*)workData)->dictionaryCounts[dictionaryIndex - 1] = (char)candidateCount; - } } - if (dictionaryIndex == ((ZiAlphaWork*)workData)->dictionaryCount) { - if (((ZiAlphaOptions*)optionData)->lookupMode == '\0') { - dictionaryKind = 10; - goto selectDictionary; - } - } - else { + if (dictionaryIndex != ((ZiAlphaWork*)workData)->dictionaryCount) { dictionaryKind = (unsigned int)((ZiAlphaWork*)workData)->dictionaryKinds[dictionaryIndex]; if ((dictionaryKind != 0xc) || (languagePassCount == 2)) { selectDictionary: - if ((!secondLanguagePass) || - ((dictionaryKind != 10 && (((9 < dictionaryKind || (4 < dictionaryKind)) || (dictionaryKind == 0)))))) { - dictionaryExact = 1; - if (dictionaryKind == 4) { - if ((int)elementCount < (int)(unsigned int)(ziU8)((ZiAlphaOptions*)optionData)->minWordLength) goto finishDictionaryPass; - } - else if (dictionaryKind < 4) { - if (dictionaryKind < 3) { - if (dictionaryKind == 0) { -selectCompletionDictionary: - if ((((elementCount == 1) && (prefixCount == 0)) && (0xeff0 < *elements)) && - ((*elements < 0xf011 && (!contextEnabled)))) goto finishDictionaryPass; - dictionaryExact = 0; - candidateLength = dictionaryIndex; - if (languagePassCount == 2) { - do { - candidateLength = candidateLength + 1; - if ((int)(unsigned int)((ZiAlphaWork*)workData)->dictionaryCount <= (int)candidateLength) - goto selectLanguagePass; - } while (((((ZiAlphaWork*)workData)->dictionaryKinds[candidateLength] != '\x01') && - (((ZiAlphaWork*)workData)->dictionaryKinds[candidateLength] != '\x02')) && - ((((ZiAlphaWork*)workData)->dictionaryKinds[candidateLength] != '\x04' && - (((ZiAlphaWork*)workData)->dictionaryKinds[candidateLength] != '\x03')))); - switchedLanguage = ZI8_TRUE; -selectLanguagePass: - if ((int)(unsigned int)((ZiAlphaWork*)workData)->dictionaryCount <= (int)candidateLength) { - languagePassCount = 1; - language = parameters->subLanguage; - dictionaryStatus[1] = 0; - dictionaryStatus[2] = 0; - dictionaryStatus[3] = 0; - dictionaryStatus[4] = 0; - dictionaryStatus[9] = 0; - dictionaryStatus[5] = 0; - dictionaryStatus[6] = 0; - dictionaryStatus[7] = 0; - dictionaryStatus[8] = 0; - completionAllowed = secondaryCompletionAllowed; - goto prepareDictionaries; - } - } - if (languagePassCount == 1) { - language = parameters->language; - completionAllowed = primaryCompletionAllowed; - } - } - } - else if (((int)elementCount < (int)(unsigned int)(ziU8)((ZiAlphaOptions*)optionData)->minWordLength) || (elementCount == 1)) + if (secondLanguagePass) { + switch (dictionaryKind) { + case 1: + case 2: + case 3: + case 4: + case 10: goto finishDictionaryPass; } - else if (dictionaryKind == 10) { + } + { + dictionaryExact = 1; + switch (dictionaryKind) { + case 10: if ((((elementCount != 1) || - (candidateLength = Zi8GetTableCount(language,0x1f,workData), (candidateLength & 0x40) != 0)) || + (((Zi8GetTableCount(language,0x1f,workData)) & 0x40) != 0)) || ((*elements < 0xeff1 || ((0xf010 < *elements || - (matched = Zi8getKeyLayout(language,*elements,(punctuationBuffer + 1),parameters->elementCount,workData - ), matched == '\0')))))) || + ((Zi8getKeyLayout(language,*elements,(punctuationBuffer + 1),parameters->elementCount,workData + )) == '\0')))))) || (((((ZiAlphaWork*)workData)->suffixMode == '\0' && ((parameters->firstCandidate == 0 && (candidateCount == 0)))) && ((parameters->currentWord == 0 || @@ -914,53 +818,67 @@ selectLanguagePass: punctuationCursor = &punctuationBuffer[0]; } punctuationCandidate = ZI8_FALSE; - } - else { - if (((9 < dictionaryKind) || (dictionaryKind < 9)) || - ((elementCount != 1 || ((*elements < 0xeff1 || (0xf010 < *elements)))))) - goto selectCompletionDictionary; - dictionaryKind = 1; + break; + case 4: + if (((ZiAlphaOptions*)optionData)->minWordLength > elementCount) goto finishDictionaryPass; + break; + case 3: + if (((ZiAlphaOptions*)optionData)->minWordLength > elementCount || elementCount == 1) goto finishDictionaryPass; + break; + case 9: + if (elementCount == 1 && *elements >= 0xEFF1 && *elements <= 0xF010) { + dictionaryKind = 1; + break; + } + default: + if (elementCount == 1 && prefixCount == 0 && *elements >= 0xEFF1 && + *elements <= 0xF010 && !contextEnabled) goto finishDictionaryPass; + dictionaryExact = 0; + if (languagePassCount == 2) { + for (index = dictionaryIndex + 1; index < ((ZiAlphaWork*)workData)->dictionaryCount; index++) { + if (((ZiAlphaWork*)workData)->dictionaryKinds[index] == 1 || + ((ZiAlphaWork*)workData)->dictionaryKinds[index] == 2 || + ((ZiAlphaWork*)workData)->dictionaryKinds[index] == 4 || + ((ZiAlphaWork*)workData)->dictionaryKinds[index] == 3) { + switchedLanguage = 1; + break; + } + } + if (index >= ((ZiAlphaWork*)workData)->dictionaryCount) { + languagePassCount = 1; + language = parameters->subLanguage; + dictionaryStatus[1] = 0; + dictionaryStatus[2] = 0; + dictionaryStatus[3] = 0; + dictionaryStatus[4] = 0; + dictionaryStatus[9] = 0; + dictionaryStatus[5] = 0; + dictionaryStatus[6] = 0; + dictionaryStatus[7] = 0; + dictionaryStatus[8] = 0; + completionAllowed = secondaryCompletionAllowed; + currentVowelRestriction = secondaryVowelRestriction; + goto prepareDictionaries; + } + } + if (languagePassCount == 1) { + language = parameters->language; + completionAllowed = primaryCompletionAllowed; + currentVowelRestriction = primaryVowelRestriction; + } + break; + case 1: + case 2: + break; } do { wordLength = 0; matchMode = dictionaryExact; switch(dictionaryKind) { - case 1: - case 5: - goto matchRomDictionary; - case 2: - case 6: - if (elementCount != 0) { - wordLength = Zi8MatchPUDdata(elements,elementCount & 0xff,language,wordCursor, - wordCapacity & 0xffff,dictionaryExact, - dictionaryStatus[dictionaryKind] & 0xff,workData); - wordLength = wordLength & 0xff; - } - break; - case 3: - case 7: - while( ZI8_TRUE ) { - wordLength = Zi8MatchUWDdata(elements,elementCount & 0xff, - parameters->currentWord,parameters->wordCharCount, - language,wordCursor,wordCapacity & 0xffff,dictionaryExact, - dictionaryStatus[dictionaryKind] & 0xff,workData); - wordLength = wordLength & 0xff; - if (((elementCount != 0) || (wordLength != 1)) || (*wordCursor != 0x20)) break; - dictionaryStatus[dictionaryKind] = 1; - } - break; - case 4: - case 8: - if (elementCount != 0) { - wordLength = Zi8MatchOEMdata(elements,elementCount & 0xff,language,wordCursor, - wordCapacity & 0xffff,dictionaryExact, - dictionaryStatus[dictionaryKind] & 0xff,workData); - wordLength = wordLength & 0xff; - } - break; case 9: matchMode = 2; -matchRomDictionary: + case 1: + case 5: if (elementCount == 0) break; if ((((matchMode == 0) && (completionAllowed)) && ((2 < (int)elementCount && @@ -971,23 +889,20 @@ matchRomDictionary: } else { if (alternateSingleCharacter != 2) { - wordLength = Zi8MatchROMdata(elements,elementCount & 0xff,language,wordCursor, + wordLength = (ziU8)Zi8MatchROMdata(elements,elementCount & 0xff,language,wordCursor, wordCapacity & 0xffff,matchMode, dictionaryStatus[dictionaryKind] & 0xff,0,exactLengthOnly,workData); - wordLength = wordLength & 0xff; - } + } if ((alternateSingleCharacter != 0) && ((wordLength == 0 || (*wordCursor == *elements)))) { if (alternateSingleCharacter == 1) { alternateSingleCharacter = 2; - wordLength = Zi8MatchROMdata(elements,elementCount & 0xff,parameters->subLanguage,wordCursor, + wordLength = (ziU8)Zi8MatchROMdata(elements,elementCount & 0xff,parameters->subLanguage,wordCursor, wordCapacity & 0xffff,1,0,0,exactLengthOnly,workData); - wordLength = wordLength & 0xff; - } + } else { - wordLength = Zi8MatchROMdata(elements,elementCount & 0xff,parameters->subLanguage,wordCursor, + wordLength = (ziU8)Zi8MatchROMdata(elements,elementCount & 0xff,parameters->subLanguage,wordCursor, wordCapacity & 0xffff,1,1,0,exactLengthOnly,workData); - wordLength = wordLength & 0xff; - } + } } } if ((dictionaryExact != 0) && ((int)elementCount < (int)wordLength)) { @@ -1003,21 +918,21 @@ matchRomDictionary: } if (((apostropheIndex != 0) && (wordLength != 0)) && (elementCount == parameters->elementCount)) { if (language == 0x2f) { - matched = Zi8ITspecialExclusion + index = Zi8ITspecialExclusion (wordCursor + apostropheIndex,apostropheIndex,wordLength - apostropheIndex); - if (matched != '\0') { + if (index != '\0') { wordLength = 0; } } else if (language == 0x58) { - matched = Zi8_814659E8(wordCursor + apostropheIndex,apostropheIndex,wordLength - apostropheIndex); - if (matched != '\0') { + index = Zi8_814659E8(wordCursor + apostropheIndex,apostropheIndex,wordLength - apostropheIndex); + if (index != '\0') { wordLength = 0; } } else { - matched = Zi8IsVowel(language,wordCursor[apostropheIndex]); - if (matched == '\0') { + index = Zi8IsVowel(language,wordCursor[apostropheIndex]); + if (index == '\0') { wordLength = 0; } } @@ -1027,27 +942,27 @@ matchRomDictionary: goto finishDictionaryPass; } filterVowelCandidate: - if ((wordLength != 0) && (vowelRestriction)) { + if ((wordLength != 0) && (prefixVowelRestriction)) { if ((*wordCursor < 0x30) || (0x39 < *wordCursor)) { if (((elementCount == 1) && (dictionaryKind != 10)) && (0xeff0 < *wordCursor)) { punctuationCandidate = ZI8_TRUE; goto finishDictionaryPass; } if (language == 0x2f) { - matched = Zi8ITspecialExclusion(wordCursor,prefixCount,wordLength); - if (matched != '\0') { + index = Zi8ITspecialExclusion(wordCursor,prefixCount,wordLength); + if (index != '\0') { wordLength = 0; } } else if (language == 0x58) { - matched = Zi8_814659E8(wordCursor,prefixCount,wordLength); - if (matched != '\0') { + index = Zi8_814659E8(wordCursor,prefixCount,wordLength); + if (index != '\0') { wordLength = 0; } } else { - matched = Zi8IsVowel(language,*wordCursor); - if (matched == '\0') { + index = Zi8IsVowel(language,*wordCursor); + if (index == '\0') { wordLength = 0; } } @@ -1070,10 +985,37 @@ filterVowelCandidate: } Zi8IsZicorpSignature(wordCursor,wordLength,workData); break; + case 2: + case 6: + if (elementCount != 0) { + wordLength = (ziU8)Zi8MatchPUDdata(elements,elementCount & 0xff,language,wordCursor, + wordCapacity & 0xffff,dictionaryExact, + dictionaryStatus[dictionaryKind] & 0xff,workData); + } + break; + case 3: + case 7: + while( ZI8_TRUE ) { + wordLength = (ziU8)Zi8MatchUWDdata(elements,elementCount & 0xff, + parameters->currentWord,parameters->wordCharCount, + language,wordCursor,wordCapacity & 0xffff,dictionaryExact, + dictionaryStatus[dictionaryKind] & 0xff,workData); + if (((elementCount != 0) || (wordLength != 1)) || (*wordCursor != 0x20)) break; + dictionaryStatus[dictionaryKind] = 1; + } + break; + case 4: + case 8: + if (elementCount != 0) { + wordLength = (ziU8)Zi8MatchOEMdata(elements,elementCount & 0xff,language,wordCursor, + wordCapacity & 0xffff,dictionaryExact, + dictionaryStatus[dictionaryKind] & 0xff,workData); + } + break; case 10: - character = *punctuationCursor; - *wordCursor = character; - if (character == 0) { + index = *punctuationCursor; + *wordCursor = index; + if (index == 0) { wordLength = 0; } else { @@ -1085,19 +1027,18 @@ filterVowelCandidate: if (prefixCount == 0) { if (retryPunctuation) { for (index = 0; - (index < (int)(parameters->elementCount - 1) && - (wordCursor[index] = ((ZiAlphaWork*)workData)->prefix[index], - wordCursor[index] != 0)); index = index + 1) { + index < parameters->elementCount - 1; index++) { + wordCursor[index] = ((ZiAlphaWork*)workData)->prefix[index]; + if (wordCursor[index] == 0) break; } if (index < (int)(parameters->elementCount - 1)) { wordLength = 0; } else { appendPunctuation: - character = *punctuationCursor; wordLength = index + 1; - wordCursor[index] = character; - if (character == 0) { + wordCursor[index] = *punctuationCursor; + if (wordCursor[index] == 0) { wordLength = 0; } else { @@ -1107,9 +1048,9 @@ appendPunctuation: } else { for (index = 0; - (index < (int)(unsigned int)((ZiAlphaWork*)workData)->rememberedCount && - (wordCursor[index] = ((ZiAlphaWork*)workData)->rememberedWord[index], - wordCursor[index] != 0)); index = index + 1) { + index < ((ZiAlphaWork*)workData)->rememberedCount; index++) { + wordCursor[index] = ((ZiAlphaWork*)workData)->rememberedWord[index]; + if (wordCursor[index] == 0) break; } if ((int)(unsigned int)((ZiAlphaWork*)workData)->rememberedCount <= index) goto appendPunctuation; wordLength = 0; @@ -1131,10 +1072,10 @@ appendPunctuation: (((ZiAlphaOptions*)optionData)->lookupMode == '\0')) && (((ZiAlphaWork*)workData)->dictionaries[language] == 0)))))) { if (language != ((ZiAlphaWork*)workData)->language) break; - characterCount = ((ZiAlphaWork*)workData)->dictionaryKinds[dictionaryIndex + 1]; - if ((characterCount == 0xc) || (((characterCount < 0xc && (characterCount < 9)) && (4 < characterCount)))) { - matched = Zi8getKeyLayout(language,0xeff1,&punctuationBuffer[0],1,workData); - if (matched == '\0') { + index = ((ZiAlphaWork*)workData)->dictionaryKinds[dictionaryIndex + 1]; + if ((index == 0xc) || (((index < 0xc && (index < 9)) && (4 < index)))) { + index = Zi8getKeyLayout(language,0xeff1,&punctuationBuffer[0],1,workData); + if (index == '\0') { punctuationBuffer[0] = 0; } punctuationCursor = &punctuationBuffer[0]; @@ -1152,33 +1093,28 @@ appendPunctuation: (((((ZiAlphaWork*)workData)->rememberedWord[0] == 0 || (((ZiAlphaOptions*)optionData)->lookupMode != '\0')) || (((ZiAlphaWork*)workData)->dictionaries[language] != 0)))))) || (languagePassCount == 2)))) break; - characterCount = ((ZiAlphaWork*)workData)->dictionaryKinds[dictionaryIndex + 1]; - if ((characterCount != 0xc) && (((0xb < characterCount || (8 < characterCount)) || (characterCount < 5)))) break; - matched = Zi8getKeyLayout(language,0xeff1,&punctuationBuffer[0],1,workData); - if (matched == '\0') { + index = ((ZiAlphaWork*)workData)->dictionaryKinds[dictionaryIndex + 1]; + if ((index != 0xc) && (((0xb < index || (8 < index)) || (index < 5)))) break; + index = Zi8getKeyLayout(language,0xeff1,&punctuationBuffer[0],1,workData); + if (index == '\0') { punctuationBuffer[0] = 0; } punctuationCursor = &punctuationBuffer[0]; dictionaryKind = 0xb; } else if ((int)(unsigned int)(ziU8)((ZiAlphaOptions*)optionData)->minWordLength <= (int)wordLength) { - if (vowelRestriction) { - if ((*wordCursor < 0x30) || (0x39 < *wordCursor)) { - if (language == 0x2f) { - matched = Zi8ITspecialExclusion(wordCursor,prefixCount,wordLength); - } - else { - if (language != 0x58) { - matched = Zi8IsVowel(language,*wordCursor); - if (matched != '\0') goto prepareCandidate; - goto retryDictionary; - } - matched = Zi8_814659E8(wordCursor,prefixCount,wordLength); - } - if (matched == '\0') goto prepareCandidate; + if (prefixVowelRestriction) { + if (*wordCursor >= 0x30 && *wordCursor <= 0x39) goto retryDictionary; + if (language == 0x2f) { + if (Zi8ITspecialExclusion(wordCursor,prefixCount,wordLength) != 0) goto retryDictionary; + } else if (language == 0x58) { + if (Zi8_814659E8(wordCursor,prefixCount,wordLength) != 0) goto retryDictionary; + } else if (Zi8IsVowel(language,*wordCursor) == 0) { + wordLength = 0; + goto retryDictionary; } } - else { + { prepareCandidate: if (((elementCount == 1) && (dictionaryKind != 10)) && ((0xeff0 < *wordCursor && (*wordCursor < 0xf011)))) { @@ -1191,17 +1127,15 @@ prepareCandidate: wordLength = elementCount; wordCursor[elementCount] = 0; } - candidateLength = Zi8DeTokenization(wordCursor,wordLength & 0xffff,wordCapacity & 0xffff, - language); - wordLength = candidateLength & 0xffff; - if (((phoneticInput) && ((unsigned int)parameters->elementCount < (candidateLength & 0xff))) && + wordLength = (ziU16)Zi8DeTokenization(wordCursor,wordLength & 0xffff,wordCapacity & 0xffff,language); + if (((phoneticInput) && ((unsigned int)parameters->elementCount < (wordLength & 0xff))) && ((wordCursor[wordLength - 1] == 0xf360 || (wordCursor[wordLength - 1] == 0x27)))) { wordLength = wordLength - 1; wordCursor[wordLength] = 0; } if ((!phoneticSeparator) || - (matched = Zi8ZHCheckSpelling(wordCursor,parameters->elements,parameters->elementCount, - workData), matched != '\0')) { + ((Zi8ZHCheckSpelling(wordCursor,parameters->elements,parameters->elementCount, + workData)) != '\0')) { if ((((ZiAlphaWork*)workData)->caseMode != '\0') && ((!phoneticInput && (!phoneticSeparator)))) { Zi8ChangeWordCase(wordCursor + -prefixCount,language,workData); } @@ -1211,52 +1145,45 @@ prepareCandidate: wordCursor[wordLength] = 0; } if (((int)(unsigned int)(ziU8)((ZiAlphaOptions*)optionData)->maxWordLength < (int)(wordLength + prefixCount)) || - (matched = Zi8IsDupWordW(wordCursor + -prefixCount,wordLength + prefixCount & 0xff, - workData), matched != '\0')) { + ((Zi8IsDupWordW(wordCursor + -prefixCount,wordLength + prefixCount & 0xff, + workData)) != '\0')) { if ((prefixCount != 0) && ((ziU8)((ZiAlphaOptions*)optionData)->maxWordLength <= prefixCount)) break; } else { - matched = (char)wordLength; - prefixCharacterCount = (char)prefixCount; + if ((((keyLayoutCount == 0) || (((ZiAlphaOptions*)optionData)->lookupMode != '\0')) || ((int)(wordLength + prefixCount) < 2)) || (0x40 < (int)(wordLength + prefixCount))) goto emitCandidate; if (dictionaryKind == 5) { checkKeyLayout: keyLayoutCursor = keyLayout; - characterCount = matched + prefixCharacterCount; - for (candidateLength = 0; (int)candidateLength < (int)(unsigned int)keyLayoutCount; candidateLength = candidateLength + 1) { - if (characterCount <= *keyLayoutCursor) { - encodedCursor = keyLayoutCursor + 1; - encodedCharacter = *keyLayoutCursor; - keyLayoutCursor = encodedCursor; - if (characterCount < encodedCharacter) { - candidateLength = (unsigned int)keyLayoutCount; + candidateCharacterCount = wordLength + prefixCount; + for (index = 0; (int)index < (int)(unsigned int)keyLayoutCount; index = index + 1) { + if (candidateCharacterCount <= *keyLayoutCursor) { + if (candidateCharacterCount < *keyLayoutCursor++) { + index = (unsigned int)keyLayoutCount; } break; } keyLayoutCursor = keyLayoutCursor + *keyLayoutCursor + 1; } - if ((int)candidateLength < (int)(unsigned int)keyLayoutCount) { - for (elementIndex = 0; (int)elementIndex < (int)(unsigned int)characterCount; + if ((int)index < (int)(unsigned int)keyLayoutCount) { + for (elementIndex = 0; (int)elementIndex < (int)(unsigned int)candidateCharacterCount; elementIndex = elementIndex + 1) { - encodedCharacter = Zi8ConvertWC2UC(wordCursor[elementIndex - prefixCount],language, - workData); - candidateBytes[elementIndex] = encodedCharacter; + candidateBytes[elementIndex] = Zi8ConvertWC2UC(wordCursor[elementIndex - prefixCount],language,workData); } - for (; (int)candidateLength < (int)(unsigned int)keyLayoutCount; candidateLength = candidateLength + 1) { + for (; (int)index < (int)(unsigned int)keyLayoutCount; index = index + 1) { for (elementIndex = 0; - ((int)elementIndex < (int)(unsigned int)characterCount && + ((int)elementIndex < (int)(unsigned int)candidateCharacterCount && (candidateBytes[elementIndex] == keyLayoutCursor[elementIndex])); elementIndex = elementIndex + 1) { } - if (elementIndex == characterCount) { + if (elementIndex == candidateCharacterCount) { wordCursor[-prefixCount] = 0; goto retryDictionary; } - encodedCursor = keyLayoutCursor + characterCount; - keyLayoutCursor = encodedCursor + 1; - if (characterCount < *encodedCursor) break; + keyLayoutCursor += candidateCharacterCount; + if (candidateCharacterCount < *keyLayoutCursor++) break; } } } @@ -1267,7 +1194,21 @@ checkKeyLayout: emitCandidate: if (firstCandidate == 0) { if (((ZiAlphaOptions*)optionData)->countOnly == '\0') { - if (((ZiAlphaOptions*)optionData)->lookupMode == '\0') { + if (((ZiAlphaOptions*)optionData)->lookupMode != '\0') { + for (index = 0; + (index <= (int)wordLength && + (wordCursor[index] == ((ZiAlphaOptions*)optionData)->dictionary[index])); + index = index + 1) { + } + if ((((((ZiAlphaWork*)workData)->operation != '\0') || ((int)wordLength <= index)) + && ((((ZiAlphaWork*)workData)->operation == '\0' || + ((exactLengthOnly == 0 || + ((int)(ziU16)Zi8WCharCount(((ZiAlphaOptions*)optionData)->dictionary,workData) <= index)))))) && + ((exactLengthOnly != 0 || ((int)wordLength <= index)))) { + candidateCount = 1; + goto finishCandidates; + } + } else { if (((((ZiAlphaWork*)workData)->suffixMode == '\0') && (wordCursor[1] == 0)) && (candidateCount == 0)) { if ((*wordCursor < 0xeff1) || (0xf010 < *wordCursor)) { @@ -1287,9 +1228,9 @@ emitCandidate: } } else { - for (characterIndex = 0; (int)characterIndex < (int)prefixCount; characterIndex = characterIndex + 1) { - ((ZiAlphaWork*)workData)->rememberedWord[characterIndex] - = wordCursor[characterIndex - prefixCount]; + for (index = 0; (int)index < (int)prefixCount; index = index + 1) { + ((ZiAlphaWork*)workData)->rememberedWord[index] + = wordCursor[index - prefixCount]; } for (index = 0; index < (int)wordLength; index = index + 1) { ((ZiAlphaWork*)workData)->rememberedWord[index + prefixCount] = @@ -1307,7 +1248,7 @@ emitCandidate: for (index = 0; index < (int)wordLength; index = index + 1) { ((ZiAlphaWork*)workData)->prefix[index] = wordCursor[index]; } - ((ZiAlphaWork*)workData)->prefixCount = matched; + ((ZiAlphaWork*)workData)->prefixCount = wordLength; ((ZiAlphaWork*)workData)->language = language; } else if ((((ZiAlphaWork*)workData)->suffixLocked == '\0') && @@ -1322,13 +1263,13 @@ emitCandidate: for (index = 0; index < (int)wordLength; index = index + 1) { ((ZiAlphaWork*)workData)->prefix[index] = wordCursor[index]; } - ((ZiAlphaWork*)workData)->prefixCount = matched; + ((ZiAlphaWork*)workData)->prefixCount = wordLength; } else { for (index = 0; index < (int)wordLength; index = index + 1) { ((ZiAlphaWork*)workData)->suffix[index] = wordCursor[index]; } - ((ZiAlphaWork*)workData)->suffixCount = matched; + ((ZiAlphaWork*)workData)->suffixCount = wordLength; } } else if ((((ZiAlphaWork*)workData)->suffixMode != '\0') && @@ -1343,7 +1284,7 @@ emitCandidate: for (index = 0; index < (int)wordLength; index = index + 1) { ((ZiAlphaWork*)workData)->alternatePrefix[index] = wordCursor[index]; } - ((ZiAlphaWork*)workData)->alternatePrefixCount = (char)index; + ((ZiAlphaWork*)workData)->alternatePrefixCount = (ziU8)index; } wordLength = wordLength + 1; if ((parameters->getOptions & 0xfd) == 0x80) { @@ -1352,9 +1293,7 @@ emitCandidate: } for (index = 0; index < (int)(wordLength + prefixCount); index = index + 1) { - outputCharacter = Zi8ConvertWC2UC(wordCursor[index - prefixCount],language, - workData); - encodedOutput[index] = outputCharacter; + encodedOutput[index] = Zi8ConvertWC2UC(wordCursor[index - prefixCount],language,workData); } encodedOutput[index] = 0; encodedOutput = encodedOutput + index; @@ -1363,11 +1302,11 @@ emitCandidate: if (((ZiAlphaOptions*)optionData)->suffixOnly != '\0') { wordCursor = wordCursor + -prefixCount; wordCapacity = wordCapacity + prefixCount; - index = wordLength + prefixCount; - for (wordLength = 0; (int)(parameters->elementCount + wordLength) < index; - wordLength = wordLength + 1) { - wordCursor[wordLength] = wordCursor[wordLength + parameters->elementCount]; + wordLength += prefixCount; + for (index = 0; parameters->elementCount + index < wordLength; index++) { + wordCursor[index] = wordCursor[index + parameters->elementCount]; } + wordLength = index; } wordCursor[wordLength] = 0; wordCursor = wordCursor + wordLength; @@ -1404,30 +1343,14 @@ emitCandidate: } } } - else { - for (index = 0; - (index <= (int)wordLength && - (wordCursor[index] == ((ZiAlphaOptions*)optionData)->dictionary[index])); - index = index + 1) { - } - if ((((((ZiAlphaWork*)workData)->operation != '\0') || ((int)wordLength <= index)) - && ((((ZiAlphaWork*)workData)->operation == '\0' || - ((exactLengthOnly == 0 || - (candidateLength = Zi8WCharCount(((ZiAlphaOptions*)optionData)->dictionary,workData), - (int)(candidateLength & 0xffff) <= index)))))) && - ((exactLengthOnly != 0 || ((int)wordLength <= index)))) { - candidateCount = 1; - goto finishCandidates; - } - } } else { if (((ZiAlphaOptions*)optionData)->suffixOnly != '\0') { if ((int)(wordLength + prefixCount) < (int)(unsigned int)(ziU8)((ZiAlphaOptions*)optionData)->shortestWord) { - ((ZiAlphaOptions*)optionData)->shortestWord = matched + prefixCharacterCount; + ((ZiAlphaOptions*)optionData)->shortestWord = wordLength + prefixCount; } if ((int)(unsigned int)(ziU8)((ZiAlphaOptions*)optionData)->longestWord < (int)(wordLength + prefixCount)) { - ((ZiAlphaOptions*)optionData)->longestWord = matched + prefixCharacterCount; + ((ZiAlphaOptions*)optionData)->longestWord = wordLength + prefixCount; } } candidateCount = candidateCount + 1; @@ -1442,20 +1365,24 @@ emitCandidate: } } retryDictionary:; - } while (dictionaryIndex != 0); + } while (dictionaryKind != 0); } } + } else { + if (((ZiAlphaOptions*)optionData)->lookupMode == '\0') { + dictionaryKind = 10; + goto selectDictionary; + } } finishDictionaryPass:; } if ((((candidateCount == 0) && (!punctuationCandidate)) && ((parameters->firstCandidate == 0 && (((parameters->elementCount == 1 && - (candidateLength = Zi8GetTableCount(parameters->language,0x1f,workData), (candidateLength & 0x40) == 0)) && - (0xeff0 < *parameters->elements)))))) && + (((Zi8GetTableCount(parameters->language,0x1f,workData)) & 0x40) == 0)) && + (*parameters->elements >= 0xeff1)))))) && ((*parameters->elements < 0xf011 && - (matched = Zi8getKeyLayout(parameters->language,*parameters->elements,&punctuationBuffer[0],1,workData), - matched != '\0')))) { + ((Zi8getKeyLayout(parameters->language,*parameters->elements,&punctuationBuffer[0],1,workData)) != '\0')))) { punctuationCandidate = ZI8_TRUE; } if (((candidateCount == 0) && (punctuationCandidate)) && (firstCandidate == 0)) { @@ -1490,6 +1417,7 @@ finishDictionaryPass:; dictionaryStatus[7] = 0; dictionaryStatus[8] = 0; completionAllowed = secondaryCompletionAllowed; + currentVowelRestriction = secondaryVowelRestriction; if (switchedLanguage) { secondLanguagePass = ZI8_FALSE; dictionaryStatus[1] = 0; @@ -1504,12 +1432,12 @@ finishDictionaryPass:; language = parameters->language; } completionAllowed = secondaryCompletionAllowed; - vowelRestriction = secondaryVowelRestriction; + currentVowelRestriction = secondaryVowelRestriction; if (language == parameters->language) { completionAllowed = primaryCompletionAllowed; - vowelRestriction = (primaryTableFlags & 2) == 0; + currentVowelRestriction = primaryVowelRestriction; } - if ((((ZiAlphaOptions*)optionData)->lookupMode != '\0') || ((!vowelRestriction && (!completionAllowed)))) goto finishCandidates; + if ((((ZiAlphaOptions*)optionData)->lookupMode != '\0') || ((!currentVowelRestriction && (!completionAllowed)))) goto finishCandidates; if ((completionAllowed) && ((((((ZiAlphaWork*)workData)->suffixMode == '\0' && (2 < (int)elementCount)) && (elements[elementCount - 2] == 0xeff1)) && @@ -1517,8 +1445,8 @@ finishDictionaryPass:; ((ZiAlphaWork*)workData)->prefixElementCount = ((ZiAlphaWork*)workData)->prefixCount + '\x01'; ((ZiAlphaWork*)workData)->suffixMode = 1; } - if ((((ZiAlphaWork*)workData)->suffixMode != '\0') && (!prefixActive)) { - prefixActive = ZI8_TRUE; + if ((((ZiAlphaWork*)workData)->suffixMode != '\0') && (!prefixPrepared)) { + prefixPrepared = ZI8_TRUE; goto preparePrefix; } if ((((completionAllowed) && (((ZiAlphaWork*)workData)->suffixMode != '\0')) && @@ -1526,7 +1454,7 @@ finishDictionaryPass:; (((elements[elementCount - 2] == 0xeff1 && ((unsigned int)((ZiAlphaWork*)workData)->suffixCount == elementCount - 2)) || (((unsigned int)((ZiAlphaWork*)workData)->suffixCount == elementCount - 1 && - (matched = Zi8IsAlphaPunct(elements[elementCount - 1]), matched != '\0')))))) { + ((Zi8IsAlphaPunct(elements[elementCount - 1])) != '\0')))))) { if ((((ZiAlphaWork*)workData)->prefixEnabled == '\0') || (elements[elementCount - 1] != 0xeff1)) { if ((!primaryMatched) && (!secondaryMatched)) { ((ZiAlphaWork*)workData)->suffixLocked = 1; @@ -1547,24 +1475,34 @@ checkPrefixPunctuation: (parameters->elements[parameters->elementCount - 1] != 0xEFF1)) goto finishCandidates; if ((((*elements == 0xeff1) || - (matched = ZiIsLetterHyphen(*elements,workData), matched != '\0')) && + ((ZiIsLetterHyphen(*elements,workData)) != '\0')) && ((((ZiAlphaWork*)workData)->suffixLocked == '\0' || - (matched = ZiIsLetterHyphen(((ZiAlphaWork*)workData)->suffix[(((ZiAlphaWork*)workData)->suffixCount - 1)], - workData), matched == '\0')))) && + ((ZiIsLetterHyphen(((ZiAlphaWork*)workData)->suffix[(((ZiAlphaWork*)workData)->suffixCount - 1)], + workData)) == '\0')))) && (((((ZiAlphaWork*)workData)->suffixMode == '\0' || ((((ZiAlphaWork*)workData)->suffixLocked != '\0' || - (matched = ZiIsLetterHyphen(((ZiAlphaWork*)workData)->prefix[((ZiAlphaWork*)workData)->prefixCount - 1], - workData), matched == '\0')))) && - ((candidateLength = Zi8GetTableCount(language,0x1f,workData), (candidateLength & 8) == 0 && + ((ZiIsLetterHyphen(((ZiAlphaWork*)workData)->prefix[((ZiAlphaWork*)workData)->prefixCount - 1], + workData)) == '\0')))) && + ((((Zi8GetTableCount(language,0x1f,workData)) & 8) == 0 && (parameters->elements[parameters->elementCount - 1] != 0xEFF1)))))) { - if (prefixActive) { + if (prefixPrepared) { wordCursor = wordCursor + -prefixCount; elements = elements + -prefixCount; elementCount = elementCount + prefixCount; wordCapacity = wordCapacity + prefixCount; prefixCount = 0; } - if (((ZiAlphaWork*)workData)->suffixLocked == '\0') { + if (((ZiAlphaWork*)workData)->suffixLocked != '\0') { + ((ZiAlphaWork*)workData)->previousSuffixCount = ((ZiAlphaWork*)workData)->suffixElementCount; + ((ZiAlphaWork*)workData)->suffixElementCount = parameters->elementCount; + elementIndex = (unsigned int)((ZiAlphaWork*)workData)->prefixCount + (unsigned int)((ZiAlphaWork*)workData)->suffixCount; + if (elements[elementIndex] != 0xEFF1 && Zi8IsAlphaPunct(elements[elementIndex]) != 0) { + ((ZiAlphaWork*)workData)->suffix[((ZiAlphaWork*)workData)->suffixCount++] = elements[elementIndex]; + } else { + ((ZiAlphaWork*)workData)->suffix[((ZiAlphaWork*)workData)->suffixCount++] = ((ZiAlphaWork*)workData)->letterHyphen; + } + prefixPrepared = ZI8_TRUE; + } else { ((ZiAlphaWork*)workData)->previousPrefixCount = ((ZiAlphaWork*)workData)->prefixElementCount; ((ZiAlphaWork*)workData)->prefixElementCount = parameters->elementCount; if (((ZiAlphaWork*)workData)->suffixMode == '\0') { @@ -1573,46 +1511,23 @@ checkPrefixPunctuation: } if (((((((ZiAlphaWork*)workData)->prefixCount == '\x03') && (((ZiAlphaWork*)workData)->prefix[0] == 0x77)) && (((ZiAlphaWork*)workData)->prefix[1] == 0x77)) && (((ZiAlphaWork*)workData)->prefix[2] == 0x77)) || - (candidateLength = Zi8GetTableCount(language,0x1f,workData), (candidateLength & 0x100) != 0)) { + (((Zi8GetTableCount(language,0x1f,workData)) & 0x100) != 0)) { ((ZiAlphaWork*)workData)->letterHyphen = 0x2e; } - if ((elements[((ZiAlphaWork*)workData)->prefixCount] == 0xeff1) || - (matched = Zi8IsAlphaPunct(elements[((ZiAlphaWork*)workData)->prefixCount]), matched == '\0')) { - characterCount = ((ZiAlphaWork*)workData)->prefixCount; - ((ZiAlphaWork*)workData)->prefix[characterCount] = ((ZiAlphaWork*)workData)->letterHyphen; - ((ZiAlphaWork*)workData)->prefixCount = characterCount + 1; + if (elements[((ZiAlphaWork*)workData)->prefixCount] != 0xEFF1 && Zi8IsAlphaPunct(elements[((ZiAlphaWork*)workData)->prefixCount]) != 0) { + ((ZiAlphaWork*)workData)->prefix[((ZiAlphaWork*)workData)->prefixCount] = elements[((ZiAlphaWork*)workData)->prefixCount]; + ((ZiAlphaWork*)workData)->prefixCount++; + } else { + ((ZiAlphaWork*)workData)->prefix[((ZiAlphaWork*)workData)->prefixCount++] = ((ZiAlphaWork*)workData)->letterHyphen; } - else { - characterCount = ((ZiAlphaWork*)workData)->prefixCount; - ((ZiAlphaWork*)workData)->prefix[characterCount] = elements[((ZiAlphaWork*)workData)->prefixCount] - ; - ((ZiAlphaWork*)workData)->prefixCount = characterCount + 1; - } - prefixActive = ZI8_TRUE; - } - else { - ((ZiAlphaWork*)workData)->previousSuffixCount = ((ZiAlphaWork*)workData)->suffixElementCount; - ((ZiAlphaWork*)workData)->suffixElementCount = parameters->elementCount; - index = (unsigned int)((ZiAlphaWork*)workData)->prefixCount + (unsigned int)((ZiAlphaWork*)workData)->suffixCount; - if ((elements[index] == 0xeff1) || - (matched = Zi8IsAlphaPunct(elements[index]), matched == '\0')) { - characterCount = ((ZiAlphaWork*)workData)->suffixCount; - ((ZiAlphaWork*)workData)->suffix[(unsigned int)characterCount] = ((ZiAlphaWork*)workData)->letterHyphen; - ((ZiAlphaWork*)workData)->suffixCount = characterCount + 1; - } - else { - characterCount = ((ZiAlphaWork*)workData)->suffixCount; - ((ZiAlphaWork*)workData)->suffix[(unsigned int)characterCount] = elements[index]; - ((ZiAlphaWork*)workData)->suffixCount = characterCount + 1; - } - prefixActive = ZI8_TRUE; + prefixPrepared = ZI8_TRUE; } goto preparePrefix; } } else { tryAlternatePrefix: - if ((prefixActive) && (1 < ((ZiAlphaWork*)workData)->alternatePrefixCount)) { + if ((prefixPrepared) && (1 < ((ZiAlphaWork*)workData)->alternatePrefixCount)) { if (language == parameters->language) { if (primaryMatched) { ((ZiAlphaWork*)workData)->alternatePrefixCount = 0; @@ -1627,7 +1542,7 @@ tryAlternatePrefix: elementCount = elementCount + prefixCount; wordCapacity = wordCapacity + prefixCount; prefixCount = 0; - prefixActive = ZI8_FALSE; + prefixPrepared = ZI8_FALSE; ((ZiAlphaWork*)workData)->suffixMode = 0; ((ZiAlphaWork*)workData)->suffixLocked = 0; ((ZiAlphaWork*)workData)->suffixCount = 0; @@ -1635,7 +1550,7 @@ tryAlternatePrefix: ((ZiAlphaWork*)workData)->prefix[index] = ((ZiAlphaWork*)workData)->alternatePrefix[index]; } - ((ZiAlphaWork*)workData)->prefixCount = (char)index; + ((ZiAlphaWork*)workData)->prefixCount = (ziU8)index; if (((ZiAlphaWork*)workData)->language == parameters->language) { ((ZiAlphaWork*)workData)->language = parameters->subLanguage; } @@ -1650,72 +1565,91 @@ tryAlternatePrefix: goto finishCandidates; if (completionAllowed) goto checkPrefixPunctuation; } - if (((((((vowelRestriction) || (((ZiAlphaWork*)workData)->suffixMode != '\0')) || - (((ZiAlphaWork*)workData)->prefixCount == '\0')) || - (((int)elementCount < 3 || ((unsigned int)((ZiAlphaWork*)workData)->prefixCount != elementCount - 1)))) || - (matched = Zi8IsAlphaPunct(parameters->elements[((ZiAlphaWork*)workData)->prefixCount - 1]), - matched == '\0')) && - (((!vowelRestriction && (((ZiAlphaWork*)workData)->suffixMode == '\0')) && - ((1 < parameters->elementCount && - (matched = Zi8IsAlphaPunct(parameters->elements[parameters->elementCount - 1]), - matched == '\0')))))) || - ((((((ZiAlphaWork*)workData)->suffixMode != '\0' || (((ZiAlphaWork*)workData)->prefixCount == 0)) || - ((int)elementCount < 3)) || - (((unsigned int)((ZiAlphaWork*)workData)->prefixCount != elementCount - 1 || - (parameters->elements[parameters->elementCount - 1] == 0xEFF1)))))) - goto finishCandidates; + if (!completionAllowed && ((ZiAlphaWork*)workData)->suffixMode == 0 && ((ZiAlphaWork*)workData)->prefixCount != 0 && + elementCount > 2 && ((ZiAlphaWork*)workData)->prefixCount == elementCount - 1 && + Zi8IsAlphaPunct(parameters->elements[((ZiAlphaWork*)workData)->prefixCount - 1]) != 0) goto checkPrefixFields; + if (!completionAllowed && ((ZiAlphaWork*)workData)->suffixMode == 0 && parameters->elementCount > 1 && + Zi8IsAlphaPunct(parameters->elements[parameters->elementCount - 1]) == 0) goto finishCandidates; +checkPrefixFields: + prefixMode = ((ZiAlphaWork*)workData)->suffixMode; + prefixLength = ((ZiAlphaWork*)workData)->prefixCount; + if (prefixMode != 0 || prefixLength == 0 || elementCount <= 2 || + prefixLength != elementCount - 1 || parameters->elements[parameters->elementCount - 1] == 0xEFF1) goto finishCandidates; ((ZiAlphaWork*)workData)->suffixMode = 1; ((ZiAlphaWork*)workData)->prefixElementCount = parameters->elementCount; - prefixActive = ZI8_TRUE; -preparePrefix: - matched = ((ZiAlphaWork*)workData)->suffixMode; - character = Zi8GetTableCount(language,0x1f,workData); - if (((((language == 0x3f) || (language == 4)) || - ((language == 0x40 || ((language == 0x58 || (language == 0x2f)))))) && (matched != '\0') - ) && ((character & 0x10) != 0)) { - vowelRestriction = ZI8_TRUE; - } - else { - vowelRestriction = ZI8_FALSE; - } - if (((ZiAlphaWork*)workData)->suffixMode != '\0') { - secondLanguagePass = ZI8_FALSE; - if ((((ZiAlphaOptions*)optionData)->countOnly != '\0') || ((parameters->getOptions & 0xfd) != 0x81)) { - wordCursor = candidateWord; - wordCapacity = 0x40; - } - for (index = 0; index < 0xe; index = index + 1) { - dictionaryStatus[index] = 0; - } - for (index = 0; index < (int)(unsigned int)((ZiAlphaWork*)workData)->prefixCount; index = index + 1) { - wordCursor[index] = ((ZiAlphaWork*)workData)->prefix[index]; - if ((elements[index] != wordCursor[index]) && - (character = Zi8ConvertWC2Key(wordCursor[index],language,workData), - elements[index] != character)) goto finishCandidates; - } - wordCursor = wordCursor + ((ZiAlphaWork*)workData)->prefixCount; - elements = elements + ((ZiAlphaWork*)workData)->prefixCount; - elementCount = elementCount - ((ZiAlphaWork*)workData)->prefixCount; - wordCapacity = wordCapacity - ((ZiAlphaWork*)workData)->prefixCount; - prefixCount = (unsigned int)((ZiAlphaWork*)workData)->prefixCount; - if (((ZiAlphaWork*)workData)->suffixLocked != '\0') { - for (index = 0; index < (int)(unsigned int)((ZiAlphaWork*)workData)->suffixCount; index = index + 1) { - wordCursor[index] = ((ZiAlphaWork*)workData)->suffix[index]; - if ((elements[index] != wordCursor[index]) && - (character = Zi8ConvertWC2Key(wordCursor[index],language,workData), - elements[index] != character)) goto finishCandidates; - } - wordCursor = wordCursor + ((ZiAlphaWork*)workData)->suffixCount; - elements = elements + ((ZiAlphaWork*)workData)->suffixCount; - elementCount = elementCount - ((ZiAlphaWork*)workData)->suffixCount; - wordCapacity = wordCapacity - ((ZiAlphaWork*)workData)->suffixCount; - prefixCount = prefixCount + ((ZiAlphaWork*)workData)->suffixCount; - } - if ((vowelRestriction) && (wordCursor[-1] != 0x27)) { - vowelRestriction = ZI8_FALSE; - } - } - goto prepareDictionaryOrder; + prefixPrepared = ZI8_TRUE; + goto preparePrefix; + +finishCandidates: + ((ZiAlphaWork*)workData)->usePrefixAsElements = 0; + if (((ZiAlphaOptions*)optionData)->countOnly == '\0') { + parameters->letters = candidateCount; + } + else { + parameters->letters = 0; + } + wordCursor[-prefixCount] = 0; + if (((((ZiAlphaOptions*)optionData)->countOnly == '\0') && (((ZiAlphaOptions*)optionData)->lookupMode == '\0')) && (parameters->elementCount != 0)) { + elementIndex = parameters->elementCount - 1; + if (((primaryVowelRestriction) || (secondaryVowelRestriction)) && + ((((ZiAlphaWork*)workData)->prefixEnabled < 2 || + (parameters->elements[elementIndex] == 0xEFF1)))) { + index = 0; + for (; (-1 < (int)elementIndex && + (parameters->elements[elementIndex] == 0xEFF1)); + elementIndex = elementIndex + -1) { + index = index + 1; + } + if (index == 0) { + if (candidateCount != 0) { + ((ZiAlphaWork*)workData)->prefixEnabled = 0; + ((ZiAlphaWork*)workData)->requiredLength = 0; + } + } + else { + ((ZiAlphaWork*)workData)->prefixEnabled = (ziU8)index; + } + ((ZiAlphaWork*)workData)->requiredLength = parameters->elementCount; + } + if ((parameters->letters != 0) && (parameters->maxCandidates == 1)) { + if ((parameters->getOptions & 0x81) == 0x81) { + wordCursor = parameters->candidates; + } + else if (outputLanguage == 0) { + wordCursor = (ziU16 *)0x0; + } + else { + encodedOutput = (ziU8*)parameters->candidates; + wordCursor = candidateWord; + for (index = 0; encodedOutput[index] != '\0'; index = index + 1) { + wordCursor[index] = Zi8ConvertUC2WC(encodedOutput[index],outputLanguage,workData); + } + wordCursor[index] = 0; + } + if (wordCursor != (ziU16 *)0x0) { + Zi8SetHighlightedWordW(wordCursor,parameters->language,parameters->subLanguage,workData); + } + } + } + if (((ZiAlphaWork*)workData)->dictionaryCounts != 0) { + if ((int)dictionaryIndex < (int)(unsigned int)((ZiAlphaWork*)workData)->dictionaryCount) { + ((ZiAlphaWork*)workData)->dictionaryCounts[dictionaryIndex] = candidateCount; + } + else { + ((ZiAlphaWork*)workData)->dictionaryCounts[((ZiAlphaWork*)workData)->dictionaryCount - 1] = candidateCount; + } + countIndex = dictionaryIndex; + if ((int)(unsigned int)((ZiAlphaWork*)workData)->dictionaryCount <= (int)dictionaryIndex) { + countIndex = ((ZiAlphaWork*)workData)->dictionaryCount - 1; + } + for (; 0 < (int)countIndex; countIndex = countIndex - 1) { + ((ZiAlphaWork*)workData)->dictionaryCounts[countIndex] = + ((ZiAlphaWork*)workData)->dictionaryCounts[countIndex] - + ((ZiAlphaWork*)workData)->dictionaryCounts[countIndex - 1]; + } + } + Zi8LogError(100,workData); + return candidateCount; } diff --git a/tools/decomp-assist/zi81key.attempts.md b/tools/decomp-assist/zi81key.attempts.md index 28cf3b3e..43a03cb0 100644 --- a/tools/decomp-assist/zi81key.attempts.md +++ b/tools/decomp-assist/zi81key.attempts.md @@ -103,3 +103,38 @@ Starting this continuation: 4/9 instruction-exact, code 2588/21460, data 1160/13 - 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. + +## Complete-body continuation, 2026-09-30 + +Starting from f20fc7b8: spelling 59.97%, candidates 53.831455%; unit 4/9 exact. Spelling target frame is 0x90; the prior source used 0xb0. Recovered byte/halfword/pointer declaration order from stack accesses, separated the input-conversion flag from the pinyin flag, and reused the target's character and scan variables across their successive roles. Restored mode-selection address order, postfix expansion/output writes, and missing spelling-call result narrowing. Frame now 0x90, 1577/1700 instructions, 79.560585%; first exact divergence +0x1c is a register choice. Quick gate PASS, zero regressions, identical pool. + +Spelling address-order pass: restored a separate condition for every phonetic expansion store, including the target's fourth EFF5 expansion F316. Corrected increment forms, language-support branch direction, early returns, spelling length's shared stack slot, explicit comparison breaks, and the exact/extended table passes through the final return. Every target basic-block region is represented; there is no stub or omitted tail. 1697/1700 instructions, 96.225296%; first exact divergence +0x20 is register allocation. Remaining structural differences are a few result moves, output scan scheduling and the remaining-skip branch. Quick gate PASS, zero regressions. + +Spelling final scan attempt: restored highlighted-output increment scheduling, workspace length comparison operand order and the final remaining-candidate branch direction. 1696/1700, 96.82353%; first exact divergence +0x20. Kept the gain after quick gate PASS. The remaining four-instruction difference consists mainly of compiler-generated copies after calls and postfix stores; all table passes and exits are present. + +Candidates frame pass: recovered separate key-value/key-mask arrays, byte declaration order and the original shared scan index. Removed decompiler-only call-result locals and added typed OEM/PUD arguments. Recovered switch dispatches and sequential phrase cursor operations. 2451/2397 instructions, frame 0x160 versus target 0x140, 68.29662%. The remaining extra frame words are compiler-generated Boolean temporaries from comma expressions. Quick gate PASS; every previously exact function remains exact. + +Candidates prefix pass: expanded comma-expression Boolean tests into sequential table loads and checks, removing five compiler temporaries; frame now exactly 0x140. Restored charset switches and branches, key-value/mask writes, division, call-result narrowing and output operand order. 2390/2397 instructions, 72.67042%; first exact divergence +0x28 is a register choice. Quick gate PASS. Continuing through OEM, PUD, phrase, sorted ordinal, user ordinal and ordinary ordinal paths. + +Candidates OEM/PUD address-order pass: recovered typed byte-return dictionary calls, corrected key-mask activation, replaced reconstructed output labels with the original skip/word/character branches and postfix output indexing. Restored the OEM and PUD scan loops through their exhaustion paths. Frame remains 0x140; candidates 80.75636% versus 53.831455% at entry. Quick gate PASS, zero regressions, identical pool. + +Candidates phrase/sorted-ordinal passes: restored the context-count decrement after comparison, first phrase-ordinal consumption and charset scan from the saved entry cursor. Rebuilt each group before continuing. Recovered character-first duplicate filtering, word output, table-filter narrowing and sorted ordinal explicit loop breaks/output increments. Candidate score 82.131%, then 84.724236%, then 88.3033%; frame 0x140 throughout. Quick gate PASS, no regressions. + +Candidates final body pass: restored user-ordinal and ordinary-ordinal duplicate branches, byte/word emission, capacity exits and cursor increment order through the final return. Measured after each pass: 91.54819%, then 94.64998%. Both huge bodies now cover every target basic-block region; candidates frame 0x140 and first exact divergence +0x28 (register choice). Quick gate PASS, zero regressions. + +Near-match continuation: candidate byte narrowing/branch inversion combined scored 94.54735% and regressed the previously exact matcher to 98.96907%; restoring its tone parameter recovered the matcher but candidates remained 94.56404%. Isolated duplicate-result casts plus final postfix store scored 94.335%; both rejected, restoring 94.64998%. MatchAltSound1Key recovered address-order search labels and halfword table indices (98.2698%, 345/341), then correct integer offset and low-byte expression (99.80939%, 341/341); restored the search restart assignment. Quick gate PASS, zero regressions. + +Additional near-match trials after the complete-body pass: MatchAltSound1Key with a generic context argument and typed local alias retained 341/341 instructions and the same twelve register differences; reversing declarations produced fifty differences; postfix backward-search decrement retained the same twelve. Restored the best readable source: 99.82404%, 341/341, context and phonetic table base exchange r25/r26. All bodies remain complete. + +Additional near-match source trials in this continuation: + +- Zi8SpellingZY: decoded components as signed halfwords; 94.10569%, src 0x1f8 base 0x1ec insns 126/123. --- replace mine 8:10 base 8:9. +- Zi8SpellingZY: initialize length at declaration; 99.756096%, src 0x1ec base 0x1ec insns 123/123. diffs 6: [27, 28, 35, 36, 37, 38]. +- Zi8SpellingZY: explicit scan for loop; 99.756096%, src 0x1ec base 0x1ec insns 123/123. diffs 6: [27, 28, 35, 36, 37, 38]. +- Zi8SpellingPY: constant tone at declaration; 94.968155%, src 0x278 base 0x274 insns 158/157. --- delete mine 4:7 base 4:4. +- Zi8SpellingPY: decode all components in declaration order; 97.54777%, src 0x278 base 0x274 insns 158/157. --- replace mine 4:5 base 4:5. +- Zi8SpellingPY: explicit scan for loops; 97.038216%, src 0x278 base 0x274 insns 158/157. --- delete mine 4:5 base 4:4. + +Retained PY component initialization in declaration order: 97.54777% versus 97.038216% at entry, 158/157 instructions. Initializing length first restored the lower baseline score; constant tone worsened it. Quick gate PASS, zero regressions. ZY retains six table-base register differences; no rejected source variant remains. + +Final full gate over zi81key and zi8alpha: PASS, original DOL hash, identical pools, zero regressions, zero net forbidden patterns and readability warnings. zi81key remains 4/9 instruction-exact; exact code 2588/21460, exact data 1208/1388, weighted fuzzy 96.51463%. Entry exact data was 1160/1388. Final function scores: ZY 99.756096%, PY 97.54777%, alternate sound 99.82404%, spelling 96.82353%, candidates 94.64998%; the four exact functions remain exact. Both large bodies cover all original block regions. Remaining differences and rejected source variants are recorded above; no new exact function is claimed. diff --git a/tools/decomp-assist/zi8alpha.attempts.md b/tools/decomp-assist/zi8alpha.attempts.md index 53b4330d..0ae1e4bc 100644 --- a/tools/decomp-assist/zi8alpha.attempts.md +++ b/tools/decomp-assist/zi8alpha.attempts.md @@ -102,3 +102,33 @@ Zi8AlphaGetCandidates: 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. + +## Complete-body continuation from f20fc7b8, 2026-09-30 + +Entry: engine 44.43563%, case conversion 99.09091%, unit 10/12 instruction-exact. Both source functions remain public; configuration remains NonMatching. The engine was walked against the original disassembly, with object rebuilds and ctxdiff after each group of blocks. + +- Recovered the byte, halfword, pointer and integer declaration order from stack accesses. Separated primary/secondary completion and vowel flags, prefix flags, dictionary state, retry state, output language and phonetic flags. Removed comma-expression Boolean temporaries. Recovered the 65-character candidate buffer, including its terminator capacity: frame now 0x2b0, matching the original, rather than 0x330. +- Restored normalization, early highlighted-word output, prefix preparation, language selection and dictionary dispatch in address order. Recovered separate loop indices and lengths rather than sharing variables with overlapping lifetimes. Rebuilt the ROM/PUD/UWD/OEM and punctuation paths, candidate filtering, detokenization, duplicate filtering, key-layout filtering, output, dictionary exhaustion and all prefix/suffix retries through the final return. Intermediate engine scores: 65%, 70.35226%, then 70.829445%; no tail is omitted. +- Typed-workspace alias experiments were rejected: a local typed alias scored 67.28865%; a const pointer alias scored 67.75748%; a generic dictionary-work alias at the target initialization position scored 70.29625%. None resolved the target's unused workspace-copy stack slot without extra loads. No unused local or padding was added to reproduce that slot. +- Recovered Zi8GetTableCount's halfword return type from matched siblings. Score initially 70.65965%. Corrected the post-dictionary vowel filter to use the prefix-vowel flag and restored Italian/French/vowel call order and failure exits: 71.42676%. +- Reversed the lookup-versus-output branch to match the target's WCharCount-before-conversion order: 72.92676%. Reversed locked/unlocked suffix branches: 73.289406%. Recovered the stack-resident suffix element index and postfix field increments, preserving sequenced prefix reads/stores: 74.21439%. + +Quick authority gate PASS: identical pool, zero regressions, zero added forbidden patterns and readability warnings. Engine frame matches; first strict instruction divergence is +0x14, the parameter/workspace register swap. Remaining differences include scalar stack offsets, branch structure, call conversions and register allocation, not just compiler register choices. Behavior is reviewed against assembly, without an independent runtime harness. + +Additional near-match source trials in this continuation: + +- Zi8ChangeWordCase: case switch; 74.88636%, src 0xc0 base 0xb0 insns 48/44. --- replace mine 9:21 base 9:14. +- Zi8ChangeWordCase: explicit cursor advance in for loop; 94.545456%, src 0xb0 base 0xb0 insns 44/44. diffs 11: [9, 10, 11, 19, 22, 25, 27, 29, 30, 31, 32]. +- Zi8ChangeWordCase: loop break at entry; 67.27273%, src 0xb0 base 0xb0 insns 44/44. diffs 18: [9, 10, 11, 19, 21, 22, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35]. + +Restored the case-conversion baseline after all three rejected variants. A generic workspace argument copied into a typed local and used for the entire engine scored 70.34288%, 4096/3946 instructions; rejected in favor of the 74.21439% committed body. + +Further address-order audit: changing the engine workspace formal to the shared generic pointer type, with typed field access, moved the first strict divergence from +0x14 to +0x20 and scored 74.8036%. A const dictionary-work alias in a nested scope scored 72.05246%; a cached phonetic character scored 74.60922%; rejected both rather than manufacture the unused target stack copy. Recovered invalid-language-first branch order: 75.2666%. Recovered default-buffer-first order, chained flag-store order, unsigned field casts and the signature's halfword length argument: 75.28484%. + +Replaced the reconstructed Finnish retry labels with the target's backward scan and switch, including the shared vowel/space stop and decrement. Moved apostrophe punctuation termination from the loop condition into the body. Corrected the final punctuation-history check to use primary/secondary vowel restrictions rather than completion flags, as shown by target slots 0x8c/0x94. 76.430305%, frame still 0x2b0. Quick authority gate PASS, no regressions. These remaining structural fixes are separate from the unresolved workspace-copy stack slot; no padding or unused local was added. + +Highlighted-output audit: recovered the element-index length slot, the last-highlighted-character test at index minus one, body comparison breaks, skip-before-emit branch and suffix output scan through the shared index. Preserved a zero dictionary index before the early highlighted-output exit; the baseline initialized it, and leaving it undefined would make the optional dictionary-count finalization read an uninitialized local. That initialization is a deliberate remaining assembly difference, not a matching trick. Corrected Zi8Memset's full-width value argument from its matched definition. 76.94551%. + +Dictionary-mode dispatch audit: replaced the reconstructed comparison chain with the target's switch, in address order: punctuation, OEM, UWD, alternate sound, completion/default, ROM/PUD. Restored the forward dictionary-kind scan with a body break and initialized scan position only on the dual-language path. 81.71363%, 3978/3946 instructions. Recovered previous-count-before-clear order, ordinary-dictionary-before-terminal-punctuation order and the secondary-pass skip switch: 81.86037%. Quick gate PASS, identical pool, zero regressions and readability warnings. Every engine exit and dictionary/prefix/suffix pass remains present. + +Final full gate over both units: PASS. Alpha remains 10/12 instruction-exact; exact code 5704/21664, exact data 72/564, weighted fuzzy 86.776405%. Final engine score 81.86037%, 3978/3946 instructions, frame 0x2b0; first strict divergence +0x40, before the target's retry-flag initialization. Case conversion remains 99.09091% with eight register differences. All 330 emitted rodata bytes equal the target prefix; its remaining six bytes are trailing alignment, which was not reproduced with padding objects. The target's workspace-copy slot and some field meanings remain unresolved. All source functions are complete; no additional exact function or linked-unit completion is claimed. -- 2.49.1