sj4/lib/sj4core/deldic.c

265 lines
6.4 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 <string.h>
#include "sj_kcnv.h"
#include "sj_kanakan.h"
2026-06-20 02:12:04 +09:00
static int del_douon(SJ4_CONTEXT TypeDicSeg, u_char*, TypeDicOfs);
static int del_segment(SJ4_CONTEXT TypeDicSeg);
static void del_uidx(SJ4_CONTEXT TypeDicSeg);
static void del_stdy(SJ4_CONTEXT TypeDicSeg, TypeDicOfs, int);
2008-01-11 11:57:08 +00:00
2026-06-20 02:12:04 +09:00
u_int deldic(SJ4_CONTEXT u_char* yomi, u_char* kanji, TypeGram hinsi) {
2026-06-19 01:49:53 +09:00
u_char yptr[MAXWDYOMILEN + 1];
u_char kptr[MAXWDKANJILEN + 1];
u_short err;
int knjlen;
TypeDicSeg useg;
TypeDicOfs ofs;
u_char * p1, *p2, *p3;
int dblknum;
int hblknum;
int kblknum;
int samlen;
u_char * stp, *edp;
int size, len;
2026-06-20 02:12:04 +09:00
if((err = addel_arg(SJ4_CONTEXT_PASS yomi, kanji, hinsi, yptr, sizeof(yptr))))
2008-01-11 11:57:08 +00:00
return err;
2026-06-19 01:49:53 +09:00
if(!curdict->maxunit) return AD_NOTUSERDICT;
2008-01-11 11:57:08 +00:00
2026-06-20 02:12:04 +09:00
knjlen = cvtknj(SJ4_CONTEXT_PASS yomi, kanji, kptr);
2008-01-11 11:57:08 +00:00
cnvstart = yptr;
2026-06-19 01:49:53 +09:00
cnvlen = sstrlen(yptr);
2008-01-11 11:57:08 +00:00
2026-06-20 02:12:04 +09:00
useg = srchidx(SJ4_CONTEXT_PASS(TypeDicSeg) DICSEGBASE, cnvlen);
(*curdict->getdic)(SJ4_CONTEXT_PASS curdict, useg);
2008-01-11 11:57:08 +00:00
2026-06-20 02:12:04 +09:00
if(!(dblknum = srchkana(SJ4_CONTEXT_PASS & p1, &samlen))) return AD_NOMIDASI;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
if(!(hblknum = srchgram(p1, &p2, hinsi))) return AD_NOHINSI;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
p3 = p2;
2008-01-11 11:57:08 +00:00
kblknum = srchkanji(&p3, kptr, knjlen);
2026-06-19 01:49:53 +09:00
if(*p3 == HINSIBLKTERM) return AD_NOKANJI;
2008-01-11 11:57:08 +00:00
ofs = p3 - dicbuf;
2026-06-19 23:45:47 +09:00
edp = skipkstr(p3);
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
if(kblknum == 1) {
if(hblknum == 1) {
if(dblknum == 1) {
2026-06-20 02:12:04 +09:00
return del_segment(SJ4_CONTEXT_PASS useg);
2026-06-19 01:49:53 +09:00
} else {
2026-06-20 02:12:04 +09:00
return del_douon(SJ4_CONTEXT_PASS useg, p1, ofs);
2008-01-11 11:57:08 +00:00
}
2026-06-19 01:49:53 +09:00
} else {
2008-01-11 11:57:08 +00:00
stp = p2;
edp++;
}
2026-06-19 01:49:53 +09:00
} else {
2008-01-11 11:57:08 +00:00
stp = p3;
}
size = edp - stp;
len = dicbuf + (curdict->seglen) - edp;
mvmemi(edp, stp, len);
edp += len;
memset(edp, DICSEGTERM, dicbuf + curdict->seglen - edp);
set_size(p1, (int)(getsize(p1) - size),
2026-06-19 01:49:53 +09:00
(int)getplen(p1), (int)getnlen(p1));
2008-01-11 11:57:08 +00:00
2026-06-20 02:12:04 +09:00
(*curdict->putdic)(SJ4_CONTEXT_PASS curdict, useg);
2008-01-11 11:57:08 +00:00
2026-06-20 02:12:04 +09:00
del_stdy(SJ4_CONTEXT_PASS useg, ofs, size);
2008-01-11 11:57:08 +00:00
return AD_DONE;
}
static int
2026-06-20 02:12:04 +09:00
del_douon(SJ4_CONTEXT TypeDicSeg seg, u_char* ptr, TypeDicOfs ofs) {
2026-06-19 01:49:53 +09:00
u_char *nxt, *p1, *p2;
2008-01-11 11:57:08 +00:00
int size;
int nlen, plen, len;
nxt = getntag(ptr);
2026-06-19 01:49:53 +09:00
if(segend(nxt)) {
2008-01-11 11:57:08 +00:00
size = nxt - ptr;
memset(ptr, DICSEGTERM, dicbuf + curdict->seglen - nxt);
2026-06-19 01:49:53 +09:00
} else {
2008-01-11 11:57:08 +00:00
size = getsize(nxt);
nlen = getnlen(nxt);
plen = getplen(nxt);
2026-06-19 01:49:53 +09:00
if(ptr == segtop()) {
2026-06-20 02:12:04 +09:00
if(nlen + plen > (unsigned int)count_uidx(SJ4_CONTEXT_PASS2) + sstrlen(get_idxptr(SJ4_CONTEXT_PASS seg)))
2008-01-11 11:57:08 +00:00
return AD_OVFLWINDEX;
}
len = ((len = getplen(ptr)) < plen) ? plen - len : 0;
set_size(ptr, size + len, plen - len, nlen + len);
p1 = nxt + DOUONBLKSIZENUMBER;
p2 = ptr + DOUONBLKSIZENUMBER + len;
mvmemi(p1, p2, dicbuf + curdict->seglen - p1);
size = p1 - p2;
memset(dicbuf + curdict->seglen - size, DICSEGTERM, size);
2026-06-19 01:49:53 +09:00
if(ptr == segtop()) {
2026-06-20 02:12:04 +09:00
chg_uidx(SJ4_CONTEXT_PASS seg, ptr + DOUONBLKSIZENUMBER, nlen + len);
2008-01-11 11:57:08 +00:00
}
}
2026-06-20 02:12:04 +09:00
(*curdict->putdic)(SJ4_CONTEXT_PASS curdict, seg);
2008-01-11 11:57:08 +00:00
2026-06-20 02:12:04 +09:00
del_stdy(SJ4_CONTEXT_PASS seg, ofs, size);
2008-01-11 11:57:08 +00:00
return AD_DONE;
}
static int
2026-06-20 02:12:04 +09:00
del_segment(SJ4_CONTEXT TypeDicSeg seg) {
2026-06-19 01:49:53 +09:00
int i;
STDYIN* styp;
TypeDicID dicid;
TypeStyNum stdynum;
TypeDicSeg sg;
if(curdict->segunit > 1) {
for(sg = seg + 1; sg < curdict->segunit; sg++) {
2026-06-20 02:12:04 +09:00
(*curdict->getdic)(SJ4_CONTEXT_PASS curdict, sg);
(*curdict->putdic)(SJ4_CONTEXT_PASS curdict, sg - 1);
2008-01-11 11:57:08 +00:00
}
curdict->segunit--;
2026-06-19 01:49:53 +09:00
} else {
2008-01-11 11:57:08 +00:00
memset(dicbuf, DICSEGTERM, (int)curdict->seglen);
dicbuf[0] = 0;
2026-06-20 02:12:04 +09:00
(*curdict->putdic)(SJ4_CONTEXT_PASS curdict, DICSEGBASE);
2008-01-11 11:57:08 +00:00
}
2026-06-20 02:12:04 +09:00
(*curdict->rszdic)(SJ4_CONTEXT_PASS curdict, curdict->segunit);
2008-01-11 11:57:08 +00:00
2026-06-20 02:12:04 +09:00
del_uidx(SJ4_CONTEXT_PASS seg);
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
if(StudyExist()) {
2008-01-11 11:57:08 +00:00
dicid = curdict->dicid;
2026-06-19 01:49:53 +09:00
for(i = 0, styp = STUDYDICT; i < STUDYCOUNT;) {
if(styp->dicid != dicid)
2008-01-11 11:57:08 +00:00
;
2026-06-19 01:49:53 +09:00
else if(styp->seg > seg)
styp->seg -= 1;
else if(styp->seg < seg)
2008-01-11 11:57:08 +00:00
;
else {
2026-06-19 01:49:53 +09:00
stdynum = styp->styno;
2008-01-11 11:57:08 +00:00
STUDYCOUNT--;
2026-06-19 01:49:53 +09:00
mvmemi((u_char*)(styp + 1), (u_char*)styp,
sizeof(*styp) * (STUDYCOUNT - i));
2008-01-11 11:57:08 +00:00
continue;
}
i++;
styp++;
}
2026-06-19 01:49:53 +09:00
for(i = 0, styp = STUDYDICT; i < STUDYCOUNT; i++, styp++)
if(styp->styno > stdynum) styp->styno -= 1;
2008-01-11 11:57:08 +00:00
2026-06-20 02:12:04 +09:00
putstydic(SJ4_CONTEXT_PASS2);
2008-01-11 11:57:08 +00:00
}
return AD_DONE;
}
static void
2026-06-20 02:12:04 +09:00
del_uidx(SJ4_CONTEXT TypeDicSeg seg) {
2026-06-19 01:49:53 +09:00
u_char *p, *q;
2008-01-11 11:57:08 +00:00
int len;
2026-06-20 02:12:04 +09:00
p = get_idxptr(SJ4_CONTEXT_PASS seg);
2026-06-19 01:49:53 +09:00
for(q = p; *q++;);
2008-01-11 11:57:08 +00:00
mvmemi(q, p, idxbuf + curdict->idxlen - q);
len = q - p;
memset(idxbuf + curdict->idxlen - len, 0, len);
2026-06-20 02:12:04 +09:00
(*curdict->putidx)(SJ4_CONTEXT_PASS curdict, 0);
2008-01-11 11:57:08 +00:00
2026-06-20 02:12:04 +09:00
mkidxtbl(SJ4_CONTEXT_PASS curdict);
2008-01-11 11:57:08 +00:00
}
static void
2026-06-20 02:12:04 +09:00
del_stdy(SJ4_CONTEXT TypeDicSeg seg, TypeDicOfs ofs, int size) {
2026-06-19 01:49:53 +09:00
int i;
TypeStyNum stdynum;
STDYIN* stdy;
TypeDicID dicid;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
if(StudyExist()) {
2008-01-11 11:57:08 +00:00
stdynum = 0;
2026-06-19 01:49:53 +09:00
dicid = curdict->dicid;
for(i = 0, stdy = STUDYDICT; i < STUDYCOUNT;) {
if(stdy->dicid != dicid)
2008-01-11 11:57:08 +00:00
;
2026-06-19 01:49:53 +09:00
else if(stdy->seg != seg)
2008-01-11 11:57:08 +00:00
;
2026-06-19 01:49:53 +09:00
else if(stdy->offset > ofs)
stdy->offset -= size;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
else if(stdy->offset == ofs) {
stdynum = stdy->styno;
2008-01-11 11:57:08 +00:00
STUDYCOUNT--;
2026-06-19 01:49:53 +09:00
mvmemi((u_char*)(stdy + 1), (u_char*)stdy,
sizeof(*stdy) * (STUDYCOUNT - i));
2008-01-11 11:57:08 +00:00
continue;
}
i++;
stdy++;
}
2026-06-19 01:49:53 +09:00
for(i = 0, stdy = STUDYDICT; i < STUDYCOUNT; i++, stdy++)
if(stdy->styno > stdynum) (stdy->styno)--;
2008-01-11 11:57:08 +00:00
2026-06-20 02:12:04 +09:00
putstydic(SJ4_CONTEXT_PASS2);
2008-01-11 11:57:08 +00:00
}
}