1 /* Output all lines of a diff_result. */
3 * Copyright (c) 2020 Neels Hofmeyr <neels@hofmeyr.de>
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.
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.
24 #include <arraylist.h>
25 #include <diff_main.h>
26 #include <diff_output.h>
28 #include "diff_internal.h"
31 diff_output_plain(struct diff_output_info
**output_info
, FILE *dest
,
32 const struct diff_input_info
*info
,
33 const struct diff_result
*result
)
35 struct diff_output_info
*outinfo
= NULL
;
40 if (result
->rc
!= DIFF_RC_OK
)
44 *output_info
= diff_output_info_alloc();
45 if (*output_info
== NULL
)
47 outinfo
= *output_info
;
50 for (i
= 0; i
< result
->chunks
.len
; i
++) {
51 struct diff_chunk
*c
= &result
->chunks
.head
[i
];
52 if (c
->left_count
&& c
->right_count
)
53 rc
= diff_output_lines(outinfo
, dest
,
54 c
->solved
? " " : "?",
55 c
->left_start
, c
->left_count
);
56 else if (c
->left_count
&& !c
->right_count
)
57 rc
= diff_output_lines(outinfo
, dest
,
58 c
->solved
? "-" : "?",
59 c
->left_start
, c
->left_count
);
60 else if (c
->right_count
&& !c
->left_count
)
61 rc
= diff_output_lines(outinfo
, dest
,
62 c
->solved
? "+" : "?",
63 c
->right_start
, c
->right_count
);