Blob


1 /* Output all lines of a diff_result. */
2 /*
3 * Copyright (c) 2020 Neels Hofmeyr <neels@hofmeyr.de>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
18 #include <diff/diff_output.h>
20 enum diff_rc
21 diff_output_plain(FILE *dest, const struct diff_input_info *info,
22 const struct diff_result *result)
23 {
24 if (!result)
25 return DIFF_RC_EINVAL;
26 if (result->rc != DIFF_RC_OK)
27 return result->rc;
29 int i;
30 for (i = 0; i < result->chunks.len; i++) {
31 struct diff_chunk *c = &result->chunks.head[i];
32 if (c->left_count && c->right_count)
33 diff_output_lines(dest, c->solved ? " " : "?", c->left_start, c->left_count);
34 else if (c->left_count && !c->right_count)
35 diff_output_lines(dest, c->solved ? "-" : "?", c->left_start, c->left_count);
36 else if (c->right_count && !c->left_count)
37 diff_output_lines(dest, c->solved ? "+" : "?", c->right_start, c->right_count);
38 }
39 return DIFF_RC_OK;
40 }