* \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.178 2008/05/21 20:41:06 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
#endif
struct input_code{
- char *name;
+ const char *name;
nkf_char stat;
nkf_char score;
nkf_char index;
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;
-static int kanji_convert(FILE *f);
#if defined(UTF8_INPUT_ENABLE) || defined(UTF8_OUTPUT_ENABLE)
/* UCS Mapping
* 0: Shift_JIS, eucJP-ascii
#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;
#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
}
backup_filename[j] = '\0';
}else{
- backup_filename = malloc(filename_length + strlen(suffix) + 1);
+ j = filename_length + strlen(suffix);
+ backup_filename = malloc(j + 1);
strcpy(backup_filename, filename);
strcat(backup_filename, suffix);
backup_filename[j] = '\0';
nkf_char val;
#endif
static const char shift_jisx0213_s1a3_table[5][2] ={ { 1, 8}, { 3, 4}, { 5,12}, {13,14}, {15, 0} };
+ if (0xFC < c1) return 1;
#ifdef SHIFTJIS_CP932
if (!cp932inv_f && is_ibmext_in_sjis(c2)){
val = shiftjis_cp932[c2 - CP932_TABLE_BEGIN][c1 - 0x40];
}
if (cp932inv_f
&& CP932INV_TABLE_BEGIN <= c2 && c2 <= CP932INV_TABLE_END){
- nkf_char c = cp932inv[c2 - CP932INV_TABLE_BEGIN][c1 - 0x40];
- if (c){
- c2 = c >> 8;
- c1 = c & 0xff;
+ val = cp932inv[c2 - CP932INV_TABLE_BEGIN][c1 - 0x40];
+ if (val){
+ c2 = val >> 8;
+ c1 = val & 0xff;
}
}
#endif /* SHIFTJIS_CP932 */
c1 = val & 0xff;
if (!val) return;
}
+
if (output_endian == ENDIAN_LITTLE){
(*o_putc)(c1);
(*o_putc)(c2);
if (alpha_f&8 && c2 == 0) {
/* HTML Entity */
- char *entity = 0;
+ const char *entity = 0;
switch (c1){
case '>': entity = ">"; break;
case '<': entity = "<"; break;
#endif
static void
-set_input_codename(char *codename)
+set_input_codename(const char *codename)
{
if (!input_codename) {
input_codename = codename;
}
}
-static char*
+static const char*
get_guessed_code(void)
{
if (input_codename && !*input_codename) {
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);
{
nkf_char c1=0, c2=0, c3=0, c4=0;
int shift_mode = 0; /* 0, 1, 2, 3 */
- char g2 = 0;
+ int g2 = 0;
int is_8bit = FALSE;
if (input_encoding && !nkf_enc_asciicompat(input_encoding)) {
cp++;
input_endian = ENDIAN_BIG;
}
- enc_idx = enc_idx == UTF_16
- ? (output_endian == ENDIAN_LITTLE ? UTF_16LE : UTF_16BE)
- : (output_endian == ENDIAN_LITTLE ? UTF_32LE : UTF_32BE);
+ enc_idx = (enc_idx == UTF_16
+ ? (input_endian == ENDIAN_LITTLE ? UTF_16LE : UTF_16BE)
+ : (input_endian == ENDIAN_LITTLE ? UTF_32LE : UTF_32BE));
input_encoding = nkf_enc_from_index(enc_idx);
}
continue;