sj3lib: KNF

Formatter: knfmt 4.2.0
Signed-off-by: Masanori Ogino <mogino@acm.org>
This commit is contained in:
Masanori Ogino 2023-11-30 08:48:00 +09:00
commit e00547f414
4 changed files with 1182 additions and 1097 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -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);

View file

@ -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);
}