⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chnconv_dll_old.cpp

📁 This software performs code conversion of Chinese characters, including GB2312/GBK and BIG5. It a
💻 CPP
📖 第 1 页 / 共 2 页
字号:
   int cSrcChar ;
   int cDstChar ;
} USERDEF ;

static USERDEF *pUserDef ;
static size_t nNumberOfUserDef ;



int WINAPI SetUserDefinition ( int nSrcCodePage, int nDstCodePage, int cSrcChar, int cDstChar ) {

   if ( cSrcChar || cDstChar ) {

      USERDEF *pNew = (USERDEF*) realloc ( pUserDef, sizeof(USERDEF) * ( nNumberOfUserDef + 1 ) ) ;
      if ( ! pNew ) return 1 ;

      pUserDef = pNew ;

      ( pUserDef + nNumberOfUserDef )->nSrcCodePage = nSrcCodePage ;
      ( pUserDef + nNumberOfUserDef )->nDstCodePage = nDstCodePage ;
      ( pUserDef + nNumberOfUserDef )->cSrcChar = cSrcChar ;
      ( pUserDef + nNumberOfUserDef )->cDstChar = cDstChar ;

      nNumberOfUserDef ++ ;

   }
   else if ( nSrcCodePage || nDstCodePage ) {

      for ( int nCount = 0 ; nCount < (int) nNumberOfUserDef ; nCount ++ ) {

         if ( ( pUserDef + nCount )->nSrcCodePage != nSrcCodePage ) continue ;
         if ( ( pUserDef + nCount )->nDstCodePage != nDstCodePage ) continue ;

         memmove ( pUserDef + nCount, pUserDef + nCount + 1, ( nNumberOfUserDef - nCount - 1 ) * sizeof(USERDEF) ) ;
         nNumberOfUserDef -- ;
      }

   }
   else {
      free ( pUserDef ) ;
      pUserDef = NULL ;
      nNumberOfUserDef = 0 ;
   }

   if ( ! InterlockedExchange ( & IsFreeBufferProcRegistered, TRUE ) ) atexit ( FreeBuffer ) ;

   return 0 ;
}



static CHNCONV_USERDEF *AllocCurrentUserDefinition ( int nSrcCodePage, int nDstCodePage, size_t *pLength ) {

   CHNCONV_USERDEF *pResult = NULL ;
   size_t nLength = 0 ;

   if ( nSrcCodePage == CP_HZ_CHINESE_SIMPLIFIED ) nSrcCodePage = CP_CHINESE_SIMPLIFIED ;
   if ( nDstCodePage == CP_HZ_CHINESE_SIMPLIFIED ) nDstCodePage = CP_CHINESE_SIMPLIFIED ;

   for ( int nCount = 0 ; nCount < (int) nNumberOfUserDef ; nCount ++ ) {

      if ( ( pUserDef + nCount )->nSrcCodePage != nSrcCodePage ) continue ;
      if ( ( pUserDef + nCount )->nDstCodePage != nDstCodePage ) continue ;

      CHNCONV_USERDEF *pNew = (CHNCONV_USERDEF*) realloc ( pResult, sizeof(CHNCONV_USERDEF) * ( nLength + 1 ) ) ;
      if ( ! pNew ) break ;

      pResult = pNew ;

      ( pResult + nLength )->nSrc = ( pUserDef + nCount )->cSrcChar ;
      ( pResult + nLength )->nDst = ( pUserDef + nCount )->cDstChar ;

      nLength ++ ;
   }

   *pLength = nLength ;
   return pResult ;
}



void __cdecl FreeBuffer ( void ) {

   free ( (char*) FontInfo.pGbFont ) ;
   free ( (char*) FontInfo.pGbGothicFont ) ;
   free ( (char*) FontInfo.pBig5Font ) ;
   free ( (char*) FontInfo.pBig5GothicFont ) ;
   free ( (char*) FontInfo.pPinyinFont ) ;
   free ( (char*) FontInfo.pPinyinGothicFont ) ;

   free ( pUserDef ) ;

}



////////////////////////////////////////////
//               媽娭悢 (4)               //
////////////////////////////////////////////



// 僾儘億乕僔儑僫儖偺儌乕僪傪愝掕乮for TM2RTF乯
int WINAPI SetTmPropMode ( unsigned long dwMode ) {

   if ( LockSemaphore () ) return 1 ;

   if ( dwMode & TMMODE_WRITE_COMMENT ) Info.dwAdditionalMode |= ADDITIONAL_MODE_WRITE_TM_COMMENT ;
   else                                 Info.dwAdditionalMode &= ~ ADDITIONAL_MODE_WRITE_TM_COMMENT ;

   dwConversionModeTm = 0 ;
   if ( dwMode & TMMODE_ASCII_ALL )   dwConversionModeTm |= CONVMODE_PINYIN_BY_ASCII ;
   if ( dwMode & TMMODE_ASCII_ALPHA ) dwConversionModeTm |= CONVMODE_PINYIN_BY_ASCII ;

   UnlockSemaphore () ;
   return 0 ;
}



// 僼僅儞僩僒僀僘傪愝掕乮for TM2RTF乯
int WINAPI SetTmFontSize ( int nSize ) {

   if ( LockSemaphore () ) return 1 ;

   if ( nSize > 0 )    Info.nFontSize = nSize ;
   else if ( ! nSize ) Info.nFontSize = -1 ;

   UnlockSemaphore () ;
   return 0 ;
}



int WINAPI SetTmAsciiFontChar ( int C ) {
   return 0 ;
}



////////////////////////////////////////////
//               媽娭悢 (5)               //
////////////////////////////////////////////



int WINAPI SetChnconvWindow ( HWND hWnd, int IsDialog ) {
   return 0 ;
}



////////////////////////////////////////////
//               媽娭悢 (6)               //
////////////////////////////////////////////



int WINAPI PrintFileStartA ( int nDstCodePage, const char *szDstFileName ) {

   if ( LockSemaphore () ) return SetChnconvLastError ( CONV_ERROR_SEMAPHORE ) ;

   Info.cbSize = sizeof(CHNCONVEXINFO) ;
   Info.dwConversionMode = 0 ;

   RESERVEDINFO ReservedInfo = { sizeof(RESERVEDINFO) } ;
   ReservedInfo.dwMode = RESERVEDMODE_ONLY_START ;
   Info.pReserved = (void*) & ReservedInfo ;

   int nResult = ChnconvExA ( NULL, szDstFileName, CP_JAPANESE_TM, nDstCodePage, & Info ) ;

   UnlockSemaphore () ;
   return nResult ;
}



int WINAPI PrintFileStartW ( int nDstCodePage, const wchar_t *szDstFileName ) {

   if ( LockSemaphore () ) return SetChnconvLastError ( CONV_ERROR_SEMAPHORE ) ;

   Info.cbSize = sizeof(CHNCONVEXINFO) ;
   Info.dwConversionMode = 0 ;

   RESERVEDINFO ReservedInfo = { sizeof(RESERVEDINFO) } ;
   ReservedInfo.dwMode = RESERVEDMODE_ONLY_START ;
   Info.pReserved = (void*) & ReservedInfo ;

   int nResult = ChnconvExW ( NULL, szDstFileName, CP_JAPANESE_TM, nDstCodePage, & Info ) ;

   UnlockSemaphore () ;
   return nResult ;
}



int WINAPI PrintFileEndA ( int nDstCodePage, const char *szDstFileName ) {

   if ( LockSemaphore () ) return SetChnconvLastError ( CONV_ERROR_SEMAPHORE ) ;

   Info.cbSize = sizeof(CHNCONVEXINFO) ;
   Info.dwConversionMode = 0 ;

   RESERVEDINFO ReservedInfo = { sizeof(RESERVEDINFO) } ;
   ReservedInfo.dwMode = RESERVEDMODE_ONLY_END ;
   Info.pReserved = (void*) & ReservedInfo ;

   int nResult = ChnconvExA ( NULL, szDstFileName, CP_JAPANESE_TM, nDstCodePage, & Info ) ;

   UnlockSemaphore () ;
   return nResult ;
}



int WINAPI PrintFileEndW ( int nDstCodePage, const wchar_t *szDstFileName ) {

   if ( LockSemaphore () ) return SetChnconvLastError ( CONV_ERROR_SEMAPHORE ) ;

   Info.cbSize = sizeof(CHNCONVEXINFO) ;
   Info.dwConversionMode = 0 ;

   RESERVEDINFO ReservedInfo = { sizeof(RESERVEDINFO) } ;
   ReservedInfo.dwMode = RESERVEDMODE_ONLY_END ;
   Info.pReserved = (void*) & ReservedInfo ;

   int nResult = ChnconvExW ( NULL, szDstFileName, CP_JAPANESE_TM, nDstCodePage, & Info ) ;

   UnlockSemaphore () ;
   return nResult ;
}



intptr_t WINAPI PrintFileStartString ( int nDstCodePage, char *szDstBuffer, size_t nMaxLen ) {

   if ( LockSemaphore () ) return SetChnconvLastError ( CONV_ERROR_SEMAPHORE ) ;

   Info.cbSize = sizeof(CHNCONVEXINFO) ;
   Info.dwConversionMode = 0 ;

   RESERVEDINFO ReservedInfo = { sizeof(RESERVEDINFO) } ;
   ReservedInfo.dwMode = RESERVEDMODE_ONLY_START ;
   Info.pReserved = (void*) & ReservedInfo ;

   intptr_t nResult = ChnconvStringEx ( NULL, szDstBuffer, CP_JAPANESE_TM, nDstCodePage, & Info, nMaxLen ) ;

   UnlockSemaphore () ;
   return nResult ;
}



intptr_t WINAPI PrintFileEndString ( int nDstCodePage, char *szDstBuffer, size_t nMaxLen ) {

   if ( LockSemaphore () ) return SetChnconvLastError ( CONV_ERROR_SEMAPHORE ) ;

   Info.cbSize = sizeof(CHNCONVEXINFO) ;
   Info.dwConversionMode = 0 ;

   RESERVEDINFO ReservedInfo = { sizeof(RESERVEDINFO) } ;
   ReservedInfo.dwMode = RESERVEDMODE_ONLY_END ;
   Info.pReserved = (void*) & ReservedInfo ;

   intptr_t nResult = ChnconvStringEx ( NULL, szDstBuffer, CP_JAPANESE_TM, nDstCodePage, & Info, nMaxLen ) ;

   UnlockSemaphore () ;
   return nResult ;
}



////////////////////////////////////////////
//               媽娭悢 (7)               //
////////////////////////////////////////////



int WINAPI Chnconv ( const void *szSrcFileName, const void *szDstFileName, int nSrcCodePage, int nDstCodePage, unsigned long dwConversionMode ) {
   if ( dwConversionMode & CONVMODE_FILENAME_UNICODE ) return ChnconvW ( (const wchar_t*) szSrcFileName, (const wchar_t*) szDstFileName, nSrcCodePage, nDstCodePage, dwConversionMode ) ;
   else                                                return ChnconvA ( (const char*)    szSrcFileName, (const char*)    szDstFileName, nSrcCodePage, nDstCodePage, dwConversionMode ) ;
}



int WINAPI PrintFileStart ( int nDstCodePage, void *pReserved ) {
   return PrintFileStartA ( nDstCodePage, (char*) pReserved ) ;
}



int WINAPI PrintFileEnd ( void *pReserved ) {
   return PrintFileEndA ( 0, (char*) pReserved ) ;
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -