Flatten sj3mkdic
Signed-off-by: Masanori Ogino <mogino@acm.org>
This commit is contained in:
parent
f2b77e4374
commit
7a3060176a
21 changed files with 33 additions and 74 deletions
198
sj3mkdic/GramTable
Normal file
198
sj3mkdic/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
sj3mkdic/Imakefile
Normal file
79
sj3mkdic/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))
|
||||
276
sj3mkdic/char.c
Normal file
276
sj3mkdic/char.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: char.c,v $
|
||||
* $SonyRevision: 1.1 $
|
||||
* $SonyDate: 1994/06/03 08:00:32 $
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include "sj_euc.h"
|
||||
#include "sj_const.h"
|
||||
|
||||
|
||||
int
|
||||
cnvyomi(int code)
|
||||
{
|
||||
u_short hh;
|
||||
u_char high;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
h2kcode(int code)
|
||||
{
|
||||
u_short hh;
|
||||
u_char high;
|
||||
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);
|
||||
}
|
||||
/* XXX: what should we do if we reach here?
|
||||
* XXX: I do not know if it is correct, but return 0 for now.
|
||||
* XXX: Hiroo Ono (2004/07/01) */
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
codesize(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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
output_knj(FILE* fp, u_char* p, 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++;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
output_str(FILE* fp, char* p)
|
||||
{
|
||||
while (*p) { fputc(*p, fp); p++; }
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
output_int(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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
yomi2zen(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]);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
output_yomi(FILE* fp, u_char* p)
|
||||
{
|
||||
int i;
|
||||
|
||||
while (*p) {
|
||||
i = yomi2zen(*p++);
|
||||
fputc((i >> 8) & 0xff, fp);
|
||||
fputc(i & 0xff, fp);
|
||||
}
|
||||
}
|
||||
117
sj3mkdic/cnvhinsi.c
Normal file
117
sj3mkdic/cnvhinsi.c
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* 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>
|
||||
#include "dicttool.h"
|
||||
|
||||
|
||||
struct gram_code {
|
||||
char *name;
|
||||
int code;
|
||||
} gramtbl[] = {
|
||||
|
||||
#include "GramTable"
|
||||
|
||||
};
|
||||
|
||||
#define GramMax (sizeof(gramtbl)/sizeof(struct gram_code) - 1)
|
||||
|
||||
int
|
||||
u_strcmp(u_char* a, u_char* 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(u_char *buf)
|
||||
{
|
||||
int min;
|
||||
int max;
|
||||
int mid;
|
||||
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(int code)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0 ; i <= GramMax ; i++) {
|
||||
if (gramtbl[i].code == code) return gramtbl[i].name;
|
||||
}
|
||||
|
||||
return "Err";
|
||||
}
|
||||
163
sj3mkdic/file.c
Normal file
163
sj3mkdic/file.c
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
/*
|
||||
* 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 <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "dicttool.h"
|
||||
|
||||
typedef struct filelist {
|
||||
FILE *fp;
|
||||
char *fname;
|
||||
struct filelist *next;
|
||||
} FileList;
|
||||
|
||||
static FileList *flist = NULL;
|
||||
|
||||
static char*
|
||||
get_fname(FILE* fp)
|
||||
{
|
||||
FileList *p;
|
||||
|
||||
for (p = flist ; p ; p = p -> next)
|
||||
if (p -> fp == fp) return p -> fname;
|
||||
return "some file";
|
||||
}
|
||||
|
||||
FILE*
|
||||
Fopen(char* filename, char* type)
|
||||
{
|
||||
FILE *fp;
|
||||
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;
|
||||
}
|
||||
|
||||
void
|
||||
Fclose(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
Fseek(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);
|
||||
}
|
||||
|
||||
long
|
||||
Ftell(FILE* fp)
|
||||
{
|
||||
return ftell(fp);
|
||||
}
|
||||
|
||||
off_t /* XXX: just looked in FreeBSD's sys/stat.h, need to check SUS spec. */
|
||||
Fsize(char* filename)
|
||||
{
|
||||
struct stat buf;
|
||||
|
||||
#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
|
||||
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);
|
||||
}
|
||||
|
||||
int
|
||||
Fread(char* p, int s, int n, FILE* fp)
|
||||
{
|
||||
if (fread(p, s, n, fp) == n) return n;
|
||||
|
||||
fprintf(stderr, "Read error in %s\n", get_fname(fp));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int
|
||||
Fwrite(char* p, int s, int n, FILE* fp)
|
||||
{
|
||||
if (fwrite(p, s, n, fp) == n) return n;
|
||||
|
||||
fprintf(stderr, "Write error in %s\n", get_fname(fp));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int
|
||||
Fgetc(FILE* fp)
|
||||
{
|
||||
return fgetc(fp);
|
||||
}
|
||||
|
||||
void
|
||||
Fflush(FILE* fp)
|
||||
{
|
||||
fflush(fp);
|
||||
}
|
||||
58
sj3mkdic/global.c
Normal file
58
sj3mkdic/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;
|
||||
629
sj3mkdic/hindo.c
Normal file
629
sj3mkdic/hindo.c
Normal file
|
|
@ -0,0 +1,629 @@
|
|||
/*
|
||||
* 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 $
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include "sj_struct.h"
|
||||
#include "dicttool.h"
|
||||
|
||||
extern HindoRec *hindo[];
|
||||
extern int hindo_num;
|
||||
extern AssyukuRec *assyuku;
|
||||
extern HindoRec *askknj[];
|
||||
extern int askknj_num;
|
||||
extern int kanji_num;
|
||||
|
||||
|
||||
int
|
||||
check_hindo(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 (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 int
|
||||
assyuku_len(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(HindoRec* hrec)
|
||||
{
|
||||
AssyukuRec *arec;
|
||||
AssyukuRec *aprev;
|
||||
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(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(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(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(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
knjhnd_set(u_char* p, int l)
|
||||
{
|
||||
u_char *kp1;
|
||||
u_char *kp2;
|
||||
int i;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
knjhnd_reset(u_char* p, int l)
|
||||
{
|
||||
u_char *kp1;
|
||||
u_char *kp2;
|
||||
int i;
|
||||
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 int
|
||||
check_assyuku(HindoRec* p, 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;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
decide_knjask(void)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
clear_hindo(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0 ; i < hindo_num ; i++) {
|
||||
Free(hindo[i]->kptr);
|
||||
Free(hindo[i]);
|
||||
}
|
||||
hindo_num = 0;
|
||||
kanji_num = 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
clear_assyuku(void)
|
||||
{
|
||||
AssyukuRec *p;
|
||||
|
||||
while (assyuku) {
|
||||
p = assyuku;
|
||||
assyuku = assyuku -> anext;
|
||||
Free(p);
|
||||
}
|
||||
}
|
||||
274
sj3mkdic/knjcvt.c
Normal file
274
sj3mkdic/knjcvt.c
Normal file
|
|
@ -0,0 +1,274 @@
|
|||
/*
|
||||
* 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 $
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include "sj_const.h"
|
||||
#include "sj_struct.h"
|
||||
#include "dicttool.h"
|
||||
|
||||
typedef struct div_list {
|
||||
int len;
|
||||
u_char code[3];
|
||||
struct div_list *child;
|
||||
} DivList;
|
||||
|
||||
extern HindoRec *askknj[];
|
||||
extern int askknj_num;
|
||||
|
||||
|
||||
|
||||
static void
|
||||
free_divlist(DivList* p)
|
||||
{
|
||||
DivList *q;
|
||||
|
||||
while (p) {
|
||||
q = p -> child;
|
||||
Free(p);
|
||||
p = q;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static DivList*
|
||||
make_divrec(void)
|
||||
{
|
||||
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 int
|
||||
make_divlist(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(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(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;
|
||||
}
|
||||
|
||||
224
sj3mkdic/makedict.c
Normal file
224
sj3mkdic/makedict.c
Normal file
|
|
@ -0,0 +1,224 @@
|
|||
/*
|
||||
* 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 $
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
|
||||
/* #include "sj_sysvdef.h" */ /* XXX: no more need it? */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <locale.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/param.h>
|
||||
#include "sj_const.h"
|
||||
#include "dicttool.h"
|
||||
|
||||
FILE *infp = NULL;
|
||||
FILE *outfp = NULL;
|
||||
|
||||
static char *idxtop = NULL;
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
parse(argc, argv);
|
||||
|
||||
while (readline()) setline(makelist);
|
||||
flush_douon();
|
||||
makehead((u_char *)argv[2]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
make_idxlist(char* name)
|
||||
{
|
||||
int i;
|
||||
char *p;
|
||||
|
||||
i = strlen(name);
|
||||
p = Zalloc(i + 2);
|
||||
strcpy(p, name);
|
||||
return p;
|
||||
}
|
||||
|
||||
char*
|
||||
get_idxlist(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"))!=NULL)
|
||||
fclose(fp);
|
||||
else {
|
||||
fprintf(stderr, "Can't open %s mode \"r\"\n", q);
|
||||
i++;
|
||||
}
|
||||
while (*q++) ;
|
||||
}
|
||||
if (i) exit(1);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
parse(int argc, char** argv)
|
||||
{
|
||||
char *progname = NULL;
|
||||
char *p;
|
||||
|
||||
|
||||
if ((progname = strrchr(argv[0], '/'))!=NULL)
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
get_number(char* ptr)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while (*ptr >= '0' && *ptr <= '9') {
|
||||
i = i * 10 + (*ptr++ - '0');
|
||||
}
|
||||
|
||||
return(i);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
usage(char* name)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s text_file binary_file\n",
|
||||
name ? name : "encode");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
getch(void)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
mark_file(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;
|
||||
}
|
||||
}
|
||||
645
sj3mkdic/makelist.c
Normal file
645
sj3mkdic/makelist.c
Normal file
|
|
@ -0,0 +1,645 @@
|
|||
/*
|
||||
* 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 $
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include "sj_struct.h"
|
||||
#include "dicttool.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 void
|
||||
clearklist(KanjiRec* krec)
|
||||
{
|
||||
KanjiRec *p;
|
||||
|
||||
|
||||
while (krec) {
|
||||
|
||||
Free(krec -> kptr);
|
||||
Free(krec -> aptr);
|
||||
|
||||
|
||||
p = krec;
|
||||
krec = krec -> knext;
|
||||
|
||||
|
||||
Free(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
clearhlist(HinsiRec* hrec)
|
||||
{
|
||||
HinsiRec *p;
|
||||
|
||||
|
||||
while (hrec) {
|
||||
|
||||
clearklist(hrec -> krec);
|
||||
|
||||
|
||||
p = hrec;
|
||||
hrec = hrec -> hnext;
|
||||
|
||||
|
||||
Free(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
clear_list(void)
|
||||
{
|
||||
DouonRec *p;
|
||||
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(int *yomi, int* kanji, int* atr, int* len)
|
||||
{
|
||||
int kana[MaxYomiLength + 1];
|
||||
u_char ktmp[MaxKanjiLength * 3 + MaxAtrNumber * 2 + 1];
|
||||
int i;
|
||||
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))!=0) {
|
||||
kanji += i;
|
||||
ktmp[pos++] = (ZenHiraAssyuku | (i - 1));
|
||||
}
|
||||
|
||||
else if ((i = top_strcmp(kana, kanji))!=0) {
|
||||
kanji += i;
|
||||
ktmp[pos++] = (ZenKataAssyuku | (i - 1));
|
||||
}
|
||||
|
||||
|
||||
while (*kanji) {
|
||||
|
||||
if ((i = last_strcmp(yomi, kanji))!=0) {
|
||||
kanji += i;
|
||||
ktmp[pos++] = (ZenHiraAssyuku | (i - 1));
|
||||
}
|
||||
|
||||
else if ((i = last_strcmp(kana, kanji))!=0) {
|
||||
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(int* yomi)
|
||||
{
|
||||
u_char tmp[MaxYomiLength + 1];
|
||||
int i;
|
||||
int j;
|
||||
int *y = yomi;
|
||||
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(u_char* kcode, int klen)
|
||||
{
|
||||
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(int hinsi)
|
||||
{
|
||||
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(u_char* ycode)
|
||||
{
|
||||
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 int
|
||||
diff_ylen(DouonRec *drec)
|
||||
{
|
||||
DouonRec *dptr;
|
||||
DouonRec *dprev;
|
||||
u_char *p1;
|
||||
u_char *p2;
|
||||
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 int
|
||||
douon_knj(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(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;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
flush_douon(void)
|
||||
{
|
||||
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(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
sj3mkdic/makeseg.c
Normal file
429
sj3mkdic/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 $
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include "sj_struct.h"
|
||||
#include "../../include/Dict.h"
|
||||
#include "dicttool.h"
|
||||
|
||||
extern HindoRec *askknj[];
|
||||
extern int askknj_num;
|
||||
extern DouonRec *douon_ptr;
|
||||
extern FILE *outfp;
|
||||
extern int douon_num;
|
||||
|
||||
static u_char segindex[MainSegmentLength];
|
||||
static int idxpos = 0;
|
||||
static int idxnum = 0;
|
||||
|
||||
|
||||
static u_char*
|
||||
set_ofsask(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;
|
||||
}
|
||||
|
||||
|
||||
size_t
|
||||
make_knjstr(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 int
|
||||
make_knjask(void)
|
||||
{
|
||||
int i;
|
||||
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(void)
|
||||
{
|
||||
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) {
|
||||
segindex[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) {
|
||||
segindex[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(u_char* p, size_t n)
|
||||
{
|
||||
p += 3;
|
||||
*p-- = n; n >>= 8;
|
||||
*p-- = n; n >>= 8;
|
||||
*p-- = n; n >>= 8;
|
||||
*p = n;
|
||||
}
|
||||
|
||||
void
|
||||
makehead(u_char* dict_name)
|
||||
{
|
||||
u_char header[HeaderLength + CommentLength];
|
||||
long i;
|
||||
u_char *p;
|
||||
time_t curtime;
|
||||
|
||||
#define IndexPos (HeaderLength + CommentLength)
|
||||
|
||||
memset(header, '\0', sizeof(header));
|
||||
put4byte(header + VersionPos, DictVersion);
|
||||
time(&curtime);
|
||||
p = header + CommentPos;
|
||||
sprintf((char *)p, "%s : %s", dict_name, ctime(&curtime));
|
||||
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(segindex, MainIndexLength, 1, outfp);
|
||||
|
||||
#undef IndexPos
|
||||
}
|
||||
72
sj3mkdic/memory.c
Normal file
72
sj3mkdic/memory.c
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* 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 $
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include "dicttool.h"
|
||||
|
||||
void*
|
||||
Malloc(size_t size)
|
||||
{
|
||||
void* p;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void*
|
||||
Zalloc (size_t size)
|
||||
{
|
||||
void* p;
|
||||
|
||||
p = Malloc(size);
|
||||
memset(p, '\0', size);
|
||||
return p;
|
||||
}
|
||||
|
||||
void
|
||||
Free(void *p)
|
||||
{
|
||||
free(p);
|
||||
}
|
||||
184
sj3mkdic/offset.c
Normal file
184
sj3mkdic/offset.c
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
/*
|
||||
* 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 <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include "sj_struct.h"
|
||||
#include "dicttool.h"
|
||||
|
||||
extern OffsetRec *ofsrec[];
|
||||
extern int ofsrec_num;
|
||||
|
||||
|
||||
|
||||
static OffsetRec*
|
||||
makeoffset(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(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++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
isknjexist(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;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
clear_ofsrec(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0 ; i < ofsrec_num ; i++) {
|
||||
Free(ofsrec[i] -> kptr);
|
||||
Free(ofsrec[i]);
|
||||
}
|
||||
|
||||
ofsrec_num = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
OffsetRec*
|
||||
real_ofsrec(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);
|
||||
}
|
||||
275
sj3mkdic/readline.c
Normal file
275
sj3mkdic/readline.c
Normal file
|
|
@ -0,0 +1,275 @@
|
|||
/*
|
||||
* 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 $
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "sj_euc.h"
|
||||
#include "sj_const.h"
|
||||
#include "sj_macro.h"
|
||||
#include "dicttool.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 void
|
||||
error(char *s)
|
||||
{
|
||||
if (s) fprintf(stderr, "%s\n", s);
|
||||
mark_file(stderr);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int
|
||||
readchar(void)
|
||||
{
|
||||
int c1;
|
||||
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 int
|
||||
skip_blank(void)
|
||||
{
|
||||
int c;
|
||||
|
||||
c = readchar();
|
||||
while (Isblank(c)) c = readchar();
|
||||
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int
|
||||
readhinsi(void)
|
||||
{
|
||||
static int c = 0;
|
||||
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(void)
|
||||
{
|
||||
int c;
|
||||
int i;
|
||||
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())!=0) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
setline(void (*func)(int*, int*, int, int*))
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0 ; hinsi[i] ; i++) (*func)(yomi, kanji, hinsi[i], atr);
|
||||
}
|
||||
112
sj3mkdic/sj_const.h
Normal file
112
sj3mkdic/sj_const.h
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* 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: sj_const.h,v $
|
||||
* $SonyRevision: 1.1 $
|
||||
* $SonyDate: 1994/06/03 08:00:24 $
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef _CONST_
|
||||
#define _CONST_
|
||||
|
||||
#define MainSegmentLength 2048
|
||||
#define MainIndexLength 2048
|
||||
#define MainIndexNumber 512
|
||||
|
||||
#define MaxYomiLength 32
|
||||
#define MaxKanjiLength 32
|
||||
#define MaxHinsiNumber 16
|
||||
#define MaxAtrNumber 16
|
||||
#define MaxJosiNumber 16
|
||||
|
||||
#define MaxKnjAskNumber 16
|
||||
#define MaxYomiAskNumber 16
|
||||
|
||||
#define DouonBlkSizeNumber 3
|
||||
|
||||
#define DouonBlkTerm 0xff
|
||||
#define HinsiBlkTerm 0xff
|
||||
|
||||
#define NormalKanjiMask 0x7f
|
||||
#define SS3Kanji 0x0080
|
||||
#define ZenHiraAssyuku 0x80
|
||||
#define OffsetAssyuku 0x90
|
||||
#define ZenKataAssyuku 0xa0
|
||||
#define AiAttribute 0xb0
|
||||
#define KanjiAssyuku 0xc0
|
||||
#define LeadingHankaku 0xd0
|
||||
#define KanjiStrEnd 0x00
|
||||
#define IsAssyuku 0x80
|
||||
#define AssukuUse2byte 0x90
|
||||
#define KnjAssyukuMask 0x0f
|
||||
#define KanjiCodeMask 0x0f
|
||||
#define KanjiModeMask 0xf0
|
||||
#define AtrMsKanjiOfs 0xc0c0
|
||||
|
||||
|
||||
#define MaxHindoNumber 2000
|
||||
#define MaxOffsetNumber 1000
|
||||
|
||||
#define IllegalFormat "\245\325\245\251\241\274\245\336\245\303\245\310\244\254\260\333\276\357\244\307\244\271"
|
||||
#define TooLongYomi "\306\311\244\337\312\270\273\372\316\363\244\254\304\271\244\271\244\256\244\336\244\271"
|
||||
#define TooLongKanji "\264\301\273\372\312\270\273\372\316\363\244\254\304\271\244\271\244\256\244\336\244\271"
|
||||
#define TooLongHinsi "\311\312\273\354\312\270\273\372\316\363\244\254\304\271\244\271\244\256\244\336\244\271"
|
||||
#define TooLongGroup "\245\260\245\353\241\274\245\327\314\276\244\254\260\333\276\357\244\307\244\271"
|
||||
#define TooLongJosi "\275\365\273\354\312\270\273\372\316\363\244\254\260\333\276\357\244\307\244\271"
|
||||
#define BadHinsi "\305\320\317\277\244\265\244\354\244\306\244\244\244\312\244\244\311\312\273\354\244\307\244\271"
|
||||
#define BadGroup "\305\320\317\277\244\265\244\354\244\306\244\244\244\312\244\244\245\260\245\353\241\274\245\327\244\307\244\271"
|
||||
#define BadJosi "\305\320\317\277\244\265\244\354\244\306\244\244\244\312\244\244\275\365\273\354\244\307\244\271"
|
||||
#define NoYomiString "\306\311\244\337\312\270\273\372\316\363\244\254\274\350\306\300\244\307\244\255\244\336\244\273\244\363"
|
||||
#define NoKanjiString "\264\301\273\372\312\270\273\372\316\363\244\254\274\350\306\300\244\307\244\255\244\336\244\273\244\363"
|
||||
#define TooManyAtr "\302\260\300\255\244\316\277\364\244\254\302\277\244\271\244\256\244\336\244\271"
|
||||
#define TooManyHinsi "\311\312\273\354\244\316\277\364\244\254\302\277\244\271\244\256\244\336\244\271"
|
||||
#define TooManyJosi "\275\365\273\354\244\316\277\364\244\254\302\277\244\271\244\256\244\336\244\271"
|
||||
#define NoDataInMain "\245\341\245\244\245\363\274\255\275\361\244\313\302\270\272\337\244\267\244\336\244\273\244\363"
|
||||
#define TooManyTarget "\311\312\273\354\244\362\243\261\244\304\273\330\304\352\244\267\244\306\244\257\244\300\244\265\244\244"
|
||||
|
||||
#define HinsiTankan cnvhinsi("\303\261\264\301")
|
||||
|
||||
#define FALSE 0
|
||||
#define TRUE (!FALSE)
|
||||
|
||||
#define DIVLIST 1
|
||||
#define ASSYUKUREC 2
|
||||
#define STRING 3
|
||||
#define HINDOREC 4
|
||||
#define OFFSETREC 5
|
||||
#define KANJIREC 6
|
||||
#define HINSIREC 7
|
||||
#define DOUONREC 8
|
||||
|
||||
#endif
|
||||
49
sj3mkdic/sj_macro.h
Normal file
49
sj3mkdic/sj_macro.h
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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: sj_macro.h,v $
|
||||
* $SonyRevision: 1.1 $
|
||||
* $SonyDate: 1994/06/03 08:00:25 $
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifndef _MACRO_
|
||||
#define _MACRO_
|
||||
|
||||
#define Isblank(c) ((c) == 0x20 || (c) == 0x09 || (c) == 0xa1a1)
|
||||
|
||||
#define Isillegal(c) ((c) < 0x20)
|
||||
|
||||
#endif
|
||||
102
sj3mkdic/sj_struct.h
Normal file
102
sj3mkdic/sj_struct.h
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* 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: sj_struct.h,v $
|
||||
* $SonyRevision: 1.1 $
|
||||
* $SonyDate: 1994/06/03 08:00:26 $
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include "sj_const.h"
|
||||
|
||||
#ifndef _STRUCT_
|
||||
#define _STRUCT_
|
||||
|
||||
|
||||
|
||||
typedef struct kanji_rec {
|
||||
int klen;
|
||||
u_char *kptr;
|
||||
int alen;
|
||||
u_char *aptr;
|
||||
struct kanji_rec *knext;
|
||||
} KanjiRec;
|
||||
|
||||
|
||||
|
||||
typedef struct hinsi_rec {
|
||||
int hinsi;
|
||||
KanjiRec *krec;
|
||||
struct hinsi_rec *hnext;
|
||||
} HinsiRec;
|
||||
|
||||
|
||||
|
||||
typedef struct douon_rec {
|
||||
u_char *yptr;
|
||||
int dlen;
|
||||
int hrec_num;
|
||||
HinsiRec *hrec;
|
||||
struct douon_rec *dnext;
|
||||
} DouonRec;
|
||||
|
||||
|
||||
|
||||
typedef struct hindo_rec {
|
||||
int klen;
|
||||
u_char *kptr;
|
||||
int exist;
|
||||
int hindo;
|
||||
|
||||
int offset;
|
||||
|
||||
struct hindo_rec *anext;
|
||||
struct assyuku_rec *arec;
|
||||
} HindoRec;
|
||||
|
||||
|
||||
|
||||
typedef struct assyuku_rec {
|
||||
int len;
|
||||
HindoRec *nrec;
|
||||
struct assyuku_rec *anext;
|
||||
} AssyukuRec;
|
||||
|
||||
|
||||
|
||||
typedef struct offset_rec {
|
||||
int klen;
|
||||
u_char *kptr;
|
||||
int offset;
|
||||
} OffsetRec;
|
||||
|
||||
#endif
|
||||
217
sj3mkdic/string.c
Normal file
217
sj3mkdic/string.c
Normal file
|
|
@ -0,0 +1,217 @@
|
|||
/*
|
||||
* 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 $
|
||||
*
|
||||
* $id$
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include "sj_const.h"
|
||||
#include "dicttool.h"
|
||||
|
||||
|
||||
int
|
||||
bubun_str(u_char* p1, int l1, u_char* p2, int l2)
|
||||
{
|
||||
u_char *p;
|
||||
int l;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
overlap_str(u_char *p1, int l1, u_char* p2, int l2)
|
||||
{
|
||||
u_char *p;
|
||||
int l;
|
||||
int i;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
size_t
|
||||
istrlen(int* s)
|
||||
{
|
||||
int *p;
|
||||
|
||||
for (p = s ; *p ; p++) ;
|
||||
|
||||
return(p - s);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
istrcmp(int* s, int* d)
|
||||
{
|
||||
for ( ; *s && (*s == *d) ; s++, d++) ;
|
||||
|
||||
return (*s - *d);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
top_strcmp(int* src, int* dst)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
|
||||
for (i = 0 ; *src && (*src == *dst) ; src++, dst++)
|
||||
i++;
|
||||
|
||||
|
||||
return (i > MaxYomiAskNumber) ? MaxYomiAskNumber : i;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
last_strcmp(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;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
string_cmp(u_char* p1, int l1, u_char* p2, 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