-/*
-**
-** $Id: jlib.c,v 1.14 2008-05-03 15:40:59 argrath Exp $
-**
-*/
-
-/* Copyright (c) Issei Numata 1994-2000 */
+/* JNetHack Copyright */
+/* (c) Issei Numata 1994-2000 */
+/* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2018 */
/* JNetHack may be freely redistributed. See license for details. */
#include <stdio.h>
#define UTF8 2
#ifdef POSIX_ICONV
-static char* ccode[]={
+static const char* ccode[]={
"EUC-JP-MS",
"CP932",
"UTF-8"
};
-static char* ccode_alt[]={
+static const char* ccode_alt[]={
"EUC-JP",
"ShiftJIS",
"UTF-8"
/* default input kcode */
#ifndef INPUT_KCODE
-# ifdef MSDOS
+# if defined(MSDOS) || defined(WIN32)
# define INPUT_KCODE SJIS
# else
-# define INPUT_KCODE EUC
+# define INPUT_KCODE UTF8
# endif
#endif
/* default output kcode */
#ifndef OUTPUT_KCODE
-# ifdef MSDOS
+# if defined(MSDOS) || defined(WIN32)
# define OUTPUT_KCODE SJIS
# else
-# define OUTPUT_KCODE EUC
+# define OUTPUT_KCODE UTF8
# endif
#endif
if (output_dsc)
iconv_close(output_dsc);
output_dsc = iconv_open(ccode[output_kcode], ccode[IC]);
- if ((size_t)output_dsc == -1)
+ if (output_dsc == (iconv_t)-1)
output_dsc = iconv_open(ccode_alt[output_kcode], ccode[IC]);
- if ((size_t)output_dsc == -1)
+ if (output_dsc == (iconv_t)-1)
output_dsc = iconv_open(ccode[output_kcode], ccode_alt[IC]);
- if ((size_t)output_dsc == -1)
+ if (output_dsc == (iconv_t)-1)
output_dsc = iconv_open(ccode_alt[output_kcode], ccode_alt[IC]);
if(input_dsc)
iconv_close(input_dsc);
input_dsc = iconv_open(ccode[IC] ,ccode[input_kcode]);
- if ((size_t)input_dsc == -1)
+ if (input_dsc == (iconv_t)-1)
input_dsc = iconv_open(ccode_alt[IC] ,ccode[input_kcode]);
- if ((size_t)input_dsc == -1)
+ if (input_dsc == (iconv_t)-1)
input_dsc = iconv_open(ccode[IC] ,ccode_alt[input_kcode]);
- if ((size_t)input_dsc == -1)
+ if (input_dsc == (iconv_t)-1)
input_dsc = iconv_open(ccode_alt[IC] ,ccode_alt[input_kcode]);
#endif
}
{
static unsigned char buf[1024];
const unsigned char *up;
- unsigned char *p, *pp;
+ unsigned char *p;
+#ifndef POSIX_ICONV
+ unsigned char *pp;
+#endif
if(!s)
return s;
#ifdef POSIX_ICONV
if (input_dsc) {
size_t src_len, dst_len;
- up = s;
+ up = (unsigned char *)s;
src_len = strlen(s);
dst_len = sizeof(buf);
if (iconv(input_dsc, (char**)&up, &src_len,
#else
if( IC==EUC && input_kcode == SJIS ){
while(*s){
- up = s;
+ up = (unsigned char *)s;
if(is_kanji(*up)){
pp = sj2e((unsigned char *)s);
*(p++) = pp[0];
{
static unsigned char buf[1024];
const unsigned char *up;
- unsigned char *p, *pp;
+ unsigned char *p;
+#ifndef POSIX_ICONV
+ unsigned char *pp;
+#endif
if(!s)
return s;
#ifdef POSIX_ICONV
if(output_dsc){
size_t src_len, dst_len;
- up = s;
+ up = (unsigned char *)s;
src_len = strlen(s);
dst_len = sizeof(buf);
if(iconv(output_dsc, (char**)&up, &src_len,
#else
if( IC==EUC && output_kcode == SJIS ){
while(*s){
- up = s;
+ up = (unsigned char *)s;
if( *up & 0x80 ){
pp = e2sj((unsigned char *)s);
*(p++) = pp[0];
{
static unsigned int ibuf[2];
unsigned int c1, c2;
+#ifndef POSIX_ICONV
unsigned char uc[2];
unsigned char *p;
+#endif
if(!buf) buf = ibuf;
if(!f1) f1 = tty_jputc;
return c;
}
} else {
- return is_kanji2(s, pos);
+ return is_kanji2((char *)s, pos);
}
}
unsigned char cc[3];
if(IC==SJIS)
- memcpy(cc, (char *)sj2e(c), 2);
+ memcpy(cc, (char *)sj2e((unsigned char *)c), 2);
else
memcpy(cc, c, 2);
if(!is_kanji1(engr, nxt)) return 0;
j = kanji2index(engr[nxt], engr[nxt + 1]);
- if (j >= 0x0000 && j <= 0x02B1) p = &ro0[j << 2];
- else if (j >= 0x0582 && j <= 0x1116) p = &ro1[(j - 0x0582) << 2];
- else if (j >= 0x1142 && j <= 0x1E7F) p = &ro2[(j - 0x1142) << 2];
- else p = "\81H";
+ if (j >= 0x0000 && j <= 0x02B1)
+ p = (unsigned char *)&ro0[j << 2];
+ else if (j >= 0x0582 && j <= 0x1116)
+ p = (unsigned char *)&ro1[(j - 0x0582) << 2];
+ else if (j >= 0x1142 && j <= 0x1E7F)
+ p = (unsigned char *)&ro2[(j - 0x1142) << 2];
+ else p = (unsigned char *)"\81H";
if (p[2] != ' ' || p[3] != ' ') p += select_rnd * 2;
engr[nxt] = *p++;