Path: blob/main/contrib/libdiff/include/diff_output.h
35065 views
/* Diff output generators and invocation shims. */1/*2* Copyright (c) 2020 Neels Hofmeyr <[email protected]>3*4* Permission to use, copy, modify, and distribute this software for any5* purpose with or without fee is hereby granted, provided that the above6* copyright notice and this permission notice appear in all copies.7*8* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES9* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF10* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR11* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES12* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN13* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF14* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.15*/1617struct diff_input_info {18const char *left_path;19const char *right_path;2021/* Set by caller of diff_output_* functions. */22int flags;23#define DIFF_INPUT_LEFT_NONEXISTENT 0x0000000124#define DIFF_INPUT_RIGHT_NONEXISTENT 0x0000000225};2627struct diff_output_info {28/*29* Byte offset to each line in the generated output file.30* The total number of lines in the file is line_offsets.len - 1.31* The last offset in this array corresponds to end-of-file.32*/33ARRAYLIST(off_t) line_offsets;34/*35* Type (i.e., context, minus, plus) of each line generated by the diff.36* nb. 0x00 to 0x3b reserved for client-defined line types.37*/38ARRAYLIST(uint8_t) line_types;39#define DIFF_LINE_HUNK 0x3c40#define DIFF_LINE_MINUS 0x3d41#define DIFF_LINE_PLUS 0x3e42#define DIFF_LINE_CONTEXT 0x3f43#define DIFF_LINE_NONE 0x40 /* binary or no EOF newline msg, etc. */44};4546void diff_output_info_free(struct diff_output_info *output_info);4748struct diff_chunk_context {49struct diff_range chunk;50struct diff_range left, right;51};5253int diff_output_plain(struct diff_output_info **output_info, FILE *dest,54const struct diff_input_info *info,55const struct diff_result *result,56int hunk_headers_only);57int diff_output_unidiff(struct diff_output_info **output_info,58FILE *dest, const struct diff_input_info *info,59const struct diff_result *result,60unsigned int context_lines);61int diff_output_edscript(struct diff_output_info **output_info,62FILE *dest, const struct diff_input_info *info,63const struct diff_result *result);64int diff_chunk_get_left_start(const struct diff_chunk *c,65const struct diff_result *r,66int context_lines);67int diff_chunk_get_left_end(const struct diff_chunk *c,68const struct diff_result *r,69int context_lines);70int diff_chunk_get_right_start(const struct diff_chunk *c,71const struct diff_result *r,72int context_lines);73int diff_chunk_get_right_end(const struct diff_chunk *c,74const struct diff_result *r,75int context_lines);76off_t diff_chunk_get_left_start_pos(const struct diff_chunk *c);77off_t diff_chunk_get_right_start_pos(const struct diff_chunk *c);78struct diff_chunk *diff_chunk_get(const struct diff_result *r, int chunk_idx);79int diff_chunk_get_left_count(struct diff_chunk *c);80int diff_chunk_get_right_count(struct diff_chunk *c);81void diff_chunk_context_get(struct diff_chunk_context *cc,82const struct diff_result *r,83int chunk_idx, int context_lines);84void diff_chunk_context_load_change(struct diff_chunk_context *cc,85int *nchunks_used,86struct diff_result *result,87int start_chunk_idx,88int context_lines);8990struct diff_output_unidiff_state;91struct diff_output_unidiff_state *diff_output_unidiff_state_alloc(void);92void diff_output_unidiff_state_reset(struct diff_output_unidiff_state *state);93void diff_output_unidiff_state_free(struct diff_output_unidiff_state *state);94int diff_output_unidiff_chunk(struct diff_output_info **output_info, FILE *dest,95struct diff_output_unidiff_state *state,96const struct diff_input_info *info,97const struct diff_result *result,98const struct diff_chunk_context *cc);99int diff_output_chunk_left_version(struct diff_output_info **output_info,100FILE *dest,101const struct diff_input_info *info,102const struct diff_result *result,103const struct diff_chunk_context *cc);104int diff_output_chunk_right_version(struct diff_output_info **output_info,105FILE *dest,106const struct diff_input_info *info,107const struct diff_result *result,108const struct diff_chunk_context *cc);109110const char *diff_output_get_label_left(const struct diff_input_info *info);111const char *diff_output_get_label_right(const struct diff_input_info *info);112113void diff_output_set_colors(bool _color,114const char *_del_code,115const char *_add_code);116117118