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

📄 filename.cpp

📁 This software performs code conversion of Chinese characters, including GB2312/GBK and BIG5. It a
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// filename.cpp

#include <windows.h>
#include <string.h>
#include <ctype.h>
#include <mbctype.h>
#include "msc.h"

#undef DEBUG_CONST_STRING
#include "filename.h"



////////////////////////////////////////////
//              奼挘巕傪庢摼              //
////////////////////////////////////////////



// 僷僗柤偐傜奼挘巕傪偝偑偡乮ANSI斉乯
// 奼挘巕偼 '.' 傪娷傑側偄
// 尒偮偐傜側偗傟偽 NULL 傪曉偡
char *GetExtensionA ( const char *szPathName ) {

   const char *szExtension = NULL ;

   for ( const char *szString = szPathName ; *szString ; szString ++ ) {
      if ( *szString == '.' ) szExtension = szString + 1 ;
      if ( IsPathOrDriveSeparator ( *szString ) ) szExtension = NULL ;
      if ( ismbblead ( (unsigned char) *szString ) && *( szString + 1 ) ) szString ++ ;
   }

   return (char*) szExtension ;
}



// 僷僗柤偐傜奼挘巕傪偝偑偡乮UNICODE斉乯
// 奼挘巕偼 '.' 傪娷傑側偄
// 尒偮偐傜側偗傟偽 NULL 傪曉偡
wchar_t *GetExtensionW ( const wchar_t *szPathName ) {

   const wchar_t *szExtension = NULL ;

   for ( const wchar_t *szString = szPathName ; *szString ; szString ++ ) {
      if ( *szString == '.' ) szExtension = szString + 1 ;
      if ( IsPathOrDriveSeparator ( *szString ) ) szExtension = NULL ;
   }

   return (wchar_t*) szExtension ;
}



////////////////////////////////////////////
//              奼挘巕傪曄峏              //
////////////////////////////////////////////



// 僷僗柤偺奼挘巕傪曄峏偡傞乮ANSI斉乯
// 奼挘巕偼 '.' 傪娷傑側偄
// 奼挘巕偵 NULL 傪巜掕偡傞偲丄奼挘巕傪嶍彍
// 僷僗柤傪曉偡
char *ChangeExtensionA ( char *szPathName, const char *szExtension ) {

   char *szString = GetExtensionA ( szPathName ) ;

   if ( szString ) {
      if ( szExtension ) strcpy ( szString, szExtension ) ;
      else               *( szString - 1 ) = 0 ;
   }
   else {
      if ( szExtension ) {
         szString = strend ( szPathName ) ;
         *szString = '.' ;
         strcpy ( szString + 1, szExtension ) ;
      }
   }

   return szPathName ;
}



// 僷僗柤偺奼挘巕傪曄峏偡傞乮UNICODE斉乯
// 奼挘巕偼 '.' 傪娷傑側偄
// 奼挘巕偵 NULL 傪巜掕偡傞偲丄奼挘巕傪嶍彍
// 僷僗柤傪曉偡
wchar_t *ChangeExtensionW ( wchar_t *szPathName, const wchar_t *szExtension ) {

   wchar_t *szString = GetExtensionW ( szPathName ) ;

   if ( szString ) {
      if ( szExtension ) wcscpy ( szString, szExtension ) ;
      else               *( szString - 1 ) = 0 ;
   }
   else {
      if ( szExtension ) {
         szString = wcsend ( szPathName ) ;
         *szString = '.' ;
         wcscpy ( szString + 1, szExtension ) ;
      }
   }

   return szPathName ;
}



////////////////////////////////////////////
//            僼傽僀儖柤傪庢摼            //
////////////////////////////////////////////



// 僷僗柤偐傜僼傽僀儖柤傪偝偑偡乮ANSI斉乯
// 尒偮偐傜側偗傟偽 NULL 傪曉偡
char *GetFileNameA ( const char *szPathName ) {

   for ( const char *szString = szPathName ; *szString ; szString ++ ) {
      if ( IsPathOrDriveSeparator ( *szString ) ) szPathName = szString + 1 ;
      if ( ismbblead ( (unsigned char) *szString ) && *( szString + 1 ) ) szString ++ ;
   }

   if ( ! *szPathName ) szPathName = NULL ;

   return (char*) szPathName ;
}



// 僷僗柤偐傜僼傽僀儖柤傪偝偑偡乮UNICODE斉乯
// 尒偮偐傜側偗傟偽 NULL 傪曉偡
wchar_t *GetFileNameW ( const wchar_t *szPathName ) {

   for ( const wchar_t *szString = szPathName ; *szString ; szString ++ ) {
      if ( IsPathOrDriveSeparator ( *szString ) ) szPathName = szString + 1 ;
   }

   if ( ! *szPathName ) szPathName = NULL ;

   return (wchar_t*) szPathName ;
}



////////////////////////////////////////////
//            僼傽僀儖柤傪曄峏            //
////////////////////////////////////////////



// 僷僗柤偺僼傽僀儖柤傪曄峏偡傞乮ANSI斉乯
// 僼傽僀儖柤偵 NULL 傪巜掕偡傞偲丄僼傽僀儖柤傪嶍彍
// 僷僗柤傪曉偡
char *ChangeFileNameA ( char *szPathName, const char *szFileName ) {

   char *szString = GetFileNameA ( szPathName ) ;
   if ( ! szString ) szString = strend ( szPathName ) ;

   if ( ! szFileName ) szFileName = "" ;
   strcpy ( szString, szFileName ) ;

   return szPathName ;
}



// 僷僗柤偺僼傽僀儖柤傪曄峏偡傞乮UNICODE斉乯
// 僼傽僀儖柤偵 NULL 傪巜掕偡傞偲丄僼傽僀儖柤傪嶍彍
// 僷僗柤傪曉偡
wchar_t *ChangeFileNameW ( wchar_t *szPathName, const wchar_t *szFileName ) {

   wchar_t *szString = GetFileNameW ( szPathName ) ;
   if ( ! szString ) szString = wcsend ( szPathName ) ;

   if ( ! szFileName ) szFileName = L"" ;
   wcscpy ( szString, szFileName ) ;

   return szPathName ;
}



////////////////////////////////////////////
//            僼儖僷僗柤傪庢摼            //
////////////////////////////////////////////



// 僼儖僷僗柤傪庢摼偡傞乮ANSI斉乯
// 弌椡偟偨暥帤楍偺挿偝傪曉偡乮廔抂僰儖暥帤傪娷傓乯
// 幐攕偟偨傜 0 傪曉偡
size_t GetFullPathNameExA ( const char *szSrcFileName, char *szDstFileName, size_t nMaxLen ) {

   char *szFilePart ;

   if ( nMaxLen > MAX_PATH ) nMaxLen = MAX_PATH ;
   if ( ! szDstFileName ) nMaxLen = 0 ;

   size_t nResult = GetFullPathNameA ( szSrcFileName, (unsigned long) nMaxLen, szDstFileName, & szFilePart ) ;
   if ( nResult > nMaxLen ) nResult = 0 ;

   return nResult ;
}



// 僼儖僷僗柤傪庢摼偡傞乮UNICODE斉乯
// 弌椡偟偨暥帤楍偺挿偝傪曉偡乮廔抂僰儖暥帤傪娷傓乯
// 幐攕偟偨傜 0 傪曉偡
size_t GetFullPathNameExW ( const wchar_t *szSrcFileName, wchar_t *szDstFileName, size_t nMaxLen ) {

   wchar_t *szFilePart ;

   if ( nMaxLen > MAX_LONG_PATH ) nMaxLen = MAX_LONG_PATH ;
   if ( ! szDstFileName ) nMaxLen = 0 ;

   size_t nResult = GetFullPathNameW ( szSrcFileName, (unsigned long) nMaxLen, szDstFileName, & szFilePart ) ;
   if ( nResult > nMaxLen ) nResult = 0 ;

   return nResult ;
}



// 僼儖僷僗柤傪庢摼偟偰暋惢偡傞乮ANSI斉乯
// free() 傪巊偭偰夝曻偡傞偙偲
// 幐攕偟偨傜 NULL 傪曉偡
char *GetFullPathNameAllocA ( const char *szFileName ) {

   char *szResult = NULL ;
   char *szFilePart ;
   unsigned long nLength ;
   unsigned long nResult ;

   if ( strlen ( szFileName ) + 1 > MAX_PATH ) return NULL ;

   if ( ! ( nLength = GetFullPathNameA ( szFileName, 0, NULL, & szFilePart ) ) ) goto CAUGHT_ERROR ;
   nLength += 8 ;       // GetFullPathName() 偼僼傽僀儖柤偑侾帤偺偲偒梋桾偑昁梫
   if ( ! ( szResult = (char*) malloc ( nLength * sizeof(char) ) ) ) goto CAUGHT_ERROR ;
   if ( ! ( nResult = GetFullPathNameA ( szFileName, nLength, szResult, & szFilePart ) ) || nResult >= nLength ) goto CAUGHT_ERROR ;

   return szResult ;

   CAUGHT_ERROR :
   free ( szResult ) ;
   return NULL ;
}



// 僼儖僷僗柤傪庢摼偟偰暋惢偡傞乮UNICODE斉乯
// free() 傪巊偭偰夝曻偡傞偙偲
// 幐攕偟偨傜 NULL 傪曉偡
wchar_t *GetFullPathNameAllocW ( const wchar_t *szFileName ) {

   wchar_t *szResult = NULL ;
   wchar_t *szFilePart ;
   unsigned long nLength ;
   unsigned long nResult ;

   if ( wcslen ( szFileName ) + 1 > MAX_LONG_PATH ) return NULL ;

⌨️ 快捷键说明

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