Blame


1 3b0f3d61 2020-01-22 neels /* Common parts for printing diff output */
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 void diff_output_lines(FILE *dest, const char *prefix, struct diff_atom *start_atom, unsigned int count)
21 3b0f3d61 2020-01-22 neels {
22 3b0f3d61 2020-01-22 neels struct diff_atom *atom;
23 3b0f3d61 2020-01-22 neels foreach_diff_atom(atom, start_atom, count) {
24 3b0f3d61 2020-01-22 neels fprintf(dest, "%s", prefix);
25 3b0f3d61 2020-01-22 neels int i;
26 3b0f3d61 2020-01-22 neels unsigned int len = atom->len;
27 3b0f3d61 2020-01-22 neels if (len && atom->at[len - 1] == '\n') {
28 3b0f3d61 2020-01-22 neels len--;
29 3b0f3d61 2020-01-22 neels if (len && atom->at[len - 1] == '\r')
30 3b0f3d61 2020-01-22 neels len--;
31 3b0f3d61 2020-01-22 neels }
32 3b0f3d61 2020-01-22 neels
33 3b0f3d61 2020-01-22 neels for (i = 0; i < len; i++) {
34 3b0f3d61 2020-01-22 neels char c = atom->at[i];
35 fbd55577 2020-01-27 neels if ((c < 0x20 || c >= 0x7f) && c != '\t')
36 3b0f3d61 2020-01-22 neels fprintf(dest, "\\x%02x", (unsigned char)c);
37 3b0f3d61 2020-01-22 neels else
38 3b0f3d61 2020-01-22 neels fprintf(dest, "%c", c);
39 3b0f3d61 2020-01-22 neels }
40 3b0f3d61 2020-01-22 neels fprintf(dest, "\n");
41 3b0f3d61 2020-01-22 neels }
42 3b0f3d61 2020-01-22 neels }