Compare commits

...

27 Commits

Author SHA1 Message Date
Devin AI
0b3652a6e5 zi8clib: zitypes work fields, zprepare store-merge, zi8alpha+zi8cgetc units
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 21:47:19 +00:00
Devin AI
b57043544c zi8match: MatchPhonetic limf/n via if/else direct stores
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 21:45:24 +00:00
Devin AI
04aefd6781 ziswordw: Zi8IsWordW slot-map reorder (15->6 diffs)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 21:33:05 +00:00
Devin AI
5e2d29f3e1 zi8dawg: ROMdata0/1/2 insn-parity
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 20:12:13 +00:00
Devin AI
7680891f5f zidawg1+cinfo+zconvert+getc2 progress
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 20:07:37 +00:00
Devin AI
a093e091ed zconvert: WC2UC block-order + table-addr index fix
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 20:05:04 +00:00
Devin AI
fc875249a8 zidawg1: EOWattribute exact; GetChild/GetGraph near
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 19:59:06 +00:00
Devin AI
fa49d3e003 zi8cinfo: GetSInfo/PYinfo/ZYinfo exact; ZiCharInfo2 insn-parity
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 19:49:23 +00:00
Devin AI
f9e904e331 clib: zi8match.c — 9/10 fns at insn parity, rodata identical
Zi8PriMatchNextChar/Zi8ExactMatchNextChar/Zi8PriMatchNextComp/Zi8SecMatchComp/
Zi8GetPyFinal/Zi8GetPCode insn-exact; SecMatchChar 311/311 (reg-perm ties);
MatchPhonetic 363/363 (stw-vs-stb n-slot + reg-perm); GetPyPhonetic 703/718
(retry-block layout residual).

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 18:51:35 +00:00
Devin AI
b7a9f480ec zidawg1: EOW exact via >0 idiom; GetChild/Sibling struct fixes; ziswordw: IsWordW insn-parity (+4 frame tie)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 18:15:39 +00:00
Devin AI
89abf2eed1 zi81key: 6/9 fns (SetFindCand + SupportedPhonetic exact; 3 at insn-parity reg ties)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 17:51:03 +00:00
Devin AI
7747160022 zi8getc2: implement all 17 fns + data sections (sdata2/rodata/sbss2/data)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 17:37:13 +00:00
Devin AI
8675357986 zprepare: Zi8PrepareMatch implementation (933/940 insn parity)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 16:17:06 +00:00
Devin AI
81ebca2497 zikorean: implement all 3 fns (E6C at insn parity, GKC +13)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 15:54:13 +00:00
Devin AI
f1364b7df2 zi8dawg: implement all 6 fns (4 opcode-identical, 2 reg-perm ties)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 15:35:28 +00:00
Devin AI
99b6386abf zi8uwd: implement Zi8_81480224/03F4/047C + Zi8MatchUWDdata
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 15:14:03 +00:00
Devin AI
02129a852c Match zi8getSW (Zi8GetSyllablesCandidates) 100%, flip to Matching
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 15:03:06 +00:00
Devin AI
d1ce321b9b zmtkey: 3/4 fns exact (Zi8_81484484, ziNumKeysWithChars, Zi8ChangeCharCase); getKeyLayout opcode-identical reg-perm
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 14:46:37 +00:00
Devin AI
ad9526fa6e zkokeyp: shrink Zi8_814834AC local buf, decl-init j/candidateIndex
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 14:31:25 +00:00
Devin AI
85d5b90463 zi8space: match Zi8ZHaddSpace, flip to Matching
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 14:22:58 +00:00
Devin AI
93cde3f00f ziswordw: implement both functions (UC2UserKey byte-identical)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 14:17:38 +00:00
Devin AI
c95cb2ac6f zi8pud2: implement all 7 functions (6 byte-identical)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 13:54:46 +00:00
Devin AI
8e43b2cc4b zidawg1.c: implement 6 DAWG functions (insn-identical, reg-perm tie-breaks)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 13:26:03 +00:00
Devin AI
3e2ee411ed zi8misc: match Zi8Uni2Ptr+3 fns, flip to Matching
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 12:58:04 +00:00
Devin AI
9ff13628d4 zi8alts: match Zi8MatchAltSound, flip to Matching
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 12:44:40 +00:00
Devin AI
90e1712f8f zi8clib: zi8is matched (flip); zoemdata 2/3 fns exact
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 12:36:55 +00:00
Devin AI
84240faff0 zi8clib: zi8is matched, zoemdata Attach/Detach exact
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-09-29 12:36:48 +00:00
27 changed files with 7613 additions and 18 deletions

View File

@@ -985,21 +985,21 @@ config.libs = [
Object(NonMatching, "clib/zconvert.c"),
Object(NonMatching, "clib/zi81key.c"),
Object(NonMatching, "clib/zi8alpha.c"),
Object(NonMatching, "clib/zi8alts.c"),
Object(Matching, "clib/zi8alts.c"),
Object(NonMatching, "clib/zi8cgetc.c"),
Object(NonMatching, "clib/zi8cinfo.c"),
Object(Matching, "clib/zi8copy.c"),
Object(NonMatching, "clib/zi8dawg.c"),
Object(NonMatching, "clib/zi8getc.c"),
Object(Matching, "clib/zi8getc.c"),
Object(NonMatching, "clib/zi8getc2.c"),
Object(NonMatching, "clib/zi8getSW.c"),
Object(NonMatching, "clib/zi8initd.c"),
Object(NonMatching, "clib/zi8is.c"),
Object(Matching, "clib/zi8getSW.c"),
Object(Matching, "clib/zi8initd.c"),
Object(Matching, "clib/zi8is.c"),
Object(NonMatching, "clib/zi8match.c"),
Object(NonMatching, "clib/zi8misc.c"),
Object(Matching, "clib/zi8misc.c"),
Object(NonMatching, "clib/zi8pud2.c"),
Object(NonMatching, "clib/Zi8punct.c"),
Object(NonMatching, "clib/zi8space.c"),
Object(Matching, "clib/Zi8punct.c"),
Object(Matching, "clib/zi8space.c"),
Object(NonMatching, "clib/zi8uwd.c"),
Object(Matching, "clib/zi8ver.c"),
Object(Matching, "clib/zi8ZHuwd.c"),

View File

@@ -160,11 +160,12 @@ typedef struct _ziGetParam {
ziWChar* candidates; // 0x18
ziU8 maxCandidates; // 0x1C
ziWChar firstCandidate; // 0x1E
ziU8 wordCandidates; // 0x1F
ziU8 unk_0x20; // 0x20
ziU8 count; // 0x20
ziU8 letters; // 0x21
ziU8* scratch; // 0x22
ziU8 count; // 0x22
ziU8* scratch; // 0x24
ziU32 unk_0x28; // 0x28
} ziGetParam;
typedef struct _ziLanguageEntry {
@@ -172,20 +173,195 @@ typedef struct _ziLanguageEntry {
ziU8* tableData; // 0x04
} ziLanguageEntry;
typedef struct _zi8DawgRec {
ziU8* node;
ziU32 attr;
ziU16 key;
ziU8 unk_0x0A[2];
ziU8* back;
} zi8DawgRec;
typedef struct _zi8DawgCtx {
ziU8 lang; // 0x00
ziU8 key; // 0x01
ziU16 cnt; // 0x02
ziU16 cap; // 0x04
ziU8 unk_0x06[2];
ziU8* p08; // 0x08
ziU8* p0C; // 0x0C
ziU8* table; // 0x10
ziU8* p14; // 0x14
zi8DawgRec recs[0x32]; // 0x18
ziU32 unk_0x338; // 0x338
} zi8DawgCtx;
typedef struct _ziUwdNode {
struct _ziUwdNode* next;
ziU8* word;
} ziUwdNode;
struct __zi8_work_data_s {
ziU8 unk_0x00;
ziU8 unk_0x01;
ziU8 unk_0x02[2];
ziLanguageEntry* langEntries; // 0x04
ziU32 unk_0x08;
ziU8 unk_0x08;
ziU8 unk_0x09;
ziU8 unk_0x0A;
ziU8 unk_0x0B;
ziU32 unk_0x0C;
ziU32 unk_0x10;
ziU32 unk_0x14;
ziU16 unk_0x14;
ziU8 unk_0x16;
ziU8 unk_0x17;
ziU8 unk_0x18;
ziU8 unk_0x1C[0x108];
ziU8 unk_0x19;
ziU16 unk_0x1A;
ziU8 unk_0x1C[3];
ziU8 unk_0x1F;
ziU16 unk_0x20[0x40];
ziU16 unk_0xA0[0x42];
ziU16* unk_0x124[1];
ziU8* unk_0x128;
ziU8 unk_0x12C;
ziU8 unk_0x12D;
ziU8 unk_0x12E;
ziU8 unk_0x12F;
ziPtr unk_0x130[2];
ziU8 unk_0x138;
ziU8 unk_0x139[3];
ziU32 unk_0x13C;
ziU8 unk_0x140;
ziU8 unk_0x141[0x43];
ziU8 unk_0x184[0x43];
ziU8 uwdCount; // 0x1C7
ziUwdNode uwdNodes[0x20]; // 0x1C8
ziUwdNode* uwdList; // 0x2C8
ziU32 pudTable[0x10]; // 0x2CC
ziU8 pudCount; // 0x30C
ziU8 unk_0x30D[3];
ziU32 unk_0x310;
ziU32 unk_0x314;
ziU32 unk_0x318;
ziU8 pdRemoveOpt; // 0x31C
ziU8 unk_0x31D;
ziU8 unk_0x31E;
ziU8 unk_0x31F;
ziU8 (*oemMatch)(ziU16 idx, ziWChar* buf, ziU8 len, ziPtr data); //0x320
ziU16 oemLen; //0x324
ziU8 unk_0x326[2];
ziU32 oemIdx; //0x328
ziPtr oemData; //0x32C
ziU8 unk_0x330[8];
ziU32 unk_0x338;
ziU8 unk_0x33C[0x1FC];
ziU8 unk_0x538;
ziU8 unk_0x539;
ziU8 unk_0x53A[0x40];
ziWChar unk_0x57A[0x641];
ziPtr unk_0x11FC;
ziPtr userKeys[0x83]; // 0x1200
ziU8 unk_0x140C[4];
ziU32 unk_0x1410;
ziU8 unk_0x1414[4];
ziU8 unk_0x1418;
ziU8 unk_0x1419;
ziU16 unk_0x141A;
ziU8 unk_0x141C;
ziU8 unk_0x141D;
ziU8 unk_0x141E;
ziU8 unk_0x141F;
ziU8 unk_0x1420[4];
zi8DawgCtx dawgCtx; // 0x1424
ziU8 unk_0x1760[4]; // 0x1760
ziU8* unk_0x1764; // 0x1764
ziU8 unk_0x1768;
ziU8 unk_0x1769[0x81];
ziU16 unk_0x17EA;
ziU8 unk_0x17EC;
ziU8 unk_0x17ED[3];
ziU8* unk_0x17F0;
ziWChar unk_0x17F4[0x40]; // 0x17F4..0x1874
ziU16 unk_0x1874;
ziU8 unk_0x1876;
ziU8 unk_0x1877;
ziU8 unk_0x1878;
ziU8 unk_0x1879;
ziWChar unk_0x187A[0x41];
ziU8 unk_0x18FC;
ziU8 unk_0x18FD;
ziWChar unk_0x18FE[0x41];
ziU8 unk_0x1980;
ziU8 unk_0x1981;
ziU8 unk_0x1982;
ziU8 unk_0x1983;
ziU8 unk_0x1984;
ziU8 unk_0x1985;
ziU8 unk_0x1986;
ziU8 unk_0x1987;
ziWChar unk_0x1988[0x41];
ziU8 unk_0x1A0A;
ziU8 unk_0x1A0B[0x85];
ziWChar unk_0x1A90;
ziWChar unk_0x1A92[0x41];
ziU8 unk_0x1B14;
ziU8 unk_0x1B15[3];
ziU16* unk_0x1B18;
ziU16 unk_0x1B1C;
ziU16 unk_0x1B1E;
ziU16 unk_0x1B20;
ziU16 unk_0x1B22;
ziU8 unk_0x1B24;
ziU8 unk_0x1B25[3];
union {
ziU32 word;
struct {
ziU32 msb : 1;
} bits;
} unk_0x1B28;
union {
ziU32 word;
struct {
ziU32 msb : 1;
} bits;
} unk_0x1B2C;
ziU8 unk_0x1B30;
ziU8 unk_0x1B31;
ziU16 unk_0x1B32;
ziU16 unk_0x1B34;
ziU16 unk_0x1B36;
ziU16 unk_0x1B38;
ziU8 unk_0x1B3A;
ziU8 unk_0x1B3B;
ziU8 unk_0x1B3C;
ziU8 unk_0x1B3D;
ziU8 unk_0x1B3E;
ziU8 unk_0x1B3F;
ziU16 unk_0x1B40;
ziU8 unk_0x1B42[2];
};
typedef struct ziMatchParam {
ziU8 count; // 0x00
ziU8 arr1[0xC]; // 0x01
ziU8 arrD[0xC]; // 0x0D
ziU8 arr19[4]; // 0x19
ziU8 arr1D[4]; // 0x1D
ziU8 pad_0x21; // 0x21
ziU16 field22; // 0x22
ziU8 length; // 0x24
ziU8 nCand; // 0x25
ziWChar phon[0x10]; // 0x26
ziWChar phon2[0x10]; // 0x46
ziWChar first; // 0x66
ziWChar first2; // 0x68
ziWChar comp; // 0x6A
ziU8 nSeg; // 0x6C
ziU8 segs1[0xC0]; // 0x6D
ziU8 segsD[0xC0]; // 0x12D
ziU8 pad_0x1ED; // 0x1ED
} ziMatchParam;
#define ZI_WORK ((struct __zi8_work_data_s*)__zi8_work_data)
#define ZI_NEED_WORK , ziPtr __zi8_work_data

View File

@@ -0,0 +1,49 @@
#include <zi8clib/zitypes.h>
const ziWChar Zi8PunctTable[40] = {
0xFF0C, 0x3002, 0x3001, 0xFF1A, 0xFF1F, 0xFF01, 0x3005, 0x2026,
0x2015, 0xFF1B, 0xFF0E, 0x30FB, 0x201C, 0x201D, 0xFF08, 0xFF09,
0x300C, 0x300D, 0xFF10, 0xFF11, 0xFF12, 0xFF13, 0xFF14, 0xFF15,
0xFF16, 0xFF17, 0xFF18, 0xFF19, 0xFF0F, 0xFF05, 0xFFE5, 0xFF04,
0xFFE1, 0x20AC, 0x203B, 0xFF20, 0x0000,
};
ziS32 Zi8Punctuation(ziGetParam* param ZI_NEED_WORK) {
ziS32 limit = ((ziU16*)__zi8_work_data)[8] - 1;
ziS32 count = 0;
ziU8 i = 0;
ziU16 fc = param->firstCandidate;
ziU16 j = 0;
for (;;) {
if (Zi8PunctTable[j] == 0) {
break;
}
if (fc == 0) {
count++;
if (ZI_WORK->unk_0x00 == 0) {
param->candidates[i++] = Zi8PunctTable[j];
if ((param->context & 0x10) != 0) {
param->candidates[i++] = 0x20;
if ((ziU8)i >= limit) {
break;
}
}
if (count >= param->maxCandidates) {
break;
}
} else {
if (count >= (ziS32)ZI_WORK->unk_0x0C) {
return count;
}
}
} else {
fc--;
}
j++;
}
if (ZI_WORK->unk_0x00 == 0) {
param->letters = count;
}
return count;
}

View File

@@ -0,0 +1,211 @@
#include <zi8clib/zconvert.h>
#include <zi8clib/zierror.h>
#include <zi8clib/zitypes.h>
extern ziU16 Zi8GetTableCount(ziU8 lang, ziU8 tableIdx ZI_NEED_WORK);
extern ziU32 Zi8GetTableAddress(ziU8 lang, ziU8 tableIdx ZI_NEED_WORK);
extern ziWChar Zi8ConvertUC2UserKey(ziChar ch, ziU8 language ZI_NEED_WORK);
typedef struct zi8CvrtEntry {
ziU16 first;
ziU16 last;
const ziU8* map;
} zi8CvrtEntry;
const zi8CvrtEntry Zi8CvrtTables[4] = {
{0, 0, ZI8_NULL},
{0, 0, ZI8_NULL},
{0, 0, ZI8_NULL},
{0, 0, ZI8_NULL},
};
ziWChar Zi8ConvertUC2WC(ziChar ch, ziU8 language ZI_NEED_WORK) {
ziU16 last;
ziU32 tableAddr;
ziU8* p;
ziU16 first;
const zi8CvrtEntry* t;
const ziU8* map;
if ((ziU8)ch == 0) {
Zi8LogError(0x133, ZI_WORK);
return 0;
}
if ((ziU16)Zi8GetTableCount(language, 6, ZI_WORK) != 0) {
tableAddr = Zi8GetTableAddress(language, 6, ZI_WORK);
if (tableAddr == ZI8_NULL) {
Zi8LogError(0x6A4, ZI_WORK);
return 0;
}
p = (ziU8*)tableAddr;
first = (ziU16)(((ziU16)p[0] << 8) | (ziU16)p[1]);
last = (ziU16)(((ziU16)p[2] << 8) | (ziU16)p[3]);
if ((ziU8)ch < first || (ziU8)ch > last) {
Zi8LogError(0x132, ZI_WORK);
return 0;
}
p += ((ziU8)ch - first) * 2 + 8;
Zi8LogError(0x64, ZI_WORK);
return (ziWChar)(((ziU16)p[0] << 8) | (ziU16)p[1]);
} else {
t = Zi8CvrtTables;
if (t == ZI8_NULL) {
Zi8LogError(0x6A4, ZI_WORK);
return 0;
}
if ((ziU8)ch < t->first || (ziU8)ch > t->last) {
Zi8LogError(0x132, ZI_WORK);
return 0;
}
map = t->map;
Zi8LogError(0x64, ZI_WORK);
return *(ziU16*)(map + ((ziU8)ch - t->first) * 2);
}
}
ziChar Zi8ConvertWC2UC(ziWChar ch, ziU8 language ZI_NEED_WORK) {
ziU32 tableAddr;
ziU8* p;
const zi8CvrtEntry* map;
ziU16 count;
ziU16 i;
ziU16 first;
ziU16 last;
ziU16 val;
const ziU8* m;
if ((ziU16)ch == 0) {
Zi8LogError(0x133, ZI_WORK);
return 0;
}
if ((ziU16)Zi8GetTableCount(language, 7, ZI_WORK) != 0) {
tableAddr = Zi8GetTableAddress(language, 7, ZI_WORK);
if (tableAddr == ZI8_NULL) {
Zi8LogError(0x6AE, ZI_WORK);
return 0;
}
p = (ziU8*)tableAddr;
count = (ziU16)(((ziU16)p[0] << 8) | (ziU16)p[1]);
p += 8;
for (i = 0; i < count; i++) {
first = (ziU16)(((ziU16)p[0] << 8) | (ziU16)p[1]);
last = (ziU16)(((ziU16)p[2] << 8) | (ziU16)p[3]);
if ((ziU16)ch < first || (ziU16)ch > last) {
p += 8;
continue;
}
val = (ziU16)(((ziU16)p[6] << 8) | (ziU16)p[7]);
if (first == last) {
Zi8LogError(0x64, ZI_WORK);
return (ziChar)val;
}
p = (ziU8*)tableAddr + val + (ziU16)ch - first + 8;
Zi8LogError(0x64, ZI_WORK);
return *p;
}
Zi8LogError(0x6C2, ZI_WORK);
return 0;
}
map = (const zi8CvrtEntry*)Zi8CvrtTables[1].map;
if (map == ZI8_NULL) {
Zi8LogError(0x6AE, ZI_WORK);
return 0;
}
count = Zi8CvrtTables[1].first;
for (i = 0; i < count; i++) {
if ((ziU16)ch >= map[i].first && (ziU16)ch <= map[i].last) {
Zi8LogError(0x64, ZI_WORK);
if (map[i].first == map[i].last) {
return (ziChar)(ziU32)map[i].map;
}
m = map[i].map;
return (ziChar)m[(ziU16)ch - map[i].first];
}
}
Zi8LogError(0x6C2, ZI_WORK);
return 0;
}
ziWChar Zi8ConvertUC2Key(ziChar ch, ziU8 language ZI_NEED_WORK) {
ziU32 tableAddr;
ziU8* p;
const zi8CvrtEntry* map;
ziU16 count;
ziU16 i;
ziU16 first;
ziU16 last;
ziU16 result;
const ziChar* m;
result = 0;
if ((ziU8)ch == 0) {
Zi8LogError(0x133, ZI_WORK);
return 0;
}
if (((struct __zi8_work_data_s*)__zi8_work_data)->userKeys[language] !=
ZI8_NULL) {
return Zi8ConvertUC2UserKey(ch, language, ZI_WORK);
}
if ((ziU16)Zi8GetTableCount(language, 8, ZI_WORK) != 0) {
tableAddr = Zi8GetTableAddress(language, 8, ZI_WORK);
if (tableAddr == ZI8_NULL) {
Zi8LogError(0x6B8, ZI_WORK);
return 0;
}
p = (ziU8*)tableAddr;
count = (ziU16)(((ziU16)p[0] << 8) | (ziU16)p[1]);
p += 8;
for (i = 0; i < count; i++) {
first = (ziU16)(((ziU16)p[0] << 8) | (ziU16)p[1]);
last = (ziU16)(((ziU16)p[2] << 8) | (ziU16)p[3]);
if ((ziU8)ch < first || (ziU8)ch > last) {
p += 8;
continue;
}
result = (ziU16)(((ziU16)p[6] << 8) | (ziU16)p[7]);
if (first != last) {
p = (ziU8*)tableAddr + result + ((ziU8)ch - first) * 2 + 8;
result = (ziU16)(((ziU16)p[0] << 8) | (ziU16)p[1]);
}
break;
}
} else {
map = (const zi8CvrtEntry*)Zi8CvrtTables[2].map;
if (map == ZI8_NULL) {
Zi8LogError(0x6B8, ZI_WORK);
return 0;
}
count = Zi8CvrtTables[2].first;
for (i = 0; i < count; i++) {
if ((ziU8)ch >= map[i].first && (ziU8)ch <= map[i].last) {
m = map[i].map;
if (map[i].first == map[i].last) {
result = (ziChar)(ziU32)m;
} else {
result = *(ziU16*)(m + ((ziU8)ch - map[i].first) * 2);
}
break;
}
}
}
if ((ziU16)result == 0) {
Zi8LogError(0x6C2, ZI_WORK);
return 0xFFF1;
}
Zi8LogError(0x64, ZI_WORK);
return result;
}
ziWChar Zi8ConvertWC2Key(ziWChar ch, ziU8 language ZI_NEED_WORK) {
return Zi8ConvertUC2Key((ziChar)Zi8ConvertWC2UC(ch, language, ZI_WORK),
language, ZI_WORK);
}

View File

@@ -0,0 +1,351 @@
#include <zi8clib/zitypes.h>
#include <zi8clib/zierror.h>
extern ziU16 Zi8Ord2Ord(ziU16 ord ZI_NEED_WORK);
extern ziU8 Zi8LangSupported(ziU8 lang ZI_NEED_WORK);
static const ziWChar zi8ZYinitialSpelling[64] = {
0x0000, 0x0000, 0xEFF2, 0x0000, 0x0000, 0xEFF2, 0xEFF4, 0x0000,
0x0000, 0xEFF4, 0xEFF4, 0x0000, 0xEFF1, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0xEFF6, 0xEFF5, 0xEFF6, 0xEFF5, 0xEFF6, 0xEFF5, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xEFF2, 0x0000,
0x0000, 0x0000, 0x0000, 0xEFF2, 0xEFF5, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0xEFF3, 0x0000, 0x0000, 0xEFF3,
0xEFF1, 0x0000, 0x0000, 0xEFF3, 0xEFF1, 0x0000, 0x0000, 0xEFF1,
};
static const ziWChar zi8ZYfinalSpelling[64][2] = {
{0x0000, 0x0000}, {0xEFF7, 0x0000}, {0xEFF7, 0x0000}, {0xEFF7, 0x0000},
{0xEFF9, 0x0000}, {0x0000, 0x0000}, {0x0000, 0x0000}, {0x0000, 0x0000},
{0xEFF8, 0x0000}, {0xEFF8, 0x0000}, {0xEFF8, 0x0000}, {0xEFF8, 0x0000},
{0xEFF9, 0x0000}, {0xEFF9, 0x0000}, {0xEFF9, 0x0000}, {0xEFF9, 0x0000},
{0x0000, 0x0000}, {0xEFFA, 0xEFF7}, {0xEFFA, 0xEFF7}, {0x0000, 0x0000},
{0x0000, 0x0000}, {0xEFFA, 0xEFF7}, {0x0000, 0x0000}, {0xEFFA, 0x0000},
{0xEFFA, 0xEFF8}, {0x0000, 0x0000}, {0xEFFA, 0xEFF8}, {0xEFFA, 0xEFF8},
{0xEFFA, 0xEFF9}, {0xEFFA, 0xEFF9}, {0xEFFA, 0xEFF9}, {0xEFFA, 0xEFF9},
{0x0000, 0x0000}, {0xEFFA, 0xEFF7}, {0xEFFA, 0xEFF7}, {0x0000, 0x0000},
{0x0000, 0x0000}, {0xEFFA, 0xEFF7}, {0x0000, 0x0000}, {0xEFFA, 0x0000},
{0xEFFA, 0xEFF8}, {0xEFFA, 0xEFF8}, {0x0000, 0x0000}, {0x0000, 0x0000},
{0xEFFA, 0xEFF9}, {0xEFFA, 0xEFF9}, {0xEFFA, 0xEFF9}, {0xEFFA, 0xEFF9},
{0x0000, 0x0000}, {0x0000, 0x0000}, {0x0000, 0x0000}, {0x0000, 0x0000},
{0x0000, 0x0000}, {0xEFFA, 0xEFF7}, {0x0000, 0x0000}, {0xEFFA, 0x0000},
{0x0000, 0x0000}, {0x0000, 0x0000}, {0x0000, 0x0000}, {0x0000, 0x0000},
{0xEFFA, 0xEFF9}, {0x0000, 0x0000}, {0xEFFA, 0xEFF9}, {0xEFFA, 0xEFF9},
};
static const ziWChar zi8PYinitialSpelling[64][2] = {
{0x0000, 0x0000}, {0x0000, 0x0000}, {0xEFF3, 0x0000}, {0x0000, 0x0000},
{0x0000, 0x0000}, {0xEFF8, 0x0000}, {0xEFF5, 0x0000}, {0x0000, 0x0000},
{0x0000, 0x0000}, {0xEFF7, 0x0000}, {0xEFF9, 0x0000}, {0x0000, 0x0000},
{0xEFF6, 0x0000}, {0xEFF9, 0x0000}, {0x0000, 0x0000}, {0x0000, 0x0000},
{0x0000, 0x0000}, {0xEFF9, 0x0000}, {0x0000, 0x0000}, {0x0000, 0x0000},
{0x0000, 0x0000}, {0x0000, 0x0000}, {0x0000, 0x0000}, {0x0000, 0x0000},
{0xEFF2, 0x0000}, {0xEFF2, 0xEFF4}, {0xEFF7, 0x0000}, {0xEFF7, 0xEFF4},
{0xEFF9, 0x0000}, {0xEFF9, 0xEFF4}, {0x0000, 0x0000}, {0x0000, 0x0000},
{0x0000, 0x0000}, {0x0000, 0x0000}, {0x0000, 0x0000}, {0x0000, 0x0000},
{0x0000, 0x0000}, {0x0000, 0x0000}, {0xEFF6, 0x0000}, {0x0000, 0x0000},
{0x0000, 0x0000}, {0x0000, 0x0000}, {0x0000, 0x0000}, {0xEFF5, 0x0000},
{0xEFF7, 0x0000}, {0x0000, 0x0000}, {0x0000, 0x0000}, {0x0000, 0x0000},
{0x0000, 0x0000}, {0x0000, 0x0000}, {0x0000, 0x0000}, {0x0000, 0x0000},
{0xEFF4, 0x0000}, {0x0000, 0x0000}, {0x0000, 0x0000}, {0xEFF5, 0x0000},
{0xEFF3, 0x0000}, {0x0000, 0x0000}, {0x0000, 0x0000}, {0xEFF4, 0x0000},
{0xEFF2, 0x0000}, {0x0000, 0x0000}, {0x0000, 0x0000}, {0xEFF7, 0x0000},
};
static const ziWChar zi8PYfinalSpelling[64][4] = {
{0x0000, 0x0000, 0x0000, 0x0000}, {0xEFF4, 0xEFF2, 0xEFF6, 0x0000},
{0xEFF4, 0xEFF2, 0xEFF6, 0x0000}, {0xEFF4, 0xEFF2, 0xEFF6, 0xEFF4},
{0xEFF4, 0xEFF2, 0x0000, 0x0000}, {0x0000, 0x0000, 0x0000, 0x0000},
{0x0000, 0x0000, 0x0000, 0x0000}, {0x0000, 0x0000, 0x0000, 0x0000},
{0xEFF4, 0x0000, 0x0000, 0x0000}, {0xEFF4, 0xEFF3, 0x0000, 0x0000},
{0x0000, 0x0000, 0x0000, 0x0000}, {0xEFF4, 0xEFF8, 0x0000, 0x0000},
{0xEFF4, 0xEFF6, 0x0000, 0x0000}, {0xEFF4, 0xEFF6, 0xEFF4, 0x0000},
{0x0000, 0x0000, 0x0000, 0x0000}, {0xEFF4, 0xEFF6, 0xEFF6, 0xEFF4},
{0xEFF8, 0xEFF2, 0xEFF6, 0x0000}, {0xEFF8, 0xEFF2, 0xEFF6, 0xEFF4},
{0x0000, 0x0000, 0x0000, 0x0000}, {0xEFF8, 0xEFF2, 0xEFF4, 0x0000},
{0x0000, 0x0000, 0x0000, 0x0000}, {0x0000, 0x0000, 0x0000, 0x0000},
{0x0000, 0x0000, 0x0000, 0x0000}, {0xEFF8, 0xEFF2, 0x0000, 0x0000},
{0xEFF8, 0x0000, 0x0000, 0x0000}, {0x0000, 0x0000, 0x0000, 0x0000},
{0x0000, 0x0000, 0x0000, 0x0000}, {0x0000, 0x0000, 0x0000, 0x0000},
{0xEFF8, 0xEFF6, 0x0000, 0x0000}, {0xEFF8, 0xEFF4, 0x0000, 0x0000},
{0xEFF8, 0xEFF6, 0x0000, 0x0000}, {0xEFF8, 0xEFF3, 0x0000, 0x0000},
{0xEFF2, 0xEFF6, 0x0000, 0x0000}, {0xEFF2, 0xEFF6, 0xEFF4, 0x0000},
{0x0000, 0x0000, 0x0000, 0x0000}, {0xEFF2, 0x0000, 0x0000, 0x0000},
{0x0000, 0x0000, 0x0000, 0x0000}, {0xEFF2, 0xEFF4, 0x0000, 0x0000},
{0xEFF2, 0xEFF6, 0x0000, 0x0000}, {0x0000, 0x0000, 0x0000, 0x0000},
{0xEFF6, 0xEFF6, 0xEFF4, 0x0000}, {0x0000, 0x0000, 0x0000, 0x0000},
{0xEFF6, 0xEFF8, 0x0000, 0x0000}, {0xEFF6, 0x0000, 0x0000, 0x0000},
{0x0000, 0x0000, 0x0000, 0x0000}, {0x0000, 0x0000, 0x0000, 0x0000},
{0x0000, 0x0000, 0x0000, 0x0000}, {0x0000, 0x0000, 0x0000, 0x0000},
{0xEFF3, 0xEFF6, 0x0000, 0x0000}, {0xEFF3, 0xEFF6, 0xEFF4, 0x0000},
{0x0000, 0x0000, 0x0000, 0x0000}, {0xEFF3, 0xEFF7, 0x0000, 0x0000},
{0xEFF3, 0x0000, 0x0000, 0x0000}, {0xEFF3, 0xEFF4, 0x0000, 0x0000},
{0x0000, 0x0000, 0x0000, 0x0000}, {0x0000, 0x0000, 0x0000, 0x0000},
{0xEFF8, 0x0000, 0x0000, 0x0000}, {0xEFF8, 0xEFF2, 0xEFF6, 0x0000},
{0x0000, 0x0000, 0x0000, 0x0000}, {0x0000, 0x0000, 0x0000, 0x0000},
{0x0000, 0x0000, 0x0000, 0x0000}, {0x0000, 0x0000, 0x0000, 0x0000},
{0x0000, 0x0000, 0x0000, 0x0000}, {0x0000, 0x0000, 0x0000, 0x0000},
};
static ziU8 Zi8SpellingZY(ziWChar* dst, ziU16 key, ziU8 flag) {
ziU8 n;
ziU16 iIdx;
ziU16 fIdx;
ziU16 tone;
n = 0;
iIdx = (key >> 9) & 0x3F;
fIdx = (key >> 3) & 0x3F;
tone = key & 7;
if ((dst[0] = zi8ZYinitialSpelling[iIdx]) != 0) {
n = 1;
}
dst[n] = zi8ZYfinalSpelling[fIdx][0];
dst[n + 1] = zi8ZYfinalSpelling[fIdx][1];
dst[n + 2] = 0;
dst[n + 3] = 0;
while (dst[n] != 0) {
n++;
}
if (flag != 0) {
switch (tone) {
case 1:
dst[n++] = 0xEFF1;
break;
case 2:
dst[n++] = 0xEFF2;
break;
case 3:
dst[n++] = 0xEFF3;
break;
case 4:
dst[n++] = 0xEFF4;
break;
case 5:
dst[n++] = 0xEFF5;
break;
}
}
return n;
}
static ziU8 Zi8SpellingPY(ziWChar* dst, ziU16 key, ziU8 flag) {
ziU8 n;
ziU16 iIdx;
ziU16 fIdx;
ziU16 tone;
n = 0;
iIdx = (key >> 9) & 0x3F;
fIdx = (key >> 3) & 0x3F;
tone = key & 7;
dst[0] = zi8PYinitialSpelling[iIdx][0];
dst[1] = zi8PYinitialSpelling[iIdx][1];
dst[2] = 0;
while (dst[n] != 0) {
n++;
}
dst[n] = zi8PYfinalSpelling[fIdx][0];
dst[n + 1] = zi8PYfinalSpelling[fIdx][1];
dst[n + 2] = zi8PYfinalSpelling[fIdx][2];
dst[n + 3] = zi8PYfinalSpelling[fIdx][3];
dst[n + 4] = 0;
dst[n + 5] = 0;
while (dst[n] != 0) {
n++;
}
if (flag != 0) {
switch (tone) {
case 1:
dst[n++] = 0xEFF1;
break;
case 2:
dst[n++] = 0xEFF2;
break;
case 3:
dst[n++] = 0xEFF3;
break;
case 4:
dst[n++] = 0xEFF4;
break;
case 5:
dst[n++] = 0xEFF5;
break;
}
}
return n;
}
ziBool Zi8IsMatch1Key(ziWChar* word, ziU8 count, ziU16 key, ziU8 exact, ziU8 isPY, ziU8 tone) {
ziWChar buf[0x10];
ziU8 n;
ziS32 c;
if (key == 0) {
return ZI8_FALSE;
}
if (count == 0) {
return ZI8_TRUE;
}
if (isPY != 0) {
n = Zi8SpellingPY(buf, key, tone);
} else {
n = Zi8SpellingZY(buf, key, tone);
}
if (exact != 0) {
if (count != n) {
return ZI8_FALSE;
}
}
if (tone == 0) {
if (count > n) {
c = word[count - 1];
if (c < 0xEFF6 && c >= 0xEFF1) {
count = count - 1;
}
}
}
if (count > n) {
return ZI8_FALSE;
}
for (n = 0; n < count; n++) {
if (buf[n] != word[n]) {
return ZI8_FALSE;
}
}
return ZI8_TRUE;
}
ziBool MatchAltSound1Key(ziWChar* word, ziU8 count, ziU8 arg5, ziU8* table, ziU16 tableCount,
ziU8* map, ziU16 key, ziU8 arg8, ziU8 arg9, ziU8 arg10, ziPtr work) {
ziU8 hi;
ziU8 lo;
ziS32 first;
ziS32 last;
ziS32 mid;
ziS32 i;
ziU16 v;
ziWChar ent;
ziU8 f;
Zi8LogError(0x64, work);
hi = (ziU8)((ziU16)key >> 8);
lo = (ziU8)key;
arg10 = (ziU8)(arg10 >> 3);
if (tableCount == 0) {
Zi8ReplaceLastError(0x964, work);
return ZI8_FALSE;
}
first = 0;
i = tableCount - 1;
if (table[i * 4 + 1] == hi && table[i * 4] == lo) {
first = i;
} else {
if (table[first * 4 + 1] != hi || table[first * 4] != lo) {
last = tableCount - 1;
for (;;) {
if (table[first * 4 + 1] == hi && table[first * 4] == lo) {
break;
}
v = (ziU16)(((ziU16)table[first * 4 + 1] << 8) | table[first * 4]);
if (v > key) {
return ZI8_FALSE;
}
mid = (first + last) / 2;
if (mid == first) {
return ZI8_FALSE;
}
v = (ziU16)(((ziU16)table[mid * 4 + 1] << 8) | table[mid * 4]);
if (v >= key) {
last = mid;
} else {
first = mid;
continue;
}
if (table[last * 4 + 1] == hi && table[last * 4] == lo) {
first = last;
break;
}
v = (ziU16)(((ziU16)table[last * 4 + 1] << 8) | table[last * 4]);
if (v < key) {
return ZI8_FALSE;
}
mid = (first + last) / 2;
if (mid == first) {
return ZI8_FALSE;
}
v = (ziU16)(((ziU16)table[mid * 4 + 1] << 8) | table[mid * 4]);
if (v >= key) {
last = mid;
} else {
first = mid;
}
}
}
}
for (i = first; i < tableCount && table[i * 4 + 1] == hi && table[i * 4] == lo; i++) {
f = table[i * 4 + 3];
if (((f >> 1) & 7) == 0 || (f & arg10) != 0) {
v = (ziU16)(table[i * 4 + 2] | ((ziU16)(f & 1) << 8));
if (*(ziU8*)((ziU8*)work + 0x11FA) == 0 ||
*(ziU8*)((ziU8*)work + 0xFFA + v) != 0) {
v = (ziU16)(v << 1);
ent = (ziWChar)(map[v] | ((ziU16)map[v + 1] << 8) | ((f & 0xF0) >> 4));
if (Zi8IsMatch1Key(word, count, ent, arg5, arg8, arg9) != 0) {
return ZI8_TRUE;
}
}
}
}
for (i = first - 1; i >= 0 && table[i * 4 + 1] == hi && table[i * 4] == lo; i--) {
f = table[i * 4 + 3];
if (((f >> 1) & 7) == 0 || (f & arg10) != 0) {
v = (ziU16)(table[i * 4 + 2] | ((ziU16)(f & 1) << 8));
if (*(ziU8*)((ziU8*)work + 0x11FA) == 0 ||
*(ziU8*)((ziU8*)work + 0xFFA + v) != 0) {
v = (ziU16)(v << 1);
ent = (ziWChar)(map[v] | ((ziU16)map[v + 1] << 8) | ((f & 0xF0) >> 4));
if (Zi8IsMatch1Key(word, count, ent, arg5, arg8, arg9) != 0) {
return ZI8_TRUE;
}
}
}
}
return ZI8_FALSE;
}
static ziU8 Zi8SetFindCand(ziU8* table, ziU16 ch ZI_NEED_WORK) {
ziU8 old;
ch = Zi8Ord2Ord(ch, ZI_WORK);
old = (ziU8)((1 << (ch % 8)) & table[ch / 8]);
table[ch / 8] |= 1 << (ch % 8);
return old;
}
static ziBool ZiIsSupportedPhonetic(ziU8 lang ZI_NEED_WORK) {
if (Zi8LangSupported(lang, ZI_WORK) != 0) {
return ZI8_TRUE;
}
switch (lang) {
case 0x77:
case 0x78:
case 0x7C:
if (Zi8LangSupported(0x77, ZI_WORK) != 0 ||
Zi8LangSupported(0x78, ZI_WORK) != 0 ||
Zi8LangSupported(0x7C, ZI_WORK) != 0) {
return ZI8_TRUE;
}
/* fallthrough */
case 0x79:
case 0x7A:
case 0x7D:
if (Zi8LangSupported(0x79, ZI_WORK) != 0 ||
Zi8LangSupported(0x7A, ZI_WORK) != 0 ||
Zi8LangSupported(0x7D, ZI_WORK) != 0) {
return ZI8_TRUE;
}
break;
}
return ZI8_FALSE;
}

View File

@@ -0,0 +1,322 @@
#include <zi8clib/zitypes.h>
#include <zi8clib/zierror.h>
extern void Zi8LogError(ziU16 code, ziPtr __zi8_work_data);
extern ziU8 Zi8IsWordW(ziWChar* w, ziU8 len, ziPtr __zi8_work_data);
extern ziU8 Zi8IsWordW2(ziWChar* w, ziU8 len, ziPtr __zi8_work_data);
extern ziU16 Zi8ConvertWC2Key(ziWChar ch, ziU8 lang, ziPtr __zi8_work_data);
extern ziU8 Zi8ChangeCharCase(ziU8 dir, ziWChar* buf, ziU8 lang, ziPtr __zi8_work_data);
typedef struct {
ziU8 k[6];
ziU16 a;
ziU16 b;
} zi8ExclPair;
const zi8ExclPair IT_EXCLUDE_PAIRS[] = {
{ "l", 'i', 0 }, { "all", 'i', 0 }, { "dell", 'i', 0 },
{ "dall", 'i', 0 }, { "nell", 'i', 0 }, { "sull", 'i', 0 },
{ "d", 'i', 0 }, { "quest", 'i', 0 }, { "quell", 'i', 0 },
{ "bell", 'i', 0 }, { "brav", 'i', 0 }, { "buon", 'i', 0 },
{ "sant", 'i', 0 }, { "gl", 0, 1 }, { "agl", 0, 1 },
{ "degl", 0, 1 }, { "dagl", 0, 1 }, { "negl", 0, 1 },
{ "sugl", 0, 1 }, { "m", 0, 1 }, { "t", 0, 1 },
{ "s", 0, 1 }, { "c", 0, 1 }, { "v", 0, 1 },
{ "un", 'a', 0x100 },
{ { 0, 0, 0, 0, 0, 0 }, 0, 0 },
};
static const zi8ExclPair lbl_81617EA4[] = {
{ "d", 0, 1 }, { "l", 0, 1 }, { "m", 0, 1 },
{ "t", 0, 1 }, { "s", 0, 1 }, { "n", 0, 1 },
{ { 0, 0, 0, 0, 0, 0 }, 0, 0 },
};
ziS32 Zi8SetParentalControls(ziU8 a, ziPtr __zi8_work_data) {
Zi8LogError(0x2C9, __zi8_work_data);
return 0;
}
ziU8 Zi8IsWordW2(ziWChar* w, ziU8 len, ziPtr __zi8_work_data) {
ziU8 b;
ziU8 ret;
b = ZI_WORK->unk_0x1983;
ret = Zi8IsWordW(w, len, ZI_WORK);
ZI_WORK->unk_0x1983 = b;
return ret;
}
ziS32 Zi8SetHighlightedWordW(ziWChar* w, ziU8 a, ziU8 b, ziPtr __zi8_work_data) {
ziS32 i;
ziS32 j;
i = 0;
while (w[i] != 0) {
i++;
}
if (i >= 0x40) {
Zi8LogError(0x131, __zi8_work_data);
return 0;
}
if (i == 1 && w[0] >= 0xEFF1 && w[0] <= 0xF010) {
Zi8LogError(0x640, __zi8_work_data);
return 0;
}
ZI_WORK->unk_0x1879 = 1;
if (ZI_WORK->unk_0x18FC == 0 || ZI_WORK->unk_0x1984 == 0) {
ZI_WORK->unk_0x1C[0] = 1;
if (ZI_WORK->unk_0x18FC == 0) {
if (ZI_WORK->unk_0x1878 == 0 || i == ZI_WORK->unk_0x1878) {
ZI_WORK->unk_0x1C[0] = 2;
if (Zi8IsWordW2(w, a, __zi8_work_data) != 0) {
ZI_WORK->unk_0x1879 = a;
} else {
if (b != a && b != 7 && Zi8IsWordW2(w, b, __zi8_work_data) != 0) {
ZI_WORK->unk_0x1879 = b;
}
}
}
} else {
j = 0;
while (j < ZI_WORK->unk_0x1980) {
if (ZI_WORK->unk_0x18FE[j] != w[j]) {
break;
}
j++;
}
if (ZI_WORK->unk_0x1878 == 0 || i == ZI_WORK->unk_0x1878) {
if (j == ZI_WORK->unk_0x1980) {
if (Zi8IsWordW2(&w[j], ZI_WORK->unk_0x1983, __zi8_work_data) != 0) {
ZI_WORK->unk_0x1879 = ZI_WORK->unk_0x1983;
}
}
}
}
ZI_WORK->unk_0x1C[0] = 0;
}
for (j = 0; j <= i; j++) {
ZI_WORK->unk_0x187A[j] = w[j];
}
Zi8LogError(0x64, __zi8_work_data);
return 1;
}
static void ZiprocessHighlightedW(ziU8 a, ziPtr __zi8_work_data) {
ziS32 i;
ziS32 j;
ziS32 k;
i = 0;
while (ZI_WORK->unk_0x187A[i] != 0) {
i++;
}
if (i + 1 != a) {
return;
}
if (i == ZI_WORK->unk_0x1878 && ZI_WORK->unk_0x1877 != 0) {
ZI_WORK->unk_0x1876 = (ziU8)i;
for (j = 0; j < i; j++) {
ZI_WORK->unk_0x18FE[j] = ZI_WORK->unk_0x187A[j];
}
}
if (ZI_WORK->unk_0x18FC == 0) {
if ((ZI_WORK->unk_0x1878 == 0 || i == ZI_WORK->unk_0x1878) &&
ZI_WORK->unk_0x1879 > 1) {
for (j = 0; j < i; j++) {
ZI_WORK->unk_0x18FE[j] = ZI_WORK->unk_0x187A[j];
}
ZI_WORK->unk_0x1980 = (ziU8)j;
ZI_WORK->unk_0x1983 = ZI_WORK->unk_0x1879;
}
} else {
if (ZI_WORK->unk_0x1984 == 0 && ZI_WORK->unk_0x1879 > 1) {
j = 0;
k = ZI_WORK->unk_0x1980;
while (k < i) {
ZI_WORK->unk_0x1988[j++] = ZI_WORK->unk_0x187A[k++];
}
ZI_WORK->unk_0x1A0A = (ziU8)j;
}
}
if (i == 1 && ZI_WORK->unk_0x1A90 != 0) {
if (ZI_WORK->unk_0x187A[0] >= 0xEFF1 && ZI_WORK->unk_0x187A[0] <= 0xF010) {
ZI_WORK->unk_0x1A90 = 0;
} else {
ZI_WORK->unk_0x1A90 = ZI_WORK->unk_0x187A[0];
}
}
if (i == ZI_WORK->unk_0x1B14 &&
Zi8ConvertWC2Key(ZI_WORK->unk_0x187A[i - 1], ZI_WORK->unk_0x1983,
__zi8_work_data) != 0xEFF1) {
for (j = 0; j <= i; j++) {
ZI_WORK->unk_0x1A92[j] = ZI_WORK->unk_0x187A[j];
}
ZI_WORK->unk_0x1A92[j] = 0;
}
ZI_WORK->unk_0x1879 = 0;
}
ziU8 Zi8IsVowel(ziU8 a, ziU16 c) {
switch (a) {
case 0x58:
switch (c) {
case 0x61:
case 0x65:
case 0x68:
case 0x69:
case 0x6F:
case 0x75:
case 0xE0:
case 0xE8:
case 0xE9:
case 0xED:
case 0xEF:
case 0xF2:
case 0xF3:
case 0xFA:
case 0xFC:
goto ret1;
default:
return 0;
}
case 0x2F:
case 0x04:
case 0x3F:
case 0x40:
switch (c & 0xFFDF) {
case 0x41:
case 0x45:
case 0x48:
case 0x49:
case 0x4F:
case 0x55:
case 0xC0:
case 0xC8:
case 0xC9:
case 0xCC:
case 0xD2:
case 0xD9:
goto ret1;
case 0x59:
case 0xC2:
case 0xC6:
case 0xCA:
case 0xCB:
case 0xCE:
case 0xCF:
case 0xD4:
case 0xDB:
if (a != 0x2F) {
goto ret1;
}
return 0;
default:
if (a != 0x2F) {
goto chk;
}
return 0;
chk:
switch (c) {
case 0xFF:
case 0x152:
case 0x153:
case 0x178:
goto ret1;
default:
goto ret0;
}
}
default:
goto ret1;
}
ret0:
return 0;
ret1:
return 1;
}
ziS32 Zi8ITspecialExclusion(ziWChar* w, ziS32 len) {
ziS32 i;
const zi8ExclPair* p;
ziWChar* s;
s = w - len;
len = len - 1;
p = IT_EXCLUDE_PAIRS;
while (p->a != 0) {
i = 0;
while (i < len) {
if (s[i] != p->k[i]) {
break;
}
i++;
}
if (i >= len && p->k[i] == 0) {
if (Zi8IsVowel(0x2F, w[0]) == 0) {
return 1;
}
return 0;
}
p++;
}
return 0;
}
ziS32 Zi8_814659E8(ziWChar* w, ziS32 len) {
ziS32 i;
const zi8ExclPair* p;
ziWChar* s;
s = w - len;
len = len - 1;
p = IT_EXCLUDE_PAIRS;
while (p->a != 0) {
i = 0;
while (i < len) {
if (s[i] != p->k[i]) {
break;
}
i++;
}
if (i >= len && p->k[i] == 0) {
if (Zi8IsVowel(0x58, w[0]) == 0) {
return 1;
}
return 0;
}
p++;
}
return 0;
}
ziS32 Zi8IsAlphaPunct(ziWChar c) {
if (c == 0xEFF1 || (c >= 0x21 && c <= 0x40) || (c >= 0x5B && c <= 0x60) ||
(c >= 0x7B && c <= 0x7E)) {
return 1;
}
return 0;
}
static ziS32 ZiIsLetterHyphen(ziWChar c, ziPtr __zi8_work_data) {
if (c == ZI_WORK->unk_0x1874 || c == 0x2D || c == 0x2E || c == 0x40) {
return 1;
}
return 0;
}
void Zi8ChangeWordCase(ziWChar* w, ziU8 lang, ziPtr __zi8_work_data) {
ziS32 dir;
dir = 0;
if (ZI_WORK->unk_0x1C[2] == 3) {
Zi8ChangeCharCase(1, w++, lang, __zi8_work_data);
} else {
if (ZI_WORK->unk_0x1C[2] == 1) {
dir = 1;
}
}
while (*w != 0) {
Zi8ChangeCharCase(dir, w++, lang, __zi8_work_data);
}
}

View File

@@ -0,0 +1,108 @@
#include <zi8clib/zitypes.h>
ziU16 Zi8MatchAltSound(ziU8* elements, ziU16 count, ziU8* table, ziU16 ch,
ziU32 mask, ziU16 target, ziU8 flags ZI_NEED_WORK) {
ziU8 hi;
ziU8 lo;
ziS32 i;
ziS32 j;
ziS32 mid;
ziU16 off;
ziU16 w;
hi = (ziU8)((ziU16)ch >> 8);
lo = (ziU8)ch;
flags = (ziU8)(flags >> 3);
if (count == 0) {
return 0;
}
j = 0;
i = count - 1;
if ((elements + i * 4)[1] == hi && (elements + i * 4)[0] == lo) {
j = i;
goto up;
}
if ((elements + j * 4)[1] == hi && (elements + j * 4)[0] == lo) {
goto up;
}
goto search;
up:
i = j;
body:
if (((elements + i * 4)[3] & 0xE) == 0 ||
((elements + i * 4)[3] & flags) != 0) {
off = (ziU16)(((ziU16)(elements + i * 4)[2] |
(((ziU16)(elements + i * 4)[3] & 1) << 8)) << 1);
w = (ziU16)((((ziU16)(elements + i * 4)[3] & 0xF0) >> 4) |
(table[off] | ((ziU16)table[off + 1] << 8)));
if (target == (w & (ziU16)mask)) {
return w;
}
}
i++;
if (i >= count) {
goto down_start;
}
if ((elements + i * 4)[1] == hi && (elements + i * 4)[0] == lo) {
goto body;
}
down_start:
i = j;
goto dec;
down_body:
if (((elements + i * 4)[3] & 0xE) == 0 ||
((elements + i * 4)[3] & flags) != 0) {
off = (ziU16)(((ziU16)(elements + i * 4)[2] |
(((ziU16)(elements + i * 4)[3] & 1) << 8)) << 1);
w = (ziU16)((((ziU16)(elements + i * 4)[3] & 0xF0) >> 4) |
(table[off] | ((ziU16)table[off + 1] << 8)));
if (target == (w & (ziU16)mask)) {
return w;
}
}
dec:
i--;
if (i < 0) {
goto fail;
}
if ((elements + i * 4)[1] == hi && (elements + i * 4)[0] == lo) {
goto down_body;
}
fail:
return 0;
search:
if ((elements + j * 4)[1] == hi && (elements + j * 4)[0] == lo) {
goto up;
}
if ((((ziU16)(elements + j * 4)[1] << 8) | (ziU16)(elements + j * 4)[0]) > ch) {
return 0;
}
mid = (j + i) / 2;
if (mid == j) {
return 0;
}
if ((((ziU16)(elements + mid * 4)[1] << 8) | (ziU16)(elements + mid * 4)[0]) >= ch) {
i = mid;
goto hi_check;
}
j = mid;
goto search;
hi_check:
if ((elements + i * 4)[1] == hi && (elements + i * 4)[0] == lo) {
j = i;
goto up;
}
if ((((ziU16)(elements + i * 4)[1] << 8) | (ziU16)(elements + i * 4)[0]) < ch) {
return 0;
}
mid = (j + i) / 2;
if (mid == j) {
return 0;
}
if ((((ziU16)(elements + mid * 4)[1] << 8) | (ziU16)(elements + mid * 4)[0]) >= ch) {
i = mid;
goto hi_check;
}
j = mid;
goto search;
}

View File

@@ -0,0 +1,316 @@
#include <zi8clib/zitypes.h>
#include <zi8clib/zierror.h>
#include <zi8clib/zi8cgetc.h>
#include <zi8clib/zi8space.h>
typedef struct _ziCandParam {
ziU8 unk_0x00;
ziU8 unk_0x01;
ziU8 unk_0x02;
ziU8 unk_0x03;
ziU32 unk_0x04;
ziU32 unk_0x08;
ziU32 unk_0x0C;
ziU16 unk_0x10;
ziU8 unk_0x12;
ziU8 unk_0x13;
ziU32 unk_0x14;
} ziCandParam;
extern ziU16 Zi8Ord2Ord(ziU16 ord ZI_NEED_WORK);
extern ziU32 Zi8WCharCount(ziWChar* str ZI_NEED_WORK);
static const ziU16 ziTones[4] = { 0x02CA, 0x02C7, 0x02CB, 0x02D9 };
static const ziU16 ziPuncts[4] = { 0xFF0C, 0x3002, 0xFF1F, 0xFF01 };
static ziU16 zi8tones[4];
static ziU8 Zi8SetFindCand(ziU8* table, ziU16 ch ZI_NEED_WORK) {
ziU8 old;
ch = Zi8Ord2Ord(ch, ZI_WORK);
old = (ziU8)((1 << (ch % 8)) & table[ch / 8]);
table[ch / 8] |= 1 << (ch % 8);
return old;
}
static ziWChar* ZiGetNextPhonetic(ziWChar* p, ziWChar* end, ziPtr __zi8_work_data) {
while (*p != 0 && *p != ZI_WORK->unk_0x1A && *p != 0xF360 && p < end) {
p++;
}
if (*p == 0) {
goto ret0;
}
if (p != end) {
goto body;
}
ret0:
return ZI8_NULL;
body:
p++;
if (*p == 0) {
goto ret0b;
}
if (p != end) {
goto retp;
}
ret0b:
return ZI8_NULL;
retp:
return p;
}
static ziS32 ZiPartialMatch(ziWChar* p, ziWChar* pend, ziWChar* q, ziWChar* qend, ziU16 n,
ziPtr __zi8_work_data) {
if (p == pend) {
goto ret1;
}
if (q == qend) {
goto ret1;
}
if (*p == 0) {
goto ret1;
}
if (*q != 0) {
goto pchk;
}
ret1:
return 1;
qchk:
if (*q == ZI_WORK->unk_0x1A) {
goto ret1b;
}
if (*q == 0xF360) {
goto ret1b;
}
cmp:
if (*p == *q) {
goto adv;
}
return 0;
adv:
p++;
q++;
if (p == pend) {
goto ret1c;
}
if (q == qend) {
goto ret1c;
}
if (*p == 0) {
goto ret1c;
}
if (*q != 0) {
goto pchk;
}
ret1c:
return 1;
pchk:
if (*p == ZI_WORK->unk_0x1A) {
goto ret1b;
}
if (*p != 0xF360) {
goto qchk;
}
ret1b:
return 1;
}
static ziS32 ZiMatchZHSpelling(ziPtr p0, ziWChar* str1, ziWChar* str2, ziU8 cnt, ziU16 n,
ziPtr __zi8_work_data) {
ziWChar bufB[0x40];
ziWChar bufA[0x40];
ziS32 ret;
ziU32 c;
ziS32 i;
ziWChar* q;
ziWChar* s;
ret = 1;
c = Zi8WCharCount(str1, ZI_WORK);
if (str1 == ZI8_NULL || cnt == 0) {
goto out1;
}
goto chk;
out1:
return ret;
chk:
for (i = 0; i < cnt; i++) {
if (str1[i] == 0 || str1[i] != str2[i]) {
ret = 0;
break;
}
}
if (ret != 0) {
goto out;
}
bufB[0] = 0;
bufA[0] = 0;
if (Zi8ZHaddSpace(str2, cnt, bufB, 0x40, ZI_WORK) == 0) {
return 0;
}
if (Zi8ZHaddSpace(str1, (ziU8)c, bufA, 0x40, ZI_WORK) == 0) {
return 0;
}
q = bufB;
s = bufA;
while (n != 0) {
s = ZiGetNextPhonetic(s, bufA + 0x40, ZI_WORK);
if (s == ZI8_NULL) {
return 0;
}
n--;
}
ret = 1;
while (q != ZI8_NULL && s != ZI8_NULL) {
if (ZiPartialMatch(q, bufB + 0x40, s, bufA + 0x40, n, ZI_WORK) == 0) {
return 0;
}
q = ZiGetNextPhonetic(q, bufB + 0x40, ZI_WORK);
s = ZiGetNextPhonetic(s, bufA + 0x40, ZI_WORK);
}
out:
return ret;
}
static ziS32 zi8InternalGetZH(ziGetParam* prm, ziCandParam* cand, ziPtr __zi8_work_data) {
return 0;
}
static ziS32 Zi8NewMatchPhonetic(ziPtr p0 ZI_NEED_WORK) {
return 0;
}
ziU8 Zi8GetElementCount(ziWChar* pElements, ziU8 elementCount, ziU8 charCount ZI_NEED_WORK) {
struct {
ziU16 old;
} tmp;
ziWChar buf[0x80];
ziU8 i;
ziU8 j;
ziU8 k;
ziU8 n;
tmp.old = ZI_WORK->unk_0x1A;
if (elementCount <= 1 || charCount == 0) {
return elementCount;
}
for (i = 0; i < elementCount; i++) {
if (pElements[i] == 0x3B) {
continue;
}
if (pElements[i] < 0x61 || pElements[i] > 0x7A) {
break;
}
}
if (i == elementCount) {
return elementCount;
}
ZI_WORK->unk_0x1A = 0xF360;
Zi8ZHaddSpace(pElements, elementCount, buf, 0x100, ZI_WORK);
ZI_WORK->unk_0x1A = tmp.old;
n = 0;
j = n;
k = j;
while (charCount != 0 && j < elementCount) {
if (buf[k] == 0xF360) {
charCount--;
if (pElements[j] != 0xF360) {
goto kinc;
}
goto tail;
}
if (buf[k] >= 0xF331 && buf[k] <= 0xF335) {
charCount--;
if (pElements[j + 1] == 0xF360) {
goto inner;
}
goto tail;
}
goto tail;
inner:
k++;
j++;
n++;
tail:
j++;
n++;
kinc:
k++;
}
return n;
}
ziS32 Zi8GetChineseCandidates(ziGetParam* prm, ziCandParam* cand ZI_NEED_WORK) {
ziGetParam tmp;
ziS32 i;
ziU8 cand_0;
ziU32 cand_c;
if (prm->firstCandidate != 0 || prm->elementCount <= 1) {
goto def;
}
goto body;
def:
return zi8InternalGetZH(prm, cand, ZI_WORK);
body:
switch (prm->getMode) {
case 0x10:
if (prm->elements[prm->elementCount - 1] == 0xF360) {
goto def;
}
i = prm->elementCount - 2;
while (i > 0) {
if (prm->elements[i] == 0xF360) {
break;
}
i--;
}
if (i++ <= 0) {
goto def;
}
break;
case 0x0C:
case 0x0D:
switch (prm->elements[prm->elementCount - 1]) {
case 0xF331:
case 0xF332:
case 0xF333:
case 0xF334:
case 0xF335:
case 0xF360:
break;
default:
goto def;
}
for (i = 1; i < 0x40; i++) {
if (Zi8GetElementCount(prm->elements, prm->elementCount, (ziU8)i, ZI_WORK) >=
prm->elementCount) {
break;
}
}
if (i-- == 1) {
goto def;
}
i = Zi8GetElementCount(prm->elements, prm->elementCount, (ziU8)i, ZI_WORK);
break;
default:
goto def;
}
tmp = *prm;
cand_0 = cand->unk_0x00;
cand_c = cand->unk_0x0C;
tmp.elements = prm->elements + i;
tmp.elementCount = (ziU8)(tmp.elementCount - i);
cand_0 = cand->unk_0x00;
cand->unk_0x00 = 1;
cand_c = cand->unk_0x0C;
cand->unk_0x0C = 1;
i = zi8InternalGetZH(&tmp, cand, ZI_WORK);
cand->unk_0x00 = cand_0;
cand->unk_0x0C = cand_c;
if (i == 0) {
Zi8LogError(0x1388, ZI_WORK);
return 0;
}
return zi8InternalGetZH(prm, cand, ZI_WORK);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,437 @@
#include <zi8clib/zitypes.h>
#include <zi8clib/zierror.h>
extern ziU16 Zi8GetTableCount(ziU8 lang, ziU8 tableIdx ZI_NEED_WORK);
extern ziU32 Zi8GetTableSize(ziU8 lang, ziU8 tableIdx ZI_NEED_WORK);
extern ziU32 Zi8GetTableAddress(ziU8 lang, ziU8 tableIdx ZI_NEED_WORK);
extern ziU16 Zi8ConvertWC2Key(ziWChar ch, ziU8 language ZI_NEED_WORK);
extern ziU8* ZiDAWGGetGraph(ziU8* arg);
extern ziU32 ZiDAWGGetGraphInfo(ziPtr work, ziU8* hdr, ziWChar* key);
extern ziU8* ZiDAWGGetChild(ziU8* node);
extern ziU8* ZiDAWGGetSibling(ziU8* node);
extern ziU8 ZiDAWGgetEOWattribute(ziU8* node);
extern ziU32 ZiDAWGgetCHARattribute(ziU8* graph, ziU8* node ZI_NEED_WORK);
static ziU8 Zi8MatchROMdata0(ziWChar* keys, ziU8 count, ziU8 lang, ziWChar* out,
ziU16 maxLen, ziU8 flag8, ziU8 flag9, ziU8 g,
ziU8 t2, ziU8 flagX, ziU8* cnt, zi8DawgCtx* ctx,
ziU8* out2 ZI_NEED_WORK);
static ziU8 Zi8MatchROMdata1(ziWChar* keys, ziU8 count, ziU8 lang, ziWChar* out,
ziU16 maxLen, ziU8 flag8, ziU8 flag9, ziU8 grpIdx,
ziU8* grp, ziU8 x ZI_NEED_WORK);
static ziU8 Zi8MatchROMdata2(ziWChar* keys, ziU8 count, ziU8 lang, ziWChar* out,
ziU16 maxLen, ziU8 flag8, ziU8 flag9, ziU8 g,
ziU8* grp, ziU8 x ZI_NEED_WORK);
ziU8* NextDawgGroup(ziU8* ptr, ziU8 lang ZI_NEED_WORK) {
if (Zi8GetTableSize(lang, 0x1C, ZI_WORK) == 0) goto Lerr;
if (ptr == ZI8_NULL) {
ptr = (ziU8*)Zi8GetTableAddress(lang, 0x1C, ZI_WORK);
if (ptr == ZI8_NULL) {
Zi8LogError(0x962, ZI_WORK);
return ZI8_NULL;
}
if (ZI_WORK->unk_0x141D == 0) {
return ptr;
}
}
while (ptr[0] != 0xFF || ptr[1] != 0xFF) {
ptr++;
}
ptr += 2;
if (ptr[0] == 0xFF) {
Zi8LogError(0x963, ZI_WORK);
return ZI8_NULL;
}
return ptr;
Lerr:
Zi8LogError(0x961, ZI_WORK);
return ZI8_NULL;
}
static ziU8 Zi8MatchROMdata0(ziWChar* keys, ziU8 count, ziU8 lang, ziWChar* out,
ziU16 maxLen, ziU8 flag8, ziU8 flag9, ziU8 g,
ziU8 t2, ziU8 flagX, ziU8* cnt, zi8DawgCtx* ctx,
ziU8* out2 ZI_NEED_WORK) {
zi8DawgRec* recs;
zi8DawgRec* rec;
ziU8* tbl;
ziU8* tbl2;
ziWChar buf[2];
ziU32 tmp;
ziU16 size;
ziU16 flag16;
ziU8 ret;
ziU16 i;
ziU8* hdr;
ziWChar c;
ziU8 r;
ret = 0;
recs = ctx->recs;
if (lang != ctx->lang || g != ctx->key) {
recs[0].key = 0;
}
if (count == 1 && flag8 != 0 && g == 0xE) goto ret;
if (flag9 != 0) {
if (recs[ctx->cnt - 1].node == (ziU8*)ctx->unk_0x338) goto ret;
for (i = 0; i < count; i++) {
if (recs[i].key != keys[i] &&
(ziWChar)recs[i].attr != keys[i]) {
goto ret;
}
}
if (flag8 == 1) {
flagX = 0;
}
goto L478;
}
{
if (ZI_WORK->unk_0x141E != 0 && g == 0xC &&
Zi8GetTableSize(lang, ZI_WORK->unk_0x141E, ZI_WORK) != 0) {
tbl = (ziU8*)Zi8GetTableAddress(lang, ZI_WORK->unk_0x141E, ZI_WORK);
t2 = ZI_WORK->unk_0x141E + 1;
} else {
if (Zi8GetTableSize(lang, g, ZI_WORK) == 0) {
Zi8LogError(0x961, ZI_WORK);
goto ret;
}
tbl = (ziU8*)Zi8GetTableAddress(lang, g, ZI_WORK);
}
ctx->table = tbl;
ctx->cap = (ziU16)((((ziU16)ctx->table[2] << 8) + ctx->table[3]) / 3);
ctx->p08 = ctx->table + 4;
ctx->p0C = ctx->table + 4 + ctx->cap * 2;
ctx->lang = lang;
ctx->key = g;
for (i = 0; i < count && recs[i].key == keys[i]; i++);
if (i >= 2) {
recs[0].node = recs[i - 1].back;
goto Lcnt;
}
size = (ziU16)Zi8GetTableSize(lang, t2, ZI_WORK);
if (size != 0 && ZI_WORK->userKeys[lang] == 0) {
for (i = 0; i < (count < 2 ? count : 2); i++) {
buf[i] = Zi8ConvertWC2Key(keys[i], lang, ZI_WORK);
if (buf[i] == 0) {
buf[i] = keys[i];
}
}
buf[i] = 0;
tbl2 = (ziU8*)Zi8GetTableAddress(lang, t2, ZI_WORK);
ctx->p14 = tbl2 + 2;
hdr = ctx->cap * 2 + tbl2 + 2;
recs[0].node = (ziU8*)ZiDAWGGetGraphInfo(ctx, hdr, buf);
} else {
recs[0].node = ZiDAWGGetGraph((ziU8*)ctx);
ctx->unk_0x338 = 0;
ctx->p14 = ZI8_NULL;
}
recs[0].key = 0;
if (recs[0].node == (ziU8*)0) goto ret;
Lcnt:
ctx->cnt = 1;
out2[1] = count;
out2[0] = 0;
if (flag8 == 1) {
out2[0] = 1;
flagX = 0;
} else if (flag8 == 0 && flagX == 0) {
out2[1]++;
}
}
L478:
flag16 = 1;
rec = recs + (ctx->cnt - 1);
goto Lcheck;
Lloop:
if ((ziU16)maxLen < ctx->cnt) goto ret;
rec->attr = ZiDAWGgetCHARattribute((ziU8*)ctx, rec->node, ZI_WORK);
if (ctx->cnt <= count) {
if (ctx->p14 == ZI8_NULL) {
tmp = Zi8ConvertWC2Key((ziWChar)rec->attr, lang, ZI_WORK);
} else {
tmp = ((ziU16) * (ctx->p14 + (rec->attr >> 0x18) * 2) << 8) +
ctx->p14[(rec->attr >> 0x18) * 2 + 1];
}
c = (ziWChar)tmp;
if (c != keys[ctx->cnt - 1] &&
(ziWChar)rec->attr != keys[ctx->cnt - 1]) {
goto L7c8;
}
if (rec->key != keys[ctx->cnt - 1]) {
rec->key = keys[ctx->cnt - 1];
rec->back = recs[0].node;
recs[ctx->cnt].key = 0;
}
if (cnt != ZI8_NULL && *cnt < ctx->cnt) {
if (ZiDAWGgetEOWattribute(rec->node) != 0) {
*cnt = (ziU8)ctx->cnt;
for (i = 0; i < ctx->cnt; i++) {
out[i] = (ziWChar)recs[i].attr;
}
}
}
}
if (ctx->cnt >= count && ctx->cnt >= out2[1]) {
if (out2[0] != 0 && ctx->cnt > out2[1]) goto L7c8;
if (flagX == 0) {
if (ZiDAWGgetEOWattribute(rec->node) == 0) goto L6fc;
}
for (i = 0; i < ctx->cnt; i++) {
out[i] = (ziWChar)recs[i].attr;
}
ret = (ziU8)ctx->cnt;
flag16 = 0;
if (flagX != 0) goto L7c8;
}
L6fc:
if (out2[0] != 0 && ctx->cnt >= out2[1]) goto L7c8;
recs[ctx->cnt].node = ZiDAWGGetChild(recs[ctx->cnt - 1].node);
if (recs[ctx->cnt].node == (ziU8*)0) goto L7c8;
ctx->cnt++;
if (ZI_WORK->unk_0x141F < ctx->cnt) {
ZI_WORK->unk_0x141F = (ziU8)ctx->cnt;
}
goto L7d4;
L7c8:
while (ctx->cnt != 0) {
recs[ctx->cnt - 1].node = ZiDAWGGetSibling(recs[ctx->cnt - 1].node);
if (recs[ctx->cnt - 1].node != (ziU8*)0) goto L7d4;
ctx->cnt--;
}
L7d4:
rec = recs + (ctx->cnt - 1);
Lcheck:
if (flag16 != 0 && ctx->cnt != 0 &&
rec->node != (ziU8*)ctx->unk_0x338) {
goto Lloop;
}
ret:
return ret;
}
static ziU8 Zi8MatchROMdata1(ziWChar* keys, ziU8 count, ziU8 lang, ziWChar* out,
ziU16 maxLen, ziU8 flag8, ziU8 flag9, ziU8 grpIdx,
ziU8* grp, ziU8 x ZI_NEED_WORK) {
ziU8 ret = 0;
ziU8* p;
if (flag9 == 0) {
ZI_WORK->unk_0x1764 = grp;
if (ZI_WORK->unk_0x1764 == ZI8_NULL) {
if (Zi8GetTableSize(lang, 0xB, ZI_WORK) != 0) {
p = (ziU8*)Zi8GetTableAddress(lang, 0xB, ZI_WORK);
ZI_WORK->unk_0x1764 = p;
}
}
if (ZI_WORK->unk_0x1764 != ZI8_NULL) {
while (ZI_WORK->unk_0x1764[0] != 0xFF && grpIdx != 0) {
do {
ZI_WORK->unk_0x1764 += 2;
} while (ZI_WORK->unk_0x1764[0] != 0xFF);
ZI_WORK->unk_0x1764 += 1;
grpIdx--;
}
}
}
if (ZI_WORK->unk_0x1764 == ZI8_NULL) {
ret = Zi8MatchROMdata0(keys, count, lang, out, maxLen, flag8, flag9, 0,
1, x, ZI8_NULL, &ZI_WORK->dawgCtx,
ZI_WORK->unk_0x1760, ZI_WORK);
goto Lret;
}
while (ZI_WORK->unk_0x1764[0] != 0xFF) {
ret = Zi8MatchROMdata0(keys, count, lang, out, maxLen, flag8, flag9,
ZI_WORK->unk_0x1764[0], ZI_WORK->unk_0x1764[1],
x, ZI8_NULL, &ZI_WORK->dawgCtx,
ZI_WORK->unk_0x1760, ZI_WORK);
if (ret != 0) goto Lret;
ZI_WORK->unk_0x1764 += 2;
flag9 = 0;
}
Lret:
return ret;
}
static ziU8 Zi8MatchROMdata2(ziWChar* keys, ziU8 count, ziU8 lang, ziWChar* out,
ziU16 maxLen, ziU8 flag8, ziU8 flag9, ziU8 g,
ziU8* grp, ziU8 x ZI_NEED_WORK) {
ziU8 ret = 0;
ziU8 n;
ziS32 c;
if (g != 0) return 0;
if (flag9 == 0) {
ZI_WORK->unk_0x1768 = 0;
ZI_WORK->unk_0x17EA = 0;
if (grp != ZI8_NULL && grp[0] == 0xC && lang == 0xA &&
ZI_WORK->unk_0x141C != 0) {
ZI_WORK->unk_0x141E = 0x10;
} else {
ZI_WORK->unk_0x141E = 0;
}
}
Lbec:
ZI_WORK->unk_0x141F = 1;
ret = Zi8MatchROMdata1(keys + ZI_WORK->unk_0x17EA,
(ziU8)(count - ZI_WORK->unk_0x17EA), lang,
ZI_WORK->unk_0x17F4 + ZI_WORK->unk_0x17EA, maxLen,
flag8, flag9, ZI_WORK->unk_0x1768, grp, x, ZI_WORK);
if (ret != 0) {
n = (ziU8)(ZI_WORK->unk_0x17EA + ret);
while (n != 0) {
out[n - 1] = ZI_WORK->unk_0x17F4[n - 1];
n--;
}
ret = (ziU8)(ret + ZI_WORK->unk_0x17EA);
goto Lret;
}
if (flag9 != 0) goto Lret;
if (count == 1) goto Lret;
if (flag8 == 1 && ZI_WORK->unk_0x1768 == 0) {
if (Zi8MatchROMdata1(keys + ZI_WORK->unk_0x17EA,
(ziU8)(count - ZI_WORK->unk_0x17EA), lang,
ZI_WORK->unk_0x17F4 + ZI_WORK->unk_0x17EA, maxLen,
0, flag9, ZI_WORK->unk_0x1768, grp, x,
ZI_WORK) != 0) {
goto Lret;
}
}
if ((Zi8GetTableCount(lang, 0x1F, ZI_WORK) & 2) == 0) {
for (n = 0; n < count; n++) {
if (keys[n] == 0xEFF1) goto Lret;
}
}
if (ZI_WORK->unk_0x141F > maxLen) goto Lret;
n = ZI_WORK->unk_0x141F;
while (n != 0) {
ret = Zi8MatchROMdata1(keys + ZI_WORK->unk_0x17EA, n, lang,
ZI_WORK->unk_0x17F4 + ZI_WORK->unk_0x17EA,
maxLen, 1, 0, ZI_WORK->unk_0x1768, grp, x,
ZI_WORK);
if (ret != 0) {
ZI_WORK->unk_0x17EA += ret;
if (ZI_WORK->unk_0x17EA == count) {
return 0;
}
ZI_WORK->unk_0x1768++;
flag9 = 0;
ZI_WORK->unk_0x141E = 0;
if (ZI_WORK->dawgCtx.key == 0 && lang == 0xA) {
for (n = 0; n < ZI_WORK->unk_0x17EA; n++) {
c = ZI_WORK->unk_0x17F4[n];
switch (c) {
case 0x61:
case 0x6F:
case 0x75:
ZI_WORK->unk_0x141E = 0x10;
goto Lbec;
}
}
}
goto Lbec;
}
n--;
}
Lret:
return ret;
}
ziU8 Zi8MatchROMdata(ziWChar* keys, ziU8 count, ziU8 lang, ziWChar* out,
ziU16 maxLen, ziU8 flag8, ziU8 flag9, ziU8 g, ziU8 x
ZI_NEED_WORK) {
ziU8 ret = 0;
ziS32 tsize = 0;
if ((ziS32)maxLen < (ziS32)count) {
Zi8LogError(0x321, ZI_WORK);
goto Lret;
}
if (flag9 == 2) {
Zi8LogError(0x64, ZI_WORK);
goto Lret;
}
if (flag9 == 0) {
ZI_WORK->unk_0x17EC = 0;
ZI_WORK->unk_0x17F0 = NextDawgGroup(ZI8_NULL, lang, ZI_WORK);
} else {
if (ZI_WORK->unk_0x17EC != 0) {
Zi8LogError(0x64, ZI_WORK);
goto Lret;
}
}
tsize = Zi8GetTableSize(lang, 0x1C, ZI_WORK);
if (tsize == 0) {
ret = Zi8MatchROMdata2(keys, count, lang, out, maxLen, flag8, flag9, g,
ZI8_NULL, x, ZI_WORK);
goto La0;
}
while (ZI_WORK->unk_0x17F0 != ZI8_NULL) {
ret = Zi8MatchROMdata2(keys, count, lang, out, maxLen, flag8, flag9, g,
ZI_WORK->unk_0x17F0, x, ZI_WORK);
if (ret != 0) break;
flag9 = 0;
if (count <= 1 && lang == 0x36) break;
ZI_WORK->unk_0x17F0 =
NextDawgGroup(ZI_WORK->unk_0x17F0, lang, ZI_WORK);
}
La0:
if (ret != 0) goto Lerr;
if (flag9 != 0) goto Lerr;
if (flag8 != 1) goto Lerr;
if (count != 1) goto Lerr;
if (maxLen < 1) goto Lerr;
flag8 = 0;
ZI_WORK->unk_0x17EC = 1;
if (tsize != 0) {
ZI_WORK->unk_0x17F0 = NextDawgGroup(ZI8_NULL, lang, ZI_WORK);
while (ZI_WORK->unk_0x17F0 != ZI8_NULL) {
if (Zi8MatchROMdata2(keys, count, lang, out, maxLen, flag8, flag9,
g, ZI_WORK->unk_0x17F0, x, ZI_WORK) != 0) {
out[0] = keys[0];
ret = 1;
goto Lerr;
}
ZI_WORK->unk_0x17F0 =
NextDawgGroup(ZI_WORK->unk_0x17F0, lang, ZI_WORK);
}
goto Lerr;
}
if (Zi8MatchROMdata2(keys, count, lang, out, maxLen, flag8, flag9, g,
ZI8_NULL, x, ZI_WORK) != 0) {
out[0] = keys[0];
ret = 1;
}
Lerr:
Zi8LogError(0x64, ZI_WORK);
Lret:
return ret;
}
ziU8 Zi8SyllablesROMdata(ziWChar* keys, ziU8 count, ziU8 lang, ziWChar* out,
ziU16 a, ziU8 b, ziU8* cntOut, ziU8 c ZI_NEED_WORK) {
ziU8 t1;
ziU8 t2;
t1 = 0x1A;
t2 = 0x1B;
if (cntOut != ZI8_NULL) {
*cntOut = 0;
}
if (c != 0) {
t1 = 0x18;
t2 = 0x19;
}
if (Zi8GetTableSize(lang, t1, ZI_WORK) == 0) {
if (t1 == 0x1A) {
t1 = 0x18;
t2 = 0x19;
} else {
t1 = 0x1A;
t2 = 0x1B;
}
}
return Zi8MatchROMdata0(keys, count, lang, out, a, 1, b, t1, t2, 0, cntOut,
&ZI_WORK->dawgCtx, ZI_WORK->unk_0x1760, ZI_WORK);
}

View File

@@ -0,0 +1,212 @@
#include <zi8clib/zierror.h>
extern ziU16 Zi8GetTableCount(ziU8 lang, ziU8 tableIdx ZI_NEED_WORK);
extern ziU8 Zi8getKeyLayout(ziU8 lang, ziU16 key, ziWChar* layout, ziU8 mode ZI_NEED_WORK);
extern ziChar Zi8ConvertWC2UC(ziWChar ch, ziU8 language ZI_NEED_WORK);
extern ziU32 Zi8AlphaGetCandidates(ziGetParam* param, ziPtr sw ZI_NEED_WORK);
extern ziU8 Zi8SyllablesROMdata(ziWChar* keys, ziU8 count, ziU8 lang, ziWChar* out,
ziU16 a, ziU8 b, ziU8* cntOut, ziU8 c ZI_NEED_WORK);
typedef struct _ziSwParam {
ziU8 flag;
ziU8 unk_0x01[0xB];
ziS32 count;
ziU16 cap;
ziU8 unk_0x12[2];
} ziSwParam;
ziU32 Zi8GetSyllablesCandidates(ziGetParam* param, ziSwParam* sw ZI_NEED_WORK) {
ziWChar buf[0x40];
ziWChar buf2[0x32];
ziS32 rem;
ziS32 cur;
ziS32 firstCand;
ziS32 count;
ziWChar* pNext;
ziU16 err;
ziU8 flag14;
ziU8 flag13;
ziU8 flag12;
ziU8 flag11;
ziU8 sylCnt;
ziWChar* out;
ziU8* u28;
ziS32 i;
firstCand = param->firstCandidate;
count = 0;
u28 = 0;
pNext = 0;
flag14 = 1;
flag13 = 1;
flag12 = 0;
flag11 = 0;
sylCnt = 0;
err = 0x64;
if (param->currentWord != 0 && param->wordCharCount != 0 &&
param->currentWord[param->wordCharCount - 1] != 0x20) {
flag11 = 1;
}
if (param->elementCount == 0 || (param->elementCount == 1 && flag11 == 0)) {
count = Zi8AlphaGetCandidates(param, sw, ZI_WORK);
goto end;
}
if (sw->flag != 0 || (param->getOptions & 0xFD) != 0x81) {
out = buf;
rem = 0x40;
} else {
out = (ziWChar*)param->candidates;
rem = sw->cap - 1;
}
if ((param->getOptions & 0xFD) == 0x80) {
u28 = (ziU8*)param->candidates;
rem = sw->cap - 1;
}
if (rem <= param->elementCount) {
err = 0x168;
goto end;
}
if ((Zi8GetTableCount(param->language, 0x1F, ZI_WORK) & 8) != 0) {
flag14 = 0;
}
if (param->elements[0] == 0xEFF1 && param->elementCount > 1 && flag14 != 0) {
buf[0] = 0x2D;
} else {
Zi8getKeyLayout(param->language, param->elements[0], buf, 1, ZI_WORK);
}
out[0] = buf[0];
Zi8SyllablesROMdata(param->elements, param->elementCount, param->language, out,
(ziU16)rem, 0, &sylCnt, flag11, ZI_WORK);
if (sylCnt != 0) {
cur = sylCnt;
} else {
cur = 1;
}
if (cur == param->elementCount) goto L5dc;
if (firstCand != 0) {
firstCand--;
goto L5dc;
}
if (sw->flag != 0) {
if (++count >= sw->count) goto end;
goto L5dc;
}
for (i = cur; i < param->elementCount; i += sylCnt) {
if (param->elements[i] == 0xEFF1 && param->elementCount - i > 1 && flag14 != 0) {
buf2[0] = 0x2D;
} else {
Zi8getKeyLayout(param->language, param->elements[i], buf2, 1, ZI_WORK);
}
out[i] = buf2[0];
Zi8SyllablesROMdata(param->elements + i, param->elementCount - i, param->language,
out + i, (ziU16)rem, 0, &sylCnt, 1, ZI_WORK);
if (sylCnt == 0) {
sylCnt = 1;
}
}
if (u28 != 0) {
for (i = 0; i < param->elementCount; i++) {
u28[i] = Zi8ConvertWC2UC(out[i], param->language, ZI_WORK);
}
u28[i++] = 0;
u28[i] = 0;
u28 += i;
} else {
out[i++] = 0;
out[i] = 0;
out += i;
}
rem -= i;
if (++count >= param->maxCandidates) goto end;
if (rem > param->elementCount) goto L5dc;
goto end;
L5dc:
while (cur >= 1) {
flag12 = 0;
goto rom;
found:
flag12 = 1;
if (cur == 1) {
flag13 = 0;
}
L464:
if (out[0] >= 0xEFF1 && out[0] <= 0xF010) {
goto dec;
}
L464b:
if (firstCand != 0) {
firstCand--;
goto L560;
}
if (sw->flag != 0) {
if (++count >= sw->count) goto end;
goto L560;
}
if (u28 != 0) {
for (i = 0; i < cur; i++) {
u28[i] = Zi8ConvertWC2UC(out[i], param->language, ZI_WORK);
}
u28[i++] = 0;
u28[i] = 0;
u28 += i;
} else {
i = cur;
out[i++] = 0;
out[i] = 0;
out += i;
}
rem -= i;
if (++count >= param->maxCandidates) goto end;
if (rem <= cur) goto end;
L560:
if (pNext != 0) {
if (*pNext == 0) goto end;
out[0] = *pNext++;
goto L464b;
}
rom:
if (Zi8SyllablesROMdata(param->elements, (ziU8)cur, param->language, out,
(ziU16)rem, flag12, 0, flag11, ZI_WORK) != 0) {
goto found;
}
dec:
cur--;
}
if (flag13 == 0) goto end;
if (param->elements[0] == 0xEFF1 && param->elementCount > 1 && flag14 != 0) {
buf2[0] = 0x2D;
buf2[1] = 0;
Zi8getKeyLayout(param->language, param->elements[0], &buf2[1], 1, ZI_WORK);
for (i = 1; buf2[i] != 0; i++) {
if (buf2[i] == 0x2D) break;
}
while (buf2[i] != 0) {
buf2[i] = buf2[i + 1];
i++;
}
} else {
Zi8getKeyLayout(param->language, param->elements[0], buf2, 1, ZI_WORK);
}
cur = 1;
pNext = buf2;
goto L560;
end:
if (sw->flag != 0) {
param->letters = 0;
} else {
param->letters = (ziU8)count;
}
Zi8LogError(err, ZI_WORK);
return count;
}

View File

@@ -0,0 +1,15 @@
#include <zi8clib/zi8getc.h>
#include <zi8clib/zitypes.h>
extern ziU8 _Zi8GetCandidates(ziGetParam* getParam ZI_NEED_WORK);
ziU8 Zi8GetCandidates(ziGetParam* getParam ZI_NEED_WORK) {
ZI_WORK->unk_0x1B3A = 0;
ZI_WORK->unk_0x1B3C = 0;
ZI_WORK->unk_0x1B3B = 0;
ZI_WORK->unk_0x1B3D = 0;
ZI_WORK->unk_0x1B36 = 0;
ZI_WORK->unk_0x1B32 = 0;
ZI_WORK->unk_0x1B34 = 0;
return _Zi8GetCandidates(getParam, ZI_WORK);
}

View File

@@ -0,0 +1,756 @@
#include <zi8clib/zi8getc2.h>
#include <zi8clib/zitypes.h>
#include <zi8clib/zierror.h>
extern ziU16 Zi8GetTableCount(ziU8 lang, ziU8 tableIdx ZI_NEED_WORK);
extern ziU32 Zi8GetTableAddress(ziU8 lang, ziU8 tableIdx ZI_NEED_WORK);
extern ziU16 Zi8GetFormatVersion(ziU8 lang ZI_NEED_WORK);
extern ziU16 Zi8GetVersion(ziPtr __zi8_work_data);
extern ziU16 Zi8GetOEMID(ziPtr __zi8_work_data);
extern ziU16 Zi8GetBuildID(ziPtr __zi8_work_data);
extern void Zi8LogError(ziU16 code, ziPtr __zi8_work_data);
extern void Zi8ReplaceLastError(ziU16 code, ziPtr __zi8_work_data);
extern void Zi8Memset(ziPtr dst, ziU32 val, ziS32 size);
extern void Zi8Memcpy(ziPtr dst, ziPtr src, ziS32 size);
typedef struct {
ziU8 unk_0x00;
ziU8 unk_0x01;
ziU8 unk_0x02;
ziU8 unk_0x03;
ziU32 unk_0x04;
ziU32 unk_0x08;
ziU32 unk_0x0C;
ziU16 unk_0x10;
ziU8 unk_0x12;
ziU8 unk_0x13;
ziU32 unk_0x14;
} ziCandParam;
extern ziS32 Zi8GetCandidatesOrCount(ziGetParam* prm, ziCandParam* cand ZI_NEED_WORK);
extern ziU8 Zi8LangSupported(ziU8 lang ZI_NEED_WORK);
extern ziS32 Zi8GetKOcandidates(ziGetParam* prm, ziCandParam* cand ZI_NEED_WORK);
extern ziS32 Zi8GetKoreanCandidates(ziGetParam* prm, ziCandParam* cand ZI_NEED_WORK);
extern ziS32 Zi8Punctuation(ziGetParam* prm, ziCandParam* cand ZI_NEED_WORK);
extern ziBool Zi8IsCharacter(ziWChar c ZI_NEED_WORK);
extern ziU8 Zi8GetCharInfo(ziWChar c, ziWChar* buf, ziU8 size, ziU8 flag ZI_NEED_WORK);
extern ziS32 Zi8GetChineseCandidates(ziGetParam* prm, ziCandParam* cand ZI_NEED_WORK);
extern ziS32 Zi8Get1KeyPressSpelling(ziGetParam* prm, ziCandParam* cand ZI_NEED_WORK);
extern ziS32 Zi8Get1KeyPressCandidates(ziGetParam* prm, ziCandParam* cand ZI_NEED_WORK);
extern ziS32 Zi8GetSyllablesCandidates(ziGetParam* prm, ziCandParam* cand ZI_NEED_WORK);
extern ziS32 Zi8AlphaGetCandidates(ziGetParam* prm, ziCandParam* cand ZI_NEED_WORK);
static const ziU32 Zi8PYdefaultFuzzyPairs[2] = {
0x7E000000, 0
};
#pragma push
#pragma section data_type ".sdata2"
static ziU32 Zi8ZYdefaultFuzzyPairs[2];
#pragma pop
static const ziU8 Zi8SOdefaultArray[0x10] = { 1, 4, 3, 2, 1, 8, 7, 6, 5 };
ziBool Zi8ZHsetPYfuzzyPairs(ziFuzzyPYPairs pairsList ZI_NEED_WORK) {
if (pairsList.ziDefault) {
ZI_WORK->unk_0x1B28.word = *(const ziU32*)&Zi8PYdefaultFuzzyPairs;
} else {
ZI_WORK->unk_0x1B28.word = *(ziU32*)&pairsList;
}
return ZI8_TRUE;
}
ziBool Zi8ZHsetZYfuzzyPairs(ziFuzzyZYPairs pairsList ZI_NEED_WORK) {
if (pairsList.ziDefault) {
ZI_WORK->unk_0x1B2C.word = Zi8ZYdefaultFuzzyPairs[0];
} else {
ZI_WORK->unk_0x1B2C.word = *(ziU32*)&pairsList;
}
return ZI8_TRUE;
}
ziBool Zi8SetLatinSearchOrder(ziU8* searchArray, ziU8 searchSize ZI_NEED_WORK) {
if (searchArray == ZI8_NULL || searchArray[0] == 0) {
ZI_WORK->unk_0x1410 = (ziU32)Zi8SOdefaultArray;
ZI_WORK->unk_0x1418 = 9;
} else {
ZI_WORK->unk_0x1410 = (ziU32)searchArray;
ZI_WORK->unk_0x1418 = searchSize;
}
return ZI8_TRUE;
}
ziU16 Zi8GetGlobalDataSize() {
return 0x1B44;
}
static ziU16 Zi8GetDataSignature(ziU8* buf, ziU16 maxLen, ziU8 sel ZI_NEED_WORK) {
ziU16 idx;
ziU8* tbl;
if (sel == 1) {
if (Zi8GetFormatVersion(1, ZI_WORK) < 8) {
Zi8LogError(0x26F, ZI_WORK);
return 0;
}
idx = 0x1E;
} else {
idx = 3;
}
tbl = (ziU8*)Zi8GetTableAddress(sel, idx, ZI_WORK);
idx = Zi8GetTableCount(sel, idx, ZI_WORK);
if (idx == 0 || idx > maxLen) {
Zi8LogError(0x961, ZI_WORK);
return 0;
}
Zi8Memcpy(buf, tbl, idx);
buf[idx] = 0;
Zi8LogError(0x64, ZI_WORK);
return idx;
}
static ziU16 Zi8GetEngineSignature(ziU8* buf ZI_NEED_WORK) {
ziU16 i = 0;
ziU16 v;
ziU16 lo[1];
buf[i++] = 'v';
v = (ziU16)((Zi8GetVersion(ZI_WORK) & 0xFF00) >> 8);
lo[0] = (ziU8)((ziU16)Zi8GetVersion(ZI_WORK) & 0xFF);
buf[i++] = (ziU8)(v / 10 + '0');
buf[i++] = (ziU8)(v % 10 + '0');
buf[i++] = (ziU8)(lo[0] / 10 + '0');
buf[i++] = (ziU8)(lo[0] % 10 + '0');
buf[i++] = 'o';
v = Zi8GetOEMID(ZI_WORK);
buf[i++] = (ziU8)(v / 100 + '0');
buf[i++] = (ziU8)(v % 100 / 10 + '0');
buf[i++] = (ziU8)(v % 100 % 10 + '0');
buf[i++] = 'b';
v = Zi8GetBuildID(ZI_WORK);
buf[i++] = (ziU8)(v / 100 + '0');
buf[i++] = (ziU8)(v % 100 / 10 + '0');
buf[i++] = (ziU8)(v % 100 % 10 + '0');
buf[i] = 0;
return i;
}
static ziBool Zi8AlphaSignature(ziGetParam* prm, ziU8 flag ZI_NEED_WORK) {
ziU8 buf[0x20];
ziU8 buf2[0x20];
ziU8* p1;
ziU8* p2;
ziU16 len1[1];
ziU16 len2;
ziU16 n;
ziU8* src;
ziWChar* out;
out = prm->candidates;
p1 = ZI8_NULL;
p2 = ZI8_NULL;
len1[0] = 0;
len2 = 0;
Zi8LogError(0x64, ZI_WORK);
prm->letters = 0;
n = Zi8GetDataSignature(buf, 0x20, prm->language, ZI_WORK);
if (n != 0 && prm->elementCount <= n) {
p1 = buf;
p2 = buf2;
len1[0] = n;
} else {
p1 = buf2;
}
n = Zi8GetEngineSignature(buf2, ZI_WORK);
if (n < prm->elementCount) {
if (len1[0] != 0) {
p2 = ZI8_NULL;
n = 1;
} else {
Zi8ReplaceLastError(0x1F4, ZI_WORK);
return ZI8_FALSE;
}
} else {
if (len1[0] != 0) {
len2 = n;
n = 2;
} else {
len1[0] = n;
n = 1;
}
}
if (prm->firstCandidate >= n) {
Zi8ReplaceLastError(0x1F5, ZI_WORK);
return ZI8_FALSE;
}
n = n - prm->firstCandidate;
if (flag != 0) {
prm->letters = n;
ZI_WORK->unk_0x0A = 0xFF;
return ZI8_TRUE;
}
if (prm->maxCandidates < n) {
n = prm->maxCandidates;
}
prm->letters = n;
if ((prm->getOptions & 0x80) == 0) {
ZI_WORK->unk_0x538 = prm->language;
prm->candidates[0] = 0xFFF0;
out = (ziWChar*)&ZI_WORK->unk_0x338;
}
if (prm->firstCandidate != 0) {
src = p2;
n = len2;
} else {
src = p1;
n = len1[0];
}
if (n > ZI_WORK->unk_0x0A) {
n = ZI_WORK->unk_0x0A;
}
if (prm->elementCount < ZI_WORK->unk_0x140C[0] ||
(prm->getOptions & 0x7E) == 2) {
if (n > prm->elementCount) {
n = prm->elementCount;
}
}
while (n-- != 0) {
*out++ = *src++;
}
*out++ = 0;
if (prm->letters == 2) {
src = p2;
n = len2;
if (n > ZI_WORK->unk_0x0A) {
n = ZI_WORK->unk_0x0A;
}
if (prm->elementCount < ZI_WORK->unk_0x140C[0] ||
(prm->getOptions & 0x7E) == 2) {
if (n > prm->elementCount) {
n = prm->elementCount;
}
}
while (n-- != 0) {
*out++ = *src++;
}
*out++ = 0;
}
*out++ = 0;
ZI_WORK->unk_0x0A = 0xFF;
return ZI8_TRUE;
}
static ziBool Zi8ZhSignature(ziGetParam* prm, ziU8 flag ZI_NEED_WORK) {
ziU8 buf1[0x20];
ziU8 buf2[0x20];
ziU8* src;
ziWChar* out;
ziU16 len1;
ziU16 len2;
ziU16 n;
ziU16 used;
out = prm->candidates;
src = ZI8_NULL;
Zi8LogError(0x64, ZI_WORK);
prm->letters = 0;
len1 = Zi8GetDataSignature(buf1, 0x20, prm->language, ZI_WORK);
len2 = Zi8GetEngineSignature(buf2, ZI_WORK);
if ((prm->context & 0x10) != 0) {
n = 0;
if (len1 != 0) {
n++;
}
if (len2 != 0) {
n++;
}
} else {
n = (ziU16)(len1 + len2);
}
if (prm->firstCandidate >= n) {
Zi8ReplaceLastError(0x1F6, ZI_WORK);
return ZI8_FALSE;
}
n = (ziU16)(n - prm->firstCandidate);
if (flag != 0) {
prm->letters = (ziU8)n;
ZI_WORK->unk_0x0A = 0xFF;
return ZI8_TRUE;
}
if (prm->maxCandidates < n) {
n = prm->maxCandidates;
}
prm->letters = (ziU8)n;
if ((prm->context & 0x10) != 0) {
if (prm->firstCandidate == 0 && len1 != 0) {
goto UseDataSig;
}
if (!(prm->firstCandidate != 0 && len1 == 0)) {
goto UseEngSig;
}
Zi8ReplaceLastError(0x1F4, ZI_WORK);
return ZI8_FALSE;
UseEngSig:
src = buf2;
n = len2;
goto CopySig;
UseDataSig:
src = buf1;
n = len1;
CopySig:
while (n-- != 0) {
*out++ = *src++;
}
*out++ = 0x20;
if (prm->letters == 2) {
src = buf2;
n = len2;
while (n-- != 0) {
*out++ = *src++;
}
*out++ = 0x20;
}
} else {
used = 0;
if (len1 != 0) {
if (prm->firstCandidate >= len1) {
n = 0;
} else {
n = (ziU16)(len1 - prm->firstCandidate);
src = buf1 + prm->firstCandidate;
}
if (prm->letters < n) {
n = prm->letters;
}
used = n;
while (n-- != 0) {
*out++ = *src++;
}
}
src = buf2;
if (prm->firstCandidate >= len1) {
n = (ziU16)(len1 + (len2 - prm->firstCandidate));
src += len2 - n;
} else {
n = len2;
}
if (prm->letters - used < n) {
n = prm->letters - used;
}
while (n-- != 0) {
*out++ = *src++;
}
}
return ZI8_TRUE;
}
ziBool _Zi8GetCandidates(ziGetParam* prm ZI_NEED_WORK) {
ziCandParam cand = { 0 };
cand.unk_0x10 = ZI_WORK->unk_0x141A;
return Zi8GetCandidatesOrCount(prm, &cand, ZI_WORK);
}
ziBool _Zi8CheckCandidates(ziGetParam* prm ZI_NEED_WORK) {
ziCandParam cand = { 0 };
cand.unk_0x10 = ZI_WORK->unk_0x141A;
cand.unk_0x13 = 1;
return Zi8GetCandidatesOrCount(prm, &cand, ZI_WORK);
}
ziS32 Zi8GetCandidatesOrCount(ziGetParam* prm, ziCandParam* cand ZI_NEED_WORK) {
ziS32 ret;
ziU16 err = 0;
ziU8 savedOpt;
ziU8 restore;
ziU8 n;
ziU8 savedCount;
ziU8 savedMode;
ziU8 i;
ziWChar* savedElements;
ziWChar* savedScratch;
ziWChar c;
ziWChar savedCh;
ziWChar buf[0x10];
savedOpt = 0;
savedScratch = ZI8_NULL;
restore = 0;
if (cand->unk_0x02 == 0) {
if (ZI_WORK->unk_0x00 == 9 && prm->elementCount != 0) {
if (prm->elements[prm->elementCount - 1] == 0xEFF8 &&
Zi8AlphaSignature(prm, cand->unk_0x00, ZI_WORK)) {
goto Done;
}
if (prm->elements[prm->elementCount - 1] == 0xEF04 &&
Zi8ZhSignature(prm, cand->unk_0x00, ZI_WORK)) {
Done:
ret = prm->letters;
if (cand->unk_0x00 != 0) {
prm->letters = 0;
}
Zi8LogError(0x64, ZI_WORK);
return ret;
}
}
if (prm->elementCount == 1 && prm->firstCandidate == 0) {
switch (prm->language) {
case 1:
if (ZI_WORK->unk_0x00 != 0 && ZI_WORK->unk_0x01 != cand->unk_0x00) {
break;
}
switch (ZI_WORK->unk_0x00) {
case 0:
if (prm->elements[0] == 0xEF04) {
ZI_WORK->unk_0x01 = cand->unk_0x00;
ZI_WORK->unk_0x00 = 1;
}
break;
case 2:
case 4:
case 6:
if (prm->elements[0] == 0xEF04) {
ZI_WORK->unk_0x00++;
} else {
ZI_WORK->unk_0x00 = 0;
}
break;
case 1:
case 3:
case 5:
case 7:
if (prm->elements[0] == 0xEF01) {
ZI_WORK->unk_0x00++;
} else {
ZI_WORK->unk_0x00 = 0;
}
break;
case 8:
case 9:
if (prm->elements[0] == 0xEF04 && Zi8ZhSignature(prm, cand->unk_0x00, ZI_WORK)) {
ZI_WORK->unk_0x00 = 9;
ret = prm->letters;
if (cand->unk_0x00 != 0) {
prm->letters = 0;
}
Zi8LogError(0x64, ZI_WORK);
return ret;
}
default:
ZI_WORK->unk_0x00 = 0;
break;
}
if (ZI_WORK->unk_0x00 == 0 && prm->elements[0] == 0xEF04) {
ZI_WORK->unk_0x00 = 1;
}
break;
case 0x10:
case 0x12:
case 0x77: case 0x78: case 0x79: case 0x7A:
case 0x7B: case 0x7C: case 0x7D:
break;
default:
if (ZI_WORK->unk_0x00 != 0 && ZI_WORK->unk_0x01 != cand->unk_0x00) {
break;
}
switch (ZI_WORK->unk_0x00) {
case 0:
if (prm->elements[0] == 0xEFF2) {
ZI_WORK->unk_0x01 = cand->unk_0x00;
ZI_WORK->unk_0x00 = 1;
}
break;
case 1:
if (prm->elements[0] == 0xEFF3) {
ZI_WORK->unk_0x00 = 2;
} else {
ZI_WORK->unk_0x00 = 0;
}
break;
case 2:
if (prm->elements[0] == 0xEFF5) {
ZI_WORK->unk_0x00 = 3;
} else {
ZI_WORK->unk_0x00 = 0;
}
break;
case 3:
if (prm->elements[0] == 0xEFF7) {
ZI_WORK->unk_0x00 = 4;
} else {
ZI_WORK->unk_0x00 = 0;
}
break;
case 4:
if (prm->elements[0] == 0xEFF8) {
ZI_WORK->unk_0x00 = 5;
} else {
ZI_WORK->unk_0x00 = 0;
}
break;
case 5:
if (prm->elements[0] == 0xEFF9) {
ZI_WORK->unk_0x00 = 6;
} else {
ZI_WORK->unk_0x00 = 0;
}
break;
case 6:
if (prm->elements[0] == 0xEFF2) {
ZI_WORK->unk_0x00 = 7;
} else {
ZI_WORK->unk_0x00 = 0;
}
break;
case 7:
if (prm->elements[0] == 0xEFF5) {
ZI_WORK->unk_0x00 = 8;
} else {
ZI_WORK->unk_0x00 = 0;
}
break;
case 8:
case 9:
if (prm->elements[0] == 0xEFF8 && Zi8AlphaSignature(prm, cand->unk_0x00, ZI_WORK)) {
ZI_WORK->unk_0x00 = 9;
ret = prm->letters;
if (cand->unk_0x00 != 0) {
prm->letters = 0;
}
Zi8LogError(0x64, ZI_WORK);
return ret;
}
default:
ZI_WORK->unk_0x00 = 0;
break;
}
if (ZI_WORK->unk_0x00 == 0 && prm->elements[0] == 0xEFF2) {
ZI_WORK->unk_0x00 = 1;
}
break;
}
} else if (prm->elementCount > 1) {
ZI_WORK->unk_0x00 = 0;
}
}
ZI_WORK->unk_0x18 = prm->subLanguage;
ZI_WORK->unk_0x16 = (ziU8)(Zi8GetFormatVersion(1, ZI_WORK) & 2);
cand->unk_0x0C = ZI_WORK->unk_0x10;
cand->unk_0x01 = ZI_WORK->unk_0x0A;
ZI_WORK->unk_0x0A = 0xFF;
if (!Zi8LangSupported(prm->language, ZI_WORK)) {
Zi8LogError(0x163, ZI_WORK);
return 0;
}
if (prm->language == 0x10) {
err = 0x2C1;
ret = 0;
} else if (prm->language == 0x12) {
if (prm->elementCount == 0 || prm->elements[0] >= 0xEFF1) {
ret = Zi8GetKOcandidates(prm, cand, ZI_WORK);
} else {
ret = Zi8GetKoreanCandidates(prm, cand, ZI_WORK);
}
} else if (prm->language == 1 && (prm->context & 8) != 0) {
ret = Zi8Punctuation(prm, cand, ZI_WORK);
err = 0x64;
} else if (prm->language == 1 && (prm->getOptions & 0xBF) == 4 &&
prm->elementCount != 0 && Zi8IsCharacter(prm->elements[0], ZI_WORK)) {
n = Zi8GetCharInfo(prm->elements[0], buf, 0x10, 1, ZI_WORK);
if (n == 0) {
prm->letters = prm->count = prm->unk_0x20 = 0;
ret = 0;
err = 0x384;
} else {
c = buf[n - 1];
if (c >= 0xF331 && c <= 0xF335) {
buf[n - 1] = 0xF360;
}
savedElements = prm->elements;
prm->elements = buf;
savedCount = prm->elementCount;
prm->elementCount = n;
savedMode = prm->getMode;
prm->getMode = 1;
ret = Zi8GetChineseCandidates(prm, cand, ZI_WORK);
prm->elements = savedElements;
prm->elementCount = savedCount;
prm->getMode = savedMode;
prm->count = 1;
}
} else if (prm->language == 1 && prm->getMode == 0xF) {
err = 0x2D0;
ret = 0;
} else if (prm->language == 1 && (prm->getMode == 3 || prm->getMode == 4)) {
if ((prm->getOptions & 0x80) != 0) {
ret = Zi8Get1KeyPressSpelling(prm, cand, ZI_WORK);
} else if (prm->elementCount == 0) {
ret = Zi8GetChineseCandidates(prm, cand, ZI_WORK);
} else {
ret = Zi8Get1KeyPressCandidates(prm, cand, ZI_WORK);
}
} else if (prm->language == 1 &&
(prm->getMode == 7 || prm->getMode == 8 || prm->getMode == 0xA || prm->getMode == 9)) {
if (ZI_WORK->unk_0x16 != 0) {
ret = Zi8GetChineseCandidates(prm, cand, ZI_WORK);
} else {
err = 0x708;
ret = 0;
}
} else if (prm->language == 1 && (prm->getMode == 0xB || prm->getMode == 0xE)) {
err = 0x2EE;
ret = 0;
} else if (prm->language == 1) {
ret = Zi8GetChineseCandidates(prm, cand, ZI_WORK);
if (ret == 0 && (prm->getOptions & 0x20) == 0 && prm->getMode == 1 && prm->elementCount != 0 &&
(prm->elements[prm->elementCount - 1] == 0xF37A ||
prm->elements[prm->elementCount - 1] == 0xF363 ||
prm->elements[prm->elementCount - 1] == 0xF373)) {
savedCh = prm->elements[prm->elementCount];
prm->elements[prm->elementCount++] = 0xF368;
ret = Zi8GetChineseCandidates(prm, cand, ZI_WORK);
prm->elements[--prm->elementCount] = savedCh;
}
} else {
ZI_WORK->unk_0x538 = prm->language;
if ((prm->getOptions & 0x80) == 0) {
restore = 1;
savedOpt = prm->getOptions;
savedScratch = prm->candidates;
prm->getOptions = prm->getOptions | 0x81;
prm->candidates = (ziWChar*)&ZI_WORK->unk_0x338;
cand->unk_0x10 = 0x100;
}
if (prm->getMode == 2) {
if ((Zi8GetTableCount(prm->language, 0x1F, ZI_WORK) & 0x200) != 0) {
ret = Zi8GetSyllablesCandidates(prm, cand, ZI_WORK);
} else {
err = 0x44C;
ret = 0;
}
} else {
ret = Zi8AlphaGetCandidates(prm, cand, ZI_WORK);
}
}
if (restore != 0) {
prm->getOptions = savedOpt;
prm->candidates = savedScratch;
for (i = 0; i < prm->letters; i++) {
prm->candidates[i] = (ziWChar)(0xFFF0 + i);
}
}
if (err != 0) {
Zi8LogError(err, ZI_WORK);
}
return ret;
}
void Zi8InitDupWordBuf(ziPtr __zi8_work_data) {
ZI_WORK->unk_0x539 = 0;
}
ziBool Zi8IsDupWChar(ziWChar c, ziPtr __zi8_work_data) {
ziS32 i;
ziBool found;
ziWChar* buf = (ziWChar*)&ZI_WORK->unk_0x57A;
found = ZI8_FALSE;
if (ZI_WORK->unk_0x539 == 0) {
buf[0] = 2;
buf[1] = c;
ZI_WORK->unk_0x539 = 1;
Zi8LogError(0x8FD, ZI_WORK);
return ZI8_FALSE;
}
for (i = ZI_WORK->unk_0x539; i != 0; i--) {
if (c == buf[i]) {
found = ZI8_TRUE;
break;
}
}
ZI_WORK->unk_0x539++;
buf[buf[0]++] = c;
if (buf[0] > 0x64) {
buf[0] = 2;
buf[1] = c;
ZI_WORK->unk_0x539 = 1;
}
Zi8LogError(0x64, ZI_WORK);
return found;
}
ziBool Zi8IsDupWordW(ziWChar* word, ziU8 len ZI_NEED_WORK) {
register ziBool found;
ziS32 i;
ziS32 j;
ziS32 idx;
found = ZI8_FALSE;
if (word == ZI8_NULL || len == 0) {
Zi8LogError(0x12C, ZI_WORK);
return ZI8_FALSE;
}
if (len > 0x14) {
word += len - 0x14;
len = 0x14;
}
for (i = 0; i < ZI_WORK->unk_0x539; i++) {
idx = ZI_WORK->unk_0x53A[i];
for (j = 0; j < len; j++) {
if (word[j] != ((ziWChar(*)[0x15])ZI_WORK->unk_0x57A)[idx][j]) {
break;
}
}
if (j >= len && ((ziWChar(*)[0x15])ZI_WORK->unk_0x57A)[idx][j] == 0) {
found = ZI8_TRUE;
break;
}
}
if (found == ZI8_FALSE) {
if (ZI_WORK->unk_0x539 < 0x40) {
idx = ZI_WORK->unk_0x53A[ZI_WORK->unk_0x539] = ZI_WORK->unk_0x539;
ZI_WORK->unk_0x539++;
} else {
idx = ZI_WORK->unk_0x53A[0];
for (i = 1; i < ZI_WORK->unk_0x539; i++) {
ZI_WORK->unk_0x53A[i - 1] = ZI_WORK->unk_0x53A[i];
}
ZI_WORK->unk_0x53A[i - 1] = idx;
}
} else {
idx = ZI_WORK->unk_0x53A[i];
for (; i < ZI_WORK->unk_0x539 - 1; i++) {
ZI_WORK->unk_0x53A[i] = ZI_WORK->unk_0x53A[i + 1];
}
ZI_WORK->unk_0x53A[i] = idx;
}
for (j = 0; j < len; j++) {
((ziWChar(*)[0x15])ZI_WORK->unk_0x57A)[idx][j] = word[j];
}
((ziWChar(*)[0x15])ZI_WORK->unk_0x57A)[idx][j] = 0;
Zi8LogError(0x64, ZI_WORK);
return found;
}
void Zi8Memset(ziPtr dst, ziU32 val, ziS32 size) {
ziS32 i;
for (i = 0; i < size; i++) {
((ziU8*)dst)[i] = (ziU8)val;
}
}
void Zi8Memcpy(ziPtr dst, ziPtr src, ziS32 size) {
ziS32 i;
for (i = 0; i < size; i++) {
((ziU8*)dst)[i] = ((ziU8*)src)[i];
}
}
ziBool Zi8SetMaxWordLength(ziU8 length ZI_NEED_WORK) {
ZI_WORK->unk_0x0A = length;
return ZI8_TRUE;
}

View File

@@ -0,0 +1,75 @@
#include <zi8clib/zitypes.h>
#include <zi8clib/zierror.h>
extern void Zi8Memset(ziPtr p, ziU32 v, ziU32 len);
extern void Zi8SetLatinSearchOrder(ziU32 a, ziU8 b ZI_NEED_WORK);
extern void ZADP_Zi8SetPDremoveOpt(ziU8 a ZI_NEED_WORK);
extern ziU16 Zi8GetFormatVersion(ziU8 a ZI_NEED_WORK);
extern void Zi8ZHsetZYfuzzyPairs(ziU32* a ZI_NEED_WORK);
extern void Zi8ZHsetPYfuzzyPairs(ziU32* a ZI_NEED_WORK);
extern void Zi8SetParentalControls(ziU8 a ZI_NEED_WORK);
ziU8 Zi8InitializeDynamic(ziLanguageEntry* langEntries ZI_NEED_WORK) {
ziU32 zyFuzzy;
ziU32 pyFuzzy;
ziU32* pzyFuzzy;
ziU32* ppyFuzzy;
Zi8Memset(__zi8_work_data, 0, 0x1B44);
ZI_WORK->unk_0x08 = 1;
ZI_WORK->unk_0x09 = 1;
ZI_WORK->unk_0x0A = 0xFF;
ZI_WORK->unk_0x10 = 0x64;
*(ziU16*)&ZI_WORK->unk_0x0C = 0xFFFF;
ZI_WORK->unk_0x1A = 0x20;
ZI_WORK->unk_0x1C[2] = 0;
ZI_WORK->unk_0x1B30 = 0;
ZI_WORK->unk_0x1B3A = 0;
ZI_WORK->unk_0x1B36 = 0;
ZI_WORK->unk_0x1B32 = 0;
ZI_WORK->unk_0x1B34 = 0;
ZI_WORK->unk_0x1B3B = 0;
ZI_WORK->unk_0x1B3C = 0;
ZI_WORK->unk_0x1B40 = 0;
ZI_WORK->unk_0x1B38 = 0;
ZI_WORK->langEntries = langEntries;
if (ZI_WORK->langEntries == ZI8_NULL) {
Zi8LogError(0x578, ZI_WORK);
return 0;
}
if (ZI_WORK->langEntries->language == 0) {
Zi8LogError(0x582, ZI_WORK);
return 0;
}
ZI_WORK->unk_0x1874 = 0x2D;
ZI_WORK->unk_0x538 = 0;
ZI_WORK->unk_0x1C[3] = 0;
ZI_WORK->unk_0x141A = 0x100;
Zi8SetLatinSearchOrder(0, 0, ZI_WORK);
ZADP_Zi8SetPDremoveOpt(1, ZI_WORK);
ZI_WORK->unk_0x17 = 5;
ZI_WORK->unk_0x16 = Zi8GetFormatVersion(1, ZI_WORK) & 2;
ZI_WORK->unk_0x1B28.bits.msb = 1;
ZI_WORK->unk_0x1B2C.bits.msb = 1;
zyFuzzy = ZI_WORK->unk_0x1B2C.word;
pzyFuzzy = &zyFuzzy;
Zi8ZHsetZYfuzzyPairs(pzyFuzzy, ZI_WORK);
pyFuzzy = ZI_WORK->unk_0x1B28.word;
ppyFuzzy = &pyFuzzy;
Zi8ZHsetPYfuzzyPairs(ppyFuzzy, ZI_WORK);
Zi8SetParentalControls(2, ZI_WORK);
Zi8LogError(0x64, ZI_WORK);
return 1;
}
ziU8 Zi8IsZicorpSignature(ziU16* p, ziU16 len) {
if ((ziU16)len > 6 && p[0] == 0x7A && p[1] == 0x69 && p[2] == 0x63 &&
p[3] == 0x6F && p[4] == 0x72 && p[5] == 0x70) {
return 1;
}
if ((ziU16)len > 6 && p[0] == 0x39 && p[1] == 0x34 && p[2] == 0x32 &&
p[3] == 0x36 && p[4] == 0x37 && p[5] == 0x37) {
return 1;
}
return 0;
}

View File

@@ -0,0 +1,138 @@
#include <zi8clib/zi8is.h>
#include <zi8clib/zierror.h>
extern ziU8 Zi8LangSupported(ziU8 lang ZI_NEED_WORK);
extern ziU16 Zi8GetTableCount(ziU8 lang, ziU8 tableIdx ZI_NEED_WORK);
extern ziU32 Zi8GetTableAddress(ziU8 lang, ziU8 tableIdx ZI_NEED_WORK);
extern ziU8 _Zi8GetCandidates(ziGetParam* getParam ZI_NEED_WORK);
extern void Zi8Memset(ziPtr p, ziU32 v, ziU32 len);
ziU8 Zi8GetZHCharSet(ziPtr workData) {
ziU8 charSet = 0;
ziU8 bak;
ziU16 v0;
ziU16 v1;
ziU16 v2;
ziU32 addr;
ziU8* p;
ziWChar candBuf[0x10];
ziGetParam getParam;
Zi8LogError(0x64, workData);
if (Zi8LangSupported(1, workData) == 0) {
Zi8ReplaceLastError(0x26C, workData);
return 0;
}
if (Zi8GetTableCount(1, 10, workData) != 0) {
bak = ((struct __zi8_work_data_s*)workData)->unk_0x18;
((struct __zi8_work_data_s*)workData)->unk_0x18 = 1;
addr = Zi8GetTableAddress(1, 10, workData);
p = (ziU8*)addr;
v0 = (ziU16)((ziU16)p[0] | ((ziU16)p[1] << 8));
((struct __zi8_work_data_s*)workData)->unk_0x18 = 0;
addr = Zi8GetTableAddress(1, 10, workData);
p = (ziU8*)addr;
v1 = (ziU16)((ziU16)p[2] | ((ziU16)p[3] << 8));
v2 = (ziU16)((ziU16)p[4] | ((ziU16)p[5] << 8));
((struct __zi8_work_data_s*)workData)->unk_0x18 = bak;
if (v0 != 0) {
if (v0 > 0x4E20) {
charSet |= 8;
} else {
charSet |= 1;
}
}
if (v1 != 0) {
if (v1 > 0x2710) {
charSet |= 2;
} else {
charSet |= 0x10;
}
}
if (v2 != 0) {
charSet |= 4;
}
return charSet;
}
Zi8Memset(&getParam, 0, 0x2C);
getParam.language = 1;
getParam.context = 1;
getParam.getOptions = 0;
getParam.candidates = candBuf;
getParam.maxCandidates = 1;
getParam.subLanguage = 1;
retry:
getParam.getMode = 0;
if (_Zi8GetCandidates(&getParam, workData) != 0) {
charSet |= getParam.subLanguage;
goto next;
}
getParam.getMode = 1;
if (_Zi8GetCandidates(&getParam, workData) != 0) {
charSet |= getParam.subLanguage;
goto next;
}
getParam.getMode = 2;
if (_Zi8GetCandidates(&getParam, workData) != 0) {
charSet |= getParam.subLanguage;
}
next:
if (getParam.subLanguage == 1) {
getParam.subLanguage = 4;
goto retry;
}
if (getParam.subLanguage == 4) {
getParam.subLanguage = 2;
goto retry;
}
return charSet;
}
ziBool Zi8IsComponent(ziWChar ch ZI_NEED_WORK) {
if (ch >= 0xEF10 && ch < 0xF305) {
return 1;
}
return 0;
}
ziBool Zi8IsCharacter(ziWChar ch ZI_NEED_WORK) {
ziU16 count;
ziU8 hi;
ziU8 lo;
ziU32 addr;
ziU8* table;
ziU16 i;
if (ch >= 0x3105 && ch <= 0x3129) {
return 1;
}
switch (ch) {
case 0x2C7:
case 0x2C9:
case 0x2CA:
case 0x2CB:
case 0x2D9:
return 1;
}
switch (ch) {
case 0x3002:
case 0xFF01:
case 0xFF0C:
case 0xFF1F:
return 1;
}
hi = (ziU8)(((ziU16)ch >> 8) & 0xFF);
lo = (ziU8)ch;
count = Zi8GetTableCount(1, 0, ZI_WORK);
addr = Zi8GetTableAddress(1, 0, ZI_WORK);
table = (ziU8*)addr;
for (i = 0; i < count; i++) {
if (table[6] == hi && table[7] == lo) {
return 1;
}
table += 0xC;
}
return 0;
}

View File

@@ -0,0 +1,946 @@
#include <zi8clib/zitypes.h>
#include <zi8clib/zierror.h>
extern ziU32 Zi8GetTableAddress(ziU8 lang, ziU8 tableIdx ZI_NEED_WORK);
extern ziU16 Zi8MatchAltSound(ziU8* elements, ziU16 count, ziU8* table, ziU16 ch,
ziU32 mask, ziU16 target, ziU8 flags ZI_NEED_WORK);
ziU8 Zi8GetPyFinal(ziU8* s, ziU8* o1, ziU8* o2);
ziU16 Zi8GetPCode(ziU8* table, ziU8* p);
static const ziU8 Zi8PinyinInitials[0x1C] = {
0x00, 0x3c, 0x98, 0x02, 0x00, 0x38, 0x34, 0x3b,
0x00, 0x06, 0x37, 0x2b, 0x0c, 0x26, 0x00, 0x3f,
0x09, 0x2c, 0x9a, 0x05, 0x00, 0x00, 0x11, 0x0a,
0x0d, 0x9c, 0x00, 0x00
};
static const ziU8 Zi8BpmfInitials[0x24] = {
0x3c, 0x3f, 0x0c, 0x38, 0x02, 0x05, 0x26, 0x2b,
0x34, 0x37, 0x3b, 0x06, 0x09, 0x0a, 0x1d, 0x19,
0x1b, 0x2c, 0x1c, 0x18, 0x1a, 0x01, 0x02, 0x03,
0x05, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0e, 0x0d,
0x0f, 0x04, 0x00, 0x00
};
static const ziU8 Zi8PinyinFinals[0x36][8] = {
{0x0f, 0xff, 0x00, 0x00, 0x3c, 0x28, 0x00, 0x00},
{0x0f, 0x00, 0x00, 0x00, 0x3f, 0x2b, 0x00, 0x00},
{0x0f, 0x0e, 0xff, 0x00, 0x3f, 0x28, 0x00, 0x00},
{0x0f, 0x0e, 0x07, 0x00, 0x3f, 0x28, 0x00, 0x00},
{0x0f, 0x15, 0x00, 0x00, 0x3f, 0x2a, 0x00, 0x00},
{0x09, 0xff, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00},
{0x09, 0x00, 0x00, 0x00, 0x3f, 0x08, 0x00, 0x00},
{0x09, 0x01, 0xff, 0x00, 0x38, 0x00, 0x00, 0x00},
{0x09, 0x01, 0x00, 0x00, 0x3f, 0x04, 0x00, 0x00},
{0x09, 0x01, 0x0f, 0x00, 0x3f, 0x01, 0x00, 0x00},
{0x09, 0x01, 0x0e, 0xff, 0x3e, 0x02, 0x00, 0x00},
{0x09, 0x01, 0x0e, 0x00, 0x3f, 0x02, 0x00, 0x00},
{0x09, 0x01, 0x0e, 0x07, 0x3f, 0x03, 0x00, 0x00},
{0x09, 0x05, 0x00, 0x00, 0x3f, 0x09, 0x00, 0x00},
{0x09, 0x15, 0x00, 0x00, 0x3f, 0x0b, 0x00, 0x00},
{0x09, 0x0e, 0xff, 0x00, 0x3e, 0x0c, 0x00, 0x00},
{0x09, 0x0e, 0x00, 0x00, 0x3f, 0x0c, 0x00, 0x00},
{0x09, 0x0e, 0x07, 0x00, 0x3f, 0x0d, 0x00, 0x00},
{0x09, 0x0f, 0xff, 0x00, 0x3e, 0x0e, 0x00, 0x00},
{0x09, 0x0f, 0x15, 0x00, 0x3f, 0x0e, 0x00, 0x00},
{0x09, 0x0f, 0x0e, 0xff, 0x3f, 0x0f, 0x00, 0x00},
{0x09, 0x0f, 0x0e, 0x07, 0x3f, 0x0f, 0x00, 0x00},
{0x15, 0xff, 0x00, 0x00, 0x30, 0x10, 0x00, 0x00},
{0x15, 0x00, 0x00, 0x00, 0x3f, 0x18, 0x00, 0x00},
{0x15, 0x01, 0xff, 0x00, 0x38, 0x10, 0x00, 0x00},
{0x15, 0x01, 0x00, 0x00, 0x3f, 0x17, 0x00, 0x00},
{0x15, 0x01, 0x0e, 0xff, 0x3e, 0x10, 0x00, 0x00},
{0x15, 0x01, 0x0e, 0x00, 0x3f, 0x10, 0x00, 0x00},
{0x15, 0x01, 0x0e, 0x07, 0x3f, 0x11, 0x00, 0x00},
{0x15, 0x01, 0x09, 0x00, 0x3f, 0x13, 0x00, 0x00},
{0x15, 0x0e, 0x00, 0x00, 0x3f, 0x1c, 0x00, 0x00},
{0x15, 0x09, 0x00, 0x00, 0x3f, 0x1d, 0x00, 0x00},
{0x15, 0x0f, 0x00, 0x00, 0x3f, 0x1e, 0x00, 0x00},
{0x15, 0x05, 0x00, 0x00, 0x3f, 0x1f, 0x00, 0x00},
{0x01, 0xff, 0x00, 0x00, 0x38, 0x20, 0x00, 0x00},
{0x01, 0x00, 0x00, 0x00, 0x3f, 0x23, 0x00, 0x00},
{0x01, 0x0e, 0xff, 0x00, 0x3e, 0x20, 0x00, 0x00},
{0x01, 0x0e, 0x00, 0x00, 0x3f, 0x20, 0x00, 0x00},
{0x01, 0x0e, 0x07, 0x00, 0x3f, 0x21, 0x00, 0x00},
{0x01, 0x09, 0x00, 0x00, 0x3f, 0x25, 0x00, 0x00},
{0x01, 0x0f, 0x00, 0x00, 0x3f, 0x26, 0x00, 0x00},
{0x05, 0xff, 0x00, 0x00, 0x38, 0x30, 0x00, 0x00},
{0x05, 0x00, 0x00, 0x00, 0x3f, 0x34, 0x00, 0x00},
{0x05, 0x0e, 0xff, 0x00, 0x3e, 0x30, 0x00, 0x00},
{0x05, 0x0e, 0x00, 0x00, 0x3f, 0x30, 0x00, 0x00},
{0x05, 0x0e, 0x07, 0x00, 0x3f, 0x31, 0x00, 0x00},
{0x05, 0x09, 0x00, 0x00, 0x3f, 0x35, 0x00, 0x00},
{0x05, 0x12, 0x00, 0x00, 0x3f, 0x33, 0x00, 0x00},
{0x16, 0xff, 0x00, 0x00, 0x3c, 0x38, 0x00, 0x00},
{0x16, 0x00, 0x00, 0x00, 0x3f, 0x38, 0x00, 0x00},
{0x16, 0x01, 0xff, 0x00, 0x3f, 0x39, 0x00, 0x00},
{0x16, 0x01, 0x0e, 0x00, 0x3f, 0x39, 0x00, 0x00},
{0x16, 0x05, 0x00, 0x00, 0x3f, 0x1f, 0x00, 0x00},
{0x16, 0x0e, 0x00, 0x00, 0x3f, 0x3b, 0x00, 0x00}
};
const ziU16 zi8PyFinalIdx[0x10] = {
0x0010, 0x0001, 0x0003, 0x0014, 0x0005, 0x0007, 0x001c, 0x000d,
0x000f, 0x0011, 0x0013, 0x0015, 0x0017, 0x001d, 0x001f, 0x0035
};
ziU8 Zi8PriMatchNextChar(ziU8* p, ziU8 m0, ziU8 v0, ziU8 m1, ziU8 v1, ziU8 m2,
ziU8 v2, ziU8 m3, ziU8 v3, ziU16* count, ziU8** match,
ziU16* index ZI_NEED_WORK) {
ziU16 n;
n = *count;
while (n-- != 0) {
if ((p[0] & m0) == v0 && (p[3] & m3) == v3 && (p[2] & m2) == v2 &&
(p[1] & m1) == v1) {
*match = p;
*index = (ziU16)(((ziU8)p[6] << 8) + p[7]);
*count = n;
Zi8LogError(0x64, ZI_WORK);
return 1;
}
p += 0xC;
}
Zi8LogError(0x12E, ZI_WORK);
return 0;
}
ziU8 Zi8ExactMatchNextChar(ziU8* p, ziU8 m0, ziU8 v0, ziU8 m1, ziU8 v1, ziU8 m2,
ziU8 v2, ziU8 m3, ziU8 v3, ziU16* count, ziU8** match,
ziU16* index ZI_NEED_WORK) {
ziU8* q;
ziU16 n;
n = *count;
q = p;
while (n-- != 0) {
if ((q[0] & m0) == v0 && (q[3] & m3) == v3 && (q[2] & m2) == v2 &&
(q[1] & m1) == v1) {
*match = q;
*index = (ziU16)(((ziU8)q[6] << 8) + q[7]);
*count = n;
Zi8LogError(0x64, ZI_WORK);
return 1;
}
q += 0xC;
}
Zi8LogError(0x12E, ZI_WORK);
return 0;
}
ziU8 Zi8SecMatchChar(ziU8* p, ziU8* table, ziMatchParam* prm, ziU16* out ZI_NEED_WORK) {
ziU16 f22;
ziU16 idx;
ziU8 i;
ziU8* e;
ziU8 m;
ziU8 n;
ziU8 flag;
flag = 0;
if (prm->field22 != 0) {
f22 = prm->field22;
idx = (ziU16)(((ziU8)(p[4] & 3) << 8) | p[5]);
i = 0;
while (i++ < 6) {
if ((ziU16)f22 == idx) {
break;
}
idx = (ziU16)(((ziU8)(*(table + idx * 8 + 6) & 3) << 8) |
*(table + idx * 8 + 7));
if (idx == 0) {
break;
}
}
if ((ziU16)f22 != idx) {
return 0;
}
}
e = (ziU8*)Zi8GetTableAddress(1, 1, ZI_WORK);
e += ((ziU32)(p[9] & 0xF) << 16) + p[0xB] + (p[0xA] << 8);
if (ZI_WORK->unk_0x16 != 0) {
switch (*e & 7) {
case 2:
e += 2;
break;
case 3:
case 4:
e += 3;
break;
case 5:
e += 4;
break;
default:
e += 1;
break;
}
}
i = *e;
i = (ziU8)((i >> 4) & 7);
if (i * 2 + 0xA < (ziS32)prm->length) {
return 0;
}
if (prm->length < 9) {
if (prm->length == 8) {
if ((*e & 0xF) == 0xF) {
flag = 1;
}
} else if ((prm->length & 1) != 0) {
if ((p[(ziS32)prm->length >> 1] & 0xF) == 0xF) {
flag = 1;
}
} else {
if ((p[(ziS32)prm->length >> 1] & 0xF0) == 0xF0) {
flag = 1;
}
}
if (prm->length > 2) {
if ((prm->length & 1) != 0) {
if ((p[((ziS32)prm->length - 1) >> 1] & 0xF0) == 0 ||
(p[((ziS32)prm->length - 1) >> 1] & 0xF0) == 0xF0) {
return 0;
}
} else {
if ((p[((ziS32)prm->length - 1) >> 1] & 0xF) == 0 ||
(p[((ziS32)prm->length - 1) >> 1] & 0xF) == 0xF) {
return 0;
}
}
}
if (out != 0) {
*out = (ziU16)(((ziU16)p[6] << 8) + p[7]);
}
if (flag != 0) {
return 2;
}
return 1;
}
if ((prm->length & 1) != 0) {
if ((*(((ziS32)prm->length - 1 >> 1) + e - 4) & 0xF0) == 0 ||
(*(((ziS32)prm->length - 1 >> 1) + e - 4) & 0xF0) == 0xF0) {
return 0;
}
} else {
if ((*(((ziS32)prm->length - 1 >> 1) + e - 4) & 0xF) == 0 ||
(*(((ziS32)prm->length - 1 >> 1) + e - 4) & 0xF) == 0xF) {
return 0;
}
}
m = 4;
n = (ziU8)((((ziS32)prm->length + 1) >> 1) - 4);
if (i + 1 < (ziS32)n) {
return 0;
}
if ((prm->length & 1) != 0) {
if ((*(((ziS32)prm->length >> 1) + e - 4) & 0xF) == 0xF) {
flag = 1;
}
} else {
if ((*(((ziS32)prm->length >> 1) + e - 4) & 0xF0) == 0xF0) {
flag = 1;
}
}
if (prm->count == 0) {
while (n != 0) {
if ((*e & prm->arr1[m]) != prm->arrD[m]) {
return 0;
}
m++;
n--;
e++;
}
}
if (out != 0) {
*out = (ziU16)(((ziU16)p[6] << 8) + p[7]);
}
if (flag != 0) {
return 2;
}
return 1;
}
ziU8 Zi8PriMatchNextComp(ziU8* p, ziU8 m0, ziU8 v0, ziU8 m1, ziU8 v1, ziU8 m2,
ziU8 v2, ziU8 m3, ziU8 v3, ziU16* count,
ziU8** match ZI_NEED_WORK) {
ziU16 n;
n = *count;
while (n-- != 0) {
if ((p[0] & m0) == v0 && (p[1] & m1) == v1 && (p[2] & m2) == v2 &&
(p[3] & m3) == v3) {
*match = p;
*count = n;
Zi8LogError(0x64, ZI_WORK);
return 1;
}
p += 8;
}
Zi8LogError(0x12E, ZI_WORK);
return 0;
}
ziU8 Zi8SecMatchComp(ziU8* p, ziMatchParam* prm, ziU8* table) {
ziU16 f22;
ziU16 idx;
ziS32 i;
if (prm->field22 != 0) {
f22 = prm->field22;
idx = (ziU16)(((ziU8)(p[6] & 3) << 8) | p[7]);
i = 0;
while (i++ < 6) {
if ((ziU16)f22 == idx) {
break;
}
idx = (ziU16)(((ziU8)(table[idx * 8 + 6] & 3) << 8) |
table[idx * 8 + 7]);
if (idx == 0) {
break;
}
}
if ((ziU16)f22 != idx) {
return 0;
}
}
if (prm->length > 8) {
if (p[5] < (ziS32)(prm->length - 2)) {
return 0;
}
} else {
if (p[5] < (ziS32)(prm->length - 1)) {
return 0;
}
}
return 1;
}
ziU8 Zi8MatchPhonetic(ziU8* tblA, ziU8* tblB, ziU8* elements, ziU16 count16,
ziU8* tblC, ziU8* row, ziU16* masks, ziU16* vals,
ziU16* countP, ziU8** out, ziU32* limit, ziU8 a4, ziU8 a5,
ziU8 len, ziU16 m5, ziU16 v5, ziU8 mask, ziU8 flag,
ziU16 total, ziU16* out2, ziU8 aC ZI_NEED_WORK) {
ziU8 limf;
ziU16 n;
ziU16 pos;
ziU8 hits;
ziU8 cnt;
ziU8 cnt2;
ziU8 cur;
ziU16 w16;
ziU16 res;
ziU8* e;
if (*limit != 0) limf = 1; else limf = 0;
if (*countP != 0) n = *countP; else n = 1;
hits = 0;
if (aC != 0 && (ziU8)len > 1) {
flag = 1;
}
while (n-- != 0) {
if ((row[0] & mask) == 0) {
row += 0xC;
continue;
}
res = Zi8GetPCode(tblA, row);
if ((ziU16)vals[0] != (ziU16)(res & masks[0]) && flag == 0 &&
(row[0] & 0x80) != 0) {
if (*countP != 0) {
pos = (ziU16)(total - n - 1);
} else {
pos = total;
}
res = Zi8MatchAltSound(elements, count16, tblA, pos, masks[0],
vals[0], mask, ZI_WORK);
}
if ((ziU16)vals[0] != (ziU16)(res & masks[0])) {
row += 0xC;
continue;
}
if ((ziU16)v5 == (ziU16)(res & m5)) {
row += 0xC;
continue;
}
hits = 1;
if (*countP != 0) {
pos = (ziU16)(total - n - 1);
} else {
pos = total;
}
e = tblC + (row[0xA] << 8) + row[0xB] + ((ziU32)(row[9] & 0xF) << 16);
if (ZI_WORK->unk_0x16 != 0) {
switch (*e & 7) {
case 5:
e += 4;
break;
case 2:
e += 2;
break;
case 3:
case 4:
e += 3;
break;
default:
e += 1;
break;
}
}
if ((*e & 0x80) != 0) {
e += ((*e & 0x7F) >> 4) + 1;
} else {
if ((ziU8)len > 1) {
row += 0xC;
continue;
}
}
do {
if ((ziU8)hits == (ziU8)len || (ziU8)len == 0) {
goto done;
}
cur = *e++;
cnt = (ziU8)(cur & 0xF);
if ((cur & mask) == 0) {
while (cnt != 0) {
e++;
while ((*e & 0x80) == 0) {
e += 2;
}
e++;
cnt--;
}
}
while (cnt != 0) {
cnt2 = 1;
for (;;) {
if (limf != 0 && e > (ziU8*)*limit) {
limf = 0;
}
if (limf == 0) {
*limit = (ziU32)e;
}
w16 = (ziU16)(e[0] | (e[1] << 8));
e += 2;
if (limf == 0) {
res = Zi8GetPCode(tblA,
tblB + (w16 & 0x7FFF) * 0xC);
if ((ziU16)(res & masks[cnt2]) != vals[cnt2] &&
flag == 0 &&
(tblB[(w16 & 0x7FFF) * 0xC] & 0x80) != 0) {
res = Zi8MatchAltSound(elements, count16, tblA,
(ziU16)(w16 & 0x7FFF),
masks[cnt2], vals[cnt2],
mask, ZI_WORK);
}
}
if ((ziU16)(res & masks[cnt2]) == vals[cnt2]) {
cnt2++;
if ((ziU8)cnt2 == (ziU8)len) {
if (a4 == 0 ||
((a5 != 0) == ((w16 & 0x8000) != 0))) {
goto done;
}
goto skipw;
}
if ((w16 & 0x8000) == 0) {
continue;
}
break;
}
skipw:
if ((w16 & 0x8000) == 0) {
e++;
while ((*e & 0x80) == 0) {
e += 2;
}
e++;
}
break;
}
cnt--;
}
} while ((cur & 0x80) == 0);
row += 0xC;
}
return 0;
done:
*out = row;
*out2 = (ziU16)((row[6] << 8) + row[7]);
*countP = n;
return 1;
}
ziU8 Zi8GetPyPhonetic(ziWChar* in, ziU8 len, ziWChar* a, ziWChar* b, ziU8* nSyl,
ziU16* d, ziU16* e ZI_NEED_WORK) {
ziWChar buf[0x100];
ziWChar* p;
ziWChar c;
ziU8 x;
ziU8 y;
ziU8 flagC;
ziU8 flagD;
ziU8 len2;
ziU8 i;
ziU8 j;
ziU8 buf2[4];
ziU8 f11;
ziU8 f10;
p = buf;
flagC = 0;
y = 0;
*nSyl = 0;
if (len == 0) {
Zi8LogError(0x135, ZI_WORK);
return 0;
}
i = 0;
len2 = 0;
for (i = 0; (ziU8)i < len; i++) {
c = in[i];
if ((c >= 0xF341 && c <= 0xF35A) || (c >= 0x41 && c <= 0x5A)) {
if (len2 != 0 && p[len2 - 1] != 0xF360 && p[len2 - 1] != 0x27) {
p[len2] = 0x27;
len2 += 1;
}
p[len2] = (ziWChar)((ziU8)c + 0x20);
len2 += 1;
} else {
p[len2] = c;
len2 += 1;
}
}
len = len2;
j = 0;
*d = 0;
*e = 0;
while ((ziU8)j <= 0xF && len != 0) {
a[j] = 0;
b[j] = 0;
c = *p;
if (c >= 0x61 && c <= 0x7A) {
c -= 0x61;
} else if (c >= 0xF361 && c <= 0xF37A) {
c -= 0xF361;
} else {
fail:
*b = *a = *e = *d = 0xFFFF;
return 1;
}
x = Zi8PinyinInitials[c];
if (x != 0) {
if (j == 0) {
*nSyl = (ziU8)(*nSyl + 1);
}
y++;
a[j] = 0x7E00;
b[j] = (ziWChar)((x & 0x7F) << 9);
*d = *a;
*e = *b;
len--;
if (len == 0) {
goto out;
}
p++;
if ((x & 0x80) != 0) {
if (flagC != 0) {
a[j] &= 0xFDFF;
b[j] &= 0xFDFF;
}
c = *p;
if (c == 0x68 || c == 0xF368) {
if (j == 0) {
*nSyl = (ziU8)(*nSyl + 1);
}
b[j] += 0x200;
*d = *a;
*e = *b;
len--;
if (len == 0) {
goto out;
}
p++;
}
}
} else {
if (*p == 0xF369 || *p == 0x69) {
goto fail;
}
}
flagD = 0;
for (i = 0; (ziU8)i < 4; i++) {
buf2[i] = 0;
}
i = 0;
while ((ziU8)i < 4) {
c = *p;
if (c == 0x27 || c == 0xF360 || c == 0x20) {
if (i != 0) {
flagD = 1;
}
break;
}
if (c >= 0xF331 && c < 0xF336) {
if (i != 0) {
flagD = 1;
}
break;
}
if (!(c >= 0x61 && c <= 0x7A)) {
if (c < 0xF361) {
break;
}
c -= 0xF361;
if (c > 0x19) {
if (j == 0) {
*nSyl = (ziU8)(*nSyl + 1);
}
break;
}
} else {
c -= 0x61;
}
buf2[i] = (ziU8)((ziU16)c + 1);
if (Zi8GetPyFinal(buf2, &f11, &f10) != 0) {
if (j == 0) {
*nSyl = (ziU8)(*nSyl + 1);
}
p++;
i++;
len--;
if (len == 0) {
break;
}
continue;
}
if (i < 3) {
buf2[i + 1] = 0xFF;
if (Zi8GetPyFinal(buf2, &f11, &f10) != 0) {
if (j == 0) {
*nSyl = (ziU8)(*nSyl + 1);
}
buf2[i + 1] = 0;
p++;
i++;
len--;
if (len == 0) {
break;
}
continue;
}
buf2[i + 1] = 0;
buf2[i] = 0;
flagD = 1;
break;
}
buf2[i] = 0;
flagD = 1;
break;
}
if ((ziU8)i > 3 && len != 0) {
c = *p;
if (c == 0x27 || c == 0xF360 || c == 0x20) {
if (j == 0) {
*nSyl = (ziU8)(*nSyl + 1);
}
p++;
len--;
}
}
if ((ziU8)i > 3) {
flagD = 1;
}
if (flagD != 0 && flagC == 0) {
if (Zi8GetPyFinal(buf2, &f11, &f10) != 0) {
if (x == 0) {
y++;
a[j] = 0x7E00;
b[j] = 0x200;
}
a[j] |= (ziWChar)(f11 << 3);
b[j] |= (ziWChar)(f10 << 3);
*d = *a;
*e = *b;
goto tail;
}
if (i == 0) {
goto tail;
}
if (len != 0) {
goto fail;
}
goto tail;
}
buf2[i] = 0xFF;
if (Zi8GetPyFinal(buf2, &f11, &f10) != 0) {
if (x == 0) {
y++;
a[j] = 0x7E00;
b[j] = 0x200;
}
a[j] |= (ziWChar)(f11 << 3);
b[j] |= (ziWChar)(f10 << 3);
*d = *a;
*e = *b;
if (j == 0 && len == 0) {
buf2[i] = 0;
if (Zi8GetPyFinal(buf2, &f11, &f10) != 0) {
if (x == 0) {
*d = 0x7E00;
*e = 0x200;
}
*d |= (ziU16)(f11 << 3);
*e |= (ziU16)(f10 << 3);
}
}
goto tail;
}
buf2[i] = 0;
if (Zi8GetPyFinal(buf2, &f11, &f10) != 0) {
if (x == 0) {
y++;
a[j] = 0x7E00;
b[j] = 0x200;
}
a[j] |= (ziWChar)(f11 << 3);
b[j] |= (ziWChar)(f10 << 3);
*d = *a;
*e = *b;
goto tail;
}
tail:
if (len == 0) {
goto out;
}
c = *p;
if (c == 0x27 || c == 0xF360 || c == 0x20) {
p++;
len--;
if (j == 0) {
*nSyl = (ziU8)(*nSyl + 1);
}
goto out;
}
if (c < 0xF331) {
goto out;
}
c -= 0xF331;
if (c > 4) {
goto out;
}
c++;
a[j] |= 7;
b[j] |= c;
*d = *a;
*e = *b;
len--;
p++;
if (j == 0) {
*nSyl = (ziU8)(*nSyl + 1);
}
if (len == 0) {
goto out;
}
c = *p;
if (c == 0x27 || c == 0xF360 || c == 0x20) {
len--;
p++;
if (j == 0) {
*nSyl = (ziU8)(*nSyl + 1);
}
}
out:
j++;
}
if ((ziU8)y > 1) {
c = in[*nSyl - 1];
if (c >= 0xF341 && c <= 0xF35A) {
*nSyl = (ziU8)(*nSyl - 1);
}
}
return y;
}
ziU8 Zi8GetPyFinal(ziU8* s, ziU8* o1, ziU8* o2) {
ziU8 i;
ziU8 j;
i = 0;
j = 0;
while ((ziU8)j < 0x36) {
while ((ziU8)i < 4 && s[i] == Zi8PinyinFinals[j][i]) {
i++;
}
if ((ziU8)i >= 4) {
*o1 = Zi8PinyinFinals[j][4];
*o2 = Zi8PinyinFinals[j][5];
return 1;
}
j++;
i = 0;
}
return 0;
}
ziU8 Zi8GetBpmfPhonetic(ziWChar* in, ziU8 count, ziU16* a, ziU16* b, ziU16* d,
ziU16* e ZI_NEED_WORK) {
ziU16 c;
ziU16 idx;
ziU8 n;
n = 0;
Zi8LogError(0x64, ZI_WORK);
if (count == 0) {
Zi8ReplaceLastError(0x135, ZI_WORK);
return 0;
}
c = *in;
if (c < 0xF305) {
Zi8ReplaceLastError(0x154, ZI_WORK);
return 0;
}
idx = c - 0xF305;
if (idx >= 0x25) {
Zi8ReplaceLastError(0x154, ZI_WORK);
return 0;
}
if (idx < 0x15) {
*a = 0x7E00;
*b = (ziU16)((Zi8BpmfInitials[idx] & 0x7F) << 9);
n++;
count--;
if (count == 0) {
*d = *a;
*e = *b;
if (idx >= 0xE && idx <= 0x14) {
*d |= 0x1F8;
*e |= 0x38;
}
return n;
}
in++;
if (*in == 0xF360) {
n++;
count--;
if (count == 0) {
return n;
}
Zi8ReplaceLastError(0x156, ZI_WORK);
return 0;
}
} else {
*a = 0x7E00;
*b = 0x200;
}
c = *in;
idx = c - 0xF305;
switch (idx) {
case 0x22:
*b |= 0x80;
*a |= 0x180;
n++;
count--;
if (count == 0) {
*d = *a | 0x78;
*e = *b | 0x38;
return n;
}
in++;
break;
case 0x23:
*b |= 0x100;
*a |= 0x180;
n++;
count--;
if (count == 0) {
*d = *a | 0x78;
*e = *b | 0x38;
return n;
}
in++;
break;
case 0x24:
*b |= 0x180;
*a |= 0x180;
n++;
count--;
if (count == 0) {
*d = *a | 0x78;
*e = *b | 0x38;
return n;
}
in++;
break;
default:
if (*in < 0xF331 || *in > 0xF335) {
*a |= 0x180;
}
break;
}
c = *in;
idx = c - 0xF305;
if (idx <= 0x14 || idx >= 0x22) {
if (*in < 0xF331 || *in > 0xF335 || (*a & 0x180) == 0x180) {
*b |= 0x38;
*a |= 0x78;
}
} else {
*b |= Zi8BpmfInitials[idx] << 3;
*a |= 0x78;
n++;
count--;
if (count == 0) {
*d = *a;
*e = *b;
return n;
}
in++;
}
c = *in;
if (c < 0xF331) {
Zi8ReplaceLastError(0x155, ZI_WORK);
return 0;
}
idx = c - 0xF331;
if (idx > 5) {
Zi8ReplaceLastError(0x155, ZI_WORK);
return 0;
}
*a |= 7;
*b |= idx;
*d = *a;
*e = *b;
n++;
count--;
if (count != 0) {
Zi8ReplaceLastError(0x157, ZI_WORK);
return 0;
}
return n;
}
ziU16 Zi8GetPCode(ziU8* table, ziU8* p) {
ziU16 idx;
idx = (ziU16)(((ziU16)p[8] << 2) | (((ziU16)p[9] & 0x80) >> 6));
return (ziU16)((((ziU16)p[9] >> 4) & 7) | table[idx] |
((ziU16)table[idx + 1] << 8));
}

View File

@@ -0,0 +1,144 @@
#include <zi8clib/zitypes.h>
#include <zi8clib/zierror.h>
extern ziU16 Zi8GetTableCount(ziU8 lang, ziU8 tableIdx ZI_NEED_WORK);
extern ziU32 Zi8GetTableAddress(ziU8 lang, ziU8 tableIdx ZI_NEED_WORK);
typedef struct { ziU8 b[0xC]; } ziE12;
#define WORKP ((struct __zi8_work_data_s*)__zi8_work_data)
ziU16 Zi8Uni2Ptr(ziU16 ch, ziE12* buf ZI_NEED_WORK) {
ziU8 hi;
ziU8 lo;
ziU16 count;
ziU32 table;
ziU32 table2;
ziU16 i;
ziU8* e;
ziU8* p;
hi = (ziU8)(((ziU16)ch >> 8) & 0xFF);
lo = (ziU8)ch;
count = Zi8GetTableCount(1, 0, __zi8_work_data);
table = Zi8GetTableAddress(1, 0, __zi8_work_data);
table2 = Zi8GetTableAddress(1, 1, __zi8_work_data);
if (buf == ZI8_NULL) {
for (i = 0; i < 0x40; i++) {
if (ch == WORKP->unk_0x20[i]) {
i = WORKP->unk_0xA0[i];
e = (ziU8*)table + i * 0xC;
if (i >= count) {
break;
}
if (hi != e[6] || lo != e[7]) {
break;
}
p = (ziU8*)(table2 +
(((e[9] & 0xF) << 16) |
(e[0xB] | (e[0xA] << 8))));
if (WORKP->unk_0x16 != 0) {
switch (p[0] & 7) {
case 2:
p += 2;
break;
case 3:
case 4:
p += 3;
break;
case 5:
p += 4;
break;
default:
p += 1;
break;
}
}
if ((p[0] & 0x80) == 0) {
break;
}
if (buf != ZI8_NULL) {
*buf = *(ziE12*)e;
}
return i;
}
}
}
e = (ziU8*)table;
if (WORKP->unk_0x1B18 != ZI8_NULL && WORKP->unk_0x1B24 == WORKP->unk_0x18) {
if ((ziU16)ch >= WORKP->unk_0x1B1C && (ziU16)ch <= WORKP->unk_0x1B1E) {
i = (ziU16)(ch - WORKP->unk_0x1B1C);
goto map;
}
if ((ziU16)ch >= WORKP->unk_0x1B20 && (ziU16)ch <= WORKP->unk_0x1B22) {
i = (ziU16)(WORKP->unk_0x1B1E + (ch - WORKP->unk_0x1B20) -
WORKP->unk_0x1B1C + 1);
goto map;
}
return 0xFFFF;
map:
i = WORKP->unk_0x1B18[i];
if (i != 0xFFFF) {
e = (ziU8*)table + i * 0xC;
if (hi == e[6] && lo == e[7]) {
if (buf != ZI8_NULL) {
*buf = *(ziE12*)e;
}
return i;
}
}
return 0xFFFF;
}
i = 0;
while (i < count) {
if (lo == e[7] && hi == e[6]) {
if (buf != ZI8_NULL) {
*buf = *(ziE12*)e;
}
return i;
}
e += 0xC;
i++;
}
return 0xFFFF;
}
ziU16 Zi8Uni2Ord(ziU16 ch ZI_NEED_WORK) {
return Zi8Uni2Ptr(ch, ZI8_NULL, __zi8_work_data);
}
ziU16 Zi8Ord2Uni(ziU16 ord ZI_NEED_WORK) {
ziU8* p;
if ((ziU16)ord >= Zi8GetTableCount(1, 0, __zi8_work_data)) {
Zi8LogError(0x132, __zi8_work_data);
return 0;
}
p = (ziU8*)Zi8GetTableAddress(1, 0, __zi8_work_data);
p += ord * 0xC;
Zi8LogError(0x64, __zi8_work_data);
return (ziU16)(((ziU16)p[6] << 8) + p[7]);
}
ziU16 Zi8Ord2Ord(ziU16 ord ZI_NEED_WORK) {
ziU32 table;
ziU16 count;
ziU8* p;
count = Zi8GetTableCount(1, 0, __zi8_work_data);
table = Zi8GetTableAddress(1, 0, __zi8_work_data);
if (ord == 0 || (ziU16)ord >= count) {
Zi8LogError(0x132, __zi8_work_data);
return ord;
}
p = (ziU8*)table + (ord - 1) * 0xC;
while (ord != 0) {
if (p[6] != p[0x12] || p[7] != p[0x13]) {
break;
}
p -= 0xC;
ord--;
}
Zi8LogError(0x64, __zi8_work_data);
return ord;
}

View File

@@ -0,0 +1,276 @@
#include <zi8clib/zitypes.h>
#include <zi8clib/zierror.h>
extern ziU8 Zi8ConvertUC2Key(ziU8 ch, ziU8 lang ZI_NEED_WORK);
extern ziU16 Zi8ConvertUC2WC(ziU8 ch, ziU8 lang ZI_NEED_WORK);
extern ziU16 Zi8ConvertWC2Key(ziWChar ch, ziU8 lang ZI_NEED_WORK);
extern ziU8 Zi8ChangeCharCase(ziU8 dir, ziWChar* buf, ziU8 lang ZI_NEED_WORK);
static ziU8 Zi8_8147FD7C(ziU32 a0, ziU8 a1, ziU8 a2, ziU32 a3, ziU16 a4,
ziU8 a5, ziU8 a6 ZI_NEED_WORK);
ziS32 ZiIsPhoneticChar(ziWChar ch) {
if ((ziU16)ch >= 0xF305 && (ziU16)ch <= 0xF329) {
goto ret1;
}
if ((ziU16)ch >= 0xF361 && (ziU16)ch <= 0xF37A) {
goto ret1;
}
return 0;
ret1:
return 1;
}
ziS32 ZiGetZHWordSize(ziWChar* s, ziS32 len) {
ziWChar* t;
ziS32 i = 0;
i = 0;
while (i < len) {
t = s;
if (ZiIsPhoneticChar(*t)) {
return i;
}
i += 2;
s++;
}
return i;
}
void Zi8CopyZHSpelling(ziWChar* src, ziWChar* dst, ziU16 cnt, ziS32 start,
ziS32 end) {
ziS32 i;
ziWChar* p;
if (dst == ZI8_NULL) {
return;
}
if (cnt == 0) {
return;
}
*dst = 0;
if (start <= end) {
return;
}
i = 0;
while (i < start - end && i < (ziU16)cnt * 2) {
p = (ziWChar*)((ziU8*)src + end + i);
*dst = *p;
dst++;
i += 2;
}
*dst = 0;
}
ziU8 ZADP_Zi8SetPDremoveOpt(ziU8 opt, struct __zi8_work_data_s* work) {
ziU8 old = work->pdRemoveOpt;
work->pdRemoveOpt = opt;
Zi8LogError(0x64, work);
return old;
}
ziU8 Zi8MatchPUDdata_ZHS(ziWChar* w, ziU8 len, ziU8 lang, ziWChar* out,
ziU16 lim, ziWChar* arg5, ziU16 arg6, ziU8 a7,
ziU8 a8 ZI_NEED_WORK) {
ziU8* p;
ziS32 i;
ziS32 b0;
ziS32 r27;
ziS32 r30;
struct __zi8_work_data_s* work = ZI_WORK;
ziU32 flagZ;
ziU8* wb;
ziU32 sz;
ziU32 t;
ziU8* outp;
ziWChar wc;
flagZ = 0;
if (work->pudCount > 0x10 || work->pudCount == 0 ||
work->pudTable[work->pudCount - 1] == 0) {
Zi8LogError(0x4B0, work);
return 0;
}
if (lang == 1) {
len <<= 1;
}
if (a8 == 0) {
t = work->pudTable[work->pudCount - 1];
p = (ziU8*)t + 8;
i = 0;
while (i < ((ziU8*)t)[3]) {
if (p[1] == lang) {
goto found;
}
p += 8;
i++;
}
if (i >= ((ziU8*)t)[3]) {
Zi8LogError(0x4F6, work);
return 0;
}
found:
work->unk_0x314 = ((ziU16)p[4] << 8) + (ziU16)p[5];
work->unk_0x310 = t + ((ziU16)p[2] << 8) + (ziU16)p[3];
work->unk_0x318 = 0;
}
loop_head:
p = (ziU8*)work->unk_0x310;
if (p == ZI8_NULL) {
Zi8LogError(0x4B3, work);
return 0;
}
goto check;
body:
b0 = (ziU8)*p;
p++;
sz = b0;
if (lang == 1) {
if ((ziU8)work->unk_0x17 > *p) {
goto miss;
}
b0--;
sz--;
p++;
b0 = ZiGetZHWordSize((ziWChar*)p, sz);
} else {
if (work->unk_0x31E != 0 && a7 != 0 && (ziU8)len < b0 &&
p[len] == 0x20) {
goto cmp454;
}
}
if ((ziU8)len > b0) {
goto miss;
}
if (a7 != 0 && b0 != (ziU8)len) {
goto miss;
}
if (a7 != 0 || b0 != (ziU8)len) {
goto cmp410;
}
miss:
work->unk_0x318++;
p += sz;
goto tail;
cmp410:
if (lang == 1) {
wb = (ziU8*)w;
i = 0;
while (i < len) {
if (p[i] != wb[i]) {
goto miss;
}
i++;
}
goto matched;
}
cmp454:
for (i = 0; i < len; i++) {
if ((ziU16)w[i] >= 0xEFF1 && (ziU16)w[i] <= 0xF37F) {
if (Zi8ConvertUC2Key(p[i], lang, work) != w[i]) {
goto miss;
}
} else {
wc = Zi8ConvertUC2WC(p[i], lang, work);
if (wc == w[i]) {
goto next454;
}
if (work->unk_0x1F == 0) {
goto miss;
}
if (Zi8ChangeCharCase(0, &wc, lang, work) == 0) {
goto miss;
}
if (wc != w[i]) {
goto miss;
}
}
next454:;
}
matched:
if (flagZ != 0) {
work->unk_0x310 = ZI8_NULL;
work->unk_0x318 = 0;
work->unk_0x314 = 0;
if ((ziU16)w[0] >= 0xEFF1) {
out[0] = w[0];
} else {
out[0] = Zi8ConvertWC2Key(w[0], lang, work);
}
return 1;
}
if (lang == 1) {
outp = (ziU8*)out;
r27 = 0;
r30 = 0;
while (r30 < b0 && r27 < (ziU16)lim) {
outp[r30] = p[r30];
r30++;
outp[r30] = p[r30];
r30++;
r27++;
}
Zi8CopyZHSpelling((ziWChar*)p, arg5, arg6, sz, b0);
} else {
r27 = 0;
while (r27 < b0 && r27 < (ziU16)lim) {
out[r27] = Zi8ConvertUC2WC(p[r27], lang, work);
if (work->unk_0x31E != 0 && r27 >= (ziU8)len &&
out[r27] == 0x20) {
if (a7 != 0) {
goto done;
}
if (r27 < (ziU8)len) {
goto miss;
}
goto done;
}
r27++;
}
}
done:
work->unk_0x318++;
work->unk_0x310 = (ziU32)(p + sz);
Zi8LogError(0x64, work);
return (ziU8)r27;
check:
tail:
if (work->unk_0x318 < work->unk_0x314) {
goto body;
}
if (len == 1 && a7 != 0 && a8 == 0) {
a7 = 0;
flagZ = 1;
work->unk_0x318 = 0;
goto loop_head;
}
work->unk_0x310 = ZI8_NULL;
work->unk_0x318 = 0;
work->unk_0x314 = 0;
return 0;
}
ziU8 Zi8MatchPUDdata(ziU32 a0, ziU8 a1, ziU8 a2, ziU32 a3, ziU16 a4, ziU8 a5,
ziU8 flag, struct __zi8_work_data_s* work) {
ziU8 res;
if (flag == 0) {
work->pudCount = 1;
}
retry:
res = Zi8_8147FD7C(a0, a1, a2, a3, a4, a5, flag, work);
if (res == 0) {
if ((ziU8)++work->pudCount <= 0x10) {
flag = 0;
goto retry;
}
work->pudCount = 1;
}
return res;
}
ziU8 Zi8_8147FD7C(ziU32 a0, ziU8 a1, ziU8 a2, ziU32 a3, ziU16 a4, ziU8 a5,
ziU8 a6 ZI_NEED_WORK) {
return Zi8MatchPUDdata_ZHS((ziWChar*)a0, a1, a2, (ziWChar*)a3, a4,
(ziWChar*)0, 0, a5, a6, __zi8_work_data);
}

View File

@@ -0,0 +1,99 @@
#include <zi8clib/zi8space.h>
#include <zi8clib/zierror.h>
#include <zi8clib/zitypes.h>
extern ziU8 Zi8GetPyPhonetic(ziWChar* src, ziU8 i, ziWChar* a, ziWChar* b, ziU8* c,
ziU16* d, ziU16* e ZI_NEED_WORK);
extern ziU8 Zi8GetBpmfPhonetic(ziWChar* src, ziU8 i, ziWChar* a, ziWChar* b,
ziU16* d, ziU16* e ZI_NEED_WORK);
ziU8 Zi8ZHaddSpace(ziWChar* src, ziU8 count, ziWChar* dst,
ziU16 maxLen ZI_NEED_WORK) {
ziWChar candBuf[0x10];
ziWChar pyBuf[0x10];
ziU16 m;
ziU16 vE;
ziU16 vC;
ziU8 n;
ziU8 flag;
ziU8 v9;
ziU8 isPy;
int i;
int k;
ziWChar* psrc;
ziWChar* pdst;
psrc = src;
n = count;
pdst = dst;
m = maxLen;
if (n == 0) {
Zi8LogError(0x137, ZI_WORK);
return 0;
}
if ((psrc[0] >= 0xF361 && psrc[0] <= 0xF37A) ||
(psrc[0] >= 0xF341 && psrc[0] <= 0xF35A)) {
isPy = 1;
} else if (psrc[0] >= 0xF305 && psrc[0] <= 0xF329) {
isPy = 0;
} else {
goto fail;
}
i = 2;
while (i <= n) {
if (isPy) {
flag = Zi8GetPyPhonetic(psrc, i, candBuf, pyBuf, &v9, &vE, &vC, ZI_WORK);
if (i == v9) {
i++;
continue;
}
} else {
if ((psrc[i - 1] == 0xF360 && psrc[i - 2] != 0xF360) ||
Zi8GetBpmfPhonetic(psrc, i, candBuf, pyBuf, &vE, &vC, ZI_WORK) !=
0) {
i++;
continue;
}
}
if (i-- >= m - 1) {
goto fail;
}
m -= i + 1;
for (k = 0; k < i; k++) {
pdst[k] = psrc[k];
}
if (pdst[k - 1] != 0xF360 &&
(pdst[k - 1] < 0xF331 || pdst[k - 1] > 0xF335)) {
pdst[k++] = ZI_WORK->unk_0x1A;
}
psrc += i;
n -= i;
pdst += k;
i = 2;
}
if (i-- > m) {
goto fail;
}
for (k = 0; k < i; k++) {
pdst[k] = psrc[k];
}
pdst[k] = 0;
Zi8LogError(0x64, ZI_WORK);
return 1;
fail:
if ((ziU8)count >= (ziU16)maxLen) {
count = (ziU8)(maxLen - 1);
}
for (i = 0; i < count; i++) {
dst[i] = src[i];
}
dst[i] = 0;
Zi8LogError(0x64, ZI_WORK);
return 1;
}

View File

@@ -0,0 +1,284 @@
#include <zi8clib/zierror.h>
extern ziWChar Zi8ConvertUC2WC(ziU8 ch, ziU8 language ZI_NEED_WORK);
extern ziU16 Zi8ConvertUC2Key(ziU8 ch, ziU8 language ZI_NEED_WORK);
extern ziChar Zi8ConvertWC2UC(ziWChar ch, ziU8 language ZI_NEED_WORK);
extern ziU8 Zi8ChangeCharCase(ziU8 toUpper, ziWChar* ch, ziU8 language ZI_NEED_WORK);
extern void Zi8Memset(ziPtr p, ziU32 v, ziU32 len);
extern void Zi8ReplaceLastError(ziU16 err ZI_NEED_WORK);
static ziU32 Zi8_81480224(ziU8* word ZI_NEED_WORK) {
ziUwdNode* prev;
ziUwdNode* node;
ziU8* nw;
ziUwdNode* slot;
ziU8 len;
ziU8 i;
if (ZI_WORK->uwdCount >= 0x20) {
Zi8LogError(0x19d, ZI_WORK);
return 0;
}
if (word == 0) {
Zi8LogError(0x19f, ZI_WORK);
return 0;
}
len = word[2];
if (len == 0) {
Zi8LogError(0x193, ZI_WORK);
return 0;
}
if (len > 0x3F) {
Zi8LogError(0x194, ZI_WORK);
return 0;
}
prev = 0;
for (node = ZI_WORK->uwdList; node != 0; node = node->next) {
nw = node->word;
if (ZI_WORK->unk_0x12E == 1 && word[3] > nw[3]) {
break;
}
if (nw[2] == len) {
for (i = 0; i < len; i++) {
if (nw[4 + i] != word[4 + i]) break;
}
if (i == len) {
Zi8LogError(0x64, ZI_WORK);
return 0;
}
}
prev = node;
}
slot = &ZI_WORK->uwdNodes[ZI_WORK->uwdCount++];
if (prev == 0) {
ZI_WORK->uwdList = slot;
slot->next = node;
} else {
prev->next = slot;
slot->next = node;
}
slot->word = word;
Zi8LogError(0x64, ZI_WORK);
return 1;
}
static ziU8* Zi8_814803F4(ziPtr __zi8_work_data) {
ziU8* word;
if (ZI_WORK->uwdCount != 0) {
ZI_WORK->uwdCount--;
word = ZI_WORK->uwdList->word;
ZI_WORK->uwdList = ZI_WORK->uwdList->next;
Zi8LogError(0x64, ZI_WORK);
return word;
}
Zi8LogError(0x19e, ZI_WORK);
return 0;
}
static void Zi8_8148047C(ziPtr __zi8_work_data) {
Zi8Memset(ZI_WORK->uwdNodes, 0, 0x100);
ZI_WORK->uwdCount = 0;
ZI_WORK->uwdList = 0;
}
ziU8 Zi8MatchUWDdata(ziWChar* keys, ziU8 keyLen, ziWChar* word, ziU16 wordLen,
ziU8 lang, ziWChar* out, ziU16 maxLen, ziU8 flag8,
ziU8 flag9 ZI_NEED_WORK) {
ziU8* base;
ziU8* cur;
ziU8* bound;
ziU8* lim34;
ziU8* lim30;
ziU8* end2c;
ziU32 flag28;
ziU32 len24;
ziS32 v20;
ziS32 v1c;
ziS32 len18;
ziS32 j;
ziS32 cnt;
ziU32 flag_c;
ziWChar wch;
ziU8* p2;
ziU8* w;
ziS32 i;
ziS32 n28;
cnt = 0;
flag_c = 0;
Zi8LogError(0x64, ZI_WORK);
if (ZI_WORK->unk_0x138 > 2 || ZI_WORK->unk_0x138 == 0 ||
ZI_WORK->unk_0x130[ZI_WORK->unk_0x138 - 1] == 0) {
Zi8ReplaceLastError(0x19c, ZI_WORK);
return 0;
}
base = ZI_WORK->unk_0x130[ZI_WORK->unk_0x138 - 1];
if (flag9 != 0) {
w = Zi8_814803F4(ZI_WORK);
len18 = 0;
if (w != 0) {
lang = w[1];
len18 = w[2];
if (len18 >= maxLen) {
Zi8_8148047C(ZI_WORK);
return 0;
}
w += 4;
for (i = 0; i < len18; i++) {
out[i] = Zi8ConvertUC2WC(w[i], lang, ZI_WORK);
}
}
return (ziU8)len18;
}
Zi8_8148047C(ZI_WORK);
ZI_WORK->unk_0x13C = 0;
if (word != 0 && wordLen != 0 && word[wordLen - 1] == 0x20) {
n28 = 0;
i = wordLen - 2;
while (i >= 0) {
if (word[i] == 0x20) break;
i--;
n28++;
}
i++;
if (n28 == 0 || n28 > 0x3F) {
ZI_WORK->unk_0x140 = 0;
goto L594;
}
ZI_WORK->unk_0x140 = 1;
ZI_WORK->unk_0x141[0] = (ziU8)(n28 + 5);
ZI_WORK->unk_0x141[4 + n28] = (ziU8)(n28 + 5);
ZI_WORK->unk_0x141[1] = lang;
ZI_WORK->unk_0x141[2] = (ziU8)n28;
j = 4;
while (n28 > 0) {
wch = word[i];
ZI_WORK->unk_0x141[j] = Zi8ConvertWC2UC(wch, lang, ZI_WORK);
ZI_WORK->unk_0x184[j] = 0;
if (ZI_WORK->unk_0x1F != 0) {
if (Zi8ChangeCharCase(1, &wch, lang, ZI_WORK) == 0) {
Zi8ChangeCharCase(0, &wch, lang, ZI_WORK);
}
ZI_WORK->unk_0x184[j] = Zi8ConvertWC2UC(wch, lang, ZI_WORK);
}
j++;
if (ZI_WORK->unk_0x141[j - 1] == 0) {
ZI_WORK->unk_0x140 = 0;
goto L594;
}
n28--;
i++;
}
} else {
ZI_WORK->unk_0x140 = 0;
}
L594:
if (ZI_WORK->unk_0x140 == 0 && keyLen == 0) {
return 0;
}
bound = base + *(ziU16*)(base + 4) + 8;
cur = bound;
lim34 = base + *(ziU16*)(base + 6) + 7;
lim30 = base + *(ziU16*)(base + 2) + 7;
flag28 = (bound < lim34) ? 1 : 0;
for (;;) {
L924:
if (cur < lim34) {
if (flag28 != 0) goto L628;
}
if (cur >= lim30) goto L95c;
if (flag28 == 0) goto L628;
goto L95c;
L628:
len24 = *cur;
if ((ziS32)(cnt++) < (ziS32)ZI_WORK->unk_0x13C || (*cur & 0xC0) != 0) {
goto L660;
}
end2c = cur + len24;
if (end2c > lim30) {
end2c = base + (lim30 - cur) + 7;
}
p2 = cur;
v20 = *p2++;
v1c = *p2++;
len18 = *p2++;
p2++;
if (v1c != lang) goto L660;
if ((ziS32)len18 < (ziS32)keyLen) goto L660;
if ((ziS32)len18 >= (ziS32)maxLen) goto L660;
if (flag8 != 0) {
if (len18 != keyLen) goto L660;
} else {
if (len18 == keyLen) goto L660;
}
for (i = 0; i < keyLen; i++) {
if (keys[i] >= 0xEFF1 && keys[i] <= 0xF010) {
if (Zi8ConvertUC2Key(p2[i], lang, ZI_WORK) != keys[i]) goto L660;
} else {
wch = Zi8ConvertUC2WC(p2[i], lang, ZI_WORK);
if (wch != keys[i]) {
if (ZI_WORK->unk_0x1F == 0) goto L660;
if (Zi8ChangeCharCase(0, &wch, lang, ZI_WORK) == 0) goto L660;
if (wch != keys[i]) goto L660;
}
}
}
if (ZI_WORK->unk_0x140 != 0) {
if (ZI_WORK->unk_0x141[0] != end2c[0]) goto L660;
if (ZI_WORK->unk_0x141[1] != end2c[1]) goto L660;
if (ZI_WORK->unk_0x141[2] != end2c[2]) goto L660;
for (j = 4; j < ZI_WORK->unk_0x141[2] + 4; j++) {
if (ZI_WORK->unk_0x141[j] != end2c[j] &&
ZI_WORK->unk_0x184[j] != end2c[j]) {
goto L660;
}
}
}
Zi8_81480224(cur, ZI_WORK);
L660:
cur += len24;
if (cur <= lim30) goto L924;
if (flag28 != 0) goto L95c;
flag28 = 1;
len24 = cur - lim30 - 1;
cur = base + len24 + 8;
}
L95c:
if (ZI_WORK->unk_0x140 != 0 && keyLen != 0) {
ZI_WORK->unk_0x140 = 0;
cnt = 0;
goto L594;
}
if (keyLen == 1 && flag8 != 0 && flag9 == 0) {
flag8 = 0;
flag_c = 1;
cnt = 0;
goto L594;
}
w = Zi8_814803F4(ZI_WORK);
if (w != 0) {
lang = w[1];
len18 = w[2];
if (len18 >= maxLen) {
Zi8_8148047C(ZI_WORK);
return 0;
}
w += 4;
for (i = 0; i < len18; i++) {
out[i] = Zi8ConvertUC2WC(w[i], lang, ZI_WORK);
}
return (ziU8)len18;
}
return 0;
}

View File

@@ -0,0 +1,207 @@
#include <zi8clib/zitypes.h>
#include <zi8clib/zierror.h>
extern ziU16 nodeHeaderTable[0x10];
ziU8* ZiDAWGGetChild(ziU8* node) {
ziU8* orig = node;
ziU16 hdr;
ziU32 off;
hdr = (ziU16)nodeHeaderTable[node[0] >> 4];
if (!(hdr & 1)) {
return ZI8_NULL;
}
if ((node[0] & 0xF) == 0xF) {
off = 2;
} else {
off = 1;
}
node += off;
if ((hdr & 2) != 0) {
if ((node[0] & 0x80) != 0) {
off = (((ziU32)(node[0] & 0x7F) << 16) +
(ziU32)((ziU16)node[1] << 8)) + 0x8000;
off = node[2] + off;
} else {
off = ((ziU16)node[0] << 8) + node[1];
}
} else if ((hdr & 8) != 0) {
if ((node[0] & 0x80) != 0) {
off += 3;
} else {
off += 2;
}
}
return orig + off;
}
ziU8* ZiDAWGGetSibling(ziU8* node) {
ziU8* orig = node;
ziS32 count = 0;
ziU16 hdr;
ziS32 off = 0;
hdr = (ziU16)nodeHeaderTable[node[0] >> 4];
if (!(hdr & 4)) {
return ZI8_NULL;
}
if ((hdr & 8) != 0) {
if ((node[0] & 0xF) == 0xF) {
node += 2;
} else {
node += 1;
}
if ((hdr & 2) != 0) {
if ((node[0] & 0x80) != 0) {
node += 3;
} else {
node += 2;
}
}
if ((node[0] & 0x80) != 0) {
count = ((ziU32)(node[0] & 0x7F) << 16) +
((ziU16)node[1] << 8);
count += 0x8000;
orig += node[2];
orig = (ziU8*)((ziU32)count + (ziU32)orig);
} else {
orig = orig + ((ziU16)node[0] << 8) + node[1];
}
return orig;
}
do {
hdr = (ziU16)nodeHeaderTable[node[0] >> 4];
if ((node[0] & 0xF) == 0xF) {
node += 2;
off += 2;
} else {
node += 1;
off += 1;
}
if ((hdr & 1) != 0) {
if ((hdr & 2) != 0) {
if ((node[0] & 0x80) != 0) {
node += 3;
off += 3;
} else {
node += 2;
off += 2;
}
} else {
count++;
}
}
if (!(hdr & 4)) {
count--;
} else if ((hdr & 8) != 0) {
if ((node[0] & 0x80) != 0) {
node += 3;
off += 3;
} else {
node += 2;
off += 2;
}
count--;
}
} while (count > 0);
return orig + off;
}
ziU8 ZiDAWGgetEOWattribute(ziU8* node) {
return (nodeHeaderTable[node[0] >> 4] & 0x10) > 0;
}
ziU32 ZiDAWGgetCHARattribute(ziU8* graph, ziU8* node ZI_NEED_WORK) {
ziU32 res;
ziU8 idx;
idx = ((node[0] & 0xF) == 0xF) ? (ziU8)(node[1] + 0xF)
: (ziU8)(node[0] & 0xF);
if (idx > *(ziU16*)(graph + 4)) {
Zi8LogError(0x138B, __zi8_work_data);
return 0;
}
res = (ziU32)idx << 0x18;
res |= (ziU32)(*(ziU8**)(graph + 0xC))[idx] << 0x10;
res |= (ziU16)(*(ziU8**)(graph + 8))[idx * 2] * 0x100 +
(*(ziU8**)(graph + 8))[idx * 2 + 1];
Zi8LogError(0x64, __zi8_work_data);
return res;
}
ziU8* ZiDAWGGetGraph(ziU8* arg) {
return *(ziU8**)(arg + 0x10) +
((ziU16)(*(ziU8**)(arg + 0x10))[2] << 8) +
(*(ziU8**)(arg + 0x10))[3] + 4;
}
ziU32 ZiDAWGGetGraphInfo(ziPtr work, ziU8* hdr, ziWChar* key) {
ziU8* graph;
ziU32 res;
ziU8* end;
ziU8 i;
graph = ZiDAWGGetGraph((ziU8*)work);
res = 0;
if (((ziU16)hdr[0] << 8) + hdr[1] != 0 ||
((ziU16)hdr[2] << 8) + hdr[3] != 0) {
return 0;
}
end = hdr + ((((ziU16)hdr[4] << 8) + hdr[5]) + 1) * 0xA;
hdr += 0xA;
i = 0;
goto check;
body:
if (*key < 0xEFF1) {
goto ret0;
}
if (*key > 0xF010) {
goto ret0;
}
goto scan;
advance:
if (*key == ((ziU16)hdr[2] << 8) + hdr[3]) {
goto found;
}
hdr += (((ziU16)hdr[0] << 8) + hdr[1]) * 0xA + 0xA;
scan:
if (hdr >= end) {
goto found;
}
if (*key != ((ziU16)hdr[2] << 8) + hdr[3]) {
goto advance;
}
goto found;
ret0:
return 0;
found:
if (hdr >= end) {
return 0;
}
res = (ziU32)(graph + ((ziU32)hdr[4] << 0x10) +
(((ziU16)hdr[5] << 8) + hdr[6]));
((struct __zi8_work_data_s*)work)->unk_0x338 =
(ziU32)(graph + ((ziU32)hdr[7] << 0x10) +
(((ziU16)hdr[8] << 8) + hdr[9]));
if (((struct __zi8_work_data_s*)work)->unk_0x338 == (ziU32)graph) {
((struct __zi8_work_data_s*)work)->unk_0x338 = ZI8_NULL;
}
if ((((ziU16)hdr[0] << 8) + hdr[1]) == 0) {
goto done;
}
end = hdr + (((ziU16)hdr[0] << 8) + hdr[1]) * 0xA;
end += 0xA;
hdr += 0xA;
i++;
key++;
check:
if (i >= 2) {
goto done;
}
if (*key != 0) {
goto body;
}
done:
return res;
}

View File

@@ -0,0 +1,402 @@
#include <zi8clib/zitypes.h>
#include <zi8clib/zierror.h>
extern ziU16 Zi8GetTableCount(ziU8 lang, ziU8 tableIdx ZI_NEED_WORK);
extern ziU32 Zi8GetTableAddress(ziU8 lang, ziU8 tableIdx ZI_NEED_WORK);
static ziU8 Zi8_814813FC(ziU16 key, ziU8* pOut, ziU16* pIdx ZI_NEED_WORK);
static ziU8 Zi8_81481E6C(ziU16* out, ziWChar* keys, ziU8 sel, ziU16 n
ZI_NEED_WORK);
static ziU8 Zi8_814813FC(ziU16 key, ziU8* pOut, ziU16* pIdx ZI_NEED_WORK) {
ziU16 i;
ziU8* tbl;
tbl = (ziU8*)Zi8GetTableAddress(0x12, 5, ZI_WORK);
for (i = 0; tbl[i] != 0; i++) {
if (key == tbl[i]) {
*pIdx = i;
*pOut = tbl[i];
Zi8LogError(0x64, ZI_WORK);
return 1;
}
}
Zi8LogError(0x2A8, ZI_WORK);
return 0;
}
ziU8 Zi8GetKoreanCandidates(ziGetParam* prm, ziU8* p2 ZI_NEED_WORK) {
ziWChar buf[0x64];
ziU8* t4;
ziU8* t1;
ziU8* t2;
ziU8* t31;
ziU16 v1a;
ziU16 v18;
ziU16 v16;
ziU16 v14;
ziU16 v12;
ziU16 ve;
ziU16 v10;
ziU16 j;
ziU16 i;
ziWChar wc;
ziU8 i8;
ziU8 j8;
ziU8 v9;
ziU8 v8;
ziU8 n;
v12 = 0;
n = 0;
v8 = 0xFF;
ve = prm->firstCandidate;
prm->unk_0x20 = prm->count = prm->letters = 0;
if (p2 != ZI8_NULL && p2[0] != 0) {
Zi8LogError(0x7D0, ZI_WORK);
return 0;
}
if (prm->elementCount == 0 || prm->elementCount > 0x64) {
Zi8LogError(0x64, ZI_WORK);
return 0;
}
t4 = (ziU8*)Zi8GetTableAddress(0x12, 4, ZI_WORK);
t1 = (ziU8*)Zi8GetTableAddress(0x12, 1, ZI_WORK);
t2 = (ziU8*)Zi8GetTableAddress(0x12, 2, ZI_WORK);
t31 = (ziU8*)Zi8GetTableAddress(0x12, 0x31, ZI_WORK);
v1a = Zi8GetTableCount(0x12, 0, ZI_WORK);
v18 = Zi8GetTableCount(0x12, 3, ZI_WORK);
v16 = Zi8GetTableCount(0x12, 6, ZI_WORK);
v14 = Zi8GetTableCount(0x12, 0x31, ZI_WORK);
for (i8 = 0; i8 < prm->elementCount; i8++) {
wc = prm->elements[i8];
if (wc >= 0x61 && wc <= 0x7A) {
buf[i8] = t1[(wc - 0x61) * 2];
} else if (wc >= 0x41 && wc <= 0x5A) {
buf[i8] = t1[(wc - 0x41) * 2 + 1];
} else {
j8 = 0;
while (*(t2 + j8 * 3) != 0) {
if (wc == *(t2 + j8 * 3)) break;
j8++;
}
if (*(t2 + j8 * 3) == 0) {
Zi8LogError(0x161, ZI_WORK);
return 0;
}
buf[i8] = (*(t2 + j8 * 3 + 1) << 8) | *(t2 + j8 * 3 + 2);
}
}
n = 0;
i = 0;
goto Lchk;
Lloop:
if (Zi8_814813FC(buf[i], &v8, &v10, ZI_WORK) != 0) {
v9 = Zi8_81481E6C(&v12, buf + i + 1, v8, (ziU16)(i8 - i - 1), ZI_WORK);
if (ZI_WORK->unk_0x1B30 == 1) {
switch (v8) {
case 1:
t4 = (ziU8*)Zi8GetTableAddress(0x12, 0x1E, ZI_WORK);
break;
case 2:
t4 = (ziU8*)Zi8GetTableAddress(0x12, 0x1F, ZI_WORK);
break;
case 4:
t4 = (ziU8*)Zi8GetTableAddress(0x12, 0x20, ZI_WORK);
break;
case 7:
t4 = (ziU8*)Zi8GetTableAddress(0x12, 0x21, ZI_WORK);
break;
case 8:
t4 = (ziU8*)Zi8GetTableAddress(0x12, 0x22, ZI_WORK);
break;
case 9:
t4 = (ziU8*)Zi8GetTableAddress(0x12, 0x23, ZI_WORK);
break;
case 17:
t4 = (ziU8*)Zi8GetTableAddress(0x12, 0x24, ZI_WORK);
break;
case 19:
t4 = (ziU8*)Zi8GetTableAddress(0x12, 0x25, ZI_WORK);
break;
case 20:
t4 = (ziU8*)Zi8GetTableAddress(0x12, 0x26, ZI_WORK);
break;
case 21:
t4 = (ziU8*)Zi8GetTableAddress(0x12, 0x27, ZI_WORK);
break;
case 22:
t4 = (ziU8*)Zi8GetTableAddress(0x12, 0x28, ZI_WORK);
break;
case 23:
t4 = (ziU8*)Zi8GetTableAddress(0x12, 0x29, ZI_WORK);
break;
case 24:
t4 = (ziU8*)Zi8GetTableAddress(0x12, 0x2A, ZI_WORK);
break;
case 25:
t4 = (ziU8*)Zi8GetTableAddress(0x12, 0x2B, ZI_WORK);
break;
case 26:
t4 = (ziU8*)Zi8GetTableAddress(0x12, 0x2C, ZI_WORK);
break;
case 27:
t4 = (ziU8*)Zi8GetTableAddress(0x12, 0x2D, ZI_WORK);
break;
case 28:
t4 = (ziU8*)Zi8GetTableAddress(0x12, 0x2E, ZI_WORK);
break;
case 29:
t4 = (ziU8*)Zi8GetTableAddress(0x12, 0x2F, ZI_WORK);
break;
case 30:
t4 = (ziU8*)Zi8GetTableAddress(0x12, 0x30, ZI_WORK);
break;
}
}
} else {
v9 = 0;
}
if (v9 != 0) {
if (v16 == 0) {
v12 = (ziU16)(v12 + v10 * v18);
}
if (ve != 0) {
ve--;
} else {
prm->candidates[n] = (ziWChar)(((ziU16)t4[v12 * 2] << 8) |
t4[v12 * 2 + 1]);
if (v16 != 0 && ZI_WORK->unk_0x1B30 == 0) {
prm->candidates[n] =
(ziWChar)(prm->candidates[n] + v10 * v18);
}
n++;
}
if (i == 0) {
prm->count = v9 + 1;
}
i += v9;
} else {
if (ve != 0) {
for (j = 0; j < v14; j++) {
if (t31[j * 3] == buf[i] && t31[j * 3 + 1] == buf[i + 1]) {
break;
}
}
if (j == v14) {
ve--;
}
if (i == 0) {
prm->count = 1;
}
} else {
for (j = 0; j < v14; j++) {
if (t31[j * 3] == buf[i] && t31[j * 3 + 1] == buf[i + 1]) {
if (i == 0) {
prm->count = 1;
}
prm->candidates[n] =
(ziWChar)(v1a + t31[j * 3 + 2]);
n++;
i++;
break;
}
}
if (j == v14) {
prm->candidates[n] = buf[i];
if (buf[i] < 0xFF) {
if (i == 0) {
prm->count = 1;
}
prm->candidates[n] =
(ziWChar)(prm->candidates[n] + v1a);
n++;
}
}
}
}
if (n < prm->maxCandidates) {
i++;
}
Lchk:
if (i < i8 && n < prm->maxCandidates) {
goto Lloop;
}
prm->letters = n;
Zi8LogError(0x64, ZI_WORK);
return n;
}
static ziU8 Zi8_81481E6C(ziU16* out, ziWChar* keys, ziU8 sel, ziU16 n
ZI_NEED_WORK) {
ziU8 v9;
ziU16 j1;
ziU16 j2;
ziU16 j3;
ziU16 j4;
ziU16 v14;
ziU16 v16;
ziWChar cur;
ziU16 cnt;
ziU8* tbl;
cur = keys[0];
v9 = 0xFF;
if (ZI_WORK->unk_0x1B30 == 0) {
tbl = (ziU8*)Zi8GetTableAddress(0x12, 3, ZI_WORK);
cnt = Zi8GetTableCount(0x12, 3, ZI_WORK);
} else {
switch (sel) {
case 1:
tbl = (ziU8*)Zi8GetTableAddress(0x12, 0xB, ZI_WORK);
cnt = Zi8GetTableCount(0x12, 0xB, ZI_WORK);
break;
case 2:
tbl = (ziU8*)Zi8GetTableAddress(0x12, 0xC, ZI_WORK);
cnt = Zi8GetTableCount(0x12, 0xC, ZI_WORK);
break;
case 4:
tbl = (ziU8*)Zi8GetTableAddress(0x12, 0xD, ZI_WORK);
cnt = Zi8GetTableCount(0x12, 0xD, ZI_WORK);
break;
case 7:
tbl = (ziU8*)Zi8GetTableAddress(0x12, 0xE, ZI_WORK);
cnt = Zi8GetTableCount(0x12, 0xE, ZI_WORK);
break;
case 8:
tbl = (ziU8*)Zi8GetTableAddress(0x12, 0xF, ZI_WORK);
cnt = Zi8GetTableCount(0x12, 0xF, ZI_WORK);
break;
case 9:
tbl = (ziU8*)Zi8GetTableAddress(0x12, 0x10, ZI_WORK);
cnt = Zi8GetTableCount(0x12, 0x10, ZI_WORK);
break;
case 17:
tbl = (ziU8*)Zi8GetTableAddress(0x12, 0x11, ZI_WORK);
cnt = Zi8GetTableCount(0x12, 0x11, ZI_WORK);
break;
case 19:
tbl = (ziU8*)Zi8GetTableAddress(0x12, 0x12, ZI_WORK);
cnt = Zi8GetTableCount(0x12, 0x12, ZI_WORK);
break;
case 20:
tbl = (ziU8*)Zi8GetTableAddress(0x12, 0x13, ZI_WORK);
cnt = Zi8GetTableCount(0x12, 0x13, ZI_WORK);
break;
case 21:
tbl = (ziU8*)Zi8GetTableAddress(0x12, 0x14, ZI_WORK);
cnt = Zi8GetTableCount(0x12, 0x14, ZI_WORK);
break;
case 22:
tbl = (ziU8*)Zi8GetTableAddress(0x12, 0x15, ZI_WORK);
cnt = Zi8GetTableCount(0x12, 0x15, ZI_WORK);
break;
case 23:
tbl = (ziU8*)Zi8GetTableAddress(0x12, 0x16, ZI_WORK);
cnt = Zi8GetTableCount(0x12, 0x16, ZI_WORK);
break;
case 24:
tbl = (ziU8*)Zi8GetTableAddress(0x12, 0x17, ZI_WORK);
cnt = Zi8GetTableCount(0x12, 0x17, ZI_WORK);
break;
case 25:
tbl = (ziU8*)Zi8GetTableAddress(0x12, 0x18, ZI_WORK);
cnt = Zi8GetTableCount(0x12, 0x18, ZI_WORK);
break;
case 26:
tbl = (ziU8*)Zi8GetTableAddress(0x12, 0x19, ZI_WORK);
cnt = Zi8GetTableCount(0x12, 0x19, ZI_WORK);
break;
case 27:
tbl = (ziU8*)Zi8GetTableAddress(0x12, 0x1A, ZI_WORK);
cnt = Zi8GetTableCount(0x12, 0x1A, ZI_WORK);
break;
case 28:
tbl = (ziU8*)Zi8GetTableAddress(0x12, 0x1B, ZI_WORK);
cnt = Zi8GetTableCount(0x12, 0x1B, ZI_WORK);
break;
case 29:
tbl = (ziU8*)Zi8GetTableAddress(0x12, 0x1C, ZI_WORK);
cnt = Zi8GetTableCount(0x12, 0x1C, ZI_WORK);
break;
case 30:
tbl = (ziU8*)Zi8GetTableAddress(0x12, 0x1D, ZI_WORK);
cnt = Zi8GetTableCount(0x12, 0x1D, ZI_WORK);
break;
}
}
*out = 0;
if (n >= 1 && cur < 0xFF) goto L1;
return 0;
L1:
j4 = *out;
for (; j4 < cnt; j4++) {
if (tbl[j4 * 4] >= cur) break;
}
if (j4 < cnt && cur == tbl[j4 * 4]) goto L1a;
return 0;
L1a:
if (n >= 2 && (cur = keys[1]) < 0xFF) goto L2;
*out = j4;
return 1;
L2:
j3 = j4;
for (; j3 < cnt; j3++) {
if (*(tbl + j3 * 4 + 1) >= cur) break;
}
if (j3 < cnt && cur == *(tbl + j3 * 4 + 1) && keys[0] == tbl[j3 * 4])
goto L2a;
*out = j4;
return 1;
L2a:
if (n >= 3 && (cur = keys[2]) < 0xFF) goto L3;
*out = j3;
return 2;
L3:
j2 = j3;
for (; j2 < cnt; j2++) {
if (*(tbl + j2 * 4 + 2) >= cur) break;
}
if (j2 < cnt && cur == *(tbl + j2 * 4 + 2) &&
keys[1] == *(tbl + j2 * 4 + 1) && keys[0] == tbl[j2 * 4])
goto L3a;
if (Zi8_814813FC(keys[1], &v9, &v16, ZI_WORK) != 0 &&
Zi8_81481E6C(&v14, keys + 2, v9, 1, ZI_WORK) != 0) {
*out = j4;
return 1;
}
*out = j3;
return 2;
L3a:
if (n >= 4 && (cur = keys[3]) < 0xFF) goto L4;
*out = j2;
return 3;
L4:
j1 = j2;
for (; j1 < cnt; j1++) {
if (*(tbl + j1 * 4 + 3) >= cur) break;
}
if (j1 < cnt && cur == *(tbl + j1 * 4 + 3) &&
keys[2] == *(tbl + j1 * 4 + 2) && keys[1] == *(tbl + j1 * 4 + 1) &&
keys[0] == tbl[j1 * 4])
goto L4a;
if (Zi8_814813FC(keys[2], &v9, &v16, ZI_WORK) != 0 &&
Zi8_81481E6C(&v14, keys + 3, v9, 1, ZI_WORK) != 0) {
*out = j3;
return 2;
}
*out = j2;
return 3;
L4a:
if (n >= 5 && (cur = keys[4]) < 0xFF) goto L5;
*out = j1;
return 4;
L5:
if (Zi8_814813FC(keys[3], &v9, &v16, ZI_WORK) != 0 &&
Zi8_81481E6C(&v14, keys + 4, v9, 1, ZI_WORK) != 0) {
*out = j2;
return 3;
}
*out = j1;
return 4;
}

View File

@@ -0,0 +1,253 @@
#include <zi8clib/zitypes.h>
#include <zi8clib/zierror.h>
typedef struct {
ziU16 unk0;
ziU8 mode;
ziU8 unk3;
ziWChar* word;
ziU8 wordLen;
ziU8 unk9[3];
ziU32 unkC;
ziU16 maxLen;
ziU16 unk12;
ziU32 unk14;
} Zi8CandParam;
extern void Zi8Memset(ziPtr p, ziU32 v, ziU32 len);
extern ziS32 Zi8GetCandidatesOrCount(ziGetParam* gp, Zi8CandParam* sp ZI_NEED_WORK);
extern ziU16 Zi8Uni2Ord(ziU16 ch ZI_NEED_WORK);
extern ziU16 Zi8GetFormatVersion(ziU8 lang ZI_NEED_WORK);
extern ziU32 Zi8GetTableAddress(ziU8 lang, ziU8 tableIdx ZI_NEED_WORK);
ziBool Zi8IsWordW(ziWChar* word, ziU8 language,
struct __zi8_work_data_s* work) {
ziU32 t1 = 0;
ziU32 t2 = 0;
ziU8* p;
ziWChar* wp;
ziU8 packed = 0;
ziU8 rem = 0;
ziU16 wc = 0;
ziU8 buf[8] = {1, 5, 0, 0, 0, 0, 0, 0};
ziGetParam gp;
ziU32 bak32 = work->unk_0x1410;
ziU8 bak8 = work->unk_0x1418;
Zi8CandParam sp = {0};
ziWChar wbuf[0x40];
ziS32 i;
ziU8* q;
ziS32 v;
ziS32 cnt;
ziWChar* wp2;
Zi8LogError(0x64, work);
if (word == ZI8_NULL || *word == 0) {
Zi8ReplaceLastError(0x12C, work);
return 0;
}
if (language != 1) {
i = 0;
while (word[i] != 0) {
if (word[i] >= 0xEFF1 || i == 0x40) {
return 0;
}
i++;
}
sp.wordLen = (ziU8)i;
sp.mode = 1;
sp.word = word;
sp.maxLen = 0x40;
gp.language = language;
gp.getMode = 0;
gp.subLanguage = 7;
gp.context = 1;
gp.getOptions = 0x81;
gp.elements = word;
gp.elementCount = (ziU8)i;
gp.currentWord = ZI8_NULL;
gp.wordCharCount = 0;
gp.candidates = wbuf;
gp.maxCandidates = 1;
gp.firstCandidate = 0;
work->unk_0x1410 = (ziU32)buf;
if (work->unk_0x1C[0] == 2) {
work->unk_0x1418 = 0;
if ((work->unk_0x09 & 1) != 0) {
buf[work->unk_0x1418++] = 1;
}
if ((work->unk_0x09 & 4) != 0) {
buf[work->unk_0x1418++] = 2;
}
if ((work->unk_0x09 & 2) != 0) {
buf[work->unk_0x1418++] = 3;
}
if ((work->unk_0x09 & 8) != 0) {
buf[work->unk_0x1418++] = 4;
}
if ((work->unk_0x09 & 1) != 0) {
buf[work->unk_0x1418++] = 5;
}
if ((work->unk_0x09 & 4) != 0) {
buf[work->unk_0x1418++] = 6;
}
if ((work->unk_0x09 & 2) != 0) {
buf[work->unk_0x1418++] = 7;
}
if ((work->unk_0x09 & 8) != 0) {
buf[work->unk_0x1418++] = 8;
}
} else if (work->unk_0x1C[0] != 0) {
work->unk_0x1418 = 2;
} else {
work->unk_0x1418 = 1;
}
i = Zi8GetCandidatesOrCount(&gp, &sp, work);
work->unk_0x1410 = bak32;
work->unk_0x1418 = bak8;
if (i != 0) {
return 1;
}
}
if (language != 1) {
Zi8ReplaceLastError(0x26C, work);
return 0;
}
i = 0;
while (word[i] != 0) {
wbuf[i] = Zi8Uni2Ord(word[i], work);
if (wbuf[i] == 0xFFFF) {
return 0;
}
i++;
if (i == 0x40) {
return 0;
}
}
if (i-- == 1) {
return 1;
}
wbuf[i] |= 0x8000;
work->unk_0x16 = (ziU8)(Zi8GetFormatVersion(1, work) & 2);
t1 = Zi8GetTableAddress(1, 0, work);
p = (ziU8*)t1 + wbuf[0] * 0xC;
t2 = Zi8GetTableAddress(1, 1, work);
t2 = t2 +
(((ziU32)(p[9] & 0xF) << 16) | ((ziU32)(p[0xB] | (p[0xA] << 8))));
q = (ziU8*)t2;
if (work->unk_0x16 != 0) {
switch (*q & 7) {
case 2:
cnt = 2;
break;
case 3:
case 4:
cnt = 3;
break;
case 5:
cnt = 4;
break;
default:
cnt = 1;
break;
}
q += cnt;
}
if ((*q & 0x80) != 0) {
packed = 0;
q += ((*q & 0x7F) >> 4) + 1;
goto tail;
}
return 0;
more:
packed = *q++;
rem = (ziU8)(packed & 0xF);
while (rem != 0) {
cnt = i;
wp = wbuf;
while (cnt > 0) {
wc = (ziWChar)(((ziU16)q[1] << 8) | q[0]);
q += 2;
if (wc != *++wp) {
break;
}
cnt--;
if ((wc & 0x8000) != 0) {
break;
}
}
if (cnt == 0) {
return 1;
}
if ((wc & 0x8000) == 0) {
q++;
while ((*q & 0x80) == 0) {
q += 2;
}
q++;
}
rem--;
}
tail:
if ((packed & 0x80) == 0) {
goto more;
}
Zi8LogError(0x2BD, work);
return 0;
}
typedef struct {
ziWChar* a[0x20];
ziWChar* b[0x20];
} Zi8UserTbl;
ziU16 Zi8ConvertUC2UserKey(ziU16 ch, ziU8 language, ziPtr workData) {
Zi8UserTbl* t;
ziWChar* p;
ziU16 i;
if ((ziU8)ch == 0 || language > 0x82 ||
(t = ((struct __zi8_work_data_s*)workData)->userKeys[language]) ==
ZI8_NULL) {
return 0;
}
{
i = 0;
while ((ziU16)i < 0x20) {
p = t->b[i];
while (p != ZI8_NULL && *p != 0) {
if (*p == (ziWChar)(ziU8)ch) {
goto found;
}
p++;
}
p = t->a[i];
while (p != ZI8_NULL && *p != 0) {
if (*p == (ziWChar)(ziU8)ch) {
goto found;
}
p++;
}
i++;
}
found:
if ((ziU16)i >= 0x20) {
return 0;
}
if (i == 0) {
return 0xEFFA;
}
if (i >= 1 && i <= 9) {
return (ziU16)(i + 0xEFF0);
}
if ((ziU16)i <= 0x1F) {
return (ziU16)(i + 0xEFF1);
}
}
return 0;
}

View File

@@ -117,12 +117,12 @@ ziU32 Zi8_814834AC(ziGetParam* param, ziU16* remaining, ziU8* count,
ziS32 tableB;
ziU16 tableCount;
ziU8 matched;
ziU32 j;
ziU32 j = 0;
ziS32 i;
ziU8 candidateIndex;
ziU8 candidateIndex = 0;
union {
ziU32 words[13];
ziU8 bytes[52];
ziU32 words[4];
ziU8 bytes[16];
} local;
matched = 0;

View File

@@ -0,0 +1,212 @@
#include <zi8clib/zitypes.h>
#include <zi8clib/zierror.h>
#include <zi8clib/zmtkey.h>
#include <zi8clib/zconvert.h>
extern ziU16 Zi8GetTableCount(ziU8 lang, ziU8 tableIdx ZI_NEED_WORK);
extern ziU32 Zi8GetTableAddress(ziU8 lang, ziU8 tableIdx ZI_NEED_WORK);
static ziU8 Zi8_81484484(ziU16 key, ziU16* out ZI_NEED_WORK) {
if (key == 0xEFFA) {
*out = 0;
} else if (key >= 0xEFF1 && key <= 0xEFF9) {
*out = key - 0xEFF0;
} else if (key >= 0xEFFB && key <= 0xF010) {
*out = key - 0xEFF1;
} else {
return 0;
}
return 1;
}
static ziU8 ziNumKeysWithChars(ziU8 lang ZI_NEED_WORK) {
ziU16 count;
ziU8* table;
ziU32 sum;
ziU32 i;
count = Zi8GetTableCount(lang, 0x1E, ZI_WORK);
table = (ziU8*)Zi8GetTableAddress(lang, 0x1E, ZI_WORK);
if (count == 0) {
return 0xC;
}
for (i = (sum = 0); (ziU16)i < 0x20; i++) {
sum += table[(ziU16)i];
}
if ((ziU16)count >= (ziU16)sum * 4 + 0x20) {
return 0x20;
}
return 0xC;
}
static ziU8 Zi8getKeyLayout(ziU8 lang, ziU16 key, ziWChar* layout,
ziU8 mode ZI_NEED_WORK) {
ziS32 table = 0;
ziU16 count;
ziU8 keyCount;
ziU16 cnt;
ziU16 i;
ziU32* keyMap;
ziWChar* chars;
keyCount = ziNumKeysWithChars(lang, ZI_WORK);
Zi8LogError(0x64, ZI_WORK);
*layout = 0;
if (ZI_WORK->userKeys[lang] != 0) {
keyMap = (ziU32*)ZI_WORK->userKeys[lang];
if (Zi8_81484484(key, &key, ZI_WORK) == 0) {
return 0;
}
chars = (ziWChar*)(&keyMap[key])[0x20];
for (i = 0; chars[(ziU16)i] != 0; i++) {
layout[(ziU16)i] = chars[(ziU16)i];
}
layout[(ziU16)i] = 0;
return 1;
}
if (mode != 1) {
count = Zi8GetTableCount(lang, 0x1D, ZI_WORK);
if (count != 0) {
table = Zi8GetTableAddress(lang, 0x1D, ZI_WORK);
} else {
goto d30;
}
goto d38;
}
d30:
count = Zi8GetTableCount(lang, 0x1E, ZI_WORK);
if (count != 0) {
table = Zi8GetTableAddress(lang, 0x1E, ZI_WORK);
}
d38:
if (table == 0) {
Zi8ReplaceLastError(0x962, ZI_WORK);
return 0;
}
if (Zi8_81484484(key, &key, ZI_WORK) == 0 || key >= keyCount) {
Zi8ReplaceLastError(0x12C, ZI_WORK);
return 0;
}
for (i = (count = 0); (ziU16)i < key; i++) {
count += ((ziU8*)table)[(ziU16)i];
}
if ((cnt = (ziU16)(ziU8)((ziU8*)table)[key]) == 0) {
return 0;
}
table += keyCount + (ziU16)count * 2;
for (i = 0; (ziU16)i < cnt; i++) {
layout[(ziU16)i] = ((ziU8*)table)[(ziU16)i * 2] | ((ziU16)((ziU8*)table)[(ziU16)i * 2 + 1] << 8);
}
layout[(ziU16)i] = 0;
return 1;
}
ziBool Zi8ChangeCharCase(ziBool upper, ziWChar* ch, ziU8 language ZI_NEED_WORK) {
ziPtr* pTab = 0;
ziU8* pKeys = 0;
ziWChar* from;
ziWChar* to;
ziU32 i;
ziU16 acc;
ziU16 cnt;
ziS16 dir;
ziU16 key;
ziS32 j;
ziU8 done = 0;
ziU8 keyCount = 0x20;
Zi8LogError(0x64, ZI_WORK);
if (ZI_WORK->userKeys[language] != 0) {
pTab = (ziPtr*)ZI_WORK->userKeys[language];
} else if (ZI_WORK->unk_0x11FC != 0) {
pTab = (ziPtr*)ZI_WORK->unk_0x11FC;
} else {
cnt = Zi8GetTableCount(language, 0x1E, ZI_WORK);
if (cnt != 0) {
pKeys = (ziU8*)Zi8GetTableAddress(language, 0x1E, ZI_WORK);
keyCount = ziNumKeysWithChars(language, ZI_WORK);
} else {
Zi8ReplaceLastError(0x138D, ZI_WORK);
return 0;
}
}
if (pTab != 0) {
for (j = 0; done == 0 && j < keyCount; j++) {
if (upper != 0) {
from = (ziWChar*)(&pTab[j])[0x20];
to = (ziWChar*)pTab[j];
} else {
from = (ziWChar*)pTab[j];
to = (ziWChar*)(&pTab[j])[0x20];
}
if (from != 0 && to != 0) {
for (i = 0; (ziU16)from[i] != 0; i++) {
if (*ch == (ziU16)from[i]) {
*ch = (ziU16)to[i];
done = 1;
break;
}
}
}
}
} else {
if (pKeys != 0) {
acc = 0;
for (j = 0; j < keyCount; j++) {
acc += pKeys[j];
}
pKeys += keyCount;
dir = 1;
if (upper == 0) {
pKeys += acc * 2;
dir = -1;
}
for (j = 0; j < acc; j++) {
cnt = (ziU16)(pKeys[j * 2] | ((ziU16)pKeys[j * 2 + 1] << 8));
if (cnt == *ch) {
pKeys += dir * (acc * 2);
*ch = (ziU16)(pKeys[j * 2] | ((ziU16)pKeys[j * 2 + 1] << 8));
done = 1;
break;
}
}
}
}
if (done == 0) {
key = 0;
if (upper != 0) {
if ((*ch >= 0x61 && *ch <= 0x7A) || (*ch >= 0xF1 && *ch <= 0xF6) ||
(*ch >= 0xF8 && *ch <= 0xFE) || (*ch >= 0xE0 && *ch <= 0xEF)) {
key = *ch - 0x20;
} else if (*ch == 0xFF) {
key = 0x178;
}
} else {
if ((*ch >= 0x41 && *ch <= 0x5A) || (*ch >= 0xD1 && *ch <= 0xD6) ||
(*ch >= 0xD8 && *ch <= 0xDE) || (*ch >= 0xC0 && *ch <= 0xCF)) {
key = *ch + 0x20;
} else if (*ch == 0x178) {
key = 0xFF;
}
}
if (key != 0) {
if (Zi8ConvertWC2UC(key, language, ZI_WORK) != 0) {
*ch = key;
done = 1;
}
}
}
return done;
}

View File

@@ -0,0 +1,144 @@
#include <zi8clib/zitypes.h>
#include <zi8clib/zierror.h>
extern ziU16 Zi8ConvertWC2Key(ziWChar ch, ziU8 mode ZI_NEED_WORK);
extern ziU8 Zi8ChangeCharCase(ziU8 toUpper, ziWChar* ch, ziU8 mode ZI_NEED_WORK);
ziU8 Zi8AttachOEMdata(ziU8 (*pfn)(ziU16, ziWChar*, ziU8, ziPtr), ziU16 len,
ziPtr data ZI_NEED_WORK) {
ZI_WORK->oemMatch = pfn;
ZI_WORK->oemLen = len;
ZI_WORK->oemData = data;
Zi8LogError(0x64, ZI_WORK);
return 1;
}
ziU8 Zi8DetachOEMdata(ziU8 force ZI_NEED_WORK) {
Zi8LogError(0x64, ZI_WORK);
if (force == 1) {
if (ZI_WORK->oemMatch != ZI8_NULL) {
goto clear;
}
}
return 0;
clear:
ZI_WORK->oemMatch = ZI8_NULL;
ZI_WORK->oemLen = 0;
return 1;
}
ziU8 Zi8MatchOEMdata(ziWChar* elements, ziU8 elementCount, ziU8 matchCase,
ziWChar* candidates, ziU16 maxCandSize, ziU8 unk8,
ziU8 unk9 ZI_NEED_WORK) {
ziS32 flag = 0;
ziWChar ch;
ziS32 idx;
ziS32 j;
if (unk9 == 0) {
ZI_WORK->oemIdx = 0;
}
idx = ZI_WORK->oemIdx;
if (idx >= ZI_WORK->oemLen) {
goto ret0;
}
if (ZI_WORK->oemMatch == ZI8_NULL) {
goto ret0;
}
maxCandSize--;
if (elementCount < maxCandSize) {
goto pass;
}
ret0:
return 0;
pass:
candidates[maxCandSize] = 0;
if (unk8 != 0) {
candidates[elementCount] = 1;
} else {
candidates[elementCount] = 0;
}
goto call;
next:
j = 0;
if (unk8 != 0 && candidates[elementCount] == 0) {
goto cont;
}
if (unk8 != 0) {
goto done;
}
if (candidates[elementCount] == 0) {
goto done;
}
cont:
for (; j < elementCount; j++) {
if (elements[j] < 0xEFF1 || elements[j] > 0xF37F) {
goto other;
}
if (elements[j] ==
Zi8ConvertWC2Key(candidates[j], matchCase, ZI_WORK)) {
continue;
}
goto done;
other:
if (candidates[j] == elements[j]) {
continue;
}
if (ZI_WORK->unk_0x1F == 0) {
goto done;
}
if (matchCase == 1) {
goto done;
}
ch = elements[j];
if (Zi8ChangeCharCase(1, &ch, matchCase, ZI_WORK) == 0) {
goto done;
}
if (ch != candidates[j]) {
goto done;
}
}
done:
if (j >= elementCount) {
goto success;
}
if (unk8 != 0) {
candidates[elementCount] = 1;
} else {
candidates[elementCount] = 0;
}
idx++;
if (idx >= ZI_WORK->oemLen) {
goto tail;
}
goto call;
success:
if (flag != 0) {
idx = 0;
candidates[0] = elements[0];
return 1;
}
idx++;
ZI_WORK->oemIdx = idx;
while (candidates[j] != 0) {
j++;
}
return (ziU8)j;
call:
if (idx >= ZI_WORK->oemLen) {
goto tail;
}
if (ZI_WORK->oemMatch((ziU16)idx, candidates, (ziU8)maxCandSize,
ZI_WORK->oemData) != 0) {
goto next;
}
tail:
if (elementCount == 1 && unk8 != 0 && unk9 == 0) {
unk8 = 0;
flag = 1;
idx = 0;
goto call;
}
return 0;
}

View File

@@ -0,0 +1,400 @@
#include <zi8clib/zitypes.h>
#include <zi8clib/zierror.h>
extern ziU32 Zi8GetTableAddress(ziU8, ziU8 ZI_NEED_WORK);
extern ziU16 Zi8GetTableCount(ziU8, ziU8 ZI_NEED_WORK);
extern ziBool Zi8IsComponent(ziWChar ZI_NEED_WORK);
extern void Zi8Memset(ziPtr, ziU32, ziU32);
extern void Zi8Memcpy(ziPtr, ziPtr, ziU32);
extern ziU8 Zi8GetPyPhonetic(ziWChar*, ziU8, ziWChar*, ziWChar*, ziU8*, ziWChar*, ziWChar* ZI_NEED_WORK);
extern ziU8 Zi8GetBpmfPhonetic(ziWChar*, ziU8, ziU16*, ziU16*, ziU16*, ziU16* ZI_NEED_WORK);
ziU16 Zi8PrepareMatch(ziGetParam* prm, ziMatchParam* out, ziU8 flag ZI_NEED_WORK)
{
ziU8 len8;
ziU8 m;
ziU8 minLen;
ziU8 c2;
ziU8 cnt;
ziU8 n;
ziU8 flag2;
ziU16 v10;
ziU16 v12;
ziU16 v14;
ziU16 v16;
ziU16 v18;
ziU16 v1a;
ziU16 j2;
ziU16 v1e;
ziU16 v20;
ziU16 v22;
ziU16 tN;
ziWChar x;
ziWChar* ptr;
ziU8* t;
ziU8 buf30[4];
ziU8 buf34[4];
ziU8* t2;
ziU8* t6;
ziU8 arr40[0xC];
ziU8 arr4c[0xC];
ziU8 ret;
ziU8 i;
c2 = 0;
minLen = 0x20;
Zi8Memset(out, 0, 0x1ee);
flag2 = 0;
ret = 0;
cnt = 0;
n = prm->elementCount;
while (n != 0) {
if (prm->elements[n - 1] != 0xef09) {
break;
}
n--;
}
out->count = n;
for (i = 0; i < n; i++) {
if (prm->elements[i] != 0xef00) {
out->count = 0;
goto L_main;
}
}
L_main:
if (n != 0) {
out->comp = x = prm->elements[0];
if (Zi8IsComponent(x, ZI_WORK) != 0) {
cnt++;
flag2 = 1;
t6 = (ziU8*)Zi8GetTableAddress(1, 2, ZI_WORK);
t2 = (ziU8*)Zi8GetTableAddress(1, 6, ZI_WORK);
t2 += ((ziS32)x - 0xef10) * 2;
out->field22 = (ziU16)(((t2[1] & 0x3f) << 8) + t2[0]);
t6 += out->field22 * 8;
switch (t6[0] & 0xf) {
case 1:
out->comp = 0xef04;
break;
case 2:
out->comp = 0xef01;
break;
case 3:
case 11:
out->comp = 0xef07;
break;
case 4:
out->comp = 0xef06;
break;
case 5:
out->comp = 0xef03;
break;
case 6:
out->comp = 0xef05;
break;
case 7:
out->comp = 0xef08;
break;
case 8:
out->comp = 0xef02;
break;
default:
break;
}
for (i = 0; i < (t6[5] >> 1) + 1; i++) {
if (i < 4) {
out->arrD[i] = t6[i];
out->arr1[i] = 0xff;
}
}
if (i != 0 && (t6[5] & 1) == 0) {
i--;
out->arrD[i] &= 0xf0;
out->arr1[i] &= 0xf0;
}
ret = t6[5] + 1;
if (ret > 8) {
ret++;
}
}
}
out->arr1[0] &= 0xf;
out->arrD[0] &= 0xf;
if (flag == 0) {
m = 0;
if ((prm->subLanguage & 0x80) || (prm->subLanguage & 0x40)) {
m = 1;
} else if (prm->subLanguage & 0x08) {
m = 4;
} else if ((prm->subLanguage & 0x20) || (prm->subLanguage & 0x10)) {
m = 2;
}
if (m == 0) {
m = prm->subLanguage;
}
switch (m) {
case 1:
case 2:
case 4:
out->arr1[0] |= m << 4;
out->arrD[0] |= m << 4;
break;
}
}
if (ret == 0) {
ret = 1;
}
if (prm->getMode != 0 && prm->getMode != 0x10 && prm->getMode != 5) {
goto L_phonetic;
}
Zi8Memcpy(arr4c, out->arr1, 0xc);
Zi8Memcpy(arr40, out->arrD, 0xc);
for (;;) {
while (cnt < n) {
x = prm->elements[cnt++];
switch (x) {
case 0xef02:
c2 = 0;
break;
case 0xef04:
c2 = 1;
break;
case 0xef01:
c2 = 2;
break;
case 0xef07:
c2 = 3;
break;
case 0xef06:
c2 = 4;
break;
case 0xef03:
c2 = 5;
break;
case 0xef05:
c2 = 6;
break;
case 0xef08:
c2 = 7;
break;
case 0xef0b:
c2 = 8;
break;
case 0xef0a:
c2 = 4;
break;
case 0xf360:
c2 = 0xff;
break;
case 0xef09:
default:
c2 = 0;
break;
}
if (c2 == 0xff) {
break;
}
if (ret > 0x17) {
out->length = 0x18;
return 0;
}
if (ret == 8) {
ret++;
}
if (ret & 1) {
arr40[ret >> 1] |= c2;
if (x == 0xef0b) {
arr4c[ret >> 1] |= 8;
} else if (x == 0xef0a) {
arr4c[ret >> 1] |= 4;
} else if (x != 0xef00) {
arr4c[ret >> 1] |= 7;
}
} else {
arr40[ret >> 1] |= c2 << 4;
if (x == 0xef0b) {
arr4c[ret >> 1] |= 0x80;
} else if (x == 0xef0a) {
arr4c[ret >> 1] |= 0x40;
} else if (x != 0xef00) {
arr4c[ret >> 1] |= 0x70;
}
}
ret++;
}
len8 = ret;
for (i = 0; i < 4; i++) {
buf34[i] = arr4c[i];
buf30[i] = arr40[i];
}
if (ret > 1 && ret < 8) {
i = ret >> 1;
if (ret & 1) {
buf34[i] |= 0xf;
buf30[i] |= 0xf;
} else {
buf34[i] |= 0xf0;
buf30[i] |= 0xf0;
}
}
if (out->nSeg == 0) {
Zi8Memcpy(out->arr1, arr4c, 0xc);
Zi8Memcpy(out->arrD, arr40, 0xc);
Zi8Memcpy(out->arr19, buf34, 4);
Zi8Memcpy(out->arr1D, buf30, 4);
out->length = len8;
}
Zi8Memcpy(out->segs1 + out->nSeg * 0xc, arr4c, 0xc);
Zi8Memcpy(out->segsD + out->nSeg * 0xc, arr40, 0xc);
out->nSeg++;
if (c2 == 0xff && cnt < n && out->nSeg < 0x10) {
Zi8Memset(arr4c, 0, 0xc);
Zi8Memset(arr40, 0, 0xc);
arr4c[0] = out->arr1[0] & 0xf0;
arr40[0] = out->arrD[0] & 0xf0;
ret = 1;
continue;
}
return 1;
}
L_phonetic:
out->length = ret;
if (n == 0) {
return 1;
}
if (prm->getMode == 1 || prm->getMode == 0xc) {
t = (ziU8*)Zi8GetTableAddress(1, 3, ZI_WORK);
tN = Zi8GetTableCount(1, 3, ZI_WORK);
} else {
t = (ziU8*)Zi8GetTableAddress(1, 4, ZI_WORK);
tN = Zi8GetTableCount(1, 4, ZI_WORK);
}
if (prm->getMode == 1 || prm->getMode == 0xc) {
out->nCand = Zi8GetPyPhonetic(prm->elements, n, out->phon, out->phon2,
&prm->count, &out->first, &out->first2, ZI_WORK);
goto L_tailchk;
}
v1a = 0;
v18 = 0;
v16 = 0;
v14 = 0;
v12 = 0;
v10 = 0;
ptr = prm->elements;
out->nCand = 0;
prm->count = prm->elementCount;
j2 = 1;
for (i = 0; i < n; i++, j2++) {
c2 = Zi8GetBpmfPhonetic(ptr, (ziU8)j2, &v1a, &v18, &v16, &v14, ZI_WORK);
if (c2 != 0) {
v12 = v16;
v10 = v14;
L_store:
out->phon[out->nCand] = v1a;
out->phon2[out->nCand] = v18;
if (out->nCand == 0) {
out->first = v16;
out->first2 = v14;
}
continue;
}
if (i == 0) {
goto L_reset;
}
if (j2 > 1 && ptr[j2 - 2] == 0xf360 && ptr[j2 - 1] == 0xf360) {
goto L_reset;
}
out->nCand++;
if (out->nCand == 0x10) {
goto L_reset;
}
goto L_tail2;
L_reset:
v1a = 0xffff;
v18 = 0xffff;
v16 = 0xffff;
v14 = 0xffff;
out->nCand = 0;
break;
L_tail2:
if (ptr[j2 - 1] == 0xf360) {
out->nCand--;
v1a = v16 = v12;
v18 = v14 = v10;
goto L_store;
}
if (out->nCand == 1) {
prm->count = j2 - 1;
}
ptr = ptr + j2 - 1;
j2 = 0;
i--;
continue;
}
if (n != 0) {
out->phon[out->nCand] = v1a;
out->phon2[out->nCand] = v18;
if (out->nCand == 0) {
out->first = v16;
out->first2 = v14;
}
out->nCand++;
}
L_tailchk:
if ((prm->context & minLen) != 0) {
if (out->nCand > 1 || prm->count != n) {
out->phon[0] = 0xffff;
out->phon2[0] = 0xffff;
out->nCand = 0;
}
}
if (!(prm->getOptions & 0x20)) {
if (!(out->phon[0] == 0xffff && out->phon2[0] == 0xffff)) {
if (out->nCand > 1) {
v22 = out->phon[out->nCand - 1] & 0xe000;
v20 = out->phon2[out->nCand - 1] & 0xe000;
} else {
v22 = out->phon[0] & 0xe000;
v20 = out->phon2[0] & 0xe000;
}
for (j2 = 0; j2 < tN; j2++) {
v1e = t[j2 * 2] | (t[j2 * 2 + 1] << 8);
if (v20 == (v1e & v22)) {
break;
}
}
if (j2 == tN) {
out->phon[0] = 0xffff;
out->phon2[0] = 0xffff;
}
}
}
return 1;
}