Revision: 3590
http://svn.sourceforge.net/winmerge/?rev=3590&view=rev
Author: kimmov
Date: 2006-09-20 07:38:13 -0700 (Wed, 20 Sep 2006)
Log Message:
-----------
PATCH: [ 1561650 ] Separate FilterCommentsManager code from DiffWrapper
Modified Paths:
--------------
trunk/Src/Changes.txt
trunk/Src/DiffWrapper.cpp
trunk/Src/DiffWrapper.h
trunk/Src/Merge.dsp
Added Paths:
-----------
trunk/Src/FilterCommentsManager.cpp
trunk/Src/FilterCommentsManager.h
Modified: trunk/Src/Changes.txt
===================================================================
--- trunk/Src/Changes.txt 2006-09-20 14:32:50 UTC (rev 3589)
+++ trunk/Src/Changes.txt 2006-09-20 14:38:13 UTC (rev 3590)
@@ -10,6 +10,9 @@
Src/Common: CSubclass.cpp sizecbar.cpp
BUG: [ 1561781 ] 64-bit compile errors from 7zCommon.cpp
Src: 7zCommon.cpp
+ PATCH: [ 1561650 ] Separate FilterCommentsManager code from DiffWrapper
+ Src: DiffWrapper.cpp DiffWrapper.h Merge.dsp
+ Src new files: FilterCommentsManager.cpp FilterCommentsManager.h
2006-09-19 Kimmo
PATCH: [ 1561001 ] Fix FileActionScript type in running actions
Modified: trunk/Src/DiffWrapper.cpp
===================================================================
--- trunk/Src/DiffWrapper.cpp 2006-09-20 14:32:50 UTC (rev 3589)
+++ trunk/Src/DiffWrapper.cpp 2006-09-20 14:38:13 UTC (rev 3590)
@@ -39,6 +39,7 @@
#include "CompareOptions.h"
#include "FileTextStats.h"
#include "DiffFileData.h"
+#include "FilterCommentsManager.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@@ -53,150 +54,23 @@
static void CopyTextStats(const file_data * inf, FileTextStats * myTextStats);
static void CopyDiffutilTextStats(file_data *inf, DiffFileData * diffData);
-//Should move FilterComments classes and global functions to it's own *.cpp & *.h file
-//IngnoreComment logic developed by David Maisonave AKA (Axter)
-/**
-@struct FilterCommentsSet
-@brief FilterCommentsSet holds search strings used to find comments in compared files.
- This data is used to find blocks that can be ignored when comparing to files.
-@note
- The ignore-comment logic can only use ANSI strings, because the search buffer is
- char* type.
- Therefore, the data members should not be replaced with CString type, and should
- remain std::string, or other non-unicode type string.
-*/
-struct FilterCommentsSet
-{
- std::string StartMarker;
- std::string EndMarker;
- std::string InlineMarker;
-};
+// Postfiltering
+static bool IsTrivialBytes(const char* Start, const char* End,
+ const FilterCommentsSet& filtercommentsset);
+static bool IsTrivialLine(const std::string &Line, const char * StartOfComment,
+ const char * EndOfComment, const char * InLineComment,
+ const FilterCommentsSet& filtercommentsset);
+static bool PostFilter(int StartPos, int EndPos, int Direction,
+ int QtyLinesInBlock, int &Op, int FileNo,
+ const FilterCommentsSet& filtercommentsset);
+static void PostFilterSingleLine(const char* LineStr, int &Op,
+ const FilterCommentsSet& filtercommentsset, bool PartOfMultiLineCheck);
+static void PostFilter(int LineNumberLeft, int QtyLinesLeft, int LineNumberRight,
+ int QtyLinesRight, int &Op, const FilterCommentsManager &filtercommentsmanager,
+ const TCHAR *FileNameExt);
/**
-@class FilterCommentsManager
-@brief FilterCommentsManager reads language comment start and end marker strings from
- an INI file, and stores it in the map member variable m_FilterCommentsSetByFileType.
- Each set of comment markers have a list of file types that can be used with
- the file markers.
-@note
-The ignore-comment logic can only use ANSI strings, because the search buffer is
-char* type.
-FilterCommentsManager uses _T logic, only so-as to allow UNICODE file names to be
-used for the INI file, or INI file base directory.
-After retrieving data from INI file, the data is converted to ANSI.
-If no INI file exist, or the INI file is empty, then a default INI file is
-created with default values that are assoicated with most commen languages.
-*/
-class FilterCommentsManager
-{
-public:
- /**
- @brief FilterCommentsManager constructor, which reads the INI file data
- and populates the mapped member variable m_FilterCommentsSetByFileType.
- @param[in] Optional full INI file name, to include path.
- */
- FilterCommentsManager(const TCHAR* IniFileName = _T("")) : m_IniFileName(IniFileName)
- {
- USES_CONVERSION;
-
- int SectionNo = 0;
- TCHAR SectionName[99];
- TCHAR buffer[1024];
- if (m_IniFileName.IsEmpty())
- {
- m_IniFileName = GetModulePath() + _T("\\IgnoreSectionMarkers.ini");
- }
- for(SectionNo = 0;;++SectionNo)
- {//Get each set of markers
- FilterCommentsSet filtercommentsset;
- _sntprintf(SectionName, sizeof(SectionName)/sizeof(SectionName[0]), _T("set%i"), SectionNo);
- GetPrivateProfileString(SectionName, _T("StartMarker"), _T(""), buffer,sizeof(buffer), m_IniFileName);
- filtercommentsset.StartMarker = T2CA(buffer);
- GetPrivateProfileString(SectionName, _T("EndMarker"), _T(""), buffer,sizeof(buffer), m_IniFileName);
- filtercommentsset.EndMarker = T2CA(buffer);
- GetPrivateProfileString(SectionName, _T("InlineMarker"), _T(""), buffer,sizeof(buffer), m_IniFileName);
- filtercommentsset.InlineMarker = T2CA(buffer);
- if (filtercommentsset.StartMarker.empty() &&
- filtercommentsset.EndMarker.empty() &&
- filtercommentsset.InlineMarker.empty())
- {
- break;
- }
- int FileTypeNo = 0;
- TCHAR FileTypeFieldName[99];
- for(FileTypeNo = 0;;++FileTypeNo)
- {//Get each file type associated with current set of markers
- _sntprintf(FileTypeFieldName, sizeof(FileTypeFieldName)/sizeof(FileTypeFieldName[0]), _T("FileType%i"), FileTypeNo);
- GetPrivateProfileString(SectionName, FileTypeFieldName, _T(""), buffer,sizeof(buffer), m_IniFileName);
- CString FileTypeExtensionName = buffer;
- if (FileTypeExtensionName.IsEmpty())
- break;
- m_FilterCommentsSetByFileType[FileTypeExtensionName] = filtercommentsset;
- }
- }
-
- if (!SectionNo)
- {//If no markers were found, then initialize default markers
- CreateDefaultMarkers();
- }
- }
-
- /**
- @brief Get comment markers that are associated with this file type.
- If there are no comment markers associated with this file type,
- then return an empty set.
- @param[in] The file name extension. Example:("cpp", "java", "c", "h")
- Must be lower case.
- */
- FilterCommentsSet GetSetForFileType(const CString& FileTypeName) const
- {
- std::map <CString, FilterCommentsSet> :: const_iterator pSet =
- m_FilterCommentsSetByFileType.find(FileTypeName);
- if (pSet == m_FilterCommentsSetByFileType.end())
- return FilterCommentsSet();
- return pSet->second;
- }
-private:
- FilterCommentsManager(const FilterCommentsManager&); //Don't allow copy
- FilterCommentsManager& operator=(const FilterCommentsManager&);//Don't allow assignment
- /**
- @brief Create default comment marker strings
- @note
- Currently, only have C/C++/Java type markers.
- */
- void CreateDefaultMarkers()
- {
- USES_CONVERSION;
- int SectionNo = 0;
- TCHAR SectionName[99];
- FilterCommentsSet filtercommentsset;
- filtercommentsset.StartMarker = "/*";
- filtercommentsset.EndMarker = "*/";
- filtercommentsset.InlineMarker = "//";
- TCHAR CommonFileTypes1[][9] = {_T("java"), _T("cs"), _T("cpp"), _T("c"), _T("h"), _T("cxx"), _T("cc"), _T("js"), _T("jsl"), _T("tli"), _T("tlh"), _T("rc")};
- _sntprintf(SectionName, sizeof(SectionName)/sizeof(SectionName[0]), _T("set%i"), SectionNo);
- ++SectionNo;
- WritePrivateProfileString(SectionName, _T("StartMarker"), A2CT(filtercommentsset.StartMarker.c_str()), m_IniFileName);
- WritePrivateProfileString(SectionName, _T("EndMarker"), A2CT(filtercommentsset.EndMarker.c_str()), m_IniFileName);
- WritePrivateProfileString(SectionName, _T("InlineMarker"), A2CT(filtercommentsset.InlineMarker.c_str()), m_IniFileName);
- int FileTypeNo = 0;
- for(int i = 0;i < sizeof(CommonFileTypes1)/sizeof(CommonFileTypes1[0]);++i)
- {
- m_FilterCommentsSetByFileType[CommonFileTypes1[i]] = filtercommentsset;
- TCHAR FileTypeFieldName[99];
- _sntprintf(FileTypeFieldName, sizeof(FileTypeFieldName)/sizeof(FileTypeFieldName[0]), _T("FileType%i"), FileTypeNo);
- ++FileTypeNo;
- WritePrivateProfileString(SectionName, FileTypeFieldName, CommonFileTypes1[i], m_IniFileName);
- }
- }
-
- //Use CString instead of std::string, so as to allow UNICODE file extensions
- std::map<CString, FilterCommentsSet> m_FilterCommentsSetByFileType;
- CString m_IniFileName;
-};
-
-/**
* @brief Default constructor.
* Initializes members and creates new FilterCommentsManager.
*/
@@ -353,7 +227,8 @@
* @param [in] filtercommentsset - For future use to determine trivial bytes
* @return Returns true if all characters are trivial
*/
-bool IsTrivialBytes(const char* Start, const char* End, const FilterCommentsSet& filtercommentsset)
+static bool IsTrivialBytes(const char* Start, const char* End,
+ const FilterCommentsSet& filtercommentsset)
{
std::string testdata(Start, End);
//@TODO: Need to replace the following trivial string with a user specified string
@@ -370,7 +245,7 @@
* @param [in] filtercommentsset - Comment marker set used to indicate comment blocks.
* @return Returns true if entire line is trivial
*/
-bool IsTrivialLine(const std::string &Line,
+static bool IsTrivialLine(const std::string &Line,
const char * StartOfComment,
const char * EndOfComment,
const char * InLineComment,
@@ -421,7 +296,9 @@
@return Always returns true in reverse direction.
In forward direction, returns false if none trivial data is found within QtyLinesInBlock
*/
-bool PostFilter(int StartPos, int EndPos, int Direction, int QtyLinesInBlock, int &Op, int FileNo, const FilterCommentsSet& filtercommentsset)
+static bool PostFilter(int StartPos, int EndPos, int Direction,
+ int QtyLinesInBlock, int &Op, int FileNo,
+ const FilterCommentsSet& filtercommentsset)
{
const char* EolIndicators = "\r\n"; //List of characters used as EOL
if (Op == OP_TRIVIAL) //If already set to trivial, then exit.
@@ -546,7 +423,8 @@
@param[in] filtercommentsset - Comment marker set used to indicate comment blocks.
@param[in] PartOfMultiLineCheck- Set to true, if this block is a multiple line block
*/
-void PostFilterSingleLine(const char* LineStr, int &Op, const FilterCommentsSet& filtercommentsset, bool PartOfMultiLineCheck)
+static void PostFilterSingleLine(const char* LineStr, int &Op,
+ const FilterCommentsSet& filtercommentsset, bool PartOfMultiLineCheck)
{
if (Op == OP_TRIVIAL)
return;
@@ -587,7 +465,9 @@
@param[in] filtercommentsset - Comment marker set used to indicate comment blocks.
@param[in] FileNameExt - The file name extension. Needs to be lower case string ("cpp", "java", "c")
*/
-void PostFilter(int LineNumberLeft, int QtyLinesLeft, int LineNumberRight, int QtyLinesRight, int &Op, const FilterCommentsManager &filtercommentsmanager, const TCHAR *FileNameExt)
+static void PostFilter(int LineNumberLeft, int QtyLinesLeft, int LineNumberRight,
+ int QtyLinesRight, int &Op, const FilterCommentsManager &filtercommentsmanager,
+ const TCHAR *FileNameExt)
{
if (Op == OP_TRIVIAL)
return;
Modified: trunk/Src/DiffWrapper.h
===================================================================
--- trunk/Src/DiffWrapper.h 2006-09-20 14:32:50 UTC (rev 3589)
+++ trunk/Src/DiffWrapper.h 2006-09-20 14:38:13 UTC (rev 3590)
@@ -39,6 +39,8 @@
class DiffList;
struct DiffFileData;
struct file_data;
+class FilterCommentsManager;
+struct FilterCommentsSet;
/** @enum COMPARE_TYPE
* @brief Different foldercompare methods.
Added: trunk/Src/FilterCommentsManager.cpp
===================================================================
--- trunk/Src/FilterCommentsManager.cpp (rev 0)
+++ trunk/Src/FilterCommentsManager.cpp 2006-09-20 14:38:13 UTC (rev 3590)
@@ -0,0 +1,122 @@
+/////////////////////////////////////////////////////////////////////////////
+// License (GPLv2+):
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or (at
+// your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+/////////////////////////////////////////////////////////////////////////////
+/**
+ * @file FilterCommentsManager.cpp
+ *
+ * @brief FilterCommentsManager class implementation.
+ */
+
+#include "stdafx.h"
+#include <string>
+#include <map>
+
+#include "coretools.h"
+#include "FilterCommentsManager.h"
+
+/**
+@brief FilterCommentsManager constructor, which reads the INI file data
+ and populates the mapped member variable m_FilterCommentsSetByFileType.
+@param[in] Optional full INI file name, to include path.
+*/
+FilterCommentsManager::FilterCommentsManager(const TCHAR* IniFileName /*= _T("")*/)
+ : m_IniFileName(IniFileName)
+{
+ USES_CONVERSION;
+
+ int SectionNo = 0;
+ TCHAR SectionName[99];
+ TCHAR buffer[1024];
+ if (m_IniFileName.IsEmpty())
+ {
+ m_IniFileName = GetModulePath() + _T("\\IgnoreSectionMarkers.ini");
+ }
+ for(SectionNo = 0;;++SectionNo)
+ {//Get each set of markers
+ FilterCommentsSet filtercommentsset;
+ _sntprintf(SectionName, sizeof(SectionName)/sizeof(SectionName[0]), _T("set%i"), SectionNo);
+ GetPrivateProfileString(SectionName, _T("StartMarker"), _T(""), buffer,sizeof(buffer), m_IniFileName);
+ filtercommentsset.StartMarker = T2CA(buffer);
+ GetPrivateProfileString(SectionName, _T("EndMarker"), _T(""), buffer,sizeof(buffer), m_IniFileName);
+ filtercommentsset.EndMarker = T2CA(buffer);
+ GetPrivateProfileString(SectionName, _T("InlineMarker"), _T(""), buffer,sizeof(buffer), m_IniFileName);
+ filtercommentsset.InlineMarker = T2CA(buffer);
+ if (filtercommentsset.StartMarker.empty() &&
+ filtercommentsset.EndMarker.empty() &&
+ filtercommentsset.InlineMarker.empty())
+ {
+ break;
+ }
+ int FileTypeNo = 0;
+ TCHAR FileTypeFieldName[99];
+ for(FileTypeNo = 0;;++FileTypeNo)
+ {//Get each file type associated with current set of markers
+ _sntprintf(FileTypeFieldName, sizeof(FileTypeFieldName)/sizeof(FileTypeFieldName[0]), _T("FileType%i"), FileTypeNo);
+ GetPrivateProfileString(SectionName, FileTypeFieldName, _T(""), buffer,sizeof(buffer), m_IniFileName);
+ CString FileTypeExtensionName = buffer;
+ if (FileTypeExtensionName.IsEmpty())
+ break;
+ m_FilterCommentsSetByFileType[FileTypeExtensionName] = filtercommentsset;
+ }
+ }
+
+ if (!SectionNo)
+ {//If no markers were found, then initialize default markers
+ CreateDefaultMarkers();
+ }
+}
+
+/**
+ @brief Get comment markers that are associated with this file type.
+ If there are no comment markers associated with this file type,
+ then return an empty set.
+ @param[in] The file name extension. Example:("cpp", "java", "c", "h")
+ Must be lower case.
+*/
+FilterCommentsSet FilterCommentsManager::GetSetForFileType(const CString& FileTypeName) const
+{
+ std::map <CString, FilterCommentsSet> :: const_iterator pSet =
+ m_FilterCommentsSetByFileType.find(FileTypeName);
+ if (pSet == m_FilterCommentsSetByFileType.end())
+ return FilterCommentsSet();
+ return pSet->second;
+}
+
+void FilterCommentsManager::CreateDefaultMarkers()
+{
+ USES_CONVERSION;
+ int SectionNo = 0;
+ TCHAR SectionName[99];
+ FilterCommentsSet filtercommentsset;
+ filtercommentsset.StartMarker = "/*";
+ filtercommentsset.EndMarker = "*/";
+ filtercommentsset.InlineMarker = "//";
+ TCHAR CommonFileTypes1[][9] = {_T("java"), _T("cs"), _T("cpp"), _T("c"), _T("h"), _T("cxx"), _T("cc"), _T("js"), _T("jsl"), _T("tli"), _T("tlh"), _T("rc")};
+ _sntprintf(SectionName, sizeof(SectionName)/sizeof(SectionName[0]), _T("set%i"), SectionNo);
+ ++SectionNo;
+ WritePrivateProfileString(SectionName, _T("StartMarker"), A2CT(filtercommentsset.StartMarker.c_str()), m_IniFileName);
+ WritePrivateProfileString(SectionName, _T("EndMarker"), A2CT(filtercommentsset.EndMarker.c_str()), m_IniFileName);
+ WritePrivateProfileString(SectionName, _T("InlineMarker"), A2CT(filtercommentsset.InlineMarker.c_str()), m_IniFileName);
+ int FileTypeNo = 0;
+ for(int i = 0;i < sizeof(CommonFileTypes1)/sizeof(CommonFileTypes1[0]);++i)
+ {
+ m_FilterCommentsSetByFileType[CommonFileTypes1[i]] = filtercommentsset;
+ TCHAR FileTypeFieldName[99];
+ _sntprintf(FileTypeFieldName, sizeof(FileTypeFieldName)/sizeof(FileTypeFieldName[0]), _T("FileType%i"), FileTypeNo);
+ ++FileTypeNo;
+ WritePrivateProfileString(SectionName, FileTypeFieldName, CommonFileTypes1[i], m_IniFileName);
+ }
+}
Added: trunk/Src/FilterCommentsManager.h
===================================================================
--- trunk/Src/FilterCommentsManager.h (rev 0)
+++ trunk/Src/FilterCommentsManager.h 2006-09-20 14:38:13 UTC (rev 3590)
@@ -0,0 +1,78 @@
+/////////////////////////////////////////////////////////////////////////////
+// License (GPLv2+):
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or (at
+// your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+/////////////////////////////////////////////////////////////////////////////
+/**
+ * @file FilterCommentsManager.h
+ *
+ * @brief FilterCommentsManager class declaration.
+ */
+
+//#include <string>
+//#include <map>
+
+#ifndef _FILTERCOMMENTSMANAGER_H_
+#define _FILTERCOMMENTSMANAGER_H_
+
+//IngnoreComment logic developed by David Maisonave AKA (Axter)
+/**
+@struct FilterCommentsSet
+@brief FilterCommentsSet holds search strings used to find comments in compared files.
+ This data is used to find blocks that can be ignored when comparing to files.
+@note
+ The ignore-comment logic can only use ANSI strings, because the search buffer is
+ char* type.
+ Therefore, the data members should not be replaced with CString type, and should
+ remain std::string, or other non-unicode type string.
+*/
+struct FilterCommentsSet
+{
+ std::string StartMarker;
+ std::string EndMarker;
+ std::string InlineMarker;
+};
+
+/**
+@class FilterCommentsManager
+@brief FilterCommentsManager reads language comment start and end marker strings from
+ an INI file, and stores it in the map member variable m_FilterCommentsSetByFileType.
+ Each set of comment markers have a list of file types that can be used with
+ the file markers.
+@note
+The ignore-comment logic can only use ANSI strings, because the search buffer is
+char* type.
+FilterCommentsManager uses _T logic, only so-as to allow UNICODE file names to be
+used for the INI file, or INI file base directory.
+After retrieving data from INI file, the data is converted to ANSI.
+If no INI file exist, or the INI file is empty, then a default INI file is
+created with default values that are assoicated with most commen languages.
+*/
+class FilterCommentsManager
+{
+public:
+ FilterCommentsManager(const TCHAR* IniFileName = _T(""));
+ FilterCommentsSet GetSetForFileType(const CString& FileTypeName) const;
+
+private:
+ FilterCommentsManager(const FilterCommentsManager&); //Don't allow copy
+ FilterCommentsManager& operator=(const FilterCommentsManager&);//Don't allow assignment
+ void CreateDefaultMarkers();
+
+ //Use CString instead of std::string, so as to allow UNICODE file extensions
+ std::map<CString, FilterCommentsSet> m_FilterCommentsSetByFileType;
+ CString m_IniFileName;
+};
+
+#endif // _FILTERCOMMENTSMANAGER_H_
Modified: trunk/Src/Merge.dsp
===================================================================
--- trunk/Src/Merge.dsp 2006-09-20 14:32:50 UTC (rev 3589)
+++ trunk/Src/Merge.dsp 2006-09-20 14:38:13 UTC (rev 3590)
@@ -437,6 +437,10 @@
# End Source File
# Begin Source File
+SOURCE=.\FilterCommentsManager.cpp
+# End Source File
+# Begin Source File
+
SOURCE=.\GhostTextBuffer.cpp
# End Source File
# Begin Source File
@@ -1161,6 +1165,10 @@
# End Source File
# Begin Source File
+SOURCE=.\FilterCommentsManager.h
+# End Source File
+# Begin Source File
+
SOURCE=.\GhostTextBuffer.h
# End Source File
# Begin Source File
@@ -2412,10 +2420,10 @@
# End Group
# End Target
# End Project
-# Section Merge : {00312E6C-0754-0055-90BD-550078075500}
-# 1:19:IDR_POPUP_ABOUT_DLG:104
-# End Section
# Section Merge : {6F747475-446E-6C62-436C-6B0000003100}
# 1:10:IDB_SPLASH:103
# 2:21:SplashScreenInsertKey:4.0
# End Section
+# Section Merge : {00312E6C-0754-0055-90BD-550078075500}
+# 1:19:IDR_POPUP_ABOUT_DLG:104
+# End Section
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|