OSDN Git Service

Patch by sava. [nkf-patch#13930]
authorNARUSE, Yui <naruse@users.sourceforge.jp>
Fri, 7 Nov 2008 11:37:21 +0000 (11:37 +0000)
committerNARUSE, Yui <naruse@users.sourceforge.jp>
Fri, 7 Nov 2008 11:37:21 +0000 (11:37 +0000)
* replace int type with nkf_char.
* remove duplicate NKF_INT32_C.
* use APIs for getting locales on OS/2.
* nkf_default_encoding returns UTF-8 if no locale encoding.
* definitions for (Open) Watcom.
* add DEFAULT_CODE_WINDOWS_31J.
* pointers can't be negative.

config.h
nkf.c
nkf.h

index 7c6fc6c..752ed38 100644 (file)
--- a/config.h
+++ b/config.h
@@ -44,8 +44,8 @@
 
 /* #define DEFAULT_CODE_JIS    */
 /* #define DEFAULT_CODE_SJIS   */
+/* #define DEFAULT_CODE_WINDOWS_31J */
 /* #define DEFAULT_CODE_EUC    */
 /* #define DEFAULT_CODE_UTF8   */
-#define DEFAULT_CODE_LOCALE
 
 #endif /* _CONFIG_H_ */
diff --git a/nkf.c b/nkf.c
index d21c641..e609edc 100644 (file)
--- a/nkf.c
+++ b/nkf.c
@@ -31,7 +31,7 @@
  * \e$B8=:_!"\e(Bnkf \e$B$O\e(B SorceForge \e$B$K$F%a%s%F%J%s%9$,B3$1$i$l$F$$$^$9!#\e(B
  * http://sourceforge.jp/projects/nkf/
  ***********************************************************************/
-#define NKF_IDENT "$Id: nkf.c,v 1.186 2008/10/28 14:26:31 naruse Exp $"
+#define NKF_IDENT "$Id: nkf.c,v 1.187 2008/11/07 02:37:21 naruse Exp $"
 #define NKF_VERSION "2.0.8"
 #define NKF_RELEASE_DATE "2008-10-28"
 #define COPY_RIGHT \
 #include <windows.h>
 #include <locale.h>
 #endif
+#if defined(__OS2__)
+# define INCL_DOS
+# define INCL_DOSERRORS
+# include <os2.h>
+#endif
 
 /* state of output_mode and input_mode
 
@@ -267,6 +272,8 @@ struct {
 #define            DEFAULT_ENCIDX ISO_2022_JP
 #elif defined(DEFAULT_CODE_SJIS)
 #define            DEFAULT_ENCIDX SHIFT_JIS
+#elif defined(DEFAULT_CODE_WINDOWS_31J)
+#define            DEFAULT_ENCIDX WINDOWS_31J
 #elif defined(DEFAULT_CODE_EUC)
 #define            DEFAULT_ENCIDX EUC_JP
 #elif defined(DEFAULT_CODE_UTF8)
@@ -424,8 +431,8 @@ static nkf_char (*i_uungetc)(nkf_char c ,FILE *f) = std_ungetc;
 #define nkf_char_euc3_new(c) ((c) | PREFIX_EUCG3)
 #define nkf_char_unicode_new(c) ((c) | CLASS_UNICODE)
 #define nkf_char_unicode_p(c) ((c & CLASS_MASK) == CLASS_UNICODE)
-#define nkf_char_unicode_bmp_p(c) ((c & VALUE_MASK) <= NKF_INT32_C(UNICODE_BMP_MAX))
-#define nkf_char_unicode_value_p(c) ((c & VALUE_MASK) <= NKF_INT32_C(UNICODE_MAX))
+#define nkf_char_unicode_bmp_p(c) ((c & VALUE_MASK) <= UNICODE_BMP_MAX)
+#define nkf_char_unicode_value_p(c) ((c & VALUE_MASK) <= UNICODE_MAX)
 
 #ifdef NUMCHAR_OPTION
 static int numchar_f = FALSE;
@@ -732,6 +739,21 @@ nkf_locale_charmap()
       return str;
     }
     else return NULL;
+#elif defined(__OS2__)
+# if defined(INT_IS_SHORT)
+    /* OS/2 1.x */
+    return NULL;
+# else
+    /* OS/2 32bit */
+    static char buf[16];
+    ULONG ulCP[1], ulncp;
+    DosQueryCp(sizeof(ulCP), ulCP, &ulncp);
+    if (ulCP[0] == 932 || ulCP[0] == 943)
+        strcpy(buf, "Shift_JIS");
+    else
+        sprintf(buf, "CP%lu", ulCP[0]);
+    return buf;
+# endif
 #else
     return NULL;
 #endif
@@ -744,20 +766,26 @@ nkf_locale_encoding()
     char *encname = nkf_locale_charmap();
     if (encname)
        enc = nkf_enc_find(encname);
-    if (enc < 0) enc = 0;
     return enc;
 }
 #endif /* DEFAULT_CODE_LOCALE */
 
 static nkf_encoding*
+nkf_utf8_encoding()
+{
+    return &nkf_encoding_table[UTF_8];
+}
+
+static nkf_encoding*
 nkf_default_encoding()
 {
     nkf_encoding *enc = 0;
 #ifdef DEFAULT_CODE_LOCALE
     enc = nkf_locale_encoding();
-#elif DEFAULT_ENCIDX
+#elif defined(DEFAULT_ENCIDX)
     enc = nkf_enc_from_index(DEFAULT_ENCIDX);
 #endif
+    if (!enc) enc = nkf_utf8_encoding();
     return enc;
 }
 
@@ -855,7 +883,7 @@ show_configuration(void)
            "    Default output encoding:     "
 #ifdef DEFAULT_CODE_LOCALE
            "LOCALE (%s)\n", nkf_enc_name(nkf_default_encoding())
-#elif DEFAULT_ENCIDX
+#elif defined(DEFAULT_ENCIDX)
            "CONFIG (%s)\n", nkf_enc_name(nkf_default_encoding())
 #else
            "NONE\n"
@@ -1551,7 +1579,7 @@ s2e_conv(nkf_char c2, nkf_char c1, nkf_char *p2, nkf_char *p1)
 
 #if defined(UTF8_INPUT_ENABLE) || defined(UTF8_OUTPUT_ENABLE)
 static void
-nkf_unicode_to_utf8(nkf_char val, int *p1, int *p2, int *p3, int *p4)
+nkf_unicode_to_utf8(nkf_char val, nkf_char *p1, nkf_char *p2, nkf_char *p3, nkf_char *p4)
 {
     val &= VALUE_MASK;
     if (val < 0x80){
@@ -1583,7 +1611,7 @@ nkf_unicode_to_utf8(nkf_char val, int *p1, int *p2, int *p3, int *p4)
 }
 
 static nkf_char
-nkf_utf8_to_unicode(int c1, int c2, int c3, int c4)
+nkf_utf8_to_unicode(nkf_char c1, nkf_char c2, nkf_char c3, nkf_char c4)
 {
     nkf_char wc;
     if (c1 <= 0x7F) {
@@ -1884,7 +1912,7 @@ w2e_conv(nkf_char c2, nkf_char c1, nkf_char c0, nkf_char *p2, nkf_char *p1)
 static nkf_char
 w16e_conv(nkf_char val, nkf_char *p2, nkf_char *p1)
 {
-    int c1, c2, c3, c4;
+    nkf_char c1, c2, c3, c4;
     nkf_char ret = 0;
     val &= VALUE_MASK;
     if (val < 0x80) {
@@ -2101,7 +2129,7 @@ unicode_iconv(nkf_char wc)
 #define NKF_ICONV_NEED_TWO_MORE_BYTES -2
 #define UTF16_TO_UTF32(lead, trail) (((lead) << 10) + (trail) - NKF_INT32_C(0x35FDC00))
 static size_t
-nkf_iconv_utf_16(int c1, int c2, int c3, int c4)
+nkf_iconv_utf_16(nkf_char c1, nkf_char c2, nkf_char c3, nkf_char c4)
 {
     nkf_char wc;
 
@@ -2144,7 +2172,7 @@ w_iconv32(nkf_char c2, nkf_char c1, nkf_char c0)
 }
 
 static size_t
-nkf_iconv_utf_32(int c1, int c2, int c3, int c4)
+nkf_iconv_utf_32(nkf_char c1, nkf_char c2, nkf_char c3, nkf_char c4)
 {
     nkf_char wc;
 
@@ -2428,7 +2456,7 @@ s_oconv(nkf_char c2, nkf_char c1)
 static void
 w_oconv(nkf_char c2, nkf_char c1)
 {
-    int c3, c4;
+    nkf_char c3, c4;
     nkf_char val;
 
     if (output_bom_f) {
@@ -5569,7 +5597,7 @@ kanji_convert(FILE *f)
                           C%7 : 0 1 2 3 4 5 6
                           NUM : 2 0 3 4 5 X 1
                         */
-                       static const int jphone_emoji_first_table[7] =
+                       static const nkf_char jphone_emoji_first_table[7] =
                        {0xE1E0, 0xDFE0, 0xE2E0, 0xE3E0, 0xE4E0, 0xDFE0, 0xE0E0};
                        c3 = nkf_char_unicode_new(jphone_emoji_first_table[c1 % 7]);
                        if ((c1 = (*i_getc)(f)) == EOF) LAST;
@@ -5758,7 +5786,8 @@ options(unsigned char *cp)
                }
                if (strcmp(long_option[i].name, "oc=") == 0){
                    enc = nkf_enc_find((char *)p);
-                   if (enc <= 0) continue;
+                   /* if (enc <= 0) continue; */
+                   if (!enc) continue;
                    output_encoding = enc;
                    continue;
                }
diff --git a/nkf.h b/nkf.h
index f6005a1..2615dd8 100755 (executable)
--- a/nkf.h
+++ b/nkf.h
@@ -2,7 +2,7 @@
  * 
  * nkf.h - Header file for nkf
  * 
- * $Id: nkf.h,v 1.4 2008/10/22 18:27:57 naruse Exp $
+ * $Id: nkf.h,v 1.5 2008/11/07 02:37:21 naruse Exp $
  */
 
 #ifndef NKF_H
@@ -51,7 +51,7 @@ typedef int nkf_char;
 #define NKF_INT32_C(n)   (n)
 #endif
 
-#if (defined(__TURBOC__) || defined(_MSC_VER) || defined(LSI_C) || defined(__MINGW32__) || defined(__EMX__) || defined(__MSDOS__) || defined(__WINDOWS__) || defined(__DOS__) || defined(__OS2__)) && !defined(MSDOS)
+#if (defined(__TURBOC__) || defined(_MSC_VER) || defined(LSI_C) || (defined(__WATCOMC__) && defined(__386__) && !defined(__LINUX__)) || defined(__MINGW32__) || defined(__EMX__) || defined(__MSDOS__) || defined(__WINDOWS__) || defined(__DOS__) || defined(__OS2__)) && !defined(MSDOS)
 #define MSDOS
 #if (defined(__Win32__) || defined(_WIN32)) && !defined(__WIN32__)
 #define __WIN32__
@@ -143,17 +143,37 @@ void  setbinmode(FILE *fp)
 #endif
 #endif
 
+#if !defined(DEFAULT_CODE_JIS) && !defined(DEFAULT_CODE_SJIS) && \
+       !defined(DEFAULT_CODE_WINDOWS_31J) && !defined(DEFAULT_CODE_EUC) && \
+       !defined(DEFAULT_CODE_UTF8) && !defined(DEFAULT_CODE_LOCALE)
+#define DEFAULT_CODE_LOCALE
+#endif
+
 #ifdef DEFAULT_CODE_LOCALE
 
-#ifndef __WIN32__ /* not win32 should be posix */
-#ifndef HAVE_LANGINFO_H
-#define HAVE_LANGINFO_H
-#endif
-#ifndef HAVE_LOCALE_H
-#define HAVE_LOCALE_H
-#endif
+#if defined(__WIN32__) /* not win32 should be posix */
+# ifndef HAVE_LOCALE_H
+#  define HAVE_LOCALE_H
+# endif
+#elif defined(__OS2__)
+# undef HAVE_LANGINFO_H /* We do not use kLIBC's langinfo. */
+# ifndef HAVE_LOCALE_H
+#  define HAVE_LOCALE_H
+# endif
+#elif defined(MSDOS)
+# ifndef HAVE_LOCALE_H
+#  define HAVE_LOCALE_H
+# endif
+#else
+# ifndef HAVE_LANGINFO_H
+#  define HAVE_LANGINFO_H
+# endif
+# ifndef HAVE_LOCALE_H
+#  define HAVE_LOCALE_H
+# endif
 #endif
 
+
 #ifdef HAVE_LANGINFO_H
 #include <langinfo.h>
 #endif