sj4/lib/sj3core/mk2claus.c

156 lines
3.3 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: mk2claus.c,v $
* $SonyRevision: 1.1 $
2008-01-11 11:57:08 +00:00
* $SonyDate: 1994/06/03 08:02:00 $
*/
#include "sj_kcnv.h"
#include "sj_right.h"
#include "sj_kanakan.h"
static int
2026-06-19 01:49:53 +09:00
set2nd(CLREC* clrec) {
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
CLREC* rec2;
2008-01-11 11:57:08 +00:00
mkjiritu(DO_IKKATU | DO_CLSTUDY);
mkbunsetu();
2026-06-19 01:49:53 +09:00
if(!maxclptr) {
2008-01-11 11:57:08 +00:00
wakachi();
2026-06-19 01:49:53 +09:00
return clrec->cllen;
2008-01-11 11:57:08 +00:00
}
2026-06-19 01:49:53 +09:00
for(rec2 = maxclptr; rec2; rec2 = rec2->clsort) {
if(terminate(rec2->right, cnvstart + rec2->cllen) != SHU)
2008-01-11 11:57:08 +00:00
break;
}
2026-06-19 01:49:53 +09:00
return rec2 ? (clrec->cllen + rec2->cllen) : (clrec->cllen);
2008-01-11 11:57:08 +00:00
}
2026-06-19 01:49:53 +09:00
void mk2claus() {
u_char* keepptr;
2008-01-11 11:57:08 +00:00
int keeplen;
2026-06-19 01:49:53 +09:00
CLREC* clrec;
2008-01-11 11:57:08 +00:00
int len;
int save2ln;
int prty;
int maxprty;
int count;
int prty2;
prty = maxprty = prty2 = 0;
clt2nd = maxclptr = NULL;
2026-06-19 01:49:53 +09:00
jrt2nd = maxjptr = NULL;
2008-01-11 11:57:08 +00:00
selcl = clt1st;
2026-06-19 01:49:53 +09:00
if(selcl->right == R_FZKKGU) {
2008-01-11 11:57:08 +00:00
pritiny();
return;
}
2026-06-19 01:49:53 +09:00
if(cnvlen == selcl->cllen) {
2008-01-11 11:57:08 +00:00
pritiny();
return;
}
keepptr = cnvstart;
keeplen = cnvlen;
len = count = 0;
2026-06-19 01:49:53 +09:00
for(clrec = selcl; clrec && count < 5; clrec = clrec->clsort) {
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
cnvstart = keepptr + clrec->cllen;
cnvlen = keeplen - clrec->cllen;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
if(len != clrec->cllen) {
if(clt2nd != maxclptr) {
2008-01-11 11:57:08 +00:00
free_clall(maxclptr);
free_jall(maxjptr);
}
save2ln = set2nd(clrec);
count++;
2026-06-19 01:49:53 +09:00
len = clrec->cllen;
2008-01-11 11:57:08 +00:00
prty2 = 0;
}
2026-06-19 01:49:53 +09:00
if(Termtbl[clrec->right] & T_SHUUJO)
clrec->cl2len = (u_char)len;
2008-01-11 11:57:08 +00:00
else
2026-06-19 01:49:53 +09:00
clrec->cl2len = (u_char)save2ln;
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
if(selcl->cl2len > clrec->cl2len) continue;
2008-01-11 11:57:08 +00:00
prty = priority(clrec) - prty2;
prty2++;
2026-06-19 01:49:53 +09:00
if(selcl->cl2len == clrec->cl2len) {
if(clrec->cllen == nextcllen) {
if(selcl->cllen != nextcllen)
2008-01-11 11:57:08 +00:00
;
2026-06-19 01:49:53 +09:00
else if(prty <= maxprty)
2008-01-11 11:57:08 +00:00
continue;
}
2026-06-19 01:49:53 +09:00
else if(prty <= maxprty)
2008-01-11 11:57:08 +00:00
continue;
}
2026-06-19 01:49:53 +09:00
selcl = clrec;
2008-01-11 11:57:08 +00:00
maxprty = prty;
2026-06-19 01:49:53 +09:00
if(clt2nd == maxclptr) continue;
2008-01-11 11:57:08 +00:00
free_clall(clt2nd);
free_jall(jrt2nd);
jrt2nd = maxjptr;
clt2nd = maxclptr;
}
2026-06-19 01:49:53 +09:00
if(clt2nd != maxclptr) {
2008-01-11 11:57:08 +00:00
free_clall(maxclptr);
2026-06-19 01:49:53 +09:00
maxclptr = NULL;
2008-01-11 11:57:08 +00:00
free_jall(maxjptr);
2026-06-19 01:49:53 +09:00
maxjptr = NULL;
2008-01-11 11:57:08 +00:00
}
cnvstart = keepptr;
2026-06-19 01:49:53 +09:00
cnvlen = keeplen;
2008-01-11 11:57:08 +00:00
}