1
/* Shared definitions for GNU DIFF
2
Copyright (C) 1988, 89, 91, 92, 93 Free Software Foundation, Inc.
4
This file is part of GNU DIFF.
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)
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.
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. */
26
/* Variables for command line options */
35
/* Default output style. */
37
/* Output the differences with lines of context before and after (-c). */
39
/* Output the differences in a unified context diff format (-u). */
41
/* Output the differences as commands suitable for `ed' (-e). */
43
/* Output the diff as a forward ed script (-f). */
45
/* Like -f, but output a count of changed lines in each "command" (-n). */
47
/* Output merged #ifdef'd file (-D). */
49
/* Output sdiff style (-y). */
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)
57
EXTERN enum output_style output_style;
59
/* Nonzero if output cannot be generated for identical files. */
60
EXTERN int no_diff_means_no_output;
62
/* Number of lines of context to show in each set of diffs.
63
This is zero when context is not to be shown. */
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;
70
/* Number of lines to keep in identical prefix and suffix. */
71
EXTERN int horizon_lines;
73
/* Ignore changes in horizontal white space (-b). */
74
EXTERN int ignore_space_change_flag;
76
/* Ignore all horizontal white space (-w). */
77
EXTERN int ignore_all_space_flag;
79
/* Ignore changes that affect only blank lines (-B). */
80
EXTERN int ignore_blank_lines_flag;
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;
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;
90
/* Ignore differences in case of letters (-i). */
91
EXTERN int ignore_case_flag;
93
/* File labels for `-c' output headers (-L). */
94
EXTERN char *file_label[2];
98
struct re_pattern_buffer buf;
99
struct regexp_list *next;
102
/* Regexp to identify function-header lines (-F). */
103
EXTERN struct regexp_list *function_regexp_list;
105
/* Ignore changes that affect only lines matching this regexp (-I). */
106
EXTERN struct regexp_list *ignore_regexp_list;
108
/* Say only whether files differ, not how (-q). */
109
EXTERN int no_details_flag;
111
/* Report files compared that match (-s).
112
Normally nothing is output when that happens. */
113
EXTERN int print_file_same_flag;
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;
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;
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;
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;
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;
137
/* Pipe each file's output through pr (-l). */
138
EXTERN int paginate_flag;
141
/* Lines taken from just the first file. */
143
/* Lines taken from just the second file. */
145
/* Lines common to both files. */
147
/* A hunk containing both old and new lines (line groups only). */
151
/* Line group formats for old, new, unchanged, and changed groups. */
152
EXTERN char *group_format[CHANGED + 1];
154
/* Line formats for old, new, and unchanged lines. */
155
EXTERN char *line_format[UNCHANGED + 1];
157
/* If using OUTPUT_SDIFF print extra information to help the sdiff filter. */
158
EXTERN int sdiff_help_sdiff;
160
/* Tell OUTPUT_SDIFF to show only the left version of common lines. */
161
EXTERN int sdiff_left_only;
163
/* Tell OUTPUT_SDIFF to not show common lines. */
164
EXTERN int sdiff_skip_common_lines;
166
/* The half line width and column 2 offset for OUTPUT_SDIFF. */
167
EXTERN unsigned sdiff_half_width;
168
EXTERN unsigned sdiff_column2_offset;
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;
175
/* Nonzero means use heuristics for better speed. */
176
EXTERN int heuristic;
178
/* Name of program the user invoked (for error messages). */
179
EXTERN char *program_name;
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.
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.
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. */
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 */
202
/* Structures that describe the input files. */
204
/* Data on one input file being compared. */
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 */
212
/* Buffer in which text of file is read. */
214
/* Allocated size of buffer. */
216
/* Number of valid characters now in the buffer. */
217
size_t buffered_chars;
219
/* Array of pointers to lines in the file. */
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;
228
/* Pointer to end of prefix of this file to ignore when hashing. */
229
char const *prefix_end;
231
/* Count of lines in the prefix.
232
There are this many lines in the file before linbuf[0]. */
235
/* Pointer to start of suffix of this file to ignore when hashing. */
236
char const *suffix_begin;
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. */
243
/* Vector, like the previous one except that
244
the elements for discarded lines have been squeezed out. */
247
/* Vector mapping virtual line numbers (not counting discarded lines)
248
to real ones (counting those lines). Both are origin-0. */
251
/* Total number of nondiscarded lines. */
252
int nondiscarded_lines;
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. */
259
/* 1 if file ends in a line with no final newline. */
262
/* 1 more than the maximum equivalence value used for this or its
267
/* Describe the two files currently being compared. */
269
EXTERN struct file_data files[2];
271
/* Stdio stream to output diffs to. */
273
EXTERN FILE *outfile;
275
/* Declare various functions. */
278
int diff_2_files PARAMS((struct file_data[], int));
281
void print_context_header PARAMS((struct file_data[], int));
282
void print_context_script PARAMS((struct change *, int));
285
int excluded_filename PARAMS((char const *));
288
int diff_dirs PARAMS((struct file_data const[], int (*) PARAMS((char const *, char const *, char const *, char const *, int)), int));
291
void print_ed_script PARAMS((struct change *));
292
void pr_forward_ed_script PARAMS((struct change *));
295
void print_ifdef_script PARAMS((struct change *));
298
int read_files PARAMS((struct file_data[], int));
299
int sip PARAMS((struct file_data *, int));
300
void slurp PARAMS((struct file_data *));
303
void print_normal_script PARAMS((struct change *));
306
void print_rcs_script PARAMS((struct change *));
309
void print_sdiff_script PARAMS((struct change *));
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 *));
340
extern char const version_string[];