OSDN Git Service

Change content of w_iconv16 and w_iconv32. [nkf-forum:47545]
[nkf/nkf.git] / nkf.c
diff --git a/nkf.c b/nkf.c
index 4230199..65bdea4 100644 (file)
--- a/nkf.c
+++ b/nkf.c
  *
  * 3. This notice may not be removed or altered from any source distribution.
  */
-#define NKF_VERSION "2.0.9"
-#define NKF_RELEASE_DATE "2009-06-23"
+#define NKF_VERSION "2.1.1"
+#define NKF_RELEASE_DATE "2010-01-05"
 #define COPY_RIGHT \
     "Copyright (C) 1987, FUJITSU LTD. (I.Ichikawa).\n" \
-    "Copyright (C) 1996-2009, The nkf Project."
+    "Copyright (C) 1996-2010, The nkf Project."
 
 #include "config.h"
 #include "nkf.h"
@@ -210,6 +210,8 @@ struct {
 } encoding_name_to_id_table[] = {
     {"US-ASCII",               ASCII},
     {"ASCII",                  ASCII},
+    {"646",                    ASCII},
+    {"ROMAN8",                 ASCII},
     {"ISO-2022-JP",            ISO_2022_JP},
     {"ISO2022JP-CP932",                CP50220},
     {"CP50220",                        CP50220},
@@ -221,6 +223,7 @@ struct {
     {"ISO-2022-JP-2004",       ISO_2022_JP_2004},
     {"SHIFT_JIS",              SHIFT_JIS},
     {"SJIS",                   SHIFT_JIS},
+    {"PCK",                    SHIFT_JIS},
     {"WINDOWS-31J",            WINDOWS_31J},
     {"CSWINDOWS31J",           WINDOWS_31J},
     {"CP932",                  WINDOWS_31J},
@@ -1028,7 +1031,7 @@ nkf_each_char_to_hex(void (*f)(nkf_char c2,nkf_char c1), nkf_char c)
     int shift = 20;
     c &= VALUE_MASK;
     while(shift >= 0){
-       if(c >= 1<<shift){
+       if(c >= NKF_INT32_C(1)<<shift){
            while(shift >= 0){
                (*f)(0, bin2hex(c>>shift));
                shift -= 4;
@@ -1206,6 +1209,7 @@ set_input_encoding(nkf_encoding *enc)
     case CP50220:
     case CP50221:
     case CP50222:
+       x0201_f = TRUE;
 #ifdef SHIFTJIS_CP932
        cp51932_f = TRUE;
 #endif
@@ -1227,6 +1231,7 @@ set_input_encoding(nkf_encoding *enc)
     case SHIFT_JIS:
        break;
     case WINDOWS_31J:
+       x0201_f = TRUE;
 #ifdef SHIFTJIS_CP932
        cp51932_f = TRUE;
 #endif
@@ -1248,6 +1253,7 @@ set_input_encoding(nkf_encoding *enc)
     case EUCJP_NKF:
        break;
     case CP51932:
+       x0201_f = TRUE;
 #ifdef SHIFTJIS_CP932
        cp51932_f = TRUE;
 #endif
@@ -1327,6 +1333,7 @@ set_output_encoding(nkf_encoding *enc)
 #endif
        break;
     case CP50221:
+       x0201_f = TRUE;
 #ifdef SHIFTJIS_CP932
        if (cp932inv_f == TRUE) cp932inv_f = FALSE;
 #endif
@@ -1355,6 +1362,7 @@ set_output_encoding(nkf_encoding *enc)
     case SHIFT_JIS:
        break;
     case WINDOWS_31J:
+       x0201_f = TRUE;
 #ifdef UTF8_OUTPUT_ENABLE
        ms_ucs_map_f = UCS_MAP_CP932;
 #endif
@@ -1383,6 +1391,7 @@ set_output_encoding(nkf_encoding *enc)
 #endif
        break;
     case CP51932:
+       x0201_f = TRUE;
 #ifdef SHIFTJIS_CP932
        if (cp932inv_f == TRUE) cp932inv_f = FALSE;
 #endif
@@ -2224,13 +2233,13 @@ nkf_iconv_utf_16(nkf_char c1, nkf_char c2, nkf_char c3, nkf_char c4)
 static nkf_char
 w_iconv16(nkf_char c2, nkf_char c1, nkf_char c0)
 {
-    return 0;
+    return 16;
 }
 
 static nkf_char
 w_iconv32(nkf_char c2, nkf_char c1, nkf_char c0)
 {
-    return 0;
+    return 32;
 }
 
 static size_t
@@ -3056,11 +3065,11 @@ push_hold_buf(nkf_char c2)
 }
 
 static int
-h_conv(FILE *f, int c1, int c2)
+h_conv(FILE *f, nkf_char c1, nkf_char c2)
 {
-    int ret, c4, c3;
+    int ret;
     int hold_index;
-
+    nkf_char c3, c4;
 
     /** it must NOT be in the kanji shifte sequence      */
     /** it must NOT be written in JIS7                   */
@@ -4433,7 +4442,7 @@ mime_getc(FILE *f)
        }
        if (c1=='='&&c2<SP) { /* this is soft wrap */
            while((c1 =  (*i_mgetc)(f)) <=SP) {
-               if ((c1 = (*i_mgetc)(f)) == EOF) return (EOF);
+               if (c1 == EOF) return (EOF);
            }
            mime_decode_mode = 'Q'; /* still in MIME */
            goto restart_mime_q;
@@ -4643,7 +4652,8 @@ mime_prechar(nkf_char c2, nkf_char c1)
                base64_count = 1;
            }
        } else {
-           if (base64_count + mimeout_state.count/3*4> 66) {
+           if (!(c2 == 0 && (c1 == CR || c1 == LF)) &&
+                   base64_count + mimeout_state.count/3*4> 66) {
                (*o_base64conv)(EOF,0);
                OCONV_NEWLINE((*o_base64conv));
                (*o_base64conv)(0,SP);
@@ -4843,14 +4853,17 @@ mime_putc(nkf_char c)
                    return;
                }
            }
-           (*o_mputc)(c);
-           base64_count++;
+           if (c != 0x1B) {
+               (*o_mputc)(c);
+               base64_count++;
+               return;
+           }
        }
-       return;
     }
 
     if (mimeout_mode <= 0) {
-       if (c <= DEL && (output_mode==ASCII ||output_mode == ISO_8859_1)) {
+       if (c <= DEL && (output_mode==ASCII || output_mode == ISO_8859_1 ||
+                   output_mode == UTF_8)) {
            if (nkf_isspace(c)) {
                int flag = 0;
                if (mimeout_mode == -1) {
@@ -4941,14 +4954,15 @@ mime_putc(nkf_char c)
        }
     }else{
        /* mimeout_mode == 'B', 1, 2 */
-       if ( c<=DEL && (output_mode==ASCII ||output_mode == ISO_8859_1)) {
+       if (c <= DEL && (output_mode==ASCII || output_mode == ISO_8859_1 ||
+                   output_mode == UTF_8)) {
            if (lastchar == CR || lastchar == LF){
                if (nkf_isblank(c)) {
                    for (i=0;i<mimeout_state.count;i++) {
                        mimeout_addchar(mimeout_state.buf[i]);
                    }
                    mimeout_state.count = 0;
-               } else if (SP<c && c<DEL) {
+               } else {
                    eof_mime();
                    for (i=0;i<mimeout_state.count;i++) {
                        (*o_mputc)(mimeout_state.buf[i]);
@@ -5244,6 +5258,8 @@ module_connection(void)
     set_output_encoding(output_encoding);
     oconv = nkf_enc_to_oconv(output_encoding);
     o_putc = std_putc;
+    if (nkf_enc_unicode_p(output_encoding))
+       output_mode = UTF_8;
 
     /* replace continucation module, from output side */