Blame


1 fe621944 2020-11-10 stsp /* Diff output generators and invocation shims. */
2 fe621944 2020-11-10 stsp /*
3 fe621944 2020-11-10 stsp * Copyright (c) 2020 Neels Hofmeyr <neels@hofmeyr.de>
4 fe621944 2020-11-10 stsp *
5 fe621944 2020-11-10 stsp * Permission to use, copy, modify, and distribute this software for any
6 fe621944 2020-11-10 stsp * purpose with or without fee is hereby granted, provided that the above
7 fe621944 2020-11-10 stsp * copyright notice and this permission notice appear in all copies.
8 fe621944 2020-11-10 stsp *
9 fe621944 2020-11-10 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 fe621944 2020-11-10 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 fe621944 2020-11-10 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 fe621944 2020-11-10 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 fe621944 2020-11-10 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 fe621944 2020-11-10 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 fe621944 2020-11-10 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 fe621944 2020-11-10 stsp */
17 fe621944 2020-11-10 stsp
18 fe621944 2020-11-10 stsp struct diff_input_info {
19 fe621944 2020-11-10 stsp const char *left_path;
20 fe621944 2020-11-10 stsp const char *right_path;
21 c4cd9c5b 2020-11-21 stsp
22 c4cd9c5b 2020-11-21 stsp /* Set by caller of diff_output_* functions. */
23 c4cd9c5b 2020-11-21 stsp int flags;
24 c4cd9c5b 2020-11-21 stsp #define DIFF_INPUT_LEFT_NONEXISTENT 0x00000001
25 c4cd9c5b 2020-11-21 stsp #define DIFF_INPUT_RIGHT_NONEXISTENT 0x00000002
26 fe621944 2020-11-10 stsp };
27 fe621944 2020-11-10 stsp
28 fe621944 2020-11-10 stsp struct diff_output_info {
29 fe621944 2020-11-10 stsp /*
30 fe621944 2020-11-10 stsp * Byte offset to each line in the generated output file.
31 fe621944 2020-11-10 stsp * The total number of lines in the file is line_offsets.len - 1.
32 fe621944 2020-11-10 stsp * The last offset in this array corresponds to end-of-file.
33 fe621944 2020-11-10 stsp */
34 fe621944 2020-11-10 stsp ARRAYLIST(off_t) line_offsets;
35 b77ebd68 2022-08-04 mark /*
36 b77ebd68 2022-08-04 mark * Type (i.e., context, minus, plus) of each line generated by the diff.
37 b77ebd68 2022-08-04 mark * nb. 0x00 to 0x3b reserved for client-defined line types.
38 b77ebd68 2022-08-04 mark */
39 b77ebd68 2022-08-04 mark ARRAYLIST(uint8_t) line_types;
40 b77ebd68 2022-08-04 mark #define DIFF_LINE_HUNK 0x3c
41 b77ebd68 2022-08-04 mark #define DIFF_LINE_MINUS 0x3d
42 b77ebd68 2022-08-04 mark #define DIFF_LINE_PLUS 0x3e
43 b77ebd68 2022-08-04 mark #define DIFF_LINE_CONTEXT 0x3f
44 b77ebd68 2022-08-04 mark #define DIFF_LINE_NONE 0x40 /* binary or no EOF newline msg, etc. */
45 fe621944 2020-11-10 stsp };
46 fe621944 2020-11-10 stsp
47 fe621944 2020-11-10 stsp void diff_output_info_free(struct diff_output_info *output_info);
48 fe621944 2020-11-10 stsp
49 fe621944 2020-11-10 stsp struct diff_chunk_context {
50 fe621944 2020-11-10 stsp struct diff_range chunk;
51 fe621944 2020-11-10 stsp struct diff_range left, right;
52 fe621944 2020-11-10 stsp };
53 fe621944 2020-11-10 stsp
54 fe621944 2020-11-10 stsp int diff_output_plain(struct diff_output_info **output_info, FILE *dest,
55 fe621944 2020-11-10 stsp const struct diff_input_info *info,
56 e72b0983 2022-09-03 stsp const struct diff_result *result,
57 e72b0983 2022-09-03 stsp int hunk_headers_only);
58 fe621944 2020-11-10 stsp int diff_output_unidiff(struct diff_output_info **output_info,
59 fe621944 2020-11-10 stsp FILE *dest, const struct diff_input_info *info,
60 fe621944 2020-11-10 stsp const struct diff_result *result,
61 fe621944 2020-11-10 stsp unsigned int context_lines);
62 fe621944 2020-11-10 stsp int diff_output_edscript(struct diff_output_info **output_info,
63 fe621944 2020-11-10 stsp FILE *dest, const struct diff_input_info *info,
64 fe621944 2020-11-10 stsp const struct diff_result *result);
65 fe621944 2020-11-10 stsp int diff_chunk_get_left_start(const struct diff_chunk *c,
66 fe621944 2020-11-10 stsp const struct diff_result *r,
67 fe621944 2020-11-10 stsp int context_lines);
68 fe621944 2020-11-10 stsp int diff_chunk_get_left_end(const struct diff_chunk *c,
69 fe621944 2020-11-10 stsp const struct diff_result *r,
70 fe621944 2020-11-10 stsp int context_lines);
71 fe621944 2020-11-10 stsp int diff_chunk_get_right_start(const struct diff_chunk *c,
72 fe621944 2020-11-10 stsp const struct diff_result *r,
73 fe621944 2020-11-10 stsp int context_lines);
74 fe621944 2020-11-10 stsp int diff_chunk_get_right_end(const struct diff_chunk *c,
75 fe621944 2020-11-10 stsp const struct diff_result *r,
76 fe621944 2020-11-10 stsp int context_lines);
77 3db5a0af 2023-02-20 mark off_t diff_chunk_get_left_start_pos(const struct diff_chunk *c);
78 3db5a0af 2023-02-20 mark off_t diff_chunk_get_right_start_pos(const struct diff_chunk *c);
79 fe621944 2020-11-10 stsp struct diff_chunk *diff_chunk_get(const struct diff_result *r, int chunk_idx);
80 fe621944 2020-11-10 stsp int diff_chunk_get_left_count(struct diff_chunk *c);
81 fe621944 2020-11-10 stsp int diff_chunk_get_right_count(struct diff_chunk *c);
82 fe621944 2020-11-10 stsp void diff_chunk_context_get(struct diff_chunk_context *cc,
83 fe621944 2020-11-10 stsp const struct diff_result *r,
84 fe621944 2020-11-10 stsp int chunk_idx, int context_lines);
85 fe621944 2020-11-10 stsp void diff_chunk_context_load_change(struct diff_chunk_context *cc,
86 fe621944 2020-11-10 stsp int *nchunks_used,
87 fe621944 2020-11-10 stsp struct diff_result *result,
88 fe621944 2020-11-10 stsp int start_chunk_idx,
89 fe621944 2020-11-10 stsp int context_lines);
90 fe621944 2020-11-10 stsp
91 fe621944 2020-11-10 stsp struct diff_output_unidiff_state;
92 fe621944 2020-11-10 stsp struct diff_output_unidiff_state *diff_output_unidiff_state_alloc(void);
93 fe621944 2020-11-10 stsp void diff_output_unidiff_state_reset(struct diff_output_unidiff_state *state);
94 fe621944 2020-11-10 stsp void diff_output_unidiff_state_free(struct diff_output_unidiff_state *state);
95 fe621944 2020-11-10 stsp int diff_output_unidiff_chunk(struct diff_output_info **output_info, FILE *dest,
96 fe621944 2020-11-10 stsp struct diff_output_unidiff_state *state,
97 fe621944 2020-11-10 stsp const struct diff_input_info *info,
98 fe621944 2020-11-10 stsp const struct diff_result *result,
99 fe621944 2020-11-10 stsp const struct diff_chunk_context *cc);
100 fe621944 2020-11-10 stsp int diff_output_chunk_left_version(struct diff_output_info **output_info,
101 fe621944 2020-11-10 stsp FILE *dest,
102 fe621944 2020-11-10 stsp const struct diff_input_info *info,
103 fe621944 2020-11-10 stsp const struct diff_result *result,
104 fe621944 2020-11-10 stsp const struct diff_chunk_context *cc);
105 fe621944 2020-11-10 stsp int diff_output_chunk_right_version(struct diff_output_info **output_info,
106 fe621944 2020-11-10 stsp FILE *dest,
107 fe621944 2020-11-10 stsp const struct diff_input_info *info,
108 fe621944 2020-11-10 stsp const struct diff_result *result,
109 fe621944 2020-11-10 stsp const struct diff_chunk_context *cc);
110 c4cd9c5b 2020-11-21 stsp
111 c4cd9c5b 2020-11-21 stsp const char *diff_output_get_label_left(const struct diff_input_info *info);
112 c4cd9c5b 2020-11-21 stsp const char *diff_output_get_label_right(const struct diff_input_info *info);