sj4/lib/sj4core/ph2knj.c

103 lines
2.6 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 "sj_kcnv.h"
#include "sj_yomi.h"
#include "sj_kanakan.h"
2026-06-20 02:12:04 +09:00
int ph2knj(SJ4_CONTEXT u_char* zyomi, u_char* kanji, int knjlen) {
2026-06-19 01:49:53 +09:00
u_char* ptr;
u_char* dst;
2008-01-11 11:57:08 +00:00
int i;
2026-06-19 01:49:53 +09:00
for(ptr = zyomi, dst = hyomi, i = 0; *ptr;) {
if(i++ >= MAXPHINPUTLEN) {
*kanji = 0;
return 0;
}
2008-01-11 11:57:08 +00:00
ptr += sj2cd_chr(ptr, dst++);
}
*dst = 0;
2026-06-20 02:12:04 +09:00
freework(SJ4_CONTEXT_PASS2);
2008-01-11 11:57:08 +00:00
prevclgrm = 0;
prevclrow = 0;
2026-06-19 01:49:53 +09:00
khcount = 0;
2008-01-11 11:57:08 +00:00
nextcllen = 0;
inputyomi = zyomi;
cnvstart = ystart = hyomi;
2026-06-19 01:49:53 +09:00
cnvlen = sstrlen(hyomi);
2008-01-11 11:57:08 +00:00
kanjipos = kanji;
kanjilen = knjlen;
2026-06-19 01:49:53 +09:00
while(cnvlen && kanjilen) {
if(!clt1st) {
2026-06-20 02:12:04 +09:00
mkjiritu(SJ4_CONTEXT_PASS DO_CLSTUDY | DO_IKKATU);
2008-01-11 11:57:08 +00:00
2026-06-20 02:12:04 +09:00
mkbunsetu(SJ4_CONTEXT_PASS2);
2008-01-11 11:57:08 +00:00
2026-06-20 02:12:04 +09:00
if(!maxclptr) wakachi(SJ4_CONTEXT_PASS2);
2008-01-11 11:57:08 +00:00
jrt1st = maxjptr;
clt1st = maxclptr;
}
2026-06-20 02:12:04 +09:00
mk2claus(SJ4_CONTEXT_PASS2);
2008-01-11 11:57:08 +00:00
2026-06-20 02:12:04 +09:00
selclrec(SJ4_CONTEXT_PASS2);
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
prevclgrm = selcl->jnode->hinsi;
prevclrow = selcl->right;
2008-01-11 11:57:08 +00:00
2026-06-20 02:12:04 +09:00
clt1st = free_clst(SJ4_CONTEXT_PASS clt1st, (int)selcl->cllen);
jrt1st = free_jlst(SJ4_CONTEXT_PASS jrt1st);
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
cnvstart += selcl->cllen;
cnvlen -= selcl->cllen;
2008-01-11 11:57:08 +00:00
2026-06-20 02:12:04 +09:00
cvtphknj(SJ4_CONTEXT_PASS2);
2008-01-11 11:57:08 +00:00
2026-06-19 01:49:53 +09:00
clt1st = clt2nd;
jrt1st = jrt2nd;
2008-01-11 11:57:08 +00:00
}
2026-06-19 01:49:53 +09:00
if(!kanjilen) {
2026-06-20 02:12:04 +09:00
free_clall(SJ4_CONTEXT_PASS clt1st);
free_jall(SJ4_CONTEXT_PASS jrt1st);
2026-06-19 01:49:53 +09:00
}
2008-01-11 11:57:08 +00:00
*kanjipos = 0;
2026-06-19 01:49:53 +09:00
return (inputyomi - zyomi);
2008-01-11 11:57:08 +00:00
}