joachim99@52
|
1 /* Shared definitions for GNU DIFF
|
joachim99@52
|
2
|
joachim99@68
|
3 Modified for KDiff3 by Joachim Eibl 2003, 2004, 2005.
|
joachim99@53
|
4 The original file was part of GNU DIFF.
|
joachim99@52
|
5
|
joachim99@52
|
6 Copyright (C) 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1998, 2001,
|
joachim99@52
|
7 2002 Free Software Foundation, Inc.
|
joachim99@52
|
8
|
joachim99@52
|
9 GNU DIFF is free software; you can redistribute it and/or modify
|
joachim99@52
|
10 it under the terms of the GNU General Public License as published by
|
joachim99@52
|
11 the Free Software Foundation; either version 2, or (at your option)
|
joachim99@52
|
12 any later version.
|
joachim99@52
|
13
|
joachim99@52
|
14 GNU DIFF is distributed in the hope that it will be useful,
|
joachim99@52
|
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
joachim99@52
|
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
joachim99@52
|
17 GNU General Public License for more details.
|
joachim99@52
|
18
|
joachim99@52
|
19 You should have received a copy of the GNU General Public License
|
joachim99@52
|
20 along with this program; see the file COPYING.
|
joachim99@52
|
21 If not, write to the Free Software Foundation,
|
joachim99@69
|
22 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. */
|
joachim99@52
|
23
|
joachim99@53
|
24 #ifndef GNUDIFF_DIFF_H
|
joachim99@53
|
25 #define GNUDIFF_DIFF_H
|
joachim99@53
|
26
|
joachim99@52
|
27 #include "gnudiff_system.h"
|
joachim99@52
|
28
|
joachim99@52
|
29 #include <stdio.h>
|
joachim99@68
|
30 #include <qstring.h>
|
joachim99@52
|
31
|
joachim99@52
|
32 #define TAB_WIDTH 8
|
joachim99@52
|
33
|
joachim99@53
|
34 class GnuDiff
|
joachim99@52
|
35 {
|
joachim99@53
|
36 public:
|
joachim99@52
|
37 /* What kind of changes a hunk contains. */
|
joachim99@52
|
38 enum changes
|
joachim99@52
|
39 {
|
joachim99@52
|
40 /* No changes: lines common to both files. */
|
joachim99@52
|
41 UNCHANGED,
|
joachim99@52
|
42
|
joachim99@52
|
43 /* Deletes only: lines taken from just the first file. */
|
joachim99@52
|
44 OLD,
|
joachim99@52
|
45
|
joachim99@52
|
46 /* Inserts only: lines taken from just the second file. */
|
joachim99@52
|
47 NEW,
|
joachim99@52
|
48
|
joachim99@52
|
49 /* Both deletes and inserts: a hunk containing both old and new lines. */
|
joachim99@52
|
50 CHANGED
|
joachim99@52
|
51 };
|
joachim99@52
|
52
|
joachim99@52
|
53 /* Variables for command line options */
|
joachim99@52
|
54
|
joachim99@52
|
55 /* Nonzero if output cannot be generated for identical files. */
|
joachim99@53
|
56 bool no_diff_means_no_output;
|
joachim99@52
|
57
|
joachim99@52
|
58 /* Number of lines of context to show in each set of diffs.
|
joachim99@52
|
59 This is zero when context is not to be shown. */
|
joachim99@53
|
60 lin context;
|
joachim99@52
|
61
|
joachim99@52
|
62 /* Consider all files as text files (-a).
|
joachim99@52
|
63 Don't interpret codes over 0177 as implying a "binary file". */
|
joachim99@53
|
64 bool text;
|
joachim99@52
|
65
|
joachim99@52
|
66 /* The significance of white space during comparisons. */
|
joachim99@53
|
67 enum
|
joachim99@52
|
68 {
|
joachim99@52
|
69 /* All white space is significant (the default). */
|
joachim99@52
|
70 IGNORE_NO_WHITE_SPACE,
|
joachim99@52
|
71
|
joachim99@52
|
72 /* Ignore changes due to tab expansion (-E). */
|
joachim99@52
|
73 IGNORE_TAB_EXPANSION,
|
joachim99@52
|
74
|
joachim99@52
|
75 /* Ignore changes in horizontal white space (-b). */
|
joachim99@52
|
76 IGNORE_SPACE_CHANGE,
|
joachim99@52
|
77
|
joachim99@52
|
78 /* Ignore all horizontal white space (-w). */
|
joachim99@52
|
79 IGNORE_ALL_SPACE
|
joachim99@52
|
80 } ignore_white_space;
|
joachim99@52
|
81
|
joachim99@52
|
82 /* Ignore changes that affect only blank lines (-B). */
|
joachim99@53
|
83 bool ignore_blank_lines;
|
joachim99@52
|
84
|
joachim99@52
|
85 /* Ignore changes that affect only numbers. (J. Eibl) */
|
joachim99@53
|
86 bool bIgnoreNumbers;
|
joachim99@53
|
87 bool bIgnoreWhiteSpace;
|
joachim99@52
|
88
|
joachim99@52
|
89 /* Files can be compared byte-by-byte, as if they were binary.
|
joachim99@52
|
90 This depends on various options. */
|
joachim99@53
|
91 bool files_can_be_treated_as_binary;
|
joachim99@52
|
92
|
joachim99@52
|
93 /* Ignore differences in case of letters (-i). */
|
joachim99@53
|
94 bool ignore_case;
|
joachim99@52
|
95
|
joachim99@52
|
96 /* Ignore differences in case of letters in file names. */
|
joachim99@53
|
97 bool ignore_file_name_case;
|
joachim99@52
|
98
|
joachim99@52
|
99 /* Regexp to identify function-header lines (-F). */
|
joachim99@53
|
100 //struct re_pattern_buffer function_regexp;
|
joachim99@52
|
101
|
joachim99@52
|
102 /* Ignore changes that affect only lines matching this regexp (-I). */
|
joachim99@53
|
103 //struct re_pattern_buffer ignore_regexp;
|
joachim99@52
|
104
|
joachim99@52
|
105 /* Say only whether files differ, not how (-q). */
|
joachim99@53
|
106 bool brief;
|
joachim99@52
|
107
|
joachim99@52
|
108 /* Expand tabs in the output so the text lines up properly
|
joachim99@52
|
109 despite the characters added to the front of each line (-t). */
|
joachim99@53
|
110 bool expand_tabs;
|
joachim99@52
|
111
|
joachim99@52
|
112 /* Use a tab in the output, rather than a space, before the text of an
|
joachim99@52
|
113 input line, so as to keep the proper alignment in the input line
|
joachim99@52
|
114 without changing the characters in it (-T). */
|
joachim99@53
|
115 bool initial_tab;
|
joachim99@52
|
116
|
joachim99@52
|
117 /* In directory comparison, specify file to start with (-S).
|
joachim99@52
|
118 This is used for resuming an aborted comparison.
|
joachim99@52
|
119 All file names less than this name are ignored. */
|
joachim99@68
|
120 const QChar *starting_file;
|
joachim99@52
|
121
|
joachim99@52
|
122 /* Pipe each file's output through pr (-l). */
|
joachim99@53
|
123 bool paginate;
|
joachim99@52
|
124
|
joachim99@52
|
125 /* Line group formats for unchanged, old, new, and changed groups. */
|
joachim99@68
|
126 const QChar *group_format[CHANGED + 1];
|
joachim99@52
|
127
|
joachim99@52
|
128 /* Line formats for unchanged, old, and new lines. */
|
joachim99@68
|
129 const QChar *line_format[NEW + 1];
|
joachim99@52
|
130
|
joachim99@52
|
131 /* If using OUTPUT_SDIFF print extra information to help the sdiff filter. */
|
joachim99@53
|
132 bool sdiff_merge_assist;
|
joachim99@52
|
133
|
joachim99@52
|
134 /* Tell OUTPUT_SDIFF to show only the left version of common lines. */
|
joachim99@53
|
135 bool left_column;
|
joachim99@52
|
136
|
joachim99@52
|
137 /* Tell OUTPUT_SDIFF to not show common lines. */
|
joachim99@53
|
138 bool suppress_common_lines;
|
joachim99@52
|
139
|
joachim99@52
|
140 /* The half line width and column 2 offset for OUTPUT_SDIFF. */
|
joachim99@53
|
141 unsigned int sdiff_half_width;
|
joachim99@53
|
142 unsigned int sdiff_column2_offset;
|
joachim99@52
|
143
|
joachim99@52
|
144 /* Use heuristics for better speed with large files with a small
|
joachim99@52
|
145 density of changes. */
|
joachim99@53
|
146 bool speed_large_files;
|
joachim99@52
|
147
|
joachim99@52
|
148 /* Patterns that match file names to be excluded. */
|
joachim99@53
|
149 struct exclude *excluded;
|
joachim99@52
|
150
|
joachim99@52
|
151 /* Don't discard lines. This makes things slower (sometimes much
|
joachim99@52
|
152 slower) but will find a guaranteed minimal set of changes. */
|
joachim99@53
|
153 bool minimal;
|
joachim99@52
|
154
|
joachim99@52
|
155
|
joachim99@52
|
156 /* The result of comparison is an "edit script": a chain of `struct change'.
|
joachim99@52
|
157 Each `struct change' represents one place where some lines are deleted
|
joachim99@52
|
158 and some are inserted.
|
joachim99@52
|
159
|
joachim99@52
|
160 LINE0 and LINE1 are the first affected lines in the two files (origin 0).
|
joachim99@52
|
161 DELETED is the number of lines deleted here from file 0.
|
joachim99@52
|
162 INSERTED is the number of lines inserted here in file 1.
|
joachim99@52
|
163
|
joachim99@52
|
164 If DELETED is 0 then LINE0 is the number of the line before
|
joachim99@52
|
165 which the insertion was done; vice versa for INSERTED and LINE1. */
|
joachim99@52
|
166
|
joachim99@52
|
167 struct change
|
joachim99@52
|
168 {
|
joachim99@52
|
169 struct change *link; /* Previous or next edit command */
|
joachim99@52
|
170 lin inserted; /* # lines of file 1 changed here. */
|
joachim99@52
|
171 lin deleted; /* # lines of file 0 changed here. */
|
joachim99@52
|
172 lin line0; /* Line number of 1st deleted line. */
|
joachim99@52
|
173 lin line1; /* Line number of 1st inserted line. */
|
joachim99@52
|
174 bool ignore; /* Flag used in context.c. */
|
joachim99@52
|
175 };
|
joachim99@52
|
176
|
joachim99@52
|
177 /* Structures that describe the input files. */
|
joachim99@52
|
178
|
joachim99@52
|
179 /* Data on one input file being compared. */
|
joachim99@52
|
180
|
joachim99@52
|
181 struct file_data {
|
joachim99@52
|
182 /* Buffer in which text of file is read. */
|
joachim99@69
|
183 const QChar* buffer;
|
joachim99@52
|
184
|
joachim99@68
|
185 /* Allocated size of buffer, in QChars. Always a multiple of
|
joachim99@52
|
186 sizeof *buffer. */
|
joachim99@52
|
187 size_t bufsize;
|
joachim99@52
|
188
|
joachim99@52
|
189 /* Number of valid bytes now in the buffer. */
|
joachim99@52
|
190 size_t buffered;
|
joachim99@52
|
191
|
joachim99@52
|
192 /* Array of pointers to lines in the file. */
|
joachim99@68
|
193 const QChar **linbuf;
|
joachim99@52
|
194
|
joachim99@52
|
195 /* linbuf_base <= buffered_lines <= valid_lines <= alloc_lines.
|
joachim99@52
|
196 linebuf[linbuf_base ... buffered_lines - 1] are possibly differing.
|
joachim99@52
|
197 linebuf[linbuf_base ... valid_lines - 1] contain valid data.
|
joachim99@52
|
198 linebuf[linbuf_base ... alloc_lines - 1] are allocated. */
|
joachim99@52
|
199 lin linbuf_base, buffered_lines, valid_lines, alloc_lines;
|
joachim99@52
|
200
|
joachim99@52
|
201 /* Pointer to end of prefix of this file to ignore when hashing. */
|
joachim99@68
|
202 const QChar *prefix_end;
|
joachim99@52
|
203
|
joachim99@52
|
204 /* Count of lines in the prefix.
|
joachim99@52
|
205 There are this many lines in the file before linbuf[0]. */
|
joachim99@52
|
206 lin prefix_lines;
|
joachim99@52
|
207
|
joachim99@52
|
208 /* Pointer to start of suffix of this file to ignore when hashing. */
|
joachim99@68
|
209 const QChar *suffix_begin;
|
joachim99@52
|
210
|
joachim99@52
|
211 /* Vector, indexed by line number, containing an equivalence code for
|
joachim99@52
|
212 each line. It is this vector that is actually compared with that
|
joachim99@52
|
213 of another file to generate differences. */
|
joachim99@52
|
214 lin *equivs;
|
joachim99@52
|
215
|
joachim99@52
|
216 /* Vector, like the previous one except that
|
joachim99@52
|
217 the elements for discarded lines have been squeezed out. */
|
joachim99@52
|
218 lin *undiscarded;
|
joachim99@52
|
219
|
joachim99@52
|
220 /* Vector mapping virtual line numbers (not counting discarded lines)
|
joachim99@52
|
221 to real ones (counting those lines). Both are origin-0. */
|
joachim99@52
|
222 lin *realindexes;
|
joachim99@52
|
223
|
joachim99@52
|
224 /* Total number of nondiscarded lines. */
|
joachim99@52
|
225 lin nondiscarded_lines;
|
joachim99@52
|
226
|
joachim99@52
|
227 /* Vector, indexed by real origin-0 line number,
|
joachim99@52
|
228 containing TRUE for a line that is an insertion or a deletion.
|
joachim99@52
|
229 The results of comparison are stored here. */
|
joachim99@52
|
230 bool *changed;
|
joachim99@52
|
231
|
joachim99@52
|
232 /* 1 if at end of file. */
|
joachim99@52
|
233 bool eof;
|
joachim99@52
|
234
|
joachim99@52
|
235 /* 1 more than the maximum equivalence value used for this or its
|
joachim99@52
|
236 sibling file. */
|
joachim99@52
|
237 lin equiv_max;
|
joachim99@52
|
238 };
|
joachim99@52
|
239
|
joachim99@52
|
240 /* Data on two input files being compared. */
|
joachim99@52
|
241
|
joachim99@52
|
242 struct comparison
|
joachim99@52
|
243 {
|
joachim99@52
|
244 struct file_data file[2];
|
joachim99@52
|
245 struct comparison const *parent; /* parent, if a recursive comparison */
|
joachim99@52
|
246 };
|
joachim99@52
|
247
|
joachim99@52
|
248 /* Describe the two files currently being compared. */
|
joachim99@52
|
249
|
joachim99@53
|
250 struct file_data files[2];
|
joachim99@52
|
251
|
joachim99@52
|
252 /* Stdio stream to output diffs to. */
|
joachim99@52
|
253
|
joachim99@53
|
254 FILE *outfile;
|
joachim99@52
|
255
|
joachim99@52
|
256 /* Declare various functions. */
|
joachim99@52
|
257
|
joachim99@52
|
258 /* analyze.c */
|
joachim99@52
|
259 struct change* diff_2_files (struct comparison *);
|
joachim99@52
|
260
|
joachim99@52
|
261 /* context.c */
|
joachim99@52
|
262 void print_context_header (struct file_data[], bool);
|
joachim99@52
|
263 void print_context_script (struct change *, bool);
|
joachim99@52
|
264
|
joachim99@52
|
265 /* dir.c */
|
joachim99@68
|
266 int diff_dirs (struct comparison const *, int (*) (struct comparison const *, const QChar *, const QChar *));
|
joachim99@52
|
267
|
joachim99@52
|
268 /* ed.c */
|
joachim99@52
|
269 void print_ed_script (struct change *);
|
joachim99@52
|
270 void pr_forward_ed_script (struct change *);
|
joachim99@52
|
271
|
joachim99@52
|
272 /* ifdef.c */
|
joachim99@52
|
273 void print_ifdef_script (struct change *);
|
joachim99@52
|
274
|
joachim99@52
|
275 /* io.c */
|
joachim99@52
|
276 void file_block_read (struct file_data *, size_t);
|
joachim99@52
|
277 bool read_files (struct file_data[], bool);
|
joachim99@52
|
278
|
joachim99@52
|
279 /* normal.c */
|
joachim99@52
|
280 void print_normal_script (struct change *);
|
joachim99@52
|
281
|
joachim99@52
|
282 /* rcs.c */
|
joachim99@52
|
283 void print_rcs_script (struct change *);
|
joachim99@52
|
284
|
joachim99@52
|
285 /* side.c */
|
joachim99@52
|
286 void print_sdiff_script (struct change *);
|
joachim99@52
|
287
|
joachim99@52
|
288 /* util.c */
|
joachim99@68
|
289 QChar *concat (const QChar *, const QChar *, const QChar *);
|
joachim99@69
|
290 bool lines_differ ( const QChar *, size_t, const QChar *, size_t );
|
joachim99@52
|
291 lin translate_line_number (struct file_data const *, lin);
|
joachim99@52
|
292 struct change *find_change (struct change *);
|
joachim99@52
|
293 struct change *find_reverse_change (struct change *);
|
joachim99@52
|
294 void *zalloc (size_t);
|
joachim99@52
|
295 enum changes analyze_hunk (struct change *, lin *, lin *, lin *, lin *);
|
joachim99@52
|
296 void begin_output (void);
|
joachim99@52
|
297 void debug_script (struct change *);
|
joachim99@52
|
298 void finish_output (void);
|
joachim99@68
|
299 void message (const QChar *, const QChar *, const QChar *);
|
joachim99@68
|
300 void message5 (const QChar *, const QChar *, const QChar *, const QChar *, const QChar *);
|
joachim99@68
|
301 void output_1_line (const QChar *, const QChar *, const QChar *, const QChar *);
|
joachim99@68
|
302 void perror_with_name (const QChar *);
|
joachim99@68
|
303 void setup_output (const QChar *, const QChar *, bool);
|
joachim99@52
|
304 void translate_range (struct file_data const *, lin, lin, long *, long *);
|
joachim99@52
|
305
|
joachim99@52
|
306 /* version.c */
|
joachim99@68
|
307 //extern const QChar version_string[];
|
joachim99@53
|
308
|
joachim99@53
|
309 private:
|
joachim99@53
|
310 // gnudiff_analyze.cpp
|
joachim99@53
|
311 lin diag (lin xoff, lin xlim, lin yoff, lin ylim, bool find_minimal, struct partition *part);
|
joachim99@53
|
312 void compareseq (lin xoff, lin xlim, lin yoff, lin ylim, bool find_minimal);
|
joachim99@53
|
313 void discard_confusing_lines (struct file_data filevec[]);
|
joachim99@53
|
314 void shift_boundaries (struct file_data filevec[]);
|
joachim99@53
|
315 struct change * add_change (lin line0, lin line1, lin deleted, lin inserted, struct change *old);
|
joachim99@53
|
316 struct change * build_reverse_script (struct file_data const filevec[]);
|
joachim99@53
|
317 struct change* build_script (struct file_data const filevec[]);
|
joachim99@69
|
318
|
joachim99@53
|
319 // gnudiff_io.cpp
|
joachim99@53
|
320 void find_and_hash_each_line (struct file_data *current);
|
joachim99@53
|
321 void find_identical_ends (struct file_data filevec[]);
|
joachim99@53
|
322
|
joachim99@53
|
323 // gnudiff_xmalloc.cpp
|
joachim99@53
|
324 void *xmalloc (size_t n);
|
joachim99@53
|
325 void *xrealloc(void *p, size_t n);
|
joachim99@53
|
326 void xalloc_die (void);
|
joachim99@69
|
327
|
joachim99@68
|
328 inline bool isWhite( QChar c )
|
joachim99@53
|
329 {
|
joachim99@53
|
330 return c==' ' || c=='\t' || c=='\r';
|
joachim99@53
|
331 }
|
joachim99@53
|
332 }; // class GnuDiff
|
joachim99@53
|
333
|
joachim99@53
|
334 # define XMALLOC(Type, N_items) ((Type *) xmalloc (sizeof (Type) * (N_items)))
|
joachim99@53
|
335 # define XREALLOC(Ptr, Type, N_items) \
|
joachim99@53
|
336 ((Type *) xrealloc ((void *) (Ptr), sizeof (Type) * (N_items)))
|
joachim99@53
|
337
|
joachim99@53
|
338 /* Declare and alloc memory for VAR of type TYPE. */
|
joachim99@53
|
339 # define NEW(Type, Var) Type *(Var) = XMALLOC (Type, 1)
|
joachim99@53
|
340
|
joachim99@53
|
341 /* Free VAR only if non NULL. */
|
joachim99@53
|
342 # define XFREE(Var) \
|
joachim99@53
|
343 do { \
|
joachim99@53
|
344 if (Var) \
|
joachim99@53
|
345 free (Var); \
|
joachim99@53
|
346 } while (0)
|
joachim99@53
|
347
|
joachim99@53
|
348 /* Return a pointer to a malloc'ed copy of the array SRC of NUM elements. */
|
joachim99@53
|
349 # define CCLONE(Src, Num) \
|
joachim99@53
|
350 (memcpy (xmalloc (sizeof (*Src) * (Num)), (Src), sizeof (*Src) * (Num)))
|
joachim99@53
|
351
|
joachim99@53
|
352 /* Return a malloc'ed copy of SRC. */
|
joachim99@53
|
353 # define CLONE(Src) CCLONE (Src, 1)
|
joachim99@53
|
354
|
joachim99@53
|
355 #endif
|