OSDN Git Service

apply #39273
[jnethack/source.git] / japanese / jlib.c
index c9083b6..01de74f 100644 (file)
@@ -1,10 +1,6 @@
-/*
-**
-**      $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>
@@ -23,12 +19,12 @@ int xputc2(int, int);
 #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"
@@ -42,19 +38,19 @@ static char* ccode_alt[]={
 
 /* 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
 
@@ -112,20 +108,20 @@ setkcode(c)
     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
 }
@@ -181,7 +177,10 @@ str2ic(s)
 {
     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;
@@ -197,7 +196,7 @@ str2ic(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,
@@ -207,7 +206,7 @@ str2ic(s)
 #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];
@@ -240,7 +239,10 @@ ic2str(s)
 {
     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;
@@ -251,7 +253,7 @@ ic2str(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,
@@ -261,7 +263,7 @@ ic2str(s)
 #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];
@@ -348,8 +350,10 @@ jbuffer(
 {
     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;
@@ -579,7 +583,7 @@ offset_in_kanji(s, pos)
             return c;
         }
     } else {
-        return is_kanji2(s, pos);
+        return is_kanji2((char *)s, pos);
     }
 }
 
@@ -722,7 +726,7 @@ jrndm_replace(c)
     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);
 
@@ -1403,10 +1407,13 @@ jrubout(engr, nxt, use_rubout, select_rnd)
     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++;