📄 chnconv_com.cpp
字号:
IsTxtUnicodeHtml = 1 ;
break ;
case 'W' :
case 'w' :
// IsWriteInUnicode = 1 ;
break ;
case 'X' :
case 'x' :
if ( *( szArgv + 2 ) == '-' && *( szArgv + 3 ) == 0 ) IsConvertCjkEx = 0 ;
else if ( *( szArgv + 2 ) == 0 ) IsConvertCjkEx = 1 ;
else nError = nCountArgv ;
continue ;
case '7' :
if ( *( szArgv + 2 ) == '-' && *( szArgv + 3 ) == 0 ) IsOutputCwNewFont = 0 ;
else if ( *( szArgv + 2 ) == 0 ) IsOutputCwNewFont = 1 ;
else nError = nCountArgv ;
continue ;
case '?' :
// IsDisplayHelp = 1 ;
break ;
case '@' :
// IsReadOption = 1 ;
continue ;
default :
nError = nCountArgv ;
break ;
}
if ( *( szArgv + 2 ) ) nError = nCountArgv ;
continue ;
}
// 僼傽僀儖柤偺庢摼
if ( ! nSearchPath ) {
nSearchPath = nCountArgv ;
continue ;
}
// 奼挘巕柤偺庢摼
if ( ! nExtension ) {
nExtension = nCountArgv ;
continue ;
}
nError = nCountArgv ;
}
// 儕僟僀儗僋僩偺専嵏
if ( nSearchPath && ! fisatty ( stdin ) || nExtension && ! fisatty ( stdout ) ) {
fputws ( GetStringW ( IDS_CANNOT_REDIRECT ), stderr ) ;
return 1 ;
}
// 僿儖僾偺昞帵
if ( IsDisplayHelp || ! nSearchPath && fisatty ( stdin ) && ! nError ) {
Help () ;
return 1 ;
}
// 僄儔乕昞帵
if ( nError ) {
fwprintf ( stderr, L"%s%s\n", GetStringW ( IDS_PARAM_ERROR ), GetArgumentW ( nError ) ) ;
return 1 ;
}
// 僐儞僜乕儖傪巜掕
if ( nSearchPath ) {
wchar_t *szFileName = GetFileNameW ( GetArgumentW ( nSearchPath ) ) ;
if ( szFileName && ! wcsicmp ( szFileName, L"CON" ) ) nSearchPath = 0 ;
}
// 僒僽僨傿儗僋僩儕専嶕偑壜擻偐丠
if ( ! nSearchPath && ( dwSearchMode & WILD_SEARCH_SUB ) ) {
fputws ( GetStringW ( IDS_CANNOT_SEARCH_SUBDIR ), stderr ) ;
return 1 ;
}
// 僐乕僪儁乕僕偑巜掕偝傟偨偐丠
if ( ! nSrcCodePage || ! nDstCodePage ) {
fputws ( GetStringW ( IDS_NOT_SPECIFIED_CODEPAGE ), stderr ) ;
return 1 ;
}
// 僞僀儉僗僞儞僾曐懚偑壜擻偐丠
if ( ( dwFileconvMode & FILECONV_SAVE_TIMESTAMP ) && ! nExtension ) {
fputws ( GetStringW ( IDS_CANNOT_SAVE_TIMESTAMP ), stderr ) ;
}
// 曄姺僆僾僔儑儞偺専嵏
if ( ( IsGb2big5N || IsBig52gbN ) && ( ! IsValidCodePage ( CP_CHINESE_SIMPLIFIED ) || ! IsValidCodePage ( CP_CHINESE_TRADITIONAL ) ) ) {
fwprintf ( stderr, L"%s%s\n", GetStringW ( IDS_INVALID_OPTION ), L"-n" ) ;
return 1 ;
}
// DLL偺儘乕僪
if ( LoadChnconvDll () ) {
fputws ( GetStringW ( IDS_DLL_ERROR ), stderr ) ;
return 1 ;
}
CHNCONVEXINFO Info = { sizeof(CHNCONVEXINFO) } ;
CHNFONTINFO FontInfo = { sizeof(CHNFONTINFO) } ;
Info.pFontInfo = & FontInfo ;
RESERVEDINFO ReservedInfo = { sizeof(RESERVEDINFO) } ;
Info.pReserved = (void*) & ReservedInfo ;
// 僆僾僔儑儞傪愝掕
Info.dwConversionMode = TranslateConversionMode ( nSrcCodePage, nDstCodePage ) ;
Info.dwAdditionalMode = TranslateAdditionalMode ( nSrcCodePage, nDstCodePage ) ;
// 僼僅儞僩僒僀僘
Info.nFontSize = nTmFontSize ;
if ( ! Info.nFontSize ) Info.nFontSize = -1 ;
// 僼僅儞僩柤傪愝掕
if ( nDstCodePage == CP_CHINESE_SIMPLIFIED ) {
if ( ! szFont && *szGbFont ) szFont = szGbFont ;
if ( ! szGothicFont && *szGbGothicFont ) szGothicFont = szGbGothicFont ;
FontInfo.pGbFont = szFont ;
FontInfo.pGbGothicFont = szGothicFont ;
}
if ( nDstCodePage == CP_CHINESE_TRADITIONAL ) {
if ( ! szFont && *szBig5Font ) szFont = szBig5Font ;
if ( ! szGothicFont && *szBig5GothicFont ) szGothicFont = szBig5GothicFont ;
FontInfo.pBig5Font = szFont ;
FontInfo.pBig5GothicFont = szGothicFont ;
}
if ( nDstCodePage == CP_CHINESE_SIMPLIFIED || nDstCodePage == CP_CHINESE_TRADITIONAL ) {
if ( ! szFontSub && *szPinyinFont ) szFontSub = szPinyinFont ;
if ( ! szGothicFontSub && *szPinyinGothicFont ) szGothicFontSub = szPinyinGothicFont ;
FontInfo.pPinyinFont = szFontSub ;
FontInfo.pPinyinGothicFont = szGothicFontSub ;
}
if ( nDstCodePage != CP_CHINESE_SIMPLIFIED && nDstCodePage != CP_CHINESE_TRADITIONAL ) {
if ( szFont || szGothicFont || szFontSub || szGothicFontSub ) {
fputws ( GetStringW ( IDS_CANNOT_SPECIFY_FONT ), stderr ) ;
return 1 ;
}
}
// 奜帤掕媊偺撉傒崬傒
GAIJIINFO GaijiInfo = { 0 } ;
int nGaijiErrorLineNumber ;
if ( ReadGaijiFile ( nSrcCodePage, nDstCodePage, & GaijiInfo, & nGaijiErrorLineNumber ) < 0 ) {
if ( nGaijiErrorLineNumber ) fwprintf ( stderr, L"User Definition File Error (Line:%d)\n", nGaijiErrorLineNumber ) ;
else fwprintf ( stderr, L"Reading User Definition File%s", GetStringW ( IDS_NOT_ENOUGH_MEMORY ) ) ;
return 1 ;
}
Info.pSrcToDst = GaijiInfo.pSrcToDst ;
Info.nNumberOfSrcToDst = GaijiInfo.nNumberOfSrcToDst ;
Info.pSrcToUc = GaijiInfo.pSrcToUc ;
Info.nNumberOfSrcToUc = GaijiInfo.nNumberOfSrcToUc ;
// 僔僌僫儖娭悢傪巜掕
signal ( SIGINT, AbortProc ) ;
if ( IsNT () ) {
// 僼傽僀儖柤傪巜掕偟側偄応崌
if ( ! nSearchPath ) {
// 幚峴
int nResult = CallChnconvExW ( NULL, NULL, nSrcCodePage, nDstCodePage, & Info ) ;
// 僄儔乕傪暘愅
if ( nResult && DisplayErrorMessageW ( nResult, NULL, NULL ) ) nExitCode = 1 ;
}
// 僼傽僀儖柤傪巜掕偟偨応崌
else {
// 儚僀儖僪僇乕僪偺揥奐
WILDCARDW *Wildcard = SearchWildcardW ( NULL, GetArgumentW ( nSearchPath ), dwSearchMode, WildcardCallbackW, nSearchDepth ) ;
if ( Wildcard == WILDCARD_ERROR ) {
if ( IsAborted ) fputws ( GetStringW ( IDS_ABORTED ), stderr ) ;
else fputws ( GetStringW ( IDS_TOO_MANY_FILES ), stderr ) ;
return 1 ;
}
if ( Wildcard == NULL ) {
fputws ( GetStringW ( IDS_FILE_NOT_FOUND ), stderr ) ;
return 1 ;
}
wchar_t *szExtension = nExtension ? GetArgumentW ( nExtension ) : NULL ;
wchar_t *szDirName = NULL ;
nExitCode = 0 ;
if ( szExtension && *szExtension == '.' ) szExtension ++ ; // 奼挘巕偐傜 '.' 傪嶍彍
int IsPrintStartEnd = ( IsNecChineseCodePage ( nSrcCodePage ) && ! szExtension ) ;
if ( IsPrintStartEnd ) ReservedInfo.dwMode = RESERVEDMODE_NO_START_END ;
if ( IsPrintStartEnd ) PrintFileStart ( nSrcCodePage, nDstCodePage, & Info ) ;
// 僼傽僀儖偑懚嵼偟偨応崌
for ( const wchar_t *szString = GetFirstFileW ( Wildcard ) ; szString ; szString = GetNextFileW ( Wildcard ) ) {
// 拞巭
if ( IsAborted && DisplayErrorMessageW ( CONV_ERROR_ABORTED, NULL, NULL ) < 0 ) { nExitCode = 1 ; break ; }
// 婎弨僼僅儖僟偺庢摼
if ( ! GetFileNameW ( szString ) ) {
free ( szDirName ) ;
szDirName = wcsdup_expand ( szString, (size_t) -1, MAX_PATH ) ;
if ( ! szDirName && DisplayErrorMessageW ( FILECONV_ERROR_MEMORY, szString, NULL ) < 0 ) { nExitCode = 1 ; break ; }
continue ;
}
// 僼傽僀儖柤偺庢摼
const wchar_t *szFileName ;
if ( szDirName ) szFileName = ChangeFileNameW ( szDirName, szString ) ;
else szFileName = szString ;
// 幚峴
int nResult = FileConvertW ( szFileName, szExtension, CallChnconvExW, nSrcCodePage, nDstCodePage, & Info, dwFileconvMode ) ;
// 僄儔乕傪暘愅
if ( nResult ) {
if ( DisplayErrorMessageW ( nResult, szFileName, szExtension ) < 0 ) { nExitCode = 1 ; break ; }
if ( IsCatchErrorStrictly ) { nExitCode = 1 ; break ; }
continue ;
}
}
free ( szDirName ) ;
if ( IsPrintStartEnd ) PrintFileEnd ( nSrcCodePage, nDstCodePage, & Info ) ;
// 儚僀儖僪僇乕僪僴儞僪儖偺夝曻
CloseWildcardW ( Wildcard ) ;
}
}
else {
// 僼傽僀儖柤傪巜掕偟側偄応崌
if ( ! nSearchPath ) {
// 幚峴
int nResult = CallChnconvExA ( NULL, NULL, nSrcCodePage, nDstCodePage, & Info ) ;
// 僄儔乕傪暘愅
if ( nResult && DisplayErrorMessageA ( nResult, NULL, NULL ) < 0 ) nExitCode = 1 ;
}
// 僼傽僀儖柤傪巜掕偟偨応崌
else {
// 儚僀儖僪僇乕僪偺揥奐
WILDCARDA *Wildcard = SearchWildcardA ( NULL, GetArgumentA ( nSearchPath ), dwSearchMode, WildcardCallbackA, nSearchDepth ) ;
if ( Wildcard == WILDCARD_ERROR ) {
if ( IsAborted ) fputws ( GetStringW ( IDS_ABORTED ), stderr ) ;
else fputws ( GetStringW ( IDS_TOO_MANY_FILES ), stderr ) ;
return 1 ;
}
if ( Wildcard == NULL ) {
fputws ( GetStringW ( IDS_FILE_NOT_FOUND ), stderr ) ;
return 1 ;
}
char *szExtension = nExtension ? GetArgumentA ( nExtension ) : NULL ;
char *szDirName = NULL ;
nExitCode = 0 ;
if ( szExtension && *szExtension == '.' ) szExtension ++ ; // 奼挘巕偐傜 '.' 傪嶍彍
int IsPrintStartEnd = ( IsNecChineseCodePage ( nSrcCodePage ) && ! szExtension ) ;
if ( IsPrintStartEnd ) ReservedInfo.dwMode = RESERVEDMODE_NO_START_END ;
if ( IsPrintStartEnd ) PrintFileStart ( nSrcCodePage, nDstCodePage, & Info ) ;
// 僼傽僀儖偑懚嵼偟偨応崌
for ( const char *szString = GetFirstFileA ( Wildcard ) ; szString ; szString = GetNextFileA ( Wildcard ) ) {
// 拞巭
if ( IsAborted && DisplayErrorMessageA ( CONV_ERROR_ABORTED, NULL, NULL ) < 0 ) { nExitCode = 1 ; break ; }
// 婎弨僼僅儖僟偺庢摼
if ( ! GetFileNameA ( szString ) ) {
free ( szDirName ) ;
szDirName = strdup_expand ( szString, (size_t) -1, MAX_PATH ) ;
if ( ! szDirName && DisplayErrorMessageA ( FILECONV_ERROR_MEMORY, szString, NULL ) < 0 ) { nExitCode = 1 ; break ; }
continue ;
}
// 僼傽僀儖柤偺庢摼
const char *szFileName ;
if ( szDirName ) szFileName = ChangeFileNameA ( szDirName, szString ) ;
else szFileName = szString ;
// 幚峴
int nResult = FileConvertA ( szFileName, szExtension, CallChnconvExA, nSrcCodePage, nDstCodePage, & Info, dwFileconvMode ) ;
// 僄儔乕傪暘愅
if ( nResult ) {
if ( DisplayErrorMessageA ( nResult, szFileName, szExtension ) < 0 ) { nExitCode = 1 ; break ; }
if ( IsCatchErrorStrictly ) { nExitCode = 1 ; break ; }
continue ;
}
}
free ( szDirName ) ;
if ( IsPrintStartEnd ) PrintFileEnd ( nSrcCodePage, nDstCodePage, & Info ) ;
// 儚僀儖僪僇乕僪僴儞僪儖偺夝曻
CloseWildcardA ( Wildcard ) ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -