Import sj3-patches-20040916

Signed-off-by: Masanori Ogino <mogino@acm.org>
This commit is contained in:
Masanori Ogino 2023-11-27 11:34:52 +09:00
commit a76f53bc03
78 changed files with 3433 additions and 3852 deletions

View file

@ -31,13 +31,15 @@
* $SonyRCSfile: comuni.c,v $
* $SonyRevision: 1.4 $
* $SonyDate: 1994/11/16 07:34:05 $
*
* $Id$
*/
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "sj_sysvdef.h"
#include "sj_kcnv.h"
#include <sys/socket.h>
@ -109,8 +111,8 @@ static int buflen = 0;
static int getpos = 0;
socket_init()
void
socket_init(void)
{
#ifdef SVR4
int i;
@ -129,8 +131,8 @@ socket_init()
static void set_fd(fd)
int fd;
static void
set_fd(int fd)
{
#ifdef SVR4
poll_fds[maxfds].fd = fd;
@ -144,11 +146,11 @@ int fd;
static void clr_fd(fd)
int fd;
static void
clr_fd(int fd)
{
#ifdef SVR4
register int i, j;
int i, j;
for (i = 0; i < maxfds; i++) {
if (poll_fds[i].fd == fd) {
@ -178,7 +180,8 @@ int fd;
#if (!defined(TLI) || (defined(TLI) && defined(SOCK_UNIX)))
static void open_af_unix()
static void
open_af_unix(void)
{
struct sockaddr_un sunix;
@ -223,7 +226,8 @@ struct netconfig *nconf;
#endif
static void open_af_inet()
static void
open_af_inet(void)
{
#ifdef TLI
struct t_bind *req;
@ -335,7 +339,7 @@ static void open_af_inet()
inet_callptr->udata.len = 0;
inet_callptr->udata.buf = (char *) NULL;
#else
if (sp = getservbyname(port_name, "tcp"))
if ((sp = getservbyname(port_name, "tcp")) != NULL)
port = ntohs(sp -> s_port);
else
port = port_number;
@ -379,7 +383,9 @@ static void open_af_inet()
#endif
set_fd(fd_inet);
}
open_socket()
void
open_socket(void)
{
open_af_inet();
#if (!defined(TLI) || (defined(TLI) && defined(SOCK_UNIX)))
@ -390,7 +396,8 @@ open_socket()
#if (!defined(TLI) || (defined(TLI) && defined(SOCK_UNIX)))
static int connect_af_unix()
static int
connect_af_unix(void)
{
struct sockaddr_un sunix;
int i = sizeof(sunix);
@ -401,13 +408,10 @@ static int connect_af_unix()
return fd;
}
#endif
#ifdef TLI
int
accept_func(fd, callptr, name, closeflg)
int fd;
struct t_call *callptr;
char *name;
int closeflg;
accept_func(int fd, struct t_call* callptr, char* name, int closeflg)
{
int newfd;
int look;
@ -441,7 +445,8 @@ int closeflg;
static int connect_af_inet()
static int
connect_af_inet(void)
{
#ifndef TLI
struct sockaddr_in sin;
@ -466,7 +471,8 @@ static int connect_af_inet()
#if (!defined(TLI) || (defined(TLI) && defined(SOCK_UNIX)))
static void close_af_unix()
static void
close_af_unix(void)
{
struct sockaddr_un sunix;
int true = 1;
@ -486,7 +492,8 @@ static void close_af_unix()
static void close_af_inet()
static void
close_af_inet(void)
{
#ifndef TLI
struct sockaddr_in sin;
@ -514,7 +521,9 @@ static void close_af_inet()
clr_fd(fd_inet);
#endif
}
close_socket()
void
close_socket(void)
{
#if (!defined(TLI) || (defined(TLI) && defined(SOCK_UNIX)))
close_af_unix();
@ -524,11 +533,11 @@ close_socket()
static void connect_client(readfds)
static void
#ifdef SVR4
struct pollfd *readfds;
connect_client(struct pollfd *readfds)
#else
fd_set *readfds;
connect_client(fd_set *readfds)
#endif
{
int fd;
@ -591,7 +600,7 @@ fd_set *readfds;
logging_out("connect to client on %d", fd);
if (client_tmp = (Client *)malloc(sizeof(Client))) {
if ((client_tmp = (Client *)malloc(sizeof(Client))) != NULL) {
memset(client_tmp, 0, sizeof(Client));
client_tmp->fd = fd;
#if (defined(TLI) && defined(SOCK_UNIX))
@ -629,17 +638,16 @@ fd_set *readfds;
static Client *disconnect_client(cp)
Client *cp;
static Client*
disconnect_client(Client *cp)
{
WorkArea *wp;
StdyFile *sp;
int fd;
Client *cl_tmp, *cl_before;
int i;
if (sp = cp->stdy) closestdy(sp);
if (wp = cp->work) free_workarea(wp);
if ((sp = cp->stdy) != NULL) closestdy(sp);
if ((wp = cp->work) != NULL) free_workarea(wp);
debug_out(1, "client dead(%d)\r\n", cp->fd);
logging_out("disconnect from client on %d", cp->fd);
@ -692,7 +700,8 @@ Client *cp;
#include <signal.h>
#endif
void communicate()
void
communicate(void)
{
signal(SIGPIPE, SIG_IGN);
@ -751,12 +760,12 @@ void communicate()
}
void put_flush()
void
put_flush(void)
{
register int len;
register int i;
register char *p;
int len;
int i;
char *p;
for (len = putpos, p = putbuf ; len > 0 ; ) {
if ((i = write(client_fd, p, len)) == ERROR) {
@ -767,28 +776,36 @@ void put_flush()
}
putpos = 0;
}
void put_byte(c)
register int c;
void
put_byte(int c)
{
putbuf[putpos++] = c;
if (putpos >= sizeof(putbuf)) put_flush();
}
void put_work(c)
register int c;
void
put_work(int c)
{
put_byte(c >> 8);
put_byte(c & 0xff);
}
void put_int(c)
register int c;
void
put_int(int c)
{
put_byte(c >> (8 * 3));
put_byte(c >> (8 * 2));
put_byte(c >> (8 * 1));
put_byte(c);
}
Uchar *put_string(p)
register Uchar *p;
u_char*
put_string(u_char* p)
{
if (p) {
do {
@ -799,19 +816,20 @@ register Uchar *p;
put_byte(0);
return p;
}
Uchar *put_ndata(p, n)
register Uchar *p;
register int n;
u_char*
put_ndata(u_char* p, int n)
{
while (n-- > 0) put_byte(p ? *p++ : 0);
return p;
}
void get_buf()
void
get_buf(void)
{
register int i;
int i;
for (;;) {
if ((i = read(client_fd, getbuf, sizeof(getbuf))) > 0) break;
@ -824,34 +842,44 @@ void get_buf()
buflen = i;
getpos = 0;
}
int get_byte()
int
get_byte(void)
{
if (getpos >= buflen) get_buf();
return (getbuf[getpos++] & 0xff);
}
int get_word()
int
get_word(void)
{
register int i;
int i;
i = get_byte();
return ((i << 8) | get_byte());
}
int get_int()
int
get_int(void)
{
register int i0;
register int i1;
register int i2;
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(p, n)
register Uchar *p;
register int n;
int
get_nstring(u_char* p, int n)
{
register int c;
int c;
do {
c = get_byte();
@ -860,9 +888,10 @@ register int n;
return (n < 0) ? ERROR : 0;
}
Uchar *get_ndata(p, n)
register Uchar *p;
register int n;
u_char*
get_ndata(u_char* p, int n)
{
while (n-- > 0) *p++ = get_byte();
return p;

View file

@ -31,13 +31,19 @@
* $SonyRCSfile: error.c,v $
* $SonyRevision: 1.1 $
* $SonyDate: 1994/06/03 08:02:51 $
*
* $Id$
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "sj_typedef.h"
#include "server.h"
extern char program_name[];
extern int debug_level;
@ -49,8 +55,8 @@ static FILE *logfp = NULL;
static FILE *dbgfp = NULL;
open_error()
int
open_error(void)
{
extern char *error_file;
int flg = 0;
@ -69,9 +75,9 @@ open_error()
return flg;
}
error_out(s, p1, p2, p3, p4, p5)
char *s;
int p1, p2, p3, p4, p5;
void
error_out(char* s, int p1, int p2, int p3, int p4, int p5)
{
char tmp[BUFSIZ];
@ -83,9 +89,9 @@ int p1, p2, p3, p4, p5;
exit(1);
}
warning_out(s, p1, p2, p3, p4, p5)
char *s;
int p1, p2, p3, p4, p5;
void
warning_out(char* s, int p1, int p2, int p3, int p4, int p5)
{
char tmp[BUFSIZ];
@ -97,8 +103,8 @@ int p1, p2, p3, p4, p5;
}
open_log()
int
open_log(void)
{
extern char *log_file;
int flg = 0;
@ -111,7 +117,7 @@ open_log()
else
logfp = fopen(log_file, "a");
if (logfp) {
long t;
time_t t;
time(&t);
fprintf(logfp, "%s: log started at %s\r",
@ -127,9 +133,9 @@ open_log()
return flg;
}
logging_out(s, p1, p2, p3, p4, p5)
char *s;
int p1, p2, p3, p4, p5;
void
logging_out(char* s, int p1, int p2, int p3, int p4, int p5)
{
char tmp[BUFSIZ];
@ -141,8 +147,8 @@ int p1, p2, p3, p4, p5;
}
open_debug()
int
open_debug(void)
{
extern char *debug_file;
int flg = 0;
@ -161,10 +167,9 @@ open_debug()
return flg;
}
debug_out(lvl, s, p1, p2, p3, p4, p5)
int lvl;
char *s;
int p1, p2, p3, p4, p5;
void
debug_out(int lvl, char* s, int p1, int p2, int p3, int p4, int p5)
{
if (lvl <= debug_level && dbgfp) {
fprintf(dbgfp, s, p1, p2, p3, p4, p5);

View file

@ -31,21 +31,24 @@
* $SonyRCSfile: execute.c,v $
* $SonyRevision: 1.7 $
* $SonyDate: 1998/04/13 11:20:12 $
*
* $Id$
*/
#include "sj_kcnv.h"
#include <stdlib.h>
#include <string.h>
#include <pwd.h>
#include <setjmp.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <errno.h>
#include <unistd.h>
#include "sj3cmd.h"
#include "sj3err.h"
#include "Dict.h"
#include "server.h"
#define rmemcpy(a, b, n) memcpy((b), (a), (n))
@ -89,10 +92,9 @@ Uchar *put_ndata(), *put_string();
make_full_path(path)
char *path;
int
make_full_path (char *path)
{
extern char *strtok();
char tmp[PathNameLen];
char *index;
int i;
@ -102,11 +104,11 @@ char *path;
i = strlen(dict_dir) + 1 + strlen(path) + 1;
if (i > sizeof(tmp)) return ERROR;
strcpy(tmp, path);
strlcpy(tmp, path, sizeof(tmp));
index = strtok(tmp, "/");
do {
if (!strcmp(index, "..")) return ERROR;
} while (index = strtok(NULL, "/"));
} while ((index = strtok(NULL, "/")) != NULL);
if (*path == '/') {
if (strncmp(path, dict_dir, strlen(dict_dir)) == 0) {
@ -115,16 +117,15 @@ char *path;
return ERROR;
}
}
strcpy(tmp, dict_dir);
strcat(tmp, "/");
strcat(tmp, path);
snprintf(tmp, sizeof(tmp), "%s/%s", dict_dir, path);
strcpy(path, tmp);
return 0;
}
WorkArea *alloc_workarea()
WorkArea*
alloc_workarea (void)
{
WorkArea *p;
@ -144,8 +145,7 @@ WorkArea *alloc_workarea()
}
void
free_workarea(p)
WorkArea *p;
free_workarea (WorkArea *p)
{
if (!p) return;
if (--(p -> refcnt)) return;
@ -153,7 +153,7 @@ WorkArea *p;
if (worklist == p)
worklist = p -> link;
else {
register WorkArea *q;
WorkArea *q;
for (q = worklist ; q ; q = q -> link) {
if (q -> link == p) {
@ -171,7 +171,8 @@ WorkArea *p;
exec_connect()
void
exec_connect (void)
{
int version;
char hostname[HostNameLen];
@ -226,7 +227,8 @@ exec_connect()
exec_disconnect()
void
exec_disconnect (void)
{
if (cur_cli -> stdy) {
closestdy(cur_cli -> stdy);
@ -244,12 +246,13 @@ exec_disconnect()
exec_opendict()
void
exec_opendict (void)
{
char filename[PathNameLen];
char password[PassWordLen];
DICT *dict;
DICTL *dictl, *dltp, *tmp;
DICTL *dictl, *dltp, *tmp, *tmp1;
get_nstring(filename, sizeof(filename));
get_nstring(password, sizeof(password));
@ -267,8 +270,23 @@ exec_opendict()
while (dltp) {
dictl = (DICTL *)malloc(sizeof *dictl);
if (!dictl) {
for (tmp = dictlist; tmp; tmp->next)
free(tmp);
/* XXX 2004.09.16 Hiroo Ono
* Fixed list deletion when malloc() returns
* NULL, but it will segfault anyway just after
* getting out of this if block.
* Maybe continue, break or return lack in
* this block, but I don't know what was
* intended to be done when malloc() caused
* an error. So just fix the list deletion bug
* in this block and leave the code causing
* segfault when malloc() fails.
*/
tmp = dictlist;
while (tmp != NULL) {
tmp1 = tmp;
tmp = tmp->next;
free (tmp1);
}
dictlist = NULL;
}
if (!dictlist) dictlist = dictl;
@ -301,7 +319,11 @@ exec_opendict()
put_int(SJ3_NormalEnd);
put_int((int)dict->dicid);
}
exec_closedict()
void
exec_closedict (void)
{
TypeDicID id;
DICTL *dictl;
@ -332,8 +354,11 @@ exec_closedict()
free((char *)dictl);
put_int(SJ3_NormalEnd);
}
close_dictlist(dictl)
DICTL *dictl;
void
close_dictlist(DICTL *dictl)
{
DICTL *p;
@ -348,7 +373,8 @@ DICTL *dictl;
exec_openstdy()
void
exec_openstdy (void)
{
char filename[PathNameLen];
char password[PassWordLen];
@ -366,7 +392,11 @@ exec_openstdy()
put_int(SJ3_NormalEnd);
}
exec_closestdy()
void
exec_closestdy (void)
{
if (!cur_cli -> stdy) longjmp(error_ret, SJ3_StdyFileNotOpened);
@ -378,7 +408,8 @@ exec_closestdy()
exec_stdysize()
void
exec_stdysize (void)
{
put_int(SJ3_NormalEnd);
put_int(sizeof(STDYOUT));
@ -386,7 +417,8 @@ exec_stdysize()
static void exec_lock()
static void
exec_lock (void)
{
int lock;
DICTL *dl;
@ -407,7 +439,11 @@ static void exec_lock()
put_int(SJ3_NormalEnd);
}
static void exec_unlock()
static void
exec_unlock (void)
{
int lock;
DICTL *dl;
@ -428,7 +464,11 @@ static void exec_unlock()
put_int(SJ3_NormalEnd);
}
static void lock_check_for_read()
static void
lock_check_for_read (void)
{
int lock;
@ -445,8 +485,7 @@ static void lock_check_for_read()
void
exec_ph2knj(mb_flag)
int mb_flag;
exec_ph2knj (int mb_flag)
{
int i, j, l, stdy_size, buf_size, srchead = 0, srclen;
Uchar *p,*q;
@ -523,8 +562,7 @@ CCONVERR:
void
exec_cl2knj(mb_flag)
int mb_flag;
exec_cl2knj (int mb_flag)
{
int len, stdy_size, buf_size;
int i, j, l;
@ -589,8 +627,7 @@ CCONVERR:
void
exec_nextcl(mb_flag)
int mb_flag;
exec_nextcl (int mb_flag)
{
int mode, stdy_size, buf_size;
int i, l;
@ -643,8 +680,7 @@ CCONVERR:
void
exec_prevcl(mb_flag)
int mb_flag;
exec_prevcl (int mb_flag)
{
int mode, stdy_size, buf_size;
int i, l;
@ -698,8 +734,7 @@ CCONVERR:
void
exec_cl2knj_cnt(mb_flag)
int mb_flag;
exec_cl2knj_cnt(int mb_flag)
{
int len, buf_size, stdy_size;
int i;
@ -747,8 +782,7 @@ CCONVERR:
void
exec_cl2knj_all(mb_flag)
int mb_flag;
exec_cl2knj_all (int mb_flag)
{
int len, stdy_size, buf_size;
int i, l;
@ -847,9 +881,10 @@ CCONVERR:
exec_study()
void
exec_study (void)
{
register int err;
int err;
STDYOUT stdy;
get_ndata(&stdy, sizeof(stdy));
@ -875,10 +910,9 @@ exec_study()
void
exec_clstudy(mb_flag)
int mb_flag;
exec_clstudy (int mb_flag)
{
register int err;
int err;
STDYOUT stdy;
err = get_nstring(buf1, sizeof(buf1));
@ -921,12 +955,11 @@ CCONVERR:
void
exec_adddict(mb_flag)
int mb_flag;
exec_adddict (int mb_flag)
{
TypeDicID dicid;
TypeGram gram;
register int err;
int err;
int err1;
DICTL *dl;
@ -985,12 +1018,11 @@ CCONVERR:
}
void
exec_deldict(mb_flag)
int mb_flag;
exec_deldict (int mb_flag)
{
TypeDicID dicid;
TypeGram gram;
register int err;
int err;
int err1;
DICTL *dl;
@ -1047,8 +1079,7 @@ CCONVERR:
void
exec_getdict(mb_flag)
int mb_flag;
exec_getdict (int mb_flag)
{
TypeDicID dicid;
int err, buf_size, l;
@ -1129,9 +1160,10 @@ CCONVERR:
return;
}
void
exec_nextdict(mb_flag)
int mb_flag;
exec_nextdict (int mb_flag)
{
TypeDicID dicid;
int err, buf_size, l;
@ -1212,9 +1244,10 @@ CCONVERR:
return;
}
void
exec_prevdict(mb_flag)
int mb_flag;
exec_prevdict (int mb_flag)
{
TypeDicID dicid;
int err, buf_size, l;
@ -1297,7 +1330,8 @@ CCONVERR:
exec_makedict()
void
exec_makedict (void)
{
struct stat sbuf;
char path[PathNameLen];
@ -1326,7 +1360,8 @@ exec_makedict()
exec_makestdy()
void
exec_makestdy (void)
{
struct stat sbuf;
char path[PathNameLen];
@ -1354,7 +1389,8 @@ exec_makestdy()
exec_access()
void
exec_access (void)
{
char path[PathNameLen];
int mode;
@ -1370,7 +1406,8 @@ exec_access()
exec_makedir()
void
exec_makedir (void)
{
char path[PathNameLen];
int i;
@ -1392,10 +1429,11 @@ exec_makedir()
exec_who()
void
exec_who (void)
{
register int i;
register Client *cli;
int i;
Client *cli;
i = 0;
cli = client;
@ -1418,14 +1456,19 @@ exec_who()
exec_kill()
void
exec_kill (void)
{
put_int(SJ3_NormalEnd);
put_flush();
server_terminate();
}
exec_quit()
void
exec_quit (void)
{
if (client_num > 1) longjmp(error_ret, SJ3_UserConnected);
exec_kill();
@ -1433,7 +1476,8 @@ exec_quit()
exec_version()
void
exec_version (void)
{
extern char *version_number, *time_stamp;
static char *Version = "version : ";
@ -1449,11 +1493,12 @@ exec_version()
exec_dictpass()
void
exec_dictpass (void)
{
TypeDicID dicid;
char buf[PasswdLen + 1];
register int err;
int err;
DICTL *dl;
@ -1471,11 +1516,15 @@ exec_dictpass()
if (set_dictpass(dl -> dict, buf)) longjmp(error_ret, serv_errno);
put_int(SJ3_NormalEnd);
}
exec_dictcmnt()
void
exec_dictcmnt (void)
{
TypeDicID dicid;
char buf[CommentLength + 1];
register int err;
int err;
DICTL *dl;
@ -1493,10 +1542,14 @@ exec_dictcmnt()
if (set_dictcmnt(dl -> dict, buf)) longjmp(error_ret, serv_errno);
put_int(SJ3_NormalEnd);
}
exec_stdypass()
void
exec_stdypass (void)
{
char buf[PasswdLen + 1];
register int err;
char buf[PasswdLen + 1];
int err;
err = get_nstring(buf, sizeof(buf));
@ -1508,10 +1561,14 @@ exec_stdypass()
if (set_stdypass(buf)) longjmp(error_ret, serv_errno);
put_int(SJ3_NormalEnd);
}
exec_stdycmnt()
void
exec_stdycmnt (void)
{
char buf[CommentLength + 1];
register int err;
char buf[CommentLength + 1];
int err;
err = get_nstring(buf, sizeof(buf));
@ -1526,7 +1583,8 @@ exec_stdycmnt()
exec_stdypara()
void
exec_stdypara (void)
{
int stynum, clstep, cllen;
@ -1542,11 +1600,12 @@ exec_stdypara()
void execute_cmd()
void
execute_cmd (void)
{
int i;
if (i = setjmp(error_ret)) {
if ((i = setjmp(error_ret)) != 0) {
debug_out(1, "%d: error code = %d\r\n", client_fd, i);
put_int(i);
}

View file

@ -31,24 +31,28 @@
* $SonyRCSfile: main.c,v $
* $SonyRevision: 1.3 $
* $SonyDate: 1995/02/03 07:38:44 $
*
* $Id$
*/
#include "sj_sysvdef.h"
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <unistd.h>
#ifdef SVR4
#include <sys/fcntl.h>
#include <sys/termios.h>
#endif
#include "Const.h"
#include "server.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;";
@ -58,14 +62,13 @@ static char rcsid_sony[] = "$Header: /export/work/contrib/sj3/server/RCS/main.c,
#define signal sigset
#endif
void _exit();
extern int fork_flag;
extern char *lock_file;
static void opening()
static void
opening (void)
{
extern char *version_number;
extern char *time_stamp;
@ -78,7 +81,8 @@ static void opening()
#ifdef LOCK_FILE
int make_lockfile()
int
make_lockfile (void)
{
int fd;
@ -87,7 +91,10 @@ int make_lockfile()
close(fd);
return 0;
}
int erase_lockfile()
int
erase_lockfile (void)
{
return unlink(lock_file);
}
@ -97,14 +104,14 @@ int erase_lockfile()
#if !defined(__sony_news) || defined(SVR4)
static int signal_handler(sig)
int sig;
static int
signal_handler (int sig)
{
warning_out("signal %d catched.", sig);
}
static int terminate_handler(sig)
int sig;
static int
terminate_handler (int sig)
{
close_socket();
sj_closeall();
@ -113,8 +120,10 @@ int sig;
#endif
exit(0);
}
#else
static int signal_handler(sig, code, scp)
#else /* __sony_news && !SVR4 */
static int
signal_handler (sig, code, scp)
int sig;
int code;
struct sigcontext *scp;
@ -134,8 +143,11 @@ struct sigcontext *scp;
#endif
exit(0);
}
#endif
server_terminate()
#endif /* __sony_news && !SVR4 */
void
server_terminate (void)
{
close_socket();
sj_closeall();
@ -147,7 +159,8 @@ server_terminate()
static void exec_fork()
static void
exec_fork (void)
{
int tmp;
@ -180,8 +193,8 @@ static void exec_fork()
static void leave_tty()
static void
leave_tty (void)
{
int tmp;
@ -207,9 +220,8 @@ static void leave_tty()
int main(argc, argv)
int argc;
char **argv;
int
main (int argc, char **argv)
{
#ifdef __sony_news
(void) setlocale(LC_CTYPE, "ja_JP.EUC");

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 1991-1994 Sony Corporation
* Copyright (c) 1996 Hidekazu Kuroki <hidekazu at cs.titech.ac.jp>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -31,22 +32,22 @@
* $SonyRCSfile: setup.c,v $
* $SonyRevision: 1.3 $
* $SonyDate: 1994/12/09 11:27:07 $
*
* $Id$
*/
#include "sj_sysvdef.h"
#include <stdio.h>
#include <ctype.h>
#ifdef SVR4
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#else
#include <strings.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <unistd.h>
#include "sj_typedef.h"
#include "sj_const.h"
#include "sj_var.h"
@ -56,6 +57,8 @@
#include "Const.h"
#include "Struct.h"
#include "sj_global.h"
#include "kanakan.h"
#include "server.h"
typedef struct strlist {
u_char *str1;
@ -95,33 +98,30 @@ char *proto_name = NULL;
static int line_number;
char *malloc();
#ifdef OLD
#else
RcError(p)
char *p;
#else /* !OLD */
void
RcError(char* p)
{
fprintf(stderr, "%s: \"%s\", line %d: %s\r\n",
program_name, runcmd_file, line_number, p);
fflush(stderr);
exit(1);
}
RcWarning(p)
char *p;
void
RcWarning(char* p)
{
fprintf(stderr, "%s: warning: \"%s\", line %d: %s\r\n",
program_name, runcmd_file, line_number, p);
fflush(stderr);
}
#endif
#endif /* !OLD */
static cmpstr(src, dst)
u_char *src, *dst;
static int
cmpstr(u_char* src, u_char* dst)
{
int flg;
int c;
@ -185,9 +185,10 @@ void *pv_dst;
while (*p++) ;
return p;
}
static u_char *get_list(p, dst)
u_char *p;
StrList **dst;
static u_char*
get_list(u_char* p, StrList** dst)
{
StrList *s1, *s2;
@ -357,10 +358,9 @@ int len;
return c;
}
read_line(fp, buf, len)
FILE *fp;
char *buf;
int len;
int
read_line(FILE* fp, char* buf, int len)
{
int flg;
@ -374,13 +374,13 @@ int len;
void read_runcmd()
void
read_runcmd(void)
{
FILE *fp;
u_char buf[BUFSIZ];
struct optlist *opt;
u_char *p;
int i;
if (!(fp = fopen(runcmd_file, "r"))) {
warning_out("Can't open run-command file \"%s\"", runcmd_file);
@ -388,7 +388,7 @@ void read_runcmd()
}
line_number = 0;
while (read_line(fp, buf, sizeof(buf)) != EOF) {
for (opt = option ; p = (u_char *)opt -> optname ; opt++)
for (opt = option ; (p = (u_char *)opt -> optname) != NULL ; opt++)
if (!cmpstr(p, buf)) break;
if (p) {
p = buf; while (*p++) ;
@ -404,9 +404,8 @@ void read_runcmd()
}
static set_defstr(d, s)
char **d, *s;
static void
set_defstr(char** d, char* s)
{
if (*d == NULL && s) {
*d = malloc(strlen(s) + 1);
@ -414,12 +413,17 @@ char **d, *s;
strcpy(*d, s);
}
}
static set_defint(d, s)
int *d, s;
static void
set_defint(int* d, int s)
{
if (*d < 0) *d = s;
}
void set_default()
void
set_default(void)
{
set_defstr(&debug_file, DebugOutFile);
set_defstr(&error_file, ErrorOutFile);
@ -447,26 +451,27 @@ void set_default()
}
void parse_arg(argc, argv)
int argc;
char **argv;
void
parse_arg(int argc, char** argv)
{
int c;
int errflg = 0;
char *p;
size_t ret;
extern char *optarg, *strrchr();
extern int optind;
p = (p = strrchr(argv[0], '/')) ? p + 1 : argv[0];
strcpy(program_name, p);
strcpy(runcmd_file, RunCmdFile);
strlcpy(program_name, p, sizeof(program_name));
strlcpy(runcmd_file, RunCmdFile, sizeof(runcmd_file));
while ((c = getopt(argc, argv, "f:")) != EOF) {
switch (c) {
case 'f':
strcpy(runcmd_file, optarg);
ret = strlcpy(runcmd_file, optarg, sizeof(runcmd_file));
if (ret > sizeof(runcmd_file))
errflg++;
break;
case '?':
@ -484,7 +489,7 @@ char **argv;
void
preload_dict()
preload_dict(void)
{
StrList *p;
char filename[PathNameLen];
@ -511,7 +516,8 @@ preload_dict()
free(work_base);
}
preopen_dict()
void
preopen_dict(void)
{
StrList *p;
char filename[PathNameLen];
@ -531,9 +537,9 @@ preopen_dict()
if (make_full_path(filename))
warning_out("too long filename \"%s\"", p -> str1);
else if (dict = (DICT *)opendict(filename, p -> str2)) {
else if ((dict = (DICT *)opendict(filename, p -> str2)) != NULL) {
logging_out("open dictionary \"%s\"", filename);
if (!(dictl = (DICTL *)malloc(sizeof *dictl))) {
if ((dictl = (DICTL *)malloc(sizeof *dictl)) == NULL) {
closedict((DictFile *)dict);
warning_out("can't open dictionary \"%s\"", filename);
continue;
@ -548,10 +554,8 @@ preopen_dict()
}
static str_match(s, d)
char *s;
char *d;
static int
str_match(char* s, char* d)
{
while (*d) {
if (*s == '*') {
@ -571,10 +575,8 @@ char *d;
}
check_user(user, host)
char *user;
char *host;
int
check_user(char* user, char* host)
{
StrList *p;