1 /////////////////////////////////////////////////////////////////////////////
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful, but
9 // WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 /////////////////////////////////////////////////////////////////////////////
20 * @brief Declaration file for CDiffWrapper.
22 * @date Created: 2003-08-22
24 // ID line follows -- this is updated by SVN
25 // $Id: DiffWrapper.h 7091 2010-01-11 20:27:43Z kimmov $
27 #ifndef _DIFFWRAPPER_H
28 #define _DIFFWRAPPER_H
30 #include "FileLocation.h"
31 #include "PathContext.h"
32 #include "FileTextStats.h"
33 #include "CompareOptions.h"
42 class FilterCommentsManager;
43 struct FilterCommentsSet;
48 /** @enum COMPARE_TYPE
49 * @brief Different foldercompare methods.
50 * These values are the foldercompare methods WinMerge supports.
54 * @brief Normal by content compare.
55 * This compare type is first, default and all-seeing compare type.
56 * diffutils is used for producing compare results. So all limitations
57 * of diffutils (like buffering) apply to this compare method. But this
58 * is also currently only compare method that produces difference lists
59 * we can use in file compare.
62 /** @var CMP_QUICK_CONTENT
63 * @brief Faster byte per byte -compare.
64 * This type of compare was a response for needing faster compare results
65 * in folder compare. It independent from diffutils, and fully customised
66 * for WinMerge. It basically does byte-per-byte compare, still implementing
67 * different whitespace ignore options.
69 * Optionally this compare type can be stopped when first difference is found.
70 * Which gets compare as fast as possible. But misses sometimes binary files
71 * if zero bytes aren't found before first difference. Also difference counts
72 * are not useful with that option.
76 * @brief Compare by modified date.
77 * This compare type was added after requests and realization that in some
78 * situations difference in file's timestamps is enough to judge them
79 * different. E.g. when modifying files in local machine, file timestamps
80 * are certainly different after modifying them. This method doesn't even
81 * open files for reading them. It only reads file's infos for timestamps
84 * This is no doubt fastest way to compare files.
87 /** @var CMP_DATE_SIZE
88 * @brief Compare by date and then by size.
89 * This method is basically same than CMP_DATE, but it adds check for file
90 * sizes if timestamps are identical. This is because there are situations
91 * timestamps can't be trusted alone, especially with network shares. Adding
92 * checking for file sizes adds some more reliability for results with
93 * minimal increase in compare time.
97 * @brief Compare by file size.
98 * This compare method compares file sizes. This isn't quite accurate method,
99 * other than it can detect files that certainly differ. But it can show lot of
100 * different files as identical too. Advantage is in some use cases where different
101 * size always means files are different. E.g. automatically created logs - when
102 * more data is added size increases.
114 * @brief Additional options for creating patch files
118 enum output_style outputStyle; /**< Patch file style. */
119 int nContext; /**< Number of context lines. */
120 BOOL bAddCommandline; /**< Add diff-style commandline to patch file. */
126 IDENTLEVEL_EXCEPTLEFT,
127 IDENTLEVEL_EXCEPTMIDDLE,
128 IDENTLEVEL_EXCEPTRIGHT,
131 * @brief Diffutils returns this statusdata about files compared
135 BOOL bMissingNL[3]; /**< file is missing EOL before EOF */
136 BOOL bBinaries; /**< Files are binaries */
137 IDENTLEVEL Identical; /**< diffutils said files are identical */
138 BOOL bPatchFileFailed; /**< Creating patch file failed */
140 DIFFSTATUS() { memset(this, 0, sizeof(*this)); } // start out with all flags clear
143 class FilterCommentsManager;
146 * @brief Wrapper class for diffengine (diffutils and ByteComparator).
147 * Diffwappre class is used to run selected diffengine. For folder compare
148 * there are several methods (COMPARE_TYPE), but for file compare diffutils
149 * is used always. For file compare diffutils can output results to external
150 * DiffList or to patch file. Output type must be selected with member
151 * functions SetCreatePatchFile() and SetCreateDiffList().
158 void SetCreatePatchFile(const String &filename);
159 void SetCreateDiffList(DiffList *diffList);
160 void SetDiffList(DiffList *diffList);
161 void GetOptions(DIFFOPTIONS *options);
162 void SetOptions(const DIFFOPTIONS *options);
163 void SetTextForAutomaticPrediff(const String &text);
164 void SetPrediffer(PrediffingInfo * prediffer =NULL);
165 void GetPrediffer(PrediffingInfo * prediffer);
166 void SetPatchOptions(const PATCHOPTIONS *options);
167 void SetDetectMovedBlocks(bool bDetectMovedBlocks);
168 bool GetDetectMovedBlocks() { return (m_pMovedLines[0] != NULL); }
169 void SetAppendFiles(BOOL bAppendFiles);
170 void SetPaths(const PathContext &files, BOOL tempPaths);
171 void SetAlternativePaths(const PathContext &altPaths);
172 void SetCodepage(int codepage) { m_codepage = codepage; }
174 void GetDiffStatus(DIFFSTATUS *status);
175 void AddDiffRange(DiffList *pDiffList, UINT begin0, UINT end0, UINT begin1, UINT end1, OP_TYPE op);
176 void AddDiffRange(DiffList *pDiffList, DIFFRANGE &dr);
177 void FixLastDiffRange(int nFiles, int bufferLines[], int bMissingNL[], bool bIgnoreBlankLines);
178 MovedLines * GetMovedLines(int index) { return m_pMovedLines[index]; }
179 void SetCompareFiles(const PathContext &originalFile);
180 int Make3wayDiff(DiffList& diff3, DiffList& diff02, DiffList& diff10, DiffList& diff21);
181 void WritePatchFileHeader(enum output_style output_style, BOOL bAppendFiles);
182 void WritePatchFileTerminator(enum output_style output_style);
183 void SetFilterList(const String& filterStr);
184 void EnablePlugins(bool enable);
185 bool IsTrivialBytes(const char* Start, const char* End,
186 const FilterCommentsSet& filtercommentsset);
187 bool IsTrivialLine(const std::string &Line, const char * StartOfComment,
188 const char * EndOfComment, const char * InLineComment,
189 const FilterCommentsSet& filtercommentsset);
190 bool PostFilter(int StartPos, int EndPos, int Direction,
191 int QtyLinesInBlock, OP_TYPE &Op, int FileNo,
192 const FilterCommentsSet& filtercommentsset);
193 void PostFilter(int LineNumberLeft, int QtyLinesLeft, int LineNumberRight,
194 int QtyLinesRight, OP_TYPE &Op, const FilterCommentsManager &filtercommentsmanager,
195 const TCHAR *FileNameExt);
198 String FormatSwitchString();
199 BOOL Diff2Files(struct change ** diffs, DiffFileData *diffData,
200 int * bin_status, int * bin_file);
201 void LoadWinMergeDiffsFromDiffUtilsScript(struct change * script, const file_data * inf);
202 void WritePatchFile(struct change * script, file_data * inf);
204 void LoadWinMergeDiffsFromDiffUtilsScript3(
205 struct change * script10, struct change * script02, struct change * script12,
206 const file_data * inf10, const file_data * inf02, const file_data * inf12);
207 void FreeDiffUtilsScript3(struct change * & script10, struct change * & script12, struct change * & script02);
208 bool RegExpFilter(int StartPos, int EndPos, int FileNo);
211 DiffutilsOptions m_options;
212 DIFFSTATUS m_status; /**< Status of last compare */
213 FilterList * m_pFilterList; /**< List of linefilters. */
214 PathContext m_files; /**< Full path to diff'ed file. */
215 PathContext m_alternativePaths; /**< file's alternative path (may be relative). */
216 PathContext m_originalFile; /**< file's original (NON-TEMP) path. */
218 String m_sPatchFile; /**< Full path to created patch file. */
219 BOOL m_bPathsAreTemp; /**< Are compared paths temporary? */
220 /// prediffer info are stored only for MergeDoc
221 PrediffingInfo * m_infoPrediffer;
222 /// prediffer info are stored only for MergeDoc
223 String m_sToFindPrediffer;
224 BOOL m_bUseDiffList; /**< Are results returned in difflist? */
225 BOOL m_bCreatePatchFile; /**< Do we create a patch file? */
226 BOOL m_bAddCmdLine; /**< Do we add commandline to patch file? */
227 BOOL m_bAppendFiles; /**< Do we append to existing patch file? */
228 int m_nDiffs; /**< Difference count */
229 int m_codepage; /**< Codepage used in line filter */
230 DiffList *m_pDiffList; /**< Pointer to external DiffList */
231 MovedLines * m_pMovedLines[3];
232 FilterCommentsManager * m_FilterCommentsManager; /**< Comments filtering manager */
233 bool m_bPluginsEnabled; /**< Are plugins enabled? */
237 #endif // _DIFFWRAPPER_H