#include "CompareOptions.h"
#include "FileTextStats.h"
#include "DiffFileData.h"
+#include "FilterCommentsManager.h"
#ifdef _DEBUG
#define new DEBUG_NEW
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;
-};
-
-
-/**
-@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);
- }
- }
+// 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);
- //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.
* @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
* @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,
@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.
@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;
@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;
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////\r
+// License (GPLv2+):\r
+// This program is free software; you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation; either version 2 of the License, or (at\r
+// your option) any later version.\r
+// \r
+// This program is distributed in the hope that it will be useful, but\r
+// WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+/////////////////////////////////////////////////////////////////////////////\r
+/** \r
+ * @file FilterCommentsManager.cpp\r
+ *\r
+ * @brief FilterCommentsManager class implementation.\r
+ */\r
+\r
+#include "stdafx.h"\r
+#include <string>\r
+#include <map>\r
+\r
+#include "coretools.h"\r
+#include "FilterCommentsManager.h"\r
+\r
+/**\r
+@brief FilterCommentsManager constructor, which reads the INI file data\r
+ and populates the mapped member variable m_FilterCommentsSetByFileType.\r
+@param[in] Optional full INI file name, to include path.\r
+*/\r
+FilterCommentsManager::FilterCommentsManager(const TCHAR* IniFileName /*= _T("")*/)\r
+ : m_IniFileName(IniFileName)\r
+{\r
+ USES_CONVERSION;\r
+\r
+ int SectionNo = 0;\r
+ TCHAR SectionName[99];\r
+ TCHAR buffer[1024];\r
+ if (m_IniFileName.IsEmpty())\r
+ {\r
+ m_IniFileName = GetModulePath() + _T("\\IgnoreSectionMarkers.ini");\r
+ }\r
+ for(SectionNo = 0;;++SectionNo) \r
+ {//Get each set of markers\r
+ FilterCommentsSet filtercommentsset;\r
+ _sntprintf(SectionName, sizeof(SectionName)/sizeof(SectionName[0]), _T("set%i"), SectionNo);\r
+ GetPrivateProfileString(SectionName, _T("StartMarker"), _T(""), buffer,sizeof(buffer), m_IniFileName);\r
+ filtercommentsset.StartMarker = T2CA(buffer);\r
+ GetPrivateProfileString(SectionName, _T("EndMarker"), _T(""), buffer,sizeof(buffer), m_IniFileName);\r
+ filtercommentsset.EndMarker = T2CA(buffer);\r
+ GetPrivateProfileString(SectionName, _T("InlineMarker"), _T(""), buffer,sizeof(buffer), m_IniFileName);\r
+ filtercommentsset.InlineMarker = T2CA(buffer);\r
+ if (filtercommentsset.StartMarker.empty() && \r
+ filtercommentsset.EndMarker.empty() &&\r
+ filtercommentsset.InlineMarker.empty())\r
+ {\r
+ break;\r
+ }\r
+ int FileTypeNo = 0;\r
+ TCHAR FileTypeFieldName[99];\r
+ for(FileTypeNo = 0;;++FileTypeNo) \r
+ {//Get each file type associated with current set of markers\r
+ _sntprintf(FileTypeFieldName, sizeof(FileTypeFieldName)/sizeof(FileTypeFieldName[0]), _T("FileType%i"), FileTypeNo);\r
+ GetPrivateProfileString(SectionName, FileTypeFieldName, _T(""), buffer,sizeof(buffer), m_IniFileName);\r
+ CString FileTypeExtensionName = buffer;\r
+ if (FileTypeExtensionName.IsEmpty())\r
+ break;\r
+ m_FilterCommentsSetByFileType[FileTypeExtensionName] = filtercommentsset;\r
+ }\r
+ } \r
+\r
+ if (!SectionNo)\r
+ {//If no markers were found, then initialize default markers\r
+ CreateDefaultMarkers();\r
+ }\r
+}\r
+\r
+/**\r
+ @brief Get comment markers that are associated with this file type.\r
+ If there are no comment markers associated with this file type,\r
+ then return an empty set.\r
+ @param[in] The file name extension. Example:("cpp", "java", "c", "h")\r
+ Must be lower case.\r
+*/\r
+FilterCommentsSet FilterCommentsManager::GetSetForFileType(const CString& FileTypeName) const\r
+{\r
+ std::map <CString, FilterCommentsSet> :: const_iterator pSet =\r
+ m_FilterCommentsSetByFileType.find(FileTypeName);\r
+ if (pSet == m_FilterCommentsSetByFileType.end())\r
+ return FilterCommentsSet();\r
+ return pSet->second;\r
+}\r
+\r
+void FilterCommentsManager::CreateDefaultMarkers()\r
+{\r
+ USES_CONVERSION;\r
+ int SectionNo = 0;\r
+ TCHAR SectionName[99];\r
+ FilterCommentsSet filtercommentsset;\r
+ filtercommentsset.StartMarker = "/*";\r
+ filtercommentsset.EndMarker = "*/";\r
+ filtercommentsset.InlineMarker = "//";\r
+ 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")};\r
+ _sntprintf(SectionName, sizeof(SectionName)/sizeof(SectionName[0]), _T("set%i"), SectionNo);\r
+ ++SectionNo;\r
+ WritePrivateProfileString(SectionName, _T("StartMarker"), A2CT(filtercommentsset.StartMarker.c_str()), m_IniFileName);\r
+ WritePrivateProfileString(SectionName, _T("EndMarker"), A2CT(filtercommentsset.EndMarker.c_str()), m_IniFileName);\r
+ WritePrivateProfileString(SectionName, _T("InlineMarker"), A2CT(filtercommentsset.InlineMarker.c_str()), m_IniFileName);\r
+ int FileTypeNo = 0;\r
+ for(int i = 0;i < sizeof(CommonFileTypes1)/sizeof(CommonFileTypes1[0]);++i)\r
+ {\r
+ m_FilterCommentsSetByFileType[CommonFileTypes1[i]] = filtercommentsset;\r
+ TCHAR FileTypeFieldName[99];\r
+ _sntprintf(FileTypeFieldName, sizeof(FileTypeFieldName)/sizeof(FileTypeFieldName[0]), _T("FileType%i"), FileTypeNo);\r
+ ++FileTypeNo;\r
+ WritePrivateProfileString(SectionName, FileTypeFieldName, CommonFileTypes1[i], m_IniFileName);\r
+ }\r
+}\r
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////\r
+// License (GPLv2+):\r
+// This program is free software; you can redistribute it and/or modify\r
+// it under the terms of the GNU General Public License as published by\r
+// the Free Software Foundation; either version 2 of the License, or (at\r
+// your option) any later version.\r
+// \r
+// This program is distributed in the hope that it will be useful, but\r
+// WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU General Public License\r
+// along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+/////////////////////////////////////////////////////////////////////////////\r
+/** \r
+ * @file FilterCommentsManager.h\r
+ *\r
+ * @brief FilterCommentsManager class declaration.\r
+ */\r
+\r
+//#include <string>\r
+//#include <map>\r
+\r
+#ifndef _FILTERCOMMENTSMANAGER_H_\r
+#define _FILTERCOMMENTSMANAGER_H_\r
+\r
+//IngnoreComment logic developed by David Maisonave AKA (Axter)\r
+/**\r
+@struct FilterCommentsSet\r
+@brief FilterCommentsSet holds search strings used to find comments in compared files.\r
+ This data is used to find blocks that can be ignored when comparing to files.\r
+@note\r
+ The ignore-comment logic can only use ANSI strings, because the search buffer is\r
+ char* type.\r
+ Therefore, the data members should not be replaced with CString type, and should\r
+ remain std::string, or other non-unicode type string.\r
+*/\r
+struct FilterCommentsSet\r
+{\r
+ std::string StartMarker;\r
+ std::string EndMarker;\r
+ std::string InlineMarker;\r
+};\r
+\r
+/**\r
+@class FilterCommentsManager\r
+@brief FilterCommentsManager reads language comment start and end marker strings from\r
+ an INI file, and stores it in the map member variable m_FilterCommentsSetByFileType.\r
+ Each set of comment markers have a list of file types that can be used with\r
+ the file markers.\r
+@note\r
+The ignore-comment logic can only use ANSI strings, because the search buffer is\r
+char* type.\r
+FilterCommentsManager uses _T logic, only so-as to allow UNICODE file names to be \r
+used for the INI file, or INI file base directory.\r
+After retrieving data from INI file, the data is converted to ANSI.\r
+If no INI file exist, or the INI file is empty, then a default INI file is \r
+created with default values that are assoicated with most commen languages.\r
+*/\r
+class FilterCommentsManager\r
+{\r
+public:\r
+ FilterCommentsManager(const TCHAR* IniFileName = _T(""));\r
+ FilterCommentsSet GetSetForFileType(const CString& FileTypeName) const;\r
+\r
+private:\r
+ FilterCommentsManager(const FilterCommentsManager&); //Don't allow copy\r
+ FilterCommentsManager& operator=(const FilterCommentsManager&);//Don't allow assignment\r
+ void CreateDefaultMarkers();\r
+\r
+ //Use CString instead of std::string, so as to allow UNICODE file extensions\r
+ std::map<CString, FilterCommentsSet> m_FilterCommentsSetByFileType;\r
+ CString m_IniFileName;\r
+};\r
+\r
+#endif // _FILTERCOMMENTSMANAGER_H_\r