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