1 fe621944 2020-11-10 stsp /* Output all lines of a diff_result. */
3 fe621944 2020-11-10 stsp * Copyright (c) 2020 Neels Hofmeyr <neels@hofmeyr.de>
5 fe621944 2020-11-10 stsp * Permission to use, copy, modify, and distribute this software for any
6 fe621944 2020-11-10 stsp * purpose with or without fee is hereby granted, provided that the above
7 fe621944 2020-11-10 stsp * copyright notice and this permission notice appear in all copies.
9 fe621944 2020-11-10 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 fe621944 2020-11-10 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 fe621944 2020-11-10 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 fe621944 2020-11-10 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 fe621944 2020-11-10 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 fe621944 2020-11-10 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 fe621944 2020-11-10 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 fe621944 2020-11-10 stsp #include <errno.h>
19 f3c44083 2020-11-14 naddy #include <stdint.h>
20 fe621944 2020-11-10 stsp #include <stdio.h>
21 fe621944 2020-11-10 stsp #include <stdbool.h>
22 fe621944 2020-11-10 stsp #include <stdlib.h>
24 fe621944 2020-11-10 stsp #include <arraylist.h>
25 fe621944 2020-11-10 stsp #include <diff_main.h>
26 fe621944 2020-11-10 stsp #include <diff_output.h>
28 fe621944 2020-11-10 stsp #include "diff_internal.h"
31 fe621944 2020-11-10 stsp diff_output_plain(struct diff_output_info **output_info, FILE *dest,
32 fe621944 2020-11-10 stsp const struct diff_input_info *info,
33 fe621944 2020-11-10 stsp const struct diff_result *result)
35 fe621944 2020-11-10 stsp struct diff_output_info *outinfo = NULL;
38 fe621944 2020-11-10 stsp if (!result)
39 fe621944 2020-11-10 stsp return EINVAL;
40 fe621944 2020-11-10 stsp if (result->rc != DIFF_RC_OK)
41 fe621944 2020-11-10 stsp return result->rc;
43 fe621944 2020-11-10 stsp if (output_info) {
44 fe621944 2020-11-10 stsp *output_info = diff_output_info_alloc();
45 fe621944 2020-11-10 stsp if (*output_info == NULL)
46 fe621944 2020-11-10 stsp return errno;
47 fe621944 2020-11-10 stsp outinfo = *output_info;
50 fe621944 2020-11-10 stsp for (i = 0; i < result->chunks.len; i++) {
51 fe621944 2020-11-10 stsp struct diff_chunk *c = &result->chunks.head[i];
52 fe621944 2020-11-10 stsp if (c->left_count && c->right_count)
53 fe621944 2020-11-10 stsp rc = diff_output_lines(outinfo, dest,
54 fe621944 2020-11-10 stsp c->solved ? " " : "?",
55 fe621944 2020-11-10 stsp c->left_start, c->left_count);
56 fe621944 2020-11-10 stsp else if (c->left_count && !c->right_count)
57 fe621944 2020-11-10 stsp rc = diff_output_lines(outinfo, dest,
58 fe621944 2020-11-10 stsp c->solved ? "-" : "?",
59 fe621944 2020-11-10 stsp c->left_start, c->left_count);
60 fe621944 2020-11-10 stsp else if (c->right_count && !c->left_count)
61 fe621944 2020-11-10 stsp rc = diff_output_lines(outinfo, dest,
62 fe621944 2020-11-10 stsp c->solved ? "+" : "?",
63 fe621944 2020-11-10 stsp c->right_start, c->right_count);
67 fe621944 2020-11-10 stsp return DIFF_RC_OK;