This commit is contained in:
Nishi 2026-06-19 01:31:17 +09:00
commit 145c203403
167 changed files with 77 additions and 41295 deletions

View file

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

View file

@ -1,20 +0,0 @@
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

View file

@ -1,359 +0,0 @@
/*
* 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

@ -1,26 +0,0 @@
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

View file

@ -1,158 +0,0 @@
/*
* 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

@ -1,99 +0,0 @@
/*
* 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);
}

View file

@ -1,227 +0,0 @@
/*
* 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++;
}
}
}
}

View file

@ -1,258 +0,0 @@
/*
* 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;
}

View file

@ -1,333 +0,0 @@
/*
* 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);
}

View file

@ -1,87 +0,0 @@
/*
* 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 */

View file

@ -1,108 +0,0 @@
/*
* 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

@ -1,77 +0,0 @@
/*
* 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

View file

@ -1,290 +0,0 @@
/*
* 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);
}

View file

@ -1,69 +0,0 @@
/*
* 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

@ -1,31 +0,0 @@
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

View file

@ -1,62 +0,0 @@
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

View file

@ -1,230 +0,0 @@
/*
* 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;
}

View file

@ -1,586 +0,0 @@
/*
* 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;
}

View file

@ -1,187 +0,0 @@
/*
* 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);
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,26 +0,0 @@
#!/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"

View file

@ -1,203 +0,0 @@
/*
* 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);
}

View file

@ -1,61 +0,0 @@
/*
* 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);
}
}

View file

@ -1,631 +0,0 @@
/*
* 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;
}

View file

@ -1,156 +0,0 @@
/*
* 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

@ -1,117 +0,0 @@
--[[ -- -*- 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

@ -1,336 +0,0 @@
/*
* 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

@ -1,36 +0,0 @@
/*
* 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

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

View file

@ -1,36 +0,0 @@
/*
* 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

@ -1,16 +0,0 @@
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

View file

@ -1,117 +0,0 @@
/*
* 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;
}