diff --git a/sj3serv/comuni.c b/sj3serv/comuni.c index 0eaac95..a0b1836 100644 --- a/sj3serv/comuni.c +++ b/sj3serv/comuni.c @@ -28,34 +28,24 @@ * from Sony Corporation. */ - - -#include -#include -#include -#include #include "sj_sysvdef.h" -#include "sj_kcnv.h" -#include -#include + #include +#include +#include +#include + #include + +#include #include #include -#include -#ifdef SVR4 -#include -#include -#include -#endif -#ifdef TLI -#include -#include -#include -#include -#include -#include -#endif +#include +#include +#include +#include + +#include "sj_kcnv.h" #ifdef SVR4 #define signal sigset @@ -72,45 +62,44 @@ # define SOMAXCONN 5 #endif -int client_num = 0; +int client_num = 0; Client *client = NULL; -Client *cur_client; +Client *cur_client; -int maxfds = 0; +int maxfds = 0; #ifdef SVR4 struct pollfd poll_fds[_NFILE]; #else -fd_set fds_org = { 0 }; +fd_set fds_org = { 0 }; #endif jmp_buf client_dead; int client_fd; -extern char *socket_name; -extern char *port_name; +extern char *socket_name; +extern char *port_name; #ifdef TLI -extern char *port_number; -extern char *proto_name; +extern char *port_number; +extern char *proto_name; #else -extern int port_number; +extern int port_number; #endif -extern int max_client; +extern int max_client; -static int fd_inet = -1; -static int fd_unix = -1; - -static char putbuf[BUFSIZ]; -static char getbuf[BUFSIZ]; -static int putpos = 0; -static int buflen = 0; -static int getpos = 0; +static int fd_inet = -1; +static int fd_unix = -1; +static char putbuf[BUFSIZ]; +static char getbuf[BUFSIZ]; +static int putpos = 0; +static int buflen = 0; +static int getpos = 0; void socket_init(void) { #ifdef SVR4 int i; - + for (i = 0; i < _NFILE; i++) { poll_fds[i].fd = -1; poll_fds[i].events = 0; @@ -123,23 +112,20 @@ socket_init(void) maxfds = 0; } - - static void set_fd(int fd) { #ifdef SVR4 - poll_fds[maxfds].fd = fd; - poll_fds[maxfds].events = POLLIN; + poll_fds[maxfds].fd = fd; + poll_fds[maxfds].events = POLLIN; maxfds++; #else FD_SET(fd, &fds_org); - if (fd >= maxfds) maxfds = fd + 1; + if (fd >= maxfds) + maxfds = fd + 1; #endif } - - static void clr_fd(int fd) { @@ -150,9 +136,9 @@ clr_fd(int fd) if (poll_fds[i].fd == fd) { maxfds--; for (j = i; j < maxfds; j++) { - poll_fds[j].fd = poll_fds[j+1].fd; - poll_fds[j].events = poll_fds[j+1].events; - poll_fds[j].revents = poll_fds[j+1].revents; + poll_fds[j].fd = poll_fds[j + 1].fd; + poll_fds[j].events = poll_fds[j + 1].events; + poll_fds[j].revents = poll_fds[j + 1].revents; } poll_fds[j].fd = -1; poll_fds[j].events = 0; @@ -164,7 +150,8 @@ clr_fd(int fd) FD_CLR(fd, &fds_org); if (maxfds == fd + 1) { while (--fd >= 0) { - if (FD_ISSET(fd, &fds_org)) break; + if (FD_ISSET(fd, &fds_org)) + break; } maxfds = fd + 1; } @@ -173,7 +160,6 @@ clr_fd(int fd) #if (!defined(TLI) || (defined(TLI) && defined(SOCK_UNIX))) - static void open_af_unix(void) { @@ -191,12 +177,14 @@ open_af_unix(void) exit(1); } - if (bind(fd_unix, (struct sockaddr *)&sunix, strlen(sunix.sun_path) + 2) == ERROR) { - if (errno == EADDRINUSE) + 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", - socket_name); - else + socket_name); + } else { fprintf(stderr, "Can't bind AF_UNIX socket\n"); + } shutdown(fd_unix, 2); close(fd_unix); unlink(socket_name); @@ -219,128 +207,131 @@ struct t_call *inet_callptr; struct netconfig *nconf; #endif - static void open_af_inet(void) { #ifdef TLI - struct t_bind *req; - struct nd_hostserv hserv; - struct nd_addrlist *addrs; + struct t_bind *req; + struct nd_hostserv hserv; + struct nd_addrlist *addrs; struct t_optmgmt *opt; struct opthdr *hdr; - void *handlep; - extern int t_errno; - extern void *setnetpath(); - extern struct netconfig *getnetpath(); + void *handlep; + extern int t_errno; + extern void *setnetpath(); + extern struct netconfig *getnetpath(); #else - struct sockaddr_in sin; - struct servent *sp; - u_short port; + struct sockaddr_in sin; + struct servent *sp; + u_short port; #endif int true = 1; - #ifdef TLI - if (( handlep = setnetpath()) == NULL) { - fprintf(stderr, "Setnetpath fail\n"); - exit(1); - } + if ((handlep = setnetpath()) == NULL) { + fprintf(stderr, "Setnetpath fail\n"); + exit(1); + } - while((nconf = getnetpath(handlep)) != NULL) { - if ((nconf->nc_semantics == NC_TPI_COTS_ORD) && - (strncmp(nconf->nc_proto, proto_name, strlen(proto_name)) == 0)) - break; + while ((nconf = getnetpath(handlep)) != NULL) { + if ((nconf->nc_semantics == NC_TPI_COTS_ORD) && + (strncmp(nconf->nc_proto, proto_name, strlen(proto_name)) == + 0)) + break; } if (nconf == NULL) { - fprintf(stderr, "No connection mode transport\n"); - exit(1); + fprintf(stderr, "No connection mode transport\n"); + exit(1); } - hserv.h_host = HOST_SELF; - hserv.h_serv = port_number; + hserv.h_host = HOST_SELF; + hserv.h_serv = port_number; if (netdir_getbyname(nconf, &hserv, &addrs) != 0) { - hserv.h_serv = port_name; + hserv.h_serv = port_name; if (netdir_getbyname(nconf, &hserv, &addrs) != 0) { - fprintf(stderr, "Can't get address\n"); - exit(1); + fprintf(stderr, "Can't get address\n"); + exit(1); } } - if ((fd_inet = t_open(nconf->nc_device, O_RDWR, (struct t_info *) NULL)) < 0) { - fprintf(stderr,"Can't t_open\n"); - exit(1); + if ((fd_inet = t_open(nconf->nc_device, O_RDWR, + (struct t_info *)NULL)) < 0) { + fprintf(stderr, "Can't t_open\n"); + exit(1); } - if ((opt = (struct t_optmgmt *) t_alloc(fd_inet, T_OPTMGMT, T_ALL)) == NULL) { + if ((opt = (struct t_optmgmt *)t_alloc(fd_inet, T_OPTMGMT, T_ALL)) == + NULL) { fprintf(stderr, "Can't t_alloc error for T_OPTMGT\n"); exit(1); } - if ((hdr = (struct opthdr *) malloc(sizeof(*hdr) + sizeof(true))) == NULL) { + if ((hdr = (struct opthdr *)malloc(sizeof(*hdr) + sizeof(true))) == + NULL) { fprintf(stderr, "server: not malloc\n"); exit(1); } - hdr->level = SOL_SOCKET; - hdr->name = SO_REUSEADDR; - hdr->len = sizeof(true); - - (void) memcpy(&true, (char *)hdr + sizeof(*hdr), sizeof(true)); + hdr->level = SOL_SOCKET; + hdr->name = SO_REUSEADDR; + hdr->len = sizeof(true); - opt->opt.len = opt->opt.maxlen = sizeof(*hdr) + sizeof(true); - opt->flags = T_CHECK; - opt->opt.buf = (char *)hdr; + (void)memcpy(&true, (char *)hdr + sizeof(*hdr), sizeof(true)); - if ((t_optmgmt(fd_inet, opt, opt) < 0) || !(opt->flags & T_SUCCESS)){ + opt->opt.len = opt->opt.maxlen = sizeof(*hdr) + sizeof(true); + opt->flags = T_CHECK; + opt->opt.buf = (char *)hdr; + + if ((t_optmgmt(fd_inet, opt, opt) < 0) || !(opt->flags & T_SUCCESS)) { fprintf(stderr, "Warning: Can't reuse address %s(%s)\n", - port_name, port_number); + port_name, port_number); } else { - opt->flags = T_NEGOTIATE; - - (void) memcpy(&true, (char *)hdr + sizeof(*hdr), sizeof(true)); - (void) t_optmgmt(fd_inet, opt, opt); + opt->flags = T_NEGOTIATE; + + (void)memcpy(&true, (char *)hdr + sizeof(*hdr), sizeof(true)); + (void)t_optmgmt(fd_inet, opt, opt); } - if ((req = (struct t_bind *) t_alloc(fd_inet, T_BIND, T_ALL)) == NULL) { - t_close(fd_inet); - fprintf(stderr, "Can't alloc bind data\n"); - exit(1); + if ((req = (struct t_bind *)t_alloc(fd_inet, T_BIND, T_ALL)) == NULL) { + t_close(fd_inet); + fprintf(stderr, "Can't alloc bind data\n"); + exit(1); } - req->addr.maxlen = addrs->n_addrs->maxlen; - req->addr.len = addrs->n_addrs->len; - - (void) memcpy(addrs->n_addrs->buf, req->addr.buf, addrs->n_addrs->len); - req->qlen = 5; - - if (t_bind(fd_inet, req, req) < 0 ) { + req->addr.maxlen = addrs->n_addrs->maxlen; + req->addr.len = addrs->n_addrs->len; + + (void)memcpy(addrs->n_addrs->buf, req->addr.buf, addrs->n_addrs->len); + req->qlen = 5; + + if (t_bind(fd_inet, req, req) < 0) { fprintf(stderr, "Can't t_bind\n"); t_close(fd_inet); exit(1); } - if (memcmp(req->addr.buf, addrs->n_addrs->buf, addrs->n_addrs->len) != 0) { - fprintf(stderr, "Port '%s(%s)' is already in use\n", - port_name, port_number); - t_close(fd_inet); - exit(1); + if (memcmp(req->addr.buf, addrs->n_addrs->buf, addrs->n_addrs->len) != + 0) { + fprintf(stderr, "Port '%s(%s)' is already in use\n", + port_name, port_number); + t_close(fd_inet); + exit(1); } - if ((inet_callptr = (struct t_call *) t_alloc(fd_inet, T_CALL, T_ALL)) == NULL) { - fprintf(stderr,"t_alloc error for T_CALL\n"); - t_close(fd_inet); - exit(1); + if ((inet_callptr = (struct t_call *)t_alloc(fd_inet, T_CALL, T_ALL)) == + NULL) { + fprintf(stderr, "t_alloc error for T_CALL\n"); + t_close(fd_inet); + exit(1); } inet_callptr->addr = *(addrs->n_addrs); - inet_callptr->udata.maxlen = 0; inet_callptr->udata.len = 0; - inet_callptr->udata.buf = (char *) NULL; + inet_callptr->udata.buf = (char *)NULL; #else if ((sp = getservbyname(port_name, "tcp")) != NULL) - port = ntohs(sp -> s_port); + port = ntohs(sp->s_port); else port = port_number; memset((char *)&sin, '\0', sizeof(sin)); - sin.sin_family = AF_INET; - sin.sin_port = htons(port); + sin.sin_family = AF_INET; + sin.sin_port = htons(port); sin.sin_addr.s_addr = htonl(INADDR_ANY); if ((fd_inet = socket(AF_INET, SOCK_STREAM, 0)) == ERROR) { @@ -352,17 +343,18 @@ open_af_inet(void) if (bind(fd_inet, (struct sockaddr *)&sin, sizeof(sin)) == ERROR) { if (errno == EADDRINUSE) { - if (sp) + if (sp) { fprintf(stderr, - "Port '%s(%d)' is already in use\n", - port_name, port); - else + "Port '%s(%d)' is already in use\n", + port_name, port); + } else { fprintf(stderr, - "Port %d is already in use\n", - port); - } - else + "Port %d is already in use\n", + port); + } + } else { fprintf(stderr, "Can't bind AF_INET socket\n"); + } shutdown(fd_inet, 2); close(fd_inet); exit(1); @@ -389,13 +381,12 @@ open_socket(void) #if (!defined(TLI) || (defined(TLI) && defined(SOCK_UNIX))) - static int connect_af_unix(void) { struct sockaddr_un sunix; - int i = sizeof(sunix); - int fd; + int i = sizeof(sunix); + int fd; if ((fd = accept(fd_unix, (struct sockaddr *)&sunix, &i)) == ERROR) warning_out("Can't accept AF_UNIX socket"); @@ -405,56 +396,57 @@ connect_af_unix(void) #ifdef TLI int -accept_func(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; - extern int t_errno; - + int look, newfd; + extern int t_errno; + if ((newfd = t_open(name, O_RDWR, (struct t_info *)0)) < 0) { - if (!closeflg) warning_out("Can't t_open"); - return ERROR; + if (!closeflg) + warning_out("Can't t_open"); + return ERROR; } if (t_bind(newfd, (struct t_bind *)0, (struct t_bind *)0) < 0) { - if (!closeflg) warning_out("t_bind error"); - return ERROR; + if (!closeflg) + warning_out("t_bind error"); + return ERROR; } - t_errno = 0; - if (t_accept(fd, newfd, callptr) <0 ){ - t_close(newfd); - if (!closeflg) warning_out("t_accept error"); - return ERROR; + t_errno = 0; + if (t_accept(fd, newfd, callptr) < 0) { + t_close(newfd); + if (!closeflg) + warning_out("t_accept error"); + return ERROR; } - if (ioctl(newfd, I_POP, (char *) 0) < 0) { - if (!closeflg) warning_out("I_POP timod failed"); - return ERROR; + if (ioctl(newfd, I_POP, (char *)0) < 0) { + if (!closeflg) + warning_out("I_POP timod failed"); + return ERROR; } if (ioctl(newfd, I_PUSH, "tirdwr") < 0) { - if (!closeflg) warning_out("I_PUSH tirdwr failed"); - return ERROR; + if (!closeflg) + warning_out("I_PUSH tirdwr failed"); + return ERROR; } - return(newfd); + return (newfd); } #endif - - static int connect_af_inet(void) { #ifndef TLI struct sockaddr_in sin; - int i = sizeof(sin); + int i = sizeof(sin); #endif int fd; #ifdef TLI - if (t_listen(fd_inet, inet_callptr) < 0) { - warning_out("t_listen error"); + if (t_listen(fd_inet, inet_callptr) < 0) + warning_out("t_listen error"); - } - - if ((fd = accept_func(fd_inet, inet_callptr, nconf->nc_device, FALSE)) == ERROR) + if ((fd = accept_func(fd_inet, inet_callptr, nconf->nc_device, + FALSE)) == ERROR) #else if ((fd = accept(fd_inet, (struct sockaddr *)&sin, &i)) == ERROR) #endif @@ -464,18 +456,18 @@ connect_af_inet(void) #if (!defined(TLI) || (defined(TLI) && defined(SOCK_UNIX))) - static void close_af_unix(void) { struct sockaddr_un sunix; - int true = 1; - int i; + int true = 1; + int i; ioctl(fd_unix, FIONBIO, &true); - for ( ; ; ) { + for (; ;) { i = sizeof(sunix); - if (accept(fd_unix, (struct sockaddr *)&sunix, &i) < 0) break; + if (accept(fd_unix, (struct sockaddr *)&sunix, &i) < 0) + break; } shutdown(fd_unix, 2); close(fd_unix); @@ -484,8 +476,6 @@ close_af_unix(void) } #endif - - static void close_af_inet(void) { @@ -496,19 +486,21 @@ close_af_inet(void) int i; ioctl(fd_inet, FIONBIO, &true); - for ( ; ; ) { + for (; ;) { #ifdef TLI - if (accept_func(fd_inet, inet_callptr, nconf->nc_device, TRUE) < 0) + if (accept_func(fd_inet, inet_callptr, nconf->nc_device, TRUE) < + 0) break; #else i = sizeof(sin); - if (accept(fd_inet, (struct sockaddr *)&sin, &i) < 0) break; + if (accept(fd_inet, (struct sockaddr *)&sin, &i) < 0) + break; #endif } #ifdef TLI t_sndrel(fd_inet); - t_close(fd_inet); - clr_fd(fd_inet); + t_close(fd_inet); + clr_fd(fd_inet); #else shutdown(fd_inet, 2); close(fd_inet); @@ -525,8 +517,6 @@ close_socket(void) close_af_inet(); } - - static void #ifdef SVR4 connect_client(struct pollfd *readfds) @@ -536,7 +526,7 @@ connect_client(fd_set *readfds) { int fd; #if (defined(TLI) && defined(SOCK_UNIX)) - int unix_flag=0; + int unix_flag = 0; #endif Client *client_tmp; @@ -544,7 +534,7 @@ connect_client(fd_set *readfds) int i; for (i = 0; i < maxfds; i++) { - if ((readfds[i].fd == fd_inet) && + if ((readfds[i].fd == fd_inet) && (readfds[i].revents == POLLIN)) { fd = connect_af_inet(); readfds[i].revents = 0; @@ -562,14 +552,15 @@ connect_client(fd_set *readfds) } #endif } - if (i == maxfds) return; + if (i == maxfds) + return; #else /* SVR4 */ if (FD_ISSET(fd_inet, readfds)) fd = connect_af_inet(); #if (!defined(TLI) || (defined(TLI) && defined(SOCK_UNIX))) else if (FD_ISSET(fd_unix, readfds)) #if (defined(TLI) && defined(SOCK_UNIX)) - { + { fd = connect_af_unix(); unix_flag = 1; } @@ -580,20 +571,15 @@ connect_client(fd_set *readfds) else return; #endif /* SVR4 */ - if (fd == ERROR) return; + if (fd == ERROR) + return; - - - if (client_num >= MaxClientNum || client_num >= max_client) { warning_out("No more client"); - } - - else { + } else { debug_out(1, "client create(%d)\r\n", fd); logging_out("connect to client on %d", fd); - if ((client_tmp = (Client *)malloc(sizeof(Client))) != NULL) { memset(client_tmp, 0, sizeof(Client)); client_tmp->fd = fd; @@ -603,9 +589,9 @@ connect_client(fd_set *readfds) client_tmp->next = client; client = client_tmp; client_num++; - + set_fd(fd); - + return; } warning_out("No more client(Can't alloc)"); @@ -630,38 +616,38 @@ connect_client(fd_set *readfds) } - - -static Client* +static Client * disconnect_client(Client *cp) { - WorkArea *wp; - StdyFile *sp; - int fd; - Client *cl_tmp, *cl_before; + WorkArea *wp; + StdyFile *sp; + int fd; + Client *cl_before, *cl_tmp; + + if ((sp = cp->stdy) != NULL) + closestdy(sp); + if ((wp = cp->work) != NULL) + 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); #ifdef TLI #ifdef SOCK_UNIX - if (cp->unix_flag) { + if (cp->unix_flag) { shutdown(fd = cp->fd, 2); close(fd); clr_fd(fd); - } else { + } else { fd = cp->fd; t_sndrel(fd); t_close(fd); clr_fd(fd); } #else - fd = cp->fd; + fd = cp->fd; t_sndrel(fd); - t_close(fd); - clr_fd(fd); + t_close(fd); + clr_fd(fd); #endif #else shutdown(fd = cp->fd, 2); @@ -686,56 +672,52 @@ disconnect_client(Client *cp) } cp = cl_before->next; } - client_num--; + client_num--; return cp; } -#ifndef SIGPIPE -#include -#endif - void communicate(void) { - + signal(SIGPIPE, SIG_IGN); - - for ( ; ; ) { + + for (; ;) { #ifdef SVR4 int i; - while(poll(poll_fds, maxfds, -1) == ERROR) { - if (errno != EINTR) error_out("poll"); + while (poll(poll_fds, maxfds, -1) == ERROR) { + if (errno != EINTR) + error_out("poll"); errno = 0; } #else fd_set readfds; - readfds = fds_org; - while (select(maxfds,&readfds,NULL,NULL,NULL) == ERROR) { - if (errno != EINTR) error_out("select"); + while (select(maxfds, &readfds, NULL, NULL, NULL) == ERROR) { + if (errno != EINTR) + error_out("select"); errno = 0; } #endif - for (cur_client = client ; cur_client; ) { - + for (cur_client = client; cur_client;) { if (setjmp(client_dead)) { cur_client = disconnect_client(cur_client); continue; } #ifdef SVR4 - for ( i = 0; i < maxfds; i++) { + for (i = 0; i < maxfds; i++) { if ((poll_fds[i].fd == cur_client->fd) && (poll_fds[i].revents == POLLIN)) { - poll_fds[i].revents = 0; - client_fd = cur_client->fd; - putpos = buflen = getpos = 0; - execute_cmd(); - break; - } + poll_fds[i].revents = 0; + client_fd = cur_client->fd; + putpos = buflen = getpos = 0; + execute_cmd(); + break; + } } cur_client = cur_client->next; } @@ -753,33 +735,29 @@ communicate(void) } } - void put_flush(void) { - int len; - int i; + int i, len; char *p; - for (len = putpos, p = putbuf ; len > 0 ; ) { - if ((i = write(client_fd, p, len)) == ERROR) { + 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(); + if (putpos >= sizeof(putbuf)) + put_flush(); } - void put_work(int c) { @@ -787,7 +765,6 @@ put_work(int c) put_byte(c & 0xff); } - void put_int(int c) { @@ -797,39 +774,40 @@ put_int(int c) put_byte(c); } - -u_char* -put_string(u_char* p) +u_char * +put_string(u_char *p) { if (p) { do { put_byte(*p); } while (*p++); - } - else + } else { put_byte(0); + } return p; } - -u_char* -put_ndata(u_char* p, int n) +u_char * +put_ndata(u_char *p, int n) { - while (n-- > 0) put_byte(p ? *p++ : 0); + while (n-- > 0) + put_byte(p ? *p++ : 0); return p; } - void get_buf(void) { int i; for (;;) { - if ((i = read(client_fd, getbuf, sizeof(getbuf))) > 0) break; + if ((i = read(client_fd, getbuf, sizeof(getbuf))) > 0) + break; if (i == ERROR) { - if (errno == EINTR) continue; - if (errno == EWOULDBLOCK) continue; + if (errno == EINTR) + continue; + if (errno == EWOULDBLOCK) + continue; } longjmp(client_dead, -1); } @@ -837,56 +815,52 @@ get_buf(void) getpos = 0; } - int get_byte(void) { - if (getpos >= buflen) get_buf(); - return (getbuf[getpos++] & 0xff); + if (getpos >= buflen) + get_buf(); + return getbuf[getpos++] & 0xff; } - int get_word(void) { int i; i = get_byte(); - return ((i << 8) | get_byte()); + return (i << 8) | get_byte(); } - int get_int(void) { - int i0; - int i1; - int i2; + int i0, i1, i2; i0 = get_byte(); i1 = get_byte(); i2 = get_byte(); - return((i0 << (8*3)) | (i1 << (8*2)) | (i2 << (8*1)) | get_byte()); + return (i0 << (8*3)) | (i1 << (8*2)) | (i2 << (8*1)) | get_byte(); } - int -get_nstring(u_char* p, int n) +get_nstring(u_char *p, int n) { int c; do { c = get_byte(); - if (n-- > 0) *p++ = c; + if (n-- > 0) + *p++ = c; } while (c); return (n < 0) ? ERROR : 0; } - -u_char* -get_ndata(u_char* p, int n) +u_char * +get_ndata(u_char *p, int n) { - while (n-- > 0) *p++ = get_byte(); + while (n-- > 0) + *p++ = get_byte(); return p; } diff --git a/sj3serv/error.c b/sj3serv/error.c index 8d7c8cb..be0dc57 100644 --- a/sj3serv/error.c +++ b/sj3serv/error.c @@ -2,7 +2,7 @@ * SPDX-License-Identifier: MIT-open-group * * 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 @@ -10,10 +10,10 @@ * 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. @@ -21,57 +21,52 @@ * 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. */ - - - - #include #include #include #include -#include "sj_typedef.h" + #include "server.h" +#include "sj_typedef.h" -extern char program_name[]; -extern int debug_level; -extern int client_fd; - -static char *tty_name = "/dev/tty"; -static FILE *errfp = NULL; -static FILE *logfp = NULL; -static FILE *dbgfp = NULL; +extern char program_name[]; +extern int debug_level; +extern int client_fd; +static char *tty_name = "/dev/tty"; +static FILE *errfp = NULL; +static FILE *logfp = NULL; +static FILE *dbgfp = NULL; int open_error(void) { - extern char *error_file; - int flg = 0; + extern char *error_file; + 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"))) + } else if (!(errfp = fopen(error_file, "a"))) { fprintf(stderr, "Can't open \"%s\"\r\n", error_file); - } - else + } + } else { errfp = NULL; + } return flg; } - void -error_out(char* s, int p1, int p2, int p3, int p4, int p5) +error_out(char *s, int p1, int p2, int p3, int p4, int p5) { char tmp[BUFSIZ]; @@ -83,9 +78,8 @@ error_out(char* s, int p1, int p2, int p3, int p4, int p5) exit(1); } - void -warning_out(char* s, int p1, int p2, int p3, int p4, int p5) +warning_out(char *s, int p1, int p2, int p3, int p4, int p5) { char tmp[BUFSIZ]; @@ -96,40 +90,38 @@ warning_out(char* s, int p1, int p2, int p3, int p4, int p5) } } - int open_log(void) { - extern char *log_file; - int flg = 0; + extern char *log_file; + int flg = 0; if (log_file && *log_file) { if (!strcmp(log_file, tty_name)) { logfp = stderr; flg = -1; - } - else + } else { logfp = fopen(log_file, "a"); + } if (logfp) { time_t t; time(&t); fprintf(logfp, "%s: log started at %s\r", - program_name, ctime(&t)); + program_name, ctime(&t)); fflush(logfp); - } - else + } else { fprintf(stderr, "Can't open \"%s\"\r\n", log_file); - } - else + } + } else { logfp = NULL; + } return flg; } - void -logging_out(char* s, int p1, int p2, int p3, int p4, int p5) +logging_out(char *s, int p1, int p2, int p3, int p4, int p5) { char tmp[BUFSIZ]; @@ -140,30 +132,28 @@ logging_out(char* s, int p1, int p2, int p3, int p4, int p5) } } - int open_debug(void) { - extern char *debug_file; - int flg = 0; + extern char *debug_file; + 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"))) + } else if (!(dbgfp = fopen(debug_file, "a"))) { fprintf(stderr, "Can't open \"%s\"\r\n", debug_file); - } - else + } + } else { dbgfp = NULL; + } return flg; } - void -debug_out(int lvl, char* s, int p1, int p2, int p3, int p4, int p5) +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); diff --git a/sj3serv/execute.c b/sj3serv/execute.c index 1a4961e..f2e0bd4 100644 --- a/sj3serv/execute.c +++ b/sj3serv/execute.c @@ -1,8 +1,8 @@ /*- * SPDX-License-Identifier: MIT-open-group - * + * * 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 @@ -10,10 +10,10 @@ * 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. @@ -21,166 +21,165 @@ * 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. */ - - -#include "sj_kcnv.h" -#include -#include -#include -#include #include #include + #include +#include +#include +#include +#include #include -#include "sj3cmd.h" -#include "sj3err.h" + #include "Dict.h" #include "server.h" - +#include "sj3cmd.h" +#include "sj3err.h" +#include "sj_kcnv.h" #define rmemcpy(a, b, n) memcpy((b), (a), (n)) #define SJIS_PROTO 1 #define EUC_PROTO 2 -extern Global *work_base; -extern STDY *stdy_base; -extern int serv_errno; +extern Global *work_base; +extern STDY *stdy_base; +extern int serv_errno; -extern int client_num; -extern Client *client; -extern Client *cur_client; -extern int client_fd; +extern int client_num; +extern Client *client; +extern Client *cur_client; +extern int client_fd; -extern char *dict_dir; -extern int dir_mode; -extern int file_mode; +extern char *dict_dir; +extern int dir_mode; +extern int file_mode; -static Uchar buf1[YomiBufSize]; -static Uchar buf2[YomiBufSize]; -static Uchar buf3[YomiBufSize]; -static Uchar buf4[YomiBufSize]; -static Uchar kbuf[KanjiBufSize]; -static Uchar skbuf[KanjiBufSize]; +static Uchar buf1[YomiBufSize]; +static Uchar buf2[YomiBufSize]; +static Uchar buf3[YomiBufSize]; +static Uchar buf4[YomiBufSize]; +static Uchar kbuf[KanjiBufSize]; +static Uchar skbuf[KanjiBufSize]; -static jmp_buf error_ret; -static WorkArea *worklist = NULL; -static Client *cur_cli; +static jmp_buf error_ret; +static WorkArea *worklist = NULL; +static Client *cur_cli; -static Uchar defaultchar[2] = {(Uchar)0x81, (Uchar)0x40}; -static int defuse=0, defuse2=0; +static Uchar defaultchar[2] = {(Uchar)0x81, (Uchar)0x40}; +static int defuse = 0, defuse2 = 0; -DictFile *opendict(); -int closedict(); -StdyFile *openstdy(); -int closestdy(); +DictFile *opendict(); +int closedict(); +StdyFile *openstdy(); +int closestdy(); Uchar *put_ndata(), *put_string(); - - int -make_full_path (char *path) +make_full_path(char *path) { - char tmp[PathNameLen]; - char *index; - int i; + char tmp[PathNameLen]; + char *index; + int i; - if (!path || !*path) return ERROR; + if (!path || !*path) + return ERROR; i = strlen(dict_dir) + 1 + strlen(path) + 1; - if (i > sizeof(tmp)) return ERROR; + if (i > sizeof(tmp)) + return ERROR; strlcpy(tmp, path, sizeof(tmp)); index = strtok(tmp, "/"); do { - if (!strcmp(index, "..")) return ERROR; + if (!strcmp(index, "..")) + return ERROR; } while ((index = strtok(NULL, "/")) != NULL); if (*path == '/') { - if (strncmp(path, dict_dir, strlen(dict_dir)) == 0) { + if (strncmp(path, dict_dir, strlen(dict_dir)) == 0) return 0; - } else { + else return ERROR; - } } snprintf(tmp, sizeof(tmp), "%s/%s", dict_dir, path); strcpy(path, tmp); return 0; } - - -WorkArea* -alloc_workarea (void) +WorkArea * +alloc_workarea(void) { WorkArea *p; - if (!(p = (WorkArea *)malloc(sizeof(WorkArea)))) return NULL; + if (!(p = (WorkArea *)malloc(sizeof(WorkArea)))) + return NULL; memset(p, '\0', sizeof(WorkArea)); - p -> lock = NotLocked; - p -> refcnt = 1; + p->lock = NotLocked; + p->refcnt = 1; - p -> link = worklist; + p->link = worklist; worklist = p; - work_base = &(p -> global); + work_base = &(p->global); initwork(); return p; } void -free_workarea (WorkArea *p) +free_workarea(WorkArea *p) { - if (!p) return; - if (--(p -> refcnt)) return; + if (!p) + return; + if (--(p->refcnt)) + return; - if (worklist == p) - worklist = p -> link; - else { + if (worklist == p) { + worklist = p->link; + } else { WorkArea *q; - for (q = worklist ; q ; q = q -> link) { - if (q -> link == p) { - q -> link = p -> link; + for (q = worklist; q; q = q->link) { + if (q->link == p) { + q->link = p->link; break; } } } - if (p -> global.Jdictlist) - close_dictlist(p -> global.Jdictlist); + if (p->global.Jdictlist) + close_dictlist(p->global.Jdictlist); free((char *)p); } - - void -exec_connect (void) +exec_connect(void) { - int version; - char hostname[HostNameLen]; - char username[UserNameLen]; - char progname[ProgNameLen]; - WorkArea *wp; - struct passwd *pw; + int version; + char hostname[HostNameLen]; + char username[UserNameLen]; + char progname[ProgNameLen]; + WorkArea *wp; + struct passwd *pw; version = get_int(); get_nstring(hostname, sizeof(hostname)); get_nstring(username, sizeof(username)); get_nstring(progname, sizeof(progname)); - if (cur_cli -> work) longjmp(error_ret, SJ3_AlreadyConnected); + if (cur_cli->work) + longjmp(error_ret, SJ3_AlreadyConnected); if (version < 0) longjmp(error_ret, SJ3_DifferentVersion); @@ -198,68 +197,65 @@ exec_connect (void) longjmp(error_ret, SJ3_NotEnoughMemory); pw = getpwnam(username); - if (pw) { - cur_cli -> uid = pw->pw_uid; - } else { - cur_cli -> uid = 0; - } - cur_cli -> version = version; - strcpy(cur_cli -> host, hostname); - strcpy(cur_cli -> user, username); - strcpy(cur_cli -> prog, progname); - strncpy(cur_cli -> def_char, defaultchar, 2); - cur_cli -> work = wp; + if (pw) + cur_cli->uid = pw->pw_uid; + else + cur_cli->uid = 0; + cur_cli->version = version; + strcpy(cur_cli->host, hostname); + strcpy(cur_cli->user, username); + strcpy(cur_cli->prog, progname); + strncpy(cur_cli->def_char, defaultchar, 2); + cur_cli->work = wp; - if (version == 1) - put_int(SJ3_NormalEnd); - else - put_int((-SJ3SERV_VERSION_NO)); + if (version == 1) + put_int(SJ3_NormalEnd); + else + put_int((-SJ3SERV_VERSION_NO)); logging_out("connection established on %d(%s, %s, %s)", - cur_cli -> fd, hostname, username, progname); + cur_cli->fd, hostname, username, progname); } - - void -exec_disconnect (void) +exec_disconnect(void) { - if (cur_cli -> stdy) { - closestdy(cur_cli -> stdy); - cur_cli -> stdy = NULL; + if (cur_cli->stdy) { + closestdy(cur_cli->stdy); + cur_cli->stdy = NULL; } - if (cur_cli -> work) { - free_workarea(cur_cli -> work); - cur_cli -> work = NULL; - } - else + if (cur_cli->work) { + free_workarea(cur_cli->work); + cur_cli->work = NULL; + } else { longjmp(error_ret, SJ3_NotConnected); + } put_int(SJ3_NormalEnd); } - - void -exec_opendict (void) +exec_opendict(void) { - char filename[PathNameLen]; - char password[PassWordLen]; + char filename[PathNameLen]; + char password[PassWordLen]; DICT *dict; - DICTL *dictl, *dltp, *tmp, *tmp1; + DICTL *dictl, *dltp, *tmp, *tmp1; get_nstring(filename, sizeof(filename)); get_nstring(password, sizeof(password)); - if (!work_base) longjmp(error_ret, SJ3_NotConnected); - if (make_full_path(filename)) longjmp(error_ret, SJ3_TooLongParameter); + if (!work_base) + longjmp(error_ret, SJ3_NotConnected); + if (make_full_path(filename)) + longjmp(error_ret, SJ3_TooLongParameter); if (!(dict = (DICT *)opendict(filename, password))) longjmp(error_ret, serv_errno); if (!dictlist && global_work_base) { DICTL *b_dictl = NULL; - dltp = global_work_base -> Jdictlist; + dltp = global_work_base->Jdictlist; dictl = NULL; while (dltp) { dictl = (DICTL *)malloc(sizeof *dictl); @@ -279,68 +275,72 @@ exec_opendict (void) while (tmp != NULL) { tmp1 = tmp; tmp = tmp->next; - free (tmp1); + free(tmp1); } dictlist = NULL; } - if (!dictlist) dictlist = dictl; + if (!dictlist) + dictlist = dictl; dictl->dict = dltp->dict; - ((DictFile *)(dictl -> dict))->refcnt++; + ((DictFile *)(dictl->dict))->refcnt++; dictl->next = NULL; - if (b_dictl) b_dictl->next = dictl; + if (b_dictl) + b_dictl->next = dictl; b_dictl = dictl; dltp = dltp->next; } } - for (dltp = dictlist; dltp && dltp->dict != dict; dltp = dltp->next) ; + for (dltp = dictlist; dltp && dltp->dict != dict; dltp = dltp->next) + ; if (!dltp) { if (!(dictl = (DICTL *)malloc(sizeof *dictl))) { closedict((DictFile *)dict); longjmp(error_ret, SJ3_NotEnoughMemory); } - - dictl -> dict = dict; - dictl -> next = dictlist; + + dictl->dict = dict; + dictl->next = dictlist; dictlist = dictl; } - if (cur_cli -> work -> lock == cur_cli -> fd) { - if (dict -> maxunit != 0) - lock_dict((DictFile *)dict, cur_cli -> fd); + if (cur_cli->work->lock == cur_cli->fd) { + if (dict->maxunit != 0) + lock_dict((DictFile *)dict, cur_cli->fd); } put_int(SJ3_NormalEnd); put_int((int)dict->dicid); } - - void -exec_closedict (void) +exec_closedict(void) { - TypeDicID id; - DICTL *dictl; + TypeDicID id; + DICTL *dictl; id = get_int(); - if (!work_base) longjmp(error_ret, SJ3_NotConnected); + if (!work_base) + longjmp(error_ret, SJ3_NotConnected); - for (dictl = dictlist ; dictl ; dictl = dictl -> next) - if (dictl -> dict -> dicid == id) break; - if (!dictl) longjmp(error_ret, SJ3_BadDictID); + for (dictl = dictlist; dictl; dictl = dictl->next) + if (dictl->dict->dicid == id) + break; + if (!dictl) + longjmp(error_ret, SJ3_BadDictID); - unlock_dict((DictFile *)(dictl -> dict), cur_cli -> fd); + unlock_dict((DictFile *)(dictl->dict), cur_cli->fd); - closedict((DictFile *)(dictl -> dict)); + closedict((DictFile *)(dictl->dict)); if (dictlist == dictl) { - dictlist = dictl -> next; + dictlist = dictl->next; } else { DICTL *p; - for (p = dictlist ; p -> next ; p = p -> next) { - if (p -> next == dictl) { - p -> next = dictl -> next; + for (p = dictlist; p->next; p = p->next) { + if (p->next == dictl) { + p->next = dictl->next; break; } } @@ -349,189 +349,192 @@ exec_closedict (void) put_int(SJ3_NormalEnd); } - - void close_dictlist(DICTL *dictl) { DICTL *p; while (dictl) { - unlock_dict((DictFile *)(dictl -> dict), cur_cli -> fd); - closedict((DictFile *)(dictl -> dict)); - p = dictl -> next; + unlock_dict((DictFile *)(dictl->dict), cur_cli->fd); + closedict((DictFile *)(dictl->dict)); + p = dictl->next; free((char *)dictl); dictl = p; } } - - void -exec_openstdy (void) +exec_openstdy(void) { - char filename[PathNameLen]; - char password[PassWordLen]; - StdyFile *stdy; + char filename[PathNameLen]; + char password[PassWordLen]; + StdyFile *stdy; get_nstring(filename, sizeof(filename)); get_nstring(password, sizeof(password)); - if (cur_cli -> stdy) longjmp(error_ret, SJ3_StdyAlreadyOpened); - if (make_full_path(filename)) longjmp(error_ret, SJ3_TooLongParameter); + if (cur_cli->stdy) + longjmp(error_ret, SJ3_StdyAlreadyOpened); + if (make_full_path(filename)) + longjmp(error_ret, SJ3_TooLongParameter); if (!(stdy = openstdy(filename, password))) longjmp(error_ret, serv_errno); - cur_cli -> stdy = stdy; + cur_cli->stdy = stdy; put_int(SJ3_NormalEnd); } - - void -exec_closestdy (void) +exec_closestdy(void) { - if (!cur_cli -> stdy) longjmp(error_ret, SJ3_StdyFileNotOpened); + if (!cur_cli->stdy) + longjmp(error_ret, SJ3_StdyFileNotOpened); - closestdy(cur_cli -> stdy); - cur_cli -> stdy = NULL; + closestdy(cur_cli->stdy); + cur_cli->stdy = NULL; put_int(SJ3_NormalEnd); } - - void -exec_stdysize (void) +exec_stdysize(void) { put_int(SJ3_NormalEnd); put_int(sizeof(STDYOUT)); } - - -static void -exec_lock (void) +static void +exec_lock(void) { - int lock; + int lock; DICTL *dl; - if (!work_base) longjmp(error_ret, SJ3_NotConnected); + if (!work_base) + longjmp(error_ret, SJ3_NotConnected); - - lock = cur_cli -> work -> lock; - if (lock != NotLocked && lock != cur_cli -> fd) + lock = cur_cli->work->lock; + if (lock != NotLocked && lock != cur_cli->fd) longjmp(error_ret, SJ3_LockedByOther); - cur_cli -> work -> lock = cur_cli -> fd; + cur_cli->work->lock = cur_cli->fd; - - for (dl = dictlist ; dl ; dl = dl -> next) { - if (dl -> dict -> maxunit == 0) continue; - lock_dict((DictFile *)(dl -> dict), cur_cli -> fd); + for (dl = dictlist; dl; dl = dl->next) { + if (dl->dict->maxunit == 0) + continue; + lock_dict((DictFile *)(dl->dict), cur_cli->fd); } put_int(SJ3_NormalEnd); } - - -static void -exec_unlock (void) +static void +exec_unlock(void) { - int lock; + int lock; DICTL *dl; - if (!work_base) longjmp(error_ret, SJ3_NotConnected); + if (!work_base) + longjmp(error_ret, SJ3_NotConnected); - - lock = cur_cli -> work -> lock; - if (lock == NotLocked) longjmp(error_ret, SJ3_NotLocked); - if (lock != cur_cli -> fd) longjmp(error_ret, SJ3_LockedByOther); - cur_cli -> work -> lock = NotLocked; + lock = cur_cli->work->lock; + if (lock == NotLocked) + longjmp(error_ret, SJ3_NotLocked); + if (lock != cur_cli->fd) + longjmp(error_ret, SJ3_LockedByOther); + cur_cli->work->lock = NotLocked; - - for (dl = dictlist ; dl ; dl = dl -> next) { - if (dl -> dict -> maxunit == 0) continue; - unlock_dict((DictFile *)(dl -> dict), cur_cli -> fd); + for (dl = dictlist; dl; dl = dl->next) { + if (dl->dict->maxunit == 0) + continue; + unlock_dict((DictFile *)(dl->dict), cur_cli->fd); } put_int(SJ3_NormalEnd); } - - -static void -lock_check_for_read (void) +static void +lock_check_for_read(void) { int lock; - lock = cur_cli -> work -> lock; + lock = cur_cli->work->lock; if (lock == NotLocked) #ifdef SEVERE_LOCK longjmp(error_ret, SJ3_NotLocked); #else ; #endif - else if (lock != cur_cli -> fd) + else if (lock != cur_cli->fd) longjmp(error_ret, SJ3_LockedByOther); } - void -exec_ph2knj (int mb_flag) +exec_ph2knj(int mb_flag) { - int i, j, l, stdy_size, buf_size, srchead = 0, srclen; - Uchar *p,*q; + int srchead = 0; + int buf_size, i, j, l, srclen, stdy_size; + Uchar *p, *q; i = get_nstring(buf1, sizeof(buf1)); - if (!work_base) longjmp(error_ret, SJ3_NotConnected); - if (i) longjmp(error_ret, SJ3_TooLongParameter); + if (!work_base) + longjmp(error_ret, SJ3_NotConnected); + if (i) + longjmp(error_ret, SJ3_TooLongParameter); lock_check_for_read(); if (mb_flag == SJIS_PROTO) { - if (sj3_str_sjistoeuc(buf2, sizeof(buf2), buf1, - cur_cli->def_char, &defuse) < 0) - goto CCONVERR; + if (sj3_str_sjistoeuc(buf2, sizeof(buf2), buf1, + cur_cli->def_char, &defuse) < 0) + goto CCONVERR; i = ph2knj(buf2, kbuf, sizeof(kbuf)); p = kbuf; q = skbuf; stdy_size = sizeof(STDYOUT) + 1; buf_size = sizeof(skbuf); - + while (*p) { srchead += *p; srclen = *p; buf_size -= stdy_size; - if (buf_size <= 0) goto CCONVERR; - (void) rmemcpy(q, p, stdy_size); + if (buf_size <= 0) + goto CCONVERR; + (void)rmemcpy(q, p, stdy_size); p += stdy_size; - q += stdy_size; - l = sj3_str_euctosjis(q, buf_size, p, cur_cli->def_char, &defuse); - if (l < 0) goto CCONVERR; + q += stdy_size; + l = sj3_str_euctosjis(q, buf_size, p, + cur_cli->def_char, &defuse); + if (l < 0) + goto CCONVERR; if (defuse) { - (void) rmemcpy(buf3, &(buf2[srchead-srclen]), srclen); + (void)rmemcpy(buf3, &(buf2[srchead - srclen]), + srclen); buf3[srclen] = '\0'; - j = cl2knj(buf3, srclen, buf4); - l = sj3_str_euctosjis(q, buf_size, &(buf4[stdy_size]), - cur_cli->def_char, &defuse); - while(defuse && (j == srclen)) { + j = cl2knj(buf3, srclen, buf4); + l = sj3_str_euctosjis(q, buf_size, + &(buf4[stdy_size]), cur_cli->def_char, + &defuse); + while (defuse && (j == srclen)) { j = nextcl(buf4, 0); - l = sj3_str_euctosjis(q, buf_size, &(buf4[stdy_size]), - cur_cli->def_char, &defuse); - if (l < 0) goto CCONVERR; + l = sj3_str_euctosjis(q, buf_size, + &(buf4[stdy_size]), + cur_cli->def_char, &defuse); + if (l < 0) + goto CCONVERR; } - if (!defuse && (j == srclen)) { - (void) rmemcpy(q-stdy_size, buf4, stdy_size); + if (!defuse && (j == srclen)) { + (void)rmemcpy(q - stdy_size, buf4, + stdy_size); } else { - l = sj3_str_euctosjis(q, buf_size, buf3, - cur_cli->def_char, &defuse); - if ((l < 0) || defuse) goto CCONVERR; + l = sj3_str_euctosjis(q, buf_size, buf3, + cur_cli->def_char, &defuse); + if ((l < 0) || defuse) + goto CCONVERR; } - } + } p += strlen(p) + 1; - q += l + 1; buf_size -= l + 1; + q += l + 1; + buf_size -= l + 1; } *q = '\0'; p = skbuf; @@ -539,11 +542,12 @@ exec_ph2knj (int mb_flag) i = ph2knj(buf1, kbuf, sizeof(kbuf)); p = kbuf; } - + put_int(SJ3_NormalEnd); put_int(i); while (*p) { - put_byte(*p); p++; + put_byte(*p); + p++; p = put_ndata(p, sizeof(STDYOUT)); p = put_string(p); } @@ -554,52 +558,56 @@ CCONVERR: return; } - void -exec_cl2knj (int mb_flag) +exec_cl2knj(int mb_flag) { - int len, stdy_size, buf_size; - int i, j, l; + int buf_size, i, j, l, len, stdy_size; Uchar *ptr, *q; len = get_int(); i = get_nstring(buf1, sizeof(buf1)); - if (!work_base) longjmp(error_ret, SJ3_NotConnected); - if (i) longjmp(error_ret, SJ3_TooLongParameter); + if (!work_base) + longjmp(error_ret, SJ3_NotConnected); + if (i) + longjmp(error_ret, SJ3_TooLongParameter); lock_check_for_read(); if (mb_flag == SJIS_PROTO) { - if (sj3_str_sjistoeuc(buf2, sizeof(buf2), buf1, - cur_cli->def_char, &defuse) < 0) - goto CCONVERR; + if (sj3_str_sjistoeuc(buf2, sizeof(buf2), buf1, + cur_cli->def_char, &defuse) < 0) + goto CCONVERR; i = cl2knj(buf2, strlen(buf2), kbuf); ptr = kbuf; q = skbuf; buf_size = sizeof(skbuf); stdy_size = sizeof(STDYOUT); - - (void) rmemcpy(q, ptr, stdy_size); + + (void)rmemcpy(q, ptr, stdy_size); ptr += stdy_size; - q += stdy_size; + q += stdy_size; buf_size -= stdy_size; - l = sj3_str_euctosjis(q, buf_size, ptr, - cur_cli->def_char, &defuse); - if (l < 0) goto CCONVERR; + l = sj3_str_euctosjis(q, buf_size, ptr, + cur_cli->def_char, &defuse); + if (l < 0) + goto CCONVERR; if (defuse) { j = strlen(buf2); while (defuse && (i == j)) { i = nextcl(buf4, 0); - l = sj3_str_euctosjis(q, buf_size, &(buf4[stdy_size]), - cur_cli->def_char, &defuse); - if (l < 0) goto CCONVERR; + l = sj3_str_euctosjis(q, buf_size, + &(buf4[stdy_size]), cur_cli->def_char, + &defuse); + if (l < 0) + goto CCONVERR; } if (!defuse && (j == i)) { - (void) rmemcpy(q-stdy_size, buf4, stdy_size); + (void)rmemcpy(q - stdy_size, buf4, stdy_size); } else { l = sj3_str_euctosjis(q, buf_size, buf2, - cur_cli->def_char, &defuse); - if ((l < 0) || defuse) goto CCONVERR; + cur_cli->def_char, &defuse); + if ((l < 0) || defuse) + goto CCONVERR; i = l; } } @@ -608,7 +616,7 @@ exec_cl2knj (int mb_flag) i = cl2knj(buf1, len, kbuf); ptr = kbuf; } - + put_int(SJ3_NormalEnd); put_int(i); ptr = put_ndata(ptr, sizeof(STDYOUT)); @@ -619,17 +627,16 @@ CCONVERR: return; } - void -exec_nextcl (int mb_flag) +exec_nextcl(int mb_flag) { - int mode, stdy_size, buf_size; - int i, l; + int buf_size, i, l, mode, stdy_size; Uchar *ptr, *q; mode = get_int(); - if (!work_base) longjmp(error_ret, SJ3_NotConnected); + if (!work_base) + longjmp(error_ret, SJ3_NotConnected); lock_check_for_read(); i = nextcl(kbuf, mode); @@ -638,21 +645,24 @@ exec_nextcl (int mb_flag) q = skbuf; buf_size = sizeof(skbuf); stdy_size = sizeof(STDYOUT); - - (void) rmemcpy(q, ptr, stdy_size); + + (void)rmemcpy(q, ptr, stdy_size); ptr += stdy_size; - q += stdy_size; + q += stdy_size; buf_size -= stdy_size; - l = sj3_str_euctosjis(q, buf_size, ptr, cur_cli->def_char, &defuse); - if (l < 0) goto CCONVERR; + l = sj3_str_euctosjis(q, buf_size, ptr, cur_cli->def_char, + &defuse); + if (l < 0) + goto CCONVERR; while (defuse && i) { i = nextcl(kbuf, mode); - l = sj3_str_euctosjis(q, buf_size, &(kbuf[stdy_size]), - cur_cli->def_char, &defuse); - if (l < 0) goto CCONVERR; + l = sj3_str_euctosjis(q, buf_size, &(kbuf[stdy_size]), + cur_cli->def_char, &defuse); + if (l < 0) + goto CCONVERR; } if (!defuse && i) { - (void) rmemcpy(q-stdy_size, kbuf, stdy_size); + (void)rmemcpy(q - stdy_size, kbuf, stdy_size); } else { put_int(SJ3_NoMoreDouonWord); return; @@ -661,28 +671,27 @@ exec_nextcl (int mb_flag) } else { ptr = kbuf; } - + put_int(SJ3_NormalEnd); put_int(i); ptr = put_ndata(ptr, sizeof(STDYOUT)); put_string(ptr); return; CCONVERR: - put_int(SJ3_CannotCodeConvert); - return; + put_int(SJ3_CannotCodeConvert); + return; } - void -exec_prevcl (int mb_flag) +exec_prevcl(int mb_flag) { - int mode, stdy_size, buf_size; - int i, l; + int buf_size, i, l, mode, stdy_size; Uchar *ptr, *q; mode = get_int(); - if (!work_base) longjmp(error_ret, SJ3_NotConnected); + if (!work_base) + longjmp(error_ret, SJ3_NotConnected); lock_check_for_read(); i = prevcl(kbuf, mode); @@ -691,21 +700,24 @@ exec_prevcl (int mb_flag) q = skbuf; buf_size = sizeof(skbuf); stdy_size = sizeof(STDYOUT); - - (void) rmemcpy(q, ptr, stdy_size); + + (void)rmemcpy(q, ptr, stdy_size); ptr += stdy_size; - q += stdy_size; + q += stdy_size; buf_size -= stdy_size; - l = sj3_str_euctosjis(q, buf_size, ptr, cur_cli->def_char, &defuse); - if (l < 0) goto CCONVERR; + l = sj3_str_euctosjis(q, buf_size, ptr, cur_cli->def_char, + &defuse); + if (l < 0) + goto CCONVERR; while (defuse && i) { i = prevcl(kbuf, mode); - l = sj3_str_euctosjis(q, buf_size, &(kbuf[stdy_size]), - cur_cli->def_char, &defuse); - if (l < 0) goto CCONVERR; + l = sj3_str_euctosjis(q, buf_size, &(kbuf[stdy_size]), + cur_cli->def_char, &defuse); + if (l < 0) + goto CCONVERR; } if (!defuse && i) { - (void) rmemcpy(q-stdy_size, kbuf, stdy_size); + (void)rmemcpy(q - stdy_size, kbuf, stdy_size); } else { put_int(SJ3_NoMoreDouonWord); return; @@ -715,53 +727,54 @@ exec_prevcl (int mb_flag) ptr = kbuf; } - put_int(SJ3_NormalEnd); put_int(i); ptr = put_ndata(ptr, sizeof(STDYOUT)); put_string(ptr); return; CCONVERR: - put_int(SJ3_CannotCodeConvert); - return; + put_int(SJ3_CannotCodeConvert); + return; } - void exec_cl2knj_cnt(int mb_flag) { - int len, buf_size, stdy_size; - int i; int cnt = 0; + int buf_size, i, len, stdy_size; len = get_int(); i = get_nstring(buf1, sizeof(buf1)); - if (!work_base) longjmp(error_ret, SJ3_NotConnected); - if (i) longjmp(error_ret, SJ3_TooLongParameter); + if (!work_base) + longjmp(error_ret, SJ3_NotConnected); + if (i) + longjmp(error_ret, SJ3_TooLongParameter); lock_check_for_read(); if (mb_flag == SJIS_PROTO) { - if (sj3_str_sjistoeuc(buf2, sizeof(buf2), buf1, - cur_cli->def_char, &defuse) < 0) - goto CCONVERR; + if (sj3_str_sjistoeuc(buf2, sizeof(buf2), buf1, + cur_cli->def_char, &defuse) < 0) + goto CCONVERR; i = cl2knj(buf2, len, kbuf); stdy_size = sizeof(STDYOUT); buf_size = sizeof(skbuf) - stdy_size; - } else { + } else { i = cl2knj(buf1, len, kbuf); } if (i) { while (i == len) { if (mb_flag == SJIS_PROTO) { - if (sj3_str_euctosjis(skbuf, buf_size, - &(kbuf[stdy_size]), - cur_cli->def_char, &defuse) - < 0) - goto CCONVERR; - if (!defuse) cnt++; - } else - cnt++; + if (sj3_str_euctosjis(skbuf, buf_size, + &(kbuf[stdy_size]), + cur_cli->def_char, &defuse) < + 0) + goto CCONVERR; + if (!defuse) + cnt++; + } else { + cnt++; + } i = nextcl(kbuf, 0); } } @@ -774,55 +787,58 @@ CCONVERR: return; } - void -exec_cl2knj_all (int mb_flag) +exec_cl2knj_all(int mb_flag) { - int len, stdy_size, buf_size; - int i, l; + int buf_size, i, l, len, stdy_size; Uchar *ptr, *q; len = get_int(); i = get_nstring(buf1, sizeof(buf1)); - if (!work_base) longjmp(error_ret, SJ3_NotConnected); - if (i) longjmp(error_ret, SJ3_TooLongParameter); + if (!work_base) + longjmp(error_ret, SJ3_NotConnected); + if (i) + longjmp(error_ret, SJ3_TooLongParameter); lock_check_for_read(); if (mb_flag == SJIS_PROTO) { - if (sj3_str_sjistoeuc(buf2, sizeof(buf2), buf1, - cur_cli->def_char, &defuse) < 0) - goto CCONVERR; + if (sj3_str_sjistoeuc(buf2, sizeof(buf2), buf1, + cur_cli->def_char, &defuse) < 0) + goto CCONVERR; len = strlen(buf2); i = cl2knj(buf2, len, kbuf); ptr = kbuf; q = skbuf; buf_size = sizeof(skbuf); stdy_size = sizeof(STDYOUT); - - (void) rmemcpy(q, ptr, stdy_size); + + (void)rmemcpy(q, ptr, stdy_size); ptr += stdy_size; - q += stdy_size; + q += stdy_size; buf_size -= stdy_size; - l = sj3_str_euctosjis(q, buf_size, ptr, cur_cli->def_char, &defuse); - if (l < 0) goto CCONVERR; + l = sj3_str_euctosjis(q, buf_size, ptr, cur_cli->def_char, + &defuse); + if (l < 0) + goto CCONVERR; if (defuse) { while (defuse && (i == len)) { - i = nextcl(kbuf, 0); - l = sj3_str_euctosjis(q, buf_size, - &(kbuf[stdy_size]), - cur_cli->def_char, &defuse); - if (l < 0) goto CCONVERR; + i = nextcl(kbuf, 0); + l = sj3_str_euctosjis(q, buf_size, + &(kbuf[stdy_size]), + cur_cli->def_char, &defuse); + if (l < 0) + goto CCONVERR; } if (!defuse && (i == len)) { - (void) rmemcpy(q-stdy_size, kbuf, stdy_size); + (void)rmemcpy(q - stdy_size, kbuf, stdy_size); } else { put_int(SJ3_NoMoreDouonWord); return; } } ptr = skbuf; - } else { + } else { i = cl2knj(buf1, len, kbuf); ptr = kbuf; } @@ -838,26 +854,28 @@ exec_cl2knj_all (int mb_flag) q = skbuf; buf_size = sizeof(skbuf); stdy_size = sizeof(STDYOUT); - - (void) rmemcpy(q, ptr, stdy_size); + + (void)rmemcpy(q, ptr, stdy_size); ptr += stdy_size; - q += stdy_size; + q += stdy_size; buf_size -= stdy_size; - l = sj3_str_euctosjis(q, buf_size, ptr, - cur_cli->def_char, &defuse); - if (l < 0) goto CCONVERR; + l = sj3_str_euctosjis(q, buf_size, ptr, + cur_cli->def_char, &defuse); + if (l < 0) + goto CCONVERR; if (defuse) { while (defuse && (i == len)) { i = nextcl(kbuf, 0); - l = sj3_str_euctosjis(q, buf_size, - &(kbuf[stdy_size]), - cur_cli->def_char, - &defuse); - if (l < 0) goto CCONVERR; + l = sj3_str_euctosjis(q, + buf_size, + &(kbuf[stdy_size]), + cur_cli->def_char, &defuse); + if (l < 0) + goto CCONVERR; } if (!defuse && (len == i)) { - (void) rmemcpy(q-stdy_size, - kbuf, stdy_size); + (void)rmemcpy(q - stdy_size, + kbuf, stdy_size); } } ptr = skbuf; @@ -869,77 +887,79 @@ exec_cl2knj_all (int mb_flag) put_int(0); return; CCONVERR: - put_int(SJ3_CannotCodeConvert); - return; + put_int(SJ3_CannotCodeConvert); + return; } - - void -exec_study (void) +exec_study(void) { int err; STDYOUT stdy; get_ndata(&stdy, sizeof(stdy)); - if (!work_base) longjmp(error_ret, SJ3_NotConnected); - if (!stdy_base) longjmp(error_ret, SJ3_StdyFileNotOpened); + if (!work_base) + longjmp(error_ret, SJ3_NotConnected); + if (!stdy_base) + longjmp(error_ret, SJ3_StdyFileNotOpened); lock_check_for_read(); err = study(&stdy); - switch (err) { - case StudyNoDict: err = SJ3_StdyFileNotOpened; break; + case StudyNoDict: err = SJ3_StdyFileNotOpened; break; case StudyNormEnd: case StudyFullArea: - case StudyNotStudy: err = SJ3_NormalEnd; break; + case StudyNotStudy: err = SJ3_NormalEnd; break; case StudyError: - default: err = SJ3_InternalError; break; + default: err = SJ3_InternalError; break; } - if (err != SJ3_NormalEnd) longjmp(error_ret, err); + if (err != SJ3_NormalEnd) + longjmp(error_ret, err); put_int(err); } - void -exec_clstudy (int mb_flag) +exec_clstudy(int mb_flag) { int err; STDYOUT stdy; - err = get_nstring(buf1, sizeof(buf1)); + err = get_nstring(buf1, sizeof(buf1)); err |= get_nstring(buf2, sizeof(buf2)); get_ndata(&stdy, sizeof(stdy)); - if (!work_base) longjmp(error_ret, SJ3_NotConnected); - if (!stdy_base) longjmp(error_ret, SJ3_StdyFileNotOpened); - if (err) longjmp(error_ret, SJ3_TooLongParameter); + if (!work_base) + longjmp(error_ret, SJ3_NotConnected); + if (!stdy_base) + longjmp(error_ret, SJ3_StdyFileNotOpened); + if (err) + longjmp(error_ret, SJ3_TooLongParameter); lock_check_for_read(); if (mb_flag == SJIS_PROTO) { - if (sj3_str_sjistoeuc(buf3, sizeof(buf3), buf1, - cur_cli->def_char, &defuse) < 0) - goto CCONVERR; - if (sj3_str_sjistoeuc(buf4, sizeof(buf4), buf2, - cur_cli->def_char, &defuse) < 0) - goto CCONVERR; + if (sj3_str_sjistoeuc(buf3, sizeof(buf3), buf1, + cur_cli->def_char, &defuse) < 0) + goto CCONVERR; + if (sj3_str_sjistoeuc(buf4, sizeof(buf4), buf2, + cur_cli->def_char, &defuse) < 0) + goto CCONVERR; err = clstudy(buf3, buf4, &stdy); } else { err = clstudy(buf1, buf2, &stdy); } - switch (err) { - case ClstudyNoDict: err = SJ3_StdyFileNotOpened; break; - case ClstudyNormEnd: err = SJ3_NormalEnd; break; + case ClstudyNoDict: err = SJ3_StdyFileNotOpened; break; + case ClstudyNormEnd: err = SJ3_NormalEnd; break; case ClstudyParaErr: - case ClstudyYomiErr: err = SJ3_IllegalParameter; break; - case ClstudyNoArea: err = SJ3_TooSmallStdyArea; break; - default: err = SJ3_InternalError; break; + case ClstudyYomiErr: err = SJ3_IllegalParameter; break; + case ClstudyNoArea: err = SJ3_TooSmallStdyArea; break; + default: err = SJ3_InternalError; break; } - if (err != SJ3_NormalEnd) longjmp(error_ret, err); + if (err != SJ3_NormalEnd) + longjmp(error_ret, err); put_int(err); return; CCONVERR: @@ -947,153 +967,172 @@ CCONVERR: return; } - void -exec_adddict (int mb_flag) +exec_adddict(int mb_flag) { - TypeDicID dicid; - TypeGram gram; - int err; - int err1; + TypeDicID dicid; + TypeGram gram; + int err, err1; DICTL *dl; - dicid = get_int(); - err = get_nstring(buf1, sizeof(buf1)); + err = get_nstring(buf1, sizeof(buf1)); err1 = get_nstring(buf2, sizeof(buf2)); gram = get_int(); - if (!work_base) longjmp(error_ret, SJ3_NotConnected); - if (err) longjmp(error_ret, SJ3_BadYomiString); - if (err1) longjmp(error_ret, SJ3_BadKanjiString); + if (!work_base) + longjmp(error_ret, SJ3_NotConnected); + if (err) + longjmp(error_ret, SJ3_BadYomiString); + if (err1) + longjmp(error_ret, SJ3_BadKanjiString); - - for (dl = dictlist ; dl ; dl = dl -> next) - if (dl -> dict -> dicid == dicid) break; - if (!dl) longjmp(error_ret, SJ3_NoSuchDict); - if (dl -> dict -> maxunit == 0) + for (dl = dictlist; dl; dl = dl->next) + if (dl->dict->dicid == dicid) + break; + if (!dl) + longjmp(error_ret, SJ3_NoSuchDict); + if (dl->dict->maxunit == 0) longjmp(error_ret, SJ3_ReadOnlyDict); - if (is_dict_locked((DictFile *)(dl -> dict))) + if (is_dict_locked((DictFile *)(dl->dict))) longjmp(error_ret, SJ3_DictLocked); - debug_out(2, "adddic %s:%s:%d ", buf1, buf2, gram); seldict(dicid); if (mb_flag == SJIS_PROTO) { - if (sj3_str_sjistoeuc(buf3, sizeof(buf3), buf1, - cur_cli->def_char, &defuse) < 0) - goto CCONVERR; - if (sj3_str_sjistoeuc(buf4, sizeof(buf4), buf2, - cur_cli->def_char, &defuse) < 0) - goto CCONVERR; + if (sj3_str_sjistoeuc(buf3, sizeof(buf3), buf1, + cur_cli->def_char, &defuse) < 0) + goto CCONVERR; + if (sj3_str_sjistoeuc(buf4, sizeof(buf4), buf2, + cur_cli->def_char, &defuse) < 0) + goto CCONVERR; err = adddic(buf3, buf4, gram); } else { err = adddic(buf1, buf2, gram); } - - if (err & AD_NotUserDict) err = SJ3_ReadOnlyDict; - else if (err & AD_BadYomi) err = SJ3_BadYomiString; - else if (err & AD_BadKanji) err = SJ3_BadKanjiString; - else if (err & AD_BadHinsi) err = SJ3_BadHinsiCode; - else if (err & AD_ArExist) err = SJ3_AlreadyExistWord; - else if (err & AD_OvflwDouBlk) err = SJ3_NoMoreDouonWord; - else if (err & AD_OvflwDouNum) err = SJ3_NoMoreDouonWord; - else if (err & AD_OvflwUsrDic) err = SJ3_NoMoreUserDict; - else if (err & AD_OvflwIndex) err = SJ3_NoMoreIndexBlock; - else if (err) err = SJ3_AddDictFailed; - else err = SJ3_NormalEnd; - if (err != SJ3_NormalEnd) longjmp(error_ret, err); + if (err & AD_NotUserDict) + err = SJ3_ReadOnlyDict; + else if (err & AD_BadYomi) + err = SJ3_BadYomiString; + else if (err & AD_BadKanji) + err = SJ3_BadKanjiString; + else if (err & AD_BadHinsi) + err = SJ3_BadHinsiCode; + else if (err & AD_ArExist) + err = SJ3_AlreadyExistWord; + else if (err & AD_OvflwDouBlk) + err = SJ3_NoMoreDouonWord; + else if (err & AD_OvflwDouNum) + err = SJ3_NoMoreDouonWord; + else if (err & AD_OvflwUsrDic) + err = SJ3_NoMoreUserDict; + else if (err & AD_OvflwIndex) + err = SJ3_NoMoreIndexBlock; + else if (err) + err = SJ3_AddDictFailed; + else + err = SJ3_NormalEnd; + if (err != SJ3_NormalEnd) + longjmp(error_ret, err); put_int(err); return; CCONVERR: - put_int(SJ3_CannotCodeConvert); - return; + put_int(SJ3_CannotCodeConvert); + return; } void -exec_deldict (int mb_flag) +exec_deldict(int mb_flag) { - TypeDicID dicid; - TypeGram gram; - int err; - int err1; + TypeDicID dicid; + TypeGram gram; + int err, err1; DICTL *dl; - dicid = get_int(); - err = get_nstring(buf1, sizeof(buf1)); + err = get_nstring(buf1, sizeof(buf1)); err1 = get_nstring(buf2, sizeof(buf2)); gram = get_int(); - if (!work_base) longjmp(error_ret, SJ3_NotConnected); - if (err) longjmp(error_ret, SJ3_BadYomiString); - if (err1) longjmp(error_ret, SJ3_BadKanjiString); + if (!work_base) + longjmp(error_ret, SJ3_NotConnected); + if (err) + longjmp(error_ret, SJ3_BadYomiString); + if (err1) + longjmp(error_ret, SJ3_BadKanjiString); - - for (dl = dictlist ; dl ; dl = dl -> next) - if (dl -> dict -> dicid == dicid) break; - if (!dl) longjmp(error_ret, SJ3_NoSuchDict); - if (dl -> dict -> maxunit == 0) + for (dl = dictlist; dl; dl = dl->next) + if (dl->dict->dicid == dicid) + break; + if (!dl) + longjmp(error_ret, SJ3_NoSuchDict); + if (dl->dict->maxunit == 0) longjmp(error_ret, SJ3_ReadOnlyDict); - if (is_dict_locked((DictFile *)(dl -> dict))) + if (is_dict_locked((DictFile *)(dl->dict))) longjmp(error_ret, SJ3_DictLocked); - seldict(dicid); if (mb_flag == SJIS_PROTO) { - if (sj3_str_sjistoeuc(buf3, sizeof(buf3), buf1, - cur_cli->def_char, &defuse) < 0) - goto CCONVERR; - if (sj3_str_sjistoeuc(buf4, sizeof(buf4), buf2, - cur_cli->def_char, &defuse) < 0) - goto CCONVERR; + if (sj3_str_sjistoeuc(buf3, sizeof(buf3), buf1, + cur_cli->def_char, &defuse) < 0) + goto CCONVERR; + if (sj3_str_sjistoeuc(buf4, sizeof(buf4), buf2, + cur_cli->def_char, &defuse) < 0) + goto CCONVERR; err = deldic(buf3, buf4, gram); } else { err = deldic(buf1, buf2, gram); } - - if (err & AD_NotUserDict) err = SJ3_ReadOnlyDict; - else if (err & AD_BadYomi) err = SJ3_BadYomiString; - else if (err & AD_BadKanji) err = SJ3_BadKanjiString; - else if (err & AD_BadHinsi) err = SJ3_BadHinsiCode; - else if (err & AD_NoMidasi) err = SJ3_NoSuchWord; - else if (err & AD_NoHinsi) err = SJ3_NoSuchWord; - else if (err & AD_NoKanji) err = SJ3_NoSuchWord; - else if (err) err = SJ3_DelDictFailed; - else err = SJ3_NormalEnd; - if (err != SJ3_NormalEnd) longjmp(error_ret, err); + if (err & AD_NotUserDict) + err = SJ3_ReadOnlyDict; + else if (err & AD_BadYomi) + err = SJ3_BadYomiString; + else if (err & AD_BadKanji) + err = SJ3_BadKanjiString; + else if (err & AD_BadHinsi) + err = SJ3_BadHinsiCode; + else if (err & AD_NoMidasi) + err = SJ3_NoSuchWord; + else if (err & AD_NoHinsi) + err = SJ3_NoSuchWord; + else if (err & AD_NoKanji) + err = SJ3_NoSuchWord; + else if (err) + err = SJ3_DelDictFailed; + else + err = SJ3_NormalEnd; + if (err != SJ3_NormalEnd) + longjmp(error_ret, err); put_int(err); return; CCONVERR: - put_int(SJ3_CannotCodeConvert); - return; + put_int(SJ3_CannotCodeConvert); + return; } - void -exec_getdict (int mb_flag) +exec_getdict(int mb_flag) { - TypeDicID dicid; - int err, buf_size, l; + TypeDicID dicid; + int buf_size, err, l; DICTL *dl; Uchar *ptr, *q; - dicid = get_int(); - if (!work_base) longjmp(error_ret, SJ3_NotConnected); - - - for (dl = dictlist ; dl ; dl = dl -> next) - if (dl -> dict -> dicid == dicid) break; - if (!dl) longjmp(error_ret, SJ3_NoSuchDict); + if (!work_base) + longjmp(error_ret, SJ3_NotConnected); + for (dl = dictlist; dl; dl = dl->next) + if (dl->dict->dicid == dicid) + break; + if (!dl) + longjmp(error_ret, SJ3_NoSuchDict); lock_check_for_read(); - seldict(dicid); err = getusr(kbuf); if (err) { @@ -1101,38 +1140,42 @@ exec_getdict (int mb_flag) buf_size = sizeof(skbuf); ptr = kbuf; q = skbuf; - l = sj3_str_euctosjis(q, buf_size, ptr, - cur_cli->def_char, &defuse); - if (l < 0) goto CCONVERR; + l = sj3_str_euctosjis(q, buf_size, ptr, + cur_cli->def_char, &defuse); + if (l < 0) + goto CCONVERR; ptr += strlen(ptr) + 1; q += l + 1; buf_size -= l + 1; - l = sj3_str_euctosjis(q, buf_size, ptr, - cur_cli->def_char, &defuse2); - if (l < 0) goto CCONVERR; + l = sj3_str_euctosjis(q, buf_size, ptr, + cur_cli->def_char, &defuse2); + if (l < 0) + goto CCONVERR; if (defuse || defuse2) { while ((defuse || defuse2) && err) { ptr = kbuf; q = skbuf; buf_size = sizeof(skbuf); err = nextusr(kbuf); - if (!err) break; - l = sj3_str_euctosjis(q, buf_size, ptr, - cur_cli->def_char, - &defuse); - if (l < 0) goto CCONVERR; + if (!err) + break; + l = sj3_str_euctosjis(q, buf_size, ptr, + cur_cli->def_char, + &defuse); + if (l < 0) + goto CCONVERR; ptr += strlen(ptr) + 1; q += l + 1; buf_size -= l + 1; - l = sj3_str_euctosjis(q, buf_size, ptr, - cur_cli->def_char, - &defuse2); - if (l < 0) goto CCONVERR; + l = sj3_str_euctosjis(q, buf_size, ptr, + cur_cli->def_char, + &defuse2); + if (l < 0) + goto CCONVERR; } - if (!err) { + if (!err) longjmp(error_ret, SJ3_NoMoreDictData); - } - } + } ptr += strlen(ptr) + 1; q += l + 1; *q = *ptr; @@ -1140,44 +1183,41 @@ exec_getdict (int mb_flag) } else { ptr = kbuf; } - + put_int(SJ3_NormalEnd); ptr = put_string(ptr); ptr = put_string(ptr); put_int(*ptr); - } - else + } else { longjmp(error_ret, SJ3_NoMoreDictData); + } return; CCONVERR: - put_int(SJ3_CannotCodeConvert); - return; + put_int(SJ3_CannotCodeConvert); + return; } - - void -exec_nextdict (int mb_flag) +exec_nextdict(int mb_flag) { - TypeDicID dicid; - int err, buf_size, l; + TypeDicID dicid; + int buf_size, err, l; DICTL *dl; Uchar *ptr, *q; - dicid = get_int(); - if (!work_base) longjmp(error_ret, SJ3_NotConnected); - - - for (dl = dictlist ; dl ; dl = dl -> next) - if (dl -> dict -> dicid == dicid) break; - if (!dl) longjmp(error_ret, SJ3_NoSuchDict); + if (!work_base) + longjmp(error_ret, SJ3_NotConnected); + for (dl = dictlist; dl; dl = dl->next) + if (dl->dict->dicid == dicid) + break; + if (!dl) + longjmp(error_ret, SJ3_NoSuchDict); lock_check_for_read(); - seldict(dicid); err = nextusr(kbuf); if (err) { @@ -1185,38 +1225,42 @@ exec_nextdict (int mb_flag) buf_size = sizeof(skbuf); ptr = kbuf; q = skbuf; - l = sj3_str_euctosjis(q, buf_size, ptr, cur_cli->def_char, - &defuse); - if (l < 0) goto CCONVERR; + l = sj3_str_euctosjis(q, buf_size, ptr, + cur_cli->def_char, &defuse); + if (l < 0) + goto CCONVERR; ptr += strlen(ptr) + 1; q += l + 1; buf_size -= l + 1; - l = sj3_str_euctosjis(q, buf_size, ptr, cur_cli->def_char, - &defuse2); - if (l < 0) goto CCONVERR; + l = sj3_str_euctosjis(q, buf_size, ptr, + cur_cli->def_char, &defuse2); + if (l < 0) + goto CCONVERR; if (defuse || defuse2) { while ((defuse || defuse2) && err) { ptr = kbuf; q = skbuf; buf_size = sizeof(skbuf); err = nextusr(kbuf); - if (!err) break; - l = sj3_str_euctosjis(q, buf_size, ptr, - cur_cli->def_char, - &defuse); - if (l < 0) goto CCONVERR; + if (!err) + break; + l = sj3_str_euctosjis(q, buf_size, ptr, + cur_cli->def_char, + &defuse); + if (l < 0) + goto CCONVERR; ptr += strlen(ptr) + 1; q += l + 1; buf_size -= l + 1; - l = sj3_str_euctosjis(q, buf_size, ptr, - cur_cli->def_char, - &defuse2); - if (l < 0) goto CCONVERR; + l = sj3_str_euctosjis(q, buf_size, ptr, + cur_cli->def_char, + &defuse2); + if (l < 0) + goto CCONVERR; } - if (!err) { + if (!err) longjmp(error_ret, SJ3_NoMoreDictData); - } - } + } ptr += strlen(ptr) + 1; q += l + 1; *q = *ptr; @@ -1224,44 +1268,41 @@ exec_nextdict (int mb_flag) } else { ptr = kbuf; } - + put_int(SJ3_NormalEnd); ptr = put_string(ptr); ptr = put_string(ptr); put_int(*ptr); - } - else + } else { longjmp(error_ret, SJ3_NoMoreDictData); + } return; CCONVERR: - put_int(SJ3_CannotCodeConvert); - return; + put_int(SJ3_CannotCodeConvert); + return; } - - void -exec_prevdict (int mb_flag) +exec_prevdict(int mb_flag) { - TypeDicID dicid; - int err, buf_size, l; + TypeDicID dicid; + int buf_size, err, l; DICTL *dl; Uchar *ptr, *q; - dicid = get_int(); - if (!work_base) longjmp(error_ret, SJ3_NotConnected); - - - for (dl = dictlist ; dl ; dl = dl -> next) - if (dl -> dict -> dicid == dicid) break; - if (!dl) longjmp(error_ret, SJ3_NoSuchDict); + if (!work_base) + longjmp(error_ret, SJ3_NotConnected); + for (dl = dictlist; dl; dl = dl->next) + if (dl->dict->dicid == dicid) + break; + if (!dl) + longjmp(error_ret, SJ3_NoSuchDict); lock_check_for_read(); - seldict(dicid); err = prevusr(kbuf); if (err) { @@ -1269,38 +1310,42 @@ exec_prevdict (int mb_flag) buf_size = sizeof(skbuf); ptr = kbuf; q = skbuf; - l = sj3_str_euctosjis(q, buf_size, ptr, - cur_cli->def_char, &defuse); - if (l < 0) goto CCONVERR; + l = sj3_str_euctosjis(q, buf_size, ptr, + cur_cli->def_char, &defuse); + if (l < 0) + goto CCONVERR; ptr += strlen(ptr) + 1; q += l + 1; buf_size -= l + 1; - l = sj3_str_euctosjis(q, buf_size, ptr, - cur_cli->def_char, &defuse2); - if (l < 0) goto CCONVERR; + l = sj3_str_euctosjis(q, buf_size, ptr, + cur_cli->def_char, &defuse2); + if (l < 0) + goto CCONVERR; if (defuse || defuse2) { while ((defuse || defuse2) && err) { ptr = kbuf; q = skbuf; buf_size = sizeof(skbuf); err = prevusr(kbuf); - if (!err) break; - l = sj3_str_euctosjis(q, buf_size, ptr, - cur_cli->def_char, - &defuse); - if (l < 0) goto CCONVERR; + if (!err) + break; + l = sj3_str_euctosjis(q, buf_size, ptr, + cur_cli->def_char, + &defuse); + if (l < 0) + goto CCONVERR; ptr += strlen(ptr) + 1; q += l + 1; buf_size -= l + 1; - l = sj3_str_euctosjis(q, buf_size, ptr, - cur_cli->def_char, - &defuse2); - if (l < 0) goto CCONVERR; + l = sj3_str_euctosjis(q, buf_size, ptr, + cur_cli->def_char, + &defuse2); + if (l < 0) + goto CCONVERR; } - if (!err) { + if (!err) longjmp(error_ret, SJ3_NoMoreDictData); - } - } + } ptr += strlen(ptr) + 1; q += l + 1; *q = *ptr; @@ -1308,107 +1353,99 @@ exec_prevdict (int mb_flag) } else { ptr = kbuf; } - + put_int(SJ3_NormalEnd); ptr = put_string(ptr); ptr = put_string(ptr); put_int(*ptr); - } - else + } else { longjmp(error_ret, SJ3_NoMoreDictData); + } return; CCONVERR: - put_int(SJ3_CannotCodeConvert); - return; + put_int(SJ3_CannotCodeConvert); + return; } - - void -exec_makedict (void) +exec_makedict(void) { - struct stat sbuf; - char path[PathNameLen]; - int err; - int ofslen; - int idxlen; - int seglen; - int segnum; + struct stat sbuf; + char path[PathNameLen]; + int err, idxlen, ofslen, seglen, segnum; err = get_nstring(path, sizeof(path)); idxlen = get_int(); seglen = get_int(); segnum = get_int(); - if (err) longjmp(error_ret, SJ3_TooLongParameter); - if (make_full_path(path)) longjmp(error_ret, SJ3_TooLongParameter); + if (err) + longjmp(error_ret, SJ3_TooLongParameter); + if (make_full_path(path)) + longjmp(error_ret, SJ3_TooLongParameter); - if ((stat(path, &sbuf) != ERROR) || (errno != ENOENT)){ + if ((stat(path, &sbuf) != ERROR) || (errno != ENOENT)) longjmp(error_ret, SJ3_IllegalDictFile); - } err = makedict(path, idxlen, seglen, segnum); - if (err != SJ3_NormalEnd) longjmp(error_ret, err); + if (err != SJ3_NormalEnd) + longjmp(error_ret, err); chmod(path, (file_mode & MODE_MASK)); chown(path, cur_client->uid, -1); put_int(err); } - - void -exec_makestdy (void) +exec_makestdy(void) { - struct stat sbuf; - char path[PathNameLen]; - int err; - int stynum; - int clstep; - int cllen; + struct stat sbuf; + char path[PathNameLen]; + int cllen, clstep, err, stynum; err = get_nstring(path, sizeof(path)); stynum = get_int(); clstep = get_int(); cllen = get_int(); - if (err) longjmp(error_ret, SJ3_TooLongParameter); - if (make_full_path(path)) longjmp(error_ret, SJ3_TooLongParameter); + if (err) + longjmp(error_ret, SJ3_TooLongParameter); + if (make_full_path(path)) + longjmp(error_ret, SJ3_TooLongParameter); - if ((stat(path, &sbuf) != ERROR) || (errno != ENOENT)){ + if ((stat(path, &sbuf) != ERROR) || (errno != ENOENT)) longjmp(error_ret, SJ3_IllegalStdyFile); - } err = makestdy(path, stynum, clstep, cllen); - if (err != SJ3_NormalEnd) longjmp(error_ret, err); + if (err != SJ3_NormalEnd) + longjmp(error_ret, err); chmod(path, (file_mode & MODE_MASK)); chown(path, cur_client->uid, -1); put_int(err); } - - void -exec_access (void) +exec_access(void) { char path[PathNameLen]; - int mode; - int i; + int i, mode; i = get_nstring(path, sizeof(path)); mode = get_int(); - if (i) longjmp(error_ret, SJ3_TooLongParameter); - if (make_full_path(path)) longjmp(error_ret, SJ3_TooLongParameter); + if (i) + longjmp(error_ret, SJ3_TooLongParameter); + if (make_full_path(path)) + longjmp(error_ret, SJ3_TooLongParameter); put_int(access(path, mode)); } - - void -exec_makedir (void) +exec_makedir(void) { char path[PathNameLen]; int i; i = get_nstring(path, sizeof(path)); - if (i) longjmp(error_ret, SJ3_TooLongParameter); - if (make_full_path(path)) longjmp(error_ret, SJ3_TooLongParameter); + if (i) + longjmp(error_ret, SJ3_TooLongParameter); + if (make_full_path(path)) + longjmp(error_ret, SJ3_TooLongParameter); if (mkdir(path, dir_mode)) { if (errno == EEXIST) @@ -1421,12 +1458,10 @@ exec_makedir (void) put_int(SJ3_NormalEnd); } - - void -exec_who (void) +exec_who(void) { - int i; + int i; Client *cli; i = 0; @@ -1435,23 +1470,21 @@ exec_who (void) i++; cli = cli->next; } - if (i < client_num) { + if (i < client_num) put_int(i); - } else { + else put_int(client_num); - } - for (i = 0, cli = client ; (i < client_num) && cli ; i++, cli = cli->next) { - put_int(cli -> fd); - put_string(cli -> host); - put_string(cli -> user); - put_string(cli -> prog); + for (i = 0, cli = client; (i < client_num) && cli; + i++, cli = cli->next) { + put_int(cli->fd); + put_string(cli->host); + put_string(cli->user); + put_string(cli->prog); } } - - void -exec_kill (void) +exec_kill(void) { put_int(SJ3_NormalEnd); put_flush(); @@ -1459,23 +1492,20 @@ exec_kill (void) server_terminate(); } - - void -exec_quit (void) +exec_quit(void) { - if (client_num > 1) longjmp(error_ret, SJ3_UserConnected); + if (client_num > 1) + longjmp(error_ret, SJ3_UserConnected); exec_kill(); } - - void -exec_version (void) +exec_version(void) { - extern char *version_number, *time_stamp; - static char *Version = "version : "; - static char *TimeStamp = "times-stamp : "; + extern char *time_stamp, *version_number; + static char *Version = "version : "; + static char *TimeStamp = "times-stamp : "; put_int(SJ3_NormalEnd); put_ndata(Version, strlen(Version)); @@ -1485,105 +1515,109 @@ exec_version (void) put_string(NULL); } - - void -exec_dictpass (void) +exec_dictpass(void) { - TypeDicID dicid; - char buf[PasswdLen + 1]; - int err; + TypeDicID dicid; + char buf[PasswdLen + 1]; + int err; DICTL *dl; - dicid = get_int(); - err = get_nstring(buf, sizeof(buf)); + err = get_nstring(buf, sizeof(buf)); - if (!work_base) longjmp(error_ret, SJ3_NotConnected); - if (err) longjmp(error_ret, SJ3_TooLongPasswd); + if (!work_base) + longjmp(error_ret, SJ3_NotConnected); + if (err) + longjmp(error_ret, SJ3_TooLongPasswd); - - for (dl = dictlist ; dl ; dl = dl -> next) - if (dl -> dict -> dicid == dicid) break; - if (!dl) longjmp(error_ret, SJ3_NoSuchDict); + for (dl = dictlist; dl; dl = dl->next) + if (dl->dict->dicid == dicid) + break; + if (!dl) + longjmp(error_ret, SJ3_NoSuchDict); - if (set_dictpass(dl -> dict, buf)) longjmp(error_ret, serv_errno); + if (set_dictpass(dl->dict, buf)) + longjmp(error_ret, serv_errno); put_int(SJ3_NormalEnd); } - - void -exec_dictcmnt (void) +exec_dictcmnt(void) { - TypeDicID dicid; - char buf[CommentLength + 1]; - int err; + TypeDicID dicid; + char buf[CommentLength + 1]; + int err; DICTL *dl; - dicid = get_int(); - err = get_nstring(buf, sizeof(buf)); + err = get_nstring(buf, sizeof(buf)); - if (!work_base) longjmp(error_ret, SJ3_NotConnected); - if (err) longjmp(error_ret, SJ3_TooLongComment); + if (!work_base) + longjmp(error_ret, SJ3_NotConnected); + if (err) + longjmp(error_ret, SJ3_TooLongComment); - - for (dl = dictlist ; dl ; dl = dl -> next) - if (dl -> dict -> dicid == dicid) break; - if (!dl) longjmp(error_ret, SJ3_NoSuchDict); + for (dl = dictlist; dl; dl = dl->next) + if (dl->dict->dicid == dicid) + break; + if (!dl) + longjmp(error_ret, SJ3_NoSuchDict); - if (set_dictcmnt(dl -> dict, buf)) longjmp(error_ret, serv_errno); + if (set_dictcmnt(dl->dict, buf)) + longjmp(error_ret, serv_errno); put_int(SJ3_NormalEnd); } - - void -exec_stdypass (void) +exec_stdypass(void) { char buf[PasswdLen + 1]; int err; - - err = get_nstring(buf, sizeof(buf)); + err = get_nstring(buf, sizeof(buf)); - if (!work_base) longjmp(error_ret, SJ3_NotConnected); - if (!stdy_base) longjmp(error_ret, SJ3_StdyFileNotOpened); - if (err) longjmp(error_ret, SJ3_TooLongPasswd); + if (!work_base) + longjmp(error_ret, SJ3_NotConnected); + if (!stdy_base) + longjmp(error_ret, SJ3_StdyFileNotOpened); + if (err) + longjmp(error_ret, SJ3_TooLongPasswd); - if (set_stdypass(buf)) longjmp(error_ret, serv_errno); + if (set_stdypass(buf)) + longjmp(error_ret, serv_errno); put_int(SJ3_NormalEnd); } - - void -exec_stdycmnt (void) +exec_stdycmnt(void) { char buf[CommentLength + 1]; int err; - - err = get_nstring(buf, sizeof(buf)); + err = get_nstring(buf, sizeof(buf)); - if (!work_base) longjmp(error_ret, SJ3_NotConnected); - if (!stdy_base) longjmp(error_ret, SJ3_StdyFileNotOpened); - if (err) longjmp(error_ret, SJ3_TooLongComment); + if (!work_base) + longjmp(error_ret, SJ3_NotConnected); + if (!stdy_base) + longjmp(error_ret, SJ3_StdyFileNotOpened); + if (err) + longjmp(error_ret, SJ3_TooLongComment); - if (set_stdycmnt(buf)) longjmp(error_ret, serv_errno); + if (set_stdycmnt(buf)) + longjmp(error_ret, serv_errno); put_int(SJ3_NormalEnd); } - - void -exec_stdypara (void) +exec_stdypara(void) { - int stynum, clstep, cllen; + int cllen, clstep, stynum; - if (!work_base) longjmp(error_ret, SJ3_NotConnected); - if (!stdy_base) longjmp(error_ret, SJ3_StdyFileNotOpened); + if (!work_base) + longjmp(error_ret, SJ3_NotConnected); + if (!stdy_base) + longjmp(error_ret, SJ3_StdyFileNotOpened); get_stdysize(&stynum, &clstep, &cllen); put_int(SJ3_NormalEnd); @@ -1592,87 +1626,127 @@ exec_stdypara (void) put_int(cllen); } - - void -execute_cmd (void) +execute_cmd(void) { int i; if ((i = setjmp(error_ret)) != 0) { debug_out(1, "%d: error code = %d\r\n", client_fd, i); put_int(i); - } - else { + } else { cur_cli = cur_client; work_base = cur_cli->work ? &(cur_cli->work->global) : NULL; stdy_base = cur_cli->stdy ? &(cur_cli->stdy->stdy) : NULL; #define CASE(X) case (X): { int j=X; debug_out(1, "%d: %d\t", client_fd, j); } switch (i = get_int()) { + CASE(SJ3_CONNECT) exec_connect(); + break; + CASE(SJ3_DISCONNECT) exec_disconnect(); + break; - CASE(SJ3_CONNECT) exec_connect(); break; - CASE(SJ3_DISCONNECT) exec_disconnect(); break; + CASE(SJ3_OPENDICT) exec_opendict(); + break; + CASE(SJ3_CLOSEDICT) exec_closedict(); + break; - CASE(SJ3_OPENDICT) exec_opendict(); break; - CASE(SJ3_CLOSEDICT) exec_closedict(); break; + CASE(SJ3_OPENSTDY) exec_openstdy(); + break; + CASE(SJ3_CLOSESTDY) exec_closestdy(); + break; + CASE(SJ3_STDYSIZE) exec_stdysize(); + break; - CASE(SJ3_OPENSTDY) exec_openstdy(); break; - CASE(SJ3_CLOSESTDY) exec_closestdy(); break; - CASE(SJ3_STDYSIZE) exec_stdysize(); break; + CASE(SJ3_LOCK) exec_lock(); + break; + CASE(SJ3_UNLOCK) exec_unlock(); + break; - CASE(SJ3_LOCK) exec_lock(); break; - CASE(SJ3_UNLOCK) exec_unlock(); break; + CASE(SJ3_PH2KNJ) exec_ph2knj(SJIS_PROTO); + break; + CASE(SJ3_PH2KNJ_EUC) exec_ph2knj(EUC_PROTO); + break; - CASE(SJ3_PH2KNJ) exec_ph2knj(SJIS_PROTO); break; - CASE(SJ3_PH2KNJ_EUC) exec_ph2knj(EUC_PROTO); break; + CASE(SJ3_CL2KNJ) exec_cl2knj(SJIS_PROTO); + break; + CASE(SJ3_CL2KNJ_EUC) exec_cl2knj(EUC_PROTO); + break; + CASE(SJ3_NEXTCL) exec_nextcl(SJIS_PROTO); + break; + CASE(SJ3_NEXTCL_EUC) exec_nextcl(EUC_PROTO); + break; + CASE(SJ3_PREVCL) exec_prevcl(SJIS_PROTO); + break; + CASE(SJ3_PREVCL_EUC) exec_prevcl(EUC_PROTO); + break; + CASE(SJ3_CL2KNJ_CNT) exec_cl2knj_cnt(SJIS_PROTO); + break; + CASE(SJ3_CL2KNJ_CNT_EUC) exec_cl2knj_cnt(EUC_PROTO); + break; + CASE(SJ3_CL2KNJ_ALL) exec_cl2knj_all(SJIS_PROTO); + break; + CASE(SJ3_CL2KNJ_ALL_EUC) exec_cl2knj_all(EUC_PROTO); + break; - CASE(SJ3_CL2KNJ) exec_cl2knj(SJIS_PROTO); break; - CASE(SJ3_CL2KNJ_EUC) exec_cl2knj(EUC_PROTO); break; - CASE(SJ3_NEXTCL) exec_nextcl(SJIS_PROTO); break; - CASE(SJ3_NEXTCL_EUC) exec_nextcl(EUC_PROTO); break; - CASE(SJ3_PREVCL) exec_prevcl(SJIS_PROTO); break; - CASE(SJ3_PREVCL_EUC) exec_prevcl(EUC_PROTO); break; - CASE(SJ3_CL2KNJ_CNT) exec_cl2knj_cnt(SJIS_PROTO); break; - CASE(SJ3_CL2KNJ_CNT_EUC) exec_cl2knj_cnt(EUC_PROTO); - break; - CASE(SJ3_CL2KNJ_ALL) exec_cl2knj_all(SJIS_PROTO); break; - CASE(SJ3_CL2KNJ_ALL_EUC) exec_cl2knj_all(EUC_PROTO); - break; + CASE(SJ3_STUDY) exec_study(); + break; + CASE(SJ3_CLSTUDY) exec_clstudy(SJIS_PROTO); + break; + CASE(SJ3_CLSTUDY_EUC) exec_clstudy(EUC_PROTO); + break; - CASE(SJ3_STUDY) exec_study(); break; - CASE(SJ3_CLSTUDY) exec_clstudy(SJIS_PROTO); break; - CASE(SJ3_CLSTUDY_EUC) exec_clstudy(EUC_PROTO); break; + CASE(SJ3_ADDDICT) exec_adddict(SJIS_PROTO); + break; + CASE(SJ3_ADDDICT_EUC) exec_adddict(EUC_PROTO); + break; + CASE(SJ3_DELDICT) exec_deldict(SJIS_PROTO); + break; + CASE(SJ3_DELDICT_EUC) exec_deldict(EUC_PROTO); + break; - CASE(SJ3_ADDDICT) exec_adddict(SJIS_PROTO); break; - CASE(SJ3_ADDDICT_EUC) exec_adddict(EUC_PROTO); break; - CASE(SJ3_DELDICT) exec_deldict(SJIS_PROTO); break; - CASE(SJ3_DELDICT_EUC) exec_deldict(EUC_PROTO); break; + CASE(SJ3_GETDICT) exec_getdict(SJIS_PROTO); + break; + CASE(SJ3_GETDICT_EUC) exec_getdict(EUC_PROTO); + break; + CASE(SJ3_NEXTDICT) exec_nextdict(SJIS_PROTO); + break; + CASE(SJ3_NEXTDICT_EUC) exec_nextdict(EUC_PROTO); + break; + CASE(SJ3_PREVDICT) exec_prevdict(SJIS_PROTO); + break; + CASE(SJ3_PREVDICT_EUC) exec_prevdict(EUC_PROTO); + break; - CASE(SJ3_GETDICT) exec_getdict(SJIS_PROTO); break; - CASE(SJ3_GETDICT_EUC) exec_getdict(EUC_PROTO); break; - CASE(SJ3_NEXTDICT) exec_nextdict(SJIS_PROTO); break; - CASE(SJ3_NEXTDICT_EUC) exec_nextdict(EUC_PROTO); break; - CASE(SJ3_PREVDICT) exec_prevdict(SJIS_PROTO); break; - CASE(SJ3_PREVDICT_EUC) exec_prevdict(EUC_PROTO); break; + CASE(SJ3_MAKEDICT) exec_makedict(); + break; + CASE(SJ3_MAKESTDY) exec_makestdy(); + break; + CASE(SJ3_ACCESS) exec_access(); + break; + CASE(SJ3_MAKEDIR) exec_makedir(); + break; - CASE(SJ3_MAKEDICT) exec_makedict(); break; - CASE(SJ3_MAKESTDY) exec_makestdy(); break; - CASE(SJ3_ACCESS) exec_access(); break; - CASE(SJ3_MAKEDIR) exec_makedir(); break; + CASE(SJ3_WHO) exec_who(); + break; + CASE(SJ3_QUIT) exec_quit(); + break; + CASE(SJ3_KILL) exec_kill(); + break; + CASE(SJ3_VERSION) exec_version(); + break; - CASE(SJ3_WHO) exec_who(); break; - CASE(SJ3_QUIT) exec_quit(); break; - CASE(SJ3_KILL) exec_kill(); break; - CASE(SJ3_VERSION) exec_version(); break; - - CASE(SJ3_DICTPASS) exec_dictpass(); break; - CASE(SJ3_DICTCMNT) exec_dictcmnt(); break; - CASE(SJ3_STDYPASS) exec_stdypass(); break; - CASE(SJ3_STDYCMNT) exec_stdycmnt(); break; - default: warning_out("Illegal command"); - longjmp(error_ret, SJ3_IllegalCommand); - break; + CASE(SJ3_DICTPASS) exec_dictpass(); + break; + CASE(SJ3_DICTCMNT) exec_dictcmnt(); + break; + CASE(SJ3_STDYPASS) exec_stdypass(); + break; + CASE(SJ3_STDYCMNT) exec_stdycmnt(); + break; + default: warning_out("Illegal command"); + longjmp(error_ret, SJ3_IllegalCommand); + break; } #undef CASE debug_out(1, "cmd end\r\n"); diff --git a/sj3serv/main.c b/sj3serv/main.c index e61e516..b59f25f 100644 --- a/sj3serv/main.c +++ b/sj3serv/main.c @@ -1,8 +1,8 @@ /*- * SPDX-License-Identifier: MIT-open-group - * + * * 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 @@ -10,10 +10,10 @@ * 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. @@ -21,7 +21,7 @@ * 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 @@ -29,11 +29,7 @@ */ #include "sj_sysvdef.h" -#include -#include -#include -#include -#include + #include #include #include @@ -52,46 +48,37 @@ #define signal sigset #endif -extern int fork_flag; -extern char *lock_file; - - +extern int fork_flag; +extern char *lock_file; #ifdef LOCK_FILE - - int -make_lockfile (void) +make_lockfile(void) { int fd; fd = open(lock_file, O_CREAT | O_EXCL, 0600); - if (fd < 0) return ERROR; + if (fd < 0) + return ERROR; close(fd); return 0; } - int -erase_lockfile (void) +erase_lockfile(void) { return unlink(lock_file); } #endif static int -signal_handler (sig, code, scp) -int sig; -int code; -struct sigcontext *scp; +signal_handler(int sig, int code, struct sigcontext *scp) { warning_out("signal %d, code %d catched.", sig, code); } -static int terminate_handler(sig, code, scp) -int sig; -int code; -struct sigcontext *scp; +static int +terminate_handler(int sig, int code, struct sigcontext *scp) { close_socket(); sj_closeall(); @@ -102,7 +89,7 @@ struct sigcontext *scp; } void -server_terminate (void) +server_terminate(void) { close_socket(); sj_closeall(); @@ -112,10 +99,8 @@ server_terminate (void) exit(0); } - - -static void -exec_fork (void) +static void +exec_fork(void) { int tmp; @@ -123,11 +108,10 @@ exec_fork (void) if (tmp < 0) { fprintf(stderr, "Can't fork child process\r\n"); fflush(stderr); - } - else { + } else { signal(SIGCHLD, _exit); - signal(SIGHUP , SIG_IGN); - signal(SIGINT , SIG_IGN); + signal(SIGHUP, SIG_IGN); + signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); signal(SIGTSTP, SIG_IGN); signal(SIGTERM, _exit); @@ -136,30 +120,28 @@ exec_fork (void) } } - signal(SIGHUP, (void (*)())signal_handler); + signal(SIGHUP, (void (*)())signal_handler); - - signal(SIGINT, (void (*)())terminate_handler); + signal(SIGINT, (void (*)())terminate_handler); signal(SIGQUIT, (void (*)())signal_handler); signal(SIGTERM, (void (*)())terminate_handler); if (fork_flag) signal(SIGTSTP, SIG_IGN); } - - -static void -leave_tty (void) +static void +leave_tty(void) { int tmp; - tmp = open_error(); + tmp = open_error(); tmp |= open_log(); tmp |= open_debug(); kill(getppid(), SIGTERM); fclose(stdin); fclose(stdout); - if (!tmp) fclose(stderr); + if (!tmp) + fclose(stderr); if (fork_flag) { if ((tmp = open("/dev/tty", O_RDWR)) >= 0) { @@ -169,33 +151,33 @@ leave_tty (void) } } - - int -main (int argc, char **argv) +main(int argc, char **argv) { #ifndef __NetBSD__ if (setuid(geteuid())) { - fprintf(stderr, "error at setuid.\r\n"); exit(1); + fprintf(stderr, "error at setuid.\r\n"); + exit(1); } #endif - parse_arg(argc, argv); - read_runcmd(); - set_default(); + parse_arg(argc, argv); + read_runcmd(); + set_default(); #ifdef LOCK_FILE if (make_lockfile() == ERROR) { - fprintf(stderr, "Already running...\r\n"); exit(1); + fprintf(stderr, "Already running...\r\n"); + exit(1); } #endif - exec_fork(); + exec_fork(); socket_init(); open_socket(); - leave_tty(); + leave_tty(); preload_dict(); preopen_dict(); diff --git a/sj3serv/time_stamp.c b/sj3serv/time_stamp.c index 07b2269..71162c9 100644 --- a/sj3serv/time_stamp.c +++ b/sj3serv/time_stamp.c @@ -1,8 +1,8 @@ /*- * SPDX-License-Identifier: MIT-open-group - * + * * 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 @@ -10,10 +10,10 @@ * 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. @@ -21,17 +21,11 @@ * 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. */ - - - - - char *time_stamp = "Mon Mar 23 16:42:59 JST 1998"; - diff --git a/sj3serv/version.c b/sj3serv/version.c index c6556f7..0ec8bf6 100644 --- a/sj3serv/version.c +++ b/sj3serv/version.c @@ -1,8 +1,8 @@ /*- * SPDX-License-Identifier: MIT-open-group - * + * * 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 @@ -10,10 +10,10 @@ * 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. @@ -21,16 +21,11 @@ * 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. */ - - - - - char *version_number = "2.08C";