sj4/lib/sj3core/setkouho.c

250 lines
4.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.
*
*/
/*
2026-06-19 01:49:53 +09:00
* $SonyRCSfile: setkouho.c,v $
* $SonyRevision: 1.1 $
2008-01-11 11:57:08 +00:00
* $SonyDate: 1994/06/03 08:02:20 $
*/
#include "sj_euc.h"
#include "sj_kcnv.h"
#include "sj_hinsi.h"
#include "sj_kanakan.h"
2026-06-19 01:49:53 +09:00
static int hiraknj();
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
void setkouho(CLREC* clrec, TypeDicOfs offs, int mode) {
JREC* jrec;
KHREC* kptr;
u_char* fptr;
2008-01-11 11:57:08 +00:00
int flg;
int i;
2026-06-19 01:49:53 +09:00
if(khcount >= MAXKOUHONUMBER) return;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
jrec = clrec->jnode;
2008-01-11 11:57:08 +00:00
kptr = &kouhotbl[khcount++];
2026-06-19 01:49:53 +09:00
if(mode && !offs) nkhcount++;
kptr->clrec = clrec;
kptr->offs = offs;
kptr->rank = 0;
kptr->styno = 0;
kptr->mode = (u_char)mode;
if(jrec->flags & JFLAG_KA) {
kptr->ka_fg = 1;
kptr->ka_kj = 1;
flg = 1;
} else if(clrec->fzk_ka) {
kptr->ka_fg = 1;
kptr->ka_kj = 0;
flg = 2;
} else {
kptr->ka_fg = 0;
kptr->ka_kj = 0;
flg = 0;
2008-01-11 11:57:08 +00:00
}
2026-06-19 01:49:53 +09:00
kptr->sttfg = kptr->sttkj = 0;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
if(!(fptr = Settou_ptr(jrec->sttofs))) return;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
if(!SttHiraKnj(fptr)) return;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
kptr->sttfg = 1;
kptr->sttkj = 0;
2008-01-11 11:57:08 +00:00
i = hiraknj(dicbuf + offs);
2026-06-19 01:49:53 +09:00
if(offs > 1 && (i == 2 || i == 3)) return;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
if(khcount >= MAXKOUHONUMBER) return;
2008-01-11 11:57:08 +00:00
kptr++;
khcount++;
2026-06-19 01:49:53 +09:00
if(mode && !offs) nkhcount++;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
kptr->clrec = clrec;
kptr->offs = offs;
kptr->rank = 0;
kptr->styno = 0;
kptr->mode = (u_char)mode;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
kptr->sttfg = 1;
kptr->sttkj = 1;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
switch(flg) {
case 1:
kptr->ka_fg = kptr->ka_kj = 1;
break;
case 2:
kptr->ka_fg = 1;
kptr->ka_kj = 0;
break;
default:
kptr->ka_fg = kptr->ka_kj = 0;
break;
2008-01-11 11:57:08 +00:00
}
}
2026-06-19 01:49:53 +09:00
void ph_setkouho(CLREC* clrec, TypeDicOfs offs, STDYIN* sptr) {
JREC* jrec;
u_char* p;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
if(sptr) {
stdytop = sptr;
kouhotbl[0].styno = sptr->styno;
kouhotbl[0].sttkj = sptr->sttkj;
} else {
2008-01-11 11:57:08 +00:00
kouhotbl[0].styno = -1;
kouhotbl[0].sttkj = 0;
}
kouhotbl[0].clrec = clrec;
kouhotbl[0].offs = offs;
kouhotbl[0].rank = 0;
2026-06-19 01:49:53 +09:00
kouhotbl[0].mode = sel_sjmode(jrec = clrec->jnode);
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
kouhotbl[0].sttfg = (u_char)((p = Settou_ptr(jrec->sttofs)) ? (SttHiraKnj(p) ? 1 : 0) : 0);
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
if(jrec->flags & JFLAG_KA) {
2008-01-11 11:57:08 +00:00
kouhotbl[0].ka_fg =
2026-06-19 01:49:53 +09:00
kouhotbl[0].ka_kj = 1;
} else if(clrec->fzk_ka) {
2008-01-11 11:57:08 +00:00
kouhotbl[0].ka_fg = 1;
kouhotbl[0].ka_kj = 0;
2026-06-19 01:49:53 +09:00
} else {
2008-01-11 11:57:08 +00:00
kouhotbl[0].ka_fg =
2026-06-19 01:49:53 +09:00
kouhotbl[0].ka_kj = 0;
2008-01-11 11:57:08 +00:00
}
khcount = 1;
}
static int
2026-06-19 01:49:53 +09:00
hiraknj(u_char* p) {
char flg = TRUE;
int i;
int result;
2008-01-11 11:57:08 +00:00
do {
2026-06-19 01:49:53 +09:00
if(p[codesize(*p)] == KANJISTREND) flg = FALSE;
2008-01-11 11:57:08 +00:00
switch(*p & KANJIMODEMASK) {
2026-06-19 01:49:53 +09:00
case ZENHIRAASSYUKU:
result = hiraknj_hask(p, &i);
break;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
case ZENKATAASSYUKU:
result = hiraknj_kask(p, &i);
break;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
case OFFSETASSYUKU:
result = hiraknj_ofs(p, &i);
break;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
case AIATTRIBUTE:
result = hiraknj_atrb(p, &i);
break;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
case LEADINGHANKAKU:
result = hiraknj_norm(p, &i);
break;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
case KANJIASSYUKU:
result = hiraknj_knj(p, &i);
break;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
default:
2008-01-11 11:57:08 +00:00
result = hiraknj_hira(p, &i);
}
2026-06-19 01:49:53 +09:00
if(result) return result;
2008-01-11 11:57:08 +00:00
p += i;
2026-06-19 01:49:53 +09:00
} while(flg);
2008-01-11 11:57:08 +00:00
return 0;
}
2026-06-19 01:49:53 +09:00
int hiraknj_atrb(u_char* p, int* len) {
2008-01-11 11:57:08 +00:00
*len = 2;
return 0;
}
2026-06-19 01:49:53 +09:00
int hiraknj_ofs(u_char* p, int* len) {
2008-01-11 11:57:08 +00:00
*len = 2;
2026-06-19 01:49:53 +09:00
return hiraknj(dicbuf + ((*p & KANJICODEMASK) << 8) + *(p + 1));
2008-01-11 11:57:08 +00:00
}
2026-06-19 01:49:53 +09:00
int hiraknj_knj(u_char* p, int* len) {
2008-01-11 11:57:08 +00:00
*len = 1;
return hiraknj(askknj[*p & KNJASSYUKUMASK]);
}
2026-06-19 01:49:53 +09:00
int hiraknj_hask(u_char* p, int* len) {
2008-01-11 11:57:08 +00:00
*len = 1;
return 2;
}
2026-06-19 01:49:53 +09:00
int hiraknj_kask(u_char* p, int* len) {
2008-01-11 11:57:08 +00:00
*len = 1;
return 3;
}
2026-06-19 01:49:53 +09:00
int hiraknj_norm(u_char* p, int* len) {
2008-01-11 11:57:08 +00:00
*len = codesize(*p);
return 1;
}
2026-06-19 01:49:53 +09:00
int hiraknj_hira(u_char* p, int* len) {
u_char ch;
2008-01-11 11:57:08 +00:00
*len = codesize(*p);
2026-06-19 01:49:53 +09:00
ch = *(p + 1);
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
switch(*p) {
2008-01-11 11:57:08 +00:00
case 0x24:
2026-06-19 01:49:53 +09:00
if(ch >= 0x21 && ch <= 0x73) return 2;
2008-01-11 11:57:08 +00:00
return 1;
case 0x25:
2026-06-19 01:49:53 +09:00
if(ch >= 0x21 && ch <= 0x76) return 3;
2008-01-11 11:57:08 +00:00
return 1;
default:
break;
}
return 1;
}