OSDN Git Service

Release 2.1.1.
[nkf/nkf.git] / nkf32dll.c
index cad89be..0ec2a63 100644 (file)
@@ -1,14 +1,14 @@
 /* nkf32.dll nfk32dll.c */
 /* 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 */
 
 /*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.8"
+#define NKF_VERSIONW L"2.1.1"
 /* NKF_VERSION \82Ì\83\8f\83C\83h\95\8e\9a */
 /* NKF_VERSION \82Ì\83\8f\83C\83h\95\8e\9a */
-#define DLL_VERSION   "2.0.8.0 1"
+#define DLL_VERSION   "2.1.1.0 2"
 /* DLL\82ª\95Ô\82· */
 /* DLL\82ª\95Ô\82· */
-#define DLL_VERSIONW L"2.0.8.0 1"
+#define DLL_VERSIONW L"2.1.1.0 2"
 /* DLL\82ª\95Ô\82· DLL_VERSION \82Ì\83\8f\83C\83h\95\8e\9a */
 
 /* nkf32.dll main */
 /* DLL\82ª\95Ô\82· DLL_VERSION \82Ì\83\8f\83C\83h\95\8e\9a */
 
 /* nkf32.dll main */
@@ -53,7 +53,7 @@ wchar_t *guessbuffW = NULL;
 UINT guessCodePage = CP_OEMCP;
 DWORD guessdwFlags = MB_PRECOMPOSED;
 
 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;
 {
 static wchar_t buff[GUESS];
     int sts;
@@ -127,8 +127,8 @@ int
 std_getc(f)
 FILE *f;
 {
 std_getc(f)
 FILE *f;
 {
-    if (std_gc_ndx){
-        return std_gc_buf[--std_gc_ndx];
+    if (!nkf_buf_empty_p(nkf_state->std_gc_buf)) {
+        return nkf_buf_pop(nkf_state->std_gc_buf);
     } else {
         if ( std_getc_mode == 1 ) {
             return getc(f);
     } else {
         if ( std_getc_mode == 1 ) {
             return getc(f);
@@ -182,14 +182,7 @@ void
 print_guessed_code (filename)
     char *filename;
 {
 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);
     if (filename != NULL) {
         guessbuffA = realloc(guessbuffA,(strlen(filename) + GUESS + 1) * sizeof (char) );
         sprintf(guessbuffA,"%s:%s", filename,codename);
@@ -204,20 +197,16 @@ void
 print_guessed_codeW (filename)
     wchar_t *filename;
 {
 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;
-        }
-    }
+    const char *codename = get_guessed_code();
+    size_t size;
     if (filename != NULL) {
     if (filename != NULL) {
-        guessbuffW = realloc(guessbuffW,(wcslen(filename) + GUESS + 1) * sizeof (wchar_t) );
-        swprintf(guessbuffW,L"%s:%s",filename,tounicode(codename));
+       size = (wcslen(filename) + GUESS + 1) * sizeof (wchar_t);
+       guessbuffW = realloc(guessbuffW, size);
+       _snwprintf(guessbuffW, size, L"%s:%s", filename, tounicode(codename));
     } else {
     } else {
-        guessbuffW = realloc(guessbuffW,(GUESS + 1) * sizeof (wchar_t));
-        swprintf(guessbuffW,L"%s",tounicode(codename));
+       size = (GUESS + 1) * sizeof (wchar_t);
+       guessbuffW = realloc(guessbuffW, size);
+       _snwprintf(guessbuffW, size, L"%s", tounicode(codename));
     }
 }
 #endif /*UNICODESUPPORT*/
     }
 }
 #endif /*UNICODESUPPORT*/
@@ -236,8 +225,8 @@ print_guessed_codeW (filename)
  **
  **/
 
  **
  **/
 
-void 
-reinitdll()
+void
+reinitdll(void)
 {
     cin = NULL;
     nin = -1;
 {
     cin = NULL;
     nin = -1;
@@ -331,27 +320,38 @@ BOOL WINAPI GetNkfVersionSafeW(LPWSTR verStr,DWORD nBufferLength /*in TCHARs*/,L
 #endif /*UNICODESUPPORT*/
 }
 
 #endif /*UNICODESUPPORT*/
 }
 
-int CALLBACK SetNkfOption(LPCSTR optStr)
+static LPSTR optStr0 = NULL;
+
+int CALLBACK SetNkfOption(LPSTR optStr)
 {
     LPSTR p;
 {
     LPSTR p;
+    int len;
 
     if ( *optStr == '-' ) {
 
     if ( *optStr == '-' ) {
-        reinit();
-        options(optStr);
+        len = strlen(optStr) + 1;
+        p = realloc(optStr0,len);
+        strcpy(p,optStr);
     } else {
     } else {
-        p = malloc(strlen(optStr) + 2);
-        if ( p == NULL ) return -1;
+        len = strlen(optStr) + 2;
+        p = realloc(optStr0,len);
         *p = '-';
         strcpy(p + 1,optStr);
         *p = '-';
         strcpy(p + 1,optStr);
-        reinit();
-        options(p);
-        free(p);
     }
     }
+    optStr0 = p;
     return 0;
 }
 
     return 0;
 }
 
+void options0(void)
+{
+    reinit();
+    if ( optStr0 != NULL ) {
+        options(optStr0);
+    }
+}
+
 void CALLBACK NkfConvert(LPSTR outStr, LPCSTR inStr)
 {
 void CALLBACK NkfConvert(LPSTR outStr, LPCSTR inStr)
 {
+    options0();
     std_putc_mode = 2;
     cout = outStr;
     noutmax = -1;
     std_putc_mode = 2;
     cout = outStr;
     noutmax = -1;
@@ -366,6 +366,7 @@ void CALLBACK NkfConvert(LPSTR outStr, LPCSTR inStr)
 
 BOOL WINAPI NkfConvertSafe(LPSTR outStr,DWORD nOutBufferLength /*in Bytes*/,LPDWORD lpBytesReturned /*in Bytes*/, LPCSTR inStr,DWORD nInBufferLength /*in Bytes*/){
     if ( inStr == NULL ) return FALSE;
 
 BOOL WINAPI NkfConvertSafe(LPSTR outStr,DWORD nOutBufferLength /*in Bytes*/,LPDWORD lpBytesReturned /*in Bytes*/, LPCSTR inStr,DWORD nInBufferLength /*in Bytes*/){
     if ( inStr == NULL ) return FALSE;
+    options0();
     std_putc_mode = 6;
     cout = outStr;
     noutmax = nOutBufferLength;
     std_putc_mode = 6;
     cout = outStr;
     noutmax = nOutBufferLength;
@@ -389,7 +390,6 @@ void CALLBACK ToHankaku(LPSTR inStr)
     p = malloc(len);
     if ( p == NULL ) return;
     memcpy(p,inStr,len);
     p = malloc(len);
     if ( p == NULL ) return;
     memcpy(p,inStr,len);
-    reinit();
     options("-ZSs");
     NkfConvert(inStr,p);
     free(p);
     options("-ZSs");
     NkfConvert(inStr,p);
     free(p);
@@ -397,34 +397,29 @@ void CALLBACK ToHankaku(LPSTR inStr)
 
 BOOL WINAPI ToHankakuSafe(LPSTR outStr,DWORD nOutBufferLength /*in Bytes*/,LPDWORD lpBytesReturned /*in Bytes*/,LPCSTR inStr,DWORD nInBufferLength /*in Bytes*/)
 {
 
 BOOL WINAPI ToHankakuSafe(LPSTR outStr,DWORD nOutBufferLength /*in Bytes*/,LPDWORD lpBytesReturned /*in Bytes*/,LPCSTR inStr,DWORD nInBufferLength /*in Bytes*/)
 {
-    reinit();
     options("-ZSs");
     return NkfConvertSafe(outStr,nOutBufferLength,lpBytesReturned,inStr,nInBufferLength);
 }
 
 void CALLBACK ToZenkakuKana(LPSTR outStr, LPCSTR inStr)
 {
     options("-ZSs");
     return NkfConvertSafe(outStr,nOutBufferLength,lpBytesReturned,inStr,nInBufferLength);
 }
 
 void CALLBACK ToZenkakuKana(LPSTR outStr, LPCSTR inStr)
 {
-    reinit();
     options("-Ss");
     NkfConvert(outStr, inStr);
 }
 
 BOOL WINAPI ToZenkakuKanaSafe(LPSTR outStr,DWORD nOutBufferLength /*in Bytes*/,LPDWORD lpBytesReturned /*in Bytes*/,LPCSTR inStr,DWORD nInBufferLength /*in Bytes*/)
 {
     options("-Ss");
     NkfConvert(outStr, inStr);
 }
 
 BOOL WINAPI ToZenkakuKanaSafe(LPSTR outStr,DWORD nOutBufferLength /*in Bytes*/,LPDWORD lpBytesReturned /*in Bytes*/,LPCSTR inStr,DWORD nInBufferLength /*in Bytes*/)
 {
-    reinit();
     options("-Ss");
     return NkfConvertSafe(outStr,nOutBufferLength,lpBytesReturned,inStr,nInBufferLength);
 }
 
 void CALLBACK EncodeSubject(LPSTR outStr ,LPCSTR inStr){
     options("-Ss");
     return NkfConvertSafe(outStr,nOutBufferLength,lpBytesReturned,inStr,nInBufferLength);
 }
 
 void CALLBACK EncodeSubject(LPSTR outStr ,LPCSTR inStr){
-    reinit();
     options("-jM");
     NkfConvert(outStr, inStr);
 }
 
 BOOL WINAPI EncodeSubjectSafe(LPSTR outStr,DWORD nOutBufferLength /*in Bytes*/,LPDWORD lpBytesReturned /*in Bytes*/,LPCSTR inStr,DWORD nInBufferLength /*in Bytes*/)
 {
     options("-jM");
     NkfConvert(outStr, inStr);
 }
 
 BOOL WINAPI EncodeSubjectSafe(LPSTR outStr,DWORD nOutBufferLength /*in Bytes*/,LPDWORD lpBytesReturned /*in Bytes*/,LPCSTR inStr,DWORD nInBufferLength /*in Bytes*/)
 {
-    reinit();
     options("-jM");
     return NkfConvertSafe(outStr,nOutBufferLength,lpBytesReturned,inStr,nInBufferLength);
 }
     options("-jM");
     return NkfConvertSafe(outStr,nOutBufferLength,lpBytesReturned,inStr,nInBufferLength);
 }
@@ -440,7 +435,7 @@ void CALLBACK ToMime(LPSTR outStr ,LPCSTR inStr)
 int CALLBACK NkfGetKanjiCode(VOID)
 {
     int iCode=0;
 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(input_endian == ENDIAN_BIG)iCode=5; /* 5:UTF-16BE */
     if(iconv == w_iconv)iCode=3; /* UTF-8 */
     else if(iconv == w_iconv16){
         if(input_endian == ENDIAN_BIG)iCode=5; /* 5:UTF-16BE */
@@ -463,6 +458,7 @@ void CALLBACK NkfFileConvert1(LPCSTR fName)
     DWORD len;
     BOOL sts;
 
     DWORD len;
     BOOL sts;
 
+    options0();
     len = GetTempPath(sizeof d,d);
     tempdname = malloc(len + 1);
     if ( tempdname == NULL ) return;
     len = GetTempPath(sizeof d,d);
     tempdname = malloc(len + 1);
     if ( tempdname == NULL ) return;
@@ -504,6 +500,7 @@ BOOL WINAPI NkfFileConvert1SafeA(LPCSTR fName,DWORD nBufferLength /*in TCHARs*/)
     BOOL ret;
     LPCSTR p;
 
     BOOL ret;
     LPCSTR p;
 
+    options0();
     ret = FALSE;
     p = fName;
     for ( ;; ) {
     ret = FALSE;
     p = fName;
     for ( ;; ) {
@@ -556,6 +553,7 @@ BOOL WINAPI NkfFileConvert1SafeW(LPCWSTR fName,DWORD nBufferLength /*in TCHARs*/
     BOOL ret;
     LPCWSTR p;
 
     BOOL ret;
     LPCWSTR p;
 
+    options0();
     ret = FALSE;
     p = fName;
     for ( ;; ) {
     ret = FALSE;
     p = fName;
     for ( ;; ) {
@@ -604,6 +602,7 @@ void CALLBACK NkfFileConvert2(LPCSTR fInName,LPCSTR fOutName)
 {
     FILE *fin;
 
 {
     FILE *fin;
 
+    options0();
     if ((fin = fopen(fInName, "rb")) == NULL) return;
     if((fout=fopen(fOutName, "wb")) == NULL) {
         fclose(fin);
     if ((fin = fopen(fInName, "rb")) == NULL) return;
     if((fout=fopen(fOutName, "wb")) == NULL) {
         fclose(fin);
@@ -630,6 +629,7 @@ BOOL WINAPI NkfFileConvert2SafeA(LPCSTR fInName,DWORD fInBufferLength /*in TCHAR
     BOOL ret;
     LPCSTR p;
 
     BOOL ret;
     LPCSTR p;
 
+    options0();
     ret = FALSE;
     p = fInName;
     for ( ;; ) {
     ret = FALSE;
     p = fInName;
     for ( ;; ) {
@@ -672,6 +672,7 @@ BOOL WINAPI NkfFileConvert2SafeW(LPCWSTR fInName,DWORD fInBufferLength /*in TCHA
     BOOL ret;
     LPCWSTR p;
 
     BOOL ret;
     LPCWSTR p;
 
+    options0();
     ret = FALSE;
     p = fInName;
     for ( ;; ) {
     ret = FALSE;
     p = fInName;
     for ( ;; ) {
@@ -756,7 +757,7 @@ BOOL WINAPI GetNkfSupportFunctions(void *outStr,DWORD nBufferLength /*in Bytes*/
 {
     *lpBytesReturned = sizeof NkfSupportFunctions;
     if ( outStr == NULL || nBufferLength == 0 ) return FALSE;
 {
     *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;
 }
     memcpy(outStr,&NkfSupportFunctions,sizeof NkfSupportFunctions > nBufferLength ? nBufferLength : sizeof NkfSupportFunctions);
     return TRUE;
 }