OSDN Git Service

* nkf.c (numchar_getc): increase buffer size.
[nkf/nkf.git] / nkf.c
diff --git a/nkf.c b/nkf.c
index 8fa9d5b..045d877 100644 (file)
--- a/nkf.c
+++ b/nkf.c
@@ -31,9 +31,9 @@
  * \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.180 2008/09/18 18:40:48 naruse Exp $"
+#define NKF_IDENT "$Id: nkf.c,v 1.185 2008/10/28 13:42:25 naruse Exp $"
 #define NKF_VERSION "2.0.8"
-#define NKF_RELEASE_DATE "2008-02-08"
+#define NKF_RELEASE_DATE "2008-10-28"
 #define COPY_RIGHT \
     "Copyright (C) 1987, FUJITSU LTD. (I.Ichikawa),2000 S. Kono, COW\n" \
     "Copyright (C) 2002-2008 Kono, Furukawa, Naruse, mastodon"
 #include "config.h"
 #include "nkf.h"
 #include "utf8tbl.h"
+#ifdef __WIN32__
+#include <windows.h>
+#include <locale.h>
+#endif
 
 /* state of output_mode and input_mode
 
@@ -318,7 +322,7 @@ extern POINT _BufferSize;
 #endif
 
 struct input_code{
-    char *name;
+    const char *name;
     nkf_char stat;
     nkf_char score;
     nkf_char index;
@@ -328,7 +332,7 @@ struct input_code{
     int _file_stat;
 };
 
-static char *input_codename = NULL; /* NULL: unestablished, "": BINARY */
+static const char *input_codename = NULL; /* NULL: unestablished, "": BINARY */
 static nkf_encoding *input_encoding = NULL;
 static nkf_encoding *output_encoding = NULL;
 
@@ -438,7 +442,7 @@ static nkf_char (*iconv_for_check)(nkf_char c2,nkf_char c1,nkf_char c0) = 0;
 #endif
 
 static int guess_f = 0; /* 0: OFF, 1: ON, 2: VERBOSE */
-static  void    set_input_codename(char *codename);
+static  void    set_input_codename(const char *codename);
 
 #ifdef EXEC_IO
 static int exec_f = 0;
@@ -718,7 +722,16 @@ nkf_locale_charmap()
 #ifdef HAVE_LANGINFO_H
     return nl_langinfo(CODESET);
 #elif defined(__WIN32__)
-    return sprintf("CP%d", GetACP());
+    char buf[16];
+    char *str;
+    int len = sprintf(buf, "CP%d", GetACP());
+    if (len > 0) {
+      str = malloc(len + 1);
+      strcpy(str, buf);
+      str[len] = '\0';
+      return str;
+    }
+    else return NULL;
 #else
     return NULL;
 #endif
@@ -3501,7 +3514,7 @@ z_conv(nkf_char c2, nkf_char c1)
 
     if (alpha_f&8 && c2 == 0) {
        /* HTML Entity */
-       char *entity = 0;
+       const char *entity = 0;
        switch (c1){
        case '>': entity = "&gt;"; break;
        case '<': entity = "&lt;"; break;
@@ -3984,7 +3997,7 @@ debug(const char *str)
 #endif
 
 static void
-set_input_codename(char *codename)
+set_input_codename(const char *codename)
 {
     if (!input_codename) {
        input_codename = codename;
@@ -3993,7 +4006,7 @@ set_input_codename(char *codename)
     }
 }
 
-static char*
+static const char*
 get_guessed_code(void)
 {
     if (input_codename && !*input_codename) {
@@ -4100,7 +4113,7 @@ numchar_getc(FILE *f)
     nkf_char (*g)(FILE *) = i_ngetc;
     nkf_char (*u)(nkf_char c ,FILE *f) = i_nungetc;
     int i = 0, j;
-    nkf_char buf[8];
+    nkf_char buf[12];
     long c = -1;
 
     buf[i] = (*g)(f);