📄 chnconv_com.cpp
字号:
FreeGaijiInfo ( & GaijiInfo ) ;
return nExitCode ;
}
// 僐儞僶乕僞偺僄儔乕儊僢僙乕僕傪弌椡
// 栠傝抣偼丄惉岟側傜 0 傪丄幐攕側傜 1 傪丄宲懕晄擻側幐攕側傜 -1 傪曉偡
int DisplayErrorMessageA ( int nErrorCode, const char *szFileName, const char *szExtension ) {
if ( ! szFileName ) szFileName = "" ;
if ( ! szExtension ) szExtension = "" ;
wchar_t wszFileName [ MAX_PATH ] ;
wchar_t wszExtension [ MAX_PATH ] ;
MultiByteToWideChar ( nOsCodePage, 0, szFileName, -1, wszFileName, MAX_PATH ) ;
MultiByteToWideChar ( nOsCodePage, 0, szExtension, -1, wszExtension, MAX_PATH ) ;
wszFileName [ MAX_PATH - 1 ] = 0 ; // 擮偺偨傔
wszExtension [ MAX_PATH - 1 ] = 0 ; // 擮偺偨傔
return DisplayErrorMessageW ( nErrorCode, wszFileName, wszExtension ) ;
}
// 僐儞僶乕僞偺僄儔乕儊僢僙乕僕傪弌椡
// 栠傝抣偼丄惉岟側傜 0 傪丄幐攕側傜 1 傪丄宲懕晄擻側幐攕側傜 -1 傪曉偡
int DisplayErrorMessageW ( int nErrorCode, const wchar_t *szFileName, const wchar_t *szExtension ) {
if ( ! szFileName ) szFileName = L"" ;
if ( ! szExtension ) szExtension = L"" ;
switch ( nErrorCode ) {
case CONV_SUCCESS :
return 0 ;
case CONV_ERROR_WRITE :
fwprintf ( stderr, L"\r%s%s", szFileName, GetStringW ( IDS_WRITE_ERROR ) ) ;
return 1 ;
case CONV_ERROR_READ :
fwprintf ( stderr, L"\r%s%s", szFileName, GetStringW ( IDS_ACCESS_DENIED ) ) ;
return 1 ;
case CONV_ERROR_FORMAT :
fwprintf ( stderr, L"\r%s%s", szFileName, GetStringW ( IDS_INVALID_FORMAT ) ) ;
return 1 ;
case CONV_ERROR_BRACE :
fwprintf ( stderr, L"\r%s%s", szFileName, GetStringW ( IDS_BRACE_ERROR ) ) ;
return 1 ;
case CONV_ERROR_MEMORY :
fwprintf ( stderr, L"\r%s%s", szFileName, GetStringW ( IDS_NOT_ENOUGH_MEMORY ) ) ;
return -1 ;
case CONV_ERROR_CODEPAGE :
fputws ( GetStringW ( IDS_INVALID_CODEPAGE ), stderr ) ;
return -1 ;
case CONV_ERROR_ABORTED :
fwprintf ( stderr, L"\r%s%s", szFileName, GetStringW ( IDS_ABORTED ) ) ;
return -1 ;
case FILECONV_ERROR_ACCESS :
fwprintf ( stderr, L"%s%s", szFileName, GetStringW ( IDS_ACCESS_DENIED ) ) ;
return 1 ;
case FILECONV_ERROR_EXTENSION :
fwprintf ( stderr, L"\r%s%s", szExtension, GetStringW ( IDS_INVALID_EXTENSION ) ) ;
return -1 ;
case FILECONV_ERROR_MEMORY :
fwprintf ( stderr, L"%s%s", szFileName, GetStringW ( IDS_NOT_ENOUGH_MEMORY ) ) ;
return -1 ;
default :
fputws ( GetStringW ( IDS_UNKNOWN_ERROR ), stderr ) ;
return -1 ;
}
}
// 儚僀儖僪僇乕僪専嶕偺僐乕儖僶僢僋娭悢
// 僒僀僘 0 偺僼傽僀儖傪攔彍偟丄僒僽僨傿儗僋僩儕専嶕偺怺偝傪惂屼偡傞
int CALLBACK WildcardCallbackA ( const char *szSearchPath, WIN32_FIND_DATAA *pFindData, int nDepth, LPARAM lParam ) {
if ( ! pFindData->nFileSizeLow && ! pFindData->nFileSizeHigh ) return 0 ;
if ( lParam ) if ( nDepth > lParam ) return -1 ;
return 1 ;
}
// 儚僀儖僪僇乕僪専嶕偺僐乕儖僶僢僋娭悢
// 僒僀僘 0 偺僼傽僀儖傪攔彍偟丄僒僽僨傿儗僋僩儕専嶕偺怺偝傪惂屼偡傞
int CALLBACK WildcardCallbackW ( const wchar_t *szSearchPath, WIN32_FIND_DATAW *pFindData, int nDepth, LPARAM lParam ) {
if ( ! pFindData->nFileSizeLow && ! pFindData->nFileSizeHigh ) return 0 ;
if ( lParam ) if ( nDepth > lParam ) return -1 ;
return 1 ;
}
// 嫮惂廔椆娭悢
void __cdecl AbortProc ( int nSignal ) {
IsAborted = 1 ;
AbortWildcard () ;
if ( AbortChnconv ) AbortChnconv () ;
else {
fputws ( GetStringW ( IDS_ABORTED ), stderr ) ;
DisableAlertOnClose () ;
exit ( 1 ) ;
}
signal ( nSignal, AbortProc ) ;
}
////////////////////////////////////////////
// 曄姺娭悢偺屇傃弌偟 //
////////////////////////////////////////////
int WINAPI CallChnconvExA ( const char *szSrcFileName, const char *szDstFileName, int nSrcCodePage, int nDstCodePage, void *pInfo ) {
return ChnconvExA ( szSrcFileName, szDstFileName, nSrcCodePage, nDstCodePage, (CHNCONVEXINFO*) pInfo ) ;
}
int WINAPI CallChnconvExW ( const wchar_t *szSrcFileName, const wchar_t *szDstFileName, int nSrcCodePage, int nDstCodePage, void *pInfo ) {
return ChnconvExW ( szSrcFileName, szDstFileName, nSrcCodePage, nDstCodePage, (CHNCONVEXINFO*) pInfo ) ;
}
int PrintFileStart ( int nSrcCodePage, int nDstCodePage, const CHNCONVEXINFO *pInfo ) {
CHNCONVEXINFO Info = *pInfo ;
RESERVEDINFO ReservedInfo = { sizeof(RESERVEDINFO) } ;
Info.pReserved = (void*) & ReservedInfo ;
ReservedInfo.dwMode = RESERVEDMODE_ONLY_START ;
if ( IsNT () ) {
int nResult = ChnconvExW ( NULL, NULL, nSrcCodePage, nDstCodePage, (CHNCONVEXINFO*) & Info ) ;
if ( nResult ) { DisplayErrorMessageW ( nResult, NULL, NULL ) ; exit ( 1 ) ; }
}
else {
int nResult = ChnconvExA ( NULL, NULL, nSrcCodePage, nDstCodePage, (CHNCONVEXINFO*) & Info ) ;
if ( nResult ) { DisplayErrorMessageA ( nResult, NULL, NULL ) ; exit ( 1 ) ; }
}
return 0 ;
}
int PrintFileEnd ( int nSrcCodePage, int nDstCodePage, const CHNCONVEXINFO *pInfo ) {
CHNCONVEXINFO Info = *pInfo ;
RESERVEDINFO ReservedInfo = { sizeof(RESERVEDINFO) } ;
Info.pReserved = (void*) & ReservedInfo ;
ReservedInfo.dwMode = RESERVEDMODE_ONLY_END ;
if ( IsNT () ) {
int nResult = ChnconvExW ( NULL, NULL, nSrcCodePage, nDstCodePage, (CHNCONVEXINFO*) & Info ) ;
if ( nResult ) { DisplayErrorMessageW ( nResult, NULL, NULL ) ; exit ( 1 ) ; }
}
else {
int nResult = ChnconvExA ( NULL, NULL, nSrcCodePage, nDstCodePage, (CHNCONVEXINFO*) & Info ) ;
if ( nResult ) { DisplayErrorMessageA ( nResult, NULL, NULL ) ; exit ( 1 ) ; }
}
return 0 ;
}
////////////////////////////////////////////
// 僥僋僲儊僀僩 //
////////////////////////////////////////////
// 僥僋僲儊僀僩娭楢偺僆僾僔儑儞傪巜掕
// szString 偵偼 /t 偺偁偲偺暥帤楍傪巜掕
// 惉岟偟偨傜 0 傪丄幐攕偟偨傜 1 傪曉偡
int SetTmOptions ( char *szString ) {
static unsigned long dwTmPropMode = 0 ;
if ( *szString == 'P' || *szString == 'p' ) {
szString ++ ;
if ( ! *szString ) {
dwTmPropMode |= TMMODE_ASCII_ALL ;
IsUseSameFont = 0 ;
return 0 ;
}
if ( *szString == '=' ) {
return 0 ;
}
if ( isascii ( *szString ) && isdigit ( *szString ) ) {
errno = 0 ;
unsigned long dwTmPropMode = strtoul ( szString, & szString, 10 ) ;
if ( errno == ERANGE || *szString ) return 1 ;
if ( dwTmPropMode & TMMODE_ASCII_ALPHA ) IsUseSameFont = 0 ;
if ( dwTmPropMode & TMMODE_WRITE_COMMENT ) IsWriteTmComment = 0 ;
return 0 ;
}
return 1 ;
}
if ( *szString == 'Z' || *szString == 'z' ) {
szString ++ ;
if ( isascii ( *szString ) && isdigit ( *szString ) ) {
errno = 0 ;
int nFontSize = strtoul ( szString, & szString, 10 ) ;
if ( errno == ERANGE || *szString ) return 1 ;
else nTmFontSize = nFontSize ;
return 0 ;
}
return 1 ;
}
if ( *szString == 'C' || *szString == 'c' ) {
szString ++ ;
if ( ! *szString ) {
IsWriteTmComment = 1 ;
return 0 ;
}
return 1 ;
}
return 1 ;
}
////////////////////////////////////////////
// 僿儖僾 //
////////////////////////////////////////////
// 僿儖僾昞帵
// 僶乕僕儑儞傪曉偡
int Help ( void ) {
int nVersion = 0 ;
// 廔椆帪偺僉乕僾儘儞僾僩傪柍岠壔
DisableAlertOnClose () ;
// 僶乕僕儑儞傪庢摼
if ( ! hChnconv && LoadChnconvDll () ) {
fputws ( GetStringW ( IDS_DLL_ERROR ), stderr ) ;
if ( fisatty ( stdout ) && AskW ( GetStringW ( IDS_ASK_DISPLAY_HELP ), MB_YESNO ) ) return 1 ;
FILEVERSION FileVersion ;
if ( ! GetFileVersion ( & FileVersion ) ) nVersion = TranslateVersionInfo ( & FileVersion ) ;
}
else {
nVersion = GetDllVersion () ;
}
// 奣棯
fwprintf ( stdout, L" %s version %d.%02d %s\n", szCommandName, nVersion / 100, nVersion % 100, GetVersionCopyrightW () ) ;
fwprintf ( stdout, GetStringW ( IDS_HELP_100 ), szCommandName ) ;
fwprintf ( stdout, GetStringW ( IDS_HELP_101 ), szCommandName ) ;
fwprintf ( stdout, GetStringW ( IDS_HELP_102 ), szCommandName ) ;
fputws ( GetStringW ( IDS_HELP_103 ), stdout ) ;
if ( fisatty ( stdout ) && AskW ( GetStringW ( IDS_HELP_107 ), MB_YESNO ) ) return 1 ;
// 僐乕僪儁乕僕巜掕偺愢柧
fputws ( GetStringW ( IDS_HELP_200 ), stdout ) ;
fputws ( GetStringW ( IDS_HELP_201 ), stdout ) ;
fputws ( GetStringW ( IDS_HELP_202 ), stdout ) ;
fputws ( GetStringW ( IDS_HELP_203 ), stdout ) ;
if ( fisatty ( stdout ) && AskW ( GetStringW ( IDS_PRESS_ANY_KEY ), MB_OK ) ) return 1 ;
// 僆僾僔儑儞偺愢柧
fputws ( GetStringW ( IDS_HELP_204 ), stdout ) ;
if ( fisatty ( stdout ) && AskW ( GetStringW ( IDS_PRESS_ANY_KEY ), MB_OK ) ) return 1 ;
fputws ( GetStringW ( IDS_HELP_205 ), stdout ) ;
if ( fisatty ( stdout ) && AskW ( GetStringW ( IDS_PRESS_ANY_KEY ), MB_OK ) ) return 1 ;
// 拲堄
fputws ( GetStringW ( IDS_HELP_206 ), stdout ) ;
if ( ! IsConsole () && fisatty ( stdout ) && fisatty ( stderr ) && AskW ( GetStringW ( IDS_PRESS_ANY_KEY ), MB_OK ) ) return 1 ;
return 1 ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -