OSDN Git Service

Allow NUL and \\.\NUL in paths specified as command line arguments (#2056)
[winmerge-jp/winmerge-jp.git] / Src / CompareOptions.h
1 /** 
2  * @file  CompareOptions.h
3  *
4  * @brief Compare options classes and types.
5  */
6 #pragma once
7
8 #include "diff.h"
9
10 /**
11  * @brief Whether to ignore whitespace (or to ignore changes in whitespace)
12  *
13  * Examples:
14  * "abc def" is only equivalent to "abcdef" under WHITESPACE_IGNORE_ALL
15  *
16  * but "abc def" is equivalent to "abc    def" under both 
17  *   WHITESPACE_IGNORE_CHANGE and WHITESPACE_IGNORE_ALL
18  *
19  * Also, trailing and leading whitespace is ignored for both
20  *   WHITESPACE_IGNORE_CHANGE and WHITESPACE_IGNORE_ALL
21  */
22 enum WhitespaceIgnoreChoices
23 {
24         WHITESPACE_COMPARE_ALL = 0,    /**< no special handling of whitespace */
25         WHITESPACE_IGNORE_CHANGE,      /**< ignore changes in whitespace */
26         WHITESPACE_IGNORE_ALL,         /**< ignore whitespace altogether */
27 };
28
29 enum DiffAlgorithm
30 {
31         DIFF_ALGORITHM_DEFAULT = 0,
32         DIFF_ALGORITHM_MINIMAL = 1,
33         DIFF_ALGORITHM_PATIENCE = 2,
34         DIFF_ALGORITHM_HISTOGRAM = 3,
35         DIFF_ALGORITHM_NONE = 4,
36 };
37
38 /**
39  * @brief Patch styles.
40  *
41  * Diffutils can output patch in these formats. Normal format has original
42  * and altered lines listed in separate blocks, prefixed with \< and \>
43  * characters. Context format has context lines around difference blocks,
44  * which are prefixed with - and + characters. Unified format combines
45  * difference blocks and prefixes lines with + and - characters.
46  * @note We really use only first three types (normal + context formats).
47  * Those three types are the ones mostly used and preferred.
48  */
49 enum DiffOutputType
50 {
51         // NOTE: these values are stored in the user's Registry - don't change their value !!
52         /**< Default output style.  */
53         DIFF_OUTPUT_NORMAL = OUTPUT_NORMAL,
54         /**< Output the differences with lines of context before and after (-c).  */
55         DIFF_OUTPUT_CONTEXT = OUTPUT_CONTEXT,
56         /**< Output the differences in a unified context diff format (-u). */
57         DIFF_OUTPUT_UNIFIED = OUTPUT_UNIFIED,
58 // These are not used, see the comment above enum.
59 #if 0
60         /**< Output the differences as commands suitable for `ed' (-e).  */
61         DIFF_OUTPUT_ED = OUTPUT_ED,
62         /**< Output the diff as a forward ed script (-f).  */
63         DIFF_OUTPUT_FORWARD_ED = OUTPUT_FORWARD_ED,
64         /**< Like -f, but output a count of changed lines in each "command" (-n). */
65         DIFF_OUTPUT_RCS = OUTPUT_RCS,
66         /**< Output merged #ifdef'd file (-D).  */
67         DIFF_OUTPUT_IFDEF = OUTPUT_IFDEF,
68         /**< Output sdiff style (-y).  */
69         DIFF_OUTPUT_SDIFF = OUTPUT_SDIFF,
70 #endif
71 //  ... end of unused
72         /** Output html style.  */
73         DIFF_OUTPUT_HTML = OUTPUT_HTML,
74 };
75
76 /**
77  * @brief Diffutils options.
78  */
79 struct DIFFOPTIONS
80 {
81         int nIgnoreWhitespace; /**< Ignore whitespace -option. */
82         int nDiffAlgorithm; /**< Diff algorithm -option. */
83         bool bIgnoreCase; /**< Ignore case -option. */
84         bool bIgnoreNumbers; /**< Ignore numbers -option. */
85         bool bIgnoreBlankLines; /**< Ignore blank lines -option. */
86         bool bIgnoreEol; /**< Ignore EOL differences -option. */
87         bool bFilterCommentsLines; /**< Ignore Multiline comments differences -option. */
88         bool bIndentHeuristic; /**< Ident heuristic -option */
89         bool bCompletelyBlankOutIgnoredChanges;
90 };
91
92 /**
93  * @brief General compare options.
94  * This class has general compare options we expect every compare engine and
95  * routine to implement.
96  */
97 class CompareOptions
98 {
99 public:
100         CompareOptions();
101         virtual void SetFromDiffOptions(const DIFFOPTIONS & options);
102
103         enum WhitespaceIgnoreChoices m_ignoreWhitespace; /**< Ignore whitespace characters */
104         bool m_bIgnoreBlankLines; /**< Ignore blank lines (both sides) */
105         bool m_bIgnoreCase; /**< Ignore case differences? */
106         bool m_bIgnoreNumbers; /**< Ignore number differences? */
107         bool m_bIgnoreEOLDifference; /**< Ignore EOL style differences? */
108 };
109
110 /**
111  * @brief Compare options used with diffutils.
112  * This class adds some diffutils-specific compare options to general compare
113  * options class. And also methods for easy setting options and forwarding
114  * options to diffutils.
115  */
116 class DiffutilsOptions : public CompareOptions
117 {
118 public:
119         DiffutilsOptions();
120         explicit DiffutilsOptions(const CompareOptions& options);
121         void SetToDiffUtils();
122         void GetAsDiffOptions(DIFFOPTIONS &options) const;
123         virtual void SetFromDiffOptions(const DIFFOPTIONS & options) override;
124
125         DiffOutputType m_outputStyle; /**< Output style (for patch files) */
126         DiffAlgorithm m_diffAlgorithm; /** Diff algorithm */
127         int m_contextLines; /**< Number of context lines (for patch files) */
128         bool m_filterCommentsLines;/**< Ignore Multiline comments differences.*/
129         bool m_bIndentHeuristic; /**< Indent heuristic */
130         bool m_bCompletelyBlankOutIgnoredDiffereneces; /**< Completely blank out ignored differences */
131 };
132
133 /**
134  * @brief Compare options used with Quick compare -method.
135  * This class has some Quick Compare specifics in addition to general compare
136  * options.
137  */
138 class QuickCompareOptions : public CompareOptions
139 {
140 public:
141         QuickCompareOptions();
142         explicit QuickCompareOptions(const CompareOptions& options);
143
144         bool m_bStopAfterFirstDiff; /**< Optimize compare by stopping after first difference? */
145 };