This commit is contained in:
Nishi 2026-06-19 01:49:53 +09:00
commit 73cb09624a
116 changed files with 19741 additions and 21522 deletions

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 1991-1994 Sony Corporation
*
*
* 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
@ -8,10 +8,10 @@
* 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:
*
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
*
* 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.
@ -19,7 +19,7 @@
* 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.
*
*
* 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
@ -28,91 +28,86 @@
*/
/*
* $SonyRCSfile: adddic.c,v $
* $SonyRevision: 1.1 $
* $SonyRCSfile: adddic.c,v $
* $SonyRevision: 1.1 $
* $SonyDate: 1994/06/03 08:01:26 $
*/
#include <stdlib.h>
#include <string.h>
#include "sj_euc.h"
#include "sj_kcnv.h"
#include "sj_kanakan.h"
static void sprt_seg(TypeDicSeg, TypeDicOfs);
static void apnd_uidx(TypeDicSeg, u_char *, int);
static int cal_nextym(u_char *);
static int usr_freelen();
static u_int checkdict(u_char *, TypeGram);
static void sprt_seg(TypeDicSeg, TypeDicOfs);
static void apnd_uidx(TypeDicSeg, u_char*, int);
static int cal_nextym(u_char*);
static int usr_freelen();
static u_int checkdict(u_char*, TypeGram);
u_int adddic(u_char* yomi, u_char* kanji, TypeGram hinsi) {
u_int err;
u_char yptr[MAXWDYOMILEN + 1];
u_char kptr[MAXWDKANJILEN + 1];
int klen;
TypeDicSeg segnum;
int saml;
TypeDicOfs dstofs;
TypeDicOfs douofs;
TypeDicOfs hnsofs;
TypeDicOfs knjofs;
TypeDicOfs nxtask;
TypeDicOfs newsiz;
TypeDicOfs oldsiz;
TypeDicOfs fresiz;
TypeIdxOfs freidx;
u_char* douptr;
u_char* dstptr;
TypeDicOfs pos;
u_char* p1;
int i;
int nlen, plen;
int size;
STDYIN* stdy;
STDYOUT stdydat;
u_int
adddic(u_char *yomi, u_char *kanji, TypeGram hinsi)
{
u_int err;
u_char yptr[MAXWDYOMILEN + 1];
u_char kptr[MAXWDKANJILEN + 1];
int klen;
TypeDicSeg segnum;
int saml;
TypeDicOfs dstofs;
TypeDicOfs douofs;
TypeDicOfs hnsofs;
TypeDicOfs knjofs;
TypeDicOfs nxtask;
TypeDicOfs newsiz;
TypeDicOfs oldsiz;
TypeDicOfs fresiz;
TypeIdxOfs freidx;
u_char *douptr;
u_char *dstptr;
TypeDicOfs pos;
u_char *p1;
int i;
int nlen, plen;
int size;
STDYIN *stdy;
STDYOUT stdydat;
if (err = addel_arg(yomi, kanji, hinsi, yptr, sizeof(yptr)))
if(err = addel_arg(yomi, kanji, hinsi, yptr, sizeof(yptr)))
return err;
inputyomi = yomi;
cnvstart = ystart = yptr;
cnvlen = sstrlen(yptr);
cnvlen = sstrlen(yptr);
if (err = checkdict(kanji, hinsi))
if(err = checkdict(kanji, hinsi))
return err;
if (!curdict -> maxunit)
if(!curdict->maxunit)
return AD_NOTUSERDICT;
klen = cvtknj(yomi, kanji, kptr);
newsiz = DOUONBLKSIZENUMBER + cnvlen + (klen !=0 ? klen+1 : 0) + 2;
newsiz = DOUONBLKSIZENUMBER + cnvlen + (klen != 0 ? klen + 1 : 0) + 2;
if (newsiz > MAXDOUONBLK)
if(newsiz > MAXDOUONBLK)
return AD_OVFLWDOUBLK;
if (newsiz > curdict->seglen)
if(newsiz > curdict->seglen)
return AD_OVFLWDOUBLK;
segnum = srchidx((TypeDicSeg)DICSEGBASE, cnvlen);
for ( ; ; ) {
for(;;) {
(*curdict->getdic)(curdict, segnum);
i = srchkana(&p1, &saml);
i = srchkana(&p1, &saml);
dstofs = douofs = p1 - dicbuf;
hnsofs = knjofs = 0;
if (i) {
i = srchgram(p1, &p1, hinsi);
if(i) {
i = srchgram(p1, &p1, hinsi);
dstofs = hnsofs = p1 - dicbuf;
if (i) {
if(i) {
srchkanji(&p1, kptr, klen);
if (*p1 != HINSIBLKTERM)
if(*p1 != HINSIBLKTERM)
return AD_AREXIST;
dstofs = knjofs = p1 - dicbuf;
}
@ -120,46 +115,45 @@ adddic(u_char *yomi, u_char *kanji, TypeGram hinsi)
p1 = dicbuf + douofs;
if (!hnsofs) {
if(!hnsofs) {
oldsiz = 0;
nlen = cnvlen - saml;
newsiz = DOUONBLKSIZENUMBER + nlen;
nlen = cnvlen - saml;
newsiz = DOUONBLKSIZENUMBER + nlen;
nxtask = cal_nextym(p1);
}
else {
} else {
oldsiz = newsiz = getsize(p1);
nxtask = 0;
nxtask = 0;
}
if (!knjofs) newsiz += 2;
if(!knjofs) newsiz += 2;
newsiz += (klen != 0 ? klen+1 : 0);
newsiz += (klen != 0 ? klen + 1 : 0);
fresiz = usr_freelen();
if ((unsigned int) (newsiz - oldsiz - nxtask) <=
(unsigned int) fresiz) break;
if((unsigned int)(newsiz - oldsiz - nxtask) <=
(unsigned int)fresiz) break;
if (segend(p1) && (segnum + 1 < curdict->segunit)) {
if(segend(p1) && (segnum + 1 < curdict->segunit)) {
segnum++;
continue;
}
if (curdict->segunit >= curdict->maxunit)
if(curdict->segunit >= curdict->maxunit)
return AD_OVFLWUSRDIC;
freidx = count_uidx();
if ((unsigned int) (douofs + newsiz) <= curdict->seglen) {
if (hnsofs)
if((unsigned int)(douofs + newsiz) <= curdict->seglen) {
if(hnsofs)
p1 = getntag(p1);
pos = p1 - dicbuf;
nlen = getnlen(p1);
if ((unsigned int) freidx < getplen(p1) + nlen + 1)
if((unsigned int)freidx < getplen(p1) + nlen + 1)
return AD_OVFLWINDEX;
if ((*curdict->putdic)(curdict, curdict->segunit))
if((*curdict->putdic)(curdict, curdict->segunit))
return AD_OVFLWUSRDIC;
sprt_seg(segnum, pos);
@ -168,11 +162,11 @@ adddic(u_char *yomi, u_char *kanji, TypeGram hinsi)
break;
}
if (segend(p1)) {
if ((unsigned int) freidx < cnvlen + 1)
if(segend(p1)) {
if((unsigned int)freidx < cnvlen + 1)
return AD_OVFLWINDEX;
if ((*curdict->putdic)(curdict, curdict->segunit))
if((*curdict->putdic)(curdict, curdict->segunit))
return AD_OVFLWUSRDIC;
curdict->segunit++;
@ -184,13 +178,12 @@ adddic(u_char *yomi, u_char *kanji, TypeGram hinsi)
mkidxtbl(curdict);
segnum++;
}
else {
} else {
nlen = getnlen(p1);
if ((unsigned int) freidx < getplen(p1) + nlen + 1)
if((unsigned int)freidx < getplen(p1) + nlen + 1)
return AD_OVFLWINDEX;
if ((*curdict->putdic)(curdict, curdict->segunit))
if((*curdict->putdic)(curdict, curdict->segunit))
return AD_OVFLWUSRDIC;
sprt_seg(segnum, douofs);
@ -201,16 +194,16 @@ adddic(u_char *yomi, u_char *kanji, TypeGram hinsi)
douptr = dicbuf + douofs;
if (nxtask) {
u_char *tp;
if(nxtask) {
u_char* tp;
size = getsize(douptr) - nxtask;
plen = getplen(douptr) + nxtask;
nlen = getnlen(douptr) - nxtask;
size = getsize(douptr) - nxtask;
plen = getplen(douptr) + nxtask;
nlen = getnlen(douptr) - nxtask;
*douptr = (size >> 8);
if (nlen & 0x10)
if(nlen & 0x10)
*douptr |= NOKORIYOMITOP;
if (plen & 0x10)
if(plen & 0x10)
*douptr |= ASSYUKUYOMITOP;
*(douptr + 1) = size;
*(douptr + 2) = ((nlen & 0x0f) | ((plen & 0x0f) << 4));
@ -221,128 +214,124 @@ adddic(u_char *yomi, u_char *kanji, TypeGram hinsi)
}
dstptr = dicbuf + dstofs;
size = newsiz - oldsiz;
p1 = dicbuf + curdict->seglen;
size = newsiz - oldsiz;
p1 = dicbuf + curdict->seglen;
mvmemd(p1 - size, p1, p1 - dstptr - size);
if (!hnsofs) {
if (douofs == segtop() - dicbuf) {
if(!hnsofs) {
if(douofs == segtop() - dicbuf) {
chg_uidx(segnum, yptr, cnvlen);
}
*dstptr = 0;
nlen = cnvlen - saml;
if (nlen & 0x10)
*dstptr = 0;
nlen = cnvlen - saml;
if(nlen & 0x10)
*dstptr |= NOKORIYOMITOP;
if (saml & 0x10)
if(saml & 0x10)
*dstptr |= ASSYUKUYOMITOP;
*dstptr++ |= (size >> 8);
*dstptr++ = size;
*dstptr++ = ((nlen&0x0f)|((saml&0x0f)<<4));
*dstptr++ = size;
*dstptr++ = ((nlen & 0x0f) | ((saml & 0x0f) << 4));
while (saml < cnvlen) *dstptr++ = yptr[saml++];
}
else {
plen = getplen(douptr);
nlen = getnlen(douptr);
while(saml < cnvlen) *dstptr++ = yptr[saml++];
} else {
plen = getplen(douptr);
nlen = getnlen(douptr);
*douptr = (newsiz >> 8);
if (nlen & 0x10)
if(nlen & 0x10)
*douptr |= NOKORIYOMITOP;
if (plen & 0x10)
if(plen & 0x10)
*douptr |= ASSYUKUYOMITOP;
*(douptr + 1) = newsiz;
*(douptr + 2) = ((nlen & 0x0f) | ((plen & 0x0f) << 4));
}
if (!knjofs)
if(!knjofs)
*dstptr++ = hinsi;
stdydat.stdy1.offset = dstptr - dicbuf;
for (saml = 0 ; saml < klen ; )
for(saml = 0; saml < klen;)
*dstptr++ = kptr[saml++];
if (klen > 0)
if(klen > 0)
*dstptr++ = KANJISTREND;
if (!knjofs)
if(!knjofs)
*dstptr++ = HINSIBLKTERM;
(*curdict->putdic)(curdict, segnum);
if (StudyExist()) {
if(StudyExist()) {
size -= nxtask;
for (i = STUDYCOUNT, stdy = STUDYDICT ; i-- ; stdy++) {
if (stdy -> dicid != curdict->dicid)
for(i = STUDYCOUNT, stdy = STUDYDICT; i--; stdy++) {
if(stdy->dicid != curdict->dicid)
continue;
if (stdy -> seg != segnum)
if(stdy->seg != segnum)
continue;
if (stdy -> offset >= dstofs)
stdy -> offset += size;
if(stdy->offset >= dstofs)
stdy->offset += size;
}
for (p1 = CLSTUDYDICT ; !iseocl(p1) ; p1 = ClNextTag(p1)) {
err = sstrncmp(yptr, (u_char *)ClYomiPos(p1),
(int)ClYomiLen(p1));
if (err == MATCH) {
for(p1 = CLSTUDYDICT; !iseocl(p1); p1 = ClNextTag(p1)) {
err = sstrncmp(yptr, (u_char*)ClYomiPos(p1),
(int)ClYomiLen(p1));
if(err == MATCH) {
delclsub(p1);
mkclidx();
putcldic();
break;
} else if (err == OVER)
} else if(err == OVER)
break;
}
}
stdydat.stdy1.seg = segnum;
stdydat.stdy1.dicid = curdict->dicid;
stdydat.stdy1.styno = 0;
stdydat.stdy1.sttkj = 0;
stdydat.stdy1.ka_kj = 0;
stdydat.stdy1.nmflg = 0;
stdydat.hinshi = hinsi;
stdydat.len = cnvlen;
stdydat.sttlen = 0;
stdydat.sttfg = 0;
stdydat.ka_fg = 0;
stdydat.stdy1.seg = segnum;
stdydat.stdy1.dicid = curdict->dicid;
stdydat.stdy1.styno = 0;
stdydat.stdy1.sttkj = 0;
stdydat.stdy1.ka_kj = 0;
stdydat.stdy1.nmflg = 0;
stdydat.hinshi = hinsi;
stdydat.len = cnvlen;
stdydat.sttlen = 0;
stdydat.sttfg = 0;
stdydat.ka_fg = 0;
(void)study(&stdydat);
return AD_DONE;
}
static int
checksub(u_char *kanji, TypeGram grm)
{
u_char *tagp;
u_char *ptr;
u_char *endp;
checksub(u_char* kanji, TypeGram grm) {
u_char* tagp;
u_char* ptr;
u_char* endp;
int flg, nlen;
int dounum;
u_char buf[MAXWDKANJILEN + 1];
dicinl = cnvlen;
dicinl = cnvlen;
dicsaml = 0;
prevseg = (TypeDicSeg)-1;
for (;;) {
if (!(tagp = srchdict(tagp)))
for(;;) {
if(!(tagp = srchdict(tagp)))
return 0;
if (cnvlen == getnlen(tagp) + getplen(tagp))
if(cnvlen == getnlen(tagp) + getplen(tagp))
break;
}
dounum = 0;
nlen = getnlen(tagp);
ptr = tagp + DOUONBLKSIZENUMBER + nlen;
ptr = tagp + DOUONBLKSIZENUMBER + nlen;
endp = tagp + getsize(tagp);
while (ptr < endp) {
while(ptr < endp) {
flg = (grm == *ptr++);
while (*ptr != HINSIBLKTERM) {
if (flg) {
while(*ptr != HINSIBLKTERM) {
if(flg) {
buf[getkanji(inputyomi, cnvlen, ptr, buf)] = 0;
if (cmpstr(kanji, buf))
if(cmpstr(kanji, buf))
return -1;
}
dounum++;
@ -355,22 +344,19 @@ checksub(u_char *kanji, TypeGram grm)
return dounum;
}
static u_int
checkdict(u_char *kanji, TypeGram grm)
{
DICTL *dp;
int dounum = 0;
int tmp;
DICT *tmpdict;
checkdict(u_char* kanji, TypeGram grm) {
DICTL* dp;
int dounum = 0;
int tmp;
DICT* tmpdict;
tmpdict = curdict;
for (dp = dictlist ; dp ; dp = dp -> next) {
for(dp = dictlist; dp; dp = dp->next) {
curdict = dp -> dict;
curdict = dp->dict;
if ((tmp = checksub(kanji, grm)) < 0) {
if((tmp = checksub(kanji, grm)) < 0) {
curdict = tmpdict;
return AD_AREXIST;
}
@ -379,29 +365,26 @@ checkdict(u_char *kanji, TypeGram grm)
}
curdict = tmpdict;
if (MAXKOUHONUMBER <= dounum)
if(MAXKOUHONUMBER <= dounum)
return AD_OVFLWDOUNUM;
return 0;
}
static int
cal_nextym(u_char *ptr)
{
cal_nextym(u_char* ptr) {
int count = 0;
u_char *src;
u_char* src;
int len;
if (!segend(ptr)) {
if(!segend(ptr)) {
src = cnvstart + getplen(ptr);
len = getnlen(ptr);
ptr += DOUONBLKSIZENUMBER;
while (len--) {
if (*ptr++ == *src++)
while(len--) {
if(*ptr++ == *src++)
count++;
else
break;
@ -410,37 +393,31 @@ cal_nextym(u_char *ptr)
return count;
}
static int
usr_freelen()
{
u_char *ptr;
usr_freelen() {
u_char* ptr;
ptr = segtop();
while (!segend(ptr))
while(!segend(ptr))
ptr += getsize(ptr);
return curdict->seglen - (ptr - dicbuf);
}
static void
sprt_seg(TypeDicSeg seg, TypeDicOfs ofs)
{
TypeDicSeg s;
u_char *pos;
u_char *p;
u_char *q;
int i;
int j;
int ylen, nlen;
TypeDicID dicid;
u_char yomi[MAXWDYOMILEN];
STDYIN *stdy;
sprt_seg(TypeDicSeg seg, TypeDicOfs ofs) {
TypeDicSeg s;
u_char* pos;
u_char* p;
u_char* q;
int i;
int j;
int ylen, nlen;
TypeDicID dicid;
u_char yomi[MAXWDYOMILEN];
STDYIN* stdy;
for (s = curdict->segunit - 1 ; s >= seg ; s--) {
for(s = curdict->segunit - 1; s >= seg; s--) {
(*curdict->getdic)(curdict, s);
(*curdict->putdic)(curdict, s + 1);
}
@ -451,22 +428,22 @@ sprt_seg(TypeDicSeg seg, TypeDicOfs ofs)
pos = dicbuf + ofs;
for (p = segtop() ; (p <= pos) && !segend(p) ; p = q) {
q = getntag(p);
i = getplen(p);
for(p = segtop(); (p <= pos) && !segend(p); p = q) {
q = getntag(p);
i = getplen(p);
nlen = getnlen(p);
j = (nlen != 0) ? nlen+1: 0;
j = (nlen != 0) ? nlen + 1 : 0;
p += DOUONBLKSIZENUMBER;
while (j-- > 0)
while(j-- > 0)
yomi[i++] = *p++;
}
nlen = getnlen(pos);
ylen = (i = getplen(pos)) + (j = nlen);
ylen = (i = getplen(pos)) + (j = nlen);
apnd_uidx(seg, yomi, ylen);
set_size(segtop(), getsize(pos) + i, 0, ylen);
set_size(segtop(), getsize(pos) + i, 0, ylen);
mvmemi(yomi, (p = segtop() + DOUONBLKSIZENUMBER), ylen);
@ -480,18 +457,18 @@ sprt_seg(TypeDicSeg seg, TypeDicOfs ofs)
(*curdict->putdic)(curdict, seg + 1);
if (StudyExist()) {
dicid = curdict -> dicid;
for (i = STUDYCOUNT, stdy = STUDYDICT ; i-- > 0 ; stdy++) {
if (stdy -> dicid != dicid)
if(StudyExist()) {
dicid = curdict->dicid;
for(i = STUDYCOUNT, stdy = STUDYDICT; i-- > 0; stdy++) {
if(stdy->dicid != dicid)
continue;
else if (stdy -> seg < seg)
else if(stdy->seg < seg)
continue;
else if (stdy -> seg > seg)
stdy -> seg += 1;
else if (stdy -> offset >= ofs) {
stdy -> seg += 1;
stdy -> offset -= j;
else if(stdy->seg > seg)
stdy->seg += 1;
else if(stdy->offset >= ofs) {
stdy->seg += 1;
stdy->offset -= j;
}
}
}
@ -501,22 +478,18 @@ sprt_seg(TypeDicSeg seg, TypeDicOfs ofs)
(*curdict->putdic)(curdict, seg);
}
static void
apnd_uidx(TypeDicSeg seg, u_char *yomi, int len)
{
u_char *p;
u_char *q;
apnd_uidx(TypeDicSeg seg, u_char* yomi, int len) {
u_char* p;
u_char* q;
p = get_idxptr(seg);
while (*p++)
;
while(*p++);
q = idxbuf + curdict->idxlen;
mvmemd(q - (len + 1), q, (int)(q - (len + 1) - p));
while (len--)
while(len--)
*p++ = *yomi++;
*p = 0;