OSDN Git Service

PATCH: [ 826584 ] User-specified codepage conversions
authorPerry Rapp <elsapo@users.sourceforge.net>
Sat, 25 Oct 2003 00:16:13 +0000 (00:16 +0000)
committerPerry Rapp <elsapo@users.sourceforge.net>
Sat, 25 Oct 2003 00:16:13 +0000 (00:16 +0000)
Src/DiffContext.h
Src/DirView.cpp
Src/MainFrm.cpp
Src/MainFrm.h
Src/MergeDoc.cpp
Src/MergeDoc.h
Src/readme.txt

index 8eb0f47..2c97dbc 100644 (file)
@@ -71,7 +71,8 @@ struct DiffFileInfo
        CString version; /**< string of fixed file version, eg, 1.2.3.4 */
        CString spath; /**< fully qualified directory of file */
        FileFlags flags; /**< file attributes */
-       DiffFileInfo() : mtime(0), ctime(0), size(0) { }
+       int codepage; /**< 8bit codepage, if applicable, 0 is unknown or N/A */
+       DiffFileInfo() : mtime(0), ctime(0), size(0), codepage(0) { }
        // We could stash a pointer here to the parent DIFFITEM
        // but, I ran into trouble with, I think, the DIFFITEM copy constructor
 };
index 50cc2bf..da80566 100644 (file)
@@ -629,7 +629,9 @@ void CDirView::OpenSelection(PackingInfo * infoUnpacker /*= NULL*/)
 
                        GetItemFileNames(sel, left, right);
                        mf->ShowMergeDoc(GetDocument(), left, right,
-                               bLeftRO, bRightRO, infoUnpacker);
+                               bLeftRO, bRightRO,
+                               di.left.codepage, di.right.codepage,
+                               infoUnpacker);
                }
        }
 }
index ce94f56..9611c42 100644 (file)
@@ -303,7 +303,9 @@ void CMainFrame::OnFileOpen()
 }
 
 /// Creates new MergeDoc instance and shows documents
-void CMainFrame::ShowMergeDoc(CDirDoc * pDirDoc, LPCTSTR szLeft, LPCTSTR szRight, BOOL bROLeft, BOOL bRORight, PackingInfo * infoUnpacker /*= NULL*/)
+void CMainFrame::ShowMergeDoc(CDirDoc * pDirDoc, LPCTSTR szLeft, LPCTSTR szRight,
+       BOOL bROLeft, BOOL bRORight,  int cpleft, int cpright,
+       PackingInfo * infoUnpacker /*= NULL*/)
 {
        BOOL docNull;
        BOOL bOpenSuccess = FALSE;
@@ -317,7 +319,7 @@ void CMainFrame::ShowMergeDoc(CDirDoc * pDirDoc, LPCTSTR szLeft, LPCTSTR szRight
        pMergeDoc->SetUnpacker(infoUnpacker);
 
        bOpenSuccess = pMergeDoc->OpenDocs(szLeft, szRight,
-                       bROLeft, bRORight);
+                       bROLeft, bRORight, cpleft, cpright);
 
        if (bOpenSuccess)
        {
@@ -1164,6 +1166,7 @@ BOOL CMainFrame::DoFileOpen(LPCTSTR pszLeft /*=NULL*/, LPCTSTR pszRight /*=NULL*
        CString strRight(pszRight);
        CString strExt;
        PackingInfo infoUnpacker;
+       int cpleft=0, cpright=0; // 8-bit codepages
 
        BOOL bRORight = dwLeftFlags & FFILEOPEN_READONLY;
        BOOL bROLeft = dwRightFlags & FFILEOPEN_READONLY;
@@ -1200,6 +1203,9 @@ BOOL CMainFrame::DoFileOpen(LPCTSTR pszLeft /*=NULL*/, LPCTSTR pszRight /*=NULL*
                strExt = dlg.m_strParsedExt;
                infoUnpacker = dlg.m_infoHandler;
                pathsType = static_cast<PATH_EXISTENCE>(dlg.m_pathsType);
+               // TODO: add codepage options to open dialog ?
+               cpleft = 0;
+               cpright = 0;
        }
        else
        {
@@ -1275,7 +1281,8 @@ BOOL CMainFrame::DoFileOpen(LPCTSTR pszLeft /*=NULL*/, LPCTSTR pszRight /*=NULL*
                if (files_isFileReadOnly(strRight))
                        bRORight = TRUE;
        
-               ShowMergeDoc(pDirDoc, strLeft, strRight, bROLeft, bRORight, &infoUnpacker);
+               ShowMergeDoc(pDirDoc, strLeft, strRight, bROLeft, bRORight,
+                       cpleft, cpright, &infoUnpacker);
        }
        return TRUE;
 }
@@ -1667,6 +1674,8 @@ void CMainFrame::OnViewSelectfont()
        memset(&cf, 0, sizeof(CHOOSEFONT));
        cf.lStructSize = sizeof(CHOOSEFONT);
        cf.Flags = CF_INITTOLOGFONTSTRUCT|CF_FORCEFONTEXIST|CF_SCREENFONTS|CF_FIXEDPITCHONLY;
+       // CF_FIXEDPITCHONLY = 0x00004000L
+       // in case you are a developer and want to disable it to test with, eg, a Chinese capable font
        cf.lpLogFont = &m_lfDiff;
        if (ChooseFont(&cf))
        {
index 3b2feb6..7d761ae 100644 (file)
@@ -94,7 +94,7 @@ public:
        BOOL DoSyncFiles(LPCTSTR pszSrc, LPCTSTR pszDest, CString * psError);
        BOOL DoFileOpen(LPCTSTR pszLeft = NULL, LPCTSTR pszRight = NULL,
                DWORD dwLeftFlags = 0, DWORD dwRightFlags = 0, BOOL bRecurse = FALSE);
-       void ShowMergeDoc(CDirDoc * pDirDoc, LPCTSTR szLeft, LPCTSTR szRight, BOOL bROLeft = FALSE, BOOL bRORight = FALSE, PackingInfo * infoUnpacker = NULL);
+       void ShowMergeDoc(CDirDoc * pDirDoc, LPCTSTR szLeft, LPCTSTR szRight, BOOL bROLeft, BOOL bRORight, int cpleft, int cpright, PackingInfo * infoUnpacker = NULL);
        void UpdateResources();
        HMENU NewDefaultMenu();
        BOOL CreateBackup(LPCTSTR pszPath);
index 94c071d..b7e603c 100644 (file)
@@ -1090,7 +1090,7 @@ GetLineByteTimeReport(UINT lines, UINT bytes, const COleDateTime & start)
  * @brief Load file from disk into buffer
  */
 int CMergeDoc::CDiffTextBuffer::LoadFromFile(LPCTSTR pszFileNameInit, PackingInfo * infoUnpacker, CString sToFindUnpacker, BOOL & readOnly,
-               int nCrlfStyle /*= CRLF_STYLE_AUTOMATIC*/)
+               int nCrlfStyle, int codepage)
 {
        // Unpacking the file here, save the result in a temporary file
        CString sFileName = pszFileNameInit;
@@ -1133,7 +1133,10 @@ int CMergeDoc::CDiffTextBuffer::LoadFromFile(LPCTSTR pszFileNameInit, PackingInf
 
        if (pufile->OpenReadOnly())
        {
-               pufile->ReadBom();
+               // Recognize Unicode files with BOM (byte order mark)
+               // or else, use the codepage we were given to interpret the 8-bit characters
+               if (!pufile->ReadBom())
+                       pufile->SetCodepage(codepage);
                UINT lineno = 0;
                CString line, eol, preveol;
                bool done = false;
@@ -2274,6 +2277,8 @@ RECT CMergeDoc::Computelinediff(CCrystalTextView * pView, CCrystalTextView * pOt
 *
 * @param sFileName File to open
 * @param bLeft Left/right-side file
+* @param readOnly whether file is read-only
+* @param codepage relevant 8-bit codepage if any (0 if none or unknown)
 *
 * @return Tells if files were loaded succesfully
 *
@@ -2282,7 +2287,7 @@ RECT CMergeDoc::Computelinediff(CCrystalTextView * pView, CCrystalTextView * pOt
 * @sa CMergeDoc::OpenDocs()
 *
 */
-int CMergeDoc::LoadFile(CString sFileName, BOOL bLeft, BOOL & readOnly)
+int CMergeDoc::LoadFile(CString sFileName, BOOL bLeft, BOOL & readOnly, int codepage)
 {
        CDiffTextBuffer *pBuf;
        CString sError;
@@ -2299,7 +2304,8 @@ int CMergeDoc::LoadFile(CString sFileName, BOOL bLeft, BOOL & readOnly)
                m_strRightFile = sFileName;
        }
 
-       retVal = pBuf->LoadFromFile(sFileName, m_pInfoUnpacker, m_strBothFilenames, readOnly);
+       int nCrlfStyle = CRLF_STYLE_AUTOMATIC;
+       retVal = pBuf->LoadFromFile(sFileName, m_pInfoUnpacker, m_strBothFilenames, readOnly, nCrlfStyle, codepage);
 
        if (retVal != FRESULT_OK)
        {
@@ -2328,6 +2334,8 @@ int CMergeDoc::LoadFile(CString sFileName, BOOL bLeft, BOOL & readOnly)
 * @param sRightFile File to open to right side
 * @param bROLeft Is left file read-only
 * @param bRORight Is right file read-only
+* @param cpleft Is left file's 8-bit codepage (eg, 1252) if applicable (0 is unknown or N/A)
+* @param cpright Is right file's 8-bit codepage (eg, 1252) if applicable (0 is unknown or N/A)
 *
 * @return Tells if files were loaded and scanned succesfully
 *
@@ -2337,7 +2345,7 @@ int CMergeDoc::LoadFile(CString sFileName, BOOL bLeft, BOOL & readOnly)
 *
 */
 BOOL CMergeDoc::OpenDocs(CString sLeftFile, CString sRightFile,
-               BOOL bROLeft, BOOL bRORight)
+               BOOL bROLeft, BOOL bRORight, int cpleft, int cpright)
 {
        DIFFOPTIONS diffOptions = {0};
        int nRescanResult = RESCAN_OK;
@@ -2352,12 +2360,16 @@ BOOL CMergeDoc::OpenDocs(CString sLeftFile, CString sRightFile,
        m_strBothFilenames = sLeftFile + "|" + sRightFile;
 
        // Load left side file
-       int nLeftSuccess = LoadFile(sLeftFile, TRUE, bROLeft);
+       BOOL bLeft = TRUE;
+       int nLeftSuccess = LoadFile(sLeftFile, bLeft, bROLeft, cpleft);
        
        // Load right side only if left side was succesfully loaded
        int nRightSuccess = FRESULT_ERROR;
        if (nLeftSuccess == FRESULT_OK)
-               nRightSuccess = LoadFile(sRightFile, FALSE, bRORight);
+       {
+               bLeft = FALSE;
+               nRightSuccess = LoadFile(sRightFile, bLeft, bRORight, cpright);
+       }
 
        // Bail out if either side failed
        if (nLeftSuccess != FRESULT_OK || nRightSuccess != FRESULT_OK)
index 2c41b64..8d66dd1 100644 (file)
@@ -119,7 +119,7 @@ public :
                void ReplaceLine(CCrystalTextView * pSource, int nLine, const CString& strText, int nAction =CE_ACTION_UNKNOWN);
                void ReplaceFullLine(CCrystalTextView * pSource, int nLine, const CString& strText, int nAction =CE_ACTION_UNKNOWN);
 
-               BOOL LoadFromFile(LPCTSTR pszFileName, PackingInfo * infoUnpacker, CString filteredFilenames, BOOL & readOnly, int nCrlfStyle = CRLF_STYLE_AUTOMATIC);
+               BOOL LoadFromFile(LPCTSTR pszFileName, PackingInfo * infoUnpacker, CString filteredFilenames, BOOL & readOnly, int nCrlfStyle, int codepage);
                BOOL SaveToFile (LPCTSTR pszFileName, BOOL bTempFile, PackingInfo * infoUnpacker = NULL,
                                int nCrlfStyle = CRLF_STYLE_AUTOMATIC, BOOL bClearModifiedFlag = TRUE );
 
@@ -201,8 +201,8 @@ public:
        void UpdateHeaderActivity(BOOL bLeft, BOOL bActivate);
        void ReadSettings();
        BOOL OpenDocs(CString sLeftFile, CString sRightFile,
-               BOOL bROLeft = FALSE, BOOL bRORight = FALSE);
-       int LoadFile(CString sFileName, BOOL bLeft, BOOL & readOnly);
+               BOOL bROLeft, BOOL bRORight, int cpleft, int cpright);
+       int LoadFile(CString sFileName, BOOL bLeft, BOOL & readOnly, int codepage);
        void RescanIfNeeded(float timeOutInSecond);
        int Rescan(BOOL bForced = FALSE);
        void ShowRescanError(int nRescanResult);
index 97bf75b..cc40abb 100644 (file)
@@ -4,6 +4,9 @@
  Add byte counts, and remove doubled line returns for load timing traces.
   WinMerge: MergeDoc.cpp
   common: UniMemFile.h
+ PATCH: [ 826584 ] User-specified codepage conversions
+  WinMerge: DiffContext.h DirView.cpp MainFrm.cpp MainFrm.h
+   MergeDoc.cpp MergeDoc.h
 
 2003-10-24 Kimmo
  PATCH: [ 828283 ] Open Read-only files as such