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 1dfba055 2020-10-07 stsp #include <arraylist.h>
25 1dfba055 2020-10-07 stsp #include <diff_main.h>
26 1dfba055 2020-10-07 stsp #include <diff_output.h>
27 3b0f3d61 2020-01-22 neels
28 85ab4559 2020-09-22 stsp #include "diff_internal.h"
29 e10a628a 2020-09-16 stsp
30 3e6cba3a 2020-08-13 stsp int
31 2c20a3ed 2020-09-22 stsp diff_output_plain(struct diff_output_info **output_info, FILE *dest,
32 2c20a3ed 2020-09-22 stsp const struct diff_input_info *info,
33 2c20a3ed 2020-09-22 stsp const struct diff_result *result)
34 3b0f3d61 2020-01-22 neels {
35 2c20a3ed 2020-09-22 stsp struct diff_output_info *outinfo = NULL;
36 8cba9b5e 2020-09-22 stsp int i, rc;
37 2c20a3ed 2020-09-22 stsp
38 3b0f3d61 2020-01-22 neels if (!result)
39 3e6cba3a 2020-08-13 stsp return EINVAL;
40 3b0f3d61 2020-01-22 neels if (result->rc != DIFF_RC_OK)
41 3b0f3d61 2020-01-22 neels return result->rc;
42 2c20a3ed 2020-09-22 stsp
43 2c20a3ed 2020-09-22 stsp if (output_info) {
44 2c20a3ed 2020-09-22 stsp *output_info = diff_output_info_alloc();
45 2c20a3ed 2020-09-22 stsp if (*output_info == NULL)
46 2c20a3ed 2020-09-22 stsp return errno;
47 2c20a3ed 2020-09-22 stsp outinfo = *output_info;
48 2c20a3ed 2020-09-22 stsp }
49 3b0f3d61 2020-01-22 neels
50 3b0f3d61 2020-01-22 neels for (i = 0; i < result->chunks.len; i++) {
51 3b0f3d61 2020-01-22 neels struct diff_chunk *c = &result->chunks.head[i];
52 3b0f3d61 2020-01-22 neels if (c->left_count && c->right_count)
53 8cba9b5e 2020-09-22 stsp rc = diff_output_lines(outinfo, dest,
54 2c20a3ed 2020-09-22 stsp c->solved ? " " : "?",
55 0d27172a 2020-05-06 neels c->left_start, c->left_count);
56 3b0f3d61 2020-01-22 neels else if (c->left_count && !c->right_count)
57 8cba9b5e 2020-09-22 stsp rc = diff_output_lines(outinfo, dest,
58 2c20a3ed 2020-09-22 stsp c->solved ? "-" : "?",
59 0d27172a 2020-05-06 neels c->left_start, c->left_count);
60 3b0f3d61 2020-01-22 neels else if (c->right_count && !c->left_count)
61 8cba9b5e 2020-09-22 stsp rc = diff_output_lines(outinfo, dest,
62 2c20a3ed 2020-09-22 stsp c->solved ? "+" : "?",
63 0d27172a 2020-05-06 neels c->right_start, c->right_count);
64 8cba9b5e 2020-09-22 stsp if (rc)
65 8cba9b5e 2020-09-22 stsp return rc;
66 3b0f3d61 2020-01-22 neels }
67 3b0f3d61 2020-01-22 neels return DIFF_RC_OK;
68 3b0f3d61 2020-01-22 neels }