sj4/lib/sj3core/peepdic.c

363 lines
5.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: peepdic.c,v $
* $SonyRevision: 1.2 $
2008-01-11 11:57:08 +00:00
* $SonyDate: 1995/07/21 05:22:51 $
*/
#include "sj_kcnv.h"
#include "sj_yomi.h"
#include "sj_kanakan.h"
2026-06-19 01:49:53 +09:00
static int prev_kanji(), prev_hinsi(), prev_douon();
static int next_kanji(), next_hinsi(), next_douon();
static void set_kanji(), set_buf(), add_yomi();
static void set_idxyomi();
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
static void cd2sjh_chr(u_char ch, u_char* dst);
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
int getusr(u_char* buf) {
2008-01-11 11:57:08 +00:00
int nlen;
peepyomi[0] = peepknj[0] = peepgrm = 0;
(*curdict->getdic)(curdict, peepidx = DICSEGBASE);
get_askknj();
peepdptr = segtop();
2026-06-19 01:49:53 +09:00
if(segend(peepdptr)) return 0;
2008-01-11 11:57:08 +00:00
add_yomi();
2026-06-19 01:49:53 +09:00
nlen = getnlen(peepdptr);
peephptr = peepdptr + DOUONBLKSIZENUMBER + nlen;
2008-01-11 11:57:08 +00:00
peepgrm = *peephptr;
peepkptr = peephptr + 1;
set_kanji();
set_buf(buf);
return -1;
}
2026-06-19 01:49:53 +09:00
int nextusr(u_char* buf) {
2008-01-11 11:57:08 +00:00
(*curdict->getdic)(curdict, peepidx);
get_askknj();
2026-06-19 01:49:53 +09:00
if(next_kanji()) {
2008-01-11 11:57:08 +00:00
set_kanji();
set_buf(buf);
return -1;
}
return 0;
}
2026-06-19 01:49:53 +09:00
int prevusr(u_char* buf) {
2008-01-11 11:57:08 +00:00
(*curdict->getdic)(curdict, peepidx);
get_askknj();
2026-06-19 01:49:53 +09:00
if(prev_kanji()) {
2008-01-11 11:57:08 +00:00
set_kanji();
set_buf(buf);
return -1;
}
return 0;
}
static void
2026-06-19 01:49:53 +09:00
set_kanji() {
int len;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
len = getkanji(peepyomi, getnlen(peepdptr) + getplen(peepdptr),
peepkptr, peepknj);
2008-01-11 11:57:08 +00:00
*(peepknj + len) = 0;
}
static void
2026-06-19 01:49:53 +09:00
set_buf(u_char* buf) {
u_char* p;
int i, csize;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
for(p = peepyomi; *p;) *buf++ = *p++;
2008-01-11 11:57:08 +00:00
*buf++ = 0;
2026-06-19 01:49:53 +09:00
for(p = peepknj; *p;) {
2008-01-11 11:57:08 +00:00
csize = euc_codesize(*p);
2026-06-19 01:49:53 +09:00
for(i = 0; i < csize; i++) *buf++ = *p++;
2008-01-11 11:57:08 +00:00
}
*buf++ = 0;
*buf++ = peepgrm;
*buf++ = 0;
}
static int
2026-06-19 01:49:53 +09:00
prev_kanji() {
u_char* p1;
u_char* p2;
2008-01-11 11:57:08 +00:00
p1 = peephptr + 1;
2026-06-19 01:49:53 +09:00
if(peepkptr <= p1) return prev_hinsi();
2008-01-11 11:57:08 +00:00
p2 = peepkptr;
2026-06-19 01:49:53 +09:00
while(p1 < p2) {
2008-01-11 11:57:08 +00:00
peepkptr = p1;
2026-06-19 01:49:53 +09:00
p1 = skipkstr(p1);
2008-01-11 11:57:08 +00:00
}
return -1;
}
static int
2026-06-19 01:49:53 +09:00
prev_hinsi() {
u_char* p1;
u_char* p2;
int nlen;
2008-01-11 11:57:08 +00:00
nlen = getnlen(peepdptr);
2026-06-19 01:49:53 +09:00
p1 = peepdptr + DOUONBLKSIZENUMBER + nlen;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
if(peephptr <= p1) return prev_douon();
2008-01-11 11:57:08 +00:00
p2 = peephptr;
2026-06-19 01:49:53 +09:00
while(p1 < p2) {
2008-01-11 11:57:08 +00:00
peephptr = p1;
2026-06-19 01:49:53 +09:00
p1 = skiphblk(p1);
2008-01-11 11:57:08 +00:00
}
peepgrm = *peephptr;
p1 = peephptr + 1;
2026-06-19 01:49:53 +09:00
while(*p1 != HINSIBLKTERM) {
2008-01-11 11:57:08 +00:00
peepkptr = p1;
p1 = skipkstr(p1);
}
return -1;
}
static int
2026-06-19 01:49:53 +09:00
prev_douon() {
u_char* p1;
u_char* p2;
int nlen;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
if(peepdptr <= segtop()) {
if(peepidx <= DICSEGBASE) return 0;
2008-01-11 11:57:08 +00:00
(*curdict->getdic)(curdict, --peepidx);
get_askknj();
set_idxyomi();
p1 = segtop();
do {
peepdptr = p1;
add_yomi();
p1 = getntag(p1);
2026-06-19 01:49:53 +09:00
} while(!segend(p1));
} else {
2008-01-11 11:57:08 +00:00
set_idxyomi();
p1 = segtop();
p2 = peepdptr;
do {
peepdptr = p1;
add_yomi();
p1 = getntag(p1);
2026-06-19 01:49:53 +09:00
} while(p1 < p2);
2008-01-11 11:57:08 +00:00
}
nlen = getnlen(peepdptr);
2026-06-19 01:49:53 +09:00
p1 = peepdptr + DOUONBLKSIZENUMBER + nlen;
2008-01-11 11:57:08 +00:00
p2 = getntag(peepdptr);
do {
peephptr = p1;
2026-06-19 01:49:53 +09:00
p1 = skiphblk(p1);
} while(p1 < p2);
2008-01-11 11:57:08 +00:00
peepgrm = *peephptr;
p1 = peephptr + 1;
do {
peepkptr = p1;
p1 = skipkstr(p1);
2026-06-19 01:49:53 +09:00
} while(*p1 != HINSIBLKTERM);
2008-01-11 11:57:08 +00:00
return -1;
}
static int
2026-06-19 01:49:53 +09:00
next_kanji() {
u_char* p1;
2008-01-11 11:57:08 +00:00
p1 = skipkstr(peepkptr);
2026-06-19 01:49:53 +09:00
if(*p1 == HINSIBLKTERM) return next_hinsi();
2008-01-11 11:57:08 +00:00
peepkptr = p1;
return -1;
}
static int
2026-06-19 01:49:53 +09:00
next_hinsi() {
u_char* p1;
2008-01-11 11:57:08 +00:00
p1 = skiphblk(peephptr);
2026-06-19 01:49:53 +09:00
if(p1 >= getntag(peepdptr)) return next_douon();
2008-01-11 11:57:08 +00:00
peephptr = p1;
peepgrm = *p1;
peepkptr = p1 + 1;
return -1;
}
static int
2026-06-19 01:49:53 +09:00
next_douon() {
u_char* p1;
int nlen;
2008-01-11 11:57:08 +00:00
p1 = getntag(peepdptr);
2026-06-19 01:49:53 +09:00
if(segend(p1)) {
if(peepidx + 1 < curdict->segunit) {
2008-01-11 11:57:08 +00:00
(*curdict->getdic)(curdict, ++peepidx);
get_askknj();
peepdptr = segtop();
set_idxyomi();
2026-06-19 01:49:53 +09:00
} else
return 0;
} else {
2008-01-11 11:57:08 +00:00
peepdptr = p1;
}
add_yomi();
2026-06-19 01:49:53 +09:00
nlen = getnlen(peepdptr);
peephptr = peepdptr + DOUONBLKSIZENUMBER + nlen;
2008-01-11 11:57:08 +00:00
peepgrm = *peephptr;
peepkptr = peephptr + 1;
return -1;
}
static void
2026-06-19 01:49:53 +09:00
set_idxyomi() {
u_char *p1, *p2;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
if(p2 = get_idxptr(peepidx)) {
2008-01-11 11:57:08 +00:00
p1 = peepyomi;
2026-06-19 01:49:53 +09:00
while(*p2) {
2008-01-11 11:57:08 +00:00
cd2sjh_chr(*p2++, p1);
p1 += 2;
}
*p1 = 0;
}
}
static void
2026-06-19 01:49:53 +09:00
add_yomi() {
2008-01-11 11:57:08 +00:00
int nlen;
2026-06-19 01:49:53 +09:00
u_char *p1, *p2;
2008-01-11 11:57:08 +00:00
nlen = getnlen(peepdptr);
p1 = peepyomi + getplen(peepdptr) * 2;
p2 = peepdptr + DOUONBLKSIZENUMBER;
2026-06-19 01:49:53 +09:00
while(nlen--) {
2008-01-11 11:57:08 +00:00
cd2sjh_chr(*p2++, p1);
p1 += 2;
}
*p1 = 0;
}
static void
2026-06-19 01:49:53 +09:00
cd2sjh_chr(u_char ch, u_char* dst) {
if(ch == _TYOUON) {
2008-01-11 11:57:08 +00:00
*dst++ = 0xa1;
*dst++ = 0xbc;
2026-06-19 01:49:53 +09:00
} else if(ch == _IGETA) {
2008-01-11 11:57:08 +00:00
*dst++ = 0xa1;
*dst++ = 0xf4;
2026-06-19 01:49:53 +09:00
} else if(ch == _ATTO) {
2008-01-11 11:57:08 +00:00
*dst++ = 0xa1;
*dst++ = 0xf7;
2026-06-19 01:49:53 +09:00
} else if(ch == _YUUBIN) {
2008-01-11 11:57:08 +00:00
*dst++ = 0xa2;
*dst++ = 0xa9;
2026-06-19 01:49:53 +09:00
} else if(ch < N_0) {
} else if(ch <= N_9) {
2008-01-11 11:57:08 +00:00
*dst++ = 0xa3;
*dst++ = ch + 0xa0;
2026-06-19 01:49:53 +09:00
} else if(ch <= A_Z) {
2008-01-11 11:57:08 +00:00
*dst++ = 0xa3;
*dst++ = ch + 0xa7;
2026-06-19 01:49:53 +09:00
} else if(ch <= A_z) {
2008-01-11 11:57:08 +00:00
*dst++ = 0xa3;
*dst++ = ch + 0xad;
2026-06-19 01:49:53 +09:00
} else if(ch <= _NN) {
2008-01-11 11:57:08 +00:00
*dst++ = 0xa4;
*dst++ = ch + 0x53;
2026-06-19 01:49:53 +09:00
} else if(ch <= _XKE) {
2008-01-11 11:57:08 +00:00
*dst++ = 0xa5;
*dst++ = ch + 0x53;
2026-06-19 01:49:53 +09:00
} else {
2008-01-11 11:57:08 +00:00
}
}