From e00547f41481b0f93d28272882d787e42153952a Mon Sep 17 00:00:00 2001 From: Masanori Ogino Date: Thu, 30 Nov 2023 08:48:00 +0900 Subject: [PATCH] sj3lib: KNF Formatter: knfmt 4.2.0 Signed-off-by: Masanori Ogino --- sj3lib/level1.c | 1159 ++++++++++++++++++++++++----------------------- sj3lib/sj.c | 686 ++++++++++++++++------------ sj3lib/sj3lib.h | 128 +++--- sj3lib/string.c | 298 ++++++------ 4 files changed, 1178 insertions(+), 1093 deletions(-) diff --git a/sj3lib/level1.c b/sj3lib/level1.c index d8b7f86..15e219f 100644 --- a/sj3lib/level1.c +++ b/sj3lib/level1.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 @@ -46,49 +46,49 @@ #include "sj3err.h" #include "sj3lib.h" -int sj3_error_number; -char *sj3_socket_name = SocketName; -char *sj3_port_name = PortName; -int sj3_port_number = PortNumber; +int sj3_error_number; +char *sj3_socket_name = SocketName; +char *sj3_port_name = PortName; +int sj3_port_number = PortNumber; #define BUFFER_SIZE BUFSIZ -static char *af_unix_str = "unix"; -static u_char putbuf[BUFFER_SIZE]; -static u_char getbuf[BUFFER_SIZE]; -static int putpos = 0; -static int getlen = 0; -static int getpos = 0; -static SJ3_CLIENT_ENV *cliptr; -static int server_fd = -1; +static char *af_unix_str = "unix"; +static u_char putbuf[BUFFER_SIZE]; +static u_char getbuf[BUFFER_SIZE]; +static int putpos = 0; +static int getlen = 0; +static int getpos = 0; +static SJ3_CLIENT_ENV *cliptr; +static int server_fd = -1; -static int sj3_timeout = 0; +static int sj3_timeout = 0; -static int INTLEN = sizeof(int); -static int CMDLEN = sizeof(int); -static int ReadErrorFlag = FALSE; +static int INTLEN = sizeof(int); +static int CMDLEN = sizeof(int); +static int ReadErrorFlag = FALSE; -#define client_init(p) { \ - cliptr = (p); \ - if ((server_fd = cliptr -> fd) == -1) { \ - sj3_error_number = SJ3_NotOpened; \ - return ERROR; \ - } \ +#define client_init(p) { \ + cliptr = (p); \ + if ((server_fd = cliptr -> fd) == -1) { \ + sj3_error_number = SJ3_NotOpened; \ + return ERROR; \ + } \ } static int put_flush(void) { - int i, j; + int i, j; u_char *p; - for (i = putpos, p = putbuf ; i > 0 ; i -= j, p += j) { - if ((j = write(server_fd, p, i)) <= 0) { - shutdown(server_fd, 2); - close(server_fd); - cliptr -> fd = server_fd = -1; - sj3_error_number = SJ3_ServerDown; - return(ERROR); - } + for (i = putpos, p = putbuf; i > 0; i -= j, p += j) { + if ((j = write(server_fd, p, i)) <= 0) { + shutdown(server_fd, 2); + close(server_fd); + cliptr->fd = server_fd = -1; + sj3_error_number = SJ3_ServerDown; + return (ERROR); + } } putpos = 0; @@ -120,84 +120,95 @@ put_int(int c) static void put_cmd(int cmd) { - ReadErrorFlag = FALSE; + ReadErrorFlag = FALSE; putpos = getlen = 0; put_int(cmd); } #define put_string put_ndata -static u_char* -put_ndata(u_char* p, int n) +static 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; } static int -put_over( - int buflen, - int n, - u_char* (*func1)(), u_char* str1, int len1, - u_char* (*func2)(), u_char* str2, int len2, - u_char* (*func3)(), u_char* str3, int len3, - u_char* (*func4)(), u_char* str4, int len4) +put_over(int buflen, + int n, + u_char *(*func1)(), u_char *str1, int len1, + u_char *(*func2)(), u_char *str2, int len2, + u_char *(*func3)(), u_char *str3, int len3, + u_char *(*func4)(), u_char *str4, int len4) { #define ARGNUM 4 - u_char *(*func[ARGNUM])(); - u_char *data[ARGNUM]; - int len[ARGNUM]; - int i; + u_char *(*func[ARGNUM])(); + u_char *data[ARGNUM]; + int len[ARGNUM]; + int i; - func[0] = func1; data[0] = str1; len[0] = len1; - func[1] = func2; data[1] = str2; len[1] = len2; - func[2] = func3; data[2] = str3; len[2] = len3; - func[3] = func4; data[3] = str4; len[3] = len4; + func[0] = func1; + data[0] = str1; + len[0] = len1; + func[1] = func2; + data[1] = str2; + len[1] = len2; + func[2] = func3; + data[2] = str3; + len[2] = len3; + func[3] = func4; + data[3] = str4; + len[3] = len4; - for(i = 0; i < n; i++) { - if (len[i] < buflen) { - (*func[i])(data[i], len[i]); - buflen -= len[i]; - } else { - while (len[i] > 0) { - data[i] = (*func[i])(data[i], (len[i] < buflen) ? len[i] : buflen); - if (put_flush() == ERROR) return ERROR; - len[i] -= buflen; - buflen = BUFFER_SIZE; - } - } - } - if ((buflen != BUFFER_SIZE) && (put_flush() == ERROR)) - return ERROR; + for (i = 0; i < n; i++) { + if (len[i] < buflen) { + (*func[i])(data[i], len[i]); + buflen -= len[i]; + } else { + while (len[i] > 0) { + data[i] = (*func[i])(data[i], + (len[i] < buflen) ? len[i] : buflen); + if (put_flush() == ERROR) + return ERROR; + len[i] -= buflen; + buflen = BUFFER_SIZE; + } + } + } + if ((buflen != BUFFER_SIZE) && (put_flush() == ERROR)) + return ERROR; - return 0; + return 0; } static int get_buffer(void) { - if (ReadErrorFlag) return ERROR; - getpos = getlen = 0; + if (ReadErrorFlag) + return ERROR; + getpos = getlen = 0; - getlen = read(server_fd, getbuf, sizeof(getbuf)); - if (getlen <=0) { - shutdown(server_fd, 2); - close(server_fd); - cliptr -> fd = server_fd = -1; - sj3_error_number = SJ3_ServerDown; - return ERROR; + getlen = read(server_fd, getbuf, sizeof(getbuf)); + if (getlen <= 0) { + shutdown(server_fd, 2); + close(server_fd); + cliptr->fd = server_fd = -1; + sj3_error_number = SJ3_ServerDown; + return ERROR; } - return getlen; + return getlen; } static u_char get_byte(void) { - if ((getpos >= getlen) && (get_buffer() == ERROR)) { - ReadErrorFlag = TRUE; - return 0; + if ((getpos >= getlen) && (get_buffer() == ERROR)) { + ReadErrorFlag = TRUE; + return 0; } - return(getbuf[getpos++] & 0xff); + return (getbuf[getpos++] & 0xff); } static int @@ -212,9 +223,9 @@ get_word(void) static int get_int(void) { - int i0; - int i1; - int i2; + int i0; + int i1; + int i2; i0 = get_byte(); i1 = get_byte(); @@ -222,8 +233,8 @@ get_int(void) return ((i0 << (8*3)) | (i1 << (8*2)) | (i2 << (8*1)) | get_byte()); } -static u_char* -get_string(u_char* p) +static u_char * +get_string(u_char *p) { int c; @@ -235,45 +246,52 @@ get_string(u_char* p) } static int -get_nstring(u_char* p, int n) +get_nstring(u_char *p, int n) { int c; c = get_byte(); while (c) { - if (n > 1) { *p++ = c; n--; } + if (n > 1) { + *p++ = c; + n--; + } c = get_byte(); } - if (n > 0) *p++ = 0; + if (n > 0) + *p++ = 0; return n; } -static u_char* -get_ndata(u_char* p, int n) +static u_char * +get_ndata(u_char *p, int n) { - while (n-- > 0) *p++ = get_byte(); + while (n-- > 0) + *p++ = get_byte(); return p; } static void skip_string(void) { - while (get_byte()) ; + while (get_byte()) + ; } static void skip_ndata(int n) { - while (n-- > 0) get_byte(); + while (n-- > 0) + get_byte(); } static int open_unix(void) { - int fd, len; - struct sockaddr_un sunix; + int fd, len; + struct sockaddr_un sunix; - sunix.sun_family = AF_UNIX; + sunix.sun_family = AF_UNIX; strcpy(sunix.sun_path, sj3_socket_name); if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == ERROR) { @@ -281,12 +299,12 @@ open_unix(void) return ERROR; } - len = strlen(sunix.sun_path)+sizeof(sunix.sun_family); + len = strlen(sunix.sun_path) + sizeof(sunix.sun_family); #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) len += sizeof(sunix.sun_len); #endif - if (connect(fd, (struct sockaddr *)&sunix, len) - == ERROR) { + if (connect(fd, (struct sockaddr *)&sunix, len) == + ERROR) { sj3_error_number = SJ3_ConnectSocket; return ERROR; } @@ -297,7 +315,7 @@ open_unix(void) void sj3_set_timeout(int timeout) { - sj3_timeout = timeout; + sj3_timeout = timeout; } static void @@ -306,13 +324,13 @@ connect_timeout(void) } static int -open_inet(char* host) +open_inet(char *host) { - struct hostent *hp; - struct servent *sp; - int port; - struct sockaddr_in sin; - int fd, ret; + struct hostent *hp; + struct servent *sp; + int port; + struct sockaddr_in sin; + int fd, ret; if (!(hp = gethostbyname(host))) { sj3_error_number = SJ3_GetHostByName; @@ -320,30 +338,30 @@ open_inet(char* host) } if ((sp = getservbyname(sj3_port_name, "tcp"))) - port = ntohs(sp -> s_port); + port = ntohs(sp->s_port); else port = sj3_port_number; - memset((char *)&sin, '\0',sizeof(sin)); - sin.sin_family = AF_INET; - sin.sin_port = htons(port); - memcpy(&sin.sin_addr, hp -> h_addr, hp -> h_length); + memset((char *)&sin, '\0', sizeof(sin)); + sin.sin_family = AF_INET; + sin.sin_port = htons(port); + memcpy(&sin.sin_addr, hp->h_addr, hp->h_length); if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == ERROR) { sj3_error_number = SJ3_OpenSocket; return ERROR; } - - if (sj3_timeout > 0) { - signal(SIGALRM, (void (*)())connect_timeout); - alarm(sj3_timeout); - } - ret = connect(fd, (struct sockaddr *)&sin, sizeof(sin)); - if (sj3_timeout > 0) { - alarm(0); - signal(SIGALRM, SIG_IGN); - } - if (ret == ERROR) { + + if (sj3_timeout > 0) { + signal(SIGALRM, (void (*)())connect_timeout); + alarm(sj3_timeout); + } + ret = connect(fd, (struct sockaddr *)&sin, sizeof(sin)); + if (sj3_timeout > 0) { + alarm(0); + signal(SIGALRM, SIG_IGN); + } + if (ret == ERROR) { sj3_error_number = SJ3_ConnectSocket; return ERROR; } @@ -351,65 +369,65 @@ open_inet(char* host) return fd; } - int -sj3_make_connection( - SJ3_CLIENT_ENV* client, - char* serv, - char* user, - char* prog) +sj3_make_connection(SJ3_CLIENT_ENV *client, char *serv, char *user, char *prog) { - char host[MAXHOSTNAMELEN]; - int tmp; - int hostlen, userlen, proglen, datalen, buflen; - int curlen; - char *curdata; + char host[MAXHOSTNAMELEN]; + int tmp; + int hostlen, userlen, proglen, datalen, buflen; + int curlen; + char *curdata; - client -> fd = -1; + client->fd = -1; - if (!serv || *serv == '\0' || !strcmp(serv, af_unix_str)) - { - if ((server_fd = open_unix()) == ERROR) return ERROR; + if (!serv || *serv == '\0' || !strcmp(serv, af_unix_str)) { + if ((server_fd = open_unix()) == ERROR) + return ERROR; strcpy(host, af_unix_str); - } - else { - if ((server_fd = open_inet(serv)) == ERROR) return ERROR; + } else { + if ((server_fd = open_inet(serv)) == ERROR) + return ERROR; gethostname(host, sizeof(host)); } - client -> fd = server_fd; + client->fd = server_fd; client_init(client); - hostlen = strlen(host) + 1; - userlen = strlen(user) + 1; - proglen = strlen(prog) + 1; - datalen = hostlen + userlen + proglen; + hostlen = strlen(host) + 1; + userlen = strlen(user) + 1; + proglen = strlen(prog) + 1; + datalen = hostlen + userlen + proglen; put_cmd(SJ3_CONNECT); put_int(SJ3SERV_VERSION_NO); - if (datalen <= (buflen = BUFFER_SIZE - CMDLEN - INTLEN)) { - put_string(host, hostlen); - put_string(user, userlen); - put_string(prog, proglen); - if (put_flush() == ERROR) return ERROR; + if (datalen <= (buflen = BUFFER_SIZE - CMDLEN - INTLEN)) { + put_string(host, hostlen); + put_string(user, userlen); + put_string(prog, proglen); + if (put_flush() == ERROR) + return ERROR; } else { - if (put_over(buflen, 3, put_string, host, hostlen, put_string, user, - userlen, put_string, prog, proglen, NULL, NULL, 0) == ERROR) - return ERROR; + if (put_over(buflen, 3, put_string, host, hostlen, put_string, + user, userlen, put_string, prog, proglen, NULL, NULL, 0) == + ERROR) + return ERROR; } - if ((tmp = get_int()) == SJ3_DifferentVersion) { - if (ReadErrorFlag) return ERROR; + if ((tmp = get_int()) == SJ3_DifferentVersion) { + if (ReadErrorFlag) + return ERROR; put_cmd(SJ3_CONNECT); put_int(1); if (datalen <= (buflen = BUFFER_SIZE - CMDLEN - INTLEN)) { put_string(host, hostlen); put_string(user, userlen); put_string(prog, proglen); - if (put_flush() == ERROR) return ERROR; + if (put_flush() == ERROR) + return ERROR; } else { - if (put_over(buflen, 3, put_string, host, hostlen, put_string, user, - userlen, put_string, prog, proglen, NULL, NULL, 0) == ERROR) - return ERROR; + if (put_over(buflen, 3, put_string, host, hostlen, + put_string, user, userlen, put_string, prog, + proglen, NULL, NULL, 0) == ERROR) + return ERROR; } if ((tmp = get_int())) { sj3_erase_connection(client); @@ -420,16 +438,18 @@ sj3_make_connection( sj3_erase_connection(client); sj3_error_number = tmp; return ERROR; - } - cliptr -> svr_version = ((tmp)? -tmp : 1); - cliptr -> cli_version = SJ3SERV_VERSION_NO; - cliptr -> default_char[0] = 0x81; - cliptr -> default_char[1] = 0x40; + } + cliptr->svr_version = ((tmp) ? -tmp : 1); + cliptr->cli_version = SJ3SERV_VERSION_NO; + cliptr->default_char[0] = 0x81; + cliptr->default_char[1] = 0x40; sj3_error_number = 0; - if (ReadErrorFlag) return ERROR; + if (ReadErrorFlag) + return ERROR; put_cmd(SJ3_STDYSIZE); - if (put_flush() == ERROR) return ERROR; + if (put_flush() == ERROR) + return ERROR; if ((tmp = get_int())) { sj3_erase_connection(client); @@ -437,139 +457,148 @@ sj3_make_connection( return ERROR; } - cliptr -> stdy_size = get_int(); - cliptr -> fd = server_fd; + cliptr->stdy_size = get_int(); + cliptr->fd = server_fd; - return ReadErrorFlag ? ERROR : 0; + return ReadErrorFlag ? ERROR : 0; } int -sj3_erase_connection(SJ3_CLIENT_ENV* client) +sj3_erase_connection(SJ3_CLIENT_ENV *client) { client_init(client); put_cmd(SJ3_DISCONNECT); - if (put_flush() == ERROR) return ERROR; + if (put_flush() == ERROR) + return ERROR; sj3_error_number = get_int(); close(server_fd); - cliptr -> fd = -1; - if (ReadErrorFlag) return ERROR; + cliptr->fd = -1; + if (ReadErrorFlag) + return ERROR; return sj3_error_number ? ERROR : 0; } - long -sj3_open_dictionary( - SJ3_CLIENT_ENV* client, - char* dictname, char* password) +sj3_open_dictionary(SJ3_CLIENT_ENV *client, + char *dictname, char *password) { - int res; - int dictlen, passlen; - int datalen, buflen; + int res; + int dictlen, passlen; + int datalen, buflen; client_init(client); - dictlen = strlen(dictname) + 1; - passlen = ((password) ? strlen(password) : 0) + 1; - datalen = dictlen + passlen; + dictlen = strlen(dictname) + 1; + passlen = ((password) ? strlen(password) : 0) + 1; + datalen = dictlen + passlen; put_cmd(SJ3_OPENDICT); - if (datalen < (buflen = BUFFER_SIZE - CMDLEN)) { - put_string(dictname, dictlen); - put_string(password, passlen); - if (put_flush() == ERROR) return ERROR; + if (datalen < (buflen = BUFFER_SIZE - CMDLEN)) { + put_string(dictname, dictlen); + put_string(password, passlen); + if (put_flush() == ERROR) + return ERROR; } else { - if (put_over(buflen, 2, put_string, dictname, dictlen, put_string, - password, passlen, NULL, NULL, 0, NULL, NULL, 0) == ERROR) - return ERROR; + if (put_over(buflen, 2, put_string, dictname, dictlen, + put_string, password, passlen, NULL, NULL, 0, NULL, NULL, + 0) == ERROR) + return ERROR; } - if ((sj3_error_number = get_int())) return 0; - res = get_int(); - return ReadErrorFlag ? ERROR : res; + if ((sj3_error_number = get_int())) + return 0; + res = get_int(); + return ReadErrorFlag ? ERROR : res; } int -sj3_close_dictionary(SJ3_CLIENT_ENV* client, long dicid) +sj3_close_dictionary(SJ3_CLIENT_ENV *client, long dicid) { client_init(client); put_cmd(SJ3_CLOSEDICT); put_int(dicid); - if (put_flush() == ERROR) return ERROR; + if (put_flush() == ERROR) + return ERROR; - if ((sj3_error_number = get_int())) return ERROR; - return ReadErrorFlag ? ERROR : 0; + if ((sj3_error_number = get_int())) + return ERROR; + return ReadErrorFlag ? ERROR : 0; } - int -sj3_open_study_file( - SJ3_CLIENT_ENV* client, - char* stdyname, char* password) +sj3_open_study_file(SJ3_CLIENT_ENV *client, char *stdyname, char *password) { - int stdylen, passlen; - int datalen, buflen; + int stdylen, passlen; + int datalen, buflen; client_init(client); - stdylen = strlen(stdyname) + 1; - passlen = strlen(password) + 1; - datalen = stdylen + passlen; + stdylen = strlen(stdyname) + 1; + passlen = strlen(password) + 1; + datalen = stdylen + passlen; put_cmd(SJ3_OPENSTDY); - if (datalen < (buflen = BUFFER_SIZE - CMDLEN)) { - put_string(stdyname, stdylen); - put_string(password, passlen); - if (put_flush() == ERROR) return ERROR; + if (datalen < (buflen = BUFFER_SIZE - CMDLEN)) { + put_string(stdyname, stdylen); + put_string(password, passlen); + if (put_flush() == ERROR) + return ERROR; } else { - if (put_over(buflen, 2, put_string, stdyname, stdylen, put_string, - password, passlen, NULL, NULL, 0, NULL, NULL, 0) == ERROR) - return ERROR; + if (put_over(buflen, 2, put_string, stdyname, stdylen, + put_string, password, passlen, NULL, NULL, 0, NULL, NULL, + 0) == ERROR) + return ERROR; } - if ((sj3_error_number = get_int())) return ERROR; - return ReadErrorFlag ? ERROR : 0; + if ((sj3_error_number = get_int())) + return ERROR; + return ReadErrorFlag ? ERROR : 0; } int -sj3_close_study_file(SJ3_CLIENT_ENV* client) +sj3_close_study_file(SJ3_CLIENT_ENV *client) { client_init(client); put_cmd(SJ3_CLOSESTDY); - if (put_flush() == ERROR) return ERROR; + if (put_flush() == ERROR) + return ERROR; - if ((sj3_error_number = get_int())) return ERROR; - return ReadErrorFlag ? ERROR : 0; + if ((sj3_error_number = get_int())) + return ERROR; + return ReadErrorFlag ? ERROR : 0; } - int -sj3_get_id_size(SJ3_CLIENT_ENV* client) +sj3_get_id_size(SJ3_CLIENT_ENV *client) { client_init(client); put_cmd(SJ3_STDYSIZE); - if (put_flush() == ERROR) return ERROR; + if (put_flush() == ERROR) + return ERROR; - if ((sj3_error_number = get_int())) return ERROR; - cliptr -> stdy_size = get_int(); - return ReadErrorFlag ? ERROR : cliptr -> stdy_size; + if ((sj3_error_number = get_int())) + return ERROR; + cliptr->stdy_size = get_int(); + return ReadErrorFlag ? ERROR : cliptr->stdy_size; } - int -sj3_lock_server(SJ3_CLIENT_ENV* client) +sj3_lock_server(SJ3_CLIENT_ENV *client) { client_init(client); put_cmd(SJ3_LOCK); - if (put_flush() == ERROR) return ERROR; + if (put_flush() == ERROR) + return ERROR; - if ((sj3_error_number = get_int())) return ERROR; - return ReadErrorFlag ? ERROR : 0; + if ((sj3_error_number = get_int())) + return ERROR; + return ReadErrorFlag ? ERROR : 0; } int @@ -578,67 +607,66 @@ sj3_unlock_server(SJ3_CLIENT_ENV *client) client_init(client); put_cmd(SJ3_UNLOCK); - if (put_flush() == ERROR) return ERROR; + if (put_flush() == ERROR) + return ERROR; - if ((sj3_error_number = get_int())) return ERROR; - return ReadErrorFlag ? ERROR : 0; + if ((sj3_error_number = get_int())) + return ERROR; + return ReadErrorFlag ? ERROR : 0; } - int -sj3_ikkatu_henkan( - SJ3_CLIENT_ENV* client, - u_char* src, - u_char* dst, - int dstsiz, - int mb_flag) +sj3_ikkatu_henkan(SJ3_CLIENT_ENV *client, u_char *src, u_char *dst, int dstsiz, + int mb_flag) { - int c; + int c; u_char *top; - int result; - int len; - int len1; - int stysiz; + int result; + int len; + int len1; + int stysiz; - int srclen; - int buflen; + int srclen; + int buflen; client_init(client); - srclen = strlen(src) + 1; + srclen = strlen(src) + 1; if (mb_flag == MBCODE_SJIS) - put_cmd(SJ3_PH2KNJ); + put_cmd(SJ3_PH2KNJ); else - put_cmd(SJ3_PH2KNJ_EUC); - if (srclen < (buflen = BUFFER_SIZE - CMDLEN)) { - put_string(src, srclen); - if (put_flush() == ERROR) return ERROR; + put_cmd(SJ3_PH2KNJ_EUC); + if (srclen < (buflen = BUFFER_SIZE - CMDLEN)) { + put_string(src, srclen); + if (put_flush() == ERROR) + return ERROR; } else { - if (put_over(buflen, 1, put_string, src, srclen, NULL, NULL, 0, - NULL, NULL, 0, NULL, NULL, 0) == ERROR) - return ERROR; + if (put_over(buflen, 1, put_string, src, srclen, NULL, NULL, 0, + NULL, NULL, 0, NULL, NULL, 0) == ERROR) + return ERROR; } - if ((sj3_error_number = get_int())) return ERROR; + if ((sj3_error_number = get_int())) + return ERROR; result = get_int(); - result = 0; - stysiz = cliptr -> stdy_size; - len1 = 1 + stysiz + 1 + 1; + stysiz = cliptr->stdy_size; + len1 = 1 + stysiz + 1 + 1; while ((c = get_byte())) { - - top = dst; - if (dstsiz < len1) goto error1; + top = dst; + if (dstsiz < len1) + goto error1; *dst++ = len = c; dst = get_ndata(dst, stysiz); dstsiz -= (stysiz + 1); while ((c = get_byte())) { - if (dstsiz-- < 3) goto error2; + if (dstsiz-- < 3) + goto error2; *dst++ = c; } *dst++ = 0; @@ -647,534 +675,502 @@ sj3_ikkatu_henkan( } *dst = 0; - return ReadErrorFlag ? ERROR : result; + return ReadErrorFlag ? ERROR : result; - error1: do { skip_ndata(stysiz); error2: - while (get_byte()) ; + while (get_byte()) + ; } while (get_byte()); *top = 0; - return ReadErrorFlag ? ERROR : result; + return ReadErrorFlag ? ERROR : result; } - int -sj3_bunsetu_henkan( - SJ3_CLIENT_ENV* client, - u_char* yomi, - int len, - u_char* kanji, - int mb_flag) +sj3_bunsetu_henkan(SJ3_CLIENT_ENV *client, u_char *yomi, int len, + u_char *kanji, int mb_flag) { int result; - int buflen; + int buflen; client_init(client); if (mb_flag == MBCODE_SJIS) - put_cmd(SJ3_CL2KNJ); + put_cmd(SJ3_CL2KNJ); else - put_cmd(SJ3_CL2KNJ_EUC); + put_cmd(SJ3_CL2KNJ_EUC); put_int(len); - if ((len + 1) <= (buflen = BUFFER_SIZE - CMDLEN - INTLEN)) { - put_ndata(yomi, len); - put_byte(0); - if (put_flush() == ERROR) return ERROR; + if ((len + 1) <= (buflen = BUFFER_SIZE - CMDLEN - INTLEN)) { + put_ndata(yomi, len); + put_byte(0); + if (put_flush() == ERROR) + return ERROR; } else { - - if (put_over(buflen, 2, put_ndata, yomi, len, put_ndata, NULL, 1, - NULL, NULL, 0, NULL, NULL, 0) == ERROR) - return ERROR; + if (put_over(buflen, 2, put_ndata, yomi, len, put_ndata, NULL, + 1, NULL, NULL, 0, NULL, NULL, 0) == ERROR) + return ERROR; } - if ((sj3_error_number = get_int())) return ERROR; + if ((sj3_error_number = get_int())) + return ERROR; result = get_int(); - get_string( get_ndata(kanji, cliptr -> stdy_size) ); - return ReadErrorFlag ? ERROR : result; + get_string(get_ndata(kanji, cliptr->stdy_size)); + return ReadErrorFlag ? ERROR : result; } int -sj3_bunsetu_jikouho( - SJ3_CLIENT_ENV* client, - u_char* kanji, - int mode, - int mb_flag) +sj3_bunsetu_jikouho(SJ3_CLIENT_ENV *client, u_char *kanji, int mode, + int mb_flag) { int result; client_init(client); if (mb_flag == MBCODE_SJIS) - put_cmd(SJ3_NEXTCL); + put_cmd(SJ3_NEXTCL); else - put_cmd(SJ3_NEXTCL_EUC); + put_cmd(SJ3_NEXTCL_EUC); put_int(mode); - if (put_flush() == ERROR) return ERROR; + if (put_flush() == ERROR) + return ERROR; - if ((sj3_error_number = get_int())) return ERROR; + if ((sj3_error_number = get_int())) + return ERROR; result = get_int(); - get_string( get_ndata(kanji, cliptr -> stdy_size) ); - return ReadErrorFlag ? ERROR : result; + get_string(get_ndata(kanji, cliptr->stdy_size)); + return ReadErrorFlag ? ERROR : result; } int -sj3_bunsetu_maekouho( - SJ3_CLIENT_ENV* client, - u_char* kanji, int mode, int mb_flag) +sj3_bunsetu_maekouho(SJ3_CLIENT_ENV *client, u_char *kanji, int mode, + int mb_flag) { int result; client_init(client); if (mb_flag == MBCODE_SJIS) - put_cmd(SJ3_PREVCL); + put_cmd(SJ3_PREVCL); else - put_cmd(SJ3_PREVCL_EUC); + put_cmd(SJ3_PREVCL_EUC); put_int(mode); - if (put_flush() == ERROR) return ERROR; + if (put_flush() == ERROR) + return ERROR; - if ((sj3_error_number = get_int())) return ERROR; + if ((sj3_error_number = get_int())) + return ERROR; result = get_int(); - get_string( get_ndata(kanji, cliptr -> stdy_size) ); - return ReadErrorFlag ? ERROR : result; + get_string(get_ndata(kanji, cliptr->stdy_size)); + return ReadErrorFlag ? ERROR : result; } - int -sj3_bunsetu_kouhosuu( - SJ3_CLIENT_ENV* client, - u_char* yomi, - int len, - int mb_flag) +sj3_bunsetu_kouhosuu(SJ3_CLIENT_ENV *client, u_char *yomi, int len, int mb_flag) { - int result; - int buflen; + int result; + int buflen; client_init(client); if (mb_flag == MBCODE_SJIS) - put_cmd(SJ3_CL2KNJ_CNT); + put_cmd(SJ3_CL2KNJ_CNT); else - put_cmd(SJ3_CL2KNJ_CNT_EUC); + put_cmd(SJ3_CL2KNJ_CNT_EUC); put_int(len); - if ((len + 1) <= (buflen = BUFFER_SIZE - CMDLEN - INTLEN)) { - put_ndata(yomi, len); - put_byte(0); - if (put_flush() == ERROR) return ERROR; + if ((len + 1) <= (buflen = BUFFER_SIZE - CMDLEN - INTLEN)) { + put_ndata(yomi, len); + put_byte(0); + if (put_flush() == ERROR) + return ERROR; } else { - - if (put_over(buflen, 2, put_ndata, yomi, len, put_ndata, NULL, 1, - NULL, NULL, 0, NULL, NULL, 0) == ERROR) - return ERROR; + if (put_over(buflen, 2, put_ndata, yomi, len, put_ndata, NULL, + 1, NULL, NULL, 0, NULL, NULL, 0) == ERROR) + return ERROR; } - if ((sj3_error_number = get_int())) return ERROR; + if ((sj3_error_number = get_int())) + return ERROR; result = get_int(); - return ReadErrorFlag ? ERROR : result; + return ReadErrorFlag ? ERROR : result; } int -sj3_bunsetu_zenkouho( - SJ3_CLIENT_ENV* client, - u_char* yomi, - int len, - SJ3_DOUON* douon, - int mb_flag) +sj3_bunsetu_zenkouho(SJ3_CLIENT_ENV *client, u_char *yomi, int len, + SJ3_DOUON *douon, int mb_flag) { int cnt = 0; - int buflen; + int buflen; client_init(client); if (mb_flag == MBCODE_SJIS) - put_cmd(SJ3_CL2KNJ_ALL); + put_cmd(SJ3_CL2KNJ_ALL); else - put_cmd(SJ3_CL2KNJ_ALL_EUC); + put_cmd(SJ3_CL2KNJ_ALL_EUC); put_int(len); - if ((len + 1) <= (buflen = BUFFER_SIZE - CMDLEN - INTLEN)) { - put_ndata(yomi, len); - put_byte(0); - if (put_flush() == ERROR) return ERROR; + if ((len + 1) <= (buflen = BUFFER_SIZE - CMDLEN - INTLEN)) { + put_ndata(yomi, len); + put_byte(0); + if (put_flush() == ERROR) + return ERROR; } else { - - if (put_over(buflen, 2, put_ndata, yomi, len, put_ndata, NULL, 1, - NULL, NULL, 0, NULL, NULL, 0) == ERROR) - return ERROR; + if (put_over(buflen, 2, put_ndata, yomi, len, put_ndata, NULL, + 1, NULL, NULL, 0, NULL, NULL, 0) == ERROR) + return ERROR; } - if ((sj3_error_number = get_int())) return ERROR; + if ((sj3_error_number = get_int())) + return ERROR; while (get_int()) { - get_ndata(&(douon -> dcid), cliptr -> stdy_size); - get_string(douon -> ddata); - douon -> dlen = strlen(douon -> ddata); + get_ndata(&(douon->dcid), cliptr->stdy_size); + get_string(douon->ddata); + douon->dlen = strlen(douon->ddata); douon++; cnt++; } - return ReadErrorFlag ? ERROR : cnt; + return ReadErrorFlag ? ERROR : cnt; } - int -sj3_tango_gakusyuu(SJ3_CLIENT_ENV* client, SJ3_STUDYREC* stdy) +sj3_tango_gakusyuu(SJ3_CLIENT_ENV *client, SJ3_STUDYREC *stdy) { - int buflen; + int buflen; client_init(client); - + put_cmd(SJ3_STUDY); - if (cliptr -> stdy_size <= (buflen = BUFFER_SIZE - CMDLEN)) { - put_ndata(stdy, cliptr -> stdy_size); - if (put_flush() == ERROR) return ERROR; + if (cliptr->stdy_size <= (buflen = BUFFER_SIZE - CMDLEN)) { + put_ndata(stdy, cliptr->stdy_size); + if (put_flush() == ERROR) + return ERROR; } else { - - if (put_over(buflen, 1, put_ndata, stdy, cliptr -> stdy_size, NULL, - NULL, 0, NULL, NULL, 0, NULL, NULL, 0) == ERROR) - return ERROR; + if (put_over(buflen, 1, put_ndata, stdy, cliptr->stdy_size, + NULL, NULL, 0, NULL, NULL, 0, NULL, NULL, 0) == ERROR) + return ERROR; } - - if ((sj3_error_number = get_int())) return ERROR; - return ReadErrorFlag ? ERROR : 0; + if ((sj3_error_number = get_int())) + return ERROR; + return ReadErrorFlag ? ERROR : 0; } int -sj3_bunsetu_gakusyuu( - SJ3_CLIENT_ENV* client, - u_char* yomi1, - u_char* yomi2, - SJ3_STUDYREC* stdy, - int mb_flag) +sj3_bunsetu_gakusyuu(SJ3_CLIENT_ENV *client, u_char *yomi1, u_char *yomi2, + SJ3_STUDYREC *stdy, int mb_flag) { - int yomilen1, yomilen2; - int datalen, buflen; + int yomilen1, yomilen2; + int datalen, buflen; client_init(client); - yomilen1 = strlen(yomi1) + 1; - yomilen2 = strlen(yomi2) + 1; - datalen = yomilen1 + yomilen2 + cliptr -> stdy_size; + yomilen1 = strlen(yomi1) + 1; + yomilen2 = strlen(yomi2) + 1; + datalen = yomilen1 + yomilen2 + cliptr->stdy_size; if (mb_flag == MBCODE_SJIS) - put_cmd(SJ3_CLSTUDY); + put_cmd(SJ3_CLSTUDY); else - put_cmd(SJ3_CLSTUDY_EUC); - if (datalen <= (buflen = BUFFER_SIZE - CMDLEN)) { - put_string(yomi1, yomilen1); - put_string(yomi2, yomilen2); - put_ndata(stdy, cliptr -> stdy_size); - if (put_flush() == ERROR) return ERROR; + put_cmd(SJ3_CLSTUDY_EUC); + if (datalen <= (buflen = BUFFER_SIZE - CMDLEN)) { + put_string(yomi1, yomilen1); + put_string(yomi2, yomilen2); + put_ndata(stdy, cliptr->stdy_size); + if (put_flush() == ERROR) + return ERROR; } else { - if (put_over(buflen, 3, put_string, yomi1, yomilen1, put_string, - yomi2, yomilen2, put_ndata, stdy, cliptr->stdy_size, - NULL, NULL, 0) == ERROR) - return ERROR; + if (put_over(buflen, 3, put_string, yomi1, yomilen1, put_string, + yomi2, yomilen2, put_ndata, stdy, cliptr->stdy_size, + NULL, NULL, 0) == ERROR) + return ERROR; } - if ((sj3_error_number = get_int())) return ERROR; - return ReadErrorFlag ? ERROR : 0; + if ((sj3_error_number = get_int())) + return ERROR; + return ReadErrorFlag ? ERROR : 0; } - int -sj3_tango_touroku( - SJ3_CLIENT_ENV* client, - long dicid, - u_char* yomi, - u_char* kanji, - int code, - int mb_flag) +sj3_tango_touroku(SJ3_CLIENT_ENV *client, long dicid, u_char *yomi, + u_char *kanji, int code, int mb_flag) { - int yomilen, kanjilen; - int datalen, buflen; + int yomilen, kanjilen; + int datalen, buflen; client_init(client); - yomilen = strlen(yomi) + 1; - kanjilen = strlen(kanji) + 1; - datalen = yomilen + kanjilen + INTLEN; + yomilen = strlen(yomi) + 1; + kanjilen = strlen(kanji) + 1; + datalen = yomilen + kanjilen + INTLEN; if (mb_flag == MBCODE_SJIS) - put_cmd(SJ3_ADDDICT); + put_cmd(SJ3_ADDDICT); else - put_cmd(SJ3_ADDDICT_EUC); + put_cmd(SJ3_ADDDICT_EUC); put_int(dicid); - if (datalen <= (buflen = BUFFER_SIZE - CMDLEN -INTLEN)) { - put_string(yomi, yomilen); - put_string(kanji, kanjilen); - put_int(code); - if (put_flush() == ERROR) return ERROR; + if (datalen <= (buflen = BUFFER_SIZE - CMDLEN - INTLEN)) { + put_string(yomi, yomilen); + put_string(kanji, kanjilen); + put_int(code); + if (put_flush() == ERROR) + return ERROR; } else { - if (put_over(buflen, 3, put_string, yomi, yomilen, put_string, kanji, - kanjilen, put_ndata, &code, INTLEN, NULL, NULL, 0) == ERROR) - return ERROR; + if (put_over(buflen, 3, put_string, yomi, yomilen, put_string, + kanji, kanjilen, put_ndata, &code, INTLEN, NULL, NULL, 0) == + ERROR) + return ERROR; } - if ((sj3_error_number = get_int())) return ERROR; - return ReadErrorFlag ? ERROR : 0; + if ((sj3_error_number = get_int())) + return ERROR; + return ReadErrorFlag ? ERROR : 0; } int -sj3_tango_sakujo( - SJ3_CLIENT_ENV* client, - long dicid, - u_char* yomi, - u_char* kanji, - int code, - int mb_flag) +sj3_tango_sakujo(SJ3_CLIENT_ENV *client, long dicid, u_char *yomi, + u_char *kanji, int code, int mb_flag) { - int yomilen, kanjilen; - int datalen, buflen; + int yomilen, kanjilen; + int datalen, buflen; client_init(client); - yomilen = strlen(yomi) + 1; - kanjilen = strlen(kanji) + 1; - datalen = yomilen + kanjilen + INTLEN; + yomilen = strlen(yomi) + 1; + kanjilen = strlen(kanji) + 1; + datalen = yomilen + kanjilen + INTLEN; if (mb_flag == MBCODE_SJIS) - put_cmd(SJ3_DELDICT); + put_cmd(SJ3_DELDICT); else - put_cmd(SJ3_DELDICT_EUC); + put_cmd(SJ3_DELDICT_EUC); put_int(dicid); - if (datalen <= (buflen = BUFFER_SIZE - CMDLEN -INTLEN)) { - put_string(yomi, yomilen); - put_string(kanji, kanjilen); - put_int(code); - if (put_flush() == ERROR) return ERROR; + if (datalen <= (buflen = BUFFER_SIZE - CMDLEN - INTLEN)) { + put_string(yomi, yomilen); + put_string(kanji, kanjilen); + put_int(code); + if (put_flush() == ERROR) + return ERROR; } else { - if (put_over(buflen, 3, put_string, yomi, yomilen, put_string, kanji, - kanjilen, put_ndata, &code, INTLEN, NULL, NULL, 0) == ERROR) - return ERROR; + if (put_over(buflen, 3, put_string, yomi, yomilen, put_string, + kanji, kanjilen, put_ndata, &code, INTLEN, NULL, NULL, 0) == + ERROR) + return ERROR; } - if ((sj3_error_number = get_int())) return ERROR; - return ReadErrorFlag ? ERROR : 0; + if ((sj3_error_number = get_int())) + return ERROR; + return ReadErrorFlag ? ERROR : 0; } - int -sj3_tango_syutoku( - SJ3_CLIENT_ENV* client, - int dicid, - u_char* buf, - int mb_flag) +sj3_tango_syutoku(SJ3_CLIENT_ENV *client, int dicid, u_char *buf, int mb_flag) { u_char *p; client_init(client); if (mb_flag == MBCODE_SJIS) - put_cmd(SJ3_GETDICT); + put_cmd(SJ3_GETDICT); else - put_cmd(SJ3_GETDICT_EUC); + put_cmd(SJ3_GETDICT_EUC); put_int(dicid); - if (put_flush() == ERROR) return ERROR; + if (put_flush() == ERROR) + return ERROR; - if ((sj3_error_number = get_int())) return ERROR; + if ((sj3_error_number = get_int())) + return ERROR; p = get_string(buf); p = get_string(p); *p = get_int(); - return ReadErrorFlag ? ERROR : 0; + return ReadErrorFlag ? ERROR : 0; } int -sj3_tango_jikouho( - SJ3_CLIENT_ENV* client, - int dicid, - u_char* buf, - int mb_flag) +sj3_tango_jikouho(SJ3_CLIENT_ENV *client, int dicid, u_char *buf, int mb_flag) { u_char *p; client_init(client); if (mb_flag == MBCODE_SJIS) - put_cmd(SJ3_NEXTDICT); + put_cmd(SJ3_NEXTDICT); else - put_cmd(SJ3_NEXTDICT_EUC); + put_cmd(SJ3_NEXTDICT_EUC); put_int(dicid); - if (put_flush() == ERROR) return ERROR; + if (put_flush() == ERROR) + return ERROR; - if ((sj3_error_number = get_int())) return ERROR; + if ((sj3_error_number = get_int())) + return ERROR; p = get_string(buf); p = get_string(p); *p = get_int(); - return ReadErrorFlag ? ERROR : 0; + return ReadErrorFlag ? ERROR : 0; } int -sj3_tango_maekouho( - SJ3_CLIENT_ENV* client, - int dicid, - u_char* buf, - int mb_flag) +sj3_tango_maekouho(SJ3_CLIENT_ENV *client, int dicid, u_char *buf, int mb_flag) { u_char *p; client_init(client); if (mb_flag == MBCODE_SJIS) - put_cmd(SJ3_PREVDICT); + put_cmd(SJ3_PREVDICT); else - put_cmd(SJ3_PREVDICT_EUC); + put_cmd(SJ3_PREVDICT_EUC); put_int(dicid); - if (put_flush() == ERROR) return ERROR; + if (put_flush() == ERROR) + return ERROR; - if ((sj3_error_number = get_int())) return ERROR; + if ((sj3_error_number = get_int())) + return ERROR; p = get_string(buf); p = get_string(p); *p = get_int(); - return ReadErrorFlag ? ERROR : 0; + return ReadErrorFlag ? ERROR : 0; } - int -sj3_make_dict_file( - SJ3_CLIENT_ENV* client, - char* path, - int idxlen, - int seglen, - int segnum) +sj3_make_dict_file(SJ3_CLIENT_ENV *client, char *path, int idxlen, int seglen, + int segnum) { - int pathlen; - int buflen, datalen; + int pathlen; + int buflen, datalen; client_init(client); - pathlen = strlen(path) + 1; - datalen = pathlen + INTLEN + INTLEN + INTLEN; + pathlen = strlen(path) + 1; + datalen = pathlen + INTLEN + INTLEN + INTLEN; put_cmd(SJ3_MAKEDICT); - if (datalen <= (buflen = BUFFER_SIZE - CMDLEN)) { - put_string(path, pathlen); - put_int(idxlen); - put_int(seglen); - put_int(segnum); - if (put_flush() == ERROR) return ERROR; + if (datalen <= (buflen = BUFFER_SIZE - CMDLEN)) { + put_string(path, pathlen); + put_int(idxlen); + put_int(seglen); + put_int(segnum); + if (put_flush() == ERROR) + return ERROR; } else { - if (put_over(buflen, 4, put_string, path, pathlen, put_ndata, - &idxlen, INTLEN, put_ndata, &seglen, INTLEN, - put_ndata, &segnum, 0) == ERROR) - return ERROR; + if (put_over(buflen, 4, put_string, path, pathlen, put_ndata, + &idxlen, INTLEN, put_ndata, &seglen, INTLEN, + put_ndata, &segnum, 0) == ERROR) + return ERROR; } - if ((sj3_error_number = get_int())) return ERROR; - return ReadErrorFlag ? ERROR : 0; + if ((sj3_error_number = get_int())) + return ERROR; + return ReadErrorFlag ? ERROR : 0; } - int -sj3_make_study_file( - SJ3_CLIENT_ENV* client, - char* path, - int stynum, - int clstep, - int cllen) +sj3_make_study_file(SJ3_CLIENT_ENV *client, char *path, int stynum, int clstep, + int cllen) { - int pathlen; - int buflen, datalen; + int pathlen; + int buflen, datalen; client_init(client); - pathlen = strlen(path) + 1; - datalen = pathlen + INTLEN + INTLEN + INTLEN; + pathlen = strlen(path) + 1; + datalen = pathlen + INTLEN + INTLEN + INTLEN; put_cmd(SJ3_MAKESTDY); - if (datalen <= (buflen = BUFFER_SIZE - CMDLEN)) { - put_string(path, pathlen); - put_int(stynum); - put_int(clstep); - put_int(cllen); - if (put_flush() == ERROR) return ERROR; + if (datalen <= (buflen = BUFFER_SIZE - CMDLEN)) { + put_string(path, pathlen); + put_int(stynum); + put_int(clstep); + put_int(cllen); + if (put_flush() == ERROR) + return ERROR; } else { - if (put_over(buflen, 4, put_string, path, pathlen, put_ndata, - &stynum, INTLEN, put_ndata, &clstep, INTLEN, - put_ndata, &cllen, 0) == ERROR) - return ERROR; + if (put_over(buflen, 4, put_string, path, pathlen, put_ndata, + &stynum, INTLEN, put_ndata, &clstep, INTLEN, + put_ndata, &cllen, 0) == ERROR) + return ERROR; } - if ((sj3_error_number = get_int())) return ERROR; - return ReadErrorFlag ? ERROR : 0; + if ((sj3_error_number = get_int())) + return ERROR; + return ReadErrorFlag ? ERROR : 0; } - int -sj3_make_directory(SJ3_CLIENT_ENV* client, char* path) +sj3_make_directory(SJ3_CLIENT_ENV *client, char *path) { - int pathlen; - int buflen; + int pathlen; + int buflen; client_init(client); - pathlen = strlen(path) + 1; + pathlen = strlen(path) + 1; put_cmd(SJ3_MAKEDIR); - if (pathlen <= (buflen = BUFFER_SIZE - CMDLEN)) { - put_string(path, pathlen); - if (put_flush() == ERROR) return ERROR; + if (pathlen <= (buflen = BUFFER_SIZE - CMDLEN)) { + put_string(path, pathlen); + if (put_flush() == ERROR) + return ERROR; } else { - if (put_over(buflen, 1, put_string, path, pathlen, NULL, NULL, 0, - NULL, NULL, 0, NULL, NULL, 0) == ERROR) - return ERROR; + if (put_over(buflen, 1, put_string, path, pathlen, NULL, NULL, + 0, NULL, NULL, 0, NULL, NULL, 0) == ERROR) + return ERROR; } - - if ((sj3_error_number = get_int())) return ERROR; - return ReadErrorFlag ? ERROR : 0; + if ((sj3_error_number = get_int())) + return ERROR; + return ReadErrorFlag ? ERROR : 0; } - int -sj3_access(SJ3_CLIENT_ENV* client, char* path, int mode) +sj3_access(SJ3_CLIENT_ENV *client, char *path, int mode) { - int result; - int pathlen; - int buflen, datalen; + int result; + int pathlen; + int buflen, datalen; client_init(client); - pathlen = strlen(path) + 1; - datalen = pathlen + INTLEN; + pathlen = strlen(path) + 1; + datalen = pathlen + INTLEN; put_cmd(SJ3_ACCESS); - if (datalen <= (buflen = BUFFER_SIZE - CMDLEN)) { - put_string(path, pathlen); - put_int(mode); - if (put_flush() == ERROR) return ERROR; + if (datalen <= (buflen = BUFFER_SIZE - CMDLEN)) { + put_string(path, pathlen); + put_int(mode); + if (put_flush() == ERROR) + return ERROR; } else { - if (put_over(buflen, 2, put_string, path, pathlen, put_ndata, - &mode, INTLEN, NULL, NULL, 0, NULL, NULL, 0) == ERROR) - return ERROR; + if (put_over(buflen, 2, put_string, path, pathlen, put_ndata, + &mode, INTLEN, NULL, NULL, 0, NULL, NULL, 0) == ERROR) + return ERROR; } sj3_error_number = 0; result = get_int(); - return ReadErrorFlag ? ERROR : result; + return ReadErrorFlag ? ERROR : result; } - int -sj3_who(SJ3_CLIENT_ENV* client, SJ3_WHO_STRUCT* ret, int num) +sj3_who(SJ3_CLIENT_ENV *client, SJ3_WHO_STRUCT *ret, int num) { int i, j; client_init(client); put_cmd(SJ3_WHO); - if (put_flush() == ERROR) return ERROR; + if (put_flush() == ERROR) + return ERROR; if ((i = get_int()) < 0) { sj3_error_number = SJ3_InternalError; @@ -1182,15 +1178,14 @@ sj3_who(SJ3_CLIENT_ENV* client, SJ3_WHO_STRUCT* ret, int num) } sj3_error_number = 0; - for (j = 0 ; j < i ; j++) { + for (j = 0; j < i; j++) { if (j < num) { - ret -> fd = get_int(); - get_nstring(ret -> hostname, SJ3_NAME_LENGTH); - get_nstring(ret -> username, SJ3_NAME_LENGTH); - get_nstring(ret -> progname, SJ3_NAME_LENGTH); + ret->fd = get_int(); + get_nstring(ret->hostname, SJ3_NAME_LENGTH); + get_nstring(ret->username, SJ3_NAME_LENGTH); + get_nstring(ret->progname, SJ3_NAME_LENGTH); ret++; - } - else { + } else { get_int(); skip_string(); skip_string(); @@ -1198,55 +1193,67 @@ sj3_who(SJ3_CLIENT_ENV* client, SJ3_WHO_STRUCT* ret, int num) } } - return ReadErrorFlag ? ERROR : ((i < num) ? i : num); + return ReadErrorFlag ? ERROR : ((i < num) ? i : num); } - int -sj3_quit(SJ3_CLIENT_ENV* client) +sj3_quit(SJ3_CLIENT_ENV *client) { client_init(client); put_cmd(SJ3_QUIT); - if (put_flush() == ERROR) return ERROR; + if (put_flush() == ERROR) + return ERROR; - if ((sj3_error_number = get_int())) return ERROR; - return ReadErrorFlag ? ERROR : 0; + if ((sj3_error_number = get_int())) + return ERROR; + return ReadErrorFlag ? ERROR : 0; } int -sj3_kill(SJ3_CLIENT_ENV* client) +sj3_kill(SJ3_CLIENT_ENV *client) { client_init(client); put_cmd(SJ3_KILL); - if (put_flush() == ERROR) return ERROR; + if (put_flush() == ERROR) + return ERROR; - if ((sj3_error_number = get_int())) return ERROR; - return ReadErrorFlag ? ERROR : 0; + if ((sj3_error_number = get_int())) + return ERROR; + return ReadErrorFlag ? ERROR : 0; } - int -sj3_version(SJ3_CLIENT_ENV* client, char* dst, int dstsiz) +sj3_version(SJ3_CLIENT_ENV *client, char *dst, int dstsiz) { int c; client_init(client); put_cmd(SJ3_VERSION); - if (put_flush() == ERROR) return ERROR; + if (put_flush() == ERROR) + return ERROR; sj3_error_number = get_int(); c = get_byte(); while (c) { while (c) { - if (dstsiz > 2) { *dst++ = c; dstsiz--; } + if (dstsiz > 2) { + *dst++ = c; + dstsiz--; + } c = get_byte(); } - if (dstsiz > 1) { *dst++ = 0; dstsiz--; } + if (dstsiz > 1) { + *dst++ = 0; + dstsiz--; + } c = get_byte(); } - if (dstsiz > 0) { *dst++ = 0; dstsiz--; } - return ReadErrorFlag ? ERROR : 0; + if (dstsiz > 0) { + *dst++ = 0; + dstsiz--; + } + return ReadErrorFlag ? ERROR : 0; } diff --git a/sj3lib/sj.c b/sj3lib/sj.c index bad4718..b759fed 100644 --- a/sj3lib/sj.c +++ b/sj3lib/sj.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 @@ -47,29 +47,30 @@ #include "sj_hinsi.h" #include "sj_string.h" -extern int sj3_error_number; +extern int sj3_error_number; + #define SYS_SJIS 0 #define SYS_EUC 1 #define SYS_NOTDEF -1 -static int _sys_code = SYS_NOTDEF; +static int _sys_code = SYS_NOTDEF; -char *sj3_user_dir = "user"; -static char *path_delimiter = "/"; -static SJ3_CLIENT_ENV client = { -1, 0 }; -static long mdicid = 0; -static long udicid = 0; -static int defuse = 0; -static long *dicid_list = NULL; -static int dicid_num = 0; +char *sj3_user_dir = "user"; +static char *path_delimiter = "/"; +static SJ3_CLIENT_ENV client = { -1, 0 }; +static long mdicid = 0; +static long udicid = 0; +static int defuse = 0; +static long *dicid_list = NULL; +static int dicid_num = 0; -static u_char buf1[YomiBufSize]; -static u_char buf2[YomiBufSize]; -static u_char kbuf[KanjiBufSize]; +static u_char buf1[YomiBufSize]; +static u_char buf2[YomiBufSize]; +static u_char kbuf[KanjiBufSize]; -static int +static int set_sys_code(void) { - char *loc; + char *loc; loc = setlocale(LC_CTYPE, NULL); if (strcmp(loc, "ja_JP.SJIS") == 0) @@ -79,39 +80,45 @@ set_sys_code(void) } static int -make_dirs(char* path) +make_dirs(char *path) { - char tmp[PathNameLen]; + char tmp[PathNameLen]; char *p; - int i; + int i; - for (p = path ; *p ; p++) { - if (*p != *path_delimiter) continue; + for (p = path; *p; p++) { + if (*p != *path_delimiter) + continue; strncpy(tmp, path, (i = p - path)); tmp[i] = '\0'; - if (sj3_access(&client, tmp, F_OK) != ERROR) continue; - if (sj3_error_number == SJ3_ServerDown) return ERROR; + if (sj3_access(&client, tmp, F_OK) != ERROR) + continue; + if (sj3_error_number == SJ3_ServerDown) + return ERROR; - if (sj3_make_directory(&client, tmp) == ERROR) return ERROR; + if (sj3_make_directory(&client, tmp) == ERROR) + return ERROR; } return 0; } - int -sj3_open(char* host, char* user) +sj3_open(char *host, char *user) { - char tmp[PathNameLen]; + char tmp[PathNameLen]; char *p; - int err = SJ3_NORMAL_END; + int err = SJ3_NORMAL_END; - if (client.fd != -1) return SJ3_ALREADY_CONNECTED; + if (client.fd != -1) + return SJ3_ALREADY_CONNECTED; sprintf(tmp, "%d.sj3lib", getpid()); if (sj3_make_connection(&client, host, user, tmp) == ERROR) { - if (sj3_error_number == SJ3_ServerDown) goto server_dead; - client.fd = -1; return SJ3_CONNECT_ERROR; + if (sj3_error_number == SJ3_ServerDown) + goto server_dead; + client.fd = -1; + return SJ3_CONNECT_ERROR; } if (client.stdy_size > SJ3_WORD_ID_SIZE) { @@ -121,7 +128,8 @@ sj3_open(char* host, char* user) mdicid = sj3_open_dictionary(&client, MainDictionary, NULL); if (mdicid == 0) { - if (sj3_error_number == SJ3_ServerDown) goto server_dead; + if (sj3_error_number == SJ3_ServerDown) + goto server_dead; err |= SJ3_CANNOT_OPEN_MDICT; } @@ -131,16 +139,19 @@ sj3_open(char* host, char* user) strcat(tmp, user); strcat(tmp, path_delimiter); if (make_dirs(tmp) == ERROR) { - if (sj3_error_number == SJ3_ServerDown) goto server_dead; + if (sj3_error_number == SJ3_ServerDown) + goto server_dead; return (err | SJ3_CANNOT_MAKE_UDIR); } - for (p = tmp ; *p ; p++) ; + for (p = tmp; *p; p++) + ; strcpy(p, UserDictionary); if (sj3_access(&client, tmp, F_OK) == ERROR) { - if (sj3_error_number == SJ3_ServerDown) goto server_dead; + if (sj3_error_number == SJ3_ServerDown) + goto server_dead; if (sj3_make_dict_file(&client, tmp, DefIdxLen, - DefSegLen, DefSegNum) == ERROR) { + DefSegLen, DefSegNum) == ERROR) { if (sj3_error_number == SJ3_ServerDown) goto server_dead; err |= SJ3_CANNOT_MAKE_UDICT; @@ -148,22 +159,25 @@ sj3_open(char* host, char* user) } udicid = sj3_open_dictionary(&client, tmp, ""); if (udicid == 0) { - if (sj3_error_number == SJ3_ServerDown) goto server_dead; + if (sj3_error_number == SJ3_ServerDown) + goto server_dead; err |= SJ3_CANNOT_OPEN_UDICT; } strcpy(p, StudyFile); if (sj3_access(&client, tmp, F_OK) == ERROR) { - if (sj3_error_number == SJ3_ServerDown) goto server_dead; + if (sj3_error_number == SJ3_ServerDown) + goto server_dead; if (sj3_make_study_file(&client, tmp, DefStyNum, DefClStep, - DefClLen) == ERROR) { + DefClLen) == ERROR) { if (sj3_error_number == SJ3_ServerDown) goto server_dead; err |= SJ3_CANNOT_MAKE_STUDY; } } if (sj3_open_study_file(&client, tmp, "") == ERROR) { - if (sj3_error_number == SJ3_ServerDown) goto server_dead; + if (sj3_error_number == SJ3_ServerDown) + goto server_dead; err |= SJ3_CANNOT_OPEN_STUDY; } @@ -174,24 +188,25 @@ server_dead: return SJ3_SERVER_DEAD; } - int -sj3_open_with_list( - char* host, char* user, int dicts_num, - char** dicts, int* error_num, int** error_index) +sj3_open_with_list(char *host, char *user, int dicts_num, char **dicts, + int *error_num, int **error_index) { - char tmp[PathNameLen]; + char tmp[PathNameLen]; char *p; - int err = SJ3_NORMAL_END; - int i, err_id_num = 0; - long *dict_idx = NULL; + int err = SJ3_NORMAL_END; + int i, err_id_num = 0; + long *dict_idx = NULL; - if (client.fd != -1) return SJ3_ALREADY_CONNECTED; + if (client.fd != -1) + return SJ3_ALREADY_CONNECTED; sprintf(tmp, "%d.sj3lib", getpid()); if (sj3_make_connection(&client, host, user, tmp) == ERROR) { - if (sj3_error_number == SJ3_ServerDown) goto server_dead; - client.fd = -1; return SJ3_CONNECT_ERROR; + if (sj3_error_number == SJ3_ServerDown) + goto server_dead; + client.fd = -1; + return SJ3_CONNECT_ERROR; } if (client.stdy_size > SJ3_WORD_ID_SIZE) { @@ -200,7 +215,8 @@ sj3_open_with_list( } if ((dicts_num > 0) && dicts) { - if (!(dict_idx = (long *)malloc(sizeof(long) * dicts_num * 2))) { + if (!(dict_idx = (long *)malloc(sizeof(long) * dicts_num * + 2))) { return SJ3_CONNECT_ERROR; } memset(dict_idx, 0, sizeof(long) * dicts_num * 2); @@ -208,9 +224,11 @@ sj3_open_with_list( dicid_list = dict_idx; err_id_num = 0; for (i = 0; i < dicts_num; i++) { - dict_idx[i] = sj3_open_dictionary(&client, dicts[i], NULL); + dict_idx[i] = sj3_open_dictionary(&client, dicts[i], + NULL); if (dict_idx[i] == 0) { - if (sj3_error_number == SJ3_ServerDown) goto server_dead; + if (sj3_error_number == SJ3_ServerDown) + goto server_dead; dict_idx[dicts_num + err_id_num] = i; err_id_num++; } else if (mdicid == 0) { @@ -219,11 +237,13 @@ sj3_open_with_list( } if (err_id_num == dicts_num) { - err |= SJ3_CANNOT_OPEN_MDICT; + err |= SJ3_CANNOT_OPEN_MDICT; mdicid = 0; } - if (error_num) *error_num = err_id_num; - if (error_index) *error_index = (int *) &(dict_idx[dicts_num]); + if (error_num) + *error_num = err_id_num; + if (error_index) + *error_index = (int *)&(dict_idx[dicts_num]); } strcpy(tmp, sj3_user_dir); @@ -232,16 +252,19 @@ sj3_open_with_list( strcat(tmp, user); strcat(tmp, path_delimiter); if (make_dirs(tmp) == ERROR) { - if (sj3_error_number == SJ3_ServerDown) goto server_dead; + if (sj3_error_number == SJ3_ServerDown) + goto server_dead; return (err | SJ3_CANNOT_MAKE_UDIR); } - for (p = tmp ; *p ; p++) ; + for (p = tmp; *p; p++) + ; strcpy(p, UserDictionary); if (sj3_access(&client, tmp, F_OK) == ERROR) { - if (sj3_error_number == SJ3_ServerDown) goto server_dead; + if (sj3_error_number == SJ3_ServerDown) + goto server_dead; if (sj3_make_dict_file(&client, tmp, DefIdxLen, - DefSegLen, DefSegNum) == ERROR) { + DefSegLen, DefSegNum) == ERROR) { if (sj3_error_number == SJ3_ServerDown) goto server_dead; err |= SJ3_CANNOT_MAKE_UDICT; @@ -250,22 +273,25 @@ sj3_open_with_list( udicid = sj3_open_dictionary(&client, tmp, ""); if (udicid == 0) { - if (sj3_error_number == SJ3_ServerDown) goto server_dead; + if (sj3_error_number == SJ3_ServerDown) + goto server_dead; err |= SJ3_CANNOT_OPEN_UDICT; } strcpy(p, StudyFile); if (sj3_access(&client, tmp, F_OK) == ERROR) { - if (sj3_error_number == SJ3_ServerDown) goto server_dead; + if (sj3_error_number == SJ3_ServerDown) + goto server_dead; if (sj3_make_study_file(&client, tmp, DefStyNum, DefClStep, - DefClLen) == ERROR) { + DefClLen) == ERROR) { if (sj3_error_number == SJ3_ServerDown) goto server_dead; err |= SJ3_CANNOT_MAKE_STUDY; } } if (sj3_open_study_file(&client, tmp, "") == ERROR) { - if (sj3_error_number == SJ3_ServerDown) goto server_dead; + if (sj3_error_number == SJ3_ServerDown) + goto server_dead; err |= SJ3_CANNOT_OPEN_STUDY; } @@ -275,28 +301,32 @@ server_dead: if (dict_idx) { free(dict_idx); dict_idx = NULL; - if (error_num) *error_num = 0; - if (error_index) *error_index = NULL; - } + if (error_num) + *error_num = 0; + if (error_index) + *error_index = NULL; + } mdicid = udicid = 0; return SJ3_SERVER_DEAD; } - int sj3_close(void) { int err = SJ3_NORMAL_END; - int i; + int i; - if (client.fd == -1) return SJ3_NOT_CONNECTED; + if (client.fd == -1) + return SJ3_NOT_CONNECTED; if (mdicid == 0) err |= SJ3_NOT_OPENED_MDICT; else if (dicid_list) { for (i = 0; i < dicid_num; i++) { - if (sj3_close_dictionary(&client, dicid_list[i]) == ERROR) { - if (sj3_error_number == SJ3_ServerDown) goto server_dead; + if (sj3_close_dictionary(&client, dicid_list[i]) == + ERROR) { + if (sj3_error_number == SJ3_ServerDown) + goto server_dead; err |= SJ3_CLOSE_MDICT_ERROR; } } @@ -304,7 +334,8 @@ sj3_close(void) dicid_list = NULL; dicid_num = 0; } else if (sj3_close_dictionary(&client, mdicid) == ERROR) { - if (sj3_error_number == SJ3_ServerDown) goto server_dead; + if (sj3_error_number == SJ3_ServerDown) + goto server_dead; err |= SJ3_CLOSE_MDICT_ERROR; } mdicid = 0; @@ -312,7 +343,8 @@ sj3_close(void) if (udicid == 0) err |= SJ3_NOT_OPENED_UDICT; else if (sj3_close_dictionary(&client, udicid) == ERROR) { - if (sj3_error_number == SJ3_ServerDown) goto server_dead; + if (sj3_error_number == SJ3_ServerDown) + goto server_dead; err |= SJ3_CLOSE_UDICT_ERROR; } udicid = 0; @@ -323,15 +355,18 @@ sj3_close(void) goto server_dead; case SJ3_StdyFileNotOpened: - err |= SJ3_NOT_OPENED_STUDY; break; + err |= SJ3_NOT_OPENED_STUDY; + break; default: - err |= SJ3_CLOSE_STUDY_ERROR; break; + err |= SJ3_CLOSE_STUDY_ERROR; + break; } } if (sj3_erase_connection(&client)) { - if (sj3_error_number == SJ3_ServerDown) goto server_dead; + if (sj3_error_number == SJ3_ServerDown) + goto server_dead; err |= SJ3_DISCONNECT_ERROR; } @@ -347,19 +382,20 @@ server_dead: return SJ3_SERVER_DEAD; } - int -sj3_getkan(u_char* yomi, SJ3_BUNSETU* bun, u_char* knj, int knjsiz) +sj3_getkan(u_char *yomi, SJ3_BUNSETU *bun, u_char *knj, int knjsiz) { u_char *src; - int buncnt = 0; - int len; - int stysiz = client.stdy_size; + int buncnt = 0; + int len; + int stysiz = client.stdy_size; - if ((len = strlen(yomi)) > SJ3_IKKATU_YOMI) return 0; + if ((len = strlen(yomi)) > SJ3_IKKATU_YOMI) + return 0; while (*yomi) { - len = sj3_ikkatu_henkan(&client, yomi, knj, knjsiz, MBCODE_SJIS); + len = sj3_ikkatu_henkan(&client, yomi, knj, knjsiz, + MBCODE_SJIS); if (len == ERROR) { if (client.fd < 0) { mdicid = udicid = 0; @@ -367,61 +403,63 @@ sj3_getkan(u_char* yomi, SJ3_BUNSETU* bun, u_char* knj, int knjsiz) } return 0; - } - else if (len == 0) + } else if (len == 0) break; src = knj; while (*src) { - bun -> srclen = *src++; - memcpy(&(bun -> dcid), src, stysiz); + bun->srclen = *src++; + memcpy(&(bun->dcid), src, stysiz); src += stysiz; - bun -> destlen = strlen(src); - bun -> srcstr = yomi; - bun -> deststr = knj; - while (*src) *knj++ = *src++; - knjsiz -= bun -> destlen; + bun->destlen = strlen(src); + bun->srcstr = yomi; + bun->deststr = knj; + while (*src) + *knj++ = *src++; + knjsiz -= bun->destlen; src++; - yomi += bun -> srclen; + yomi += bun->srclen; bun++; buncnt++; - } + } *knj = 0; } if (*yomi) { - bun -> srclen = strlen(yomi); - bun -> srcstr = yomi; - bun -> destlen = 0; - bun -> deststr = NULL; - memset(&(bun -> dcid), '\0', sizeof(bun -> dcid)); + bun->srclen = strlen(yomi); + bun->srcstr = yomi; + bun->destlen = 0; + bun->deststr = NULL; + memset(&(bun->dcid), '\0', sizeof(bun->dcid)); buncnt++; } return buncnt; } - int -sj3_getkan_euc(u_char* yomi, SJ3_BUNSETU* bun, u_char* knj, int knjsiz) +sj3_getkan_euc(u_char *yomi, SJ3_BUNSETU *bun, u_char *knj, int knjsiz) { - u_char *src, *yp, *kp, *khp; - int buncnt = 0, i; - int len, flag, mflag = 0; - int stysiz = client.stdy_size; - int sentou, saigo; - int knjorg = knjsiz; + u_char *src, *yp, *kp, *khp; + int buncnt = 0, i; + int len, flag, mflag = 0; + int stysiz = client.stdy_size; + int sentou, saigo; + int knjorg = knjsiz; SJ3_BUNSETU *hbun = bun; - if ((len = strlen(yomi)) > SJ3_IKKATU_YOMI) return 0; + if ((len = strlen(yomi)) > SJ3_IKKATU_YOMI) + return 0; if (client.svr_version == 1) { defuse = 0; - len = sj3_str_euctosjis(buf1, sizeof(buf1), yomi, client.default_char, &defuse); - if ((len < 0) || defuse) return 0; + len = sj3_str_euctosjis(buf1, sizeof(buf1), yomi, + client.default_char, &defuse); + if ((len < 0) || defuse) + return 0; yp = buf1; if (knjsiz > sizeof(kbuf)) { mflag = 1; - kp = khp = (u_char *) malloc(knjsiz); + kp = khp = (u_char *)malloc(knjsiz); } else { kp = khp = kbuf; } @@ -441,51 +479,54 @@ sj3_getkan_euc(u_char* yomi, SJ3_BUNSETU* bun, u_char* knj, int knjsiz) } return 0; - } - else if (len == 0) + } else if (len == 0) break; src = kp; while (*src) { - bun -> srclen = *src++; - memcpy(&(bun -> dcid), src, stysiz); + bun->srclen = *src++; + memcpy(&(bun->dcid), src, stysiz); src += stysiz; - bun -> destlen = strlen(src); - bun -> srcstr = yp; - bun -> deststr = kp; - while (*src) *kp++ = *src++; - knjsiz -= bun -> destlen; + bun->destlen = strlen(src); + bun->srcstr = yp; + bun->deststr = kp; + while (*src) + *kp++ = *src++; + knjsiz -= bun->destlen; src++; - yp += bun -> srclen; + yp += bun->srclen; bun++; buncnt++; - } + } *kp = 0; } if (*yp) { - bun -> srclen = strlen(yp); - bun -> srcstr = yp; - bun -> destlen = 0; - bun -> deststr = NULL; - memset(&(bun -> dcid), '\0', sizeof(bun -> dcid)); + bun->srclen = strlen(yp); + bun->srcstr = yp; + bun->destlen = 0; + bun->deststr = NULL; + memset(&(bun->dcid), '\0', sizeof(bun->dcid)); buncnt++; } - + if (client.svr_version == 1) { kp = khp; yp = buf1; bun = hbun; defuse = 0; - len = sj3_str_sjistoeuc(knj, knjorg, kp, client.default_char, &defuse); - if ((len < 0) || defuse) return 0; - for(i = 0; i < buncnt; i++) { + len = sj3_str_sjistoeuc(knj, knjorg, kp, client.default_char, + &defuse); + if ((len < 0) || defuse) + return 0; + for (i = 0; i < buncnt; i++) { sentou = sj3_sjistoeuclen(yp, bun[i].srcstr - yp); - saigo = sj3_sjistoeuclen(bun[i].srcstr, bun[i].srclen); + saigo = sj3_sjistoeuclen(bun[i].srcstr, bun[i].srclen); bun[i].srclen = saigo; bun[i].srcstr = yomi + sentou; sentou = sj3_sjistoeuclen(kp, bun[i].deststr - kp); - saigo = sj3_sjistoeuclen(bun[i].deststr, bun[i].destlen); + saigo = sj3_sjistoeuclen(bun[i].deststr, + bun[i].destlen); bun[i].destlen = saigo; bun[i].deststr = knj + sentou; } @@ -498,25 +539,24 @@ sj3_getkan_euc(u_char* yomi, SJ3_BUNSETU* bun, u_char* knj, int knjsiz) return buncnt; } - int -sj3_getkan_mb(u_char* yomi, SJ3_BUNSETU* bun, u_char* knj, int knjsiz) +sj3_getkan_mb(u_char *yomi, SJ3_BUNSETU *bun, u_char *knj, int knjsiz) { if (_sys_code == SYS_NOTDEF) _sys_code = set_sys_code(); if (_sys_code == SYS_EUC) - return sj3_getkan_euc(yomi, bun, knj, knjsiz); + return sj3_getkan_euc(yomi, bun, knj, knjsiz); else - return sj3_getkan(yomi, bun, knj, knjsiz); + return sj3_getkan(yomi, bun, knj, knjsiz); } - int -sj3_douoncnt(u_char* yomi) +sj3_douoncnt(u_char *yomi) { int i; - if ((i = strlen(yomi)) > SJ3_BUNSETU_YOMI) return 0; + if ((i = strlen(yomi)) > SJ3_BUNSETU_YOMI) + return 0; i = sj3_bunsetu_kouhosuu(&client, yomi, i, MBCODE_SJIS); if (i == ERROR) { @@ -531,19 +571,21 @@ sj3_douoncnt(u_char* yomi) return i; } - int -sj3_douoncnt_euc(u_char* yomi) +sj3_douoncnt_euc(u_char *yomi) { - int i, l, flag; - u_char *yp; + int i, l, flag; + u_char *yp; - if ((i = strlen(yomi)) > SJ3_BUNSETU_YOMI) return 0; + if ((i = strlen(yomi)) > SJ3_BUNSETU_YOMI) + return 0; if (client.svr_version == 1) { defuse = 0; - l = sj3_str_euctosjis(buf1, sizeof(buf1), yomi, client.default_char, &defuse); - if ((l < 0) || defuse) return 0; + l = sj3_str_euctosjis(buf1, sizeof(buf1), yomi, + client.default_char, &defuse); + if ((l < 0) || defuse) + return 0; yp = buf1; flag = MBCODE_SJIS; } else { @@ -563,25 +605,24 @@ sj3_douoncnt_euc(u_char* yomi) return i; } - int -sj3_douoncnt_mb(u_char* yomi) +sj3_douoncnt_mb(u_char *yomi) { if (_sys_code == SYS_NOTDEF) _sys_code = set_sys_code(); - if (_sys_code == SYS_EUC) - return sj3_douoncnt_euc(yomi); + if (_sys_code == SYS_EUC) + return sj3_douoncnt_euc(yomi); else - return sj3_douoncnt(yomi); + return sj3_douoncnt(yomi); } - int -sj3_getdouon(u_char* yomi, SJ3_DOUON* dou) +sj3_getdouon(u_char *yomi, SJ3_DOUON *dou) { int i; - if ((i = strlen(yomi)) > SJ3_BUNSETU_YOMI) return 0; + if ((i = strlen(yomi)) > SJ3_BUNSETU_YOMI) + return 0; i = sj3_bunsetu_zenkouho(&client, yomi, i, dou, MBCODE_SJIS); if (i == ERROR) { @@ -595,18 +636,20 @@ sj3_getdouon(u_char* yomi, SJ3_DOUON* dou) return i; } - int -sj3_getdouon_euc(u_char* yomi, SJ3_DOUON* dou) +sj3_getdouon_euc(u_char *yomi, SJ3_DOUON *dou) { int i, j, l; - if ((i = strlen(yomi)) > SJ3_BUNSETU_YOMI) return 0; - + if ((i = strlen(yomi)) > SJ3_BUNSETU_YOMI) + return 0; + if (client.svr_version == 1) { defuse = 0; - l = sj3_str_euctosjis(buf1, sizeof(buf1), yomi, client.default_char, &defuse); - if ((l < 0) || defuse) return 0; + l = sj3_str_euctosjis(buf1, sizeof(buf1), yomi, + client.default_char, &defuse); + if ((l < 0) || defuse) + return 0; i = sj3_bunsetu_zenkouho(&client, buf1, i, dou, MBCODE_SJIS); if (i == ERROR) { if (client.fd < 0) { @@ -617,10 +660,11 @@ sj3_getdouon_euc(u_char* yomi, SJ3_DOUON* dou) } for (j = 0; j < i; j++) { defuse = 0; - l = sj3_str_sjistoeuc(kbuf, sizeof(kbuf), - dou[j].ddata, client.default_char, &defuse); - if ((l < 0) || defuse) return 0; - (void)memcpy(dou[j].ddata, kbuf, l+1); + l = sj3_str_sjistoeuc(kbuf, sizeof(kbuf), + dou[j].ddata, client.default_char, &defuse); + if ((l < 0) || defuse) + return 0; + (void)memcpy(dou[j].ddata, kbuf, l + 1); dou[j].dlen = l; } } else { @@ -636,21 +680,19 @@ sj3_getdouon_euc(u_char* yomi, SJ3_DOUON* dou) return i; } - int -sj3_getdouon_mb(u_char* yomi, SJ3_DOUON* dou) +sj3_getdouon_mb(u_char *yomi, SJ3_DOUON *dou) { if (_sys_code == SYS_NOTDEF) _sys_code = set_sys_code(); if (_sys_code == SYS_EUC) - return sj3_getdouon_euc(yomi, dou); + return sj3_getdouon_euc(yomi, dou); else - return sj3_getdouon(yomi, dou); + return sj3_getdouon(yomi, dou); } - int -sj3_gakusyuu(SJ3_STUDYREC* dcid) +sj3_gakusyuu(SJ3_STUDYREC *dcid) { if (sj3_tango_gakusyuu(&client, dcid) == ERROR) { if (client.fd < 0) { @@ -662,11 +704,11 @@ sj3_gakusyuu(SJ3_STUDYREC* dcid) return 0; } - int -sj3_gakusyuu2(u_char* yomi1, u_char* yomi2, SJ3_STUDYREC* dcid) +sj3_gakusyuu2(u_char *yomi1, u_char *yomi2, SJ3_STUDYREC *dcid) { - if (sj3_bunsetu_gakusyuu(&client, yomi1, yomi2, dcid, MBCODE_SJIS) == ERROR) { + if (sj3_bunsetu_gakusyuu(&client, yomi1, yomi2, dcid, MBCODE_SJIS) == + ERROR) { if (client.fd < 0) { mdicid = udicid = 0; return -1; @@ -676,22 +718,25 @@ sj3_gakusyuu2(u_char* yomi1, u_char* yomi2, SJ3_STUDYREC* dcid) return 0; } - int -sj3_gakusyuu2_euc(u_char* yomi1, u_char* yomi2, SJ3_STUDYREC* dcid) +sj3_gakusyuu2_euc(u_char *yomi1, u_char *yomi2, SJ3_STUDYREC *dcid) { - int l, flag; - u_char *y1p, *y2p; + int l, flag; + u_char *y1p, *y2p; if (client.svr_version == 1) { defuse = 0; - l = sj3_str_euctosjis(buf1, sizeof(buf1), yomi1, client.default_char, &defuse); - if ((l < 0) || defuse) return 1; + l = sj3_str_euctosjis(buf1, sizeof(buf1), yomi1, + client.default_char, &defuse); + if ((l < 0) || defuse) + return 1; defuse = 0; - l = sj3_str_euctosjis(buf2, sizeof(buf2), yomi2, client.default_char, &defuse); - if ((l < 0) || defuse) return 1; + l = sj3_str_euctosjis(buf2, sizeof(buf2), yomi2, + client.default_char, &defuse); + if ((l < 0) || defuse) + return 1; y1p = buf1; - y2p = buf2; + y2p = buf2; flag = MBCODE_SJIS; } else { y1p = yomi1; @@ -708,59 +753,72 @@ sj3_gakusyuu2_euc(u_char* yomi1, u_char* yomi2, SJ3_STUDYREC* dcid) return 0; } - int -sj3_gakusyuu2_mb(u_char* yomi1, u_char* yomi2, SJ3_STUDYREC* dcid) +sj3_gakusyuu2_mb(u_char *yomi1, u_char *yomi2, SJ3_STUDYREC *dcid) { if (_sys_code == SYS_NOTDEF) _sys_code = set_sys_code(); if (_sys_code == SYS_EUC) - return sj3_gakusyuu2_euc(yomi1, yomi2, dcid); + return sj3_gakusyuu2_euc(yomi1, yomi2, dcid); else - return sj3_gakusyuu2(yomi1, yomi2, dcid); + return sj3_gakusyuu2(yomi1, yomi2, dcid); } - int -sj3_touroku(u_char* yomi, u_char* kanji, int code) +sj3_touroku(u_char *yomi, u_char *kanji, int code) { - if (sj3_tango_touroku(&client, udicid, yomi, kanji, code, MBCODE_SJIS)) { + if (sj3_tango_touroku(&client, udicid, yomi, kanji, code, + MBCODE_SJIS)) { if (client.fd < 0) { mdicid = udicid = 0; return -1; } switch (sj3_error_number) { case SJ3_NoSuchDict: - case SJ3_ReadOnlyDict: return SJ3_DICT_ERROR; - case SJ3_DictLocked: return SJ3_DICT_LOCKED; - case SJ3_BadYomiString: return SJ3_BAD_YOMI_STR; - case SJ3_BadKanjiString: return SJ3_BAD_KANJI_STR; - case SJ3_BadHinsiCode: return SJ3_BAD_HINSI_CODE; - case SJ3_AlreadyExistWord: return SJ3_WORD_EXIST; - case SJ3_NoMoreDouonWord: return SJ3_DOUON_FULL; - case SJ3_NoMoreUserDict: return SJ3_DICT_FULL; - case SJ3_NoMoreIndexBlock: return SJ3_INDEX_FULL; - default: return SJ3_TOUROKU_FAILED; + case SJ3_ReadOnlyDict: + return SJ3_DICT_ERROR; + case SJ3_DictLocked: + return SJ3_DICT_LOCKED; + case SJ3_BadYomiString: + return SJ3_BAD_YOMI_STR; + case SJ3_BadKanjiString: + return SJ3_BAD_KANJI_STR; + case SJ3_BadHinsiCode: + return SJ3_BAD_HINSI_CODE; + case SJ3_AlreadyExistWord: + return SJ3_WORD_EXIST; + case SJ3_NoMoreDouonWord: + return SJ3_DOUON_FULL; + case SJ3_NoMoreUserDict: + return SJ3_DICT_FULL; + case SJ3_NoMoreIndexBlock: + return SJ3_INDEX_FULL; + default: + return SJ3_TOUROKU_FAILED; } } return 0; } - int -sj3_touroku_euc(u_char* yomi, u_char* kanji, int code) +sj3_touroku_euc(u_char *yomi, u_char *kanji, int code) { - int l, flag; - u_char *yp; - u_char *kp; + int l, flag; + u_char *yp; + u_char *kp; + if (client.svr_version == 1) { defuse = 0; - l = sj3_str_euctosjis(buf1, sizeof(buf1), yomi, client.default_char, &defuse); - if ((l < 0) || defuse) return SJ3_BAD_YOMI_STR; + l = sj3_str_euctosjis(buf1, sizeof(buf1), yomi, + client.default_char, &defuse); + if ((l < 0) || defuse) + return SJ3_BAD_YOMI_STR; defuse = 0; - l = sj3_str_euctosjis(kbuf, sizeof(kbuf), kanji, client.default_char, &defuse); - if ((l < 0) || defuse) return SJ3_BAD_KANJI_STR; + l = sj3_str_euctosjis(kbuf, sizeof(kbuf), kanji, + client.default_char, &defuse); + if ((l < 0) || defuse) + return SJ3_BAD_KANJI_STR; yp = buf1; kp = kbuf; flag = MBCODE_SJIS; @@ -776,37 +834,45 @@ sj3_touroku_euc(u_char* yomi, u_char* kanji, int code) } switch (sj3_error_number) { case SJ3_NoSuchDict: - case SJ3_ReadOnlyDict: return SJ3_DICT_ERROR; - case SJ3_DictLocked: return SJ3_DICT_LOCKED; - case SJ3_BadYomiString: return SJ3_BAD_YOMI_STR; - case SJ3_BadKanjiString: return SJ3_BAD_KANJI_STR; - case SJ3_BadHinsiCode: return SJ3_BAD_HINSI_CODE; - case SJ3_AlreadyExistWord: return SJ3_WORD_EXIST; - case SJ3_NoMoreDouonWord: return SJ3_DOUON_FULL; - case SJ3_NoMoreUserDict: return SJ3_DICT_FULL; - case SJ3_NoMoreIndexBlock: return SJ3_INDEX_FULL; - default: return SJ3_TOUROKU_FAILED; + case SJ3_ReadOnlyDict: + return SJ3_DICT_ERROR; + case SJ3_DictLocked: + return SJ3_DICT_LOCKED; + case SJ3_BadYomiString: + return SJ3_BAD_YOMI_STR; + case SJ3_BadKanjiString: + return SJ3_BAD_KANJI_STR; + case SJ3_BadHinsiCode: + return SJ3_BAD_HINSI_CODE; + case SJ3_AlreadyExistWord: + return SJ3_WORD_EXIST; + case SJ3_NoMoreDouonWord: + return SJ3_DOUON_FULL; + case SJ3_NoMoreUserDict: + return SJ3_DICT_FULL; + case SJ3_NoMoreIndexBlock: + return SJ3_INDEX_FULL; + default: + return SJ3_TOUROKU_FAILED; } } return 0; } - int -sj3_touroku_mb(u_char* yomi, u_char* kanji, int code) +sj3_touroku_mb(u_char *yomi, u_char *kanji, int code) { if (_sys_code == SYS_NOTDEF) _sys_code = set_sys_code(); if (_sys_code == SYS_EUC) - return sj3_touroku_euc(yomi, kanji, code); + return sj3_touroku_euc(yomi, kanji, code); else - return sj3_touroku(yomi, kanji, code); + return sj3_touroku(yomi, kanji, code); } - int -sj3_syoukyo(u_char* yomi, u_char* kanji, int code) +sj3_syoukyo(u_char *yomi, u_char *kanji, int code) { if (sj3_tango_sakujo(&client, udicid, yomi, kanji, code, MBCODE_SJIS)) { if (client.fd < 0) { @@ -814,33 +880,44 @@ sj3_syoukyo(u_char* yomi, u_char* kanji, int code) return -1; } switch (sj3_error_number) { - case SJ3_NoSuchDict: - case SJ3_ReadOnlyDict: return SJ3_DICT_ERROR; - case SJ3_DictLocked: return SJ3_DICT_LOCKED; - case SJ3_BadYomiString: return SJ3_BAD_YOMI_STR; - case SJ3_BadKanjiString: return SJ3_BAD_KANJI_STR; - case SJ3_BadHinsiCode: return SJ3_BAD_HINSI_CODE; - case SJ3_NoSuchWord: return SJ3_WORD_NOT_EXIST; - default: return SJ3_SYOUKYO_FAILED; + case SJ3_NoSuchDict: + case SJ3_ReadOnlyDict: + return SJ3_DICT_ERROR; + case SJ3_DictLocked: + return SJ3_DICT_LOCKED; + case SJ3_BadYomiString: + return SJ3_BAD_YOMI_STR; + case SJ3_BadKanjiString: + return SJ3_BAD_KANJI_STR; + case SJ3_BadHinsiCode: + return SJ3_BAD_HINSI_CODE; + case SJ3_NoSuchWord: + return SJ3_WORD_NOT_EXIST; + default: + return SJ3_SYOUKYO_FAILED; } } return 0; } - int -sj3_syoukyo_euc(u_char* yomi, u_char* kanji, int code) +sj3_syoukyo_euc(u_char *yomi, u_char *kanji, int code) { - int l, flag; - u_char *yp; - u_char *kp; + int l, flag; + u_char *yp; + u_char *kp; + if (client.svr_version == 1) { defuse = 0; - l = sj3_str_euctosjis(buf1, sizeof(buf1), yomi, client.default_char, &defuse); - if ((l < 0) || defuse) return SJ3_BAD_YOMI_STR; + l = sj3_str_euctosjis(buf1, sizeof(buf1), yomi, + client.default_char, &defuse); + if ((l < 0) || defuse) + return SJ3_BAD_YOMI_STR; defuse = 0; - l = sj3_str_euctosjis(kbuf, sizeof(kbuf), kanji, client.default_char, &defuse); - if ((l < 0) || defuse) return SJ3_BAD_KANJI_STR; + l = sj3_str_euctosjis(kbuf, sizeof(kbuf), kanji, + client.default_char, &defuse); + if ((l < 0) || defuse) + return SJ3_BAD_KANJI_STR; yp = buf1; kp = kbuf; flag = MBCODE_SJIS; @@ -855,34 +932,39 @@ sj3_syoukyo_euc(u_char* yomi, u_char* kanji, int code) return -1; } switch (sj3_error_number) { - case SJ3_NoSuchDict: - case SJ3_ReadOnlyDict: return SJ3_DICT_ERROR; - case SJ3_DictLocked: return SJ3_DICT_LOCKED; - case SJ3_BadYomiString: return SJ3_BAD_YOMI_STR; - case SJ3_BadKanjiString: return SJ3_BAD_KANJI_STR; - case SJ3_BadHinsiCode: return SJ3_BAD_HINSI_CODE; - case SJ3_NoSuchWord: return SJ3_WORD_NOT_EXIST; - default: return SJ3_SYOUKYO_FAILED; + case SJ3_NoSuchDict: + case SJ3_ReadOnlyDict: + return SJ3_DICT_ERROR; + case SJ3_DictLocked: + return SJ3_DICT_LOCKED; + case SJ3_BadYomiString: + return SJ3_BAD_YOMI_STR; + case SJ3_BadKanjiString: + return SJ3_BAD_KANJI_STR; + case SJ3_BadHinsiCode: + return SJ3_BAD_HINSI_CODE; + case SJ3_NoSuchWord: + return SJ3_WORD_NOT_EXIST; + default: + return SJ3_SYOUKYO_FAILED; } } return 0; } - int -sj3_syoukyo_mb(u_char* yomi, u_char* kanji, int code) +sj3_syoukyo_mb(u_char *yomi, u_char *kanji, int code) { if (_sys_code == SYS_NOTDEF) _sys_code = set_sys_code(); if (_sys_code == SYS_EUC) - return sj3_syoukyo_euc(yomi, kanji, code); + return sj3_syoukyo_euc(yomi, kanji, code); else - return sj3_syoukyo(yomi, kanji, code); + return sj3_syoukyo(yomi, kanji, code); } - int -sj3_getdict(u_char* buf) +sj3_getdict(u_char *buf) { if (sj3_tango_syutoku(&client, udicid, buf, MBCODE_SJIS)) { if (client.fd < 0) { @@ -894,11 +976,10 @@ sj3_getdict(u_char* buf) return 0; } - int -sj3_getdict_euc(u_char* buf) +sj3_getdict_euc(u_char *buf) { - int l, ll, slen; + int l, ll, slen; if (client.svr_version == 1) { if (sj3_tango_syutoku(&client, udicid, buf, MBCODE_SJIS)) { @@ -910,12 +991,15 @@ sj3_getdict_euc(u_char* buf) } defuse = 0; slen = strlen(buf) + 1; - l = sj3_str_sjistoeuc(kbuf, sizeof(kbuf), buf, client.default_char, &defuse); - if ((l < 0) || defuse) return 1; + l = sj3_str_sjistoeuc(kbuf, sizeof(kbuf), buf, + client.default_char, &defuse); + if ((l < 0) || defuse) + return 1; l++; - ll = sj3_str_sjistoeuc(&(kbuf[l]), sizeof(kbuf) - l, &(buf[slen]), - client.default_char, &defuse); - if ((ll < 0) || defuse) return 1; + ll = sj3_str_sjistoeuc(&(kbuf[l]), sizeof(kbuf) - l, + &(buf[slen]), client.default_char, &defuse); + if ((ll < 0) || defuse) + return 1; ll++; slen += strlen(&(buf[slen])) + 1; l = l + ll; @@ -934,20 +1018,19 @@ sj3_getdict_euc(u_char* buf) return 0; } - int -sj3_getdict_mb(u_char* buf) +sj3_getdict_mb(u_char *buf) { if (_sys_code == SYS_NOTDEF) _sys_code = set_sys_code(); if (_sys_code == SYS_EUC) - return sj3_getdict_euc(buf); + return sj3_getdict_euc(buf); else - return sj3_getdict(buf); + return sj3_getdict(buf); } int -sj3_nextdict(u_char* buf) +sj3_nextdict(u_char *buf) { if (sj3_tango_jikouho(&client, udicid, buf, MBCODE_SJIS)) { if (client.fd < 0) { @@ -959,11 +1042,10 @@ sj3_nextdict(u_char* buf) return 0; } - int -sj3_nextdict_euc(u_char* buf) +sj3_nextdict_euc(u_char *buf) { - int l, ll, slen; + int l, ll, slen; if (client.svr_version == 1) { if (sj3_tango_jikouho(&client, udicid, buf, MBCODE_SJIS)) { @@ -975,12 +1057,15 @@ sj3_nextdict_euc(u_char* buf) } defuse = 0; slen = strlen(buf) + 1; - l = sj3_str_sjistoeuc(kbuf, sizeof(kbuf), buf, client.default_char, &defuse); - if ((l < 0) || defuse) return 1; + l = sj3_str_sjistoeuc(kbuf, sizeof(kbuf), buf, + client.default_char, &defuse); + if ((l < 0) || defuse) + return 1; l++; - ll = sj3_str_sjistoeuc(&(kbuf[l]), sizeof(kbuf) - l, &(buf[slen]), - client.default_char, &defuse); - if ((ll < 0) || defuse) return 1; + ll = sj3_str_sjistoeuc(&(kbuf[l]), sizeof(kbuf) - l, + &(buf[slen]), client.default_char, &defuse); + if ((ll < 0) || defuse) + return 1; ll++; slen += strlen(&(buf[slen])) + 1; l = l + ll; @@ -999,20 +1084,19 @@ sj3_nextdict_euc(u_char* buf) return 0; } - int -sj3_nextdict_mb(u_char* buf) +sj3_nextdict_mb(u_char *buf) { if (_sys_code == SYS_NOTDEF) _sys_code = set_sys_code(); if (_sys_code == SYS_EUC) - return sj3_nextdict_euc(buf); + return sj3_nextdict_euc(buf); else - return sj3_nextdict(buf); + return sj3_nextdict(buf); } int -sj3_prevdict(u_char* buf) +sj3_prevdict(u_char *buf) { if (sj3_tango_maekouho(&client, udicid, buf, MBCODE_SJIS)) { if (client.fd < 0) { @@ -1024,11 +1108,10 @@ sj3_prevdict(u_char* buf) return 0; } - int -sj3_prevdict_euc(u_char* buf) +sj3_prevdict_euc(u_char *buf) { - int l, ll, slen; + int l, ll, slen; if (client.svr_version == 1) { if (sj3_tango_maekouho(&client, udicid, buf, MBCODE_SJIS)) { @@ -1040,12 +1123,15 @@ sj3_prevdict_euc(u_char* buf) } defuse = 0; slen = strlen(buf) + 1; - l = sj3_str_sjistoeuc(kbuf, sizeof(kbuf), buf, client.default_char, &defuse); - if ((l < 0) || defuse) return 1; + l = sj3_str_sjistoeuc(kbuf, sizeof(kbuf), buf, + client.default_char, &defuse); + if ((l < 0) || defuse) + return 1; l++; - ll = sj3_str_sjistoeuc(&(kbuf[l]), sizeof(kbuf) - l, &(buf[slen]), - client.default_char, &defuse); - if ((ll < 0) || defuse) return 1; + ll = sj3_str_sjistoeuc(&(kbuf[l]), sizeof(kbuf) - l, + &(buf[slen]), client.default_char, &defuse); + if ((ll < 0) || defuse) + return 1; ll++; slen += strlen(&(buf[slen])) + 1; l = l + ll; @@ -1064,16 +1150,15 @@ sj3_prevdict_euc(u_char* buf) return 0; } - int -sj3_prevdict_mb(u_char* buf) +sj3_prevdict_mb(u_char *buf) { if (_sys_code == SYS_NOTDEF) _sys_code = set_sys_code(); if (_sys_code == SYS_EUC) - return sj3_prevdict_euc(buf); + return sj3_prevdict_euc(buf); else - return sj3_prevdict(buf); + return sj3_prevdict(buf); } int @@ -1089,7 +1174,6 @@ sj3_lockserv(void) return 0; } - int sj3_unlockserv(void) { diff --git a/sj3lib/sj3lib.h b/sj3lib/sj3lib.h index 5002cc9..b5356cb 100644 --- a/sj3lib/sj3lib.h +++ b/sj3lib/sj3lib.h @@ -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,14 +21,13 @@ * 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. */ - #ifndef _SJ3LIB_H_ #define _SJ3LIB_H_ 1 @@ -37,8 +36,6 @@ #define SJ3_NORMAL_END 0 #define SJ3_SERVER_DEAD (1 << 0) - - #define SJ3_CONNECT_ERROR (1 << 1) #define SJ3_ALREADY_CONNECTED (1 << 2) #define SJ3_CANNOT_OPEN_MDICT (1 << 3) @@ -48,8 +45,6 @@ #define SJ3_CANNOT_MAKE_UDICT (1 << 7) #define SJ3_CANNOT_MAKE_STUDY (1 << 8) - - #define SJ3_DISCONNECT_ERROR (1 << 1) #define SJ3_NOT_CONNECTED (1 << 2) #define SJ3_NOT_OPENED_MDICT (1 << 3) @@ -59,8 +54,6 @@ #define SJ3_CLOSE_UDICT_ERROR (1 << 7) #define SJ3_CLOSE_STUDY_ERROR (1 << 8) - - #define SJ3_DICT_ERROR 1 #define SJ3_DICT_LOCKED 2 #define SJ3_BAD_YOMI_STR 3 @@ -76,49 +69,33 @@ #define SJ3_WORD_NOT_EXIST 6 #define SJ3_SYOUKYO_FAILED 10 - - - #define SJ3_IKKATU_YOMI 512 - - - #define SJ3_BUNSETU_YOMI 128 #define SJ3_BUNSETU_KANJI 512 - - - #ifndef SJ3_WORD_ID_SIZE # define SJ3_WORD_ID_SIZE 32 #endif -typedef struct studyrec { +typedef struct studyrec { unsigned char dummy[SJ3_WORD_ID_SIZE]; } SJ3_STUDYREC; - - - -typedef struct bunsetu { - int srclen; - int destlen; - unsigned char *srcstr; - unsigned char *deststr; - struct studyrec dcid; +typedef struct bunsetu { + int srclen; + int destlen; + unsigned char *srcstr; + unsigned char *deststr; + struct studyrec dcid; } SJ3_BUNSETU; - - -typedef struct douon { - unsigned char ddata[SJ3_BUNSETU_KANJI]; - int dlen; - SJ3_STUDYREC dcid; +typedef struct douon { + unsigned char ddata[SJ3_BUNSETU_KANJI]; + int dlen; + SJ3_STUDYREC dcid; } SJ3_DOUON; - - #define SJ3_H_NRMNOUN 1 #define SJ3_H_PRONOUN 12 #define SJ3_H_LNAME 21 @@ -148,62 +125,70 @@ typedef struct douon { #define SJ3_H_WAVERB 99 #define SJ3_H_SINGLE 189 - -/* moved from include/sj3lowlib.h for function prototypes. - * $SonyRCSfile: sj3lowlib.h,v $ - * $SonyRevision: 1.1 $ - * $SonyDate: 1994/06/03 08:00:59 $ - */ - -typedef struct sj3_client_env { - int fd; +typedef struct sj3_client_env { + int fd; int serv_dead_flg; - int stdy_size; - short svr_version; - short cli_version; - char default_char[2]; + int stdy_size; + short svr_version; + short cli_version; + char default_char[2]; } SJ3_CLIENT_ENV; #ifndef SJ3_NAME_LENGTH # define SJ3_NAME_LENGTH 128 #endif -typedef struct sj3_who_struct { +typedef struct sj3_who_struct { int fd; char hostname[SJ3_NAME_LENGTH]; char username[SJ3_NAME_LENGTH]; char progname[SJ3_NAME_LENGTH]; } SJ3_WHO_STRUCT; - #define MBCODE_SJIS 1 #define MBCODE_EUC 2 /* level1.c */ void sj3_set_timeout(int timeout); -int sj3_make_connection(SJ3_CLIENT_ENV *client, char *serv, char *user, char *prog); +int sj3_make_connection(SJ3_CLIENT_ENV *client, char *serv, char *user, + char *prog); int sj3_erase_connection(SJ3_CLIENT_ENV *client); -long sj3_open_dictionary(SJ3_CLIENT_ENV *client, char *dictname, char *password); +long sj3_open_dictionary(SJ3_CLIENT_ENV *client, char *dictname, + char *password); int sj3_close_dictionary(SJ3_CLIENT_ENV *client, long dicid); int sj3_open_study_file(SJ3_CLIENT_ENV *client, char *stdyname, char *password); int sj3_close_study_file(SJ3_CLIENT_ENV *client); int sj3_get_id_size(SJ3_CLIENT_ENV *client); int sj3_lock_server(SJ3_CLIENT_ENV *client); int sj3_unlock_server(SJ3_CLIENT_ENV *client); -int sj3_ikkatu_henkan(SJ3_CLIENT_ENV *client, u_char *src, u_char *dst, int dstsiz, int mb_flag); -int sj3_bunsetu_henkan(SJ3_CLIENT_ENV *client, u_char *yomi, int len, u_char *kanji, int mb_flag); -int sj3_bunsetu_jikouho(SJ3_CLIENT_ENV *client, u_char *kanji, int mode, int mb_flag); -int sj3_bunsetu_maekouho(SJ3_CLIENT_ENV *client, u_char *kanji, int mode, int mb_flag); -int sj3_bunsetu_kouhosuu(SJ3_CLIENT_ENV *client, u_char *yomi, int len, int mb_flag); -int sj3_bunsetu_zenkouho(SJ3_CLIENT_ENV *client, u_char *yomi, int len, SJ3_DOUON *douon, int mb_flag); +int sj3_ikkatu_henkan(SJ3_CLIENT_ENV *client, u_char *src, u_char *dst, + int dstsiz, int mb_flag); +int sj3_bunsetu_henkan(SJ3_CLIENT_ENV *client, u_char *yomi, int len, + u_char *kanji, int mb_flag); +int sj3_bunsetu_jikouho(SJ3_CLIENT_ENV *client, u_char *kanji, int mode, + int mb_flag); +int sj3_bunsetu_maekouho(SJ3_CLIENT_ENV *client, u_char *kanji, int mode, + int mb_flag); +int sj3_bunsetu_kouhosuu(SJ3_CLIENT_ENV *client, u_char *yomi, int len, + int mb_flag); +int sj3_bunsetu_zenkouho(SJ3_CLIENT_ENV *client, u_char *yomi, int len, + SJ3_DOUON *douon, int mb_flag); int sj3_tango_gakusyuu(SJ3_CLIENT_ENV *client, SJ3_STUDYREC *stdy); -int sj3_bunsetu_gakusyuu(SJ3_CLIENT_ENV *client, u_char *yomi1, u_char *yomi2, SJ3_STUDYREC *stdy, int mb_flag); -int sj3_tango_touroku(SJ3_CLIENT_ENV *client, long dicid, u_char *yomi, u_char *kanji, int code, int mb_flag); -int sj3_tango_sakujo(SJ3_CLIENT_ENV *client, long dicid, u_char *yomi, u_char *kanji, int code, int mb_flag); -int sj3_tango_syutoku(SJ3_CLIENT_ENV *client, int dicid, u_char *buf, int mb_flag); -int sj3_tango_jikouho(SJ3_CLIENT_ENV *client, int dicid, u_char *buf, int mb_flag); -int sj3_tango_maekouho(SJ3_CLIENT_ENV *client, int dicid, u_char *buf, int mb_flag); -int sj3_make_dict_file(SJ3_CLIENT_ENV *client, char *path, int idxlen, int seglen, int segnum); -int sj3_make_study_file(SJ3_CLIENT_ENV *client, char *path, int stynum, int clstep, int cllen); +int sj3_bunsetu_gakusyuu(SJ3_CLIENT_ENV *client, u_char *yomi1, u_char *yomi2, + SJ3_STUDYREC *stdy, int mb_flag); +int sj3_tango_touroku(SJ3_CLIENT_ENV *client, long dicid, u_char *yomi, + u_char *kanji, int code, int mb_flag); +int sj3_tango_sakujo(SJ3_CLIENT_ENV *client, long dicid, u_char *yomi, + u_char *kanji, int code, int mb_flag); +int sj3_tango_syutoku(SJ3_CLIENT_ENV *client, int dicid, u_char *buf, + int mb_flag); +int sj3_tango_jikouho(SJ3_CLIENT_ENV *client, int dicid, u_char *buf, + int mb_flag); +int sj3_tango_maekouho(SJ3_CLIENT_ENV *client, int dicid, u_char *buf, + int mb_flag); +int sj3_make_dict_file(SJ3_CLIENT_ENV *client, char *path, int idxlen, + int seglen, int segnum); +int sj3_make_study_file(SJ3_CLIENT_ENV *client, char *path, int stynum, + int clstep, int cllen); int sj3_make_directory(SJ3_CLIENT_ENV *client, char *path); int sj3_access(SJ3_CLIENT_ENV *client, char *path, int mode); int sj3_who(SJ3_CLIENT_ENV *client, SJ3_WHO_STRUCT *ret, int num); @@ -213,7 +198,8 @@ int sj3_version(SJ3_CLIENT_ENV *client, char *dst, int dstsiz); /* sj.c */ int sj3_open(char *host, char *user); -int sj3_open_with_list(char *host, char *user, int dicts_num, char **dicts, int *error_num, int **error_index); +int sj3_open_with_list(char *host, char *user, int dicts_num, char **dicts, + int *error_num, int **error_index); int sj3_close(void); int sj3_getkan(u_char *yomi, SJ3_BUNSETU *bun, u_char *knj, int knjsiz); int sj3_getkan_euc(u_char *yomi, SJ3_BUNSETU *bun, u_char *knj, int knjsiz); diff --git a/sj3lib/string.c b/sj3lib/string.c index a61fa11..340db72 100644 --- a/sj3lib/string.c +++ b/sj3lib/string.c @@ -1,8 +1,8 @@ /*- * SPDX-License-Identifier: MIT-open-group - * + * * Copyright (c) 1994 Sony Corporation - * + * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including @@ -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 @@ -51,24 +51,27 @@ #define iskana(c) ((0xa1 <= (c)) && ((c) <= 0xdf)) int -sj3_str_sjistoeuc(unsigned char *out, int outlen, unsigned char *in, unsigned char *sjis_default, int *useflag) +sj3_str_sjistoeuc(unsigned char *out, int outlen, unsigned char *in, + unsigned char *sjis_default, int *useflag) { - unsigned char *sjis = in, *euc = out; - int n = 0; - unsigned short code, default_code; + unsigned char *sjis = in, *euc = out; + int n = 0; + unsigned short code, default_code; euc[0] = '\0'; *useflag = 0; - if (!sjis) return 0; - + if (!sjis) + return 0; + while (*sjis && n < outlen) { if (issjis1(*sjis)) { - code = sjis2euc( (*sjis << 8) | *(sjis+1) ); - if (n + 2 > outlen) return -1; - if (code == 0) { - default_code = sjis2euc((sjis_default[0] << 8) - | sjis_default[1]); + code = sjis2euc((*sjis << 8) | *(sjis + 1)); + if (n + 2 > outlen) + return -1; + if (code == 0) { + default_code = sjis2euc((sjis_default[0] << 8) | + sjis_default[1]); euc[n++] = default_code >> 8; euc[n++] = default_code & 0xff; (*useflag)++; @@ -78,38 +81,41 @@ sj3_str_sjistoeuc(unsigned char *out, int outlen, unsigned char *in, unsigned ch } sjis += 2; } else { - if( *sjis >= 0xa1 && *sjis <= 0xdf ) { - if (n + 2 > outlen) return -1; - euc[n++] = SS2; + if (*sjis >= 0xa1 && *sjis <= 0xdf) { + if (n + 2 > outlen) + return -1; + euc[n++] = SS2; } euc[n++] = *sjis; sjis++; } - } - if (n > outlen) return -1; - + if (n > outlen) + return -1; + euc[n] = '\0'; return n; } - int -sj3_str_euctosjis(unsigned char *out, int outlen, unsigned char *in, unsigned char *sjis_default, int *useflag) +sj3_str_euctosjis(unsigned char *out, int outlen, unsigned char *in, + unsigned char *sjis_default, int *useflag) { - unsigned char *euc = in, *sjis = out; - int n = 0; - unsigned short code, default_code; + unsigned char *euc = in, *sjis = out; + int n = 0; + unsigned short code, default_code; sjis[0] = '\0'; *useflag = 0; - if (!euc) return 0; + if (!euc) + return 0; while (*euc && n < outlen) { if (iseuc(*euc)) { - code = euc2sjis( (*euc << 8) | *(euc+1) ); - if (n + 2 > outlen) return -1; + code = euc2sjis((*euc << 8) | *(euc + 1)); + if (n + 2 > outlen) + return -1; if (code == 0) { sjis[n++] = sjis_default[0]; sjis[n++] = sjis_default[1]; @@ -120,7 +126,8 @@ sj3_str_euctosjis(unsigned char *out, int outlen, unsigned char *in, unsigned ch } euc += 2; } else if (*euc == SS3) { - if (n + 2 > outlen) return -1; + if (n + 2 > outlen) + return -1; sjis[n++] = sjis_default[0]; sjis[n++] = sjis_default[1]; euc += 3; @@ -133,195 +140,196 @@ sj3_str_euctosjis(unsigned char *out, int outlen, unsigned char *in, unsigned ch euc++; } } - if (n > outlen) return -1; + if (n > outlen) + return -1; sjis[n] = '\0'; return n; } - + int sj3_sjistoeuclen(unsigned char *str, int max) { - register int len = 0, bytes = 1; + int len = 0, bytes = 1; - if (!max) return 0; + if (!max) + return 0; while ((bytes <= max) && *str) { if (issjis1(*str)) { - str++; - bytes++; - if (!*str) break; - len += 2; + str++; + bytes++; + if (!*str) + break; + len += 2; } else if (*str & 0x80) { len += 2; } else { - len++; + len++; } - str++; - bytes++; + str++; + bytes++; } - return len; + return len; } - + #define MASK 0x7f #define MSB 0x80 -static unsigned char def_char[] = {0x81, 0x40}; +static unsigned char def_char[] = {0x81, 0x40}; -int +int sj3_sjistoeuc(unsigned char *e, int elen, unsigned char *s, int slen) { - int dummy; + int dummy; return sj3_str_sjistoeuc(e, elen, s, def_char, &dummy); } -int +int sj3_euctosjis(unsigned char *s, int slen, unsigned char *e, int elen) { - int dummy; + int dummy; return sj3_str_euctosjis(s, slen, e, def_char, &dummy); } void -sj_euc2sjis (unsigned char *s) +sj_euc2sjis(unsigned char *s) { - s[0] &= MASK; - s[1] &= MASK; - sj_jis2sjis (s); + s[0] &= MASK; + s[1] &= MASK; + sj_jis2sjis(s); } void -sj_jis2sjis (unsigned char *s) +sj_jis2sjis(unsigned char *s) { - register int high, low; - register int nh, nl; + int high, low; + int nh, nl; - high = s[0]; - low = s[1]; - nh = ((high - 0x21) >> 1) + 0x81; - if (nh > 0x9f) - nh += 0x40; + high = s[0]; + low = s[1]; + nh = ((high - 0x21) >> 1) + 0x81; + if (nh > 0x9f) + nh += 0x40; if (high & 1) { - nl = low + 0x1f; - if (low > 0x5f) - nl ++; + nl = low + 0x1f; + if (low > 0x5f) + nl++; + } else + nl = low + 0x7e; + s[0] = nh; + s[1] = nl; +} + +void +sj_sjis2euc(unsigned char *s) +{ + sj_sjis2jis(s); + s[0] |= MSB; + s[1] |= MSB; +} + +void +sj_sjis2jis(unsigned char *s) +{ + int byte1, byte2; + unsigned char *sp; + + sp = s; + byte1 = *sp++; + byte2 = *sp--; + + if (byte1 <= 0x80 || byte1 >= 0xf0 || + (byte1 >= 0xa0 && byte1 <= 0xdf) || + byte2 <= 0x3f || byte2 >= 0xfe || byte2 == 0x7f) { + byte1 = 0x81; + byte2 = 0x40; } - else - nl = low + 0x7e; - s[0] = nh; - s[1] = nl; -} - -void -sj_sjis2euc (unsigned char *s) -{ - sj_sjis2jis (s); - s[0] |= MSB; - s[1] |= MSB; -} - -void -sj_sjis2jis (unsigned char *s) -{ - register int byte1, byte2; - register unsigned char *sp; - - sp = s; - byte1 = *sp++; - byte2 = *sp--; - - if (byte1 <= 0x80 || byte1 >= 0xf0 - || ( byte1>=0xa0 && byte1<=0xdf ) - || byte2 <= 0x3f || byte2 >= 0xfe || byte2==0x7f ) { - byte1 = 0x81; - byte2 = 0x40; - } - byte1 -= (byte1 >= 0xa0) ? 0xc1 : 0x81; + byte1 -= (byte1 >= 0xa0) ? 0xc1 : 0x81; if (byte2 >= 0x9f) { - *sp++ = (byte1 << 1) + 0x22; - *sp = byte2 - 0x7e; - } - else { - *sp++ = (byte1 << 1) + 0x21; - *sp = byte2 - ((byte2 <= 0x7e) ? 0x1f : 0x20 ); + *sp++ = (byte1 << 1) + 0x22; + *sp = byte2 - 0x7e; + } else { + *sp++ = (byte1 << 1) + 0x21; + *sp = byte2 - ((byte2 <= 0x7e) ? 0x1f : 0x20); } } unsigned short sj3_jis2sjis(unsigned short code) { - unsigned char tmp[3]; - - tmp[0] = (code >> 8) & 0xff; - tmp[1] = code & 0xff; - tmp[2] = '\0'; - - sj_jis2sjis((unsigned char *) tmp); - - code = (tmp[0] << 8) + tmp[1]; - - return(code); + unsigned char tmp[3]; + + tmp[0] = (code >> 8) & 0xff; + tmp[1] = code & 0xff; + tmp[2] = '\0'; + + sj_jis2sjis((unsigned char *)tmp); + + code = (tmp[0] << 8) + tmp[1]; + + return (code); } unsigned short sj3_jis2euc(unsigned short code) { - unsigned char tmp[3]; - - tmp[0] = (code >> 8) & 0xff; - tmp[1] = code & 0xff; - tmp[2] = '\0'; - - code = ((tmp[0] | 0x80) << 8) + (tmp[1] | 0x80); - - return(code); + unsigned char tmp[3]; + + tmp[0] = (code >> 8) & 0xff; + tmp[1] = code & 0xff; + tmp[2] = '\0'; + + code = ((tmp[0] | 0x80) << 8) + (tmp[1] | 0x80); + + return (code); } unsigned short sj3_sjis2jis(unsigned short code) { - unsigned char tmp[3]; - - tmp[0] = (code >> 8) & 0xff; - tmp[1] = code & 0xff; - tmp[2] = '\0'; + unsigned char tmp[3]; - sj_sjis2jis((unsigned char *) tmp); + tmp[0] = (code >> 8) & 0xff; + tmp[1] = code & 0xff; + tmp[2] = '\0'; - code = (tmp[0] << 8) + tmp[1]; + sj_sjis2jis((unsigned char *)tmp); - return(code); + code = (tmp[0] << 8) + tmp[1]; + + return (code); } unsigned short sj3_euc2sjis(unsigned short code) { - unsigned char tmp[3]; + unsigned char tmp[3]; - tmp[0] = (code >> 8) & 0xff; - tmp[1] = code & 0xff; - tmp[2] = '\0'; + tmp[0] = (code >> 8) & 0xff; + tmp[1] = code & 0xff; + tmp[2] = '\0'; - sj_euc2sjis((unsigned char *) tmp); - - code = (tmp[0] << 8) + tmp[1]; + sj_euc2sjis((unsigned char *)tmp); - return(code); + code = (tmp[0] << 8) + tmp[1]; + + return (code); } unsigned short sj3_sjis2euc(unsigned short code) { - unsigned char tmp[3]; + unsigned char tmp[3]; - tmp[0] = (code >> 8) & 0xff; - tmp[1] = code & 0xff; - tmp[2] = '\0'; + tmp[0] = (code >> 8) & 0xff; + tmp[1] = code & 0xff; + tmp[2] = '\0'; - sj_sjis2euc((unsigned char *) tmp); + sj_sjis2euc((unsigned char *)tmp); - code = (tmp[0] << 8) + tmp[1]; + code = (tmp[0] << 8) + tmp[1]; - return(code); -} + return (code); +}