OSDN Git Service

PATCH: [ 3116407 ] Drop _UNICODE preprocessor definition
authorTim Gerundt <tim@gerundt.de>
Wed, 24 Nov 2010 07:57:25 +0000 (07:57 +0000)
committerTim Gerundt <tim@gerundt.de>
Wed, 24 Nov 2010 07:57:25 +0000 (07:57 +0000)
18 files changed:
Src/AboutDlg.cpp
Src/Common/SuperComboBox.cpp
Src/Common/UniFile.cpp
Src/Common/UnicodeString.h
Src/Common/coretools.cpp
Src/Common/string_util.cpp
Src/Common/unicoder.cpp
Src/ConfigLog.cpp
Src/MainFrm.cpp
Src/ProjectFile.cpp
Src/PropCodepage.cpp
Src/StdAfx.cpp
Src/editlib/ccrystaltextbuffer.cpp
Src/editlib/ccrystaltextview.cpp
Src/editlib/ccrystaltextview.h
Src/editlib/crystalparser.cpp
Src/editlib/filesup.cpp
Src/paths.cpp

index 148dd97..bb3eb2a 100644 (file)
@@ -72,10 +72,8 @@ BOOL CAboutDlg::OnInitDialog()
        String sVersion = version.GetFixedProductVersion();
        LangFormatString1(m_strVersion, IDS_VERSION_FMT, sVersion.c_str());
 
-#ifdef _UNICODE
        m_strVersion += _T(" ");
        m_strVersion += theApp.LoadString(IDS_UNICODE).c_str();
-#endif
 
 #ifdef WIN64
        m_strVersion += _T(" ");
index b558341..47b1bb4 100644 (file)
@@ -421,11 +421,7 @@ CString CSuperComboBox::ExpandShortcut(CString &inFile)
         if (SUCCEEDED(hres))
         {
             WCHAR wsz[MAX_PATH];
-#ifdef _UNICODE
             wcsncpy((wchar_t *)wsz, lpsz, sizeof(wsz)/sizeof(WCHAR));
-#else
-            ::MultiByteToWideChar(CP_ACP, 0, lpsz, -1, wsz, MAX_PATH);
-#endif
 
             // Load shortcut
             hres = ppf->Load((LPCOLESTR)wsz, STGM_READ);
index 4f87629..ad32573 100644 (file)
@@ -466,7 +466,6 @@ bool UniMemFile::ReadString(String & line, String & eol, bool * lossy)
 
        // shortcut methods in case file is in the same encoding as our Strings
 
-#ifdef _UNICODE
        if (m_unicoding == ucr::UCS2LE)
        {
                int cchLine = 0;
@@ -512,53 +511,6 @@ bool UniMemFile::ReadString(String & line, String & eol, bool * lossy)
                line.assign(pchLine, cchLine);
                return true;
        }
-#else
-       if (m_unicoding == ucr::NONE && EqualCodepages(m_codepage, getDefaultCodepage()))
-       {
-               int cchLine = 0;
-               // If there aren't any bytes left in the file, return FALSE to indicate EOF
-               if (m_current - m_base >= m_filesize)
-                       return false;
-               // Loop through chars, watching for eol chars or zero
-               while (m_current - m_base < m_filesize)
-               {
-                       char ch = *m_current;
-                       int ch_offset = (m_current - m_base);
-                       ++m_current;
-                       if (ch == '\n' || ch == '\r')
-                       {
-                               eol += ch;
-                               if (ch == '\r')
-                               {
-                                       if (m_current - m_base < m_filesize && *m_current == '\n')
-                                       {
-                                               eol += '\n';
-                                               ++m_current;
-                                               ++m_txtstats.ncrlfs;
-                                       }
-                                       else
-                                       {
-                                               ++m_txtstats.ncrs;
-                                       }
-                               }
-                               else
-                               {
-                                       ++m_txtstats.nlfs;
-                               }
-                               ++m_lineno;
-                               line.assign(pchLine, cchLine);
-                               return true;
-                       }
-                       if (!ch)
-                       {
-                               RecordZero(m_txtstats, ch_offset);
-                       }
-                       ++cchLine;
-               }
-               line.assign(pchLine, cchLine);
-               return true;
-       }
-#endif
 
        if (m_current - m_base + (m_charsize - 1) >= m_filesize)
                return false;
@@ -965,11 +917,7 @@ int UniStdioFile::WriteBom()
 bool UniStdioFile::WriteString(const String & line)
 {
        // shortcut the easy cases
-#ifdef _UNICODE
        if (m_unicoding == ucr::UCS2LE)
-#else
-       if (m_unicoding == ucr::NONE && EqualCodepages(m_codepage, getDefaultCodepage()))
-#endif
        {
                size_t bytes = line.length() * sizeof(TCHAR);
                size_t wbytes = fwrite(line.c_str(), 1, bytes, m_fp);
index b3d530d..6d3d4c1 100644 (file)
 
 #include <string>
 
-#ifdef _UNICODE
 #define std_tchar(type) std::w##type
-#else
-#define std_tchar(type) std::type
-#endif // _UNICODE
 
 typedef std_tchar(string) String;
 
index 8c83d2a..25d1739 100644 (file)
@@ -197,13 +197,7 @@ BOOL FileExtMatches(LPCTSTR filename, LPCTSTR ext)
  */
 bool IsSlashOrColon(LPCTSTR pszChar, LPCTSTR begin)
 {
-#ifdef _UNICODE
                return (*pszChar == '/' || *pszChar == ':' || *pszChar == '\\');
-#else
-               // Avoid 0x5C (ASCII backslash) byte occurring as trail byte in MBCS
-               return (*pszChar == '/' || *pszChar == ':' 
-                       || (*pszChar == '\\' && !_ismbstrail((unsigned char *)begin, (unsigned char *)pszChar)));
-#endif
 }
 
 /**
index 4d2bc2e..c6223a8 100644 (file)
@@ -20,11 +20,7 @@ static wint_t normch(wint_t c);
 // codepoints don't extend that high).
 static wint_t normch(wint_t c)
 {
-#ifdef _UNICODE
        return (unsigned short)(short)c;
-#else
-       return (unsigned char)(char)c;
-#endif
 }
 
 /** @brief Return nonzero if input is outside ASCII or is underline. */
index 13bb736..78102bf 100644 (file)
@@ -313,7 +313,6 @@ String maketchar(unsigned int unich, bool & lossy)
  */
 String maketchar(unsigned int unich, bool & lossy, unsigned int codepage)
 {
-#ifdef _UNICODE
        if (unich < 0x10000)
        {
                String s(1, (TCHAR)unich);
@@ -321,47 +320,6 @@ String maketchar(unsigned int unich, bool & lossy, unsigned int codepage)
        }
        lossy = TRUE;
        return _T("?");
-#else
-       if (unich < 0x80)
-       {
-               String s(1, (TCHAR)unich);
-               return s;
-       }
-       wchar_t wch = (wchar_t)unich;
-       if (!lossy)
-       {
-               static bool vercheck = false;
-               static bool has_no_best_fit = false;
-               if (!vercheck)
-               {
-                       if (!f_osvi_fetched) fetch_verinfo();
-                       // Need 2000 (5.x) or 98 (4.10)
-                       has_no_best_fit = f_osvi.dwMajorVersion >= 5 || (f_osvi.dwMajorVersion == 4 && f_osvi.dwMinorVersion >= 10);
-                       vercheck = true;
-               }
-               // So far it isn't lossy, so try for lossless conversion
-               TCHAR outch;
-               BOOL defaulted = FALSE;
-               DWORD flags = has_no_best_fit ? WC_NO_BEST_FIT_CHARS : 0;
-               if (WideCharToMultiByte(codepage, flags, &wch, 1, &outch, 1, NULL, &defaulted)
-                               && !defaulted)
-               {
-                       String s(1, outch);
-                       return s;
-               }
-               lossy = TRUE;
-       }
-       // already lossy, so make our best shot
-       DWORD flags = WC_COMPOSITECHECK + WC_DISCARDNS + WC_SEPCHARS + WC_DEFAULTCHAR;
-       TCHAR outbuff[16];
-       int n = WideCharToMultiByte(codepage, flags, &wch, 1, outbuff, sizeof(outbuff) - 1, NULL, NULL);
-       if (n > 0)
-       {
-               outbuff[n] = 0;
-               return outbuff;
-       }
-       return _T("?");
-#endif
 }
 
 /**
@@ -398,14 +356,8 @@ unsigned int byteToUnicode(unsigned char ch, unsigned int codepage)
  */
 void getInternalEncoding(UNICODESET * unicoding, int * codepage)
 {
-#ifdef _UNICODE
        *unicoding = UCS2LE;
        *codepage = 0;
-#else
-       // NB: Windows always draws in CP_ACP, not CP_THREAD_ACP, so we must use CP_ACP as an internal codepage
-       *unicoding = NONE;
-       *codepage = CP_ACP;
-#endif
 }
 
 /**
index 62ddca7..2da9f7a 100644 (file)
@@ -394,20 +394,14 @@ bool CConfigLog::DoFile(bool writing, String &sError)
                paths_CreateIfNeeded(sFileName.c_str());
                m_sFileName = paths_ConcatPath(sFileName, _T("WinMerge.txt"));
 
-#ifdef _UNICODE
                if (!m_pfile->OpenCreateUtf8(m_sFileName.c_str()))
-#else
-               if (!m_pfile->OpenCreate(m_sFileName.c_str()))
-#endif
                {
                        const UniFile::UniError &err = m_pfile->GetLastUniError();
                        sError = err.GetError();
                        return false;
                }
-#ifdef _UNICODE
                m_pfile->SetBom(true);
                m_pfile->WriteBom();
-#endif
        }
 
 // Begin log
index ef257ca..3b5aed4 100644 (file)
@@ -365,11 +365,7 @@ protected:
 
 static StatusDisplay myStatusDisplay;
 
-#ifdef _UNICODE
 const TCHAR CMainFrame::szClassName[] = _T("WinMergeWindowClassW");
-#else
-const TCHAR CMainFrame::szClassName[] = _T("WinMergeWindowClassA");
-#endif
 /**
  * @brief Change MainFrame window class name
  *        see http://support.microsoft.com/kb/403825/ja
@@ -3415,17 +3411,10 @@ BOOL CMainFrame::OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult)
                // this is the command id, not the button index
                AfxExtractSubString(strTipText, strFullText.c_str(), 1, '\n');
        }
-#ifndef _UNICODE
-       if (pNMHDR->code == TTN_NEEDTEXTA)
-               lstrcpyn(pTTTA->szText, strTipText, countof(pTTTA->szText));
-       else
-               _mbstowcsz(pTTTW->szText, strTipText, countof(pTTTW->szText));
-#else
        if (pNMHDR->code == TTN_NEEDTEXTA)
                _wcstombsz(pTTTA->szText, strTipText, countof(pTTTA->szText));
        else
                lstrcpyn(pTTTW->szText, strTipText, countof(pTTTW->szText));
-#endif
        *pResult = 0;
 
        // bring the tooltip window above other popup windows
index 54ebe7e..406e0e8 100755 (executable)
 
 #define UTF82A(lpu) W2A(UTF82W(lpu))
 #define A2UTF8(lpa) W2UTF8(A2W(lpa))
-#ifdef _UNICODE
 #  define UTF82T(lpu) UTF82W(lpu)
 #  define T2UTF8(lpw) W2UTF8(lpw)
-#else
-#  define UTF82T(lpu) UTF82A(lpu)
-#  define T2UTF8(lpw) A2UTF8(lpw)
-#endif
 
 // Constants for xml element names
 const char Root_element_name[] = "project";
index 9c0f741..2b76b4d 100644 (file)
@@ -128,13 +128,8 @@ void PropCodepage::GetEncodingCodePageFromNameString()
        if (nCustomCodepageValue == 0)
        {
                char *result= new char[80]; 
-#ifdef _UNICODE
                long len = wcslen(m_cCustomCodepageValue); 
                _wcstombsz(result, m_cCustomCodepageValue, len); //conversion to char * 
-#else
-               long len = m_cCustomCodepageValue.GetLength(); 
-               strncpy(result, m_cCustomCodepageValue.GetBuffer(0), len);
-#endif
                result[len] = '\0'; //don't forget to put the caracter of terminated string 
                nCustomCodepageValue = GetEncodingCodePageFromName(result);
                delete [] result;
index fe1989b..ca11ffa 100644 (file)
@@ -152,11 +152,7 @@ CString Fmt(LPCTSTR fmt, ...)
 // Get appropriate clipboard format for TCHAR text
 int GetClipTcharTextFormat()
 {
-#ifdef _UNICODE
        return CF_UNICODETEXT;
-#else
-       return CF_TEXT;
-#endif // _UNICODE
 }
 
 #if _MSC_VER <= 1310
index 68d4a62..f51d481 100644 (file)
@@ -525,11 +525,7 @@ BOOL CCrystalTextBuffer::SaveToFile(LPCTSTR pszFileName,
   __try
   {
     TCHAR drive[_MAX_PATH], dir[_MAX_PATH], name[_MAX_PATH], ext[_MAX_PATH];
-#ifdef _UNICODE
     _wsplitpath (pszFileName, drive, dir, name, ext);
-#else
-    _splitpath (pszFileName, drive, dir, name, ext);
-#endif
     _tcscpy (szTempFileDir, drive);
     _tcscat (szTempFileDir, dir);
     _tcscpy (szBackupFileName, pszFileName);
@@ -1845,15 +1841,7 @@ IsMBSLead (int nLine, int nCol) const
   ASSERT (m_bInit);             //  Text buffer not yet initialized.
   //  You must call InitNew() or LoadFromFile() first!
 
-#ifdef _UNICODE
-  return FALSE;
-#else // _UNICODE
-  const unsigned char *string = (const unsigned char *) GetLineChars (nLine);
-  const unsigned char *current = string + nCol;
-  if (_ismbslead (string, current) < 0)
-    return TRUE;
   return FALSE;
-#endif // _UNICODE
 }
 
 BOOL CCrystalTextBuffer::
@@ -1862,15 +1850,7 @@ IsMBSTrail (int nLine, int nCol) const
   ASSERT (m_bInit);             //  Text buffer not yet initialized.
   //  You must call InitNew() or LoadFromFile() first!
 
-#ifdef _UNICODE
-  return FALSE;
-#else // _UNICODE
-  const unsigned char *string = (const unsigned char *) GetLineChars (nLine);
-  const unsigned char *current = string + nCol;
-  if (_ismbstrail (string, current) < 0)
-    return TRUE;
   return FALSE;
-#endif // _UNICODE
 }
 
 //BEGIN SW
index b418515..891c2d9 100644 (file)
@@ -1020,10 +1020,6 @@ DrawLineHelperImpl (CDC * pdc, CPoint & ptOrigin, const CRect & rcClip,
               int nCount = lineLen - ibegin;
               int nCountFit = nWidth / nCharWidth + 2/* wide char */;
               if (nCount > nCountFit) {
-#ifndef _UNICODE
-                if (_ismbslead((unsigned char *)(LPCSTR)line, (unsigned char *)(LPCSTR)line + nCountFit - 1))
-                  nCountFit++;
-#endif
                 nCount = nCountFit;
               }
 
@@ -1660,10 +1656,6 @@ EscapeHTML (const CString & strText, BOOL & bLastCharSpace, int & nNonbreakChars
             bLastCharSpace = FALSE;
             nNonbreakChars++;
         }
-#ifndef _UNICODE
-      if (IsDBCSLeadByte (ch))
-        strHTML += strText[++i];
-#endif
       if ((nNonbreakChars % nScreenChars) == nScreenChars - 1)
         {
           strHTML += _T("<wbr>");
@@ -6002,7 +5994,6 @@ CString CCrystalTextView::GetTextBufferEol(int nLine) const
   return m_pTextBuffer->GetLineEol(nLine); 
 }
 
-#ifdef _UNICODE
 int CCrystalTextView::GetCharWidthUnicodeChar(wchar_t ch)
 {
   if (!m_bChWidthsCalculated[ch/256])
@@ -6037,15 +6028,12 @@ int CCrystalTextView::GetCharWidthUnicodeChar(wchar_t ch)
   else
     return GetCharWidth();
 }
-#endif
 
 /** @brief Reset computed unicode character widths. */
 void CCrystalTextView::ResetCharWidths ()
 {
-#ifdef _UNICODE
   ZeroMemory(m_bChWidthsCalculated, sizeof(m_bChWidthsCalculated));
   ZeroMemory(m_iChDoubleWidthFlags, sizeof(m_iChDoubleWidthFlags));
-#endif
 }
 
 // This function assumes selection is in one line
index d1cf5ba..ab634cb 100644 (file)
@@ -465,11 +465,9 @@ protected:
     int GetCharWidthFromString(LPCTSTR lpsz);
     int GetCharWidthFromDisplayableChar(const ViewableWhitespaceChars * lpspc, TCHAR ch);
 
-#ifdef _UNICODE
     BOOL m_bChWidthsCalculated[65536/256];
     int m_iChDoubleWidthFlags[65536/32];
     int GetCharWidthUnicodeChar(wchar_t ch);
-#endif
     void ResetCharWidths();
 
        //BEGIN SW
index 67cd530..eeed395 100644 (file)
@@ -95,14 +95,7 @@ void CCrystalParser::WrapLine( int nLineIndex, int nMaxLineWidth, int *anBreaks,
 
                // remember whitespace
                WORD wCharType;
-#ifdef _UNICODE
                GetStringTypeW(CT_CTYPE3, &szLine[i], 1, &wCharType);
-#else
-               if (IsDBCSLeadByte((BYTE)szLine[i]))
-                       GetStringTypeA(LOCALE_USER_DEFAULT,CT_CTYPE3, &szLine[i], 2, &wCharType);
-               else
-                       wCharType = 0;
-#endif
                if( szLine[i] == _T('\t') || szLine[i] == _T(' ') || (wCharType & (C3_IDEOGRAPH | C3_HIRAGANA | C3_KATAKANA)))
                        bBreakable = TRUE;
 
index e4ce893..b8147e8 100644 (file)
@@ -45,11 +45,7 @@ GetExtPosition (LPCTSTR pszString)
   do
     if ((test = sString.GetAt (--posit)) == _T ('.'))
       return posit;
-#ifdef _UNICODE
   while (posit && test != _T ('\\') && test != _T (':'));
-#else
-  while (posit && (test != _T ('\\') || _ismbstrail((unsigned char *)pszString, (unsigned char *)pszString + posit)) && test != _T (':'));
-#endif
   return len;
 }
 
@@ -90,11 +86,7 @@ GetNamePosition (LPCTSTR pszString)
   int posit = sString.GetLength ();
   TCHAR test;
   do
-#ifdef _UNICODE
     if ((test = sString.GetAt (--posit)) == _T ('\\') || test == _T (':'))
-#else
-    if (((test = sString.GetAt (--posit)) == _T ('\\') && !_ismbstrail((unsigned char *)pszString, (unsigned char *)pszString + posit)) || test == _T (':'))
-#endif
       return posit + 1;
   while (posit);
   return posit;
@@ -111,11 +103,7 @@ GetPath (const CString & sString, BOOL bClose /*= FALSE*/ )
 
   TCHAR test = sString.GetAt (posit - 1);
 
-#ifdef _UNICODE
   if (test == _T (':') || test == _T ('\\') && (posit == 1 || posit != 1 && sString.GetAt (posit - 2) == _T (':')))
-#else
-  if (test == _T (':') || (test == _T ('\\') && !_ismbstrail((unsigned char *)(LPCTSTR)sString, (unsigned char *)(LPCTSTR)sString + posit)) && (posit == 1 || posit != 1 && sString.GetAt (posit - 2) == _T (':')))
-#endif
     return sString.Left (posit);
   return sString.Left (bClose ? posit : test == _T (':') ? posit : posit - 1);
 }
index 234d00f..5b19b07 100644 (file)
@@ -26,12 +26,7 @@ static bool GetDirName(LPCTSTR sDir, String& sName);
 static bool IsSlash(LPCTSTR pszStart, int nPos)
 {
        return pszStart[nPos]=='/' || 
-#ifdef _UNICODE
               pszStart[nPos]=='\\';
-#else
-               // Avoid 0x5C (ASCII backslash) byte occurring as trail byte in MBCS
-              (pszStart[nPos]=='\\' && !_ismbstrail((unsigned char *)pszStart, (unsigned char *)pszStart + nPos));
-#endif
 }
 
 /** 
@@ -431,11 +426,7 @@ String ExpandShortcut(const String &inFile)
                if (SUCCEEDED(hres))
                {
                        WCHAR wsz[MAX_PATH];
-#ifdef _UNICODE
                        wcsncpy((wchar_t *)wsz, inFile.c_str(), sizeof(wsz) / sizeof(WCHAR));
-#else
-                       ::MultiByteToWideChar(CP_ACP, 0, inFile.c_str(), -1, wsz, MAX_PATH);
-#endif
 
                        // Load shortcut
                        hres = ppf->Load(wsz, STGM_READ);