Import SJ3 2.0.1.20
Signed-off-by: Masanori Ogino <mogino@acm.org>
This commit is contained in:
commit
b568905e51
208 changed files with 89304 additions and 0 deletions
198
dict/tool/GramTable
Normal file
198
dict/tool/GramTable
Normal file
|
|
@ -0,0 +1,198 @@
|
|||
"カ五1", 91,
|
||||
"カ五2", 101,
|
||||
"カ五3", 131,
|
||||
"カ五4", 141,
|
||||
"カ五5", 111,
|
||||
"カ五6", 121,
|
||||
"カ五7", 151,
|
||||
"カ五8", 161,
|
||||
"カ五音便", 185,
|
||||
"カ変仮", 181,
|
||||
"カ変終体", 180,
|
||||
"カ変未", 178,
|
||||
"カ変命", 182,
|
||||
"カ変用", 179,
|
||||
"ガ五1", 92,
|
||||
"ガ五2", 102,
|
||||
"ガ五3", 132,
|
||||
"ガ五4", 142,
|
||||
"ガ五5", 112,
|
||||
"ガ五6", 122,
|
||||
"ガ五7", 152,
|
||||
"ガ五8", 162,
|
||||
"サ五1", 93,
|
||||
"サ五2", 103,
|
||||
"サ五3", 133,
|
||||
"サ五4", 143,
|
||||
"サ五5", 113,
|
||||
"サ五6", 123,
|
||||
"サ五7", 153,
|
||||
"サ五8", 163,
|
||||
"サ変", 80,
|
||||
"サ変仮", 175,
|
||||
"サ変終体", 174,
|
||||
"サ変未1", 171,
|
||||
"サ変未2", 172,
|
||||
"サ変未用", 173,
|
||||
"サ変命1", 176,
|
||||
"サ変命2", 177,
|
||||
"ザ変", 81,
|
||||
"タ五1", 94,
|
||||
"タ五2", 104,
|
||||
"タ五3", 134,
|
||||
"タ五4", 144,
|
||||
"タ五5", 114,
|
||||
"タ五6", 124,
|
||||
"タ五7", 154,
|
||||
"タ五8", 164,
|
||||
"ナ五", 95,
|
||||
"バ五1", 96,
|
||||
"バ五2", 105,
|
||||
"バ五3", 135,
|
||||
"バ五4", 145,
|
||||
"バ五5", 115,
|
||||
"バ五6", 125,
|
||||
"バ五7", 155,
|
||||
"バ五8", 165,
|
||||
"マ五1", 97,
|
||||
"マ五2", 106,
|
||||
"マ五3", 136,
|
||||
"マ五4", 146,
|
||||
"マ五5", 116,
|
||||
"マ五6", 126,
|
||||
"マ五7", 156,
|
||||
"マ五8", 166,
|
||||
"ラ五1", 98,
|
||||
"ラ五2", 107,
|
||||
"ラ五3", 137,
|
||||
"ラ五4", 147,
|
||||
"ラ五5", 117,
|
||||
"ラ五6", 127,
|
||||
"ラ五7", 157,
|
||||
"ラ五8", 167,
|
||||
"ワ五1", 99,
|
||||
"ワ五2", 108,
|
||||
"ワ五3", 138,
|
||||
"ワ五4", 148,
|
||||
"ワ五5", 118,
|
||||
"ワ五6", 128,
|
||||
"ワ五7", 158,
|
||||
"ワ五8", 168,
|
||||
"挨拶", 187,
|
||||
"衣服", -11,
|
||||
"一括", 200,
|
||||
"一段1", 90,
|
||||
"一段2", 100,
|
||||
"一段3", 130,
|
||||
"一段4", 140,
|
||||
"雨", -21,
|
||||
"音楽", -20,
|
||||
"海", -31,
|
||||
"開閉", -4,
|
||||
"活動", -5,
|
||||
"感動", 28,
|
||||
"企業", 23,
|
||||
"魚", -14,
|
||||
"形1", 60,
|
||||
"形10", 69,
|
||||
"形11", 70,
|
||||
"形2", 61,
|
||||
"形3", 62,
|
||||
"形4", 63,
|
||||
"形5", 64,
|
||||
"形6", 65,
|
||||
"形7", 66,
|
||||
"形8", 67,
|
||||
"形9", 68,
|
||||
"形動1", 71,
|
||||
"形動2", 72,
|
||||
"形動3", 73,
|
||||
"形動4", 74,
|
||||
"形動5", 75,
|
||||
"形動6", 76,
|
||||
"形動7", 77,
|
||||
"形動8", 78,
|
||||
"形動9", 79,
|
||||
"建築", -13,
|
||||
"県区", 25,
|
||||
"湖", -33,
|
||||
"国", -12,
|
||||
"試合", -10,
|
||||
"事件", -27,
|
||||
"時", -25,
|
||||
"酒", -23,
|
||||
"州", -29,
|
||||
"出版", -18,
|
||||
"所", -2,
|
||||
"助数", 29,
|
||||
"助数2", 54,
|
||||
"乗物", -17,
|
||||
"植物", -6,
|
||||
"食物", -16,
|
||||
"身体", -8,
|
||||
"人", -1,
|
||||
"数詞", 30,
|
||||
"数詞2", 55,
|
||||
"接続", 27,
|
||||
"接頭1", 31,
|
||||
"接頭2", 32,
|
||||
"接頭3", 33,
|
||||
"接頭4", 34,
|
||||
"接頭5", 35,
|
||||
"接尾1", 36,
|
||||
"接尾2", 37,
|
||||
"接尾3", 38,
|
||||
"接尾4", 39,
|
||||
"接尾5", 40,
|
||||
"接尾6", 41,
|
||||
"接尾7", 42,
|
||||
"接尾8", 43,
|
||||
"接尾9", 44,
|
||||
"川", -30,
|
||||
"組織", -3,
|
||||
"贈物", -26,
|
||||
"代1", 12,
|
||||
"代2", 13,
|
||||
"代3", 14,
|
||||
"代4", 15,
|
||||
"代5", 16,
|
||||
"代6", 17,
|
||||
"単漢", 189,
|
||||
"地位", -7,
|
||||
"地名", 24,
|
||||
"丁寧1", 183,
|
||||
"丁寧2", 184,
|
||||
"電車", -34,
|
||||
"都市", -24,
|
||||
"島", -32,
|
||||
"動物", -9,
|
||||
"特殊形容", 188,
|
||||
"特殊副", 186,
|
||||
"病気", -15,
|
||||
"苗字", 21,
|
||||
"副1", 45,
|
||||
"副2", 46,
|
||||
"副3", 47,
|
||||
"副4", 48,
|
||||
"副5", 49,
|
||||
"副6", 50,
|
||||
"副7", 51,
|
||||
"副8", 52,
|
||||
"副9", 53,
|
||||
"文字", -19,
|
||||
"法", -35,
|
||||
"名1", 1,
|
||||
"名10", 10,
|
||||
"名11", 11,
|
||||
"名2", 2,
|
||||
"名20", 18,
|
||||
"名3", 3,
|
||||
"名4", 4,
|
||||
"名5", 5,
|
||||
"名6", 6,
|
||||
"名7", 7,
|
||||
"名8", 8,
|
||||
"名9", 9,
|
||||
"名前", 22,
|
||||
"鳴物", -28,
|
||||
"連体", 26
|
||||
79
dict/tool/Imakefile
Normal file
79
dict/tool/Imakefile
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* 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
|
||||
* 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:
|
||||
*
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $SonyRCSfile: Imakefile,v $
|
||||
* $SonyRevision: 1.4 $
|
||||
* $SonyDate: 1997/01/23 11:20:51 $
|
||||
*/
|
||||
|
||||
/*
|
||||
* Change some make rules.
|
||||
* Patched by Hidekazu Kuroki(hidekazu@cs.titech.ac.jp) 1996/8/10
|
||||
*/
|
||||
|
||||
#include "../../sj3.tmpl"
|
||||
|
||||
INCLUDES = -I../include -I../../include
|
||||
|
||||
INSTFLAGS = -o $(SJ3OWNER) -g $(SJ3GROUP) -m 755
|
||||
|
||||
SRCS = \
|
||||
char.c \
|
||||
cnvhinsi.c \
|
||||
file.c \
|
||||
global.c \
|
||||
hindo.c \
|
||||
knjcvt.c \
|
||||
makedict.c \
|
||||
makelist.c \
|
||||
makeseg.c \
|
||||
memory.c \
|
||||
offset.c \
|
||||
readline.c \
|
||||
string.c
|
||||
|
||||
OBJS = \
|
||||
char.o \
|
||||
cnvhinsi.o \
|
||||
file.o \
|
||||
global.o \
|
||||
hindo.o \
|
||||
knjcvt.o \
|
||||
makedict.o \
|
||||
makelist.o \
|
||||
makeseg.o \
|
||||
memory.o \
|
||||
offset.o \
|
||||
readline.o \
|
||||
string.o
|
||||
|
||||
AllTarget(sj3mkdic)
|
||||
NormalProgramTarget(sj3mkdic,$(OBJS),,,)
|
||||
DependTarget()
|
||||
InstallProgramWithFlags(sj3mkdic,$(SJ3BINDIR),$(INSTFLAGS))
|
||||
283
dict/tool/char.c
Normal file
283
dict/tool/char.c
Normal file
|
|
@ -0,0 +1,283 @@
|
|||
/*
|
||||
* 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
|
||||
* 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:
|
||||
*
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* $SonyRCSfile: char.c,v $
|
||||
* $SonyRevision: 1.1 $
|
||||
* $SonyDate: 1994/06/03 08:00:32 $
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include "sj_euc.h"
|
||||
#include "sj_const.h"
|
||||
|
||||
|
||||
|
||||
cnvyomi(code)
|
||||
int code;
|
||||
{
|
||||
register u_short hh;
|
||||
register u_char high;
|
||||
register u_char low;
|
||||
|
||||
hh = ((code >> 16) & 0xffff);
|
||||
high = ((code >> 8) & 0xff);
|
||||
low = (code & 0xff);
|
||||
|
||||
if (!hh) {
|
||||
if (high == 0xa1) {
|
||||
switch (low) {
|
||||
case 0xbc: return 1;
|
||||
case 0xf4: return 2;
|
||||
case 0xf7: return 3;
|
||||
case 0xa7: return 4;
|
||||
}
|
||||
}
|
||||
else if (high == 0xa2) {
|
||||
if (low == 0xa9)
|
||||
return 4;
|
||||
}
|
||||
else if (high == 0xa3) {
|
||||
if (low < 0xb0)
|
||||
;
|
||||
else if (low <= 0xb9)
|
||||
return(low - 0xb0 + 0x10);
|
||||
else if (low < 0xc0)
|
||||
;
|
||||
else if (low <= 0xda)
|
||||
return(low - 0xc1 + 0x1A);
|
||||
else if (low < 0xe1)
|
||||
;
|
||||
else if (low <= 0xfa)
|
||||
return(low - 0xe1 + 0x34);
|
||||
}
|
||||
else if (high == 0xa4) {
|
||||
if (low < 0xa1)
|
||||
;
|
||||
else if (low <= 0xf3)
|
||||
return(low - 0xa1 + 0x4e);
|
||||
}
|
||||
else if (high == 0xa5) {
|
||||
switch (low) {
|
||||
case 0xf4: return 0xa1;
|
||||
case 0xf5: return 0xa2;
|
||||
case 0xf6: return 0xa3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
h2kcode(code)
|
||||
int code;
|
||||
{
|
||||
register u_short hh;
|
||||
register u_char high;
|
||||
register u_char low;
|
||||
|
||||
hh = ((code >> 16) & 0xffff);
|
||||
high = ((code >> 8) & 0xff);
|
||||
low = (code & 0xff);
|
||||
|
||||
if (!hh) {
|
||||
if (high != 0xa4)
|
||||
return code;
|
||||
else
|
||||
return (code + 0x0100);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
codesize(code)
|
||||
u_char code;
|
||||
{
|
||||
switch (code&KanjiModeMask) {
|
||||
case ZenHiraAssyuku:
|
||||
case ZenKataAssyuku:
|
||||
case KanjiAssyuku:
|
||||
case KanjiStrEnd:
|
||||
return 1;
|
||||
case LeadingHankaku:
|
||||
case OffsetAssyuku:
|
||||
case AiAttribute:
|
||||
return 2;
|
||||
default:
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
output_knj(fp, p, l)
|
||||
FILE *fp;
|
||||
register u_char *p;
|
||||
register int l;
|
||||
{
|
||||
while (l > 0) {
|
||||
switch (*p & KanjiModeMask) {
|
||||
case ZenHiraAssyuku:
|
||||
fprintf(fp, "\244\322%d", (*p++ & 0x0f) + 1);
|
||||
l--;
|
||||
break;
|
||||
case ZenKataAssyuku:
|
||||
fprintf(fp, "\245\253%d", (*p++ & 0x0f) + 1);
|
||||
l--;
|
||||
break;
|
||||
case KanjiAssyuku:
|
||||
fprintf(fp, "\260\265%1x", (*p++ & 0x0f));
|
||||
l--;
|
||||
break;
|
||||
case LeadingHankaku:
|
||||
#ifndef UseHankakuInDict
|
||||
l = 0;
|
||||
fprintf(stderr, "\244\252\244\253\244\267\244\244");
|
||||
#else
|
||||
fputc(*p++, fp); l--;
|
||||
fputc(*p++, fp); l--;
|
||||
#endif
|
||||
break;
|
||||
case OffsetAssyuku:
|
||||
fprintf(fp, "ofs%1x", (*p++ & 0x0f));
|
||||
l--;
|
||||
fprintf(fp, "%02x", *p++); l--;
|
||||
break;
|
||||
case AiAttribute:
|
||||
fprintf(fp, "\302\260%1x", (*p++ & 0x0f));
|
||||
l--;
|
||||
fprintf(fp, "%02x", *p++); l--;
|
||||
break;
|
||||
case KanjiStrEnd:
|
||||
p++; l--;
|
||||
break;
|
||||
default:
|
||||
if (p[1] & 0x80)
|
||||
fputc(SS3, fp);
|
||||
fputc((*p | 0x80), fp); l--; p++;
|
||||
fputc((*p | 0x80), fp); l--; p++;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
output_str(fp, p)
|
||||
FILE *fp;
|
||||
char *p;
|
||||
{
|
||||
while (*p) { fputc(*p, fp); p++; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
output_int(fp, p)
|
||||
FILE *fp;
|
||||
int *p;
|
||||
{
|
||||
while (*p) {
|
||||
if (*p < 0x100) {
|
||||
fputc(*p, fp); p++;
|
||||
}
|
||||
else if (*p < 0x10000) {
|
||||
fputc((*p >> 8) & 0xff, fp);
|
||||
fputc(*p & 0xff, fp); p++;
|
||||
}
|
||||
else if (*p < 0x1000000) {
|
||||
fputc((*p >> 16) & 0xff, fp);
|
||||
fputc((*p >> 8) & 0xff, fp);
|
||||
fputc(*p & 0xff, fp); p++;
|
||||
}
|
||||
else {
|
||||
fputc((*p >> 24) & 0xff, fp);
|
||||
fputc((*p >> 16) & 0xff, fp);
|
||||
fputc((*p >> 8) & 0xff, fp);
|
||||
fputc(*p & 0xff, fp); p++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
yomi2zen(code)
|
||||
int code;
|
||||
{
|
||||
static char num[] = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
|
||||
};
|
||||
|
||||
switch (code) {
|
||||
case 0x01: return 0xa1bc;
|
||||
case 0x02: return 0xa1f4;
|
||||
case 0x03: return 0xa1f7;
|
||||
case 0x04: return 0xa2a9;
|
||||
case 0xa1: return 0xa5f4;
|
||||
case 0xa2: return 0xa5f5;
|
||||
case 0xa3: return 0xa5f6;
|
||||
default: break;
|
||||
}
|
||||
|
||||
if (code < 0x10)
|
||||
;
|
||||
|
||||
else if (code < 0x1a)
|
||||
return(0xa300 + code - 0x10 + 0xb0);
|
||||
|
||||
else if (code < 0x34)
|
||||
return(0xa300 + code - 0x1a + 0xc1);
|
||||
|
||||
else if (code < 0x4e)
|
||||
return(0xa300 + code - 0x34 + 0xe1);
|
||||
|
||||
else if (code < 0xa1)
|
||||
return(0xa400 + code - 0x4e + 0xa1);
|
||||
|
||||
return ((num[(code >> 4) & 0x0f] << 8) | num[code & 0x0f]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
output_yomi(fp, p)
|
||||
FILE *fp;
|
||||
u_char *p;
|
||||
{
|
||||
int i;
|
||||
|
||||
while (*p) {
|
||||
i = yomi2zen(*p++);
|
||||
fputc((i >> 8) & 0xff, fp);
|
||||
fputc(i & 0xff, fp);
|
||||
}
|
||||
}
|
||||
118
dict/tool/cnvhinsi.c
Normal file
118
dict/tool/cnvhinsi.c
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* 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
|
||||
* 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:
|
||||
*
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* $SonyRCSfile: cnvhinsi.c,v $
|
||||
* $SonyRevision: 1.2 $
|
||||
* $SonyDate: 1996/05/27 06:59:47 $
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
|
||||
struct gram_code {
|
||||
char *name;
|
||||
int code;
|
||||
} gramtbl[] = {
|
||||
|
||||
|
||||
#include "GramTable"
|
||||
|
||||
};
|
||||
|
||||
#define GramMax (sizeof(gramtbl)/sizeof(struct gram_code) - 1)
|
||||
|
||||
int u_strcmp(a, b)
|
||||
u_char *a, *b;
|
||||
{
|
||||
if (!a || !b) return 0;
|
||||
|
||||
while (*a && *b) {
|
||||
if (*a < *b) return -1;
|
||||
if (*a > *b) return 1;
|
||||
a++;
|
||||
b++;
|
||||
}
|
||||
if (!*a && !*b) return 0;
|
||||
if (!*a) return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int cnvhinsi(buf)
|
||||
u_char *buf;
|
||||
{
|
||||
register int min;
|
||||
register int max;
|
||||
register int mid;
|
||||
register int i;
|
||||
|
||||
min = 0;
|
||||
max = GramMax;
|
||||
while (min <= max) {
|
||||
|
||||
mid = (min + max) / 2;
|
||||
|
||||
|
||||
i = u_strcmp(buf, gramtbl[mid].name);
|
||||
|
||||
|
||||
if (i < 0) {
|
||||
max = mid - 1;
|
||||
}
|
||||
|
||||
else if (i > 0) {
|
||||
min = mid + 1;
|
||||
}
|
||||
|
||||
else {
|
||||
return(gramtbl[mid].code);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *hinsi_str(code)
|
||||
int code;
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0 ; i <= GramMax ; i++) {
|
||||
if (gramtbl[i].code == code) return gramtbl[i].name;
|
||||
}
|
||||
|
||||
return "Err";
|
||||
}
|
||||
169
dict/tool/file.c
Normal file
169
dict/tool/file.c
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
/*
|
||||
* 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
|
||||
* 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:
|
||||
*
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* $SonyRCSfile: file.c,v $
|
||||
* $SonyRevision: 1.2 $
|
||||
* $SonyDate: 1995/02/03 07:38:32 $
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
char *Malloc();
|
||||
|
||||
typedef struct filelist {
|
||||
FILE *fp;
|
||||
char *fname;
|
||||
struct filelist *next;
|
||||
} FileList;
|
||||
|
||||
static FileList *flist = NULL;
|
||||
|
||||
static char *get_fname(fp)
|
||||
FILE *fp;
|
||||
{
|
||||
FileList *p;
|
||||
|
||||
for (p = flist ; p ; p = p -> next)
|
||||
if (p -> fp == fp) return p -> fname;
|
||||
return "some file";
|
||||
}
|
||||
|
||||
FILE *Fopen(filename, type)
|
||||
char *filename, *type;
|
||||
{
|
||||
FILE *fp;
|
||||
char *p;
|
||||
FileList *fl;
|
||||
|
||||
if (!(fp = fopen(filename, type))) {
|
||||
fprintf(stderr, "Can't open %s mode \"%s\"\n", filename, type);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fl = (FileList *)Malloc(sizeof(*fl));
|
||||
fl -> fname = Malloc(strlen(filename) + 1);
|
||||
strcpy(fl -> fname, filename);
|
||||
fl -> fp = fp;
|
||||
fl -> next = flist;
|
||||
|
||||
return fp;
|
||||
}
|
||||
|
||||
Fclose(fp)
|
||||
FILE *fp;
|
||||
{
|
||||
FileList *p, *q;
|
||||
|
||||
if (fclose(fp) == EOF) {
|
||||
fprintf(stderr, "Close error in %s\n", get_fname(fp));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (p = flist, q = NULL ; p ; q = p, p = p -> next) {
|
||||
if (p -> fp == fp) {
|
||||
if (q)
|
||||
q -> next = p -> next;
|
||||
else
|
||||
flist = p -> next;
|
||||
free(p -> fname);
|
||||
free(p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Fseek(fp, ofs, ptr)
|
||||
FILE *fp;
|
||||
long ofs;
|
||||
int ptr;
|
||||
{
|
||||
if (fseek(fp, ofs, ptr) == 0) return 0;
|
||||
|
||||
fprintf(stderr, "Seek error in %s\n", get_fname(fp));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
Ftell(fp)
|
||||
FILE *fp;
|
||||
{
|
||||
return ftell(fp);
|
||||
}
|
||||
|
||||
Fsize(filename)
|
||||
char *filename;
|
||||
{
|
||||
struct stat buf;
|
||||
|
||||
#if defined(__NetBSD__) || defined(__FreeBSD__)
|
||||
if (stat(filename, &buf) == 0) return (long)buf.st_size;
|
||||
#else
|
||||
if (stat(filename, &buf) == 0) return buf.st_size;
|
||||
#endif
|
||||
|
||||
fprintf(stderr, "Stat error in %s\n", filename);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
Fread(p, s, n, fp)
|
||||
char *p;
|
||||
int s, n;
|
||||
FILE *fp;
|
||||
{
|
||||
if (fread(p, s, n, fp) == n) return n;
|
||||
|
||||
fprintf(stderr, "Read error in %s\n", get_fname(fp));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
Fwrite(p, s, n, fp)
|
||||
char *p;
|
||||
int s, n;
|
||||
FILE *fp;
|
||||
{
|
||||
if (fwrite(p, s, n, fp) == n) return n;
|
||||
|
||||
fprintf(stderr, "Write error in %s\n", get_fname(fp));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
Fgetc(fp)
|
||||
FILE *fp;
|
||||
{
|
||||
return fgetc(fp);
|
||||
}
|
||||
|
||||
Fflush(fp)
|
||||
FILE *fp;
|
||||
{
|
||||
fflush(fp);
|
||||
}
|
||||
58
dict/tool/global.c
Normal file
58
dict/tool/global.c
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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
|
||||
* 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:
|
||||
*
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* $SonyRCSfile: global.c,v $
|
||||
* $SonyRevision: 1.1 $
|
||||
* $SonyDate: 1994/06/03 08:00:35 $
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include "sj_struct.h"
|
||||
|
||||
DouonRec *douon_ptr = NULL;
|
||||
int douon_num = 0;
|
||||
int yomi_len = 0;
|
||||
int hinsi_num = 0;
|
||||
int kanji_len = 0;
|
||||
|
||||
HindoRec *hindo[MaxHindoNumber];
|
||||
int hindo_num = 0;
|
||||
|
||||
OffsetRec *ofsrec[MaxOffsetNumber];
|
||||
int ofsrec_num = 0;
|
||||
|
||||
AssyukuRec *assyuku = NULL;
|
||||
|
||||
HindoRec *askknj[MaxKnjAskNumber];
|
||||
int askknj_num = 0;
|
||||
|
||||
int kanji_num = 0;
|
||||
643
dict/tool/hindo.c
Normal file
643
dict/tool/hindo.c
Normal file
|
|
@ -0,0 +1,643 @@
|
|||
/*
|
||||
* 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
|
||||
* 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:
|
||||
*
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* $SonyRCSfile: hindo.c,v $
|
||||
* $SonyRevision: 1.2 $
|
||||
* $SonyDate: 1994/08/17 01:50:26 $
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include "sj_struct.h"
|
||||
|
||||
extern HindoRec *hindo[];
|
||||
extern int hindo_num;
|
||||
extern AssyukuRec *assyuku;
|
||||
extern HindoRec *askknj[];
|
||||
extern int askknj_num;
|
||||
extern int kanji_num;
|
||||
|
||||
OffsetRec *real_ofsrec();
|
||||
|
||||
|
||||
|
||||
check_hindo(ptr, len)
|
||||
u_char *ptr;
|
||||
int len;
|
||||
{
|
||||
int low, high, mid;
|
||||
int i;
|
||||
|
||||
|
||||
if (hindo_num <= 0) return 0;
|
||||
|
||||
|
||||
low = 0; high = hindo_num - 1;
|
||||
while (low <= high) {
|
||||
mid = (low + high) / 2;
|
||||
i = string_cmp(hindo[mid]->kptr, hindo[mid]->klen, ptr, len);
|
||||
if (i > 0)
|
||||
high = mid - 1;
|
||||
else if (i < 0)
|
||||
low = ++mid;
|
||||
else
|
||||
return(hindo[mid]->exist + hindo[mid]->hindo);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static AssyukuRec *makeassyuku(num)
|
||||
int num;
|
||||
{
|
||||
AssyukuRec *arec;
|
||||
|
||||
|
||||
arec = (AssyukuRec *)Malloc(sizeof(AssyukuRec));
|
||||
if (!arec) {
|
||||
fprintf(stderr, "\245\341\245\342\245\352\244\254\302\255\244\352\244\336\244\273\244\363\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
arec -> len = num;
|
||||
arec -> nrec = NULL;
|
||||
arec -> anext = NULL;
|
||||
|
||||
return arec;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static assyuku_len(hrec)
|
||||
HindoRec *hrec;
|
||||
{
|
||||
int org;
|
||||
int old;
|
||||
int new;
|
||||
OffsetRec *p;
|
||||
|
||||
|
||||
if (((*(hrec->kptr) & KanjiModeMask) == OffsetAssyuku) &&
|
||||
(hrec->klen == 2)) {
|
||||
|
||||
p = real_ofsrec(hrec -> kptr);
|
||||
|
||||
|
||||
org = check_hindo(p -> kptr, p -> klen);
|
||||
|
||||
|
||||
|
||||
old = p->klen * org + 2 * (hrec->exist + hrec->hindo);
|
||||
|
||||
|
||||
|
||||
new = p->klen + (hrec->exist + hrec->hindo + org);
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
old = hrec -> klen * (hrec -> exist + hrec -> hindo);
|
||||
|
||||
|
||||
new = hrec -> klen + (hrec -> exist + hrec -> hindo);
|
||||
}
|
||||
|
||||
|
||||
return (old - new);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void set_assyuku(hrec)
|
||||
HindoRec *hrec;
|
||||
{
|
||||
register AssyukuRec *arec;
|
||||
register AssyukuRec *aprev;
|
||||
register int len;
|
||||
|
||||
|
||||
len = assyuku_len(hrec);
|
||||
|
||||
|
||||
if (len <= 0) return;
|
||||
|
||||
|
||||
arec = assyuku; aprev = NULL;
|
||||
while (arec) {
|
||||
|
||||
if (arec -> len == len) {
|
||||
|
||||
hrec -> arec = arec;
|
||||
hrec -> anext = arec -> nrec;
|
||||
arec -> nrec = hrec;
|
||||
return;
|
||||
}
|
||||
|
||||
else if (arec -> len < len)
|
||||
break;
|
||||
|
||||
aprev = arec;
|
||||
arec = arec -> anext;
|
||||
}
|
||||
|
||||
|
||||
arec = makeassyuku(len);
|
||||
|
||||
|
||||
hrec -> anext = NULL;
|
||||
hrec -> arec = arec;
|
||||
arec -> nrec = hrec;
|
||||
|
||||
|
||||
if (aprev) {
|
||||
arec -> anext = aprev -> anext;
|
||||
aprev -> anext = arec;
|
||||
}
|
||||
else {
|
||||
arec -> anext = assyuku;
|
||||
assyuku = arec;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void reset_assyuku(hrec)
|
||||
HindoRec *hrec;
|
||||
{
|
||||
AssyukuRec *arec;
|
||||
AssyukuRec *aptr;
|
||||
AssyukuRec *aprev;
|
||||
HindoRec *hptr;
|
||||
HindoRec *hprev;
|
||||
|
||||
arec = hrec -> arec;
|
||||
|
||||
|
||||
if (!arec) return;
|
||||
hrec -> arec = NULL;
|
||||
|
||||
|
||||
hptr = arec -> nrec; hprev = NULL;
|
||||
while (hptr) {
|
||||
if (hptr == hrec) break;
|
||||
hprev = hptr;
|
||||
hptr = hptr -> anext;
|
||||
}
|
||||
|
||||
|
||||
if (!hptr) return;
|
||||
|
||||
|
||||
if (hprev) {
|
||||
hprev -> anext = hrec -> anext;
|
||||
hrec -> anext = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (hrec -> anext) {
|
||||
arec -> nrec = hrec -> anext;
|
||||
hrec -> anext = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (!assyuku) return;
|
||||
aptr = assyuku; aprev = NULL;
|
||||
while (aptr) {
|
||||
if (aptr == arec) break;
|
||||
aprev = aptr;
|
||||
aptr = aptr -> anext;
|
||||
}
|
||||
|
||||
|
||||
if (!aptr) return;
|
||||
|
||||
|
||||
if (aprev)
|
||||
aprev -> anext = arec -> anext;
|
||||
|
||||
else
|
||||
assyuku = arec -> anext;
|
||||
|
||||
|
||||
Free(arec);
|
||||
|
||||
|
||||
hrec -> anext = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static HindoRec *makehindo(ptr, len, alen)
|
||||
u_char *ptr;
|
||||
int len;
|
||||
int alen;
|
||||
{
|
||||
HindoRec *hrec;
|
||||
u_char *p;
|
||||
|
||||
|
||||
hrec = (HindoRec *)Malloc(sizeof(HindoRec));
|
||||
if (!hrec) {
|
||||
fprintf(stderr, "\245\341\245\342\245\352\244\254\302\255\244\352\244\336\244\273\244\363\n");
|
||||
exit(1);
|
||||
}
|
||||
p = (u_char *)Malloc(len);
|
||||
if (!p) {
|
||||
fprintf(stderr, "\245\341\245\342\245\352\244\254\302\255\244\352\244\336\244\273\244\363\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
hrec -> klen = len;
|
||||
hrec -> kptr = p;
|
||||
if (len == alen && len > 2) {
|
||||
hrec -> hindo = 0;
|
||||
hrec -> exist = 1;
|
||||
hrec -> offset = ++kanji_num;
|
||||
}
|
||||
else {
|
||||
hrec -> hindo = 1;
|
||||
hrec -> exist = 0;
|
||||
hrec -> offset = 0;
|
||||
}
|
||||
while (len-- > 0) *p++ = *ptr++;
|
||||
hrec -> anext = NULL;
|
||||
hrec -> arec = NULL;
|
||||
|
||||
return hrec;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void set_hindo(ptr, len, alen)
|
||||
u_char *ptr;
|
||||
int len;
|
||||
int alen;
|
||||
{
|
||||
HindoRec *hrec;
|
||||
int low, high, mid;
|
||||
int i;
|
||||
|
||||
|
||||
if (hindo_num <= 0) {
|
||||
hrec = makehindo(ptr, len, alen);
|
||||
hindo[0]= hrec;
|
||||
hindo_num = 1;
|
||||
|
||||
|
||||
set_assyuku(hrec);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
low = 0; high = hindo_num - 1;
|
||||
while (low <= high) {
|
||||
mid = (low + high) / 2;
|
||||
i = string_cmp(hindo[mid]->kptr, hindo[mid]->klen, ptr, len);
|
||||
if (i > 0)
|
||||
high = mid - 1;
|
||||
else if (i < 0)
|
||||
low = ++mid;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (i) {
|
||||
if (hindo_num >= MaxHindoNumber) {
|
||||
fprintf(stderr, "\311\321\305\331\245\306\241\274\245\326\245\353\244\254\244\242\244\325\244\354\244\336\244\267\244\277\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
hrec = makehindo(ptr, len, alen);
|
||||
|
||||
|
||||
for (i = hindo_num ; i > mid ; i--) hindo[i] = hindo[i - 1];
|
||||
hindo[mid] = hrec;
|
||||
hindo_num++;
|
||||
}
|
||||
|
||||
else {
|
||||
hrec = hindo[mid];
|
||||
|
||||
|
||||
reset_assyuku(hrec);
|
||||
|
||||
|
||||
if (hrec -> exist > 0)
|
||||
hrec -> exist += 1;
|
||||
|
||||
|
||||
else if (len == alen && len > 2) {
|
||||
hrec -> exist = 1;
|
||||
hrec -> offset = ++kanji_num;
|
||||
}
|
||||
|
||||
|
||||
else
|
||||
hrec -> hindo += 1;
|
||||
}
|
||||
|
||||
|
||||
set_assyuku(hrec);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void reset_hindo(p, l)
|
||||
u_char *p;
|
||||
int l;
|
||||
{
|
||||
HindoRec *hrec;
|
||||
int low, high, mid;
|
||||
int i;
|
||||
|
||||
|
||||
if (hindo_num <= 0) return;
|
||||
|
||||
|
||||
low = 0; high = hindo_num - 1;
|
||||
while (low <= high) {
|
||||
mid = (low + high) / 2;
|
||||
i = string_cmp(hindo[mid]->kptr, hindo[mid]->klen, p, l);
|
||||
if (i > 0)
|
||||
high = mid - 1;
|
||||
else if (i < 0)
|
||||
low = ++mid;
|
||||
|
||||
else {
|
||||
hrec = hindo[mid];
|
||||
|
||||
|
||||
reset_assyuku(hrec);
|
||||
|
||||
if (hrec -> exist > 0)
|
||||
hrec -> exist -= 1;
|
||||
else if (hrec -> hindo > 0)
|
||||
hrec -> hindo -= 1;
|
||||
|
||||
|
||||
if (hrec -> exist + hrec -> hindo == 0) {
|
||||
while (++mid < hindo_num) {
|
||||
hindo[mid - 1] = hindo[mid];
|
||||
}
|
||||
hindo_num--;
|
||||
Free(hrec -> kptr);
|
||||
Free(hrec);
|
||||
}
|
||||
else {
|
||||
|
||||
set_assyuku(hrec);
|
||||
}
|
||||
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
knjhnd_set(p, l)
|
||||
u_char *p;
|
||||
int l;
|
||||
{
|
||||
register u_char *kp1;
|
||||
register u_char *kp2;
|
||||
register int i;
|
||||
register int kl1;
|
||||
u_char tmp[MaxKanjiLength * 2 + MaxAtrNumber * 2 + 1];
|
||||
|
||||
for (kp1 = p, kl1 = l ; kl1 > 0 ; ) {
|
||||
|
||||
|
||||
for (i = 0, kp2 = kp1 ; i < kl1 ; ) {
|
||||
if (codesize(*kp2) == 1) {
|
||||
tmp[i++] = *kp2++;
|
||||
}
|
||||
else if (codesize(*kp2) == 2) {
|
||||
tmp[i++] = *kp2++;
|
||||
tmp[i++] = *kp2++;
|
||||
} else {
|
||||
tmp[i++] = *kp2++;
|
||||
tmp[i++] = *kp2++;
|
||||
tmp[i++] = *kp2++;
|
||||
}
|
||||
set_hindo(tmp, i, l);
|
||||
}
|
||||
|
||||
|
||||
kl1 -= codesize(*kp1);
|
||||
kp1 += codesize(*kp1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
knjhnd_reset(p, l)
|
||||
u_char *p;
|
||||
int l;
|
||||
{
|
||||
register u_char *kp1;
|
||||
register u_char *kp2;
|
||||
register int i;
|
||||
register int kl1;
|
||||
u_char tmp[MaxKanjiLength * 2 + MaxAtrNumber * 2 + 1];
|
||||
|
||||
for (kp1 = p, kl1 = l ; kl1 > 0 ; ) {
|
||||
|
||||
|
||||
for (i = 0, kp2 = kp1 ; i < kl1 ; ) {
|
||||
if (codesize(*kp2) == 1) {
|
||||
tmp[i++] = *kp2++;
|
||||
}
|
||||
else if (codesize(*kp2) == 2) {
|
||||
tmp[i++] = *kp2++;
|
||||
tmp[i++] = *kp2++;
|
||||
} else {
|
||||
tmp[i++] = *kp2++;
|
||||
tmp[i++] = *kp2++;
|
||||
tmp[i++] = *kp2++;
|
||||
}
|
||||
reset_hindo(tmp, i);
|
||||
}
|
||||
|
||||
|
||||
kl1 -= codesize(*kp1);
|
||||
kp1 += codesize(*kp1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static check_assyuku(p, q)
|
||||
register HindoRec *p;
|
||||
register HindoRec *q;
|
||||
{
|
||||
u_char ptmp[128], qtmp[128];
|
||||
int plen;
|
||||
int qlen;
|
||||
|
||||
|
||||
plen = make_knjstr(p -> kptr, p -> klen, ptmp);
|
||||
|
||||
|
||||
qlen = make_knjstr(q -> kptr, q -> klen, qtmp);
|
||||
|
||||
|
||||
if (bubun_str(ptmp, plen, qtmp, qlen)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (overlap_str(ptmp, plen, qtmp, qlen))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
decide_knjask()
|
||||
{
|
||||
int i, j;
|
||||
AssyukuRec *p;
|
||||
HindoRec *q;
|
||||
u_char *r;
|
||||
int len = 0;
|
||||
|
||||
askknj_num = 0;
|
||||
|
||||
|
||||
for (p = assyuku ; p ; p = p -> anext) {
|
||||
|
||||
|
||||
if (p -> len <= 0) break;
|
||||
|
||||
|
||||
for (q = p -> nrec ; q ; q = q -> anext) {
|
||||
|
||||
|
||||
i = q -> klen;
|
||||
r = q -> kptr;
|
||||
if (i > 2) {
|
||||
while (i > 0) {
|
||||
if ((*r & KanjiModeMask)
|
||||
== OffsetAssyuku) {
|
||||
break;
|
||||
}
|
||||
j = codesize(*r);
|
||||
i -= j;
|
||||
r += j;
|
||||
}
|
||||
if (i) continue;
|
||||
}
|
||||
|
||||
if (askknj_num) {
|
||||
|
||||
for (i = 0 ; i < askknj_num ; i++) {
|
||||
if (check_assyuku(askknj[i], q))
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (i >= askknj_num) {
|
||||
askknj[askknj_num++] = q;
|
||||
len += p -> len;
|
||||
if (askknj_num >= MaxKnjAskNumber)
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
else {
|
||||
askknj[askknj_num++] = q;
|
||||
len += p -> len;
|
||||
}
|
||||
}
|
||||
}
|
||||
end:
|
||||
{
|
||||
int i, j, len;
|
||||
u_char *p;
|
||||
|
||||
for (i = 0 ; i < askknj_num ; i++) {
|
||||
len = askknj[i] -> klen;
|
||||
p = askknj[i] -> kptr;
|
||||
if (len <= 2) continue;
|
||||
while (len > 0) {
|
||||
if ((*p & KanjiModeMask) == OffsetAssyuku) {
|
||||
printf("\245\252\245\325\245\273\245\303\245\310\260\265\275\314\244\362\264\336\244\340 %d\n", i);
|
||||
}
|
||||
j = codesize(*p);
|
||||
len -= j;
|
||||
p += j;
|
||||
}
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
|
||||
clear_hindo()
|
||||
{
|
||||
register int i;
|
||||
|
||||
for (i = 0 ; i < hindo_num ; i++) {
|
||||
Free(hindo[i]->kptr);
|
||||
Free(hindo[i]);
|
||||
}
|
||||
hindo_num = 0;
|
||||
kanji_num = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
clear_assyuku()
|
||||
{
|
||||
register AssyukuRec *p;
|
||||
|
||||
while (assyuku) {
|
||||
p = assyuku;
|
||||
assyuku = assyuku -> anext;
|
||||
Free(p);
|
||||
}
|
||||
}
|
||||
276
dict/tool/knjcvt.c
Normal file
276
dict/tool/knjcvt.c
Normal file
|
|
@ -0,0 +1,276 @@
|
|||
/*
|
||||
* 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
|
||||
* 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:
|
||||
*
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* $SonyRCSfile: knjcvt.c,v $
|
||||
* $SonyRevision: 1.1 $
|
||||
* $SonyDate: 1994/06/03 08:00:37 $
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include "sj_const.h"
|
||||
#include "sj_struct.h"
|
||||
|
||||
typedef struct div_list {
|
||||
int len;
|
||||
u_char code[3];
|
||||
struct div_list *child;
|
||||
} DivList;
|
||||
|
||||
extern HindoRec *askknj[];
|
||||
extern int askknj_num;
|
||||
|
||||
|
||||
|
||||
static free_divlist(p)
|
||||
register DivList *p;
|
||||
{
|
||||
register DivList *q;
|
||||
|
||||
while (p) {
|
||||
q = p -> child;
|
||||
Free(p);
|
||||
p = q;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static DivList *make_divrec()
|
||||
{
|
||||
register DivList *p;
|
||||
|
||||
p = (DivList *)Malloc(sizeof(DivList));
|
||||
if (!p) {
|
||||
fprintf(stderr, "\245\341\245\342\245\352\244\254\302\255\244\352\244\336\244\273\244\363\n");
|
||||
exit(1);
|
||||
}
|
||||
p -> child = NULL;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static make_divlist(parent, knj, len)
|
||||
DivList *parent;
|
||||
u_char *knj;
|
||||
int len;
|
||||
{
|
||||
int i, j;
|
||||
int num;
|
||||
int minlen;
|
||||
int tmplen;
|
||||
DivList tmprec;
|
||||
DivList *minrec;
|
||||
|
||||
|
||||
minrec = make_divrec();
|
||||
|
||||
|
||||
if (len == 0) {
|
||||
free_divlist(minrec);
|
||||
|
||||
parent -> child = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
else if (len == 1) {
|
||||
|
||||
minrec -> len = len;
|
||||
minrec -> code[0] = *knj;
|
||||
|
||||
parent -> child = minrec;
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
if (codesize(*knj) == 1) {
|
||||
minrec -> len = 1;
|
||||
minrec -> code[0] = *knj;
|
||||
minlen = make_divlist(minrec, knj + 1, len - 1) + 1;
|
||||
}
|
||||
|
||||
else if (codesize(*knj) == 2) {
|
||||
minrec -> len = 2;
|
||||
minrec -> code[0] = *knj;
|
||||
minrec -> code[1] = *(knj + 1);
|
||||
minlen = make_divlist(minrec, knj + 2, len - 2) + 2;
|
||||
}
|
||||
|
||||
|
||||
for (i = 0 ; i < len ; i = j) {
|
||||
|
||||
j = i + codesize(*(knj + i));
|
||||
|
||||
|
||||
if (j <= 2 || !(num = isknjexist(knj, j))) continue;
|
||||
|
||||
|
||||
tmprec.len = 2;
|
||||
tmprec.code[0] = (OffsetAssyuku | ((num >> 8) & 0xff));
|
||||
tmprec.code[1] = (num & 0xff);
|
||||
tmprec.child = NULL;
|
||||
tmplen = make_divlist(&tmprec, knj + j, len - j) + 2;
|
||||
|
||||
|
||||
if (tmplen < minlen) {
|
||||
|
||||
free_divlist(minrec -> child);
|
||||
|
||||
|
||||
*minrec = tmprec;
|
||||
minlen = tmplen;
|
||||
}
|
||||
else
|
||||
free_divlist(tmprec.child);
|
||||
}
|
||||
|
||||
|
||||
for (i = 0 ; i < askknj_num ; i++) {
|
||||
|
||||
if ((j = askknj[i] -> klen) > len) continue;
|
||||
|
||||
|
||||
if (string_cmp(askknj[i]->kptr, j, knj, j)) continue;
|
||||
|
||||
|
||||
tmprec.len = 1;
|
||||
tmprec.code[0] = (KanjiAssyuku | i);
|
||||
tmprec.child = NULL;
|
||||
tmplen = make_divlist(&tmprec, knj + j, len - j) + 1;
|
||||
|
||||
|
||||
if (tmplen < minlen) {
|
||||
|
||||
free_divlist(minrec -> child);
|
||||
|
||||
|
||||
*minrec = tmprec;
|
||||
minlen = tmplen;
|
||||
}
|
||||
else
|
||||
free_divlist(tmprec.child);
|
||||
}
|
||||
|
||||
|
||||
parent -> child = minrec;
|
||||
|
||||
|
||||
return minlen;
|
||||
}
|
||||
|
||||
|
||||
|
||||
u_char *knjofscvt(ptr, len, ret)
|
||||
u_char *ptr;
|
||||
int len;
|
||||
int *ret;
|
||||
{
|
||||
int i;
|
||||
u_char *p, *q;
|
||||
DivList parent, *dl;
|
||||
|
||||
|
||||
askknj_num = 0;
|
||||
|
||||
|
||||
parent.child = NULL;
|
||||
i = make_divlist(&parent, ptr, len);
|
||||
*ret = i;
|
||||
|
||||
|
||||
p = (u_char *)Malloc(i);
|
||||
if (!p) {
|
||||
fprintf(stderr, "\245\341\245\342\245\352\244\254\311\324\302\255\244\267\244\336\244\267\244\277");
|
||||
exit(1);
|
||||
}
|
||||
for (q = p, dl = parent.child ; dl ; dl = dl -> child) {
|
||||
*q++ = dl -> code[0];
|
||||
if (dl -> len == 2) {
|
||||
*q++ = dl -> code[1];
|
||||
} else if (dl -> len == 3) {
|
||||
*q++ = dl -> code[1];
|
||||
*q++ = dl -> code[2];
|
||||
}
|
||||
}
|
||||
|
||||
free_divlist(parent.child);
|
||||
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
|
||||
u_char *knjcvt(ptr, len, ret)
|
||||
u_char *ptr;
|
||||
int len;
|
||||
int *ret;
|
||||
{
|
||||
int i;
|
||||
u_char *p, *q;
|
||||
DivList parent, *dl;
|
||||
|
||||
|
||||
parent.child = NULL;
|
||||
i = make_divlist(&parent, ptr, len);
|
||||
*ret = i;
|
||||
|
||||
|
||||
p = (u_char *)Malloc(i);
|
||||
if (!p) {
|
||||
fprintf(stderr, "\245\341\245\342\245\352\244\254\311\324\302\255\244\267\244\336\244\267\244\277");
|
||||
exit(1);
|
||||
}
|
||||
for (q = p, dl = parent.child ; dl ; dl = dl -> child) {
|
||||
*q++ = dl -> code[0];
|
||||
if (dl -> len == 2) {
|
||||
*q++ = dl -> code[1];
|
||||
} else if (dl -> len == 3) {
|
||||
*q++ = dl -> code[1];
|
||||
*q++ = dl -> code[2];
|
||||
}
|
||||
}
|
||||
|
||||
free_divlist(parent.child);
|
||||
|
||||
if (i != q - p) {
|
||||
printf("\244\263\244\263\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
241
dict/tool/makedict.c
Normal file
241
dict/tool/makedict.c
Normal file
|
|
@ -0,0 +1,241 @@
|
|||
/*
|
||||
* 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
|
||||
* 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:
|
||||
*
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* $SonyRCSfile: makedict.c,v $
|
||||
* $SonyRevision: 1.2 $
|
||||
* $SonyDate: 1994/12/09 11:27:05 $
|
||||
*/
|
||||
|
||||
|
||||
#include "sj_sysvdef.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <locale.h>
|
||||
#ifdef SVR4
|
||||
#include <string.h>
|
||||
#else
|
||||
#include <strings.h>
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/param.h>
|
||||
#include "sj_const.h"
|
||||
|
||||
FILE *infp = NULL;
|
||||
FILE *outfp = NULL;
|
||||
|
||||
char *Zalloc();
|
||||
FILE *Fopen();
|
||||
|
||||
static char *idxtop = NULL;
|
||||
|
||||
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int makelist();
|
||||
|
||||
|
||||
|
||||
|
||||
parse(argc, argv);
|
||||
|
||||
while (readline()) setline(makelist);
|
||||
flush_douon();
|
||||
makehead((u_char *)argv[2]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *make_idxlist(name)
|
||||
char *name;
|
||||
{
|
||||
int i;
|
||||
char *p;
|
||||
|
||||
i = strlen(name);
|
||||
p = Zalloc(i + 2);
|
||||
strcpy(p, name);
|
||||
return p;
|
||||
}
|
||||
char *get_idxlist(name)
|
||||
char *name;
|
||||
{
|
||||
FILE *fp;
|
||||
int i;
|
||||
char *p, *q, *r;
|
||||
|
||||
|
||||
fp = Fopen(name, "r");
|
||||
|
||||
|
||||
i = Fsize(name);
|
||||
|
||||
|
||||
p = Zalloc(i + 2);
|
||||
Fseek(fp, 0L, 0);
|
||||
Fread(p, 1, i, fp);
|
||||
Fclose(fp);
|
||||
|
||||
|
||||
for (q = r = p ; *q ; ) {
|
||||
while (*q <= ' ') q++;
|
||||
while (*q > ' ') *r++ = *q++;
|
||||
*r++ = 0;
|
||||
q++;
|
||||
}
|
||||
*r = 0;
|
||||
|
||||
|
||||
i = 0;
|
||||
for (q = p ; *q ; ) {
|
||||
if (fp = fopen(q, "r"))
|
||||
fclose(fp);
|
||||
else {
|
||||
fprintf(stderr, "Can't open %s mode \"r\"\n", q);
|
||||
i++;
|
||||
}
|
||||
while (*q++) ;
|
||||
}
|
||||
if (i) exit(1);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
|
||||
parse(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int i;
|
||||
char *progname = NULL;
|
||||
char *p;
|
||||
extern char *strrchr();
|
||||
|
||||
|
||||
if (progname = strrchr(argv[0], '/'))
|
||||
progname++;
|
||||
else
|
||||
progname = argv[0];
|
||||
|
||||
|
||||
if (argc != 3) usage(progname);
|
||||
|
||||
|
||||
p = argv[1];
|
||||
idxtop = (*p == '-') ? get_idxlist(p + 1) : make_idxlist(p);
|
||||
|
||||
outfp = Fopen(argv[2], "w");
|
||||
}
|
||||
|
||||
|
||||
|
||||
get_number(ptr)
|
||||
register char *ptr;
|
||||
{
|
||||
register int i = 0;
|
||||
|
||||
while (*ptr >= '0' && *ptr <= '9') {
|
||||
i = i * 10 + (*ptr++ - '0');
|
||||
}
|
||||
|
||||
return(i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
usage(name)
|
||||
char *name;
|
||||
{
|
||||
fprintf(stderr, "Usage: %s text_file binary_file\n",
|
||||
name ? name : "encode");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int getch()
|
||||
{
|
||||
if (infp) {
|
||||
int c;
|
||||
|
||||
if ((c = Fgetc(infp)) != EOF) return c;
|
||||
|
||||
Fclose(infp);
|
||||
infp = NULL;
|
||||
|
||||
while (*idxtop++) ;
|
||||
}
|
||||
|
||||
if (*idxtop) {
|
||||
infp = Fopen(idxtop, "r");
|
||||
|
||||
fprintf(stderr, "Reading %s\n", idxtop);
|
||||
fflush(stderr);
|
||||
|
||||
return getch();
|
||||
}
|
||||
|
||||
return EOF;
|
||||
}
|
||||
|
||||
|
||||
|
||||
mark_file(out)
|
||||
FILE *out;
|
||||
{
|
||||
static char pathname[MAXPATHLEN];
|
||||
static long pos;
|
||||
|
||||
if (out) {
|
||||
FILE *fp;
|
||||
int c;
|
||||
|
||||
fprintf(out, "%s:\t", pathname);
|
||||
fp = Fopen(pathname, "r");
|
||||
Fseek(fp, pos, 0);
|
||||
c = Fgetc(fp);
|
||||
while (c != EOF && c != '\n') {
|
||||
fputc(c, out);
|
||||
c = Fgetc(fp);
|
||||
}
|
||||
fputc('\n', out);
|
||||
Fclose(fp);
|
||||
}
|
||||
else {
|
||||
strcpy(pathname, idxtop);
|
||||
pos = infp ? Ftell(infp) : 0;
|
||||
}
|
||||
}
|
||||
648
dict/tool/makelist.c
Normal file
648
dict/tool/makelist.c
Normal file
|
|
@ -0,0 +1,648 @@
|
|||
/*
|
||||
* 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
|
||||
* 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:
|
||||
*
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* $SonyRCSfile: makelist.c,v $
|
||||
* $SonyRevision: 1.1 $
|
||||
* $SonyDate: 1994/06/03 08:00:39 $
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include "sj_struct.h"
|
||||
|
||||
#ifndef SS2
|
||||
#define SS2 0x8e
|
||||
#endif
|
||||
|
||||
extern DouonRec *douon_ptr;
|
||||
extern int douon_num;
|
||||
extern int yomi_len;
|
||||
extern int hinsi_num;
|
||||
extern int kanji_len;
|
||||
extern HindoRec *hindo[];
|
||||
extern int hindo_num;
|
||||
extern HindoRec *askknj[];
|
||||
extern int askknj_num;
|
||||
extern HindoRec *assyuku;
|
||||
|
||||
static DouonRec *drectmp = NULL;
|
||||
|
||||
|
||||
|
||||
static clearklist(krec)
|
||||
register KanjiRec *krec;
|
||||
{
|
||||
register KanjiRec *p;
|
||||
|
||||
|
||||
while (krec) {
|
||||
|
||||
Free(krec -> kptr);
|
||||
Free(krec -> aptr);
|
||||
|
||||
|
||||
p = krec;
|
||||
krec = krec -> knext;
|
||||
|
||||
|
||||
Free(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static clearhlist(hrec)
|
||||
register HinsiRec *hrec;
|
||||
{
|
||||
register HinsiRec *p;
|
||||
|
||||
|
||||
while (hrec) {
|
||||
|
||||
clearklist(hrec -> krec);
|
||||
|
||||
|
||||
p = hrec;
|
||||
hrec = hrec -> hnext;
|
||||
|
||||
|
||||
Free(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
clear_list()
|
||||
{
|
||||
register DouonRec *p;
|
||||
register DouonRec *drec = douon_ptr;
|
||||
|
||||
|
||||
while (drec) {
|
||||
|
||||
Free(drec -> yptr);
|
||||
|
||||
|
||||
clearhlist(drec -> hrec);
|
||||
|
||||
|
||||
p = drec;
|
||||
drec = drec -> dnext;
|
||||
|
||||
|
||||
Free(p);
|
||||
}
|
||||
|
||||
douon_ptr = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static u_char *makekanji(yomi, kanji, atr, len)
|
||||
int *yomi;
|
||||
int *kanji;
|
||||
int *atr;
|
||||
int *len;
|
||||
{
|
||||
int kana[MaxYomiLength + 1];
|
||||
u_char ktmp[MaxKanjiLength * 3 + MaxAtrNumber * 2 + 1];
|
||||
register int i;
|
||||
register int pos = 0;
|
||||
int *p;
|
||||
u_char *q;
|
||||
|
||||
|
||||
for (p = yomi, i = 0 ; *p ; )
|
||||
kana[i++] = h2kcode(*p++);
|
||||
kana[i] = 0;
|
||||
|
||||
while (*atr) {
|
||||
i = *atr;
|
||||
atr++;
|
||||
#ifndef NO_ATR
|
||||
ktmp[pos++] = (AiAttribute | ((i >> 8) & 0xff));
|
||||
ktmp[pos++] = (i & 0xff);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
if (i = top_strcmp(yomi, kanji)) {
|
||||
kanji += i;
|
||||
ktmp[pos++] = (ZenHiraAssyuku | (i - 1));
|
||||
}
|
||||
|
||||
else if (i = top_strcmp(kana, kanji)) {
|
||||
kanji += i;
|
||||
ktmp[pos++] = (ZenKataAssyuku | (i - 1));
|
||||
}
|
||||
|
||||
|
||||
while (*kanji) {
|
||||
|
||||
if (i = last_strcmp(yomi, kanji)) {
|
||||
kanji += i;
|
||||
ktmp[pos++] = (ZenHiraAssyuku | (i - 1));
|
||||
}
|
||||
|
||||
else if (i = last_strcmp(kana, kanji)) {
|
||||
kanji += i;
|
||||
ktmp[pos++] = (ZenKataAssyuku | (i - 1));
|
||||
}
|
||||
|
||||
else if (((*kanji >> 8) & 0xff) == SS2 || *kanji < 0x100) {
|
||||
ktmp[pos] = LeadingHankaku;
|
||||
ktmp[pos + 1] = (*kanji & 0xff);
|
||||
kanji++;
|
||||
pos += 2;
|
||||
}
|
||||
|
||||
else {
|
||||
if (*kanji < 0x10000) {
|
||||
ktmp[pos] = ((*kanji >> 8) & NormalKanjiMask);
|
||||
ktmp[pos + 1] = (*kanji & NormalKanjiMask);
|
||||
kanji++;
|
||||
pos += 2;
|
||||
} else if (*kanji < 0x1000000) {
|
||||
ktmp[pos] = ((*kanji >> 8) & NormalKanjiMask);
|
||||
ktmp[pos + 1] = (*kanji & 0xff);
|
||||
kanji++;
|
||||
pos += 2;
|
||||
} else {
|
||||
fprintf(stderr, "Error: 4 byte code is found\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
*len = pos;
|
||||
|
||||
|
||||
q = (u_char *)Malloc(pos);
|
||||
if (!q) {
|
||||
fprintf(stderr, "\245\341\245\342\245\352\244\254\311\324\302\255\244\267\244\336\244\267\244\277");
|
||||
exit(1);
|
||||
}
|
||||
memcpy(q, ktmp, pos);
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static u_char *makeyomi(yomi)
|
||||
int *yomi;
|
||||
{
|
||||
u_char tmp[MaxYomiLength + 1];
|
||||
register int i;
|
||||
register int j;
|
||||
register int *y = yomi;
|
||||
register u_char *p;
|
||||
|
||||
|
||||
for (i = 0 ; *y ; ) {
|
||||
j = cnvyomi(*y++);
|
||||
if (j == 0) {
|
||||
fprintf(stderr, "\311\324\300\265\244\312\312\270\273\372\244\254\306\311\244\337\244\313\273\310\244\357\244\354\244\306\244\244\244\336\244\271\n");
|
||||
output_int(stderr, yomi); fputc('\n', stderr);
|
||||
exit(1);
|
||||
}
|
||||
tmp[i++] = j;
|
||||
}
|
||||
tmp[i++] = 0;
|
||||
|
||||
|
||||
p = (u_char *)Malloc(i);
|
||||
if (!p) {
|
||||
fprintf(stderr, "\245\341\245\342\245\352\244\254\311\324\302\255\244\267\244\336\244\267\244\277");
|
||||
exit(1);
|
||||
}
|
||||
memcpy(p, tmp, i);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static KanjiRec *make_krec(kcode, klen)
|
||||
u_char *kcode;
|
||||
int klen;
|
||||
{
|
||||
register KanjiRec *krec;
|
||||
|
||||
|
||||
krec = (KanjiRec *)Malloc(sizeof(KanjiRec));
|
||||
if (!krec) {
|
||||
fprintf(stderr, "\245\341\245\342\245\352\244\254\311\324\302\255\244\267\244\336\244\267\244\277");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
krec -> klen = klen;
|
||||
krec -> kptr = kcode;
|
||||
krec -> alen = 0;
|
||||
krec -> aptr = NULL;
|
||||
krec -> knext = NULL;
|
||||
|
||||
return krec;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static HinsiRec *make_hrec(hinsi)
|
||||
int hinsi;
|
||||
{
|
||||
register HinsiRec *hrec;
|
||||
|
||||
|
||||
hrec = (HinsiRec *)Malloc(sizeof(HinsiRec));
|
||||
if (!hrec) {
|
||||
fprintf(stderr, "\245\341\245\342\245\352\244\254\311\324\302\255\244\267\244\336\244\267\244\277");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
hrec -> hinsi = hinsi;
|
||||
hrec -> krec = NULL;
|
||||
hrec -> hnext = NULL;
|
||||
|
||||
return hrec;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static DouonRec *make_drec(ycode)
|
||||
u_char *ycode;
|
||||
{
|
||||
register DouonRec *drec;
|
||||
|
||||
|
||||
drec = (DouonRec *)Malloc(sizeof(DouonRec));
|
||||
if (!drec) {
|
||||
fprintf(stderr, "\245\341\245\342\245\352\244\254\311\324\302\255\244\267\244\336\244\267\244\277");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
drec -> yptr = ycode;
|
||||
drec -> hrec_num = 0;
|
||||
drec -> hrec = NULL;
|
||||
drec -> dnext = NULL;
|
||||
|
||||
return drec;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static diff_ylen(drec)
|
||||
DouonRec *drec;
|
||||
{
|
||||
register DouonRec *dptr;
|
||||
register DouonRec *dprev;
|
||||
register u_char *p1;
|
||||
register u_char *p2;
|
||||
register int ylen = 0;
|
||||
|
||||
|
||||
dptr = douon_ptr; dprev = NULL;
|
||||
while (dptr) {
|
||||
dprev = dptr;
|
||||
dptr = dptr -> dnext;
|
||||
}
|
||||
|
||||
if (dprev) {
|
||||
|
||||
p1 = dprev -> yptr; p2 = drec -> yptr;
|
||||
while (*p1 && (*p1 == *p2)) { p1++; p2++; }
|
||||
|
||||
|
||||
if (*p1 == *p2) {
|
||||
fprintf(stderr, "\305\371\244\267\244\244\306\311\244\337\244\316\306\261\262\273\270\354\245\326\245\355\245\303\245\257\244\254\244\242\244\353\n");
|
||||
output_yomi(stderr, dprev -> yptr); fputc('\n', stderr);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
else if (*p1 > *p2) {
|
||||
fprintf(stderr, "\306\311\244\337\244\316\275\347\275\370\244\254\244\252\244\253\244\267\244\244\n");
|
||||
output_yomi(stderr, dprev->yptr); fputc('\n', stderr);
|
||||
output_yomi(stderr, drec->yptr); fputc('\n', stderr);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
while (*p2++) ylen++;
|
||||
}
|
||||
|
||||
return ylen;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static douon_knj(drec)
|
||||
DouonRec *drec;
|
||||
{
|
||||
int i;
|
||||
int len = 0;
|
||||
u_char *p;
|
||||
u_char *knjofscvt();
|
||||
HinsiRec *hrec;
|
||||
KanjiRec *krec;
|
||||
|
||||
|
||||
for (hrec = drec -> hrec ; hrec ; hrec = hrec -> hnext) {
|
||||
|
||||
for (krec = hrec -> krec ; krec ; krec = krec -> knext) {
|
||||
|
||||
p = knjofscvt(krec -> kptr, krec -> klen, &i);
|
||||
|
||||
|
||||
len += i + 1;
|
||||
|
||||
|
||||
knjhnd_set(p, i);
|
||||
|
||||
|
||||
krec -> alen = i;
|
||||
krec -> aptr = p;
|
||||
|
||||
|
||||
set_ofsrec(krec -> kptr, krec -> klen, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void make_d_list(drec)
|
||||
DouonRec *drec;
|
||||
{
|
||||
DouonRec *dptr, *dprev;
|
||||
HinsiRec *hptr;
|
||||
KanjiRec *kptr;
|
||||
int ylen;
|
||||
int klen;
|
||||
int hnum;
|
||||
int len;
|
||||
int i;
|
||||
|
||||
start:
|
||||
|
||||
if (douon_ptr == NULL) {
|
||||
douon_num = 0;
|
||||
yomi_len = 0;
|
||||
hinsi_num = 0;
|
||||
kanji_len = 0;
|
||||
assyuku = NULL;
|
||||
}
|
||||
|
||||
|
||||
klen = douon_knj(drec);
|
||||
|
||||
|
||||
ylen = diff_ylen(drec);
|
||||
|
||||
|
||||
hnum = drec -> hrec_num;
|
||||
|
||||
|
||||
i = 1 +
|
||||
MaxKnjAskNumber +
|
||||
|
||||
douon_num * DouonBlkSizeNumber + DouonBlkSizeNumber +
|
||||
yomi_len + ylen +
|
||||
hinsi_num + hnum +
|
||||
hinsi_num + hnum +
|
||||
kanji_len + klen;
|
||||
|
||||
|
||||
len = (i <= MainSegmentLength) ? 0 : decide_knjask();
|
||||
|
||||
|
||||
if ((i - len) <= MainSegmentLength) {
|
||||
|
||||
if (douon_ptr) {
|
||||
|
||||
dptr = douon_ptr; dprev = NULL;
|
||||
while (dptr) {
|
||||
dprev = dptr;
|
||||
dptr = dptr -> dnext;
|
||||
}
|
||||
|
||||
|
||||
dprev -> dnext = drec;
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
douon_ptr = drec;
|
||||
}
|
||||
drec -> dnext = NULL;
|
||||
|
||||
|
||||
drec -> dlen = ylen;
|
||||
|
||||
|
||||
douon_num += 1;
|
||||
|
||||
|
||||
yomi_len += ylen;
|
||||
|
||||
|
||||
hinsi_num += hnum;
|
||||
|
||||
|
||||
kanji_len += klen;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
else if (douon_ptr == NULL) {
|
||||
fprintf(stderr, "\243\261\306\261\262\273\270\354\245\326\245\355\245\303\245\257\244\254\302\347\244\255\244\271\244\256\244\336\244\271\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
for (hptr = drec -> hrec ; hptr ; hptr = hptr -> hnext) {
|
||||
for (kptr = hptr -> krec ; kptr ; kptr = kptr -> knext) {
|
||||
|
||||
|
||||
knjhnd_reset(kptr -> aptr, kptr -> alen);
|
||||
|
||||
|
||||
Free(kptr -> aptr);
|
||||
kptr -> aptr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
len = decide_knjask();
|
||||
|
||||
|
||||
makeseg();
|
||||
|
||||
|
||||
clear_list();
|
||||
|
||||
|
||||
clear_hindo();
|
||||
|
||||
|
||||
clear_ofsrec();
|
||||
|
||||
|
||||
askknj_num = 0;
|
||||
|
||||
|
||||
clear_assyuku();
|
||||
|
||||
goto start;
|
||||
}
|
||||
|
||||
|
||||
|
||||
flush_douon()
|
||||
{
|
||||
if (drectmp) {
|
||||
|
||||
make_d_list(drectmp);
|
||||
|
||||
drectmp = NULL;
|
||||
}
|
||||
|
||||
if (douon_ptr) {
|
||||
|
||||
decide_knjask();
|
||||
|
||||
|
||||
makeseg();
|
||||
|
||||
|
||||
clear_list();
|
||||
|
||||
|
||||
clear_hindo();
|
||||
|
||||
|
||||
clear_ofsrec();
|
||||
|
||||
|
||||
askknj_num = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
makelist(yomi, kanji, hinsi, atr)
|
||||
int *yomi;
|
||||
int *kanji;
|
||||
int hinsi;
|
||||
int *atr;
|
||||
{
|
||||
u_char *ycode;
|
||||
u_char *kcode;
|
||||
int klen;
|
||||
HinsiRec *hrec;
|
||||
KanjiRec *krec, *kprev;
|
||||
|
||||
|
||||
ycode = makeyomi(yomi);
|
||||
|
||||
|
||||
kcode = makekanji(yomi, kanji, atr, &klen);
|
||||
|
||||
|
||||
if (drectmp && strcmp(ycode, drectmp -> yptr)) {
|
||||
|
||||
make_d_list(drectmp);
|
||||
|
||||
drectmp = NULL;
|
||||
}
|
||||
|
||||
|
||||
if (!drectmp) {
|
||||
|
||||
drectmp = make_drec(ycode);
|
||||
|
||||
|
||||
hrec = make_hrec(hinsi);
|
||||
drectmp -> hrec = hrec;
|
||||
drectmp -> hrec_num = 1;
|
||||
|
||||
|
||||
krec = make_krec(kcode, klen);
|
||||
hrec -> krec = krec;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (hrec = drectmp -> hrec ; hrec -> hnext ; hrec = hrec -> hnext)
|
||||
if (hrec -> hinsi == hinsi) break;
|
||||
|
||||
|
||||
if (hrec -> hinsi == hinsi) {
|
||||
|
||||
for (krec=hrec->krec ; krec ; krec=krec->knext) {
|
||||
|
||||
if ((krec -> klen == klen) &&
|
||||
!memcmp(krec -> kptr, kcode, klen)) {
|
||||
fprintf(stderr, "\306\261\260\354\244\316\275\317\270\354\244\254\302\270\272\337\244\267\244\277\n");
|
||||
fprintf(stderr, "\t\306\311\244\337:");
|
||||
output_int(stderr, yomi);
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, "\t\264\301\273\372:");
|
||||
output_int(stderr, kanji);
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
|
||||
Free(kcode);
|
||||
|
||||
return;
|
||||
}
|
||||
kprev = krec;
|
||||
}
|
||||
|
||||
|
||||
kprev -> knext = make_krec(kcode, klen);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
hrec -> hnext = make_hrec(hinsi);
|
||||
hrec = hrec -> hnext;
|
||||
drectmp -> hrec_num += 1;
|
||||
|
||||
|
||||
krec = make_krec(kcode, klen);
|
||||
hrec -> krec = krec;
|
||||
}
|
||||
429
dict/tool/makeseg.c
Normal file
429
dict/tool/makeseg.c
Normal file
|
|
@ -0,0 +1,429 @@
|
|||
/*
|
||||
* 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
|
||||
* 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:
|
||||
*
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* $SonyRCSfile: makeseg.c,v $
|
||||
* $SonyRevision: 1.2 $
|
||||
* $SonyDate: 1994/12/09 11:27:05 $
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include "sj_struct.h"
|
||||
#include "../../include/Dict.h"
|
||||
|
||||
extern HindoRec *askknj[];
|
||||
extern int askknj_num;
|
||||
extern DouonRec *douon_ptr;
|
||||
extern FILE *outfp;
|
||||
extern int douon_num;
|
||||
|
||||
static u_char index[MainSegmentLength];
|
||||
static int idxpos = 0;
|
||||
static int idxnum = 0;
|
||||
|
||||
OffsetRec *real_ofsrec();
|
||||
u_char *knjcvt();
|
||||
|
||||
|
||||
|
||||
static u_char *set_ofsask(src, dst)
|
||||
u_char *src;
|
||||
u_char *dst;
|
||||
{
|
||||
int len;
|
||||
u_char *ptr;
|
||||
OffsetRec *ofsrec;
|
||||
|
||||
|
||||
ofsrec = real_ofsrec(src);
|
||||
|
||||
for (len = ofsrec->klen, ptr = ofsrec->kptr ; len > 0 ; ) {
|
||||
switch (*ptr & KanjiModeMask) {
|
||||
case ZenHiraAssyuku:
|
||||
case ZenKataAssyuku:
|
||||
case KanjiAssyuku:
|
||||
*dst++ = *ptr++;
|
||||
len -= 1;
|
||||
break;
|
||||
case LeadingHankaku:
|
||||
#ifndef UseHankakuInDict
|
||||
fprintf(stderr, "\302\260\300\255\245\263\241\274\245\311\241\246\245\250\245\351\241\274\n");
|
||||
exit(1);
|
||||
#else
|
||||
*dst++ = *ptr++;
|
||||
*dst++ = *ptr++;
|
||||
len -= 2;
|
||||
break;
|
||||
#endif
|
||||
case OffsetAssyuku:
|
||||
fprintf(stderr, "\306\363\275\305\244\313\245\252\245\325\245\273\245\303\245\310\244\254\273\262\276\310\244\265\244\354\244\306\244\244\244\353\n");
|
||||
exit(1);
|
||||
case AiAttribute:
|
||||
*dst++ = *ptr++;
|
||||
*dst++ = *ptr++;
|
||||
len -= 2;
|
||||
break;
|
||||
case KanjiStrEnd:
|
||||
*dst++ = *ptr++;
|
||||
len--;
|
||||
break;
|
||||
default:
|
||||
*dst++ = *ptr++;
|
||||
*dst++ = *ptr++;
|
||||
len -= 2;
|
||||
}
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
||||
|
||||
make_knjstr(src, len, dst)
|
||||
u_char *src;
|
||||
int len;
|
||||
u_char *dst;
|
||||
{
|
||||
u_char *keep = dst;
|
||||
|
||||
while (len > 0) {
|
||||
switch (*src & KanjiModeMask) {
|
||||
case ZenHiraAssyuku:
|
||||
case ZenKataAssyuku:
|
||||
case KanjiAssyuku:
|
||||
*dst++ = *src++;
|
||||
len -= 1;
|
||||
break;
|
||||
case LeadingHankaku:
|
||||
#ifndef UseHankakuInDict
|
||||
fprintf(stderr, "\302\260\300\255\245\263\241\274\245\311\241\246\245\250\245\351\241\274\n");
|
||||
exit(1);
|
||||
#else
|
||||
*dst++ = *src++;
|
||||
*dst++ = *src++;
|
||||
len -= 2;
|
||||
break;
|
||||
#endif
|
||||
case OffsetAssyuku:
|
||||
dst = set_ofsask(src, dst);
|
||||
src += 2;
|
||||
len -= 2;
|
||||
break;
|
||||
case AiAttribute:
|
||||
*dst++ = *src++;
|
||||
*dst++ = *src++;
|
||||
len -= 2;
|
||||
break;
|
||||
case KanjiStrEnd:
|
||||
*dst++ = *src++;
|
||||
len--;
|
||||
break;
|
||||
default:
|
||||
*dst++ = *src++;
|
||||
*dst++ = *src++;
|
||||
len -= 2;
|
||||
}
|
||||
}
|
||||
return(dst - keep);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static make_knjask()
|
||||
{
|
||||
int i, j;
|
||||
u_char *p;
|
||||
u_char buf[128];
|
||||
int len;
|
||||
int tlen = 0;
|
||||
|
||||
|
||||
for (i = 0 ; i < askknj_num ; i++) {
|
||||
|
||||
|
||||
len = make_knjstr(askknj[i] -> kptr, askknj[i] -> klen, buf);
|
||||
|
||||
|
||||
Free(askknj[i] -> kptr);
|
||||
|
||||
|
||||
p = (u_char *)Malloc(len);
|
||||
if (!p) {
|
||||
fprintf(stderr, "\245\341\245\342\245\352\244\254\302\255\244\352\244\336\244\273\244\363\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
memcpy(p, buf, len);
|
||||
askknj[i] -> kptr = p;
|
||||
askknj[i] -> klen = len;
|
||||
|
||||
|
||||
tlen += len + 1;
|
||||
}
|
||||
|
||||
return tlen;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
makeseg()
|
||||
{
|
||||
u_char buf[MainSegmentLength];
|
||||
DouonRec *drec;
|
||||
HinsiRec *hrec;
|
||||
KanjiRec *krec;
|
||||
int i, j, k;
|
||||
int slen;
|
||||
u_char *dst;
|
||||
u_char *sdst;
|
||||
u_char *p, *q;
|
||||
|
||||
#ifndef HEHE
|
||||
#define datset(i) { if (dst >= buf+sizeof(buf)) goto err; *dst++ = i; }
|
||||
#else
|
||||
#define datset(i) { *dst++; i; }
|
||||
#endif
|
||||
|
||||
|
||||
dst = buf;
|
||||
|
||||
|
||||
i = make_knjask();
|
||||
if (i >= 0x100) {
|
||||
fprintf(stderr, "\264\301\273\372\260\265\275\314\312\270\273\372\316\363\244\254\304\271\244\271\244\256\244\353\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
datset(i);
|
||||
for (i = 0 ; i < askknj_num ; i++) {
|
||||
p = askknj[i] -> kptr;
|
||||
j = askknj[i] -> klen;
|
||||
while (j > 0) {
|
||||
k = codesize(*p);
|
||||
datset(*p); p++;
|
||||
if (k > 2) {
|
||||
datset(*p); p++;
|
||||
datset(*p); p++;
|
||||
} else if (k > 1) {
|
||||
datset(*p); p++;
|
||||
}
|
||||
j -= k;
|
||||
}
|
||||
datset(KanjiStrEnd);
|
||||
}
|
||||
|
||||
|
||||
clear_ofsrec();
|
||||
|
||||
|
||||
for (drec = douon_ptr ; drec ; drec = drec->dnext) {
|
||||
|
||||
|
||||
sdst = dst; dst += DouonBlkSizeNumber;
|
||||
|
||||
|
||||
p = drec -> yptr;
|
||||
slen = strlen(p) - drec -> dlen;
|
||||
p += slen;
|
||||
for (i = drec -> dlen ; i > 0 ; i--) {
|
||||
datset(*p); p++;
|
||||
}
|
||||
|
||||
for (hrec = drec->hrec ; hrec ; hrec = hrec->hnext) {
|
||||
|
||||
|
||||
datset(hrec -> hinsi);
|
||||
|
||||
|
||||
for (krec = hrec->krec ; krec ; krec = krec->knext) {
|
||||
|
||||
|
||||
p = q = knjcvt(krec -> kptr, krec -> klen, &i);
|
||||
|
||||
|
||||
set_ofsrec(krec->kptr, krec->klen, dst - buf);
|
||||
|
||||
|
||||
while (i-- > 0) {
|
||||
datset(*p); p++;
|
||||
}
|
||||
datset(KanjiStrEnd);
|
||||
|
||||
Free(q);
|
||||
}
|
||||
|
||||
|
||||
datset(HinsiBlkTerm);
|
||||
}
|
||||
|
||||
|
||||
i = dst - sdst;
|
||||
*sdst = ((i >> 8) & 0x0f);
|
||||
*(sdst + 1) = (i & 0xff);
|
||||
|
||||
|
||||
if (drec -> dlen > 0x0f) *sdst |= 0x40;
|
||||
*(sdst + 2) = (drec -> dlen & 0x0f);
|
||||
|
||||
|
||||
if (slen > 0x0f) *sdst |= 0x80;
|
||||
*(sdst + 2) |= ((slen << 4) & 0xf0);
|
||||
}
|
||||
|
||||
if (dst < buf + sizeof(buf)) {
|
||||
datset(DouonBlkTerm);
|
||||
}
|
||||
|
||||
|
||||
for (p = douon_ptr -> yptr ; ; ) {
|
||||
if (idxpos < MainIndexLength) {
|
||||
index[idxpos++] = *p;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "\245\244\245\363\245\307\245\303\245\257\245\271\244\254\244\242\244\325\244\354\244\336\244\267\244\277\n");
|
||||
exit(1);
|
||||
}
|
||||
if (!*p++) break;
|
||||
}
|
||||
if (idxpos < MainIndexLength) {
|
||||
index[idxpos] = 0;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "\245\244\245\363\245\307\245\303\245\257\245\271\244\254\244\242\244\325\244\354\244\336\244\267\244\277\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
i = dst - buf;
|
||||
|
||||
while (dst < buf + sizeof(buf)) *dst++ = DouonBlkTerm;
|
||||
|
||||
|
||||
if (Fseek(outfp,
|
||||
(long)(HeaderLength + CommentLength + MainIndexLength
|
||||
+ idxnum * MainSegmentLength),
|
||||
0) < 0) {
|
||||
fprintf(stderr, "\275\320\316\317\245\325\245\241\245\244\245\353\244\307\245\267\241\274\245\257\245\250\245\351\241\274\n");
|
||||
exit(1);
|
||||
}
|
||||
if (Fwrite(buf, sizeof(buf), 1, outfp) != 1) {
|
||||
fprintf(stderr, "\275\320\316\317\245\325\245\241\245\244\245\353\244\307\245\351\245\244\245\310\245\250\245\351\241\274\n");
|
||||
exit(1);
|
||||
}
|
||||
Fflush(outfp);
|
||||
|
||||
|
||||
printf("\245\273\245\260\245\341\245\363\245\310\310\326\271\346:%d:", idxnum++);
|
||||
output_yomi(stdout, douon_ptr -> yptr);
|
||||
printf("\t\245\273\245\260\245\341\245\363\245\310\304\271:%d", i);
|
||||
printf("\t\306\261\262\273\270\354\277\364:%d\n", douon_num);
|
||||
printf("\264\301\273\372\260\265\275\314\312\270\273\372\316\363:");
|
||||
for (i = j = 0 ; i < askknj_num ; i++) {
|
||||
putchar('\t');
|
||||
if (i && j == 0) putchar('\t');
|
||||
output_knj(stdout, askknj[i] -> kptr, askknj[i] -> klen);
|
||||
printf(":%d", askknj[i] -> hindo + askknj[i] -> exist);
|
||||
if (++j >= 4) {
|
||||
putchar('\n');
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
if (j) putchar('\n');
|
||||
putchar('\n');
|
||||
fflush(stdout);
|
||||
|
||||
return;
|
||||
|
||||
err:
|
||||
fprintf(stderr, "\245\273\245\260\245\341\245\363\245\310\271\275\300\256\303\346\244\313\245\320\245\303\245\325\245\241\244\254\244\242\244\325\244\354\244\277\n");
|
||||
fprintf(stderr, "\245\273\245\260\245\341\245\363\245\310\300\350\306\254\244\316\306\311\244\337:");
|
||||
output_yomi(stderr, douon_ptr -> yptr);
|
||||
fputc('\n', stderr);
|
||||
|
||||
exit(1);
|
||||
#undef datset
|
||||
}
|
||||
|
||||
static void put4byte(p, n)
|
||||
u_char *p;
|
||||
long n;
|
||||
{
|
||||
p += 3;
|
||||
*p-- = n; n >>= 8;
|
||||
*p-- = n; n >>= 8;
|
||||
*p-- = n; n >>= 8;
|
||||
*p = n;
|
||||
}
|
||||
void makehead(dict_name)
|
||||
u_char *dict_name;
|
||||
{
|
||||
u_char header[HeaderLength + CommentLength];
|
||||
long i;
|
||||
u_char *p;
|
||||
|
||||
#define IndexPos (HeaderLength + CommentLength)
|
||||
|
||||
memset(header, '\0', sizeof(header));
|
||||
put4byte(header + VersionPos, DictVersion);
|
||||
time(&i);
|
||||
p = header + CommentPos;
|
||||
sprintf((char *)p, "%s : %s", dict_name, ctime(&i));
|
||||
while (*p) {
|
||||
if (*p == '\n') { *p = 0; break; }
|
||||
p++;
|
||||
}
|
||||
|
||||
i = IndexPos;
|
||||
|
||||
put4byte(header + DictIdxPos, i);
|
||||
put4byte(header + DictIdxLen, MainIndexLength);
|
||||
i += MainIndexLength;
|
||||
|
||||
put4byte(header + DictSegPos, i);
|
||||
put4byte(header + DictSegLen, MainSegmentLength);
|
||||
put4byte(header + DictSegMax, 0);
|
||||
put4byte(header + DictSegNum, idxnum);
|
||||
|
||||
put4byte(header + DictAIdxPos, 0);
|
||||
put4byte(header + DictAIdxLen, 0);
|
||||
|
||||
put4byte(header + DictASegPos, 0);
|
||||
put4byte(header + DictASegLen, 0);
|
||||
|
||||
Fseek(outfp, (long)HeaderPos, 0);
|
||||
Fwrite(header, sizeof(header), 1, outfp);
|
||||
Fseek(outfp, (long)IndexPos, 0);
|
||||
Fwrite(index, MainIndexLength, 1, outfp);
|
||||
|
||||
#undef IndexPos
|
||||
}
|
||||
67
dict/tool/memory.c
Normal file
67
dict/tool/memory.c
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* 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
|
||||
* 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:
|
||||
*
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* $SonyRCSfile: memory.c,v $
|
||||
* $SonyRevision: 1.1 $
|
||||
* $SonyDate: 1994/06/03 08:00:42 $
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
char *Malloc(size)
|
||||
unsigned size;
|
||||
{
|
||||
char *p;
|
||||
char *malloc();
|
||||
|
||||
p = malloc(size);
|
||||
if (p == NULL) {
|
||||
fprintf(stderr, "\245\341\245\342\245\352\244\254\263\316\312\335\244\307\244\255\244\336\244\273\244\363\244\307\244\267\244\277\241\243\n");
|
||||
exit(1);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
char *Zalloc(size)
|
||||
int size;
|
||||
{
|
||||
char *p;
|
||||
|
||||
p = Malloc(size);
|
||||
memset(p, '\0', size);
|
||||
return p;
|
||||
}
|
||||
|
||||
void Free(p)
|
||||
char *p;
|
||||
{
|
||||
free(p);
|
||||
}
|
||||
188
dict/tool/offset.c
Normal file
188
dict/tool/offset.c
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
/*
|
||||
* 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
|
||||
* 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:
|
||||
*
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* $SonyRCSfile: offset.c,v $
|
||||
* $SonyRevision: 1.2 $
|
||||
* $SonyDate: 1994/08/17 01:50:26 $
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include "sj_struct.h"
|
||||
|
||||
extern OffsetRec *ofsrec[];
|
||||
extern int ofsrec_num;
|
||||
|
||||
|
||||
|
||||
static OffsetRec *makeoffset(ptr, len, ofs)
|
||||
u_char *ptr;
|
||||
int len;
|
||||
int ofs;
|
||||
{
|
||||
OffsetRec *orec;
|
||||
u_char *p;
|
||||
|
||||
|
||||
orec = (OffsetRec *)Malloc(sizeof(OffsetRec));
|
||||
|
||||
|
||||
p = (u_char *)Malloc(len);
|
||||
memcpy(p, ptr, len);
|
||||
|
||||
|
||||
orec -> kptr = p;
|
||||
orec -> klen = len;
|
||||
if (ofs)
|
||||
orec -> offset = ofs;
|
||||
else
|
||||
orec -> offset = ofsrec_num + 1;
|
||||
|
||||
return orec;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
set_ofsrec(ptr, len, ofs)
|
||||
u_char *ptr;
|
||||
int len;
|
||||
int ofs;
|
||||
{
|
||||
OffsetRec *orec;
|
||||
int low, high, mid;
|
||||
int i;
|
||||
|
||||
|
||||
if (ofsrec_num <= 0) {
|
||||
orec = makeoffset(ptr, len, ofs);
|
||||
ofsrec[0]= orec;
|
||||
ofsrec_num++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
low = 0; high = ofsrec_num - 1;
|
||||
while (low <= high) {
|
||||
mid = (low + high) / 2;
|
||||
i = string_cmp(ofsrec[mid]->kptr, ofsrec[mid]->klen, ptr, len);
|
||||
if (i > 0)
|
||||
high = mid - 1;
|
||||
else if (i < 0)
|
||||
low = ++mid;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (i) {
|
||||
if (ofsrec_num >= MaxOffsetNumber) {
|
||||
fprintf(stderr, "\245\252\245\325\245\273\245\303\245\310\241\246\245\306\241\274\245\326\245\353\244\254\244\242\244\325\244\354\244\336\244\267\244\277\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
orec = makeoffset(ptr, len, ofs);
|
||||
|
||||
|
||||
for (i = ofsrec_num ; i > mid ; i--) ofsrec[i] = ofsrec[i - 1];
|
||||
ofsrec[mid] = orec;
|
||||
ofsrec_num++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
isknjexist(knj, len)
|
||||
u_char *knj;
|
||||
int len;
|
||||
{
|
||||
int low, high, mid;
|
||||
int i;
|
||||
|
||||
|
||||
if (ofsrec_num <= 0) return 0;
|
||||
|
||||
|
||||
low = 0; high = ofsrec_num - 1;
|
||||
while (low <= high) {
|
||||
mid = (low + high) / 2;
|
||||
i = string_cmp(ofsrec[mid]->kptr, ofsrec[mid]->klen, knj, len);
|
||||
if (i > 0)
|
||||
high = mid - 1;
|
||||
else if (i < 0)
|
||||
low = ++mid;
|
||||
else
|
||||
return ofsrec[mid] -> offset;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
clear_ofsrec()
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0 ; i < ofsrec_num ; i++) {
|
||||
Free(ofsrec[i] -> kptr);
|
||||
Free(ofsrec[i]);
|
||||
}
|
||||
|
||||
ofsrec_num = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
OffsetRec *real_ofsrec(ptr)
|
||||
u_char *ptr;
|
||||
{
|
||||
int ofs;
|
||||
int i;
|
||||
OffsetRec **p;
|
||||
|
||||
|
||||
ofs = (*ptr++ & KnjAssyukuMask);
|
||||
ofs <<= 8;
|
||||
ofs += *ptr;
|
||||
|
||||
|
||||
for (i = ofsrec_num, p = ofsrec ; i-- > 0 ; p++)
|
||||
if ((*p) -> offset == ofs)
|
||||
return *p;
|
||||
|
||||
|
||||
fprintf(stderr, "real_ofsrec() \244\307\260\333\276\357\244\312\276\365\302\326 %x\n", ofs);
|
||||
exit(1);
|
||||
}
|
||||
272
dict/tool/readline.c
Normal file
272
dict/tool/readline.c
Normal file
|
|
@ -0,0 +1,272 @@
|
|||
/*
|
||||
* 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
|
||||
* 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:
|
||||
*
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* $SonyRCSfile: readline.c,v $
|
||||
* $SonyRevision: 1.1 $
|
||||
* $SonyDate: 1994/06/03 08:00:44 $
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include "sj_euc.h"
|
||||
#include "sj_const.h"
|
||||
#include "sj_macro.h"
|
||||
|
||||
|
||||
static long lineloc;
|
||||
|
||||
|
||||
static int yomi[MaxYomiLength + 1];
|
||||
static int kanji[MaxKanjiLength + 1];
|
||||
static int hinsi[MaxHinsiNumber + 1];
|
||||
static int atr[MaxAtrNumber + 1];
|
||||
|
||||
|
||||
|
||||
static error(s)
|
||||
char *s;
|
||||
{
|
||||
register int c;
|
||||
|
||||
if (s) fprintf(stderr, "%s\n", s);
|
||||
mark_file(stderr);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static readchar()
|
||||
{
|
||||
register int c1;
|
||||
register int c2;
|
||||
|
||||
|
||||
c1 = getch(); if (c1 == EOF) return EOF;
|
||||
|
||||
|
||||
if (c1 != SS3) {
|
||||
if (c1 & 0x80) {
|
||||
c2 = getch(); if (c2 == EOF) error(NULL);
|
||||
c1 = ((c1 & 0xff) << 8) + (c2 & 0xff);
|
||||
}
|
||||
} else {
|
||||
c2 = getch(); if (c2 == EOF) error(NULL);
|
||||
c1 = ((c1 & 0xff) << 8) + (c2 & 0xff);
|
||||
c2 = getch(); if (c2 == EOF) error(NULL);
|
||||
c1 = ((c1 & 0xffff) << 8) + (c2 & 0xff);
|
||||
}
|
||||
|
||||
return c1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static skip_blank()
|
||||
{
|
||||
register int c;
|
||||
|
||||
c = readchar();
|
||||
while (Isblank(c)) c = readchar();
|
||||
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static readhinsi()
|
||||
{
|
||||
static int c = 0;
|
||||
register int i;
|
||||
unsigned char hinsi[128];
|
||||
int flg;
|
||||
|
||||
retry:
|
||||
|
||||
if (c == '\n') {
|
||||
c = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
c = skip_blank();
|
||||
if (c == '\n') {
|
||||
c = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
for (i = 0 ; !Isblank(c) ; ) {
|
||||
if (c == '\n' || c == ':') break;
|
||||
if (Isillegal(c)) error(IllegalFormat);
|
||||
if (c > 0xffffff) {
|
||||
if (i >= 126) error(TooLongHinsi);
|
||||
hinsi[i++] = ((c >> 24) & 0xff);
|
||||
if (i >= 126) error(TooLongHinsi);
|
||||
hinsi[i++] = ((c >> 16) & 0xff);
|
||||
if (i >= 126) error(TooLongHinsi);
|
||||
hinsi[i++] = ((c >> 8) & 0xff);
|
||||
} else if (c > 0xffff) {
|
||||
if (i >= 126) error(TooLongHinsi);
|
||||
hinsi[i++] = ((c >> 16) & 0xff);
|
||||
if (i >= 126) error(TooLongHinsi);
|
||||
hinsi[i++] = ((c >> 8) & 0xff);
|
||||
} else if (c > 0xff) {
|
||||
if (i >= 126) error(TooLongHinsi);
|
||||
hinsi[i++] = ((c >> 8) & 0xff);
|
||||
}
|
||||
if (i >= 127) error(TooLongHinsi);
|
||||
hinsi[i++] = (c & 0xff);
|
||||
c = readchar();
|
||||
}
|
||||
|
||||
|
||||
if (i == 0) return 0;
|
||||
|
||||
|
||||
if (hinsi[0] == '[' && hinsi[i - 1] == ']') {
|
||||
hinsi[i - 1] = 0;
|
||||
i = cnvhinsi(hinsi + 1);
|
||||
if (i > 0) {
|
||||
fprintf(stderr, "\311\312\273\354 \"%s\" \244\313\263\347\270\314\244\254\244\304\244\244\244\306\244\244\244\353\n",
|
||||
hinsi + 1);
|
||||
}
|
||||
else if (!i) {
|
||||
|
||||
fprintf(stderr, "\"%s\" \244\254\245\263\241\274\245\311\262\275\244\307\244\255\244\336\244\273\244\363\n",
|
||||
hinsi + 1);
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
hinsi[i] = 0;
|
||||
i = cnvhinsi(hinsi);
|
||||
if (!i) {
|
||||
|
||||
fprintf(stderr, "\"%s\" \244\254\245\263\241\274\245\311\262\275\244\307\244\255\244\336\244\273\244\363\n", hinsi);
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int *readline()
|
||||
{
|
||||
register int c;
|
||||
register int i;
|
||||
register int j;
|
||||
|
||||
|
||||
for ( ; ; ) {
|
||||
|
||||
mark_file(NULL);
|
||||
|
||||
c = skip_blank();
|
||||
|
||||
|
||||
if (c == '#') {
|
||||
while (c != '\n') c = skip_blank();
|
||||
}
|
||||
|
||||
|
||||
if (c == EOF) return NULL;
|
||||
|
||||
|
||||
if (c != '\n') break;
|
||||
}
|
||||
|
||||
|
||||
for (i = 0 ; !Isblank(c) ; ) {
|
||||
if (Isillegal(c)) error(IllegalFormat);
|
||||
if (i >= MaxYomiLength) error(TooLongYomi);
|
||||
yomi[i++] = c;
|
||||
c = readchar();
|
||||
}
|
||||
yomi[i] = 0;
|
||||
if (i == 0) error(NoYomiString);
|
||||
|
||||
|
||||
c = skip_blank();
|
||||
|
||||
|
||||
if (c != '"') {
|
||||
for (i = 0 ; !Isblank(c) ; ) {
|
||||
if (Isillegal(c)) error(IllegalFormat);
|
||||
if (i >= MaxKanjiLength) error(TooLongKanji);
|
||||
kanji[i++] = c;
|
||||
c = readchar();
|
||||
}
|
||||
}
|
||||
else {
|
||||
c = readchar();
|
||||
for (i = 0 ; c != '"' ; ) {
|
||||
if (Isillegal(c)) error(IllegalFormat);
|
||||
if (i >= MaxKanjiLength) error(TooLongKanji);
|
||||
kanji[i++] = c;
|
||||
c = readchar();
|
||||
}
|
||||
}
|
||||
kanji[i] = 0;
|
||||
if (i == 0) error(NoKanjiString);
|
||||
|
||||
|
||||
i = j = 0;
|
||||
while (c = readhinsi()) {
|
||||
if (c < 0) {
|
||||
if (i >= MaxAtrNumber) error(TooManyAtr);
|
||||
atr[i++] = -c;
|
||||
}
|
||||
else {
|
||||
if (j >= MaxHinsiNumber) error(TooManyHinsi);
|
||||
hinsi[j++] = c;
|
||||
}
|
||||
}
|
||||
atr[i] = 0;
|
||||
if (j == 0) hinsi[j++] = HinsiTankan;
|
||||
hinsi[j] = 0;
|
||||
|
||||
|
||||
return yomi;
|
||||
}
|
||||
|
||||
|
||||
|
||||
setline(func)
|
||||
int (*func)();
|
||||
{
|
||||
register int i;
|
||||
|
||||
for (i = 0 ; hinsi[i] ; i++) (*func)(yomi, kanji, hinsi[i], atr);
|
||||
}
|
||||
232
dict/tool/string.c
Normal file
232
dict/tool/string.c
Normal file
|
|
@ -0,0 +1,232 @@
|
|||
/*
|
||||
* 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
|
||||
* 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:
|
||||
*
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* $SonyRCSfile: string.c,v $
|
||||
* $SonyRevision: 1.1 $
|
||||
* $SonyDate: 1994/06/03 08:00:45 $
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include "sj_const.h"
|
||||
|
||||
|
||||
|
||||
bubun_str(p1, l1, p2, l2)
|
||||
u_char *p1;
|
||||
int l1;
|
||||
u_char *p2;
|
||||
int l2;
|
||||
{
|
||||
register u_char *p;
|
||||
register int l;
|
||||
register int i;
|
||||
|
||||
for (p = p1, l = l1 ; l > 0 ; ) {
|
||||
|
||||
if (l < l2) break;
|
||||
for (i = 0 ; i < l2 ; i++)
|
||||
if (*(p + i) != *(p2 + i)) break;
|
||||
|
||||
|
||||
if (i >= l2) return 1;
|
||||
|
||||
i = codesize(*p);
|
||||
p += i;
|
||||
l -= i;
|
||||
}
|
||||
|
||||
for (p = p2, l = l2 ; l > 0 ; ) {
|
||||
|
||||
if (l < l1) break;
|
||||
for (i = 0 ; i < l1 ; i++) if (*(p + i) != *(p1 + i)) break;
|
||||
|
||||
|
||||
if (i >= l1) return -1;
|
||||
|
||||
i = codesize(*p);
|
||||
p += i;
|
||||
l -= i;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
overlap_str(p1, l1, p2, l2)
|
||||
u_char *p1;
|
||||
u_char *p2;
|
||||
int l1;
|
||||
int l2;
|
||||
{
|
||||
register u_char *p;
|
||||
register int l;
|
||||
register int i;
|
||||
register int j;
|
||||
u_char tmp[MaxKanjiLength * 2 + MaxAtrNumber * 2];
|
||||
|
||||
for (p = p1, l = l1 ; l > 0 ; ) {
|
||||
|
||||
if (l < l2) {
|
||||
for (i = 0 ; (i < l) && (*(p + i) == *(p2 + i)) ; i++) ;
|
||||
|
||||
|
||||
if ((i >= l) && (l2 + l1 - l < sizeof(tmp))) {
|
||||
|
||||
for (i = 0 ; i < l1 ; i++)
|
||||
tmp[i] = *(p1 + i);
|
||||
for (j = l ; j < l2 ; i++, j++)
|
||||
tmp[i] = *(p2 + j);
|
||||
|
||||
|
||||
if (check_hindo(tmp, i)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
i = codesize(*p);
|
||||
p += i;
|
||||
l -= i;
|
||||
}
|
||||
|
||||
for (p = p2, l = l2 ; l > 0 ; ) {
|
||||
|
||||
if (l < l1) {
|
||||
for (i = 0 ; (i < l) && (*(p + i) == *(p1 + i)) ; i++) ;
|
||||
|
||||
|
||||
if ((i >= l) && (l1 + l2 - l < sizeof(tmp))) {
|
||||
|
||||
for (i = 0 ; i < l2 ; i++)
|
||||
tmp[i] = *(p2 + i);
|
||||
for (j = l ; j < l1 ; i++, j++)
|
||||
tmp[i] = *(p1 + j);
|
||||
|
||||
|
||||
if (check_hindo(tmp, i)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
i = codesize(*p);
|
||||
p += i;
|
||||
l -= i;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
istrlen(s)
|
||||
int *s;
|
||||
{
|
||||
register int *p;
|
||||
|
||||
for (p = s ; *p ; p++) ;
|
||||
|
||||
return(p - s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
istrcmp(s, d)
|
||||
register int *s;
|
||||
register int *d;
|
||||
{
|
||||
for ( ; *s && (*s == *d) ; s++, d++) ;
|
||||
|
||||
return (*s - *d);
|
||||
}
|
||||
|
||||
|
||||
|
||||
top_strcmp(src, dst)
|
||||
register int *src;
|
||||
register int *dst;
|
||||
{
|
||||
register int i = 0;
|
||||
|
||||
|
||||
for (i = 0 ; *src && (*src == *dst) ; src++, dst++)
|
||||
i++;
|
||||
|
||||
|
||||
return (i > MaxYomiAskNumber) ? MaxYomiAskNumber : i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
last_strcmp(src, dst)
|
||||
int *src;
|
||||
int *dst;
|
||||
{
|
||||
int slen, dlen;
|
||||
|
||||
|
||||
slen = istrlen(src);
|
||||
dlen = istrlen(dst);
|
||||
|
||||
|
||||
if (dlen > MaxYomiAskNumber)
|
||||
return 0;
|
||||
|
||||
|
||||
if (istrcmp(src + (slen - dlen), dst))
|
||||
return 0;
|
||||
|
||||
|
||||
return dlen;
|
||||
}
|
||||
|
||||
|
||||
|
||||
string_cmp(p1, l1, p2, l2)
|
||||
register u_char *p1;
|
||||
register u_char *p2;
|
||||
register int l1;
|
||||
register int l2;
|
||||
{
|
||||
while (l1 > 0 && l2 > 0) {
|
||||
if (*p1 != *p2) return (*p1 - *p2);
|
||||
p1++; l1--;
|
||||
p2++; l2--;
|
||||
}
|
||||
|
||||
if (l1 == l2) return 0;
|
||||
if (l1 > l2) return 1;
|
||||
return -1;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue