Skip to content

Latest commit

 

History

History
executable file
·
194 lines (179 loc) · 5.79 KB

GNUDiff.h

File metadata and controls

executable file
·
194 lines (179 loc) · 5.79 KB
 
Jun 16, 2003
Jun 16, 2003
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* GNUDiff.h - Implementation of Diff using the GNU Diff command-line tools
*
*/
#ifndef _GNUDIFF_H_
#define _GNUDIFF_H_
#include "Diff.h"
namespace MojoMerge
{
// Size in bytes that will reserve for the 'diff' output result
#define DIFF_RESULT_BUFFER_SIZE 1048576
class GNUDiff : public Diff
{
public:
/* Diff Constructor
* Params
* DiffPath
* Full file and folder pathname of the GNU 'diff' program
* Diff3Path
* Full file and folder pathname of the GNU 'diff3' program
* TempFolder
* Location where temp files can go. This path must have
* a trailing '/' or '\' depending on platform.
* Returns
* none
*/
GNUDiff(const char *DiffPath, const char *Diff3Path, const char *TempFolder);
/* Diff Destructor
* Params
* none
* Returns
* none
*/
virtual ~GNUDiff();
/*** Overrides ***/
/* CompareFiles
* See Diff::CompareFiles for more information
*/
virtual Hunk *CompareFiles(DiffOptions Options, const char *Buffer1,
const char *Buffer2, const char *Buffer3 = NULL);
private:
// Path to GNU 'diff' program
char DiffPath[MOJO_MAX_PATH];
// Path to GNU 'diff3' program
char Diff3Path[MOJO_MAX_PATH];
// Temp folder
char TempFolder[MOJO_MAX_PATH];
// Result of 'diff' or 'diff3' output.
Aug 14, 2003
Aug 14, 2003
55
char *DiffResult;
Jun 16, 2003
Jun 16, 2003
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/* WriteTempFile
* Writes contents of Buffer to a new temporary file.
* Params
* Buffer
* Bytes to write to the temporary file
* File
* Full file name and path of the temp file are written to
* this variable.
* Returns
* none
*/
void WriteTempFile(const char *Buffer, char *File);
/* RemoveTempFile
* Removes the specified temp file
* Params
* File
* Full file name and path of file to remove
* Returns
* none
*/
void RemoveTempFile(const char *File);
/* GetDiffOutput
* Runs the program specified in 'Path' and writes the output to
* the DiffResult member
* Params
* Path
* Full file and path representing program to execute
* CommandLine
* Optional commandline parameters (can't be NULL). Specify
* an empty string ("") instead.
* Returns
* none
*/
void GetDiffOutput(const char *Path, const char *CommandLine);
/* RunDiff
* Runs the 'diff' application and calls ParseDiff on the result.
* Params
* Options
* Any combination of one or more DiffOption values
* File1
* Name of first file to diff
* File2
* Name of second file to diff
* Returns
* Pointer to the first diff hunk. Returns NULL if no differences
* were encountered, or an error occured. The caller is
* responsible for deallocating this object.
*/
Hunk *RunDiff(DiffOptions Options, const char *File1, const char *File2);
/* RunDiff3
* Runs the 'diff3' application and calls ParseDiff3 on the result.
* Params
* Options
* Any combination of one or more DiffOption values
* File1
* Name of first file to diff
* File2
* Name of second file to diff
* File3
* Name of third file to diff
* Returns
* Pointer to the first diff hunk. Returns NULL if no differences
* were encountered, or an error occured. The caller is
* responsible for deallocating this object.
*/
Hunk *RunDiff3(DiffOptions Options, const char *File1, const char *File2,
const char *File3);
/* ParseDiff3
* Parses "normal" output of the 'diff3' GNU tool. Reads data from
* NULL terminated DiffResult member.
* Params
* none
*
* Returns
* NULL if no differences encountered, otherwise returns the first
* hunk in the list of differences.
* Assumptions:
* 1. All Hunks start with "====n" at the beginning of the line. Where:
* "n" = 1,2,3 or blank.
* 2. File lines start with "f:Rc" or "f:La". Where:
* "f" = 1,2,3
* "R" = a range value in the form "#,#" or "#"
* "L" = a single "#"
*
*/
Hunk *ParseDiff3();
/* ParseDiff
* Parses a "normal" output of the 'diff' GNU tool. Reads data from
* NULL terminated DiffResult member.
* Params
* none
* Returns
* NULL if no differences encountered, otherwise returns the first
* hunk in the list of differences.
* Assumptions:
* 1. Hunks are definded as "RdL", "RcR", or "LaR" at the beginning of a line. Where:
* "R" = a range value in the form "#,#" or "#"
* "L" = a single "#"
* Ref:
* "d" indicates "delete"
* "c" indicates "change"
* "a" indicates "append"
*/
Hunk *ParseDiff();
/* ParseDiff2Hunk
* Parses a single line of "Hunk" code from "diff" output.
* Params
* Line
* The NULL terminated "Hunk" line to parse
* Startx
* Returned value, specifies the beginning of the hunk in file x
* Endx
* Returned value, specifies the end of the hunk in file x.
* If Endx is -1, then Startx is treated as an "insert after" line number.
* Returns
* -1 if any error, else 0
*
* Assumptions:
* 1. Hunks are definded as "RdL", "RcR", or "LaR" at the beginning of the line. Where:
* "R" = a range value in the form "#,#" or "#"
* "L" = a single "#"
* Ref:
* "d" indicates "delete"
* "c" indicates "change"
* "a" indicates "append"
*/
int ParseDiff2Hunk(const char *Line, uint32 *Start1, uint32 *End1,
uint32 *Start2, uint32 *End2);
};
}
Sep 7, 2003
Sep 7, 2003
194
#endif