OSDN Git Service

BUG: [ 1630762 ] Cannot save project file if including non-ascii chars
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sat, 31 Mar 2007 19:58:25 +0000 (19:58 +0000)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sat, 31 Mar 2007 19:58:25 +0000 (19:58 +0000)
Src/Changes.txt
Src/Merge.dsp
Src/ProjectFile.cpp

index f4cb3ab..716ecc4 100644 (file)
@@ -3,6 +3,10 @@ Add new items to top.
 (This summarizes all changes to all files under Src, including Src\Languages.)
 
 2007-03-31 Takashi
+ BUG: [ 1630762 ] Cannot save project file if including non-ascii chars
+  Src: Merge.dsp ProjectFile.cpp
+
+2007-03-31 Takashi
  PATCH: [ 1603292 ] Add tab interface for MDI child windows
   Src: MainFrm.cpp MainFrm.h Merge.dsp Merge.rc OptionsDef.h OptionsInit.cpp
    resource.h
index 97639bd..b2fe81b 100644 (file)
@@ -72,7 +72,7 @@ LINK32=link.exe
 # PROP Ignore_Export_Lib 0
 # PROP Target_Dir ""
 # ADD BASE CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I "." /I "..\common" /I ".\editlib" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_AFXDLL" /D "HAVE_STDLIB_H" /D "STDC_HEADERS" /D HAVE_STRING_H=1 /D PR_FILE_NAME=\"pr\" /D DIFF_PROGRAM=\"diff\" /D "REGEX_MALLOC" /D "__MSC__" /D "__NT__" /D USG=1 /D EDITPADC_CLASS= /D "COMPILE_MULTIMON_STUBS" /FR /Yu"stdafx.h" /FD /EHa /c
-# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I "." /I ".\Common" /I ".\editlib" /I ".\diffutils" /I ".\diffutils\lib" /I ".\diffutils\src" /I "..\Externals\expat\lib" /I "..\Externals\expat\xmlwf" /I "..\Externals\scew" /I "..\Externals\pcre\pcre-6.7" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_AFXDLL" /D "HAVE_STDLIB_H" /D "STDC_HEADERS" /D HAVE_STRING_H=1 /D PR_FILE_NAME=\"pr\" /D DIFF_PROGRAM=\"diff\" /D "REGEX_MALLOC" /D "__MSC__" /D "__NT__" /D USG=1 /D EDITPADC_CLASS= /D "COMPILE_MULTIMON_STUBS" /D "UNICODE" /D "_UNICODE" /D "XML_UNICODE_WCHAR_T" /FR /Yu"stdafx.h" /FD /EHa /c
+# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I "." /I ".\Common" /I ".\editlib" /I ".\diffutils" /I ".\diffutils\lib" /I ".\diffutils\src" /I "..\Externals\expat\lib" /I "..\Externals\expat\xmlwf" /I "..\Externals\scew" /I "..\Externals\pcre\pcre-6.7" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_AFXDLL" /D "HAVE_STDLIB_H" /D "STDC_HEADERS" /D HAVE_STRING_H=1 /D PR_FILE_NAME=\"pr\" /D DIFF_PROGRAM=\"diff\" /D "REGEX_MALLOC" /D "__MSC__" /D "__NT__" /D USG=1 /D EDITPADC_CLASS= /D "COMPILE_MULTIMON_STUBS" /D "UNICODE" /D "_UNICODE" /FR /Yu"stdafx.h" /FD /EHa /c
 # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o /win32 "NUL"
 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o /win32 "NUL"
 # ADD BASE RSC /l 0x409 /d "_DEBUG" /d "_AFXDLL"
@@ -82,7 +82,7 @@ BSC32=bscmake.exe
 # ADD BSC32 /nologo
 LINK32=link.exe
 # ADD BASE LINK32 version.lib shlwapi.lib /nologo /subsystem:windows /debug /machine:I386 /out:"..\Build\MergeUnicodeDebug/WinMerge.exe" /pdbtype:sept
-# ADD LINK32 version.lib shlwapi.lib imm32.lib HtmlHelp.lib libexpatw.lib pcre.lib /nologo /entry:"wWinMainCRTStartup" /subsystem:windows /debug /machine:I386 /out:"..\Build\MergeUnicodeDebug/WinMergeU.exe" /pdbtype:sept /libpath:"..\Build\expat" /libpath:"..\Build\pcre"
+# ADD LINK32 version.lib shlwapi.lib imm32.lib HtmlHelp.lib libexpat.lib pcre.lib /nologo /entry:"wWinMainCRTStartup" /subsystem:windows /debug /machine:I386 /out:"..\Build\MergeUnicodeDebug/WinMergeU.exe" /pdbtype:sept /libpath:"..\Build\expat" /libpath:"..\Build\pcre"
 
 !ELSEIF  "$(CFG)" == "Merge - Win32 Release"
 
@@ -128,7 +128,7 @@ LINK32=link.exe
 # PROP Ignore_Export_Lib 0
 # PROP Target_Dir ""
 # ADD BASE CPP /nologo /MD /W4 /GR /GX /Zi /O1 /I "." /I ".\Common" /I ".\editlib" /I ".\diffutils" /I ".\diffutils\lib" /I ".\diffutils\src" /D "WIN32" /D "_WINDOWS" /D "_AFXDLL" /D "HAVE_STDLIB_H" /D "STDC_HEADERS" /D HAVE_STRING_H=1 /D PR_FILE_NAME=\"pr\" /D DIFF_PROGRAM=\"diff\" /D "REGEX_MALLOC" /D "__MSC__" /D "__NT__" /D USG=1 /D EDITPADC_CLASS= /D "COMPILE_MULTIMON_STUBS" /D "UNICODE" /D "_UNICODE" /Yu"stdafx.h" /FD /EHa /c
-# ADD CPP /nologo /MD /W3 /GR /GX /Zi /O1 /I "." /I ".\Common" /I ".\editlib" /I ".\diffutils" /I ".\diffutils\lib" /I ".\diffutils\src" /I "..\Externals\expat\lib" /I "..\Externals\expat\xmlwf" /I "..\Externals\scew" /I "..\Externals\pcre\pcre-6.7" /D "WIN32" /D "_WINDOWS" /D "_AFXDLL" /D "HAVE_STDLIB_H" /D "STDC_HEADERS" /D HAVE_STRING_H=1 /D PR_FILE_NAME=\"pr\" /D DIFF_PROGRAM=\"diff\" /D "REGEX_MALLOC" /D "__MSC__" /D "__NT__" /D USG=1 /D EDITPADC_CLASS= /D "COMPILE_MULTIMON_STUBS" /D "UNICODE" /D "_UNICODE" /D "XML_UNICODE_WCHAR_T" /Yu"stdafx.h" /FD /EHa /c
+# ADD CPP /nologo /MD /W3 /GR /GX /Zi /O1 /I "." /I ".\Common" /I ".\editlib" /I ".\diffutils" /I ".\diffutils\lib" /I ".\diffutils\src" /I "..\Externals\expat\lib" /I "..\Externals\expat\xmlwf" /I "..\Externals\scew" /I "..\Externals\pcre\pcre-6.7" /D "WIN32" /D "_WINDOWS" /D "_AFXDLL" /D "HAVE_STDLIB_H" /D "STDC_HEADERS" /D HAVE_STRING_H=1 /D PR_FILE_NAME=\"pr\" /D DIFF_PROGRAM=\"diff\" /D "REGEX_MALLOC" /D "__MSC__" /D "__NT__" /D USG=1 /D EDITPADC_CLASS= /D "COMPILE_MULTIMON_STUBS" /D "UNICODE" /D "_UNICODE" /Yu"stdafx.h" /FD /EHa /c
 # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o /win32 "NUL"
 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o /win32 "NUL"
 # ADD BASE RSC /l 0x409 /d "NDEBUG" /d "_AFXDLL"
@@ -139,7 +139,7 @@ BSC32=bscmake.exe
 LINK32=link.exe
 # ADD BASE LINK32 version.lib shlwapi.lib /nologo /entry:"wWinMainCRTStartup" /subsystem:windows /debug /machine:I386 /nodefaultlib:"msvcrtd.lib" /out:"..\Build\MergeUnicodeRelease\WinMergeU.exe" /verbose:lib
 # SUBTRACT BASE LINK32 /pdb:none
-# ADD LINK32 version.lib shlwapi.lib imm32.lib HtmlHelp.lib libexpatw.lib pcre.lib /nologo /entry:"wWinMainCRTStartup" /subsystem:windows /debug /machine:I386 /nodefaultlib:"msvcrtd.lib" /out:"..\Build\MergeUnicodeRelease\WinMergeU.exe" /libpath:"..\Build\expat" /libpath:"..\Build\pcre" /verbose:lib
+# ADD LINK32 version.lib shlwapi.lib imm32.lib HtmlHelp.lib libexpat.lib pcre.lib /nologo /entry:"wWinMainCRTStartup" /subsystem:windows /debug /machine:I386 /nodefaultlib:"msvcrtd.lib" /out:"..\Build\MergeUnicodeRelease\WinMergeU.exe" /libpath:"..\Build\expat" /libpath:"..\Build\pcre" /verbose:lib
 # SUBTRACT LINK32 /pdb:none
 
 !ENDIF 
index 2d317ab..ab13b22 100755 (executable)
 
 #include "ProjectFile.h"
 
+// ATL conversion macro hack for UTF-8 conversion
+#define UTF82W(lpa) (\
+       ((_lpa = lpa) == NULL) ? NULL : (\
+               _convert = (lstrlenA(_lpa)+1),\
+               AtlA2WHelper((LPWSTR) alloca(_convert*2), _lpa, _convert, CP_UTF8)))
+
+#define W2UTF8(lpw) (\
+       ((_lpw = lpw) == NULL) ? NULL : (\
+               _convert = (lstrlenW(_lpw)+1)*6,\
+               AtlW2AHelper((LPSTR) alloca(_convert), _lpw, _convert, CP_UTF8)))
+
+#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 TCHAR Root_element_name[] = _T("project");
-const TCHAR Paths_element_name[] = _T("paths");
-const TCHAR Left_element_name[] = _T("left");
-const TCHAR Right_element_name[] = _T("right");
-const TCHAR Filter_element_name[] = _T("filter");
-const TCHAR Subfolders_element_name[] = _T("subfolders");
-const TCHAR Left_ro_element_name[] = _T("left-readonly");
-const TCHAR Right_ro_element_name[] = _T("right-readonly");
+const char Root_element_name[] = "project";
+const char Paths_element_name[] = "paths";
+const char Left_element_name[] = "left";
+const char Right_element_name[] = "right";
+const char Filter_element_name[] = "filter";
+const char Subfolders_element_name[] = "subfolders";
+const char Left_ro_element_name[] = "left-readonly";
+const char Right_ro_element_name[] = "right-readonly";
 
 /** 
  * @brief Standard constructor.
@@ -108,7 +129,7 @@ scew_element* ProjectFile::GetRootElement(scew_tree * tree)
        if (root != NULL)
        {
                // Make sure we have correct root element
-               if (_tcscmp(Root_element_name, scew_element_name(root)) != 0)
+               if (strcmp(Root_element_name, scew_element_name(root)) != 0)
                {
                        root = NULL;
                }
@@ -124,6 +145,7 @@ scew_element* ProjectFile::GetRootElement(scew_tree * tree)
  */
 BOOL ProjectFile::GetPathsData(scew_element * parent)
 {
+       USES_CONVERSION;
        BOOL bFoundPaths = FALSE;
        scew_element *paths = NULL;
 
@@ -151,43 +173,43 @@ BOOL ProjectFile::GetPathsData(scew_element * parent)
 
                if (left)
                {
-                       LPCTSTR path = NULL;
+                       LPCSTR path = NULL;
                        path = scew_element_contents(left);
-                       m_leftFile = path;
+                       m_leftFile = UTF82T(path);
                        m_bHasLeft = TRUE;
                }
                if (right)
                {
-                       LPCTSTR path = NULL;
+                       LPCSTR path = NULL;
                        path = scew_element_contents(right);
-                       m_rightFile = path;
+                       m_rightFile = UTF82T(path);
                        m_bHasRight = TRUE;
                }
                if (filter)
                {
-                       LPCTSTR filtername = NULL;
+                       LPCSTR filtername = NULL;
                        filtername = scew_element_contents(filter);
-                       m_filter = filtername;
+                       m_filter = UTF82T(filtername);
                        m_bHasFilter = TRUE;
                }
                if (subfolders)
                {
-                       LPCTSTR folders = NULL;
+                       LPCSTR folders = NULL;
                        folders = scew_element_contents(subfolders);
-                       m_subfolders = _ttoi(folders);
+                       m_subfolders = atoi(folders);
                        m_bHasSubfolders = TRUE;
                }
                if (left_ro)
                {
-                       LPCTSTR readonly = NULL;
+                       LPCSTR readonly = NULL;
                        readonly = scew_element_contents(left_ro);
-                       m_bLeftReadOnly = (_ttoi(readonly) != 0);
+                       m_bLeftReadOnly = (atoi(readonly) != 0);
                }
                if (right_ro)
                {
-                       LPCTSTR readonly = NULL;
+                       LPCSTR readonly = NULL;
                        readonly = scew_element_contents(right_ro);
-                       m_bRightReadOnly = (_ttoi(readonly) != 0);
+                       m_bRightReadOnly = (atoi(readonly) != 0);
                }
        }
        return bFoundPaths;
@@ -222,7 +244,7 @@ BOOL ProjectFile::Save(LPCTSTR path, CString *sError)
        else
                success = FALSE;
        
-       scew_tree_set_xml_encoding(tree, _T("UTF-8"));
+       scew_tree_set_xml_encoding(tree, "UTF-8");
 
        // Set the XML file standalone
        scew_tree_set_xml_standalone(tree, 1);
@@ -272,6 +294,7 @@ scew_element* ProjectFile::AddPathsElement(scew_element * parent)
  */
 BOOL ProjectFile::AddPathsContent(scew_element * parent)
 {
+       USES_CONVERSION;
        scew_element* element = NULL;
 
        if (!m_leftFile.IsEmpty())
@@ -279,7 +302,7 @@ BOOL ProjectFile::AddPathsContent(scew_element * parent)
                LPCTSTR path;
                element = scew_element_add(parent, Left_element_name);
                path = m_leftFile.GetBuffer(MAX_PATH);
-               scew_element_set_contents(element, path);
+               scew_element_set_contents(element, T2UTF8(path));
                m_leftFile.ReleaseBuffer();
        }
 
@@ -288,7 +311,7 @@ BOOL ProjectFile::AddPathsContent(scew_element * parent)
                LPCTSTR path;
                element = scew_element_add(parent, Right_element_name);
                path = m_rightFile.GetBuffer(MAX_PATH);
-               scew_element_set_contents(element, path);
+               scew_element_set_contents(element, T2UTF8(path));
                m_rightFile.ReleaseBuffer();
        }
 
@@ -297,27 +320,27 @@ BOOL ProjectFile::AddPathsContent(scew_element * parent)
                LPCTSTR filter;
                element = scew_element_add(parent, Filter_element_name);
                filter = m_filter.GetBuffer(MAX_PATH);
-               scew_element_set_contents(element, filter);
+               scew_element_set_contents(element, T2UTF8(filter));
                m_filter.ReleaseBuffer();
        }
 
        element = scew_element_add(parent, Subfolders_element_name);
        if (m_subfolders != 0)
-               scew_element_set_contents(element, _T("1"));
+               scew_element_set_contents(element, "1");
        else
-               scew_element_set_contents(element, _T("0"));
+               scew_element_set_contents(element, "0");
 
        element = scew_element_add(parent, Left_ro_element_name);
        if (m_bLeftReadOnly)
-               scew_element_set_contents(element, _T("1"));
+               scew_element_set_contents(element, "1");
        else
-               scew_element_set_contents(element, _T("0"));
+               scew_element_set_contents(element, "0");
 
        element = scew_element_add(parent, Right_ro_element_name);
        if (m_bRightReadOnly)
-               scew_element_set_contents(element, _T("1"));
+               scew_element_set_contents(element, "1");
        else
-               scew_element_set_contents(element, _T("0"));
+               scew_element_set_contents(element, "0");
 
        return TRUE;
 }