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 diff_output_plain(FILE *dest, const struct diff_input_info *info,
21 const struct diff_result *result)
22 {
23 if (!result)
24 return DIFF_RC_EINVAL;
25 if (result->rc != DIFF_RC_OK)
26 return result->rc;
28 int i;
29 for (i = 0; i < result->chunks.len; i++) {
30 struct diff_chunk *c = &result->chunks.head[i];
31 if (c->left_count && c->right_count)
32 diff_output_lines(dest, c->solved ? " " : "?", c->left_start, c->left_count);
33 else if (c->left_count && !c->right_count)
34 diff_output_lines(dest, c->solved ? "-" : "?", c->left_start, c->left_count);
35 else if (c->right_count && !c->left_count)
36 diff_output_lines(dest, c->solved ? "+" : "?", c->right_start, c->right_count);
37 }
38 return DIFF_RC_OK;
39 }