OSDN Git Service

Show "(BOM)" if the byte sequence has BOM.
authorNARUSE, Yui <naruse@users.sourceforge.jp>
Sat, 17 Mar 2012 11:50:17 +0000 (20:50 +0900)
committerNARUSE, Yui <naruse@users.sourceforge.jp>
Sat, 17 Mar 2012 11:50:17 +0000 (20:50 +0900)
http://sourceforge.jp/ticket/browse.php?group_id=248&tid=26325

nkf.c

diff --git a/nkf.c b/nkf.c
index b9df10e..ee855d8 100644 (file)
--- a/nkf.c
+++ b/nkf.c
  *
  * 3. This notice may not be removed or altered from any source distribution.
  */
  *
  * 3. This notice may not be removed or altered from any source distribution.
  */
-#define NKF_VERSION "2.1.2"
-#define NKF_RELEASE_DATE "2011-09-08"
+#define NKF_VERSION "2.1.3"
+#define NKF_RELEASE_DATE "2012-03-17"
 #define COPY_RIGHT \
     "Copyright (C) 1987, FUJITSU LTD. (I.Ichikawa).\n" \
 #define COPY_RIGHT \
     "Copyright (C) 1987, FUJITSU LTD. (I.Ichikawa).\n" \
-    "Copyright (C) 1996-2011, The nkf Project."
+    "Copyright (C) 1996-2012, The nkf Project."
 
 #include "config.h"
 #include "nkf.h"
 
 #include "config.h"
 #include "nkf.h"
@@ -356,6 +356,7 @@ static  int     no_cp932ext_f = FALSE;
 /* ignore ZERO WIDTH NO-BREAK SPACE */
 static  int     no_best_fit_chars_f = FALSE;
 static  int     input_endian = ENDIAN_BIG;
 /* ignore ZERO WIDTH NO-BREAK SPACE */
 static  int     no_best_fit_chars_f = FALSE;
 static  int     input_endian = ENDIAN_BIG;
+static  int     input_bom_f = FALSE;
 static  nkf_char     unicode_subchar = '?'; /* the regular substitution character */
 static  void    (*encode_fallback)(nkf_char c) = NULL;
 static  void    w_status(struct input_code *, nkf_char);
 static  nkf_char     unicode_subchar = '?'; /* the regular substitution character */
 static  void    (*encode_fallback)(nkf_char c) = NULL;
 static  void    w_status(struct input_code *, nkf_char);
@@ -3202,6 +3203,7 @@ check_bom(FILE *f)
                        set_iconv(TRUE, w_iconv32);
                    }
                    if (iconv == w_iconv32) {
                        set_iconv(TRUE, w_iconv32);
                    }
                    if (iconv == w_iconv32) {
+                       input_bom_f = TRUE;
                        input_endian = ENDIAN_BIG;
                        return;
                    }
                        input_endian = ENDIAN_BIG;
                        return;
                    }
@@ -3232,6 +3234,7 @@ check_bom(FILE *f)
                    set_iconv(TRUE, w_iconv);
                }
                if (iconv == w_iconv) {
                    set_iconv(TRUE, w_iconv);
                }
                if (iconv == w_iconv) {
+                   input_bom_f = TRUE;
                    return;
                }
                (*i_ungetc)(0xBF,f);
                    return;
                }
                (*i_ungetc)(0xBF,f);
@@ -3260,6 +3263,7 @@ check_bom(FILE *f)
            }
            if (iconv == w_iconv16) {
                input_endian = ENDIAN_BIG;
            }
            if (iconv == w_iconv16) {
                input_endian = ENDIAN_BIG;
+               input_bom_f = TRUE;
                return;
            }
            (*i_ungetc)(0xFF,f);
                return;
            }
            (*i_ungetc)(0xFF,f);
@@ -3275,6 +3279,7 @@ check_bom(FILE *f)
                    }
                    if (iconv == w_iconv32) {
                        input_endian = ENDIAN_LITTLE;
                    }
                    if (iconv == w_iconv32) {
                        input_endian = ENDIAN_LITTLE;
+                       input_bom_f = TRUE;
                        return;
                    }
                    (*i_ungetc)(0x00,f);
                        return;
                    }
                    (*i_ungetc)(0x00,f);
@@ -3286,6 +3291,7 @@ check_bom(FILE *f)
            }
            if (iconv == w_iconv16) {
                input_endian = ENDIAN_LITTLE;
            }
            if (iconv == w_iconv16) {
                input_endian = ENDIAN_LITTLE;
+               input_bom_f = TRUE;
                return;
            }
            (*i_ungetc)(0xFE,f);
                return;
            }
            (*i_ungetc)(0xFE,f);
@@ -4190,12 +4196,13 @@ print_guessed_code(char *filename)
        if (guess_f == 1) {
            printf("%s\n", input_codename);
        } else {
        if (guess_f == 1) {
            printf("%s\n", input_codename);
        } else {
-           printf("%s%s%s\n",
+           printf("%s%s%s%s\n",
                   input_codename,
                   iconv != w_iconv16 && iconv != w_iconv32 ? "" :
                   input_endian == ENDIAN_LITTLE ? " LE" :
                   input_endian == ENDIAN_BIG ? " BE" :
                   "[BUG]",
                   input_codename,
                   iconv != w_iconv16 && iconv != w_iconv32 ? "" :
                   input_endian == ENDIAN_LITTLE ? " LE" :
                   input_endian == ENDIAN_BIG ? " BE" :
                   "[BUG]",
+                  input_bom_f ? " (BOM)" : "",
                   input_eol == CR   ? " (CR)" :
                   input_eol == LF   ? " (LF)" :
                   input_eol == CRLF ? " (CRLF)" :
                   input_eol == CR   ? " (CR)" :
                   input_eol == LF   ? " (LF)" :
                   input_eol == CRLF ? " (CRLF)" :