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

📄 conv_opt.cpp

📁 This software performs code conversion of Chinese characters, including GB2312/GBK and BIG5. It a
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// 奺峴偐傜暥帤楍偺僆僾僔儑儞傪庢摼
// 僆僾僔儑儞偺柤慜偑崌抳偟偨傜 0 傪曉偡
static int GetOptionStringA ( char *szString, const char *szName, char *szValue, int nMaxLen ) {

   if ( ! strheadicmp ( szString, szName ) ) {

      szString += strlen ( szName ) ;

      if ( isascii ( *szString ) && isspace ( *szString ) ) {

         while ( isascii ( *szString ) && isspace ( *szString ) ) szString ++ ;

         szString = strtokex ( szString, NULL ) ;
         if ( szString ) strlcpy ( szValue, szString, nMaxLen ) ;
         else            *szValue = 0 ;

         return 0 ;
      }
   }

   return 1 ;
}



// 奺峴偐傜Unicode暥帤楍偺僆僾僔儑儞傪庢摼
// 僆僾僔儑儞偺柤慜偑崌抳偟偨傜 0 傪曉偡
static int GetOptionWideString ( char *szString, const char *szName, wchar_t *szValue, int nMaxLen ) {

   if ( ! strheadicmp ( szString, szName ) ) {

      szString += strlen ( szName ) ;

      if ( isascii ( *szString ) && isspace ( *szString ) ) {

         while ( isascii ( *szString ) && isspace ( *szString ) ) szString ++ ;
         if ( *szString == '\"' ) szString ++ ;

         wchar_t *szCurrent = szValue ;
         char szDigitBuffer [ 0x10 ] ;

         while ( isascii ( *szString ) && isxdigit ( *szString ) ) {
            if ( szCurrent - szValue >= nMaxLen ) break ;
            strlcpy ( szDigitBuffer, szString, 4 + 1 ) ;    // four digits and one null
            *szCurrent = (wchar_t) strtoul ( szDigitBuffer, NULL, 0x10 ) ;
            szString += 4 ;
            szCurrent ++ ;
         }

         *szCurrent = 0 ;
         return 0 ;
      }
   }

   return 1 ;
}



#if defined RTFCONV_EXE || defined RTFCONV_COM || defined SETUP_R
// 奺峴偐傜僶僀僫儕乕偺僆僾僔儑儞傪庢摼
// 僆僾僔儑儞偺柤慜偑崌抳偟偨傜 0 傪曉偡
static int GetOptionBinary ( char *szString, const char *szName, unsigned short *pValue, int nLen ) {

   if ( ! strheadicmp ( szString, szName ) ) {

      szString += strlen ( szName ) ;

      if ( isascii ( *szString ) && isspace ( *szString ) ) {

         while ( isascii ( *szString ) && isspace ( *szString ) ) szString ++ ;
         if ( *szString == '\"' ) szString ++ ;

         unsigned short *pCurrent = pValue ;
         char szDigitBuffer [ 0x10 ] ;

         while ( isascii ( *szString ) && isxdigit ( *szString ) ) {
            if ( pCurrent - pValue >= nLen ) break ;
            strlcpy ( szDigitBuffer, szString, 4 + 1 ) ;    // four digits and one null
            *pCurrent = (wchar_t) strtoul ( szDigitBuffer, NULL, 0x10 ) ;
            szString += 4 ;
            pCurrent ++ ;
         }

         return 0 ;
      }
   }

   return 1 ;
}
#endif



#if defined RTFCONV_EXE || defined RTFCONV_COM || defined SETUP_R
void __cdecl FreeFontNameArray ( void ) {
   if ( FontNameArray ) free ( FontNameArray ) ;
   FontNameArray = NULL ;
}
#endif



////////////////////////////////////////
//       廔椆帪偺僆僾僔儑儞愝掕       //
////////////////////////////////////////



#if defined RTFCONV_EXE || defined CHNCONV_EXE || defined SETUP_R || defined SETUP_C
#ifndef CONV_OPT_OLD


#include "mkdir.h"


static int WriteOptionA ( void ) ;
static int WriteOptionW ( void ) ;
static int WriteOptionFile ( FILE *Fout ) ;



// 廔椆帪偵僆僾僔儑儞偺愝掕
// 惉岟偟偨傜 0 傪丄幐攕偟偨傜 0 埲奜傪曉偡
int WriteOption ( void ) {


#if defined RTFCONV_EXE || defined CHNCONV_EXE
   if ( IsNT () ) WideCharToMultiByte ( CP_ACP, 0, szBrowsePathW, -1, szBrowsePathA, MAX_PATH, NULL, NULL ) ;
#endif

#if defined RTFCONV_EXE || defined CHNCONV_EXE
   nSavedSrcType = nSrcType ;
   nSavedDstType = nDstType ;

   nSavedSrcCode = ( AvailableCodeList [ nSrcCode ] ).nCodePage ;
   nSavedDstCode = ( AvailableCodeList [ nDstCode ] ).nCodePage ;
#endif


   if ( IsNT () ) return WriteOptionW () ;
   else           return WriteOptionA () ;
}



static int WriteOptionA ( void ) {

   char szFileNameBuffer [ MAX_PATH ] ;

   const char *szFileName = szConfigFileNameA ;

   if ( ! szFileName ) {

#if ! defined SETUP_R && ! defined SETUP_C
      GetModuleFileNameA ( NULL, szFileNameBuffer, MAX_PATH ) ;
      ChangeFileNameA ( szFileNameBuffer, CFG_FILENAME_A ) ;
#else
      strcpy ( szFileNameBuffer, szInstallFolderA ) ;
      SetPathSeparatorA ( szFileNameBuffer, ADD_SEPARATOR_ALWAYS ) ;
      strcat ( szFileNameBuffer, CFG_FILENAME_A ) ;
#endif

      szFileName = szFileNameBuffer ;
   }


   FILE *Fout = fsopen ( szFileName, "wb", _SH_DENYWR ) ;
   if ( ! Fout ) return 1 ;

   int nResult = WriteOptionFile ( Fout ) ;

   fclose ( Fout ) ;

   return nResult ;
}



static int WriteOptionW ( void ) {

   wchar_t szFileNameBuffer [ MAX_PATH ] ;

   const wchar_t *szFileName = szConfigFileNameW ;

   if ( ! szFileName ) {

      if ( GetSpecialFolderPathW ( NULL, szFileNameBuffer, CSIDL_APPDATA, 0 ) ) return 1 ;

      wcscat ( szFileNameBuffer, L"\\Harigaya" ) ;

      if ( ! IsFolderExistW ( szFileNameBuffer ) && MakeDirectoryW ( szFileNameBuffer, NULL ) ) return 1 ;

      SetPathSeparatorW ( szFileNameBuffer, ADD_SEPARATOR_ALWAYS ) ;
      wcscat ( szFileNameBuffer, CFG_FILENAME_W ) ;

      szFileName = szFileNameBuffer ;
   }


   FILE *Fout = wfsopen ( szFileName, L"wb", _SH_DENYWR ) ;
   if ( ! Fout ) return 1 ;

   int nResult = WriteOptionFile ( Fout ) ;

   fclose ( Fout ) ;

   return nResult ;
}



// 僆僾僔儑儞僼傽僀儖偺彂偒崬傒
// 惉岟偟偨傜 0 傪丄幐攕偟偨傜 0 埲奜傪曉偡
static int WriteOptionFile ( FILE *Fout ) {


   fprintf ( Fout, "// Options for %s\r\n\r\n", GetStringA ( IDS_COMMANDNAME ) ) ;


   // 惍悢抣偺曐懚
   for ( int nCount = 0 ; nCount < OPTION_INTEGER_LIST_NELEM ; nCount ++ ) {

      const char *szName = ( OptionIntegerList [ nCount ] ).szName ;
      int *pValue = ( OptionIntegerList [ nCount ] ).nValue ;

#if defined RTFCONV_EXE || defined CHNCONV_EXE || defined SETUP_R || defined SETUP_C
      if ( ( pValue == & nSavedSrcType || pValue == & nSavedDstType ) && ! IsSaveCode ) continue ;
      if ( ( pValue == & nSavedSrcCode || pValue == & nSavedDstCode ) && ! IsSaveCode ) continue ;
#endif
      if ( ( pValue == & nSavedWindowX || pValue == & nSavedWindowY ) && ! IsSaveWindow ) continue ;

      fprintf ( Fout, "%s %d\r\n", szName, *pValue ) ;
   }


   // 暥帤楍偺曐懚
   for ( int nCount = 0 ; nCount < OPTION_STRING_LIST_A_NELEM ; nCount ++ ) {

      const char *szName = ( OptionStringListA [ nCount ] ).szName ;
      char *szValue = ( OptionStringListA [ nCount ] ).szValue ;

      if ( szValue == szBrowsePathA && ! IsSavePath ) continue ;
#if defined RTFCONV_EXE || defined SETUP_R
      if ( szValue == szFontNameArrayDummy ) continue ;
#endif

      if ( *szValue ) fprintf ( Fout, "%s \"%s\"\r\n", szName, szValue ) ;
   }


   // 暥帤楍偺曐懚(UNICODE)
   if ( IsNT () ) {
      for ( int nCount = 0 ; nCount < OPTION_STRING_LIST_W_NELEM ; nCount ++ ) {

         const char *szName = ( OptionStringListW [ nCount ] ).szName ;
         wchar_t *szValue = ( OptionStringListW [ nCount ] ).szValue ;

         if ( szValue == szBrowsePathW && ! IsSavePath ) continue ;
         if ( *szValue ) {
            fprintf ( Fout, "%s ", szName ) ;
            for ( wchar_t *szString = szValue ; *szString ; szString ++ ) fprintf ( Fout, "%04X", *szString ) ;
            fprintf ( Fout, "\r\n" ) ;
         }
      }
   }


#if defined RTFCONV_EXE || defined SETUP_R
   // 僶僀僫儕乕偺曐懚
   for ( int nCount = 0 ; nCount < OPTION_BINARY_LIST_NELEM ; nCount ++ ) {

      const char *szName = ( OptionBinaryList [ nCount ] ).szName ;
      unsigned short *pValue = ( OptionBinaryList [ nCount ] ).pValue ;

#if ! defined SETUP_R
      if ( ! IsLangIdUserDefined && pValue == LangIdArray ) continue ;
#endif

      if ( pValue ) {
         fprintf ( Fout, "%s ", szName ) ;
         for ( unsigned short *pCurrent = pValue ; pCurrent - pValue < ( OptionBinaryList [ nCount ] ).nSize ; pCurrent ++ ) fprintf ( Fout, "%04X", *pCurrent ) ;
         fprintf ( Fout, "\r\n" ) ;
      }
   }
#endif


#if defined RTFCONV_EXE || defined SETUP_R
   // 僼僅儞僩柤偺曐懚
   if ( FontNameArray ) {
      for ( int nCount = 0 ; nCount < OPTION_STRING_LIST_A_NELEM ; nCount ++ ) {

         const char *szName = ( OptionStringListA [ nCount ] ).szName ;
         char *szValue = ( OptionStringListA [ nCount ] ).szValue ;

         if ( szValue == szFontNameArrayDummy ) {
            for ( int nIndex = 0 ; nIndex < UNICODE_BLOCK_NELEM ; nIndex ++ ) {
               char *szValue = FontNameArray + nIndex * LF_FACESIZE ;
               if ( *szValue ) fprintf ( Fout, "%s \"%d, %s\"\r\n", szName, nIndex, szValue ) ;
            }

            break ;
         }
      }
   }
#endif


   return 0 ;
}



#endif // #ifndef CONV_OPT_OLD
#endif // #if defined RTFCONV_EXE || defined CHNCONV_EXE || defined SETUP_R || defined SETUP_C

⌨️ 快捷键说明

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