raw
vtools_genesis          1 #include "system.h"
vtools_genesis 2 #include <stdio.h>
vtools_genesis 3 #include <string.h>
vtools_genesis 4 #include <sys/stat.h>
vdiff_keccak 5 #include "keccak.h"
vtools_genesis 6
vtools_genesis 7 /* What kind of changes a hunk contains. */
vtools_genesis 8 enum changes {
vtools_genesis 9 /* No changes: lines common to both files. */
vtools_genesis 10 UNCHANGED,
vtools_genesis 11
vtools_genesis 12 /* Deletes only: lines taken from just the first file. */
vtools_genesis 13 OLD,
vtools_genesis 14
vtools_genesis 15 /* Inserts only: lines taken from just the second file. */
vtools_genesis 16 NEW,
vtools_genesis 17
vtools_genesis 18 /* Both deletes and inserts: a hunk containing both old and new lines. */
vtools_genesis 19 CHANGED
vtools_genesis 20 };
vtools_genesis 21
vtools_genesis 22 /* Variables for command line options */
vtools_genesis 23
vtools_genesis 24 #ifndef GDIFF_MAIN
vtools_genesis 25 # define XTERN extern
vtools_genesis 26 #else
vtools_genesis 27 # define XTERN
vtools_genesis 28 #endif
vtools_genesis 29
vtools_genesis 30 /* Number of lines of context to show in each set of diffs. This is
vtools_genesis 31 zero when context is not to be shown. */
vtools_genesis 32 XTERN lin context;
vtools_genesis 33
vtools_genesis 34 /* Consider all files as text files (-a). Don't interpret codes over
vtools_genesis 35 0177 as implying a "binary file". */
vtools_genesis 36 XTERN bool text;
vtools_genesis 37
vtools_genesis 38 /* Number of lines to keep in identical prefix and suffix. */
vtools_genesis 39 XTERN lin horizon_lines;
vtools_genesis 40
vtools_genesis 41 /* Files can be compared byte-by-byte, as if they were binary. This
vtools_genesis 42 depends on various options. */
vtools_genesis 43 XTERN bool files_can_be_treated_as_binary;
vtools_genesis 44
vtools_genesis 45 /* File labels for |-c| output headers (|--label|). */
vtools_genesis 46 XTERN char *file_label[2];
vtools_genesis 47
vtools_genesis 48 /* Say only whether files differ, not how (|-q|). */
vtools_genesis 49 XTERN bool brief;
vtools_genesis 50
vtools_genesis 51 /* Do not output an initial space or tab before the text of an empty line. */
vtools_genesis 52 XTERN bool suppress_blank_empty;
vtools_genesis 53
vtools_genesis 54 /* In directory comparison, specify file to start with (|-S|). This
vtools_genesis 55 is used for resuming an aborted comparison. All file names less
vtools_genesis 56 than this name are ignored. */
vtools_genesis 57 XTERN char const *starting_file;
vtools_genesis 58
vtools_genesis 59 /* String containing all the command options diff received, with
vtools_genesis 60 spaces between and at the beginning but none at the end. If there
vtools_genesis 61 were no options given, this string is empty. */
vtools_genesis 62 XTERN char *switch_string;
vtools_genesis 63
vtools_genesis 64 /* Use heuristics for better speed with large files with a small
vtools_genesis 65 density of changes. */
vtools_genesis 66 XTERN bool speed_large_files;
vtools_genesis 67
vtools_genesis 68 /* Don't discard lines. This makes things slower (sometimes much
vtools_genesis 69 slower) but will find a guaranteed minimal set of changes. */
vtools_genesis 70 XTERN bool minimal;
vtools_genesis 71
vtools_genesis 72 /* The result of comparison is an ``edit script'': a chain of |struct
vtools_genesis 73 change|. Each |struct change| represents one place where some
vtools_genesis 74 lines are deleted and some are inserted.
vtools_genesis 75
vtools_genesis 76 |line0| and |line1| are the first affected lines in the two files
vtools_genesis 77 (origin 0). |deleted| is the number of lines deleted here from file
vtools_genesis 78 0. |inserted| is the number of lines inserted here in file 1.
vtools_genesis 79
vtools_genesis 80 If |deleted| is 0 then |line0| is the number of the line before
vtools_genesis 81 which the insertion was done; vice versa for |inserted| and
vtools_genesis 82 |line1|. */
vtools_genesis 83
vtools_genesis 84 struct change {
vtools_genesis 85 struct change *link; /* Previous or next edit command */
vtools_genesis 86 lin inserted; /* \# lines of file 1 changed here. */
vtools_genesis 87 lin deleted; /* \# lines of file 0 changed here. */
vtools_genesis 88 lin line0; /* Line number of 1st deleted line. */
vtools_genesis 89 lin line1; /* Line number of 1st inserted line. */
vtools_genesis 90 bool ignore; /* Flag used in |context.c|. */
vtools_genesis 91 };
vtools_genesis 92
vtools_genesis 93 /* Structures that describe the input files. */
vtools_genesis 94
vtools_genesis 95 /* Data on one input file being compared. */
vtools_genesis 96
vtools_genesis 97 struct file_data {
vtools_genesis 98 int desc; /* File descriptor */
vtools_genesis 99 char const *name; /* File name */
vtools_genesis 100 struct stat stat; /* File status */
vtools_genesis 101
vtools_genesis 102 /* Buffer in which text of file is read. */
vtools_genesis 103 word *buffer;
vtools_genesis 104
vtools_genesis 105 /* Allocated size of buffer, in bytes. Always a multiple of
vtools_genesis 106 sizeof |*buffer|. */
vtools_genesis 107 size_t bufsize;
vtools_genesis 108
vtools_genesis 109 /* Number of valid bytes now in the buffer. */
vtools_genesis 110 size_t buffered;
vtools_genesis 111
vtools_genesis 112 /* Array of pointers to lines in the file. */
vtools_genesis 113 char const **linbuf;
vtools_genesis 114
vtools_genesis 115 /* |linbuf_base <= buffered_lines <= valid_lines <= alloc_lines|.
vtools_genesis 116 |linebuf[linbuf_base ... buffered_lines - 1]| are possibly differing.
vtools_genesis 117 |linebuf[linbuf_base ... valid_lines - 1]| contain valid data.
vtools_genesis 118 |linebuf[linbuf_base ... alloc_lines - 1]| are allocated. */
vtools_genesis 119 lin linbuf_base, buffered_lines, valid_lines, alloc_lines;
vtools_genesis 120
vtools_genesis 121 /* Pointer to end of prefix of this file to ignore when hashing. */
vtools_genesis 122 char const *prefix_end;
vtools_genesis 123
vtools_genesis 124 /* Count of lines in the prefix. There are this many lines in the
vtools_genesis 125 file before |linbuf[0]|. */
vtools_genesis 126 lin prefix_lines;
vtools_genesis 127
vtools_genesis 128 /* Pointer to start of suffix of this file to ignore when hashing. */
vtools_genesis 129 char const *suffix_begin;
vtools_genesis 130
vtools_genesis 131 /* Vector, indexed by line number, containing an equivalence code
vtools_genesis 132 for each line. It is this vector that is actually compared
vtools_genesis 133 with that of another file to generate differences. */
vtools_genesis 134 lin *equivs;
vtools_genesis 135
vtools_genesis 136 /* Vector, like the previous one except that the elements for
vtools_genesis 137 discarded lines have been squeezed out. */
vtools_genesis 138 lin *undiscarded;
vtools_genesis 139
vtools_genesis 140 /* Vector mapping virtual line numbers (not counting discarded
vtools_genesis 141 lines) to real ones (counting those lines). Both are
vtools_genesis 142 $origin-0$. */
vtools_genesis 143 lin *realindexes;
vtools_genesis 144
vtools_genesis 145 /* Total number of nondiscarded lines. */
vtools_genesis 146 lin nondiscarded_lines;
vtools_genesis 147
vtools_genesis 148 /* Vector, indexed by real $origin-0$ line number, containing 1
vtools_genesis 149 for a line that is an insertion or a deletion. The results of
vtools_genesis 150 comparison are stored here. */
vtools_genesis 151 char *changed;
vtools_genesis 152
vtools_genesis 153 /* 1 if file ends in a line with no final newline. */
vtools_genesis 154 bool missing_newline;
vtools_genesis 155
vtools_genesis 156 /* 1 if at end of file. */
vtools_genesis 157 bool eof;
vtools_genesis 158
vtools_genesis 159 /* 1 more than the maximum equivalence value used for this or its
vtools_genesis 160 sibling file. */
vtools_genesis 161 lin equiv_max;
vdiff_keccak 162
vdiff_keccak 163 /* keccak context */
vdiff_keccak 164 void *hash_context;
vdiff_keccak 165 uint64_t hash[8];
vtools_genesis 166 };
vtools_genesis 167
vtools_genesis 168 /* The file buffer, considered as an array of bytes rather than as an
vtools_genesis 169 array of words. */
vtools_genesis 170 #define FILE_BUFFER(f) ((char *) (f)->buffer)
vtools_genesis 171
vtools_genesis 172 /* Data on two input files being compared. */
vtools_genesis 173
vtools_genesis 174 struct comparison {
vtools_genesis 175 struct file_data file[2];
vtools_genesis 176 struct comparison const *parent; /* parent, if a recursive comparison */
vtools_genesis 177 };
vtools_genesis 178
vtools_genesis 179 /* Describe the two files currently being compared. */
vtools_genesis 180
vtools_genesis 181 XTERN struct file_data files[2];
vtools_genesis 182
vtools_genesis 183 /* Stdio stream to output diffs to. */
vtools_genesis 184
vtools_genesis 185 XTERN FILE *outfile;
vtools_genesis 186
vtools_genesis 187 /* Declare various functions. */
vtools_genesis 188
vtools_genesis 189 /* analyze.c */
vtools_genesis 190 extern int diff_2_files(struct comparison *);
vtools_genesis 191
vtools_genesis 192 /* context.c */
vtools_genesis 193 extern void print_context_header(struct file_data[], char const *const *);
vtools_genesis 194
vtools_genesis 195 extern void print_context_script(struct change *);
vtools_genesis 196
vtools_genesis 197 /* dir.c */
vtools_genesis 198 extern int diff_dirs(struct comparison const *,
vtools_genesis 199 int (*)(struct comparison const *,
vtools_genesis 200 char const *, char const *));
vtools_genesis 201
vtools_genesis 202 extern char *find_dir_file_pathname(char const *, char const *);
vtools_genesis 203
vtools_genesis 204 /* diff.h */
vtools_genesis 205 extern struct change *find_hunk(struct change *);
vtools_genesis 206
vtools_genesis 207 extern void pr_unidiff_hunk(struct change *);
vtools_genesis 208
vtools_genesis 209 /* io.c */
vtools_genesis 210 extern void file_block_read(struct file_data *, size_t);
vtools_genesis 211
vtools_genesis 212 extern bool read_files(struct file_data[], bool);
vtools_genesis 213
vtools_genesis 214 /* util.c */
vtools_genesis 215
vtools_genesis 216 extern bool lines_differ(char const *, char const *);
vtools_genesis 217
vtools_genesis 218 extern lin translate_line_number(struct file_data const *, lin);
vtools_genesis 219
vtools_genesis 220 extern struct change *find_change(struct change *);
vtools_genesis 221
vtools_genesis 222 extern void *zalloc(size_t);
vtools_genesis 223
vtools_genesis 224 extern enum changes analyze_hunk(struct change *, lin *, lin *, lin *, lin *);
vtools_genesis 225
vtools_genesis 226 extern void begin_output(void);
vtools_genesis 227
vtools_genesis 228 extern void debug_script(struct change *);
vtools_genesis 229
vtools_genesis 230 extern void fatal(char const *) __attribute__((noreturn));
vtools_genesis 231
vtools_genesis 232 extern void finish_output(void);
vtools_genesis 233
vtools_genesis 234 extern void message(char const *, char const *, char const *);
vtools_genesis 235
vtools_genesis 236 extern void message5(char const *, char const *, char const *,
vtools_genesis 237 char const *, char const *);
vtools_genesis 238
vtools_genesis 239 extern void output_1_line(char const *, char const *);
vtools_genesis 240
vtools_genesis 241 extern void perror_with_name(char const *);
vtools_genesis 242
vtools_genesis 243 extern void pfatal_with_name(char const *) __attribute__((noreturn));
vtools_genesis 244
vtools_genesis 245 extern void print_1_line(char const *, char const *const *);
vtools_genesis 246
vtools_genesis 247 extern void print_1_line_nl(char const *, char const *const *, bool);
vtools_genesis 248
vtools_genesis 249 extern void print_script(struct change *);
vtools_genesis 250
vtools_genesis 251 extern void setup_output(char const *, char const *, bool);
vtools_genesis 252
vtools_genesis 253 extern void translate_range(struct file_data const *, lin, lin,
vtools_genesis 254 printint *, printint *);