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 <errno.h>
19 #include <inttypes.h>
20 #include <stdio.h>
21 #include <stdbool.h>
22 #include <stdlib.h>
24 #include <diff/arraylist.h>
25 #include <diff/diff_main.h>
26 #include <diff/diff_output.h>
29 int
30 diff_output_plain(FILE *dest, const struct diff_input_info *info,
31 const struct diff_result *result)
32 {
33 if (!result)
34 return EINVAL;
35 if (result->rc != DIFF_RC_OK)
36 return result->rc;
38 int i;
39 for (i = 0; i < result->chunks.len; i++) {
40 struct diff_chunk *c = &result->chunks.head[i];
41 if (c->left_count && c->right_count)
42 diff_output_lines(dest, c->solved ? " " : "?",
43 c->left_start, c->left_count);
44 else if (c->left_count && !c->right_count)
45 diff_output_lines(dest, c->solved ? "-" : "?",
46 c->left_start, c->left_count);
47 else if (c->right_count && !c->left_count)
48 diff_output_lines(dest, c->solved ? "+" : "?",
49 c->right_start, c->right_count);
50 }
51 return DIFF_RC_OK;
52 }