Blame


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