sj4/lib/sj4core/cvtkanji.c

169 lines
3.9 KiB
C
Raw Normal View History

2008-01-11 11:57:08 +00:00
/*
* Copyright (c) 1991-1994 Sony Corporation
2026-06-19 01:49:53 +09:00
*
2008-01-11 11:57:08 +00:00
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
2026-06-19 01:49:53 +09:00
*
2008-01-11 11:57:08 +00:00
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
2026-06-19 01:49:53 +09:00
*
2008-01-11 11:57:08 +00:00
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2026-06-19 01:49:53 +09:00
*
2008-01-11 11:57:08 +00:00
* Except as contained in this notice, the name of Sony Corporation
* shall not be used in advertising or otherwise to promote the sale, use
* or other dealings in this Software without prior written authorization
* from Sony Corporation.
*
*/
#include "sj_kcnv.h"
#include "sj_kanakan.h"
2026-06-20 02:12:04 +09:00
void cvtphknj(SJ4_CONTEXT2) {
2026-06-19 01:49:53 +09:00
int i, j;
CLREC* clrec;
CLREC* clkp;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
if(!kanjilen) goto not_enough_memory;
2008-01-11 11:57:08 +00:00
khcount = 0;
2026-06-19 01:49:53 +09:00
clkp = NULL;
2008-01-11 11:57:08 +00:00
stdytop = NULL;
2026-06-19 01:49:53 +09:00
clrec = clt1st;
while(clrec) {
2026-06-20 02:12:04 +09:00
if(ph_khtbl(SJ4_CONTEXT_PASS clrec)) clkp = clrec;
2026-06-19 01:49:53 +09:00
clrec = clrec->clsort;
}
if(clkp && stdytop) {
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
if(stdytop->nmflg)
2026-06-20 02:12:04 +09:00
ph_setkouho(SJ4_CONTEXT_PASS clkp, (TypeDicOfs)0, (STDYIN*)0);
2026-06-19 01:49:53 +09:00
}
2008-01-11 11:57:08 +00:00
kouhotbl[0].rank = 1;
kanjitmp = kanjibuf + 1;
2026-06-20 02:12:04 +09:00
setstyrec(SJ4_CONTEXT_PASS kouhotbl);
2008-01-11 11:57:08 +00:00
2026-06-20 02:12:04 +09:00
cvtkouho(SJ4_CONTEXT_PASS kouhotbl);
2008-01-11 11:57:08 +00:00
i = kanjitmp - kanjibuf;
2026-06-19 01:49:53 +09:00
if(i < kanjilen) {
2008-01-11 11:57:08 +00:00
kanjilen -= i;
2026-06-19 01:49:53 +09:00
ystart += clt1st->cllen;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
j = hzstrlen(inputyomi, (int)clt1st->cllen);
2008-01-11 11:57:08 +00:00
kanjibuf[0] = (u_char)j;
inputyomi += j;
memcpy(kanjipos, kanjibuf, i);
kanjipos += i;
2026-06-19 01:49:53 +09:00
} else
2008-01-11 11:57:08 +00:00
kanjilen = 0;
not_enough_memory:
2026-06-20 02:12:04 +09:00
free_clall(SJ4_CONTEXT_PASS clt1st);
free_jall(SJ4_CONTEXT_PASS jrt1st);
2008-01-11 11:57:08 +00:00
}
2026-06-20 02:12:04 +09:00
void cvtkouho(SJ4_CONTEXT KHREC* krec) {
2026-06-19 01:49:53 +09:00
CLREC* clrec;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
clrec = krec->clrec;
2008-01-11 11:57:08 +00:00
2026-06-24 11:39:52 +09:00
switch(clrec->jnode->jclass) {
2026-06-19 01:49:53 +09:00
case C_DICT:
2026-06-20 02:12:04 +09:00
cvtdict(SJ4_CONTEXT_PASS krec, clrec, FALSE);
2008-01-11 11:57:08 +00:00
break;
2026-06-19 01:49:53 +09:00
case C_N_ARABIA:
case C_N_ARACMA:
case C_N_KAZU:
case C_N_SUUJI:
case C_N_NANSUU:
case C_N_KANKURA:
case C_N_ARAKURA:
case C_N_KAZULONG:
case C_N_KAZULCMA:
case C_N_SUUJILONG:
2026-06-20 02:12:04 +09:00
cvtdict(SJ4_CONTEXT_PASS krec, clrec, TRUE);
2008-01-11 11:57:08 +00:00
break;
2026-06-19 01:49:53 +09:00
case C_BUNSETU:
case C_MINASI:
2026-06-20 02:12:04 +09:00
cvtminasi(SJ4_CONTEXT_PASS(int) clrec->cllen);
2008-01-11 11:57:08 +00:00
break;
2026-06-19 01:49:53 +09:00
case C_WAKACHI:
2026-06-20 02:12:04 +09:00
cvtwakachi(SJ4_CONTEXT_PASS clrec);
2008-01-11 11:57:08 +00:00
break;
}
*kanjitmp++ = 0;
}
2026-06-20 02:12:04 +09:00
void setstyrec(SJ4_CONTEXT KHREC* krec) {
2026-06-19 01:49:53 +09:00
JREC* jrec;
KHREC* kptr;
int ii;
u_char* fptr;
2026-06-20 21:16:45 +09:00
STDYOUT stdy = {0};
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
jrec = krec->clrec->jnode;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
if(krec->mode && !krec->offs) {
for(ii = khcount, kptr = kouhotbl; ii--; kptr++)
if(kptr->rank == 1) break;
stdy.stdy1.offset = kptr->offs;
stdy.stdy1.seg = kptr->clrec->jnode->jseg;
stdy.stdy1.styno = kptr->styno;
stdy.stdy1.dicid = kptr->clrec->jnode->dicid;
2008-01-11 11:57:08 +00:00
stdy.stdy1.nmflg = 1;
}
2026-06-19 01:49:53 +09:00
2008-01-11 11:57:08 +00:00
else {
2026-06-19 01:49:53 +09:00
stdy.stdy1.offset = krec->offs;
stdy.stdy1.seg = jrec->jseg;
stdy.stdy1.styno = krec->styno;
stdy.stdy1.dicid = jrec->dicid;
2008-01-11 11:57:08 +00:00
stdy.stdy1.nmflg = 0;
}
2026-06-19 01:49:53 +09:00
stdy.stdy1.sttkj = krec->sttkj;
stdy.stdy1.ka_kj = krec->ka_kj;
stdy.hinshi = jrec->hinsi;
stdy.len = jrec->jlen;
stdy.sttfg = krec->sttfg;
stdy.ka_fg = krec->ka_fg;
2026-06-19 23:45:47 +09:00
if(jrec->stbofs && (fptr = getstb(jrec->hinsi)))
2026-06-19 01:49:53 +09:00
stdy.len -= StbYomiLen(fptr + jrec->stbofs - 1);
2026-06-19 02:57:26 +09:00
if((fptr = Settou_ptr(jrec->sttofs)))
2008-01-11 11:57:08 +00:00
stdy.sttlen = SttYomiLen(fptr);
else
stdy.sttlen = 0;
2026-06-19 01:49:53 +09:00
memcpy(kanjitmp, (u_char*)&stdy, sizeof(STDYOUT));
2008-01-11 11:57:08 +00:00
kanjitmp += sizeof(STDYOUT);
}