From: Rei FURUKAWA Date: Mon, 18 Apr 2005 03:47:15 +0000 (+0000) Subject: patch (by mastodon) X-Git-Tag: v2_0_6_beta2~43 X-Git-Url: http://git.sourceforge.jp/view?p=nkf%2Fnkf.git;a=commitdiff_plain;h=2a941dd1f586ba3b98584e2002696c275e3ad667 patch (by mastodon) --- diff --git a/nkf.c b/nkf.c index 4e29e9d..0fd0059 100644 --- a/nkf.c +++ b/nkf.c @@ -39,7 +39,7 @@ ** E-Mail: furukawa@tcp-ip.or.jp ** $B$^$G8fO"Mm$r$*4j$$$7$^$9!#(B ***********************************************************************/ -/* $Id: nkf.c,v 1.67 2005/04/09 21:06:20 rei_furukawa Exp $ */ +/* $Id: nkf.c,v 1.68 2005/04/17 18:47:15 rei_furukawa Exp $ */ #define NKF_VERSION "2.0.5" #define NKF_RELEASE_DATE "2005-04-10" #include "config.h" @@ -208,8 +208,8 @@ static char *CopyRight = #define UTF8 12 #define UTF8_INPUT 13 -#define UTF16LE_INPUT 14 -#define UTF16BE_INPUT 15 +#define UTF16BE_INPUT 14 +#define UTF16LE_INPUT 15 #define WISH_TRUE 15 @@ -465,7 +465,7 @@ STATIC void s_status PROTO((struct input_code *, int)); #ifdef UTF8_INPUT_ENABLE STATIC void w_status PROTO((struct input_code *, int)); STATIC void w16_status PROTO((struct input_code *, int)); -static int utf16_mode = UTF16LE_INPUT; +static int utf16_mode = UTF16BE_INPUT; #endif struct input_code input_code_list[] = { @@ -1177,12 +1177,17 @@ options(cp) #ifdef UTF8_INPUT_ENABLE case 'W': /* UTF-8 input */ if ('1'== cp[0] && '6'==cp[1]) { - input_f = UTF16LE_INPUT; + input_f = UTF16BE_INPUT; + utf16_mode = UTF16BE_INPUT; + cp += 2; if (cp[0]=='L') { cp++; + input_f = UTF16LE_INPUT; + utf16_mode = UTF16LE_INPUT; } else if (cp[0] == 'B') { cp++; input_f = UTF16BE_INPUT; + utf16_mode = UTF16BE_INPUT; } } else if (cp[0] == '8') { cp++; @@ -1863,6 +1868,8 @@ module_connection() #ifdef UTF8_INPUT_ENABLE } else if (input_f == UTF8_INPUT) { set_iconv(-TRUE, w_iconv); + } else if (input_f == UTF16BE_INPUT) { + set_iconv(-TRUE, w_iconv16); } else if (input_f == UTF16LE_INPUT) { set_iconv(-TRUE, w_iconv16); #endif @@ -2566,13 +2573,13 @@ w_iconv16(c2, c1, c0) int ret; if (c2==0376 && c1==0377){ - utf16_mode = UTF16LE_INPUT; + utf16_mode = UTF16BE_INPUT; return 0; } else if (c2==0377 && c1==0376){ - utf16_mode = UTF16BE_INPUT; + utf16_mode = UTF16LE_INPUT; return 0; } - if (c2 != EOF && utf16_mode == UTF16BE_INPUT) { + if (c2 != EOF && utf16_mode == UTF16LE_INPUT) { int tmp; tmp=c1; c1=c2; c2=tmp; } @@ -4625,7 +4632,7 @@ reinit() } } #ifdef UTF8_INPUT_ENABLE - utf16_mode = UTF16LE_INPUT; + utf16_mode = UTF16BE_INPUT; #endif mimeout_buf_count = 0; mimeout_mode = 0; diff --git a/nkf32dll.c b/nkf32dll.c index 227fffd..18983ae 100644 --- a/nkf32dll.c +++ b/nkf32dll.c @@ -4,20 +4,21 @@ /*WIN32DLL*/ /* ‚±‚¿‚ç‚̃o[ƒWƒ‡ƒ“‚àXV‚µ‚Ä‚­‚¾‚³‚¢B */ -#define NKF_VERSIONW L"2.0.4" +#define NKF_VERSIONW L"2.0.5" /* NKF_VERSION ‚̃ƒCƒh•¶Žš */ -#define DLL_VERSION "2.0.4.1 1" +#define DLL_VERSION "2.0.5.0 2" /* DLL‚ª•Ô‚· */ -#define DLL_VERSIONW L"2.0.4.1 1" +#define DLL_VERSIONW L"2.0.5.0 2" /* DLL‚ª•Ô‚· DLL_VERSION ‚̃ƒCƒh•¶Žš */ /* nkf32.dll main */ #include #include #include -#include "nkf.h" #ifdef DLLDBG /* DLLDBG @@*/ +#include "nkf.h" + void dumpn(unsigned char *buff,unsigned n) { int i; @@ -46,9 +47,9 @@ void mkfile(char *f,char *p); #define GUESS 64 #endif /*GUESS*/ -char guessbuffA[MAX_PATH + GUESS]; +char *guessbuffA = NULL; #ifdef UNICODESUPPORT -wchar_t guessbuffW[MAX_PATH + GUESS]; +wchar_t *guessbuffW = NULL; UINT guessCodePage = CP_OEMCP; DWORD guessdwFlags = MB_PRECOMPOSED; @@ -190,17 +191,36 @@ print_guessed_code (filename) } } if (filename != NULL) { + guessbuffA = realloc(guessbuffA,(strlen(filename) + GUESS + 1) * sizeof (char) ); sprintf(guessbuffA,"%s:%s", filename,codename); -#ifdef UNICODESUPPORT - swprintf(guessbuffW,L"%s:%s",filename,tounicode(codename)); -#endif /*UNICODESUPPORT*/ } else { + guessbuffA = realloc(guessbuffA,(GUESS + 1) * sizeof (char) ); sprintf(guessbuffA,"%s", codename); + } +} + #ifdef UNICODESUPPORT +void +print_guessed_codeW (filename) + wchar_t *filename; +{ + char *codename = "BINARY"; + if (!is_inputcode_mixed) { + if (strcmp(input_codename, "") == 0) { + codename = "ASCII"; + } else { + codename = input_codename; + } + } + if (filename != NULL) { + guessbuffW = realloc(guessbuffW,(wcslen(filename) + GUESS + 1) * sizeof (wchar_t) ); + swprintf(guessbuffW,L"%s:%s",filename,tounicode(codename)); + } else { + guessbuffW = realloc(guessbuffW,(GUESS + 1) * sizeof (wchar_t)); swprintf(guessbuffW,L"%s",tounicode(codename)); -#endif /*UNICODESUPPORT*/ } } +#endif /*UNICODESUPPORT*/ /** ** ƒpƒbƒ`§ìŽÒ @@ -228,6 +248,16 @@ reinitdll() nout = -1; noutmax = -1; std_putc_mode = 1; + if ( guessbuffA ) { + free(guessbuffA); + guessbuffA = NULL; + } +#ifdef UNICODESUPPORT + if ( guessbuffW ) { + free(guessbuffW); + guessbuffW = NULL; + } +#endif /*UNICODESUPPORT*/ } #ifndef DLLDBG /* DLLDBG @@*/ @@ -413,7 +443,7 @@ int CALLBACK NkfGetKanjiCode(VOID) //if(iconv == s_iconv)iCode=0; /* 0:ƒVƒtƒgJIS */ if(iconv == w_iconv)iCode=3; /* UTF-8 */ else if(iconv == w_iconv16){ - if(utf16_mode == UTF16LE_INPUT)iCode=5; /* 5:UTF-16BE */ + if(utf16_mode == UTF16BE_INPUT)iCode=5; /* 5:UTF-16BE */ else iCode=4; /* 4:UTF-16LE */ }else if(iconv == e_iconv){ if(estab_f == FALSE)iCode=2; /* 2:ISO-2022-JP */ @@ -691,7 +721,7 @@ BOOL WINAPI GetNkfGuessW(LPWSTR outStr,DWORD nBufferLength /*in TCHARs*/,LPDWORD { #ifdef UNICODESUPPORT if ( outStr == NULL || nBufferLength == 0 ) return FALSE; - print_guessed_code(NULL); + print_guessed_codeW(NULL); *lpTCHARsReturned = wcslen(guessbuffW) + 1; return wscp(outStr,guessbuffW,nBufferLength); #else /*UNICODESUPPORT*/ @@ -699,8 +729,14 @@ BOOL WINAPI GetNkfGuessW(LPWSTR outStr,DWORD nBufferLength /*in TCHARs*/,LPDWORD #endif /*UNICODESUPPORT*/ } -static struct NKFSUPPORTFUNCTIONS NkfSupportFunctions = { -sizeof(struct NKFSUPPORTFUNCTIONS), +static struct { +DWORD size; +LPCSTR copyrightA; +LPCSTR versionA; +LPCSTR dateA; +DWORD functions; +} NkfSupportFunctions = { +sizeof(NkfSupportFunctions), NULL, NKF_VERSION, NKF_RELEASE_DATE, @@ -957,7 +993,7 @@ int main(int argc,char **argv) file2(argv[2],argv[3],argv[4],buff3); break; case 'u': - sts = NkfUsage(buff,sizeof buff * 0 + 2073,&len); + sts = NkfUsage(buff,sizeof buff,&len); printf("strlen(buff)=%d\n",strlen(buff)); printf("NkfUsage()=%d len=%d \n%s",sts,len,buff); break;