OSDN Git Service

* update nkf32.dll.
[nkf/nkf.git] / nkf32dll.c
index 227fffd..a3e8b89 100644 (file)
@@ -1,23 +1,24 @@
 /* nkf32.dll nfk32dll.c */
-// e-mail:tkaneto@nifty.com
-// URL: http://www1.ttcn.ne.jp/~kaneto
+/* e-mail:tkaneto@nifty.com */
+/* URL: http://www1.ttcn.ne.jp/~kaneto */
 
 /*WIN32DLL*/
 /* \82±\82¿\82ç\82Ì\83o\81[\83W\83\87\83\93\82à\8dX\90V\82µ\82Ä\82­\82¾\82³\82¢\81B */
-#define NKF_VERSIONW L"2.0.4"
+#define NKF_VERSIONW L"2.0.8"
 /* NKF_VERSION \82Ì\83\8f\83C\83h\95\8e\9a */
-#define DLL_VERSION   "2.0.4.1 1"
+#define DLL_VERSION   "2.0.8.0 1"
 /* DLL\82ª\95Ô\82· */
-#define DLL_VERSIONW L"2.0.4.1 1"
+#define DLL_VERSIONW L"2.0.8.0 1"
 /* DLL\82ª\95Ô\82· DLL_VERSION \82Ì\83\8f\83C\83h\95\8e\9a */
 
 /* nkf32.dll main */
 #include <windows.h>
 #include <tchar.h>
 #include <stdarg.h>
-#include "nkf.h"
 
 #ifdef DLLDBG /* DLLDBG @@*/
+#include "nkf.h"
+
 void dumpn(unsigned char *buff,unsigned n)
 {
     int i;
@@ -46,13 +47,13 @@ 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;
 
-wchar_t *tounicode(char *p)
+wchar_t *tounicode(const char *p)
 {
 static wchar_t buff[GUESS];
     int sts;
@@ -152,7 +153,7 @@ FILE *f;
     return EOF;
 }
 
-static FILE *fout = stdout;
+static FILE *fout = NULL;
 static unsigned char *cout = NULL;
 static int nout = -1;
 static int noutmax = -1;
@@ -181,26 +182,34 @@ void
 print_guessed_code (filename)
     char *filename;
 {
-    char *codename = "BINARY";
-    if (!is_inputcode_mixed) {
-        if (strcmp(input_codename, "") == 0) {
-            codename = "ASCII";
-        } else {
-            codename = input_codename;
-        }
-    }
+    const char *codename = get_guessed_code();
     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
-        swprintf(guessbuffW,L"%s",tounicode(codename));
-#endif /*UNICODESUPPORT*/
+void
+print_guessed_codeW (filename)
+    wchar_t *filename;
+{
+    const char *codename = get_guessed_code();
+    size_t size;
+    if (filename != NULL) {
+       size = (wcslen(filename) + GUESS + 1) * sizeof (wchar_t);
+       guessbuffW = realloc(guessbuffW, size);
+       _snwprintf(guessbuffW, size, L"%s:%s", filename, tounicode(codename));
+    } else {
+       size = (GUESS + 1) * sizeof (wchar_t);
+       guessbuffW = realloc(guessbuffW, size);
+       _snwprintf(guessbuffW, size, L"%s", tounicode(codename));
     }
 }
+#endif /*UNICODESUPPORT*/
 
 /**
  ** \83p\83b\83`\90§\8dì\8eÒ
@@ -216,8 +225,8 @@ print_guessed_code (filename)
  **
  **/
 
-void 
-reinitdll()
+void
+reinitdll(void)
 {
     cin = NULL;
     nin = -1;
@@ -228,6 +237,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 @@*/
@@ -301,7 +320,7 @@ BOOL WINAPI GetNkfVersionSafeW(LPWSTR verStr,DWORD nBufferLength /*in TCHARs*/,L
 #endif /*UNICODESUPPORT*/
 }
 
-int CALLBACK SetNkfOption(LPCSTR optStr)
+int CALLBACK SetNkfOption(LPSTR optStr)
 {
     LPSTR p;
 
@@ -410,10 +429,10 @@ void CALLBACK ToMime(LPSTR outStr ,LPCSTR inStr)
 int CALLBACK NkfGetKanjiCode(VOID)
 {
     int iCode=0;
-    //if(iconv == s_iconv)iCode=0; /* 0:\83V\83t\83gJIS */
+    /* if(iconv == s_iconv)iCode=0; */ /* 0:\83V\83t\83gJIS */
     if(iconv == w_iconv)iCode=3; /* UTF-8 */
     else if(iconv == w_iconv16){
-        if(utf16_mode == UTF16LE_INPUT)iCode=5; /* 5:UTF-16BE */
+        if(input_endian == ENDIAN_BIG)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 +710,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 +718,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,
@@ -720,7 +745,7 @@ BOOL WINAPI GetNkfSupportFunctions(void *outStr,DWORD nBufferLength /*in Bytes*/
 {
     *lpBytesReturned = sizeof NkfSupportFunctions;
     if ( outStr == NULL || nBufferLength == 0 ) return FALSE;
-    NkfSupportFunctions.copyrightA = CopyRight;
+    NkfSupportFunctions.copyrightA = COPY_RIGHT;
     memcpy(outStr,&NkfSupportFunctions,sizeof NkfSupportFunctions > nBufferLength ? nBufferLength : sizeof NkfSupportFunctions);
     return TRUE;
 }
@@ -957,7 +982,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;