This commit is contained in:
iratqq 2008-01-11 11:57:08 +00:00
commit 149a0ba1d9
284 changed files with 125357 additions and 0 deletions

6
trunk/src/Makefile.am Normal file
View file

@ -0,0 +1,6 @@
SUBDIRS = \
sj3mkdic \
sj3serv \
sj3dic \
sj3stat \
sj3demo

View file

@ -0,0 +1,20 @@
if BUILDABLE_SJ3DEMO
INCLUDES = \
-I$(top_srcdir)/include/sj3compat \
-I$(top_srcdir)/include/sj3common \
-I$(top_srcdir)/include/sj3lib \
-I$(top_srcdir)/include/sj3rkcv
LDADD = \
$(top_srcdir)/lib/sj3lib/libsj3lib.la \
$(top_srcdir)/lib/sj3rkcv/libsj3rkcv.la \
$(top_srcdir)/lib/sj3compat/libsj3compat.la
AM_CPPFLAGS= -DORG
sj3demo_SOURCES = sj3demo.c
bin_PROGRAMS = sj3demo
endif

359
trunk/src/sj3demo/sj3demo.c Normal file
View file

@ -0,0 +1,359 @@
/*
* Copyright (c) 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: sample.c,v $
* $SonyRevision: 1.3 $
* $SonyDate: 1997/01/23 11:26:29 $
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <locale.h>
#include <pwd.h>
#include <unistd.h>
#include "sj3lib.h"
#include "wchar16.h"
#include "sj3rkcv.h"
#include "config.h"
#define RETURN(c) ((c == '\n') || (c == '\r'))
/*
* Change a default value.
* Patched by Hidekazu Kuroki(hidekazu@cs.titech.ac.jp) 1996/8/10
*/
#define RKFILE SJ3CONFDIR "/sjrk"
#define LOCALHOST "localhost"
#define HBUFSIZ 512
#define QBUFSIZ 256
char *pname;
char *hname;
int current_locale = LC_CTYPE_EUC;
void rkconvs(unsigned char *, unsigned char *);
void print_head();
void pr_douon(unsigned char *);
void pr_bunsetu(struct bunsetu *, int);
void pr_kanji(struct bunsetu *, int);
usage()
{
fprintf(stderr, "Usage: %s [-v] [-H hostname]\n", pname);
exit(1);
}
int
main(int argc, char **argv)
{
int c;
int ret;
int vflag;
struct bunsetu bun[HBUFSIZ];
unsigned char alphabet[QBUFSIZ];
unsigned char yomi[HBUFSIZ];
unsigned char kanji[BUFSIZ];
char *uname, *loc;
struct passwd *pwd;
int count=1;
loc = setlocale(LC_CTYPE, "");
if (strcmp(loc, "ja_JP.SJIS") == 0) {
current_locale = LC_CTYPE_SHIFTJIS;
} else if (strncmp(loc, "ja", 2) != 0 &&
strncmp(loc, "Ja", 2) != 0) {
fprintf(stderr, "Error: %s is not japanese locale\n", loc);
exit(1);
}
vflag = 0;
hname = NULL;
print_head();
pname = argv[0];
while ((c = getopt(argc, argv, "vk:H:")) != EOF) {
switch(c) {
case 'v':
vflag++;
break;
case 'H':
hname = optarg;
break;
case 'k':
fprintf(stderr, "optarg = %s\n", optarg);
count = atoi(optarg);
break;
case '?':
default :
usage();
break;
}
}
uname = getlogin();
if (uname == NULL || *uname == '\0') {
setpwent();
if ((pwd = getpwuid(getuid())) != NULL) {
uname = pwd->pw_name;
endpwent();
} else {
fprintf(stderr, "Can't get user name\n");
exit(1);
}
}
#ifndef ORG
while (count--) {
#endif
if ((ret = sj3_rkinit(RKFILE)) != 0) {
if (ret == 1)
fprintf(stderr, "Can't open Romaji Kana Rule file %s\n",
RKFILE);
else
fprintf(stderr, "Error sj3_rkinit\n");
exit(1);
}
ret = sj3_open(hname, uname);
if (hname == NULL)
hname = LOCALHOST;
if (ret != 0) {
if (ret & SJ3_SERVER_DEAD) {
fprintf(stderr, "%s:sj3serv dead\n", hname);
exit(1);
}
else if (ret & SJ3_ALREADY_CONNECTED) {
fprintf(stderr, "Already connected %s:sj3serv\n",hname);
exit(1);
}
else if (ret & SJ3_CONNECT_ERROR) {
fprintf(stderr, "Can't connect %s:sj3serv\n", hname);
exit(1);
}
else if (ret & SJ3_CANNOT_OPEN_MDICT) {
fprintf(stderr, "Can't open sj3 main dictionary\n");
(void)sj3_close();
exit(1);
}
fprintf(stderr, "Warning sj3_open error (return 0x%x)\n", ret);
}
#ifdef ORG
while (1) {
fprintf(stdout, "[Input Alphabet] ");
if (fgets((char *)alphabet, QBUFSIZ, stdin) == NULL)
break;
if (RETURN(alphabet[0]))
break;
#else
strlcpy(alphabet, "tonarinokyakuhayokukakikuukyakuda", sizeof(alphabet));
#endif
rkconvs(yomi, alphabet);
ret = sj3_getkan_mb(yomi, bun, kanji, BUFSIZ);
if (ret == -1) {
fprintf(stderr, "sj3_getkan: disconnected %s:sj3serv\n",
hname);
exit(1);
}
if (vflag)
pr_kanji(bun, ret);
if (bun[ret - 1].destlen == 0)
strlcat(kanji, bun[ret - 1].srcstr, sizeof(kanji));
fprintf(stdout, "[Output Yomi ]:[%s]\n", yomi);
fprintf(stdout, "[Output Kanji]:[%s]\n", kanji);
#ifdef ORG
}
#endif
(void)sj3_close();
#ifndef ORG
}
#endif
}
void
rkconvs(unsigned char *yomi, unsigned char *roma)
{
unsigned char *p, *q, *yp;
int i;
int rlen;
int len;
unsigned char rbuf[16];
unsigned char ybuf[32];
unsigned char tmp[HBUFSIZ];
yp = tmp;
p = rbuf;
rlen = 0;
while (*roma != '\0' && !RETURN(*roma)) {
*p++ = *roma++;
*p = '\0';
rlen++;
while(1) {
if ((len = sj3_rkconv_mb(rbuf, ybuf)) > 0) {
q = ybuf;
while (*q != '\0') {
*yp++ = *q++;
}
i = rlen;
rlen = strlen(rbuf);
p = rbuf;
p += rlen;
if (len >= i)
break;
}
else if (len < 0) {
*yp++ = rbuf[0];
p = rbuf;
q = (p + 1);
while(*q != '\0')
*p++ = *q++;
*p = '\0';
rlen--;
}
else
break;
}
}
if (rlen > 0) {
*p++ = '\n';
*p = '\0';
rlen++;
while(rbuf[0] != '\0') {
if ((len = sj3_rkconv_mb(rbuf, ybuf)) > 0) {
q = ybuf;
while (*q != '\0') {
*yp++ = *q++;
}
rlen = strlen(rbuf);
p = rbuf;
p += rlen;
}
else {
*yp++ = rbuf[0];
p = rbuf;
q = (p + 1);
while(*q != '\0')
*p++ = *q++;
*p = '\0';
}
}
yp--;
}
*yp = '\0';
sj3_hantozen_mb(yomi, tmp);
}
void
print_head()
{
fprintf(stdout, "\t*--------------------------------------------*\n");
fprintf(stdout, "\t* Sample Program for *\n");
fprintf(stdout, "\t* New Japanese Convert Library *\n");
fprintf(stdout, "\t* SJ3LIB *\n");
fprintf(stdout, "\t* *\n");
fprintf(stdout, "\t* Terminator of Input : Newline-code *\n");
fprintf(stdout, "\t* *\n");
fprintf(stdout, "\t* If you want to end this process, *\n");
fprintf(stdout, "\t* input Newline-code or Control-D. *\n");
fprintf(stdout, "\t*--------------------------------------------*\n");
}
void
pr_douon(unsigned char *yomi)
{
int i;
struct douon douon[BUFSIZ];
int douon_cnt;
douon_cnt = sj3_getdouon_mb(yomi, douon);
if (douon_cnt < 0) {
fprintf(stderr, "sj3_getdouon: disconnected %s:sj3serv\n",
hname);
exit(1);
}
fprintf(stdout, "\t\tsj3_getdouon(yomi, douon)");
fprintf(stdout, "...Douon count : %d\n", douon_cnt);
for (i = 0; i < douon_cnt; i++) {
fprintf(stdout, "\t\t--- * Douon : %d * ---\n", i);
fprintf(stdout, "\t\t\tdlen : %d\n", douon[i].dlen);
fprintf(stdout, "\t\t\tddata:[%s]\n",douon[i].ddata);
}
}
void
pr_bunsetu(struct bunsetu *now_bun, int bunsetu_cnt)
{
unsigned char tmp_str[BUFSIZ];
unsigned char *yomi;
fprintf(stdout, "\t--- < Bunsetu : %d > ---\n", bunsetu_cnt);
fprintf(stdout, "\t\tsrclen : %d\n", now_bun->srclen);
strlcpy(tmp_str, now_bun->srcstr, sizeof(tmp_str));
fprintf(stdout, "\t\tsrcstr:[%s]\n", tmp_str);
yomi = tmp_str;
if (now_bun->destlen > 0)
pr_douon(yomi);
else
fprintf(stderr, "\t\tNot Conversion Bunsetsu\n");
fprintf(stdout, "\t\tdestlen : %d\n", now_bun->destlen);
strlcpy(tmp_str, now_bun->deststr, sizeof(tmp_str));
fprintf(stdout, "\t\tdeststr:[%s]\n", tmp_str);
}
void
pr_kanji(struct bunsetu *bun, int bnum)
{
int i;
fprintf(stdout, "\tsj3_getkan(yomi, kanji)");
fprintf(stdout, "...Bunsetu count : %d\n", bnum);
for (i = 0; i < bnum; i++)
pr_bunsetu(&(bun[i]), i);
}

View file

@ -0,0 +1,26 @@
if BUILDABLE_SJ3CLIENT
INCLUDES = \
-I$(top_srcdir)/include/sj3compat \
-I$(top_srcdir)/include/sj3common \
-I$(top_srcdir)/include/sj3lib
LDADD = \
$(top_srcdir)/lib/sj3lib/libsj3lib.la \
$(top_srcdir)/lib/sj3compat/libsj3compat.la
sj3dic_SOURCES = \
sj3dic.h \
sjctype.h \
sjtool.h \
codecnv.c \
dictdisp.c \
dictmake.c \
hinsi.c \
sj3dic.c \
sj3err.c \
sjrc.c
bin_PROGRAMS = sj3dic
endif

158
trunk/src/sj3dic/codecnv.c Normal file
View file

@ -0,0 +1,158 @@
/*
* 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: codecnv.c,v $
* $SonyRevision: 1.3 $
* $SonyDate: 1997/01/23 11:26:31 $
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#include <locale.h>
#include "sjctype.h"
#include "sjtool.h"
#include "sj3dic.h"
#include "sj_string.h"
static int euc_mode;
int
init_code()
{
char *loc;
loc = setlocale(LC_CTYPE, "");
if (!loc) {
fprintf(stderr, "Error: can't get current locale\n");
exit(1);
}
if (strncmp(loc, "ja_JP.SJIS", 10) == 0) {
euc_mode = 0;
} else if (strncmp(loc, "ja", 2) == 0 ||
strncmp(loc, "Ja", 2) == 0) {
euc_mode = -1;
} else
#ifdef __sony_news
return 0;
#else
{
fprintf(stderr, "Warrning: In this locale japanese will not be used.\n");
euc_mode = -1;
}
#endif
return 1;
}
void
cnvcode(unsigned char *s)
{
if (euc_mode) {
unsigned short i;
unsigned char *d = s;
while (i = *s++) {
if (iseuckana(i)) {
if (*s) {
*d++ = *s++;
}
else {
*d++ = i;
break;
}
}
else if (iseuc(i)) {
if (*s) {
i = euc2sjis((i << 8) + *s++);
*d++ = (i >> 8);
*d++ = i;
}
else {
*d++ = i;
break;
}
}
else {
*d++ = i;
}
}
*d = 0;
}
}
void
printout_mb(FILE *fp, unsigned char *s)
{
fputs((char *)s, fp);
fflush(fp);
}
void
printout(FILE *fp, unsigned char *s)
{
unsigned char buf[BUFSIZ];
if (euc_mode)
strlcpy((char *)buf, s, sizeof(buf));
else
euctosjis(buf, BUFSIZ, s, strlen(s)+1);
fputs((char *)buf, fp);
fflush(fp);
}
void
normal_out(char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
printout(stdout, buf);
}
void
error_out(char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
strlcat(buf, "\n", sizeof(buf));
printout(stderr, buf);
}

View file

@ -0,0 +1,99 @@
/*
* 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: dictdisp.c,v $
* $SonyRevision: 1.1 $
* $SonyDate: 1994/06/03 08:03:34 $
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "sj3lib.h"
#include "sj3dic.h"
void
dictdisp(char *output)
{
unsigned char buf[BUFSIZ];
unsigned char *p;
FILE *fp;
int flg;
int i;
if (output && *output) {
fp = fopen(output, "w");
if (!fp) {
error_out("%s \244\254\245\252\241\274\245\327\245\363\244\307\244\255\244\336\244\273\244\363", output);
exit(1);
}
}
else
fp = stdout;
flg = sj3_getdict_mb(buf);
while (flg == 0) {
p = buf;
printout_mb(fp, p);
i = strlen(p);
if (i < 24)
while (i < 24) {
printout_mb(fp, "\t");
i += 8;
}
else
printout_mb(fp, " ");
while (*p++)
;
printout_mb(fp, p);
i = strlen(p);
if (i < 24)
while (i < 24) {
printout_mb(fp, "\t");
i += 8;
}
else
printout_mb(fp, " ");
while (*p++)
;
printout(fp, hns2str(*p));
printout_mb(fp, ":\n");
flg = sj3_nextdict_mb(buf);
}
if (fp != stdout)
fclose(fp);
}

227
trunk/src/sj3dic/dictmake.c Normal file
View file

@ -0,0 +1,227 @@
/*
* 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: dictmake.c,v $
* $SonyRevision: 1.1 $
* $SonyDate: 1994/06/03 08:03:35 $
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "sjctype.h"
#include "sj3lib.h"
#include "sjtool.h"
#include "sj3dic.h"
#include "sj_string.h"
#define IsEOL(c) ((c) == '\0')
#define IsBlank(c) ((c) == ' ' || (c) == '\t')
static void
touroku(char *y, char *k, char *h)
{
int err;
int grm;
unsigned char buf[BUFSIZ], *hp;
if (sj3dic_sys_code == SYS_SJIS) {
(void) sjistoeuc(buf, BUFSIZ, h, strlen(h)+1);
hp = buf;
} else {
hp = (unsigned char *) h;
}
if (!(grm = str2hns(hp))) {
error_out("\311\312\273\354\312\270\273\372\316\363\244\362\262\341\244\303\244\306\244\244\244\336\244\271 %s:%s:%s", y, k, h);
if (force_flag)
return;
exit(1);
}
err = sj3_touroku_mb(y, k, grm);
switch (err) {
case -1:
error_out("\245\265\241\274\245\320\244\254\315\356\244\301\244\336\244\267\244\277");
exit(1);
case 0:
if (verbose_flag)
normal_out("%s:%s:%s \244\362\305\320\317\277\244\267\244\336\244\267\244\277\n", y, k, h);
break;
case SJ3_DICT_ERROR:
error_out("\274\255\275\361\244\254\244\312\244\244\241\242\244\242\244\353\244\244\244\317\274\255\275\361\244\313\275\361\244\255\271\376\244\341\244\336\244\273\244\363");
exit(1);
case SJ3_DICT_LOCKED:
error_out("\274\255\275\361\244\254\245\355\245\303\245\257\244\265\244\354\244\306\244\244\244\306\275\361\244\255\271\376\244\341\244\336\244\273\244\363");
exit(1);
case SJ3_WORD_EXIST:
if (verbose_flag)
normal_out("%s:%s:%s \244\317\305\320\317\277\244\265\244\354\244\306\244\244\244\336\244\271\n", y, k, h);
break;
case SJ3_DOUON_FULL:
error_out("\244\263\244\354\260\312\276\345\306\261\262\273\270\354\244\362\305\320\317\277\244\307\244\255\244\336\244\273\244\363 %s:%s:%s", y, k, h);
break;
case SJ3_DICT_FULL:
error_out("\244\263\244\354\260\312\276\345\274\255\275\361\244\362\302\347\244\255\244\257\244\307\244\255\244\336\244\273\244\363 %s:%s:%s", y, k, h);
if (force_flag) break;
exit(1);
case SJ3_BAD_YOMI_STR:
error_out("\305\320\317\277\244\307\244\255\244\312\244\244\306\311\244\337\244\307\244\271 %s", y);
if (force_flag) break;
exit(1);
case SJ3_BAD_KANJI_STR:
error_out("\305\320\317\277\244\307\244\255\244\312\244\244\264\301\273\372\244\307\244\271 %s:%s", y, k);
if (force_flag) break;
exit(1);
case SJ3_BAD_HINSI_CODE:
error_out("\305\320\317\277\244\307\244\255\244\312\244\244\311\312\273\354\244\307\244\271 %s:%s:%s", y, k, h);
if (force_flag) break;
exit(1);
case SJ3_INDEX_FULL:
error_out("\245\244\245\363\245\307\245\303\245\257\245\271\244\254\244\244\244\303\244\321\244\244\244\307\244\271");
case SJ3_TOUROKU_FAILED:
default:
error_out("\305\320\317\277\244\307\244\255\244\336\244\273\244\363\244\307\244\267\244\277 %s:%s:%s(%d)",
y, k, h, str2hns(h));
break;
}
}
void
dictmake(char *input)
{
unsigned char buf[BUFSIZ];
FILE *fp;
unsigned char *p;
unsigned char *yom, *knj, *grm;
int c;
int flg;
static char *FormatErrorString = "\245\325\245\251\241\274\245\336\245\303\245\310\245\250\245\351\241\274:%s";
if (input && *input) {
fp = fopen(input, "r");
if (!fp) {
error_out("%s \244\254\245\252\241\274\245\327\245\363\244\307\244\255\244\336\244\273\244\363", input);
exit(1);
}
}
else
fp = stdin;
while (fgets((char *)buf, sizeof(buf), fp)) {
if (p = (unsigned char *)strchr((char *)buf, '\n'))
*p = '\0';
else {
do {
c = fgetc(fp);
} while (c != '\n' && c != EOF);
}
yom = buf;
while (IsBlank(*yom))
yom++;
if (IsEOL(*yom)) {
error_out(FormatErrorString, buf);
if (force_flag)
continue;
break;
}
knj = yom;
while (!IsEOL(*knj) && !IsBlank(*knj))
knj++;
if (IsEOL(*knj)) {
error_out(FormatErrorString, buf);
if (force_flag)
continue;
break;
}
*knj++ = '\0';
while (IsBlank(*knj))
knj++;
if (IsEOL(*knj)) {
error_out(FormatErrorString, buf);
if (force_flag)
continue;
break;
}
grm = knj;
while (!IsEOL(*grm) && !IsBlank(*grm))
grm++;
if (IsEOL(*grm)) {
error_out(FormatErrorString, buf);
if (force_flag)
continue;
break;
}
*grm++ = '\0';
while (IsBlank(*grm))
grm++;
if (IsEOL(*grm)) {
error_out(FormatErrorString, buf);
if (force_flag)
continue;
break;
}
flg = -1;
while (*grm && flg) {
p = grm;
while (!IsEOL(*p) && !IsBlank(*p) && (*p != ':'))
p++;
if (IsEOL(*p))
flg = 0;
else
*p++ = '\0';
touroku(yom, knj, grm);
if (flg) {
grm = p;
while (IsBlank(*grm))
grm++;
}
}
}
}

258
trunk/src/sj3dic/hinsi.c Normal file
View file

@ -0,0 +1,258 @@
/*
* 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: hinsi.c,v $
* $SonyRevision: 1.1 $
* $SonyDate: 1994/06/03 08:03:36 $
*/
#include "sj_hinsi.h"
#include "sj3dic.h"
static struct hlist {
int code;
char *str;
} hinsi[] = {
{ MEISI_1, "\314\276\273\354" },
{ MEISI_1, "\314\276\243\261" },
{ MEISI_2, "\314\276\243\262" },
{ MEISI_3, "\314\276\243\263" },
{ MEISI_4, "\314\276\243\264" },
{ MEISI_5, "\314\276\243\265" },
{ MEISI_6, "\314\276\243\266" },
{ MEISI_7, "\314\276\243\267" },
{ MEISI_8, "\314\276\243\270" },
{ MEISI_9, "\314\276\243\271" },
{ MEISI_10, "\314\276\243\261\243\260" },
{ MEISI_11, "\314\276\243\261\243\261" },
{ MEISI_20, "\314\276\243\262\243\260" },
{ D_MEISI_1, "\302\345\314\276\273\354" },
{ D_MEISI_1, "\302\345\243\261" },
{ D_MEISI_2, "\302\345\243\262" },
{ D_MEISI_3, "\302\345\243\263" },
{ D_MEISI_4, "\302\345\243\264" },
{ D_MEISI_5, "\302\345\243\265" },
{ D_MEISI_6, "\302\345\243\266" },
{ MYOUJI, "\311\304\273\372" },
{ NAMAE, "\314\276\301\260" },
{ KIGYOU, "\264\353\266\310" },
{ TIMEI, "\303\317\314\276" },
{ KEN_KU, "\270\251\241\277\266\350\314\276" },
{ KEN_KU, "\270\251\266\350" },
{ RENTAISI, "\317\242\302\316\273\354" },
{ RENTAISI, "\317\242\302\316" },
{ SETUZOKU, "\300\334\302\263\273\354" },
{ SETUZOKU, "\300\334\302\263" },
{ KANDOUSI, "\264\266\306\260" },
{ JOSUUSI, "\275\365\277\364\273\354" },
{ JOSUUSI, "\275\365\277\364" },
{ SUUSI, "\277\364\273\354" },
{ SETTOU_1, "\300\334\306\254\270\354" },
{ SETTOU_1, "\300\334\306\254\243\261" },
{ SETTOU_2, "\300\334\306\254\243\262" },
{ SETTOU_3, "\300\334\306\254\243\263" },
{ SETTOU_4, "\300\334\306\254\243\264" },
{ SETTOU_5, "\300\334\306\254\243\265" },
{ SETUBI_1, "\300\334\310\370\270\354" },
{ SETUBI_1, "\300\334\310\370\243\261" },
{ SETUBI_2, "\300\334\310\370\243\262" },
{ SETUBI_3, "\300\334\310\370\243\263" },
{ SETUBI_4, "\300\334\310\370\243\264" },
{ SETUBI_5, "\300\334\310\370\243\265" },
{ SETUBI_6, "\300\334\310\370\243\266" },
{ SETUBI_7, "\300\334\310\370\243\267" },
{ SETUBI_8, "\300\334\310\370\243\270" },
{ SETUBI_9, "\300\334\310\370\243\271" },
{ FUKUSI_1, "\311\373\273\354" },
{ FUKUSI_1, "\311\373\243\261" },
{ FUKUSI_2, "\311\373\243\262" },
{ FUKUSI_3, "\311\373\243\263" },
{ FUKUSI_4, "\311\373\243\264" },
{ FUKUSI_5, "\311\373\243\265" },
{ FUKUSI_6, "\311\373\243\266" },
{ FUKUSI_7, "\311\373\243\267" },
{ FUKUSI_8, "\311\373\243\270" },
{ FUKUSI_9, "\311\373\243\271" },
{ JOSUUSI2, "\275\365\277\364\243\262" },
{ KEIYOUSI_1, "\267\301\315\306\273\354" },
{ KEIYOUSI_1, "\267\301\243\261" },
{ KEIYOUSI_2, "\267\301\243\262" },
{ KEIYOUSI_3, "\267\301\243\263" },
{ KEIYOUSI_4, "\267\301\243\264" },
{ KEIYOUSI_5, "\267\301\243\265" },
{ KEIYOUSI_6, "\267\301\243\266" },
{ KEIYOUSI_7, "\267\301\243\267" },
{ KEIYOUSI_8, "\267\301\243\270" },
{ KEIYOUSI_9, "\267\301\243\271" },
{ KEIYOUSI_10, "\267\301\243\261\243\260" },
{ KEIYOUSI_11, "\267\301\243\261\243\261" },
{ KE_DOUSI_1, "\267\301\315\306\306\260\273\354" },
{ KE_DOUSI_1, "\267\301\306\260\243\261" },
{ KE_DOUSI_2, "\267\301\306\260\243\262" },
{ KE_DOUSI_3, "\267\301\306\260\243\263" },
{ KE_DOUSI_4, "\267\301\306\260\243\264" },
{ KE_DOUSI_5, "\267\301\306\260\243\265" },
{ KE_DOUSI_6, "\267\301\306\260\243\266" },
{ KE_DOUSI_7, "\267\301\306\260\243\267" },
{ KE_DOUSI_8, "\267\301\306\260\243\270" },
{ KE_DOUSI_9, "\267\301\306\260\243\271" },
{ DO_SAHEN, "\306\260\241\246\245\265\312\321" },
{ DO_SAHEN, "\245\265\312\321" },
{ DO_ZAHEN, "\306\260\241\246\245\266\312\321" },
{ DO_ZAHEN, "\245\266\312\321" },
{ DO_1DAN_1, "\306\260\241\246\260\354\303\312" },
{ DO_1DAN_1, "\260\354\303\312\243\261" },
{ DO_KAGO_1, "\306\260\241\246\245\253\270\336" },
{ DO_KAGO_1, "\245\253\270\336\243\261" },
{ DO_GAGO_1, "\306\260\241\246\245\254\270\336" },
{ DO_GAGO_1, "\245\254\270\336\243\261" },
{ DO_SAGO_1, "\306\260\241\246\245\265\270\336" },
{ DO_SAGO_1, "\245\265\270\336\243\261" },
{ DO_TAGO_1, "\306\260\241\246\245\277\270\336" },
{ DO_TAGO_1, "\245\277\270\336\243\261" },
{ DO_NAGO_1, "\306\260\241\246\245\312\270\336" },
{ DO_NAGO_1, "\245\312\270\336" },
{ DO_BAGO_1, "\306\260\241\246\245\320\270\336" },
{ DO_BAGO_1, "\245\320\270\336\243\261" },
{ DO_MAGO_1, "\306\260\241\246\245\336\270\336" },
{ DO_MAGO_1, "\245\336\270\336\243\261" },
{ DO_RAGO_1, "\306\260\241\246\245\351\270\336" },
{ DO_RAGO_1, "\245\351\270\336\243\261" },
{ DO_WAGO_1, "\306\260\241\246\245\357\270\336" },
{ DO_WAGO_1, "\245\357\270\336\243\261" },
{ DO_1DAN_2, "\260\354\303\312\243\262" },
{ DO_KAGO_2, "\245\253\270\336\243\262" },
{ DO_GAGO_2, "\245\254\270\336\243\262" },
{ DO_SAGO_2, "\245\265\270\336\243\262" },
{ DO_TAGO_2, "\245\277\270\336\243\262" },
{ DO_BAGO_2, "\245\320\270\336\243\262" },
{ DO_MAGO_2, "\245\336\270\336\243\262" },
{ DO_RAGO_2, "\245\351\270\336\243\262" },
{ DO_WAGO_2, "\245\357\270\336\243\262" },
{ DO_KAGO_5, "\245\253\270\336\243\265" },
{ DO_GAGO_5, "\245\254\270\336\243\265" },
{ DO_SAGO_5, "\245\265\270\336\243\265" },
{ DO_TAGO_5, "\245\277\270\336\243\265" },
{ DO_BAGO_5, "\245\320\270\336\243\265" },
{ DO_MAGO_5, "\245\336\270\336\243\265" },
{ DO_RAGO_5, "\245\351\270\336\243\265" },
{ DO_WAGO_5, "\245\357\270\336\243\265" },
{ DO_KAGO_6, "\245\253\270\336\243\266" },
{ DO_GAGO_6, "\245\254\270\336\243\266" },
{ DO_SAGO_6, "\245\265\270\336\243\266" },
{ DO_TAGO_6, "\245\277\270\336\243\266" },
{ DO_BAGO_6, "\245\320\270\336\243\266" },
{ DO_MAGO_6, "\245\336\270\336\243\266" },
{ DO_RAGO_6, "\245\351\270\336\243\266" },
{ DO_WAGO_6, "\245\357\270\336\243\266" },
{ DO_1DAN_3, "\260\354\303\312\243\263" },
{ DO_KAGO_3, "\245\253\270\336\243\263" },
{ DO_GAGO_3, "\245\254\270\336\243\263" },
{ DO_SAGO_3, "\245\265\270\336\243\263" },
{ DO_TAGO_3, "\245\277\270\336\243\263" },
{ DO_BAGO_3, "\245\320\270\336\243\263" },
{ DO_MAGO_3, "\245\336\270\336\243\263" },
{ DO_RAGO_3, "\245\351\270\336\243\263" },
{ DO_WAGO_3, "\245\357\270\336\243\263" },
{ DO_1DAN_4, "\260\354\303\312\243\264" },
{ DO_KAGO_4, "\245\253\270\336\243\264" },
{ DO_GAGO_4, "\245\254\270\336\243\264" },
{ DO_SAGO_4, "\245\265\270\336\243\264" },
{ DO_TAGO_4, "\245\277\270\336\243\264" },
{ DO_BAGO_4, "\245\320\270\336\243\264" },
{ DO_MAGO_4, "\245\336\270\336\243\264" },
{ DO_RAGO_4, "\245\351\270\336\243\264" },
{ DO_WAGO_4, "\245\357\270\336\243\264" },
{ DO_KAGO_7, "\245\253\270\336\243\267" },
{ DO_GAGO_7, "\245\254\270\336\243\267" },
{ DO_SAGO_7, "\245\265\270\336\243\267" },
{ DO_TAGO_7, "\245\277\270\336\243\267" },
{ DO_BAGO_7, "\245\320\270\336\243\267" },
{ DO_MAGO_7, "\245\336\270\336\243\267" },
{ DO_RAGO_7, "\245\351\270\336\243\267" },
{ DO_WAGO_7, "\245\357\270\336\243\267" },
{ DO_KAGO_8, "\245\253\270\336\243\270" },
{ DO_GAGO_8, "\245\254\270\336\243\270" },
{ DO_SAGO_8, "\245\265\270\336\243\270" },
{ DO_TAGO_8, "\245\277\270\336\243\270" },
{ DO_BAGO_8, "\245\320\270\336\243\270" },
{ DO_MAGO_8, "\245\336\270\336\243\270" },
{ DO_RAGO_8, "\245\351\270\336\243\270" },
{ DO_WAGO_8, "\245\357\270\336\243\270" },
{ SP_SA_MI1, "\245\265\312\321\314\244\243\261" },
{ SP_SA_MI2, "\245\265\312\321\314\244\243\262" },
{ SP_SA_YOU, "\245\265\312\321\314\244\315\321" },
{ SP_SA_SYU, "\245\265\312\321\275\252\302\316" },
{ SP_SA_KAT, "\245\265\312\321\262\276" },
{ SP_SA_ME1, "\245\265\312\321\314\277\243\261" },
{ SP_SA_ME2, "\245\265\312\321\314\277\243\262" },
{ SP_KA_MIZ, "\245\253\312\321\314\244" },
{ SP_KA_YOU, "\245\253\312\321\315\321" },
{ SP_KA_SYU, "\245\253\312\321\275\252\302\316" },
{ SP_KA_KAT, "\245\253\312\321\262\276" },
{ SP_KA_MEI, "\245\253\312\321\314\277" },
{ TEINEI1, "\303\372\307\253\243\261" },
{ TEINEI2, "\303\372\307\253\243\262" },
{ SP_KA_ONB, "\245\253\270\336\262\273\312\330" },
{ SP_FUKUSI, "\306\303\274\354\311\373" },
{ AISATU, "\260\247\273\242" },
{ SP_KEIYOUSI, "\306\303\274\354\267\301\315\306" },
{ TANKANJI, "\303\261\264\301\273\372" },
{ TANKANJI, "\303\261\264\301" },
{ IKKATU, "\260\354\263\347" },
{ 0, 0 }
};
char *
hns2str(int code)
{
struct hlist *p;
for (p = hinsi ; p -> code ; p++) {
if (p -> code == code)
return p -> str;
}
return "ERROR";
}
int
str2hns(char *str)
{
struct hlist *p;
for (p = hinsi ; p -> code ; p++) {
if (strcmp(p -> str, str) == 0)
return p -> code;
}
return 0;
}

333
trunk/src/sj3dic/sj3dic.c Normal file
View file

@ -0,0 +1,333 @@
/*
* 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: sj3dic.c,v $
* $SonyRevision: 1.2 $
* $SonyDate: 1996/02/15 02:22:58 $
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <pwd.h>
#include <locale.h>
#include <unistd.h>
#include "sj3dic.h"
#include "sjtool.h"
#include "sj3lib.h"
static void sj3dic_open_error(int);
static void sj3dic_close_error(int);
#ifdef __sony_news
int sj3dic_sys_code = _sys_code;
#else
int sj3dic_sys_code = SYS_EUC;
#endif
#ifndef lint
static char rcsid_sony[] = "$Header: /export/work/contrib/sj3/sj3dic/RCS/sj3dic.c,v 1.11 1994/06/03 07:41:59 notanaka Exp $ SONY;";
#endif
static struct option {
char *str;
int code;
} options[] = {
{ "text", EXEC_TEXT },
{ "dict", EXEC_DICT },
{ "init", EXEC_INIT },
{ "verbose", EXEC_VERBOSE },
{ "host", EXEC_SERVER },
{ "server", EXEC_SERVER },
{ "force", EXEC_FORCE },
{ 0, 0 }
};
char prog_name[LONGLENGTH];
char home_dir[LONGLENGTH];
char user_name[LONGLENGTH];
char term_name[LONGLENGTH];
char serv_name[LONGLENGTH];
char file_name[LONGLENGTH];
char dict_name[LONGLENGTH];
int verbose_flag = 0;
int init_flag = 0;
int force_flag = 0;
int
main(int argc, char **argv)
{
int err;
int mode;
if (!init_code()) {
fprintf(stderr, "Can't excute on this locale\n");
exit(1);
}
init_env();
mode = parsearg(argc, argv);
setsjserv(getenv("SJ3SERV"));
getsjrc();
make_dicname();
if (err = sj3_open(serv_name, user_name))
sj3dic_open_error(err);
switch (mode) {
case EXEC_TEXT:
dictdisp(file_name);
break;
case EXEC_DICT:
dictmake(file_name);
break;
default:
break;
}
if ((err = sj3_close()) != TRUE)
sj3dic_close_error(err);
return 0;
}
void
init_env()
{
char *un, *hp, *tn;
struct passwd *pwd;
prog_name[0] =
home_dir[0] =
user_name[0] =
term_name[0] =
serv_name[0] =
file_name[0] =
dict_name[0] = '\0';
un = getlogin();
hp = getenv("HOME");
setpwent();
pwd = (un == NULL || *un == '\0') ? getpwuid(getuid()) : getpwnam(un);
if (pwd != NULL) {
strlcpy(user_name, pwd -> pw_name, sizeof(user_name));
if (hp == NULL)
hp = pwd -> pw_dir;
endpwent();
}
if (hp != NULL)
strlcpy(home_dir, hp, sizeof(home_dir));
if ((tn = getenv("TERM")) == NULL) {
fprintf(stderr, "Can't getenv TERM\n\r");
perror("getenv");
exit(1);
}
strlcpy(term_name, tn, sizeof(term_name));
}
void
usage(int ret)
{
fprintf(stderr,
"Usage: %s -{text|dict} [-H host_name] [file_name]\n",
prog_name);
exit(ret);
}
int
parsearg(int argc, char *argv[])
{
int errflg = 0;
int i, j;
char *p, *q;
struct option *opt;
int cmd;
int mode = 0;
char tmp[LONGLENGTH];
strlcpy(prog_name, (p = strrchr(argv[0], '/')) ? p + 1 : argv[0], sizeof(prog_name));
for (i = 1 ; i < argc ; i++) {
if (*argv[i] == '-') {
for (p = argv[i]+1, q = tmp ; *p ; p++)
*q++ = isupper(*p) ? tolower(*p) : *p;
*q = 0;
j = strlen(tmp);
cmd = 0;
for (opt = options ; opt -> code ; opt++) {
if (strncmp(opt -> str, tmp, j))
continue;
else if (cmd) {
errflg++; break;
}
else
cmd = opt -> code;
}
if (errflg)
break;
if (cmd == 0) {
errflg++;
break;
}
switch (cmd) {
case EXEC_TEXT:
case EXEC_DICT:
if (mode)
errflg++;
else
mode = cmd;
break;
case EXEC_INIT:
init_flag++;
break;
case EXEC_VERBOSE:
verbose_flag++;
break;
case EXEC_SERVER:
if (++i >= argc) {
errflg++;
break;
}
setsjserv(argv[i]);
break;
case EXEC_FORCE:
force_flag++;
break;
default:
errflg++;
break;
}
}
else if (file_name[0]) {
errflg++;
break;
}
else
strlcpy(file_name, argv[i], sizeof(file_name));
}
if (errflg || (mode == 0))
usage(1);
return mode;
}
void
make_dicname()
{
if (dict_name[0] != '\0')
return;
snprintf(dict_name, sizeof(dict_name), "%s/sj2usr.dic", home_dir);
}
void
setdicname(char *dictname)
{
if (dict_name[0] != '\0' || dictname == NULL)
return;
strlcpy(dict_name, dictname, sizeof(dict_name));
}
void
setsjserv(char *hostname)
{
if (serv_name[0] != '\0' || hostname == NULL)
return;
strlcpy(serv_name, hostname, sizeof(serv_name));
}
struct errlist {
int code;
char *msg;
int flg;
};
static void
sj3dic_error_and(int err, struct errlist *list)
{
int flag = 0;
while (list -> code) {
if (err & list -> code) {
error_out(list -> msg);
err &= ~(list -> code);
if (list -> flg)
flag++;
}
list++;
}
if (flag)
exit(1);
}
static void
sj3dic_open_error(int err)
{
static struct errlist err_msg[] = {
{ SJ3_SERVER_DEAD, "\245\265\241\274\245\320\244\254\273\340\244\363\244\307\244\244\244\336\244\271", 1 },
{ SJ3_CONNECT_ERROR, "\245\265\241\274\245\320\244\310\300\334\302\263\244\307\244\255\244\336\244\273\244\363\244\307\244\267\244\277", 1 },
{ SJ3_ALREADY_CONNECTED, "\245\265\241\274\245\320\244\310\300\334\302\263\272\321\244\307\244\271", 1 },
{ SJ3_CANNOT_OPEN_MDICT, "\245\341\245\244\245\363\274\255\275\361\244\254\245\252\241\274\245\327\245\363\244\307\244\255\244\336\244\273\244\363", 0 },
{ SJ3_CANNOT_OPEN_UDICT, "\245\346\241\274\245\266\274\255\275\361\244\254\245\252\241\274\245\327\245\363\244\307\244\255\244\336\244\273\244\363", 1 },
{ SJ3_CANNOT_OPEN_STUDY, "\263\330\275\254\245\325\245\241\245\244\245\353\244\254\245\252\241\274\245\327\245\363\244\307\244\255\244\336\244\273\244\363", 0 },
{ SJ3_CANNOT_MAKE_UDIR, "\245\346\241\274\245\266\241\274\245\307\245\243\245\354\245\257\245\310\245\352\244\254\272\356\300\256\244\307\244\255\244\336\244\273\244\363", 1 },
{ SJ3_CANNOT_MAKE_UDICT, "\245\346\241\274\245\266\274\255\275\361\244\254\272\356\300\256\244\307\244\255\244\336\244\273\244\363", 1 },
{ SJ3_CANNOT_MAKE_STUDY, "\263\330\275\254\245\325\245\241\245\244\245\353\244\254\272\356\300\256\244\307\244\255\244\336\244\273\244\363", 0 },
{ -1, "\245\250\245\351\241\274", 1 },
{ 0, 0, 0 }
};
sj3dic_error_and(err, err_msg);
}
static void
sj3dic_close_error(int err)
{
static struct errlist err_msg[] = {
{ SJ3_SERVER_DEAD, "\245\265\241\274\245\320\241\274\244\254\273\340\244\363\244\307\244\244\244\336\244\271", 1 },
{ SJ3_DISCONNECT_ERROR, "\300\332\244\352\312\374\244\267\244\307\245\250\245\351\241\274\244\254\244\242\244\352\244\336\244\267\244\277", 1 },
{ SJ3_NOT_CONNECTED, "\245\265\241\274\245\320\244\310\300\334\302\263\244\265\244\354\244\306\244\244\244\336\244\273\244\363", 1 },
{ SJ3_NOT_OPENED_MDICT, "\245\341\245\244\245\363\274\255\275\361\244\317\245\252\241\274\245\327\245\363\244\265\244\354\244\306\244\244\244\336\244\273\244\363", 0 },
{ SJ3_NOT_OPENED_UDICT, "\245\346\241\274\245\266\274\255\275\361\244\317\245\252\241\274\245\327\245\363\244\265\244\354\244\306\244\244\244\336\244\273\244\363", 1 },
{ SJ3_NOT_OPENED_STUDY, "\263\330\275\254\245\325\245\241\245\244\245\353\244\317\245\252\241\274\245\327\245\363\244\265\244\354\244\306\244\244\244\336\244\273\244\363", 0 },
{ SJ3_CLOSE_MDICT_ERROR, "\245\341\245\244\245\363\274\255\275\361\244\254\245\257\245\355\241\274\245\272\244\307\244\255\244\336\244\273\244\363", 0 },
{ SJ3_CLOSE_UDICT_ERROR, "\245\346\241\274\245\266\274\255\275\361\244\254\245\257\245\355\241\274\245\272\244\307\244\255\244\336\244\273\244\363", 1 },
{ SJ3_CLOSE_STUDY_ERROR, "\263\330\275\254\245\325\245\241\245\244\245\353\244\254\245\257\245\355\241\274\245\272\244\307\244\255\244\336\244\273\244\363", 0 },
{ -1, "\245\250\245\351\241\274", 1 },
{ 0, 0, 0 }
};
sj3dic_error_and(err, err_msg);
}

87
trunk/src/sj3dic/sj3dic.h Normal file
View file

@ -0,0 +1,87 @@
/*
* Copyright (c) 2004 Iwata <iwata@quasiquote.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef SJ3DIC_H
#define SJ3DIC_H
#include <config.h>
#include <stdio.h>
#include <sys/types.h>
#include "sjtool.h"
/* codecnv.h */
int init_code();
void cnvcode(unsigned char *);
void printout_mb(FILE *, unsigned char *);
void printout(FILE *, unsigned char *);
void normal_out(char *, ...);
void error_out(char *, ...);
/* dictdisp.c */
void dictdisp(char *);
/* dictmake.c */
void dictmake(char *);
/* hinsi.c */
char *hns2str(int);
int str2hns(char *);
/* sj3dic.c */
extern int sj3dic_sys_code;
extern char prog_name[LONGLENGTH];
extern char home_dir[LONGLENGTH];
extern char user_name[LONGLENGTH];
extern char term_name[LONGLENGTH];
extern char serv_name[LONGLENGTH];
extern char file_name[LONGLENGTH];
extern char dict_name[LONGLENGTH];
extern int verbose_flag;
extern int init_flag;
extern int force_flag;
void init_env();
void usage(int);
int parsearg(int, char **);
void make_dicname();
void setdicname(char *);
void setsjserv(char *);
/* sj3err.c */
void sj3error(FILE *, int);
/* sjrc.c */
struct wordent {
char word_str[MAXWORD];
};
extern char RCfile[LONGLENGTH];
extern struct functbl {
char *keyword;
void (*func)(struct wordent *);
} funcs[];
int sjset_code();
int getsjrc();
void setrc (char *, FILE *);
int much(char *, char *);
int getword(char *, struct wordent *);
int IsTerminator(u_char);
int isTerminator(u_char);
int IsEscape(u_char);
int IsDelimitor(u_char);
void set_dict (struct wordent *);
void set_server(struct wordent *);
#endif /* SJ3DIC_H */

108
trunk/src/sj3dic/sj3err.c Normal file
View file

@ -0,0 +1,108 @@
/*
* 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: sj3err.c,v $
* $SonyRevision: 1.1 $
* $SonyDate: 1994/06/03 08:03:38 $
*/
#include <config.h>
#include <stdio.h>
#include "sj3dic.h"
#include "sj3err.h"
void
sj3error(FILE *fp, int code)
{
unsigned char tmp[BUFSIZ];
switch (code) {
#define CASE(X, str) case (X): printout(fp, str); break;
CASE(SJ3_InternalError, "\245\244\245\363\245\277\241\274\245\312\245\353\245\250\245\351\241\274");
CASE(SJ3_NormalEnd, "\300\265\276\357\275\252\316\273");
CASE(SJ3_ServerDown, "\245\265\241\274\245\320\241\274\244\254\315\356\244\301\244\306\244\244\244\336\244\271");
CASE(SJ3_OpenSocket, "socket \244\316 open \244\313\274\272\307\324\244\267\244\336\244\267\244\277");
CASE(SJ3_ConnectSocket, "socket \244\316 connect \244\313\274\272\307\324\244\267\244\336\244\267\244\277");
CASE(SJ3_GetHostByName, "gethostbyname \244\313\274\272\307\324\244\267\244\336\244\267\244\277");
CASE(SJ3_NotOpened, "\245\252\241\274\245\327\245\363\244\265\244\354\244\306\244\244\244\336\244\273\244\363");
CASE(SJ3_NotEnoughMemory, "\245\341\245\342\245\352\244\254\302\255\244\352\244\336\244\273\244\363");
CASE(SJ3_IllegalCommand, "\245\263\245\336\245\363\245\311\244\254\304\352\265\301\244\265\244\354\244\306\244\244\244\336\244\273\244\363");
CASE(SJ3_DifferentVersion, "\245\320\241\274\245\270\245\347\245\363\244\254\260\343\244\244\244\336\244\271");
CASE(SJ3_NoHostName, "\245\333\245\271\245\310\314\276\244\254\244\242\244\352\244\336\244\273\244\363");
CASE(SJ3_NoUserName, "\245\346\241\274\245\266\314\276\244\254\244\242\244\352\244\336\244\273\244\363");
CASE(SJ3_NotAllowedUser, "\300\334\302\263\244\362\265\366\244\265\244\354\244\306\244\244\244\336\244\273\244\363");
CASE(SJ3_AlreadyConnected, "\300\334\302\263\272\321\244\307\244\271");
CASE(SJ3_NotConnected, "\300\334\302\263\244\265\244\354\244\306\244\244\244\336\244\273\244\363");
CASE(SJ3_TooLongParameter, "\245\321\245\351\245\341\241\274\245\277\244\254\304\271\244\271\244\256\244\336\244\271");
CASE(SJ3_IllegalParameter, "\245\321\245\351\245\341\241\274\245\277\244\254\260\333\276\357\244\307\244\271");
CASE(SJ3_BadDictID, "\244\275\244\316\244\350\244\246\244\312\274\255\275\361\244\317\244\242\244\352\244\336\244\273\244\363");
CASE(SJ3_IllegalDictFile, "\274\255\275\361\245\325\245\241\245\244\245\353\244\254\260\333\276\357\244\307\244\271");
CASE(SJ3_IllegalStdyFile, "\263\330\275\254\245\325\245\241\245\244\245\353\244\254\260\333\276\357\244\307\244\271");
CASE(SJ3_IncorrectPasswd, "\245\321\245\271\245\357\241\274\245\311\244\254\260\333\244\312\244\352\244\336\244\271");
CASE(SJ3_FileNotExist, "\245\325\245\241\245\244\245\353\244\254\302\270\272\337\244\267\244\336\244\273\244\363");
CASE(SJ3_CannotAccessFile, "\245\325\245\241\245\244\245\353\244\313\245\242\245\257\245\273\245\271\244\307\244\255\244\336\244\273\244\363");
CASE(SJ3_CannotOpenFile, "\245\325\245\241\245\244\245\353\244\254\245\252\241\274\245\327\245\363\244\307\244\255\244\336\244\273\244\363");
CASE(SJ3_CannotCreateFile, "\245\325\245\241\245\244\245\353\244\254\272\356\300\256\244\307\244\255\244\336\244\273\244\363");
CASE(SJ3_FileReadError, "\245\352\241\274\245\311\245\250\245\351\241\274\244\254\244\242\244\352\244\336\244\267\244\277");
CASE(SJ3_FileWriteError, "\245\351\245\244\245\310\245\250\245\351\241\274\244\254\244\242\244\352\244\336\244\267\244\277");
CASE(SJ3_FileSeekError, "\245\267\241\274\245\257\245\250\245\351\241\274\244\254\244\242\244\352\244\336\244\267\244\277");
CASE(SJ3_StdyAlreadyOpened, "\263\330\275\254\245\325\245\241\245\244\245\353\244\317\245\252\241\274\245\327\245\363\244\265\244\354\244\306\244\244\244\336\244\271");
CASE(SJ3_StdyFileNotOpened, "\263\330\275\254\245\325\245\241\245\244\245\353\244\254\245\252\241\274\245\327\245\363\244\265\244\354\244\306\244\244\244\336\244\273\244\363");
CASE(SJ3_TooSmallStdyArea, "\312\270\300\341\304\271\263\330\275\254\316\316\260\350\244\254\276\256\244\265\244\271\244\256\244\336\244\271");
CASE(SJ3_LockedByOther, "\302\276\244\316\245\257\245\351\245\244\245\242\245\363\245\310\244\313\245\355\245\303\245\257\244\265\244\354\244\306\244\336\244\271");
CASE(SJ3_NotLocked, "\245\355\245\303\245\257\244\265\244\354\244\306\244\244\244\336\244\273\244\363");
CASE(SJ3_NoSuchDict, "\244\275\244\316\244\350\244\246\244\312\274\255\275\361\244\317\244\242\244\352\244\336\244\273\244\363");
CASE(SJ3_ReadOnlyDict, "\275\361\244\255\271\376\244\337\244\307\244\255\244\312\244\244\274\255\275\361\244\307\244\271");
CASE(SJ3_DictLocked, "\274\255\275\361\244\254\245\355\245\303\245\257\244\265\244\354\244\306\244\244\244\336\244\271");
CASE(SJ3_BadYomiString, "\265\366\244\265\244\354\244\312\244\244\306\311\244\337\312\270\273\372\316\363\244\307\244\271");
CASE(SJ3_BadKanjiString, "\265\366\244\265\244\354\244\312\244\244\264\301\273\372\312\270\273\372\316\363\244\307\244\271");
CASE(SJ3_BadHinsiCode, "\311\312\273\354\245\263\241\274\245\311\260\333\276\357\244\307\244\271");
CASE(SJ3_AddDictFailed, "\274\255\275\361\305\320\317\277\244\362\274\272\307\324\244\267\244\336\244\267\244\277");
CASE(SJ3_AlreadyExistWord, "\244\271\244\307\244\313\302\270\272\337\244\267\244\306\244\244\244\336\244\271");
CASE(SJ3_NoMoreDouonWord, "\244\263\244\354\260\312\276\345\306\261\262\273\270\354\244\362\305\320\317\277\244\307\244\255\244\336\244\273\244\363");
CASE(SJ3_NoMoreUserDict, "\244\263\244\354\260\312\276\345\274\255\275\361\244\313\305\320\317\277\244\307\244\255\244\336\244\273\244\363");
CASE(SJ3_NoMoreIndexBlock, "\244\263\244\354\260\312\276\345\245\244\245\363\245\307\245\303\245\257\245\271\244\313\305\320\317\277\244\307\244\255\244\336\244\273\244\363");
CASE(SJ3_DelDictFailed, "\274\255\275\361\272\357\275\374\244\362\274\272\307\324\244\267\244\336\244\267\244\277");
CASE(SJ3_NoSuchWord, "\244\275\244\316\244\350\244\246\244\312\275\317\270\354\244\317\244\242\244\352\244\336\244\273\244\363");
CASE(SJ3_DirAlreadyExist, "\244\275\244\316\245\307\245\243\245\354\245\257\245\310\245\352\244\254\302\270\272\337\244\267\244\306\244\244\244\336\244\271");
CASE(SJ3_CannotCreateDir, "\245\307\245\243\245\354\245\257\245\310\245\352\244\254\272\356\300\256\244\307\244\255\244\336\244\273\244\363");
CASE(SJ3_NoMoreDictData, "\244\263\244\354\260\312\276\345\274\255\275\361\245\307\241\274\245\277\244\254\244\242\244\352\244\336\244\273\244\363");
CASE(SJ3_UserConnected, "\300\334\302\263\244\267\244\306\244\244\244\353\245\346\241\274\245\266\244\254\244\242\244\352\244\336\244\271");
CASE(SJ3_TooLongPasswd, "\245\321\245\271\245\357\241\274\245\311\244\254\304\271\244\271\244\256\244\336\244\271");
CASE(SJ3_TooLongComment, "\245\263\245\341\245\363\245\310\244\254\304\271\244\271\244\256\244\336\244\271");
#undef CASE
default:
snprintf((char *)tmp, sizeof(tmp), "\314\244\304\352\265\301\244\316\245\250\245\351\241\274(%d)", code);
printout(fp, tmp);
break;
}
printout(fp, "\r\n");
}

View file

@ -0,0 +1,77 @@
/*
* 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: sjctype.h,v $
* $SonyRevision: 1.1 $
* $SonyDate: 1994/06/03 08:03:39 $
*/
#ifndef __sony_news
#ifndef __SJCTYPE
#define __SJCTYPE
#define sjis2euc sj3_sjis2euc
#define jis2sjis sj3_jis2sjis
#define euctosjis sj3_euctosjis
#define sjis2jis sj3_sjis2jis
#define euc2sjis sj3_euc2sjis
#define jis2euc sj3_jis2euc
#define sjistoeuc sj3_sjistoeuc
#define issjis1(c) (((0x81 <= ((unsigned char)(c))) && (((unsigned char)(c)) <= 0x9f)) || \
((0xe0 <= ((unsigned char)(c))) && (((unsigned char)(c)) <= 0xfc)))
#define issjis2(c) (((0x40 <= ((unsigned char)(c))) && (((unsigned char)(c)) <= 0xfc)) && (((unsigned char)(c)) != 0x7f))
#define iseuc(c) ((0xa1 <= ((unsigned char)(c))) && (((unsigned char)(c)) <= 0xfe))
#define iseuckana(c) (((unsigned char)(c)) == 0x8e)
#define iskana2(c) ((0xa1 <= ((unsigned char)(c))) && (((unsigned char)(c)) <= 0xdf))
#define jiszen(c) (issjis1(((c) >> 8) & 0xff) && issjis2((c) & 0xff))
#define isjjis(c) ((0x21 <= (c)) && ((c) <= 0x7e))
#define jstrlen(s) euclen(s, 65535)
#define iseuc3byte(c) ((c) == 0x8f)
#define iseuc2byte(c) (iseuc(c) || ((c) == 0x8e))
#define iskanji issjis1
#define iskanji2 issjis2
#define iskana iskana2
#endif
#else
#define euctosjis sj3_euctosjis
#define sjistoeuc sj3_sjistoeuc
#endif

290
trunk/src/sj3dic/sjrc.c Normal file
View file

@ -0,0 +1,290 @@
/*
* 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: sjrc.c,v $
* $SonyRevision: 1.3 $
* $SonyDate: 1997/01/23 11:26:31 $
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include <ctype.h>
#include <sys/types.h>
#include "sj3dic.h"
#include "sjctype.h"
#include "sjtool.h"
#include "sj_string.h"
char RCfile[LONGLENGTH];
static char *rcfile = ".sjrc";
static int user_euc = 0;
static int file_code = SYS_SJIS;
struct functbl funcs[] = {
{ "dictionary", set_dict },
{ "userdic", set_dict },
{ "server", set_server },
{ NULL, NULL }
};
#define TOLOWER(c) (isupper(c) ? tolower(c) : (c))
int
sjset_code()
{
char *loc;
loc = setlocale(LC_CTYPE, "");
if (!loc) {
fprintf(stderr, "Error: can't get current locale\n");
exit(1);
}
if (strncmp(loc, "ja_JP.SJIS", 10) == 0) {
user_euc = 0;
} else if (strncmp(loc, "ja", 2) == 0 || strncmp(loc, "Ja", 2) == 0) {
user_euc = 1;
file_code = -1;
} else {
fprintf(stderr, "Warrning: In this locale japanese will not be used.\n");
user_euc = 1;
file_code = -1;
}
return 1;
}
int
getsjrc()
{
FILE *fd, *fopen();
char *p;
char *getenv();
sjset_code();
RCfile[0] = '\0';
if ((p = getenv("SJRC")) != NULL && *p != '\0') {
strlcpy(RCfile, home_dir, sizeof(RCfile));
if (*p != '/')
strlcat(RCfile, "/", sizeof(RCfile));
strlcat(RCfile, p, sizeof(RCfile));
if ((fd = fopen (RCfile, "r")) != NULL) {
setrc (RCfile, fd);
fclose (fd);
return TRUE;
}
}
if (home_dir[0] != '\0') {
strlcpy(RCfile, home_dir, sizeof(RCfile));
strlcat(RCfile, "/", sizeof(RCfile));
strlcat(RCfile, rcfile, sizeof(RCfile));
if ((fd = fopen (RCfile, "r")) != NULL) {
setrc (RCfile, fd);
fclose (fd);
return TRUE;
}
}
RCfile[0] = '\0';
return FALSE;
}
void
setrc(char *file, FILE *fd)
{
char line[MAXLINE];
int w;
struct wordent word[WORDN];
char *p;
struct functbl *functp;
while ((p = fgets (line, MAXLINE, fd)) != NULL) {
if ((w = getword(line, word)) <= 0)
continue;
functp = funcs;
p = word[0].word_str;
while (functp->keyword != NULL) {
if (much(p, functp->keyword)) {
if (functp->func) (*(functp->func))(word);
break;;
}
functp++;
}
}
}
int
much(char *s1, char *s2)
{
char c1, c2;
if (s1 == NULL)
return 0;
while (*s2 != '\0') {
c1 = *s1++;
c2 = *s2++;
if (TOLOWER(c1) != TOLOWER(c2))
return 0;
}
return 1;
}
int
getword(char *s, struct wordent word[])
{
u_char c, cc;
char *p;
int i, wcount;
if (IsDelimitor(*s)) {
s++;
} else {
p = s;
while(!IsDelimitor(*s)) {
if (IsTerminator(*s) || isTerminator(*s))
break;
s++;
}
*s++ = '\0';
if (much(p, term_name) == 0)
return 0;
}
i = wcount = 0;
p = word[wcount].word_str;
while (*s != '\0') {
c = *s++;
if (file_code == SYS_SJIS) {
if (issjis1(c) && issjis2(*s)) {
if (i < MAXWORD - 2) {
*p++ = c;
*p++ = *s;
i += 2;
}
s++;
continue;
}
} else if (file_code == SYS_EUC) {
if (iseuc(c) && iseuc(*s)) {
if (i < MAXWORD - 2) {
cc = (c << 8) + (*s & 0xff);
cc = euc2sjis(cc);
*p++ = (cc >> 8) & 0xff;
*p++ = cc & 0xff;
i += 2;
}
s++;
continue;
}
if (iseuckana(c) && iskana2(*s))
c = *s++;
} else {
if (issjis1(c) && issjis2(*s)) {
file_code = SYS_SJIS;
s--;
continue;
}
if ((iseuc(c) && iseuc(*s)) ||
(iseuckana(c) && iskana2(*s))) {
file_code = SYS_EUC;
s--;
continue;
}
}
if (isTerminator(c))
break;
if (IsDelimitor(c)) {
if (i > 0) {
if (++wcount >= WORDN - 1)
break;
*p = '\0';
i = 0;
p = word[wcount].word_str;
}
continue;
}
if (IsEscape(c))
c = *s++;
if (IsTerminator(c))
break;
if (i < MAXWORD - 1) {
*p++ = c;
i++;
}
}
*p = '\0';
if (word[wcount].word_str[0] != '\0')
word[++wcount].word_str[0] = '\0';
return wcount;
}
int
IsTerminator(u_char c)
{
return (c == '\n') ? 1 : 0;
}
int
isTerminator(u_char c)
{
return (c == '#') ? 1 : 0;
}
int
IsEscape(u_char c)
{
return (c == '\\') ? 1 : 0;
}
int
IsDelimitor(u_char c)
{
return (c == ' ' || c == '\t' || c == '.') ? 1 : 0;
}
void
set_dict(struct wordent word[])
{
setdicname(word[1].word_str);
}
void
set_server(struct wordent word[])
{
setsjserv(word[1].word_str);
}

69
trunk/src/sj3dic/sjtool.h Normal file
View file

@ -0,0 +1,69 @@
/*
* 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: sjtool.h,v $
* $SonyRevision: 1.2 $
* $SonyDate: 1996/02/15 02:22:59 $
*/
#ifndef SJTOOL_H
#define SJTOOL_H
#if defined(__NetBSD__)
#define LACKOF_SETLOCALE
#endif
#define LONGLENGTH 256
#define MAXLINE 256
#define MAXWORD 256
#define WORDN 32
#ifndef SYS_SJIS
# define SYS_SJIS 0
#endif
#ifndef SYS_EUC
# define SYS_EUC 1
#endif
#define TRUE -1
#define FALSE !(TRUE)
#define EXEC_TEXT 1
#define EXEC_DICT 2
#define EXEC_CONV 3
#define EXEC_INIT 10
#define EXEC_VERBOSE 11
#define EXEC_SERVER 12
#define EXEC_FORCE 13
#define SingleShift2 0x8e
#endif /* SJTOOL_H */

View 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 }

View file

@ -0,0 +1,31 @@
if BUILDABLE_SJ3SERV
INCLUDES = \
-I$(top_srcdir)/include/sj3compat \
-I$(top_srcdir)/include/sj3common \
-I$(top_srcdir)/include/sj3core
LDADD = $(top_srcdir)/lib/sj3compat/libsj3compat.la
sj3mkdic_SOURCES = \
GramTable \
sj3mkdic.h \
sj3_dict_const.h \
sj3_dict_struct.h \
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
bin_PROGRAMS = sj3mkdic
endif

275
trunk/src/sj3mkdic/char.c Normal file
View 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: char.c,v $
* $SonyRevision: 1.1 $
* $SonyDate: 1994/06/03 08:00:32 $
*/
#include <stdio.h>
#include <sys/types.h>
#include "sj_euc.h"
#include "sj3_dict_const.h"
#include "sj3mkdic.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);
}
return code; /* XXX */
}
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++;
}
}
}
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);
}
}

View file

@ -0,0 +1,118 @@
/*
* Copyright (c) 1991-1994 Sony Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Sony Corporation
* shall not be used in advertising or otherwise to promote the sale, use
* or other dealings in this Software without prior written authorization
* from Sony Corporation.
*
*/
/*
* $SonyRCSfile: cnvhinsi.c,v $
* $SonyRevision: 1.2 $
* $SonyDate: 1996/05/27 06:59:47 $
*/
#include <stdio.h>
#include <sys/types.h>
static 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
trunk/src/sj3mkdic/file.c Normal file
View 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 <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "sj3mkdic.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;
char *p;
FileList *fl;
size_t len;
if (!(fp = fopen(filename, type))) {
fprintf(stderr, "Can't open %s mode \"%s\"\n", filename, type);
exit(1);
}
fl = (FileList *)Malloc(sizeof(*fl));
len = strlen(filename) + 1;
fl -> fname = Malloc(len);
strlcpy(fl -> fname, filename, len);
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);
}
long
Fsize(char *filename)
{
struct stat buf;
if (stat(filename, &buf) == 0) return (long)buf.st_size;
fprintf(stderr, "Stat error in %s\n", filename);
exit(1);
}
size_t
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);
}
size_t
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);
}
int
Fflush(FILE *fp)
{
return fflush(fp);
}

View file

@ -0,0 +1,60 @@
/*
* 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 "sj3_dict_struct.h"
#include "sj3mkdic.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;

548
trunk/src/sj3mkdic/hindo.c Normal file
View file

@ -0,0 +1,548 @@
/*
* Copyright (c) 1991-1994 Sony Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Sony Corporation
* shall not be used in advertising or otherwise to promote the sale, use
* or other dealings in this Software without prior written authorization
* from Sony Corporation.
*
*/
/*
* $SonyRCSfile: hindo.c,v $
* $SonyRevision: 1.2 $
* $SonyDate: 1994/08/17 01:50:26 $
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "sj3_dict_struct.h"
#include "sj3mkdic.h"
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()
{
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()
{
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()
{
AssyukuRec *p;
while (assyuku) {
p = assyuku;
assyuku = assyuku -> anext;
Free(p);
}
}

232
trunk/src/sj3mkdic/knjcvt.c Normal file
View file

@ -0,0 +1,232 @@
/*
* Copyright (c) 1991-1994 Sony Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Sony Corporation
* shall not be used in advertising or otherwise to promote the sale, use
* or other dealings in this Software without prior written authorization
* from Sony Corporation.
*
*/
/*
* $SonyRCSfile: knjcvt.c,v $
* $SonyRevision: 1.1 $
* $SonyDate: 1994/06/03 08:00:37 $
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "sj3_dict_const.h"
#include "sj3_dict_struct.h"
#include "sj3mkdic.h"
typedef struct div_list {
int len;
u_char code[3];
struct div_list *child;
} DivList;
static void
free_divlist(DivList *p)
{
DivList *q;
while (p) {
q = p -> child;
Free(p);
p = q;
}
}
static DivList *
make_divrec()
{
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 = 0;
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;
}

View file

@ -0,0 +1,225 @@
/*
* Copyright (c) 1991-1994 Sony Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Sony Corporation
* shall not be used in advertising or otherwise to promote the sale, use
* or other dealings in this Software without prior written authorization
* from Sony Corporation.
*
*/
/*
* $SonyRCSfile: makedict.c,v $
* $SonyRevision: 1.2 $
* $SonyDate: 1994/12/09 11:27:05 $
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
#include "sj3_dict_const.h"
#include "sj3mkdic.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);
strlcpy(p, name, i + 2);
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"))
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)
{
int i;
char *progname = NULL;
char *p;
if (progname = strrchr(argv[0], '/'))
progname++;
else
progname = argv[0];
if (argc != 3)
usage(progname);
p = argv[1];
idxtop = (*p == '-') ? get_idxlist(p + 1) : make_idxlist(p);
outfp = Fopen(argv[2], "w");
}
/* XXX: strtonum??? */
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()
{
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 {
strlcpy(pathname, idxtop, sizeof(pathname));
pos = infp ? Ftell(infp) : 0;
}
}

View file

@ -0,0 +1,539 @@
/*
* Copyright (c) 1991-1994 Sony Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Sony Corporation
* shall not be used in advertising or otherwise to promote the sale, use
* or other dealings in this Software without prior written authorization
* from Sony Corporation.
*
*/
/*
* $SonyRCSfile: makelist.c,v $
* $SonyRevision: 1.1 $
* $SonyDate: 1994/06/03 08:00:39 $
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "sj3_dict_struct.h"
#include "sj3mkdic.h"
#ifndef SS2
#define SS2 0x8e
#endif
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()
{
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)) {
kanji += i;
ktmp[pos++] = (ZENHIRAASSYUKU | (i - 1));
} else if (i = top_strcmp(kana, kanji)) {
kanji += i;
ktmp[pos++] = (ZENKATAASSYUKU | (i - 1));
}
while (*kanji) {
if (i = last_strcmp(yomi, kanji)) {
kanji += i;
ktmp[pos++] = (ZENHIRAASSYUKU | (i - 1));
}
else if (i = last_strcmp(kana, kanji)) {
kanji += i;
ktmp[pos++] = (ZENKATAASSYUKU | (i - 1));
}
else if (((*kanji >> 8) & 0xff) == SS2 || *kanji < 0x100) {
ktmp[pos] = LEADINGHANKAKU;
ktmp[pos + 1] = (*kanji & 0xff);
kanji++;
pos += 2;
}
else {
if (*kanji < 0x10000) {
ktmp[pos] = ((*kanji >> 8) & NORMALKANJIMASK);
ktmp[pos + 1] = (*kanji & NORMALKANJIMASK);
kanji++;
pos += 2;
} else if (*kanji < 0x1000000) {
ktmp[pos] = ((*kanji >> 8) & NORMALKANJIMASK);
ktmp[pos + 1] = (*kanji & 0xff);
kanji++;
pos += 2;
} else {
fprintf(stderr, "Error: 4 byte code is found\n");
exit(0);
}
}
}
*len = pos;
q = (u_char *)Malloc(pos);
if (!q) {
fprintf(stderr, "\245\341\245\342\245\352\244\254\311\324\302\255\244\267\244\336\244\267\244\277");
exit(1);
}
memcpy(q, ktmp, pos);
return q;
}
static u_char *
makeyomi(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()
{
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 = NULL;
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;
}
if (kprev)
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;
}

View file

@ -0,0 +1,387 @@
/*
* Copyright (c) 1991-1994 Sony Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Sony Corporation
* shall not be used in advertising or otherwise to promote the sale, use
* or other dealings in this Software without prior written authorization
* from Sony Corporation.
*
*/
/*
* $SonyRCSfile: makeseg.c,v $
* $SonyRevision: 1.2 $
* $SonyDate: 1994/12/09 11:27:05 $
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
#include "sj3_dict_struct.h"
#include "Dict.h"
#include "sj3mkdic.h"
static u_char mindex[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;
}
int
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()
{
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()
{
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) {
mindex[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) {
mindex[idxpos] = 0;
}
else {
fprintf(stderr, "\245\244\245\363\245\307\245\303\245\257\245\271\244\254\244\242\244\325\244\354\244\336\244\267\244\277\n");
exit(1);
}
i = dst - buf;
while (dst < buf + sizeof(buf)) *dst++ = DOUONBLKTERM;
if (Fseek(outfp,
(long)(HEADERLENGTH + COMMENTLENGTH + MAININDEXLENGTH
+ idxnum * MAINSEGMENTLENGTH),
0) < 0) {
fprintf(stderr, "\275\320\316\317\245\325\245\241\245\244\245\353\244\307\245\267\241\274\245\257\245\250\245\351\241\274\n");
exit(1);
}
if (Fwrite(buf, sizeof(buf), 1, outfp) != 1) {
fprintf(stderr, "\275\320\316\317\245\325\245\241\245\244\245\353\244\307\245\351\245\244\245\310\245\250\245\351\241\274\n");
exit(1);
}
Fflush(outfp);
printf("\245\273\245\260\245\341\245\363\245\310\310\326\271\346:%d:", idxnum++);
output_yomi(stdout, douon_ptr -> yptr);
printf("\t\245\273\245\260\245\341\245\363\245\310\304\271:%d", i);
printf("\t\306\261\262\273\270\354\277\364:%d\n", douon_num);
printf("\264\301\273\372\260\265\275\314\312\270\273\372\316\363:");
for (i = j = 0 ; i < askknj_num ; i++) {
putchar('\t');
if (i && j == 0) putchar('\t');
output_knj(stdout, askknj[i] -> kptr, askknj[i] -> klen);
printf(":%d", askknj[i] -> hindo + askknj[i] -> exist);
if (++j >= 4) {
putchar('\n');
j = 0;
}
}
if (j) putchar('\n');
putchar('\n');
fflush(stdout);
return;
err:
fprintf(stderr, "\245\273\245\260\245\341\245\363\245\310\271\275\300\256\303\346\244\313\245\320\245\303\245\325\245\241\244\254\244\242\244\325\244\354\244\277\n");
fprintf(stderr, "\245\273\245\260\245\341\245\363\245\310\300\350\306\254\244\316\306\311\244\337:");
output_yomi(stderr, douon_ptr -> yptr);
fputc('\n', stderr);
exit(1);
#undef datset
}
static void put4byte(p, n)
u_char *p;
long n;
{
p += 3;
*p-- = n; n >>= 8;
*p-- = n; n >>= 8;
*p-- = n; n >>= 8;
*p = n;
}
void
makehead(u_char *dict_name)
{
u_char header[HEADERLENGTH + COMMENTLENGTH];
time_t i;
u_char *p;
#define INDEXPOS (HEADERLENGTH + COMMENTLENGTH)
memset(header, '\0', sizeof(header));
put4byte(header + VERSIONPOS, DICTVERSION);
time(&i);
p = header + COMMENTPOS;
snprintf((char *)p, sizeof(header) - COMMENTPOS, "%s : %s", dict_name, ctime(&i));
while (*p) {
if (*p == '\n') { *p = 0; break; }
p++;
}
i = INDEXPOS;
put4byte(header + DICTIDXPOS, i);
put4byte(header + DICTIDXLEN, MAININDEXLENGTH);
i += MAININDEXLENGTH;
put4byte(header + DICTSEGPOS, i);
put4byte(header + DICTSEGLEN, MAINSEGMENTLENGTH);
put4byte(header + DICTSEGMAX, 0);
put4byte(header + DICTSEGNUM, idxnum);
put4byte(header + DICTAIDXPOS, 0);
put4byte(header + DICTAIDXLEN, 0);
put4byte(header + DICTASEGPOS, 0);
put4byte(header + DICTASEGLEN, 0);
Fseek(outfp, (long)HEADERPOS, 0);
Fwrite(header, sizeof(header), 1, outfp);
Fseek(outfp, (long)INDEXPOS, 0);
Fwrite(mindex, MAININDEXLENGTH, 1, outfp);
#undef INDEXPOS
}

View file

@ -0,0 +1,68 @@
/*
* Copyright (c) 1991-1994 Sony Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Sony Corporation
* shall not be used in advertising or otherwise to promote the sale, use
* or other dealings in this Software without prior written authorization
* from Sony Corporation.
*
*/
/*
* $SonyRCSfile: memory.c,v $
* $SonyRevision: 1.1 $
* $SonyDate: 1994/06/03 08:00:42 $
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void *
Malloc(unsigned 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(int size)
{
void *p;
p = Malloc(size);
memset(p, '\0', size);
return p;
}
void
Free(void *p)
{
free(p);
}

167
trunk/src/sj3mkdic/offset.c Normal file
View file

@ -0,0 +1,167 @@
/*
* 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 "sj3_dict_struct.h"
#include "sj3mkdic.h"
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;
do {
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;
} while (low <= high);
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()
{
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);
}

View file

@ -0,0 +1,286 @@
/*
* Copyright (c) 1991-1994 Sony Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Sony Corporation
* shall not be used in advertising or otherwise to promote the sale, use
* or other dealings in this Software without prior written authorization
* from Sony Corporation.
*
*/
/*
* $SonyRCSfile: readline.c,v $
* $SonyRevision: 1.1 $
* $SonyDate: 1994/06/03 08:00:44 $
*/
#include <stdio.h>
#include <sys/types.h>
#include <ctype.h>
#include "sj_euc.h"
#include "sj3_dict_const.h"
#include "sj3mkdic.h"
static int yomi[MAXYOMILENGTH + 1];
static int kanji[MAXKANJILENGTH + 1];
static int hinsi[MAXHINSINUMBER + 1];
static int atr[MAXATRNUMBER + 1];
#define Isblank(c) ((c) == 0x20 || (c) == 0x09 || (c) == 0xa1a1)
#define Isillegal(c) ((c) < 0x20)
static void
error(char *s)
{
if (s)
fprintf(stderr, "%s\n", s);
mark_file(stderr);
exit(1);
}
static int
readchar()
{
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()
{
int c;
c = readchar();
while (Isblank(c))
c = readchar();
return c;
}
static int
readhinsi()
{
static int c = 0;
int i;
unsigned char hinsi[128];
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()
{
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()) {
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(int (*func)())
{
int i;
for (i = 0 ; hinsi[i] ; i++)
(*func)(yomi, kanji, hinsi[i], atr);
}

View file

@ -0,0 +1,108 @@
/*
* 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: sj3_dict_const.h,v $
* $SonyRevision: 1.1 $
* $SonyDate: 1994/06/03 08:00:24 $
*/
#ifndef SJ3_DICT_CONST_H
#define SJ3_DICT_CONST_H
#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

View file

@ -0,0 +1,90 @@
/*
* 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: sj3_dict_struct.h,v $
* $SonyRevision: 1.1 $
* $SonyDate: 1994/06/03 08:00:26 $
*/
#include "sj3_dict_const.h"
#ifndef SJ3_DICT_STRUCT_H
#define SJ3_DICT_STRUCT_H
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

View file

@ -0,0 +1,123 @@
/*
* Copyright (c) 2004 Iwata <iwata@quasiquote.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef SJ3MKDIC_H
#define SJ3MKDIC_H
#include <stdio.h>
#include "sj3_dict_struct.h"
/* char.c */
int cnvyomi(int);
int h2kcode(int);
int codesize(u_char);
void output_knj(FILE *, u_char *, int);
void output_str(FILE *, char *);
void output_int(FILE *, int *);
int yomi2zen(int);
void output_yomi(FILE *, u_char *);
/* cnvhinsi.c */
int u_strcmp(u_char *, u_char *);
int cnvhinsi(u_char *);
char *hinsi_str(int);
/* file.c */
FILE *Fopen(char *, char *);
void Fclose(FILE *);
int Fseek(FILE *, long, int);
long Ftell(FILE *);
long Fsize(char *);
size_t Fread(char *, int, int, FILE *);
size_t Fwrite(char *, int, int, FILE *);
int Fgetc(FILE *);
int Fflush(FILE *);
/* global.c */
extern DouonRec *douon_ptr;
extern int douon_num;
extern int yomi_len;
extern int hinsi_num;
extern int kanji_len;
extern HindoRec *hindo[MAXHINDONUMBER];
extern int hindo_num;
extern OffsetRec *ofsrec[MAXOFFSETNUMBER];
extern int ofsrec_num;
extern AssyukuRec *assyuku;
extern HindoRec *askknj[MAXKNJASKNUMBER];
extern int askknj_num;
extern int kanji_num;
/* hindo.c */
int check_hindo(u_char *, int);
void knjhnd_set(u_char *, int);
void knjhnd_reset(u_char *, int);
int decide_knjask();
void clear_hindo();
void clear_assyuku();
/* knjcvt.c */
u_char *knjofscvt(u_char *, int, int *);
u_char *knjcvt(u_char *, int, int *);
/* mkdict.c */
extern FILE *infp;
extern FILE *outfp;
char *make_idxlist(char *);
char *get_idxlist(char *);
void parse(int, char **);
int get_number(char *);
void usage(char *);
int getch();
void mark_file(FILE *);
/* makelist */
void flush_douon();
void makelist(int *, int *, int, int *);
/* makeseg.c */
int make_knjstr(u_char *, int, u_char *);
void makeseg();
void makehead(u_char *);
/* memory.c */
void *Malloc(unsigned);
void *Zalloc(int);
void Free(void *);
/* offset.c */
void set_ofsrec(u_char *, int, int);
int isknjexist(u_char *, int);
void clear_ofsrec();
OffsetRec *real_ofsrec(u_char *);
/* readline.c */
int *readline();
void setline(int (*)());
/* string.c */
int bubun_str(u_char *, int, u_char *, int);
int overlap_str(u_char *, int, u_char *, int);
int istrlen(int *);
int istrcmp(int *, int *);
int top_strcmp(int *, int *);
int last_strcmp(int *, int *);
int string_cmp(u_char *, int, u_char *, int);
#endif /* SJ3MKDIC_H */

202
trunk/src/sj3mkdic/string.c Normal file
View file

@ -0,0 +1,202 @@
/*
* Copyright (c) 1991-1994 Sony Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Sony Corporation
* shall not be used in advertising or otherwise to promote the sale, use
* or other dealings in this Software without prior written authorization
* from Sony Corporation.
*
*/
/*
* $SonyRCSfile: string.c,v $
* $SonyRevision: 1.1 $
* $SonyDate: 1994/06/03 08:00:45 $
*/
#include <stdio.h>
#include <sys/types.h>
#include "sj3_dict_const.h"
#include "sj3mkdic.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;
}
int
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;
}

View file

@ -0,0 +1,62 @@
if BUILDABLE_SJ3SERV
EXTRA_DIST = \
freebsd-sj3.sh.in \
sj3serv.lua.example.in \
time_stamp.sh
AM_CFLAGS = $(lua_CFLAGS)
INCLUDES = \
-I$(top_srcdir)/include/sj3compat \
-I$(top_srcdir)/include/sj3common \
-I$(top_srcdir)/include/sj3core
LDADD = \
$(top_srcdir)/lib/sj3core/libsj3core.la \
$(top_srcdir)/lib/sj3compat/libsj3compat.la \
@WRAP_LIB@
if SJ3_INTERNAL_LUA
AM_CFLAGS += -I$(top_builddir)/lib/lua/src
LDADD += $(top_builddir)/lib/lua/src/liblua.la @LIBM@
else
AM_CFLAGS += $(LUA_CFLAGS)
LDADD += $(LUA_LIBS)
endif
exampledir = $(datadir)/examples/sj3
sj3serv_SOURCES = \
sj_string.h \
sj3serv.h \
auth.c \
comuni.c \
error.c \
execute.c \
main.c \
priv.c \
setup.c \
time_stamp.c \
version.c \
sj_string.c
sbin_PROGRAMS = sj3serv
example_DATA = \
freebsd-sj3.sh.in \
sj3serv.lua.example
time_stamp.c: time_stamp.sh
sh ./time_stamp.sh > time_stamp.c
sj3serv.lua.example: sj3serv.lua.example.in
sed -e "s,%%SJ3VARDIR%%,$(SJ3VARDIR),g" \
-e "s,%%SJ3OWNER%%,$(SJ3OWNER),g" \
sj3serv.lua.example.in > sj3serv.lua.example
CLEANFILES = \
sj3serv.lua.example \
time_stamp.c
endif

230
trunk/src/sj3serv/auth.c Normal file
View file

@ -0,0 +1,230 @@
/*
* Copyright (c) 2003 Anil Madhavapeddy <anil@recoil.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <signal.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <pwd.h>
#include "sj3serv.h"
enum cmd_types {
AUTH_GETUGID,
AUTH_EXIT
};
static int auth_fd = -1;
static int may_read(int, void *, size_t);
static void must_read(int, void *, size_t);
static void must_write(int, void *, size_t);
int
exec_auth()
{
int socks[2];
int i;
pid_t child_pid = -1;
struct sigaction sa;
if (socketpair(AF_LOCAL, SOCK_STREAM, PF_UNSPEC, socks) == -1) {
fprintf(stderr, "socketpair() failed");
exit(255);
}
child_pid = fork();
if (child_pid < 0) {
fprintf(stderr, "fork() failed\n");
exit(255);
}
if (!child_pid) {
auth_fd = socks[1];
return 0;
}
memset(&sa, 0, sizeof(sa));
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
sa.sa_handler = SIG_DFL;
for (i = 1; i < NSIG; i++)
sigaction(i, &sa, NULL);
strlcpy(chroot_dir, "/", sizeof(chroot_dir));
set_priv("[auth]");
while (1) {
int cmd;
size_t username_len;
char username[BUFSIZ];
int ret;
struct passwd *pw;
if (may_read(socks[0], &cmd, sizeof(int)))
break;
switch (cmd) {
case AUTH_GETUGID:
/* length, user name */
must_read(socks[0], &username_len, sizeof(size_t));
if (username_len == 0 || username_len > sizeof(username))
_exit(0);
must_read(socks[0], username, username_len);
username[username_len - 1] = '\0';
pw = getpwnam(username);
if (pw) {
ret = 1;
must_write(socks[0], &ret, sizeof(int));
must_write(socks[0], &pw->pw_uid, sizeof(uid_t));
must_write(socks[0], &pw->pw_gid, sizeof(gid_t));
} else {
ret = 0;
must_write(socks[0], &ret, sizeof(int));
}
break;
case AUTH_EXIT:
close(socks[0]);
_exit(1);
default:
fprintf(stderr, "auth unknown command %d\n", cmd);
close(socks[0]);
_exit(255);
}
}
fprintf(stderr, "auth fatal error\n");
close(socks[0]);
_exit(1);
}
/* Read all data or return 1 for error. */
static int
may_read(int fd, void *buf, size_t n)
{
char *s = buf;
ssize_t res, pos = 0;
while (n > pos) {
res = read(fd, s + pos, n - pos);
switch (res) {
case -1:
if (errno == EINTR || errno == EAGAIN)
continue;
case 0:
return (1);
default:
pos += res;
}
}
return (0);
}
/* Read data with the assertion that it all must come through, or
* else abort the process. Based on atomicio() from openssh. */
static void
must_read(int fd, void *buf, size_t n)
{
char *s = buf;
ssize_t res, pos = 0;
while (n > pos) {
res = read(fd, s + pos, n - pos);
switch (res) {
case -1:
if (errno == EINTR || errno == EAGAIN)
continue;
case 0:
fprintf(stderr, "must_read: internal protocol error\n");
fflush(stderr);
_exit(0);
default:
pos += res;
}
}
}
/* Write data with the assertion that it all has to be written, or
* else abort the process. Based on atomicio() from openssh. */
static void
must_write(int fd, void *buf, size_t n)
{
char *s = buf;
ssize_t res, pos = 0;
while (n > pos) {
res = write(fd, s + pos, n - pos);
switch (res) {
case -1:
if (errno == EINTR || errno == EAGAIN)
continue;
case 0:
fprintf(stderr, "must_write: internal protocol error\n");
fflush(stderr);
_exit(0);
default:
pos += res;
}
}
}
int
auth_getugid(char *username, sj3_ugid *ugid)
{
size_t len;
int cmd = AUTH_GETUGID;
int ret;
uid_t uid;
gid_t gid;
if (auth_fd < 0) {
fprintf(stderr, "%s called from privileged portion", "auth_getpwnam");
exit(255);
}
len = strlen(username) + 1;
if (len == 0 || BUFSIZ < len)
return NULL;
must_write(auth_fd, &cmd, sizeof(int));
must_write(auth_fd, &len, sizeof(size_t));
must_write(auth_fd, username, len);
must_read(auth_fd, &ret, sizeof(int));
if (ret) {
must_read(auth_fd, &uid, sizeof(uid_t));
must_read(auth_fd, &gid, sizeof(gid_t));
ugid->uid = uid;
ugid->gid = gid;
return 1;
} else {
return 0;
}
}
void
exit_auth()
{
int cmd = AUTH_EXIT;
must_write(auth_fd, &cmd, sizeof(int));
return;
}

586
trunk/src/sj3serv/comuni.c Normal file
View file

@ -0,0 +1,586 @@
/*
* 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: comuni.c,v $
* $SonyRevision: 1.4 $
* $SonyDate: 1994/11/16 07:34:05 $
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <netdb.h>
#include <setjmp.h>
#include <errno.h>
#include <sys/stat.h>
#include "config.h"
#ifdef USE_LIBWRAP
#include <tcpd.h>
#include <syslog.h>
int allow_severity = LOG_INFO;
int deny_severity = LOG_WARNING;
#endif
#include "sj_kcnv.h"
#include "sj_kanakan.h"
#include "sj3serv.h"
#ifndef SOMAXCONN
# define SOMAXCONN 5
#endif
#define MAX_LISTEN_SOCKS 16
int client_num = 0;
Client *client = NULL;
Client *cur_client;
int maxfds = 0;
fd_set fds_org;
jmp_buf client_dead;
int client_fd;
static int fd_unix = -1;
static int fd_inets[MAX_LISTEN_SOCKS];
static int num_inets = 0;
static char putbuf[BUFSIZ];
static char getbuf[BUFSIZ];
static int putpos = 0;
static int buflen = 0;
static int getpos = 0;
void
socket_init()
{
FD_ZERO(&fds_org);
client_num = 0;
maxfds = 0;
}
static void
set_fd(int fd)
{
FD_SET(fd, &fds_org);
if (fd >= maxfds)
maxfds = fd + 1;
}
static void
clr_fd(int fd)
{
FD_CLR(fd, &fds_org);
if (maxfds == fd + 1) {
while (--fd >= 0) {
if (FD_ISSET(fd, &fds_org))
break;
}
maxfds = fd + 1;
}
}
void
open_af_unix()
{
struct sockaddr_un sunix;
unlink(domain_socket_name);
memset((char *)&sunix, '\0', sizeof(sunix));
sunix.sun_family = AF_UNIX;
strlcpy(sunix.sun_path, domain_socket_name, sizeof(sunix.sun_path));
if ((fd_unix = socket(AF_UNIX, SOCK_STREAM, 0)) == ERROR) {
unlink(domain_socket_name);
fprintf(stderr, "Can't create AF_UNIX socket at '%s'\n", domain_socket_name);
exit(1);
}
if (bind(fd_unix, (struct sockaddr *)&sunix, strlen(sunix.sun_path) + 2) == ERROR) {
if (errno == EADDRINUSE)
fprintf(stderr, "Port '%s' is already in use\n",
domain_socket_name);
else
fprintf(stderr, "Can't bind AF_UNIX socket at '%s'\n", domain_socket_name);
shutdown(fd_unix, 2);
close(fd_unix);
unlink(domain_socket_name);
exit(1);
}
if (listen(fd_unix, SOMAXCONN) == ERROR) {
shutdown(fd_unix, 2);
unlink(domain_socket_name);
close(fd_unix);
fprintf(stderr, "Can't listen AF_UNIX socket\n");
exit(1);
}
chmod(domain_socket_name,
S_IRUSR | S_IWUSR | S_IXUSR |
S_IRGRP | S_IWGRP | S_IXGRP |
S_IROTH | S_IWOTH | S_IXOTH);
set_fd(fd_unix);
}
void
open_af_inet()
{
struct addrinfo hints;
struct addrinfo *res, *res0;
int error;
int true = 1;
/*
* getaddrinfo() case. You can get IPv6 address and IPv4 address
* at the same time.
*/
memset(&hints, 0, sizeof(hints));
/* set-up hints structure */
hints.ai_family = address_family;
hints.ai_flags = AI_PASSIVE;
hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo(inet_host_name, inet_port_name, &hints, &res);
if (error) {
fprintf(stderr, gai_strerror(error));
exit(1);
}
res0 = res;
for ( ; res; res = res->ai_next) {
struct sockaddr *sa = res->ai_addr;
u_int8_t salen = res->ai_addrlen;
char ntop[NI_MAXHOST], strport[NI_MAXSERV];
int listen_sock;
if (res->ai_family != AF_INET && res->ai_family != AF_INET6)
continue;
if (num_inets >= MAX_LISTEN_SOCKS) {
fprintf(stderr,
"Too many listen sockets. "
"Enlarge MAX_LISTEN_SOCKS\n");
exit(1);
}
if (getnameinfo(sa, salen,
ntop, sizeof(ntop), strport, sizeof(strport),
NI_NUMERICHOST | NI_NUMERICSERV) != 0) {
fprintf(stderr, "getnameinfo failed\n");
continue;
}
listen_sock = socket(res->ai_family, res->ai_socktype,
res->ai_protocol);
if (listen_sock < 0) {
fprintf(stderr, "socket: %.100s\n", strerror(errno));
exit(1);
}
if (setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR,
&true, sizeof(true)) == -1)
fprintf(stderr, "setsockopt SO_REUSEADDR: %s\n", strerror(errno));
if (bind(listen_sock, sa, salen) < 0) {
fprintf(stderr, "Bind to port %s on %s failed: %.200s.\n",
strport, ntop, strerror(errno));
close(listen_sock);
continue;
}
if (listen(listen_sock, SOMAXCONN) < 0) {
fprintf(stderr, "listen: %.100s\n", strerror(errno));
close(listen_sock);
exit(1);
}
set_fd(listen_sock);
fd_inets[num_inets] = listen_sock;
num_inets++;
}
freeaddrinfo(res0);
if (num_inets < 0) {
fprintf(stderr, "Cannot bind any address.");
exit(1);
}
}
void
open_socket()
{
if (inet_enable)
open_af_inet();
if (domain_enable)
open_af_unix();
}
static int
connect_af_unix()
{
struct sockaddr_un sunix;
int i = sizeof(sunix);
int fd;
if ((fd = accept(fd_unix, (struct sockaddr *)&sunix, &i)) == ERROR)
warning_out("Can't accept AF_UNIX socket");
return fd;
}
static int
connect_af_inet(int fd_inet)
{
struct sockaddr_in sin;
int i = sizeof(sin);
int fd = 0;
if ((fd = accept(fd_inet, (struct sockaddr *)&sin, &i)) == ERROR)
warning_out("Can't accept AF_INET socket");
#ifdef USE_LIBWRAP
{
struct request_info req;
request_init(&req, RQ_DAEMON, "sj3", RQ_FILE, fd_inets[i], NULL);
fromhost(&req);
if (!hosts_access(&req)) {
warning_out("connection refused from %s",
eval_client(&req));
close(fd);
fd = -1;
}
}
#endif
return fd;
}
static void
close_af_unix()
{
struct sockaddr_un sunix;
int true = 1;
int i;
ioctl(fd_unix, FIONBIO, &true);
for ( ; ; ) {
i = sizeof(sunix);
if (accept(fd_unix, (struct sockaddr *)&sunix, &i) < 0)
break;
}
shutdown(fd_unix, 2);
close(fd_unix);
unlink(domain_socket_name);
clr_fd(fd_unix);
}
static void
close_af_inet()
{
struct sockaddr_in sin;
int true = 1;
int i, j;
for (j = 0; j < num_inets; j++) {
ioctl(fd_inets[j], FIONBIO, &true);
for ( ; ; ) {
i = sizeof(sin);
if (accept(fd_inets[j], (struct sockaddr *)&sin, &i) < 0)
break;
}
shutdown(fd_inets[j], 2);
close(fd_inets[j]);
clr_fd(fd_inets[j]);
}
}
void
close_socket()
{
if (inet_enable)
close_af_unix();
if (domain_enable)
close_af_inet();
}
static void
connect_client(fd_set *readfds)
{
int fd = -1;
Client *client_tmp;
int i;
for (i = 0; i < num_inets; i++) {
if (FD_ISSET(fd_inets[i], readfds)) {
fd = connect_af_inet(fd_inets[i]);
break;
}
}
if (fd < 0 && FD_ISSET(fd_unix, readfds))
fd = connect_af_unix();
if (fd == ERROR)
return;
if (client_num >= MAXCLIENTNUM || client_num >= max_client) {
warning_out("No more client");
}
else {
debug_out(1, "client create(%d)\n", fd);
logging_out("connect to client on %d", fd);
if (client_tmp = (Client *)malloc(sizeof(Client))) {
memset(client_tmp, 0, sizeof(Client));
client_tmp->fd = fd;
client_tmp->next = client;
client = client_tmp;
client_num++;
set_fd(fd);
return;
}
warning_out("No more client(Can't alloc)");
}
shutdown(fd, 2);
close(fd);
}
static Client *
disconnect_client(Client *cp)
{
WorkArea *wp;
StdyFile *sp;
int fd;
Client *cl_tmp, *cl_before;
if (sp = cp->stdy) closestdy(sp);
if (wp = cp->work) free_workarea(wp);
debug_out(1, "client dead(%d)\n", cp->fd);
logging_out("disconnect from client on %d", cp->fd);
shutdown(fd = cp->fd, 2);
close(fd);
clr_fd(fd);
if (cp == client) {
client = cp->next;
free(cp);
cp = client;
} else {
cl_before = client;
cl_tmp = client->next;
while (cl_tmp) {
if (cl_tmp == cp) {
cl_before->next = cp->next;
free(cp);
break;
}
cl_before = cl_tmp;
cl_tmp = cl_tmp->next;
}
cp = cl_before->next;
}
client_num--;
return cp;
}
void
communicate()
{
signal(SIGPIPE, SIG_IGN);
for ( ; ; ) {
fd_set readfds;
readfds = fds_org;
while (select(maxfds, &readfds, NULL, NULL, NULL) == ERROR) {
if (errno != EINTR)
error_out("select");
errno = 0;
}
for (cur_client = client ; cur_client; ) {
if (setjmp(client_dead)) {
cur_client = disconnect_client(cur_client);
continue;
}
if (FD_ISSET(cur_client->fd, &readfds)) {
client_fd = cur_client->fd;
putpos = buflen = getpos = 0;
execute_cmd();
}
cur_client = cur_client->next;
}
connect_client(&readfds);
}
}
void
put_flush()
{
int len;
int i;
char *p;
for (len = putpos, p = putbuf ; len > 0 ; ) {
if ((i = write(client_fd, p, len)) == ERROR) {
longjmp(client_dead, -1);
}
len -= i;
p += i;
}
putpos = 0;
}
void
put_byte(int c)
{
putbuf[putpos++] = c;
if (putpos >= sizeof(putbuf))
put_flush();
}
void
put_work(int c)
{
put_byte(c >> 8);
put_byte(c & 0xff);
}
void
put_int(int c)
{
put_byte(c >> (8 * 3));
put_byte(c >> (8 * 2));
put_byte(c >> (8 * 1));
put_byte(c);
}
u_char *
put_string(u_char *p)
{
if (p) {
do {
put_byte(*p);
} while (*p++);
}
else
put_byte(0);
return p;
}
u_char *
put_ndata(u_char *p, int n)
{
while (n-- > 0)
put_byte(p ? *p++ : 0);
return p;
}
void
get_buf()
{
int i;
for ( ; ; ) {
if ((i = read(client_fd, getbuf, sizeof(getbuf))) > 0)
break;
if (i == ERROR) {
if (errno == EINTR)
continue;
if (errno == EWOULDBLOCK)
continue;
}
longjmp(client_dead, -1);
}
buflen = i;
getpos = 0;
}
int
get_byte()
{
if (getpos >= buflen) get_buf();
return (getbuf[getpos++] & 0xff);
}
int
get_word()
{
int i;
i = get_byte();
return ((i << 8) | get_byte());
}
int
get_int()
{
int i0;
int i1;
int i2;
i0 = get_byte();
i1 = get_byte();
i2 = get_byte();
return((i0 << (8*3)) | (i1 << (8*2)) | (i2 << (8*1)) | get_byte());
}
int
get_nstring(u_char *p, int n)
{
int c;
do {
c = get_byte();
if (n-- > 0)
*p++ = c;
} while (c);
return (n < 0) ? ERROR : 0;
}
u_char *
get_ndata(u_char *p, int n)
{
while (n-- > 0)
*p++ = get_byte();
return p;
}

187
trunk/src/sj3serv/error.c Normal file
View file

@ -0,0 +1,187 @@
/*
* 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: error.c,v $
* $SonyRevision: 1.1 $
* $SonyDate: 1994/06/03 08:02:51 $
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <time.h>
#include "sj_typedef.h"
#include "sj_kanakan.h"
#include "sj3serv.h"
static char *tty_name = "/dev/tty";
static FILE *errfp = NULL;
static FILE *logfp = NULL;
static FILE *dbgfp = NULL;
static char *
format_time()
{
#define TBUF_LEN 2048
static char buf[TBUF_LEN];
time_t now;
time(&now);
strftime(buf, sizeof(buf), "%h %e %T ", localtime(&now));
return buf;
}
int
open_error()
{
int flg = 0;
if (error_file && *error_file) {
if (!strcmp(error_file, tty_name)) {
errfp = stderr;
flg = -1;
}
else if (!(errfp = fopen(error_file, "a")))
fprintf(stderr, "can't open \"%s\"\n", error_file);
}
else
errfp = NULL;
return flg;
}
void
error_out(const char *fmt, ...)
{
va_list ap;
char tmp[BUFSIZ];
if (errfp) {
va_start(ap, fmt);
vsnprintf(tmp, sizeof(tmp), fmt, ap);
va_end(ap);
fprintf(errfp, "%s%s: %s\n", format_time(), program_name, tmp);
fflush(errfp);
}
exit(1);
}
void
warning_out(const char *fmt, ...)
{
va_list ap;
char tmp[BUFSIZ];
if (errfp) {
va_start(ap, fmt);
vsnprintf(tmp, sizeof(tmp), fmt, ap);
va_end(ap);
fprintf(errfp, "%s%s: warning: %s\n", format_time(), program_name, tmp);
fflush(errfp);
}
}
int
open_log()
{
int flg = 0;
if (log_file && *log_file) {
if (!strcmp(log_file, tty_name)) {
logfp = stderr;
flg = -1;
}
else
logfp = fopen(log_file, "a");
if (logfp) {
fprintf(logfp, "%s%s log started\n",
format_time(), program_name);
fflush(logfp);
}
else
fprintf(stderr, "can't open \"%s\"\n", log_file);
}
else
logfp = NULL;
return flg;
}
void
logging_out(const char *fmt, ...)
{
va_list ap;
char tmp[BUFSIZ];
if (logfp) {
va_start(ap, fmt);
vsnprintf(tmp, sizeof(tmp), fmt, ap);
va_end(ap);
fprintf(logfp, "%s%s\n", format_time(), tmp);
fflush(logfp);
}
}
int
open_debug()
{
int flg = 0;
if (debug_file && *debug_file) {
if (!strcmp(debug_file, tty_name)) {
dbgfp = stderr;
flg = -1;
}
else if (!(dbgfp = fopen(debug_file, "a")))
fprintf(stderr, "can't open \"%s\"\n", debug_file);
}
else
dbgfp = NULL;
return flg;
}
void
debug_out(int lvl, const char *fmt, ...)
{
va_list ap;
if (lvl <= debug_level && dbgfp) {
va_start(ap, fmt);
vfprintf(dbgfp, fmt, ap);
va_end(ap);
fflush(dbgfp);
}
}

1714
trunk/src/sj3serv/execute.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,26 @@
#!/bin/sh
#
# PROVIDE: sj3
# REQUIRE: DAEMON
# BEFORE: LOGIN
# KEYWORD: shutdown
# Define these sj3_* variables in one of these files:
# /etc/rc.conf
# /etc/rc.conf.local
# /etc/rc.conf.d/sj3
#
# DO NOT CHANGE THESE DEFAULT VALUES HERE
#
sj3_enable=${sj3_enable:-"NO"} # Enable sj3
#sj3_program="%%PREFIX%%/sbin/sj3serv" # Location of sj3
. %%RC_SUBR%%
name="sj3"
rcvar=`set_rcvar`
command="%%PREFIX%%/sbin/sj3serv"
load_rc_config $name
run_rc_command "$1"

203
trunk/src/sj3serv/main.c Normal file
View file

@ -0,0 +1,203 @@
/*
* 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: main.c,v $
* $SonyRevision: 1.3 $
* $SonyDate: 1995/02/03 07:38:44 $
*/
#include <config.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <pwd.h>
#include <unistd.h>
#include "sj3serv.h"
#ifndef lint
static char rcsid_sony[] = "$Header: /export/work/contrib/sj3/server/RCS/main.c,v 1.12 1994/06/03 07:41:30 notanaka Exp $ SONY;";
#endif
static void
opening()
{
printf("Kana-Kanji Conversion Server Version %s\r\n", version_number);
printf("Copyright (c) 1990-1995 Sony Corporation\r\n");
printf("Build at %s\r\n", time_stamp);
}
int
make_pidfile()
{
int fd;
char buf[BUFSIZ];
size_t len;
fd = open(pid_file, O_CREAT | O_WRONLY | O_EXCL, 0600);
if (fd < 0) {
fprintf(stderr, "can't create file '%s'\n", pid_file);
return ERROR;
}
snprintf(buf, sizeof(buf), "%d", getpid());
len = strlen(buf);
if (write(fd, buf, strlen(buf)) != len) {
fprintf(stderr, "can't write file '%s'\n", pid_file);
close(fd);
return ERROR;
}
close(fd);
if (!chroot_enable)
return 0;
return 0;
}
int
erase_pidfile()
{
return unlink(pid_file);
}
static int
signal_handler(int sig)
{
static int wantwarn = 0;
if (wantwarn)
return 0;
wantwarn = 1;
warning_out("signal %d catched.", sig);
wantwarn = 0;
return 0;
}
static int
terminate_handler(int sig)
{
static int wantdie = 0;
if (wantdie)
return 0;
wantdie = 1;
warning_out("terminate signal %d catched.", sig);
server_terminate();
}
void
server_terminate()
{
close_socket();
sj_closeall();
exit_auth();
erase_pidfile();
exit(0);
}
static void
set_signals()
{
signal(SIGHUP, (void (*)(int))signal_handler);
signal(SIGINT, (void (*)(int))terminate_handler);
signal(SIGQUIT, (void (*)(int))signal_handler);
signal(SIGTERM, (void (*)(int))terminate_handler);
}
static void
exec_daemon()
{
open_error();
open_log();
open_debug();
if (daemon_enable) {
daemon(0, 1);
}
}
int
main(int argc, char **argv)
{
setlocale(LC_ALL, "");
parse_arg(argc, argv);
opening();
set_default();
read_runcmd();
exec_daemon();
exec_auth();
set_signals();
socket_init();
open_socket();
if (chroot_enable == 1)
set_priv(NULL);
preload_dict();
preopen_dict();
if (make_pidfile() == ERROR) {
fprintf(stderr, "already running...\n");
fflush(stderr);
exit_auth();
exit(1);
}
communicate();
close_socket();
sj_closeall();
exit_auth();
erase_pidfile();
exit(0);
}

61
trunk/src/sj3serv/priv.c Normal file
View file

@ -0,0 +1,61 @@
/*
* Copyright (c) 2004 Iwata <iwata@quasiquote.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include "sj3serv.h"
void
set_priv(const char *title)
{
struct passwd *pw;
if (!chroot_enable)
return;
if ((pw = getpwnam(chuser_name)) == NULL) {
fprintf(stderr, "failed to get user \"%s\"\n", chuser_name);
fflush(stderr);
exit(255);
}
if (chroot(chroot_dir) != 0) {
fprintf(stderr, "can't chroot\n");
fflush(stderr);
exit(255);
}
if (chdir("/") != 0) {
fprintf(stderr, "can't change directory '/'\n");
fflush(stderr);
exit(255);
}
if (title != NULL)
setproctitle("%s %s", pw->pw_name, title);
/*
* Drop privileges and clear the group access list
*/
if (setgroups(1, &pw->pw_gid) == -1 ||
setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) == -1 ||
setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) == -1) {
fprintf(stderr, "can't drop privileges\n");
fflush(stderr);
exit(255);
}
}

631
trunk/src/sj3serv/setup.c Normal file
View file

@ -0,0 +1,631 @@
/*
* 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: setup.c,v $
* $SonyRevision: 1.3 $
* $SonyDate: 1994/12/09 11:27:07 $
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include "sj_typedef.h"
#include "sj_const.h"
#include "sj_var.h"
#include "sj_dict.h"
#include "sj_struct.h"
#include "sj_rename.h"
#include "Const.h"
#include "Struct.h"
#include "sj_global.h"
#include "sys-queue.h"
#include "sj3serv.h"
char program_name[MAXPATHLEN];
char runcmd_file[MAXPATHLEN];
int daemon_enable = -1;
char pid_file[MAXPATHLEN];
int inet_enable = -1;
char inet_address_family[256];
int address_family = AF_UNSPEC;
char inet_host_name[MAXHOSTNAMELEN];
char inet_port_name[256];
int domain_enable = -1;
char domain_socket_name[MAXPATHLEN];
char dict_dir[MAXPATHLEN];
char dict_file[FILENAME_MAX];
char chuser_name[BUFSIZ];
int chroot_enable = -1;
char chroot_dir[MAXPATHLEN];
char log_file[MAXPATHLEN];
char debug_file[MAXPATHLEN];
int debug_level = -1;
char error_file[MAXPATHLEN];
int max_client = -1;
TAILQ_HEAD(, dict_entry) open_dict_head, read_dict_head;
struct dict_entry {
char filename[MAXPATHLEN];
char passwd[256];
TAILQ_ENTRY(dict_entry) entries;
} *read_dict, *open_dict;
int dir_mode = -1;
int file_mode = S_IRUSR | S_IWUSR;
TAILQ_HEAD(, allow_user_entry) allow_user_head;
struct allow_user_entry {
char username[BUFSIZ];
char hostname[MAXHOSTNAMELEN];
TAILQ_ENTRY(allow_user_entry) entries;
} *allow_user;
static int opt_daemon_disable = 0;
static int opt_ipv4 = 0;
static int opt_ipv6 = 0;
static lua_State *lua_state;
static int
check_table(lua_State *lstate)
{
if (!lua_istable(lstate, 1)) {
fprintf(stderr, "Illegal type of table (type=%s).\n",
lua_typename(lstate, lua_type(lstate, 1)));
return 0;
}
return 1;
}
static int
lua2sj_boolean(lua_State *lstate, char *name, int idx, int default_val, int *i)
{
lua_getfield(lstate, idx, name);
lua_pop(lstate, idx);
if (lua_isboolean(lstate, idx - 1)) {
*i = (int)lua_toboolean(lstate, idx - 1);
return *i;
} else if (lua_isnil(lstate, idx - 1)) {
*i = default_val;
return *i;
} else {
fprintf(stderr, "Illegal type of '%s'(%s), must be boolean.\n",
name, lua_typename(lstate, lua_type(lstate, idx - 1)));
exit(1);
}
}
static int
lua2sj_integer(lua_State *lstate, char *name, int idx, int default_val, int *i)
{
lua_getfield(lstate, idx, name);
lua_pop(lstate, idx);
if (lua_isnumber(lstate, idx - 1)) {
*i = (int)lua_tonumber(lstate, idx - 1);
return *i;
} else if (lua_isnil(lstate, idx - 1)) {
*i = default_val;
return *i;
} else {
fprintf(stderr, "Illegal type of '%s'(%s), must be integer.\n",
name, lua_typename(lstate, lua_type(lstate, idx - 1)));
exit(1);
}
}
static char *
lua2sj_string(lua_State *lstate, char *name, int idx, char *default_val, char *str, size_t len)
{
lua_getfield(lstate, idx, name);
lua_pop(lstate, idx);
if (lua_isstring(lstate, idx - 1)) {
strlcpy(str, lua_tostring(lstate, idx - 1), len);
return str;
} else if (lua_isnil(lstate, idx - 1)) {
if (default_val == NULL)
str[0] = '\0';
else
strlcpy(str, default_val, len);
return str;
} else {
fprintf(stderr, "Illegal type of '%s'(%s), must be string.\n",
name, lua_typename(lstate, lua_type(lstate, idx - 1)));
exit(1);
}
}
static void
sj2lua_boolean(lua_State *lstate, char *name, int i)
{
lua_pushstring(lstate, name);
lua_pushboolean(lstate, i);
lua_settable(lstate, -3);
}
static void
sj2lua_integer(lua_State *lstate, char *name, int i)
{
lua_pushstring(lstate, name);
lua_pushnumber(lstate, i);
lua_settable(lstate, -3);
}
static void
sj2lua_string(lua_State *lstate, char *name, char *s)
{
lua_pushstring(lstate, name);
lua_pushstring(lstate, s);
lua_settable(lstate, -3);
}
static int
set_server(lua_State *lstate)
{
if (!check_table(lstate))
return 0;
lua2sj_boolean(lstate, "daemon", 1, FORKFLAG, &daemon_enable);
lua2sj_string(lstate, "pidfile", 1, PIDFILE, pid_file, sizeof(pid_file));
lua2sj_integer(lstate, "max_client", 1, MAXCLIENTNUM, &max_client);
lua2sj_string(lstate, "dict_dir", 1, DICTROOTDIR, dict_dir, sizeof(dict_dir));
lua2sj_string(lstate, "user", 1, SJ3OWNER, chuser_name, sizeof(chuser_name));
lua2sj_boolean(lstate, "chroot", 1, CHROOTFLAG, &chroot_enable);
lua2sj_string(lstate, "chroot_dir", 1, CHROOTDIR, chroot_dir, sizeof(dict_dir));
return 0;
}
static int
get_server(lua_State *lstate)
{
lua_newtable(lstate);
sj2lua_boolean(lstate, "daemon", daemon_enable);
sj2lua_string(lstate, "pidfile", pid_file);
sj2lua_integer(lstate, "max_client", max_client);
sj2lua_string(lstate, "dict_dir", dict_dir);
return 1;
}
static int
set_inet(lua_State *lstate)
{
if (!check_table(lstate))
return 0;
lua2sj_boolean(lstate, "enable", 1, 0, &inet_enable);
lua2sj_string(lstate, "address_family", 1, ADDRESSFAMILY, inet_address_family, sizeof(inet_address_family));
lua2sj_string(lstate, "host_name", 1, LOCALHOST, inet_host_name, sizeof(inet_host_name));
lua2sj_string(lstate, "port_name", 1, PORTNUMBER, inet_port_name, sizeof(inet_port_name));
return 0;
}
static int
get_inet(lua_State *lstate)
{
sj2lua_boolean(lstate, "enable", inet_enable);
sj2lua_string(lstate, "address_family", inet_address_family);
sj2lua_string(lstate, "host_name", inet_host_name);
sj2lua_string(lstate, "port_name", inet_port_name);
return 1;
}
static int
set_domain(lua_State *lstate)
{
if (!check_table(lstate))
return 0;
lua2sj_boolean(lstate, "enable", 1, 0, &domain_enable);
lua2sj_string(lstate, "socket_name", 1, SOCKETNAME, domain_socket_name, sizeof(domain_socket_name));
return 0;
}
static int
get_domain(lua_State *lstate)
{
sj2lua_boolean(lstate, "enable", domain_enable);
sj2lua_string(lstate, "socket_name", domain_socket_name);
return 1;
}
static int
append_readdict(lua_State *lstate)
{
char dict[MAXPATHLEN];
char passwd[BUFSIZ];
if (!check_table(lstate))
return 0;
lua2sj_string(lstate, "file", 1, NULL, dict, sizeof(dict));
lua2sj_string(lstate, "passwd", 1, NULL, passwd, sizeof(passwd));
read_dict = malloc(sizeof(struct dict_entry));
strlcpy(read_dict->filename, dict, sizeof(read_dict->filename));
strlcpy(read_dict->passwd, passwd, sizeof(read_dict->passwd));
TAILQ_INSERT_TAIL(&read_dict_head, read_dict, entries);
return 0;
}
static int
append_opendict(lua_State *lstate)
{
char dict[MAXPATHLEN];
char passwd[BUFSIZ];
if (!check_table(lstate))
return 0;
lua2sj_string(lstate, "file", 1, NULL, dict, sizeof(dict));
lua2sj_string(lstate, "passwd", 1, NULL, passwd, sizeof(passwd));
open_dict = malloc(sizeof(struct dict_entry));
strlcpy(open_dict->filename, dict, sizeof(open_dict->filename));
strlcpy(open_dict->passwd, passwd, sizeof(open_dict->passwd));
TAILQ_INSERT_TAIL(&open_dict_head, open_dict, entries);
return 0;
}
static int
set_log(lua_State *lstate)
{
if (!check_table(lstate))
return 0;
lua2sj_string(lstate, "file", 1, LOGOUTFILE, log_file, sizeof(log_file));
return 0;
}
static int
get_log(lua_State *lstate)
{
sj2lua_string(lstate, "file", log_file);
return 1;
}
static int
set_debug(lua_State *lstate)
{
if (!check_table(lstate))
return 0;
lua2sj_string(lstate, "file", 1, DEBUGOUTFILE, debug_file, sizeof(debug_file));
lua2sj_integer(lstate, "level", 1, DEBUGLEVEL, &debug_level);
return 0;
}
static int
get_debug(lua_State *lstate)
{
sj2lua_string(lstate, "file", debug_file);
sj2lua_integer(lstate, "level", debug_level);
return 1;
}
static int
set_error(lua_State *lstate)
{
if (!check_table(lstate))
return 0;
lua2sj_string(lstate, "file", 1, ERROROUTFILE, error_file, sizeof(error_file));
return 0;
}
static int
append_allowuser(lua_State *lstate)
{
char username[BUFSIZ];
char hostname[MAXHOSTNAMELEN];
if (!check_table(lstate))
return 0;
lua2sj_string(lstate, "user", 1, NULL, username, sizeof(username));
lua2sj_string(lstate, "host", 1, NULL, hostname, sizeof(hostname));
allow_user = malloc(sizeof(struct allow_user_entry));
strlcpy(allow_user->username, username, sizeof(allow_user->username));
strlcpy(allow_user->hostname, hostname, sizeof(allow_user->hostname));
TAILQ_INSERT_TAIL(&allow_user_head, allow_user, entries);
return 0;
}
static int
get_error(lua_State *lstate)
{
sj2lua_string(lstate, "file", error_file);
return 0;
}
void
set_luafunction(lua_State *lstate, char *name, lua_CFunction fun)
{
lua_pushstring(lstate, name);
lua_pushcfunction(lstate, fun);
lua_settable(lstate, -3);
}
void
read_runcmd()
{
if (lua_state == NULL) {
exit(1);
}
luaL_openlibs(lua_state);
if (luaL_dofile(lua_state, runcmd_file) != 0) {
fprintf(stderr, "%s\n", lua_tostring(lua_state, -1));
exit(255);
}
/* overwrite from opt_args */
if (opt_daemon_disable)
daemon_enable = 0;
else
daemon_enable = 1;
if (opt_ipv4)
address_family = AF_INET;
else if (opt_ipv6)
address_family = AF_INET6;
else if (strcmp(inet_address_family, "inet") == 0)
address_family = AF_INET;
else if (strcmp(inet_address_family, "inet6") == 0)
address_family = AF_INET6;
#if 0 /* DON'T LEAVE */
lua_close(lua_state);
lua_state = NULL;
#endif
}
void
set_default()
{
if (lua_state != NULL) {
warning_out("lua is Already loaded, why?");
return;
}
if ((lua_state = luaL_newstate()) == NULL) {
warning_out("Can't setup lua");
return;
}
/* sj3.functions */
lua_newtable(lua_state);
set_luafunction(lua_state, "set_server", set_server);
set_luafunction(lua_state, "set_inet", set_inet);
set_luafunction(lua_state, "set_domain", set_domain);
set_luafunction(lua_state, "append_readdict", append_readdict);
set_luafunction(lua_state, "append_opendict", append_opendict);
set_luafunction(lua_state, "set_log", set_log);
set_luafunction(lua_state, "set_debug", set_debug);
set_luafunction(lua_state, "set_error", set_error);
set_luafunction(lua_state, "append_allowuser", append_allowuser);
set_luafunction(lua_state, "get_server", get_server);
set_luafunction(lua_state, "get_inet", get_inet);
set_luafunction(lua_state, "get_domain", get_domain);
set_luafunction(lua_state, "get_log", get_log);
set_luafunction(lua_state, "get_debug", get_debug);
set_luafunction(lua_state, "get_error", get_error);
TAILQ_INIT(&open_dict_head);
TAILQ_INIT(&read_dict_head);
TAILQ_INIT(&allow_user_head);
lua_setglobal(lua_state, "sj3");
}
extern char *optarg;
extern int optind;
void
parse_arg(int argc, char **argv)
{
int c;
int errflg = 0;
char *p;
size_t ret;
p = (p = strrchr(argv[0], '/')) ? p + 1 : argv[0];
strlcpy(program_name, p, sizeof(program_name));
strlcpy(runcmd_file, RUNCMDFILE, sizeof(runcmd_file));
while ((c = getopt(argc, argv, "46f:d")) != EOF) {
switch (c) {
case '4':
opt_ipv4 = 1;
break;
case '6':
opt_ipv6 = 1;
break;
case 'f':
ret = strlcpy(runcmd_file, optarg, sizeof(runcmd_file));
if (ret > sizeof(runcmd_file))
errflg++;
break;
case 'd':
opt_daemon_disable = 1;
break;
case '?':
default:
errflg++;
break;
}
}
if (errflg || optind < argc) {
fprintf(stderr, "Usage: %s [-46] [-d] [-f RunCmdFile]\n", program_name);
exit(1);
}
}
void
preload_dict()
{
struct dict_entry *np;
char filename[MAXPATHLEN];
work_base = (Global *)malloc(sizeof(Global));
if (!work_base) {
warning_out("can't load default dictionary(not enough memory)");
return;
}
TAILQ_FOREACH(np, &read_dict_head, entries) {
strlcpy(filename, (char *)np->filename, sizeof(filename));
if (make_full_path(filename, sizeof(filename)))
warning_out("too long filename \"%s\"", np->filename);
else if (opendict(filename, np->passwd))
logging_out("load dictionary \"%s\"", filename);
else
warning_out("can't open dictionary \"%s\"", filename);
}
free(work_base);
}
void
preopen_dict()
{
struct dict_entry *np;
char filename[MAXPATHLEN];
DICT *dict;
DICTL *dictl;
work_base = global_work_base = (Global *)malloc(sizeof(Global));
if (!work_base) {
warning_out("can't open default dictionary(not enough memory)");
return;
}
memset(work_base, 0, sizeof(Global));
TAILQ_FOREACH(np, &open_dict_head, entries) {
strlcpy(filename, np->filename, sizeof(filename));
if (make_full_path(filename, sizeof(filename)))
warning_out("too long filename \"%s\"", np->filename);
else if ((dict = (DICT *)opendict(filename, np->passwd)) != NULL) {
logging_out("open dictionary \"%s\"", filename);
if (!(dictl = (DICTL *)malloc(sizeof *dictl))) {
closedict((DictFile *)dict);
warning_out("can't open dictionary \"%s\"", filename);
continue;
}
dictl->dict = dict;
dictl->next = dictlist;
dictlist = dictl;
} else
warning_out("can't open dictionary \"%s\"", filename);
}
}
static int
str_match(char *s, char *d)
{
while (*d) {
if (*s == '*') {
while (*s == '*') s++;
if (!*s)
return TRUE;
while (*d) {
if (str_match(s, d))
return TRUE;
d++;
}
return FALSE;
}
if (*s != '?' && *s != *d)
break;
s++;
d++;
}
return (!*s) ? TRUE : FALSE;
}
int
check_user(char *user, char *host)
{
struct allow_user_entry *np;
if (TAILQ_EMPTY(&allow_user_head))
return TRUE;
TAILQ_FOREACH(np, &allow_user_head, entries) {
if (!str_match(np->username, user))
continue;
if (np->hostname)
if (!str_match(np->hostname, host))
continue;
return TRUE;
}
return FALSE;
}

156
trunk/src/sj3serv/sj3serv.h Normal file
View file

@ -0,0 +1,156 @@
/*
* Copyright (c) 2004 Iwata <iwata@quasiquote.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef SJ3SERV_H
#define SJ3SERV_H
#include <setjmp.h>
#include "sj_kanakan.h"
typedef struct {
uid_t uid;
gid_t gid;
} sj3_ugid;
/* auth.c */
int exec_auth();
void exit_auth();
int auth_getugid(char *, sj3_ugid *);
/* comuni.c */
extern int client_num;
extern Client *client;
extern Client *cur_client;
extern int maxfds;
extern fd_set fds_org;
extern jmp_buf client_dead;
extern int client_fd;
void socket_init();
void open_socket();
void close_socket();
void communicate();
void put_flush();
void put_byte(int);
void put_work(int);
void put_int(int);
u_char *put_string(u_char *);
u_char *put_ndata(u_char *, int);
void get_buf();
int get_byte();
int get_word();
int get_int();
int get_nstring(u_char *, int);
u_char *get_ndata(u_char *, int);
/* execute.c */
int make_full_path(char *, int);
WorkArea *alloc_workarea();
void free_workarea(WorkArea *);
void exec_connect();
void exec_disconnect();
void exec_opendict();
void exec_closedict();
void close_dictlist(DICTL *);
void exec_openstdy();
void exec_closestdy();
void exec_stdysize();
void exec_ph2knj(int);
void exec_cl2knj(int);
void exec_nextcl(int);
void exec_prevcl(int);
void exec_cl2knj_cnt(int);
void exec_cl2knj_all(int);
void exec_study();
void exec_clstudy(int);
void exec_adddict(int);
void exec_deldict(int);
void exec_getdict(int);
void exec_nextdict(int);
void exec_prevdict(int);
void exec_makedict();
void exec_makestdy();
void exec_access();
void exec_makedir();
void exec_who();
void exec_kill();
void exec_quit();
void exec_version();
void exec_dictpass();
void exec_dictcmnt();
void exec_stdypass();
void exec_stdycmnt();
void exec_stdypara();
void execute_cmd();
/* error.c */
int open_error();
void error_out(const char *, ...);
void warning_out(const char *, ...);
int open_log();
void logging_out(const char *, ...);
int open_debug();
void debug_out(int, const char *, ...);
/* main.c */
int make_pidfile();
void server_terminate();
extern char program_name [MAXPATHLEN];
extern char runcmd_file [MAXPATHLEN];
extern int daemon_enable;
extern char pid_file[MAXPATHLEN];
extern char chuser_name[BUFSIZ];
extern int chroot_enable;
extern char chroot_dir[MAXPATHLEN];
extern int inet_enable;
extern char inet_address_family[256];
extern int address_family;
extern char inet_host_name[MAXHOSTNAMELEN];
extern char inet_port_name[256];
extern int domain_enable;
extern char domain_socket_name[MAXPATHLEN];
extern char dict_dir[MAXPATHLEN];
extern char dict_file[FILENAME_MAX];
extern char log_file[MAXPATHLEN];
extern char debug_file[MAXPATHLEN];
extern int debug_level;
extern char error_file[MAXPATHLEN];
extern int max_client;
extern int dir_mode;
extern int file_mode;
int read_line(FILE *, char *, int);
void read_runcmd();
void set_default();
void parse_arg(int, char **);
void preload_dict();
void preopen_dict();
int check_user(char *, char *);
/* priv.c */
void set_priv(const char *);
/* timestamp.c */
extern char *time_stamp;
/* version.c */
extern char *version_number;
#endif

View file

@ -0,0 +1,117 @@
--[[ -- -*- lua -*-
Copyright (c) 2004 Iwata <iwata@quasiquote.org>
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
--]]
local prefix = "%%SJ3VARDIR%%"
sj3.set_server {
-- daemon: Boolean
-- set daemonize
daemon = true,
-- lockfile: String
-- pid file name
-- Note: this file is created after chroot
pidfile = "/run/sj3serv.pid",
-- max_client: Integer
-- client connect limit value
max_client = 512,
-- user: String
-- run as user name
user = "%%SJ3OWNER%%",
-- chroot: Boolean
-- sj3serv is chrooted or not
chroot = true,
-- chroot_dir: String
-- chrooted path
chroot_dir = prefix,
-- dict_dir: String
-- dictionary name
-- Note: this directory is opened after chroot
dict_dir = "/spool/sj3",
}
sj3.set_inet {
-- enable: Boolean
-- allow acccess via internet connection
enable = false,
-- family: String "unspec" or "inet4" or "inet6"
-- address family
address_family = "unspec",
-- host_name: String
-- listening address
host_name = "localhost",
-- port_name: String
-- binding port name, man services
port_name = "3086",
}
sj3.set_domain {
-- enable: Boolean
-- allow acccess via unix domain socket
enable = true,
-- socket_name: String
-- binding filename of unix domain socket
socket_name = prefix .. "/run/sj3serv.socket",
}
sj3.append_opendict {
-- dir: String
-- root directory of dictionaries
file = "sj3main.dic",
}
sj3.set_log {
-- file: String
-- output filename of log output
file = "/var/log/sj3",
}
sj3.set_debug {
-- file: String
-- output filename of debug out
file = nil,
-- debug_level: Integer
-- debug level
level = 0,
}
sj3.set_error {
-- file: String
-- output filename of error output
file = "/var/log/sj3_error",
}
--[[
sj3.append_allowuser {
-- file: String
-- allowed user name
user = "foo",
-- file: String
-- allowed host name
hostname = "bar",
}
--]]

View file

@ -0,0 +1,336 @@
/*
* Copyright (c) 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:03:58 $
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <locale.h>
#include "sj_euc.h"
#include "sj_string.h"
#ifndef TRUE
#define TRUE (1)
#define FALSE (0)
#endif
#define sjis2euc sj3_sjis2euc
#define euc2sjis sj3_euc2sjis
#define issjis1(c) (((0x81 <= (c)) && ((c) <= 0x9f)) || \
((0xe0 <= (c)) && ((c) <= 0xfc)))
#define iseuc(c) ((0xa1 <= (c)) && ((c) <= 0xfe))
#define iskana(c) ((0xa1 <= (c)) && ((c) <= 0xdf))
int
sj3_str_sjistoeuc(unsigned char *out, int outlen, unsigned char *in, unsigned char *sjis_default, int *useflag)
{
unsigned char *sjis = in, *euc = out;
int n = 0;
unsigned short code, default_code;
euc[0] = '\0';
*useflag = 0;
if (!sjis)
return 0;
while (*sjis && n < outlen) {
if (issjis1(*sjis)) {
code = sjis2euc((*sjis << 8) | *(sjis+1));
if (n + 2 > outlen)
return -1;
if (code == 0) {
default_code = sjis2euc((sjis_default[0] << 8)
| sjis_default[1]);
euc[n++] = default_code >> 8;
euc[n++] = default_code & 0xff;
(*useflag)++;
} else {
euc[n++] = code >> 8;
euc[n++] = code & 0xff;
}
sjis += 2;
} else {
if( *sjis >= 0xa1 && *sjis <= 0xdf ) {
if (n + 2 > outlen)
return -1;
euc[n++] = SS2;
}
euc[n++] = *sjis;
sjis++;
}
}
if (n > outlen)
return -1;
euc[n] = '\0';
return n;
}
int
sj3_str_euctosjis(unsigned char *out, int outlen, unsigned char *in, unsigned char *sjis_default, int *useflag)
{
unsigned char *euc = in, *sjis = out;
int n = 0;
unsigned short code, default_code;
sjis[0] = '\0';
*useflag = 0;
if (!euc)
return 0;
while (*euc && n < outlen) {
if (iseuc(*euc)) {
code = euc2sjis( (*euc << 8) | *(euc+1) );
if (n + 2 > outlen)
return -1;
if (code == 0) {
sjis[n++] = sjis_default[0];
sjis[n++] = sjis_default[1];
(*useflag)++;
} else {
sjis[n++] = code >> 8;
sjis[n++] = code & 0xff;
}
euc += 2;
} else if (*euc == SS3) {
if (n + 2 > outlen)
return -1;
sjis[n++] = sjis_default[0];
sjis[n++] = sjis_default[1];
euc += 3;
(*useflag)++;
} else if (*euc == SS2) {
sjis[n++] = *(euc + 1);
euc += 2;
} else {
sjis[n++] = *euc;
euc++;
}
}
if (n > outlen)
return -1;
sjis[n] = '\0';
return n;
}
int
sj3_sjistoeuclen(unsigned char *str, int max)
{
int len = 0, bytes = 1;
if (!max)
return 0;
while ((bytes <= max) && *str) {
if (issjis1(*str)) {
str++;
bytes++;
if (!*str)
break;
len += 2;
} else if (*str & 0x80) {
len += 2;
} else {
len++;
}
str++;
bytes++;
}
return len;
}
#define MASK 0x7f
#define MSB 0x80
static unsigned char def_char[] = {0x81, 0x40};
int
sj3_sjistoeuc(unsigned char *e, int elen, unsigned char *s, int slen)
{
int dummy;
return sj3_str_sjistoeuc(e, elen, s, def_char, &dummy);
}
int
sj3_euctosjis(unsigned char *s, int slen, unsigned char *e, int elen)
{
int dummy;
return sj3_str_euctosjis(s, slen, e, def_char, &dummy);
}
void
sj_euc2sjis(unsigned char *s)
{
s[0] &= MASK;
s[1] &= MASK;
sj_jis2sjis (s);
}
void
sj_jis2sjis(unsigned char *s)
{
int high, low;
int nh, nl;
high = s[0];
low = s[1];
nh = ((high - 0x21) >> 1) + 0x81;
if (nh > 0x9f)
nh += 0x40;
if (high & 1) {
nl = low + 0x1f;
if (low > 0x5f)
nl++;
} else
nl = low + 0x7e;
s[0] = nh;
s[1] = nl;
}
void
sj_sjis2euc(unsigned char *s)
{
sj_sjis2jis (s);
s[0] |= MSB;
s[1] |= MSB;
}
void
sj_sjis2jis(unsigned char *s)
{
int byte1, byte2;
unsigned char *sp;
sp = s;
byte1 = *sp++;
byte2 = *sp--;
if (byte1 <= 0x80 || byte1 >= 0xf0
|| ( byte1>=0xa0 && byte1<=0xdf )
|| byte2 <= 0x3f || byte2 >= 0xfe || byte2==0x7f ) {
byte1 = 0x81;
byte2 = 0x40;
}
byte1 -= (byte1 >= 0xa0) ? 0xc1 : 0x81;
if (byte2 >= 0x9f) {
*sp++ = (byte1 << 1) + 0x22;
*sp = byte2 - 0x7e;
} else {
*sp++ = (byte1 << 1) + 0x21;
*sp = byte2 - ((byte2 <= 0x7e) ? 0x1f : 0x20 );
}
}
unsigned short
sj3_jis2sjis(unsigned short code)
{
unsigned char tmp[3];
tmp[0] = (code >> 8) & 0xff;
tmp[1] = code & 0xff;
tmp[2] = '\0';
sj_jis2sjis((unsigned char *) tmp);
code = (tmp[0] << 8) + tmp[1];
return(code);
}
unsigned short
sj3_jis2euc(unsigned short code)
{
unsigned char tmp[3];
tmp[0] = (code >> 8) & 0xff;
tmp[1] = code & 0xff;
tmp[2] = '\0';
code = ((tmp[0] | 0x80) << 8) + (tmp[1] | 0x80);
return(code);
}
unsigned short
sj3_sjis2jis(unsigned short code)
{
unsigned char tmp[3];
tmp[0] = (code >> 8) & 0xff;
tmp[1] = code & 0xff;
tmp[2] = '\0';
sj_sjis2jis((unsigned char *) tmp);
code = (tmp[0] << 8) + tmp[1];
return(code);
}
unsigned short
sj3_euc2sjis(unsigned short code)
{
unsigned char tmp[3];
tmp[0] = (code >> 8) & 0xff;
tmp[1] = code & 0xff;
tmp[2] = '\0';
sj_euc2sjis((unsigned char *) tmp);
code = (tmp[0] << 8) + tmp[1];
return(code);
}
unsigned short
sj3_sjis2euc(unsigned short code)
{
unsigned char tmp[3];
tmp[0] = (code >> 8) & 0xff;
tmp[1] = code & 0xff;
tmp[2] = '\0';
sj_sjis2euc((unsigned char *) tmp);
code = (tmp[0] << 8) + tmp[1];
return(code);
}

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2004 Iwata <iwata@quasiquote.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef SJ3INTERN_H
#define SJ3INTERN_H
int sj3_str_sjistoeuc(unsigned char *, int, unsigned char *, unsigned char *, int *);
int sj3_str_euctosjis(unsigned char *, int, unsigned char *, unsigned char *, int *);
int sj3_sjistoeuclen(unsigned char *, int);
int sj3_sjistoeuc(unsigned char *s, int, unsigned char *, int);
int sj3_euctosjis(unsigned char *s, int, unsigned char *, int);
void sj_euc2sjis(unsigned char *);
void sj_jis2sjis(unsigned char *);
void sj_sjis2euc(unsigned char *);
void sj_sjis2jis(unsigned char *);
unsigned short sj3_jis2sjis(unsigned short);
unsigned short sj3_jis2euc(unsigned short);
unsigned short sj3_sjis2jis(unsigned short);
unsigned short sj3_euc2sjis(unsigned short);
unsigned short sj3_sjis2euc(unsigned short);
#endif /* SJ3INTERN_H */

View file

@ -0,0 +1,6 @@
#! /bin/sh
LC_ALL=C
export LC_ALL
echo "char *time_stamp = \"`date`\";"

View file

@ -0,0 +1,36 @@
/*
* 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: version.c,v $
* $SonyRevision: 1.9 $
* $SonyDate: 1998/04/08 13:11:10 $
*/
char *version_number = "2.08.99";

View file

@ -0,0 +1,16 @@
if BUILDABLE_SJ3CLIENT
INCLUDES = \
-I$(top_srcdir)/include/sj3compat \
-I$(top_srcdir)/include/sj3common \
-I$(top_srcdir)/include/sj3lib
LDADD = \
$(top_srcdir)/lib/sj3lib/libsj3lib.la \
$(top_srcdir)/lib/sj3compat/libsj3compat.la
sj3stat_SOURCES = sj3stat.c
bin_PROGRAMS = sj3stat
endif

117
trunk/src/sj3stat/sj3stat.c Normal file
View file

@ -0,0 +1,117 @@
/*
* Copyright (C) 1995 by Software Research Associates, Inc.
* Author: Y. Kawabe <kawabe@sra.co.jp>
*
* 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 SOFTWARE RESEARCH ASSOCIATES 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 Software Research
* Associates shall not be used in advertising or otherwise to
* promote the sale, use or other dealings in this Software without prior
* written authorization from Software Research Associates.
*/
/*
* $SonyRCSfile: sj3stat.c,v $
* $SonyRevision: 1.2 $
* $SonyDate: 1997/01/23 11:09:41 $
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "Const.h"
#include "sj3err.h"
#include "sj3lib.h"
#include "sj3lowlib.h"
#include "sj3intern.h"
int
main(int argc, char **argv)
{
SJ3_CLIENT_ENV clnt;
SJ3_WHO_STRUCT who[64];
char ver[256];
char pname[256];
char *hname;
char *uname;
int i, n;
char *p;
if ((argc > 1 && argv[1][0] == '-') || argc > 2) {
fprintf (stderr, "usage: %s [server]\n", argv[0]);
exit (1);
}
hname = getenv ("SJ3SERV");
uname = getenv ("USER");
if (argc > 1)
hname = argv[1];
if (uname == NULL)
uname = getlogin();
if (uname == NULL)
uname = "unknown";
snprintf (pname, sizeof(pname), "%d.sj3stat", getpid());
if (sj3_make_connection(&clnt, hname, uname, pname) == ERROR) {
char *server, *status;
server = hname ? hname : "localhost";
switch (sj3_error_number) {
case SJ3_ServerDown:
status = "down";
break;
case SJ3_GetHostByName:
status = "unknown";
break;
default:
status = "dead";
break;
}
fprintf(stderr, "Server '%s' is %s.\n", server, status);
return 1;
}
sj3_version(&clnt, ver, sizeof(ver));
n = sj3_who(&clnt, who, sizeof(who) / sizeof(who[0]));
for (p = ver; *p; p++) {
while (*p)
putc(*p++, stdout);
fprintf(stdout, ", ");
}
fprintf (stdout, "%d users.\n", n);
/*
* Change hostname entry's length.
* Because it's so short.
* Patched by Hidekazu Kuroki(hidekazu@cs.titech.ac.jp) 1996/8/10
*/
fprintf(stdout, "%-16s %-32s %-8s %s\n",
"(USER)", "(HOST)", "(FD)", "(CLIENT)");
for (i = 0; i < n; i++) {
fprintf(stdout, "%-16s %-32s %-8d %s\n", who[i].username,
who[i].hostname, who[i].fd, who[i].progname);
}
(void) sj3_erase_connection(&clnt);
return 0;
}