OSDN Git Service

PATCH: [ 3104374 ] Drop UNICODE preprocessor definition
authorTim Gerundt <tim@gerundt.de>
Sat, 20 Nov 2010 11:52:43 +0000 (11:52 +0000)
committerTim Gerundt <tim@gerundt.de>
Sat, 20 Nov 2010 11:52:43 +0000 (11:52 +0000)
16 files changed:
Src/AnsiConvert.cpp
Src/BCMenu.cpp
Src/BCMenu.h
Src/Common/Ucs2Utf8.cpp
Src/Common/unicoder.cpp
Src/Common/unicoder.h
Src/ConfigLog.cpp
Src/DiffWrapper.cpp
Src/DirDoc.cpp
Src/DirViewColItems.cpp
Src/FileFilterHelper.cpp
Src/Merge2.rc
Src/StdAfx.cpp
Src/ViewableWhitespace.cpp
Src/editlib/ccrystaltextview.cpp
Src/stringdiffs.cpp

index 4a8dc22..ae54d8c 100644 (file)
@@ -46,9 +46,6 @@ LPCSTR ansiconvert_ThreadCP(LPCTSTR str)
  */
 LPCSTR convert(LPCTSTR str, UINT codepage)
 {
-#ifndef UNICODE
-       return _strdup(str);
-#else
        int len = WideCharToMultiByte(codepage, 0, str, -1, 0, 0, 0, 0);
        if (len)
        {
@@ -57,5 +54,4 @@ LPCSTR convert(LPCTSTR str, UINT codepage)
                return ansi;
        }
        return NULL;
-#endif
 }
index 18bd4e3..e6e8ce0 100644 (file)
@@ -129,12 +129,7 @@ CString BCMenuData::GetString(void)//returns the menu text in ANSI or UNICODE
        CString strText;
        if (m_szMenuText)
     {
-#ifdef UNICODE
                strText = m_szMenuText;
-#else
-               USES_CONVERSION;
-               strText=W2A(m_szMenuText);     //SK:  see MFC Tech Note 059
-#endif    
     }
        return strText;
 }
@@ -989,18 +984,6 @@ void BCMenu::MeasureItem( LPMEASUREITEMSTRUCT lpMIS )
                if (Win32s!=g_Shell)
                        VERIFY(::GetTextExtentPoint32W(pDC->m_hDC,lpstrText,
                        wcslen(lpstrText),&size)); //SK should also work on 95
-#ifndef UNICODE //can't be UNICODE for Win32s
-               else{//it's Win32suckx
-                       RECT rect;
-                       rect.left=rect.top=0;
-                       size.cy=DrawText(pDC->m_hDC,(LPCTSTR)lpstrText,
-                               wcslen(lpstrText),&rect,
-                               DT_SINGLELINE|DT_LEFT|DT_VCENTER|DT_CALCRECT);
-                       //+3 makes at least three pixels space to the menu border
-                       size.cx=rect.right-rect.left+3;
-                       size.cx += 3*(size.cx/wcslen(lpstrText));
-               }
-#endif    
                
                CSize t = CSize(size);
                if(IsNewShell())
@@ -1474,11 +1457,7 @@ BCMenuData *BCMenu::NewODMenu(UINT pos,UINT nFlags,UINT nID,CString string)
        mdata = new BCMenuData;
        mdata->menuIconNormal = -1;
        mdata->xoffset=-1;
-#ifdef UNICODE
        mdata->SetWideString((LPCTSTR)string);//SK: modified for dynamic allocation
-#else
-       mdata->SetAnsiString(string);
-#endif
        mdata->nFlags = nFlags;
        mdata->nID = nID;
        
@@ -1900,11 +1879,7 @@ void BCMenu::InsertSpaces(void)
                                t=pDC->GetTextExtent(lpstrText,(int)_tcslen(lpstrText));
                        }
                        newstring+=string.Mid(j);
-#ifdef UNICODE      
                        m_MenuList[i]->SetWideString(newstring);//SK: modified for dynamic allocation
-#else
-                       m_MenuList[i]->SetAnsiString(newstring);
-#endif
                }
        }
        pDC->SelectObject (pFont);              // Select old font in
@@ -2045,11 +2020,7 @@ void BCMenu::SynchronizeMenu(void)
                        if(!mdata)mdata=NewODMenu(j,
                                (state&0xFF)|MF_BYPOSITION|MF_POPUP|MF_OWNERDRAW,submenu,string);
                        else if(string.GetLength()>0)
-#ifdef UNICODE
                                mdata->SetWideString(string);  //SK: modified for dynamic allocation
-#else
-                       mdata->SetAnsiString(string);
-#endif
                }
                else if(state&MF_SEPARATOR){
                        mdata=FindMenuList(0);
@@ -2066,11 +2037,7 @@ void BCMenu::SynchronizeMenu(void)
                        else{
                                mdata->nFlags=state|MF_BYPOSITION|MF_OWNERDRAW;
                                if(string.GetLength()>0)
-#ifdef UNICODE
                                        mdata->SetWideString(string);//SK: modified for dynamic allocation
-#else
-                               mdata->SetAnsiString(string);
-#endif
                                
                                ModifyMenu(j,mdata->nFlags,nID,(LPCTSTR)mdata);
                        }
@@ -3041,11 +3008,7 @@ BOOL BCMenu::SetMenuText(UINT id, CString string, UINT nFlags/*= MF_BYPOSITION*/
        {
                INT_PTR numMenuItems = m_MenuList.GetUpperBound();
                if(id<=numMenuItems){
-#ifdef UNICODE
                        m_MenuList[id]->SetWideString((LPCTSTR)string);
-#else
-                       m_MenuList[id]->SetAnsiString(string);
-#endif
                        returnflag=TRUE;
                }
        }
index 4ff5e26..67bc302 100644 (file)
@@ -50,11 +50,7 @@ public:
 //struct CMenuItemInfo : public MENUITEMINFO {
 struct CMenuItemInfo : public 
 //MENUITEMINFO 
-#ifndef UNICODE   //SK: this fixes warning C4097: typedef-name 'MENUITEMINFO' used as synonym for class-name 'tagMENUITEMINFOA'
-tagMENUITEMINFOA
-#else
 tagMENUITEMINFOW
-#endif
 {
        CMenuItemInfo()
        {
@@ -70,15 +66,6 @@ typedef enum {BCMENU_DRAWMODE_ORIGINAL,BCMENU_DRAWMODE_XP} BC_MenuDrawMode;
 typedef enum {BCMENU_NONE, BCMENU_HEAD, BCMENU_TAIL, BCMENU_BOTH} BC_Seperator;
 
 // defines for unicode support
-#ifndef UNICODE
-#define AppendMenu AppendMenuA
-#define InsertMenu InsertMenuA
-#define InsertODMenu InsertODMenuA
-#define AppendODMenu AppendODMenuA
-#define AppendODPopupMenu AppendODPopupMenuA
-#define ModifyODMenu ModifyODMenuA
-#define SetImageForPopupFromToolbar SetImageForPopupFromToolbarA
-#else
 #define AppendMenu AppendMenuW
 #define InsertMenu InsertMenuW
 #define InsertODMenu InsertODMenuW
@@ -86,7 +73,6 @@ typedef enum {BCMENU_NONE, BCMENU_HEAD, BCMENU_TAIL, BCMENU_BOTH} BC_Seperator;
 #define ModifyODMenu ModifyODMenuW
 #define AppendODPopupMenu AppendODPopupMenuW
 #define SetImageForPopupFromToolbar SetImageForPopupFromToolbarW
-#endif
 
 
 class BCMenu : public CMenu
index 9ec78ab..b10a4bd 100644 (file)
@@ -102,7 +102,6 @@ UINT TransformUtf8ToUcs2(LPCSTR pcsUtf, UINT nUtf, LPWSTR psUcs, UINT nUcs)
  */
 char * UCS2UTF8_ConvertToUtf8(LPCTSTR strOrigin)
 {
-#ifdef UNICODE
        // Get the size of UTF-8 string
        int str_len = TransformUcs2ToUtf8(strOrigin, _tcslen(strOrigin), NULL, 0);
        ++str_len; // Space for zero at end
@@ -110,9 +109,6 @@ char * UCS2UTF8_ConvertToUtf8(LPCTSTR strOrigin)
        char * str_utf = (char *) malloc(str_len);
        ZeroMemory(str_utf, str_len);
        str_len = TransformUcs2ToUtf8(strOrigin, _tcslen(strOrigin), str_utf, str_len);
-#else
-       char *str_utf = strdup(strOrigin);
-#endif
        
        return str_utf;
 }
index c9953df..13bb736 100644 (file)
@@ -489,7 +489,6 @@ bool maketstring(String & str, const char* lpd, unsigned int len, int codepage,
        if (codepage == -1)
                codepage = defcodepage;
 
-#ifdef UNICODE
        // Convert input to Unicode, using specified codepage
        // TCHAR is wchar_t, so convert into String (str)
        DWORD flags = MB_ERR_INVALID_CHARS;
@@ -543,39 +542,9 @@ bool maketstring(String & str, const char* lpd, unsigned int len, int codepage,
        while (flags == 0 && GetLastError() == ERROR_NO_UNICODE_TRANSLATION);
        str = _T('?');
        return true;
-
-#else
-       if (EqualCodepages(codepage, defcodepage))
-       {
-               // trivial case, they want the bytes in the file interpreted in our current codepage
-               // Only caveat is that input (lpd) is not zero-terminated
-               str = String(lpd, len);
-               return true;
-       }
-
-       str = CrossConvertToStringA(lpd, len, codepage, defcodepage, lossy);
-       return true;
-#endif
 }
 
 /**
- * @brief (ANSI build only) Convert from one 8 bit codepage to another
- */
-#ifndef UNICODE
-String CrossConvertToStringA(const char* src, unsigned int srclen, int cpin, int cpout, bool * lossy)
-{
-       int wlen = srclen * 2 + 6;
-       int clen = wlen * 2 + 6;
-       String str;
-       str.resize(clen);
-       char* cbuff = &*str.begin();
-       int nbytes = CrossConvert(src, srclen, cbuff, clen, cpin, cpout, lossy);
-       str.resize(nbytes);
-       return str;
-}
-#endif
-
-/**
  * @brief Convert from one 8-bit codepage to another
  *
  * destsize must be at least 2
index fe4c9a6..7cc1194 100644 (file)
@@ -63,9 +63,6 @@ void getInternalEncoding(UNICODESET * unicoding, int * codepage);
 bool convert(UNICODESET unicoding1, int codepage1, const unsigned char * src, int srcbytes, UNICODESET unicoding2, int codepage2, buffer * dest);
 
 int CrossConvert(const char* src, unsigned int srclen, char* dest, unsigned int destsize, int cpin, int cpout, bool * lossy);
-#ifndef UNICODE
-String CrossConvertToStringA(const char* src, unsigned int srclen, int cpin, int cpout, bool * lossy);
-#endif
 
 UNICODESET DetermineEncoding(PBYTE pBuffer, INT64 size, bool * pBom);
 
index bd929f1..62ddca7 100644 (file)
@@ -528,9 +528,6 @@ bool CConfigLog::DoFile(bool writing, String &sError)
        FileWriteString(_T(" codepage settings:\r\n"));
        WriteItem(2, _T("ANSI codepage"), GetACP());
        WriteItem(2, _T("OEM codepage"), GetOEMCP());
-#ifndef UNICODE
-       WriteItem(2, _T("multibyte codepage"), _getmbcp());
-#endif
        WriteLocaleSettings(GetThreadLocale(), _T("Locale (Thread)"));
        WriteLocaleSettings(LOCALE_USER_DEFAULT, _T("Locale (User)"));
        WriteLocaleSettings(LOCALE_SYSTEM_DEFAULT, _T("Locale (System)"));
index 1de74df..0358274 100644 (file)
@@ -1353,14 +1353,8 @@ void CDiffWrapper::SetFilterList(LPCTSTR filterStr)
        char * regexp_str;
        FilterList::EncodingType type;
        
-#ifdef UNICODE
        regexp_str = UCS2UTF8_ConvertToUtf8(filterStr);
        type = FilterList::ENC_UTF8;
-#else
-       CString tmp_str(filterStr);
-       regexp_str = tmp_str.LockBuffer();
-       type = FilterList::ENC_ANSI;
-#endif
 
        // Add every "line" of regexps to regexp list
        char * token;
@@ -1371,11 +1365,7 @@ void CDiffWrapper::SetFilterList(LPCTSTR filterStr)
                m_pFilterList->AddRegExp(token, type);
                token = strtok(NULL, sep);
        }
-#ifdef UNICODE
        UCS2UTF8_Dealloc(regexp_str);
-#else
-       tmp_str.UnlockBuffer();
-#endif
 }
 
 /**
index 398d98e..ca832d5 100644 (file)
@@ -295,19 +295,12 @@ void CDirDoc::LoadLineFilterList()
        char * regexp_str;
        FilterList::EncodingType type;
 
-#ifdef UNICODE
        regexp_str = UCS2UTF8_ConvertToUtf8(filters.c_str());
        type = FilterList::ENC_UTF8;
-#else
-       regexp_str = (char *) filters.c_str();
-       type = FilterList::ENC_ANSI;
-#endif
 
        m_pCtxt->m_pFilterList->AddRegExp(regexp_str, type);
 
-#ifdef UNICODE
        UCS2UTF8_Dealloc(regexp_str);
-#endif
 }
 
 /**
index 87e7b6d..53a0b51 100644 (file)
 #include "coretools.h"
 
 // shlwapi.h prior to VC6SP6 might lack definition of StrIsIntlEqual
-#ifdef UNICODE
 #define StrIsIntlEqual StrIsIntlEqualW
-#else
-#define StrIsIntlEqual StrIsIntlEqualA
-#endif
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
index 65a08cb..dba669e 100644 (file)
@@ -211,20 +211,13 @@ void FileFilterHelper::SetMask(LPCTSTR strMask)
        char * regexp_str;
        FilterList::EncodingType type;
 
-#ifdef UNICODE
        regexp_str = UCS2UTF8_ConvertToUtf8(regExp.c_str());
        type = FilterList::ENC_UTF8;
-#else
-       regexp_str = &*regExp.begin();
-       type = FilterList::ENC_ANSI;
-#endif
 
        m_pMaskFilter->RemoveAllFilters();
        m_pMaskFilter->AddRegExp(regexp_str, type);
 
-#ifdef UNICODE
        UCS2UTF8_Dealloc(regexp_str);
-#endif
 }
 
 /**
index 122106d..205cbca 100644 (file)
@@ -5,11 +5,7 @@
 
 // Include the manifest file for VC6 and VS2003.Net
 #if _MSC_VER < 1400
-  #ifdef UNICODE
-    CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "res\\WinMergeU.exe.manifest"
-  #else
-    CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "res\\WinMerge.exe.manifest"
-  #endif
+  CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "res\\WinMergeU.exe.manifest"
 #endif // MSC_VER
 
 
index 5d0d111..7658174 100644 (file)
@@ -164,11 +164,7 @@ int GetClipTcharTextFormat()
  */
 bool IsUnicodeBuild()
 {
-#ifdef UNICODE
        return true;
-#else
-       return false;
-#endif
 }
 
 #if _MSC_VER <= 1310
index 1ba28e9..e07c59d 100644 (file)
@@ -12,7 +12,6 @@
 /** @brief Is structure initialized? */
 static bool f_initialized = false;
 
-#ifdef UNICODE
 // For UNICODE build, there is just one set which is always used
 // tab, space, cr, lf, eol
 
@@ -44,65 +43,6 @@ static void initialize()
        f_initialized = true;
 }
 
-#else
-// For ANSI build, there are various sets for different codepages
-static CMap<int, int, int, int> f_offset; // map codepage to offset
-
-// tab, space, cr, lf, eol
-/** @brief Structure for whitespace characters.
- *  Char order is tab, space, cr, lf, eol.
- */
-static struct ViewableWhitespaceChars
- f_specialChars[] = {
-        { 0, ">", ".", "$", "!", "&" } // default all-ASCII for unhandled codepages
-       , { 850, "\xAF", "\xFA", "\xF5", "\xF4", "\xCF" } // CP-850 MSDOS Multilingual
-
-       // CP-932 Windows version of Japanese ShiftJIS
-       // \x81\x98 = u+A7
-       // \x81\xF7 = u+B6
-       , { 932, ">", ".", "\x81\x98", "\x81\xF7", "&" } // CP-932 Japanese
-
-       // CP-949 Korean
-       // \xA1\xA4 = u+B7
-       // \xA1\xD7 = u+A7
-       // \xA2\xD2 = u+B6
-       // \xA2\xB4 = u+A4
-       , { 949, ">", "\xA1\xA4", "\xA1\xD7", "\xA2\xD2", "\xA2\xB4" } // CP-949 Korean
-
-       // CP-950 Windows version of Big5 Chinese Traditional
-       // \xA1\x6D = u+300A
-       // \xA1\x50 = u+B7
-       // \xA1\xB1 = u+A7
-       // \xA2\x54 = ?
-       // \xA1\x3B = u+33A1
-       , { 951, "\xA1\x6D", "\xA1\x50", "\xA1\xB1", "\xA2\x54", "\xA1\x3B" } // CP-950 Chinese Traditional
-
-       , { 1250, "\xBB", "\xB7", "\xA7", "\xB6", "\xA4" } // CP-1250 Central Europe
-       , { 1251, "\xBB", "\xB7", "\xA7", "\xB6", "\xA4" } // CP-1251 Windows Cyrillic
-       , { 1252, "\xBB", "\xB7", "\xA7", "\xB6", "\xA4" } // CP-1252 Western Europe
-       , { 1253, "\xBB", "\xB7", "\xA7", "\xB6", "\xA4" } // CP-1253 Windows Greek
-       , { 1254, "\xBB", "\xB7", "\xA7", "\xB6", "\xA4" } // CP-1254 Windows Turkish
-       , { 1255, "\xBB", "\xB7", "\xA7", "\xB6", "\xA5" } // CP-1255 Windows Hebrew
-       , { 1256, "\xBB", "\xB7", "\xA7", "\xB6", "\xA4" } // CP-1256 Windows Arabic
-       , { 1257, "\xBB", "\xB7", "\xA7", "\xB6", "\xA4" } // CP-1257 Windows Baltic Rim
-};
-
-/**
- * @brief Initialize whitespace chars structure.
- */
-static void initialize()
-{
-       for (int i=0; i<sizeof(f_specialChars)/sizeof(f_specialChars[0]); ++i)
-       {
-               int codepage = f_specialChars[i].c_codepage;
-               f_offset[codepage] = i;
-       }
-
-       f_initialized = true;
-}
-
-#endif
-
 /**
  * @brief Return viewable whitespace chars.
  * @param [in] codepage Used codepage (only efective in ANSI builds).
@@ -112,15 +52,5 @@ const ViewableWhitespaceChars * GetViewableWhitespaceChars(int codepage)
 {
        if (!f_initialized)
                initialize();
-#ifdef UNICODE
        return &f_specialChars;
-#else
-       // Use the [0] version by default, if lookup fails to find a better one
-       int offset = 0;
-       if (f_offset.Lookup(codepage, offset))
-       {
-               int d=9;
-       }
-       return &f_specialChars[offset];
-#endif
 }
index 5f1c755..b418515 100644 (file)
@@ -926,11 +926,7 @@ int CCrystalTextView::GetCharWidthFromChar(TCHAR ch)
     return GetCharWidth() * 3;
   // This assumes a fixed width font
   // But the UNICODE case handles double-wide glyphs (primarily Chinese characters)
-#ifdef _UNICODE
   return GetCharWidthUnicodeChar(ch);
-#else
-  return GetCharWidth();
-#endif
 }
 
 /**
@@ -940,14 +936,10 @@ int CCrystalTextView::GetCharWidthFromString(LPCTSTR lpsz)
 {
   // This assumes a fixed width font
   // But the UNICODE case handles double-wide glyphs (primarily Chinese characters)
-#ifdef _UNICODE
   int n=0;
   for (LPCTSTR p = lpsz; *p; ++p)
     n += GetCharWidthUnicodeChar(*p);
   return n;
-#else
-  return strlen(lpsz) * GetCharWidth();
-#endif
 }
 
 /**
@@ -2397,11 +2389,7 @@ int CCrystalTextView::CharPosToPoint( int nLineIndex, int nCharPos, CPoint &char
 /** Does character introduce a multicharacter character? */
 static inline bool IsLeadByte(TCHAR ch)
 {
-#ifdef UNICODE
   return false;
-#else
-  return _getmbcp() && IsDBCSLeadByte(ch);
-#endif
 }
 
 int CCrystalTextView::CursorPointToCharPos( int nLineIndex, const CPoint &curPoint )
@@ -4538,13 +4526,8 @@ FindStringHelper (LPCTSTR pszFindWhere, LPCTSTR pszFindWhat, DWORD dwFlags,
 
     if (result >= 0)
     {
-#ifdef UNICODE
       pos = ucr::stringlen_of_utf8(compString, ovector[0]);
       nLen = ucr::stringlen_of_utf8(compString, ovector[1]) - pos;
-#else
-      pos = ovector[0];
-      nLen = ovector[1] - ovector[0];
-#endif
     }
     else
       pos = -1;
index a75f223..869bbb3 100644 (file)
@@ -1216,11 +1216,7 @@ matchchar(TCHAR ch1, TCHAR ch2, bool casitive)
 /** Does character introduce a multicharacter character? */
 static inline bool IsLeadByte(TCHAR ch)
 {
-#ifdef UNICODE
        return false;
-#else
-       return _getmbcp() && IsDBCSLeadByte(ch);
-#endif
 }
 
 /**