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