~ubuntu-branches/ubuntu/hardy/xxdiff/hardy

« back to all changes in this revision

Viewing changes to diff27-ming/diff.h

  • Committer: Bazaar Package Importer
  • Author(s): Tomas Pospisek
  • Date: 2005-03-29 08:43:56 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050329084356-nkwv8jf18nc7u5qf
Tags: 1:3.1-3
re-upload

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Shared definitions for GNU DIFF
2
 
   Copyright (C) 1988, 89, 91, 92, 93 Free Software Foundation, Inc.
3
 
 
4
 
This file is part of GNU DIFF.
5
 
 
6
 
GNU DIFF is free software; you can redistribute it and/or modify
7
 
it under the terms of the GNU General Public License as published by
8
 
the Free Software Foundation; either version 2, or (at your option)
9
 
any later version.
10
 
 
11
 
GNU DIFF is distributed in the hope that it will be useful,
12
 
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
GNU General Public License for more details.
15
 
 
16
 
You should have received a copy of the GNU General Public License
17
 
along with GNU DIFF; see the file COPYING.  If not, write to
18
 
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
 
 
20
 
#include "system.h"
21
 
#include <stdio.h>
22
 
#include "regex.h"
23
 
 
24
 
#define TAB_WIDTH 8
25
 
 
26
 
/* Variables for command line options */
27
 
 
28
 
#ifndef GDIFF_MAIN
29
 
#define EXTERN extern
30
 
#else
31
 
#define EXTERN
32
 
#endif
33
 
 
34
 
enum output_style {
35
 
  /* Default output style.  */
36
 
  OUTPUT_NORMAL,
37
 
  /* Output the differences with lines of context before and after (-c).  */
38
 
  OUTPUT_CONTEXT,
39
 
  /* Output the differences in a unified context diff format (-u). */
40
 
  OUTPUT_UNIFIED,
41
 
  /* Output the differences as commands suitable for `ed' (-e).  */
42
 
  OUTPUT_ED,
43
 
  /* Output the diff as a forward ed script (-f).  */
44
 
  OUTPUT_FORWARD_ED,
45
 
  /* Like -f, but output a count of changed lines in each "command" (-n). */
46
 
  OUTPUT_RCS,
47
 
  /* Output merged #ifdef'd file (-D).  */
48
 
  OUTPUT_IFDEF,
49
 
  /* Output sdiff style (-y).  */
50
 
  OUTPUT_SDIFF
51
 
};
52
 
 
53
 
/* True for output styles that are robust,
54
 
   i.e. can handle a file that ends in a non-newline.  */
55
 
#define ROBUST_OUTPUT_STYLE(S) ((S) != OUTPUT_ED && (S) != OUTPUT_FORWARD_ED)
56
 
 
57
 
EXTERN enum output_style output_style;
58
 
 
59
 
/* Nonzero if output cannot be generated for identical files.  */
60
 
EXTERN int no_diff_means_no_output;
61
 
 
62
 
/* Number of lines of context to show in each set of diffs.
63
 
   This is zero when context is not to be shown.  */
64
 
EXTERN int      context;
65
 
 
66
 
/* Consider all files as text files (-a).
67
 
   Don't interpret codes over 0177 as implying a "binary file".  */
68
 
EXTERN int      always_text_flag;
69
 
 
70
 
/* Number of lines to keep in identical prefix and suffix.  */
71
 
EXTERN int      horizon_lines;
72
 
 
73
 
/* Ignore changes in horizontal white space (-b).  */
74
 
EXTERN int      ignore_space_change_flag;
75
 
 
76
 
/* Ignore all horizontal white space (-w).  */
77
 
EXTERN int      ignore_all_space_flag;
78
 
 
79
 
/* Ignore changes that affect only blank lines (-B).  */
80
 
EXTERN int      ignore_blank_lines_flag;
81
 
 
82
 
/* 1 if lines may match even if their contents do not match exactly.
83
 
   This depends on various options.  */
84
 
EXTERN int      ignore_some_line_changes;
85
 
 
86
 
/* 1 if files may match even if their contents are not byte-for-byte identical.
87
 
   This depends on various options.  */
88
 
EXTERN int      ignore_some_changes;
89
 
 
90
 
/* Ignore differences in case of letters (-i).  */
91
 
EXTERN int      ignore_case_flag;
92
 
 
93
 
/* File labels for `-c' output headers (-L).  */
94
 
EXTERN char *file_label[2];
95
 
 
96
 
struct regexp_list
97
 
{
98
 
  struct re_pattern_buffer buf;
99
 
  struct regexp_list *next;
100
 
};
101
 
 
102
 
/* Regexp to identify function-header lines (-F).  */
103
 
EXTERN struct regexp_list *function_regexp_list;
104
 
 
105
 
/* Ignore changes that affect only lines matching this regexp (-I).  */
106
 
EXTERN struct regexp_list *ignore_regexp_list;
107
 
 
108
 
/* Say only whether files differ, not how (-q).  */
109
 
EXTERN int      no_details_flag;
110
 
 
111
 
/* Report files compared that match (-s).
112
 
   Normally nothing is output when that happens.  */
113
 
EXTERN int      print_file_same_flag;
114
 
 
115
 
/* Output the differences with exactly 8 columns added to each line
116
 
   so that any tabs in the text line up properly (-T).  */
117
 
EXTERN int      tab_align_flag;
118
 
 
119
 
/* Expand tabs in the output so the text lines up properly
120
 
   despite the characters added to the front of each line (-t).  */
121
 
EXTERN int      tab_expand_flag;
122
 
 
123
 
/* In directory comparison, specify file to start with (-S).
124
 
   All file names less than this name are ignored.  */
125
 
EXTERN char     *dir_start_file;
126
 
 
127
 
/* If a file is new (appears in only one dir)
128
 
   include its entire contents (-N).
129
 
   Then `patch' would create the file with appropriate contents.  */
130
 
EXTERN int      entire_new_file_flag;
131
 
 
132
 
/* If a file is new (appears in only the second dir)
133
 
   include its entire contents (-P).
134
 
   Then `patch' would create the file with appropriate contents.  */
135
 
EXTERN int      unidirectional_new_file_flag;
136
 
 
137
 
/* Pipe each file's output through pr (-l).  */
138
 
EXTERN int      paginate_flag;
139
 
 
140
 
enum line_class {
141
 
  /* Lines taken from just the first file.  */
142
 
  OLD,
143
 
  /* Lines taken from just the second file.  */
144
 
  NEW,
145
 
  /* Lines common to both files.  */
146
 
  UNCHANGED,
147
 
  /* A hunk containing both old and new lines (line groups only).  */
148
 
  CHANGED
149
 
};
150
 
 
151
 
/* Line group formats for old, new, unchanged, and changed groups.  */
152
 
EXTERN char *group_format[CHANGED + 1];
153
 
 
154
 
/* Line formats for old, new, and unchanged lines.  */
155
 
EXTERN char *line_format[UNCHANGED + 1];
156
 
 
157
 
/* If using OUTPUT_SDIFF print extra information to help the sdiff filter. */
158
 
EXTERN int sdiff_help_sdiff;
159
 
 
160
 
/* Tell OUTPUT_SDIFF to show only the left version of common lines. */
161
 
EXTERN int sdiff_left_only;
162
 
 
163
 
/* Tell OUTPUT_SDIFF to not show common lines. */
164
 
EXTERN int sdiff_skip_common_lines;
165
 
 
166
 
/* The half line width and column 2 offset for OUTPUT_SDIFF.  */
167
 
EXTERN unsigned sdiff_half_width;
168
 
EXTERN unsigned sdiff_column2_offset;
169
 
 
170
 
/* String containing all the command options diff received,
171
 
   with spaces between and at the beginning but none at the end.
172
 
   If there were no options given, this string is empty.  */
173
 
EXTERN char *   switch_string;
174
 
 
175
 
/* Nonzero means use heuristics for better speed.  */
176
 
EXTERN int      heuristic;
177
 
 
178
 
/* Name of program the user invoked (for error messages).  */
179
 
EXTERN char *program_name;
180
 
 
181
 
/* The result of comparison is an "edit script": a chain of `struct change'.
182
 
   Each `struct change' represents one place where some lines are deleted
183
 
   and some are inserted.
184
 
 
185
 
   LINE0 and LINE1 are the first affected lines in the two files (origin 0).
186
 
   DELETED is the number of lines deleted here from file 0.
187
 
   INSERTED is the number of lines inserted here in file 1.
188
 
 
189
 
   If DELETED is 0 then LINE0 is the number of the line before
190
 
   which the insertion was done; vice versa for INSERTED and LINE1.  */
191
 
 
192
 
struct change
193
 
{
194
 
  struct change *link;          /* Previous or next edit command  */
195
 
  int inserted;                 /* # lines of file 1 changed here.  */
196
 
  int deleted;                  /* # lines of file 0 changed here.  */
197
 
  int line0;                    /* Line number of 1st deleted line.  */
198
 
  int line1;                    /* Line number of 1st inserted line.  */
199
 
  char ignore;                  /* Flag used in context.c */
200
 
};
201
 
 
202
 
/* Structures that describe the input files.  */
203
 
 
204
 
/* Data on one input file being compared.  */
205
 
 
206
 
struct file_data {
207
 
    int             desc;       /* File descriptor  */
208
 
    char const      *name;      /* File name  */
209
 
    struct stat     stat;       /* File status from fstat()  */
210
 
    int             dir_p;      /* nonzero if file is a directory  */
211
 
 
212
 
    /* Buffer in which text of file is read.  */
213
 
    char *          buffer;
214
 
    /* Allocated size of buffer.  */
215
 
    size_t          bufsize;
216
 
    /* Number of valid characters now in the buffer. */
217
 
    size_t          buffered_chars;
218
 
 
219
 
    /* Array of pointers to lines in the file.  */
220
 
    char const **linbuf;
221
 
 
222
 
    /* linbuf_base <= buffered_lines <= valid_lines <= alloc_lines.
223
 
       linebuf[linbuf_base ... buffered_lines - 1] are possibly differing.
224
 
       linebuf[linbuf_base ... valid_lines - 1] contain valid data.
225
 
       linebuf[linbuf_base ... alloc_lines - 1] are allocated.  */
226
 
    int linbuf_base, buffered_lines, valid_lines, alloc_lines;
227
 
 
228
 
    /* Pointer to end of prefix of this file to ignore when hashing. */
229
 
    char const *prefix_end;
230
 
 
231
 
    /* Count of lines in the prefix.
232
 
       There are this many lines in the file before linbuf[0].  */
233
 
    int prefix_lines;
234
 
 
235
 
    /* Pointer to start of suffix of this file to ignore when hashing. */
236
 
    char const *suffix_begin;
237
 
 
238
 
    /* Vector, indexed by line number, containing an equivalence code for
239
 
       each line.  It is this vector that is actually compared with that
240
 
       of another file to generate differences. */
241
 
    int            *equivs;
242
 
 
243
 
    /* Vector, like the previous one except that
244
 
       the elements for discarded lines have been squeezed out.  */
245
 
    int            *undiscarded;
246
 
 
247
 
    /* Vector mapping virtual line numbers (not counting discarded lines)
248
 
       to real ones (counting those lines).  Both are origin-0.  */
249
 
    int            *realindexes;
250
 
 
251
 
    /* Total number of nondiscarded lines. */
252
 
    int             nondiscarded_lines;
253
 
 
254
 
    /* Vector, indexed by real origin-0 line number,
255
 
       containing 1 for a line that is an insertion or a deletion.
256
 
       The results of comparison are stored here.  */
257
 
    char           *changed_flag;
258
 
 
259
 
    /* 1 if file ends in a line with no final newline. */
260
 
    int             missing_newline;
261
 
 
262
 
    /* 1 more than the maximum equivalence value used for this or its
263
 
       sibling file. */
264
 
    int equiv_max;
265
 
};
266
 
 
267
 
/* Describe the two files currently being compared.  */
268
 
 
269
 
EXTERN struct file_data files[2];
270
 
 
271
 
/* Stdio stream to output diffs to.  */
272
 
 
273
 
EXTERN FILE *outfile;
274
 
 
275
 
/* Declare various functions.  */
276
 
 
277
 
/* analyze.c */
278
 
int diff_2_files PARAMS((struct file_data[], int));
279
 
 
280
 
/* context.c */
281
 
void print_context_header PARAMS((struct file_data[], int));
282
 
void print_context_script PARAMS((struct change *, int));
283
 
 
284
 
/* diff.c */
285
 
int excluded_filename PARAMS((char const *));
286
 
 
287
 
/* dir.c */
288
 
int diff_dirs PARAMS((struct file_data const[], int (*) PARAMS((char const *, char const *, char const *, char const *, int)), int));
289
 
 
290
 
/* ed.c */
291
 
void print_ed_script PARAMS((struct change *));
292
 
void pr_forward_ed_script PARAMS((struct change *));
293
 
 
294
 
/* ifdef.c */
295
 
void print_ifdef_script PARAMS((struct change *));
296
 
 
297
 
/* io.c */
298
 
int read_files PARAMS((struct file_data[], int));
299
 
int sip PARAMS((struct file_data *, int));
300
 
void slurp PARAMS((struct file_data *));
301
 
 
302
 
/* normal.c */
303
 
void print_normal_script PARAMS((struct change *));
304
 
 
305
 
/* rcs.c */
306
 
void print_rcs_script PARAMS((struct change *));
307
 
 
308
 
/* side.c */
309
 
void print_sdiff_script PARAMS((struct change *));
310
 
 
311
 
/* util.c */
312
 
VOID *xmalloc PARAMS((size_t));
313
 
VOID *xrealloc PARAMS((VOID *, size_t));
314
 
char *concat PARAMS((char const *, char const *, char const *));
315
 
char *dir_file_pathname PARAMS((char const *, char const *));
316
 
int change_letter PARAMS((int, int));
317
 
int line_cmp PARAMS((char const *, char const *));
318
 
int translate_line_number PARAMS((struct file_data const *, int));
319
 
struct change *find_change PARAMS((struct change *));
320
 
struct change *find_reverse_change PARAMS((struct change *));
321
 
void analyze_hunk PARAMS((struct change *, int *, int *, int *, int *, int *, int *));
322
 
void begin_output PARAMS((void));
323
 
void debug_script PARAMS((struct change *));
324
 
void error PARAMS((char const *, char const *, char const *));
325
 
void fatal PARAMS((char const *));
326
 
void finish_output PARAMS((void));
327
 
void message PARAMS((char const *, char const *, char const *));
328
 
void message5 PARAMS((char const *, char const *, char const *, char const *, char const *));
329
 
void output_1_line PARAMS((char const *, char const *, char const *, char const *));
330
 
void perror_with_name PARAMS((char const *));
331
 
void pfatal_with_name PARAMS((char const *));
332
 
void print_1_line PARAMS((char const *, char const * const *));
333
 
void print_message_queue PARAMS((void));
334
 
void print_number_range PARAMS((int, struct file_data *, int, int));
335
 
void print_script PARAMS((struct change *, struct change * (*) PARAMS((struct change *)), void (*) PARAMS((struct change *))));
336
 
void setup_output PARAMS((char const *, char const *, int));
337
 
void translate_range PARAMS((struct file_data const *, int, int, int *, int *));
338
 
 
339
 
/* version.c */
340
 
extern char const version_string[];