Blame


1 fe621944 2020-11-10 stsp /* Common parts for printing diff output */
2 fe621944 2020-11-10 stsp /*
3 fe621944 2020-11-10 stsp * Copyright (c) 2020 Neels Hofmeyr <neels@hofmeyr.de>
4 fe621944 2020-11-10 stsp *
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.
8 fe621944 2020-11-10 stsp *
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.
16 fe621944 2020-11-10 stsp */
17 fe621944 2020-11-10 stsp
18 fe621944 2020-11-10 stsp #include <ctype.h>
19 fe621944 2020-11-10 stsp #include <errno.h>
20 fe621944 2020-11-10 stsp #include <stdbool.h>
21 f3c44083 2020-11-14 naddy #include <stdint.h>
22 fe621944 2020-11-10 stsp #include <stdio.h>
23 fe621944 2020-11-10 stsp #include <stdlib.h>
24 fe621944 2020-11-10 stsp #include <string.h>
25 fe621944 2020-11-10 stsp #include <unistd.h>
26 fe621944 2020-11-10 stsp
27 fe621944 2020-11-10 stsp #include <arraylist.h>
28 fe621944 2020-11-10 stsp #include <diff_main.h>
29 fe621944 2020-11-10 stsp #include <diff_output.h>
30 fe621944 2020-11-10 stsp
31 fe621944 2020-11-10 stsp #include "diff_internal.h"
32 fe621944 2020-11-10 stsp
33 fe621944 2020-11-10 stsp static int
34 fe621944 2020-11-10 stsp get_atom_byte(int *ch, struct diff_atom *atom, off_t off)
35 fe621944 2020-11-10 stsp {
36 fe621944 2020-11-10 stsp off_t cur;
37 fe621944 2020-11-10 stsp
38 fe621944 2020-11-10 stsp if (atom->at != NULL) {
39 fe621944 2020-11-10 stsp *ch = atom->at[off];
40 fe621944 2020-11-10 stsp return 0;
41 fe621944 2020-11-10 stsp }
42 fe621944 2020-11-10 stsp
43 fe621944 2020-11-10 stsp cur = ftello(atom->root->f);
44 fe621944 2020-11-10 stsp if (cur == -1)
45 fe621944 2020-11-10 stsp return errno;
46 fe621944 2020-11-10 stsp
47 fe621944 2020-11-10 stsp if (cur != atom->pos + off &&
48 fe621944 2020-11-10 stsp fseeko(atom->root->f, atom->pos + off, SEEK_SET) == -1)
49 fe621944 2020-11-10 stsp return errno;
50 fe621944 2020-11-10 stsp
51 fe621944 2020-11-10 stsp *ch = fgetc(atom->root->f);
52 fe621944 2020-11-10 stsp if (*ch == EOF && ferror(atom->root->f))
53 fe621944 2020-11-10 stsp return errno;
54 fe621944 2020-11-10 stsp
55 fe621944 2020-11-10 stsp return 0;
56 fe621944 2020-11-10 stsp }
57 fe621944 2020-11-10 stsp
58 4f655d1b 2021-07-08 stsp #define DIFF_OUTPUT_BUF_SIZE 512
59 4f655d1b 2021-07-08 stsp
60 fe621944 2020-11-10 stsp int
61 fe621944 2020-11-10 stsp diff_output_lines(struct diff_output_info *outinfo, FILE *dest,
62 fe621944 2020-11-10 stsp const char *prefix, struct diff_atom *start_atom,
63 fe621944 2020-11-10 stsp unsigned int count)
64 fe621944 2020-11-10 stsp {
65 fe621944 2020-11-10 stsp struct diff_atom *atom;
66 fe621944 2020-11-10 stsp off_t outoff = 0, *offp;
67 b77ebd68 2022-08-04 mark uint8_t *typep;
68 fe621944 2020-11-10 stsp int rc;
69 fe621944 2020-11-10 stsp
70 fe621944 2020-11-10 stsp if (outinfo && outinfo->line_offsets.len > 0) {
71 fe621944 2020-11-10 stsp unsigned int idx = outinfo->line_offsets.len - 1;
72 fe621944 2020-11-10 stsp outoff = outinfo->line_offsets.head[idx];
73 fe621944 2020-11-10 stsp }
74 fe621944 2020-11-10 stsp
75 fe621944 2020-11-10 stsp foreach_diff_atom(atom, start_atom, count) {
76 fe621944 2020-11-10 stsp off_t outlen = 0;
77 4f655d1b 2021-07-08 stsp int i, ch, nbuf = 0;
78 fe621944 2020-11-10 stsp unsigned int len = atom->len;
79 4f655d1b 2021-07-08 stsp unsigned char buf[DIFF_OUTPUT_BUF_SIZE + 1 /* '\n' */];
80 4f655d1b 2021-07-08 stsp size_t n;
81 4f655d1b 2021-07-08 stsp
82 4f655d1b 2021-07-08 stsp n = strlcpy(buf, prefix, sizeof(buf));
83 4f655d1b 2021-07-08 stsp if (n >= DIFF_OUTPUT_BUF_SIZE) /* leave room for '\n' */
84 4f655d1b 2021-07-08 stsp return ENOBUFS;
85 4f655d1b 2021-07-08 stsp nbuf += n;
86 4f655d1b 2021-07-08 stsp
87 fe621944 2020-11-10 stsp if (len) {
88 fe621944 2020-11-10 stsp rc = get_atom_byte(&ch, atom, len - 1);
89 fe621944 2020-11-10 stsp if (rc)
90 fe621944 2020-11-10 stsp return rc;
91 fe621944 2020-11-10 stsp if (ch == '\n')
92 fe621944 2020-11-10 stsp len--;
93 fe621944 2020-11-10 stsp if (len) {
94 fe621944 2020-11-10 stsp rc = get_atom_byte(&ch, atom, len - 1);
95 fe621944 2020-11-10 stsp if (rc)
96 fe621944 2020-11-10 stsp return rc;
97 fe621944 2020-11-10 stsp if (ch == '\r')
98 fe621944 2020-11-10 stsp len--;
99 fe621944 2020-11-10 stsp }
100 fe621944 2020-11-10 stsp }
101 fe621944 2020-11-10 stsp
102 fe621944 2020-11-10 stsp for (i = 0; i < len; i++) {
103 fe621944 2020-11-10 stsp rc = get_atom_byte(&ch, atom, i);
104 fe621944 2020-11-10 stsp if (rc)
105 fe621944 2020-11-10 stsp return rc;
106 4f655d1b 2021-07-08 stsp if (nbuf >= DIFF_OUTPUT_BUF_SIZE) {
107 4f655d1b 2021-07-08 stsp rc = fwrite(buf, 1, nbuf, dest);
108 4f655d1b 2021-07-08 stsp if (rc != nbuf)
109 4f655d1b 2021-07-08 stsp return errno;
110 4f655d1b 2021-07-08 stsp outlen += rc;
111 4f655d1b 2021-07-08 stsp nbuf = 0;
112 4f655d1b 2021-07-08 stsp }
113 4f655d1b 2021-07-08 stsp buf[nbuf++] = ch;
114 fe621944 2020-11-10 stsp }
115 4f655d1b 2021-07-08 stsp buf[nbuf++] = '\n';
116 4f655d1b 2021-07-08 stsp rc = fwrite(buf, 1, nbuf, dest);
117 4f655d1b 2021-07-08 stsp if (rc != nbuf)
118 fe621944 2020-11-10 stsp return errno;
119 fe621944 2020-11-10 stsp outlen += rc;
120 fe621944 2020-11-10 stsp if (outinfo) {
121 fe621944 2020-11-10 stsp ARRAYLIST_ADD(offp, outinfo->line_offsets);
122 fe621944 2020-11-10 stsp if (offp == NULL)
123 fe621944 2020-11-10 stsp return ENOMEM;
124 fe621944 2020-11-10 stsp outoff += outlen;
125 fe621944 2020-11-10 stsp *offp = outoff;
126 b77ebd68 2022-08-04 mark ARRAYLIST_ADD(typep, outinfo->line_types);
127 b77ebd68 2022-08-04 mark if (typep == NULL)
128 b77ebd68 2022-08-04 mark return ENOMEM;
129 b77ebd68 2022-08-04 mark *typep = *prefix == ' ' ? DIFF_LINE_CONTEXT :
130 b77ebd68 2022-08-04 mark *prefix == '-' ? DIFF_LINE_MINUS :
131 b77ebd68 2022-08-04 mark *prefix == '+' ? DIFF_LINE_PLUS : DIFF_LINE_NONE;
132 fe621944 2020-11-10 stsp }
133 fe621944 2020-11-10 stsp }
134 fe621944 2020-11-10 stsp
135 fe621944 2020-11-10 stsp return DIFF_RC_OK;
136 fe621944 2020-11-10 stsp }
137 fe621944 2020-11-10 stsp
138 fe621944 2020-11-10 stsp int
139 fe621944 2020-11-10 stsp diff_output_chunk_left_version(struct diff_output_info **output_info,
140 fe621944 2020-11-10 stsp FILE *dest,
141 fe621944 2020-11-10 stsp const struct diff_input_info *info,
142 fe621944 2020-11-10 stsp const struct diff_result *result,
143 fe621944 2020-11-10 stsp const struct diff_chunk_context *cc)
144 fe621944 2020-11-10 stsp {
145 fe621944 2020-11-10 stsp int rc, c_idx;
146 fe621944 2020-11-10 stsp struct diff_output_info *outinfo = NULL;
147 fe621944 2020-11-10 stsp
148 fe621944 2020-11-10 stsp if (diff_range_empty(&cc->left))
149 fe621944 2020-11-10 stsp return DIFF_RC_OK;
150 fe621944 2020-11-10 stsp
151 fe621944 2020-11-10 stsp if (output_info) {
152 fe621944 2020-11-10 stsp *output_info = diff_output_info_alloc();
153 fe621944 2020-11-10 stsp if (*output_info == NULL)
154 fe621944 2020-11-10 stsp return ENOMEM;
155 fe621944 2020-11-10 stsp outinfo = *output_info;
156 fe621944 2020-11-10 stsp }
157 fe621944 2020-11-10 stsp
158 fe621944 2020-11-10 stsp /* Write out all chunks on the left side. */
159 fe621944 2020-11-10 stsp for (c_idx = cc->chunk.start; c_idx < cc->chunk.end; c_idx++) {
160 fe621944 2020-11-10 stsp const struct diff_chunk *c = &result->chunks.head[c_idx];
161 fe621944 2020-11-10 stsp
162 fe621944 2020-11-10 stsp if (c->left_count) {
163 fe621944 2020-11-10 stsp rc = diff_output_lines(outinfo, dest, "",
164 fe621944 2020-11-10 stsp c->left_start, c->left_count);
165 fe621944 2020-11-10 stsp if (rc)
166 fe621944 2020-11-10 stsp return rc;
167 fe621944 2020-11-10 stsp }
168 fe621944 2020-11-10 stsp }
169 fe621944 2020-11-10 stsp
170 fe621944 2020-11-10 stsp return DIFF_RC_OK;
171 fe621944 2020-11-10 stsp }
172 fe621944 2020-11-10 stsp
173 fe621944 2020-11-10 stsp int
174 fe621944 2020-11-10 stsp diff_output_chunk_right_version(struct diff_output_info **output_info,
175 fe621944 2020-11-10 stsp FILE *dest,
176 fe621944 2020-11-10 stsp const struct diff_input_info *info,
177 fe621944 2020-11-10 stsp const struct diff_result *result,
178 fe621944 2020-11-10 stsp const struct diff_chunk_context *cc)
179 fe621944 2020-11-10 stsp {
180 fe621944 2020-11-10 stsp int rc, c_idx;
181 fe621944 2020-11-10 stsp struct diff_output_info *outinfo = NULL;
182 fe621944 2020-11-10 stsp
183 fe621944 2020-11-10 stsp if (diff_range_empty(&cc->right))
184 fe621944 2020-11-10 stsp return DIFF_RC_OK;
185 fe621944 2020-11-10 stsp
186 fe621944 2020-11-10 stsp if (output_info) {
187 fe621944 2020-11-10 stsp *output_info = diff_output_info_alloc();
188 fe621944 2020-11-10 stsp if (*output_info == NULL)
189 fe621944 2020-11-10 stsp return ENOMEM;
190 fe621944 2020-11-10 stsp outinfo = *output_info;
191 fe621944 2020-11-10 stsp }
192 fe621944 2020-11-10 stsp
193 fe621944 2020-11-10 stsp /* Write out all chunks on the right side. */
194 fe621944 2020-11-10 stsp for (c_idx = cc->chunk.start; c_idx < cc->chunk.end; c_idx++) {
195 fe621944 2020-11-10 stsp const struct diff_chunk *c = &result->chunks.head[c_idx];
196 fe621944 2020-11-10 stsp
197 fe621944 2020-11-10 stsp if (c->right_count) {
198 fe621944 2020-11-10 stsp rc = diff_output_lines(outinfo, dest, "", c->right_start,
199 fe621944 2020-11-10 stsp c->right_count);
200 fe621944 2020-11-10 stsp if (rc)
201 fe621944 2020-11-10 stsp return rc;
202 fe621944 2020-11-10 stsp }
203 fe621944 2020-11-10 stsp }
204 fe621944 2020-11-10 stsp
205 fe621944 2020-11-10 stsp return DIFF_RC_OK;
206 fe621944 2020-11-10 stsp }
207 fe621944 2020-11-10 stsp
208 fe621944 2020-11-10 stsp int
209 fe621944 2020-11-10 stsp diff_output_trailing_newline_msg(struct diff_output_info *outinfo, FILE *dest,
210 fe621944 2020-11-10 stsp const struct diff_chunk *c)
211 fe621944 2020-11-10 stsp {
212 fe621944 2020-11-10 stsp enum diff_chunk_type chunk_type = diff_chunk_type(c);
213 fe621944 2020-11-10 stsp struct diff_atom *atom, *start_atom;
214 fe621944 2020-11-10 stsp unsigned int atom_count;
215 fe621944 2020-11-10 stsp int rc, ch;
216 fe621944 2020-11-10 stsp off_t outoff = 0, *offp;
217 b77ebd68 2022-08-04 mark uint8_t *typep;
218 fe621944 2020-11-10 stsp
219 b77ebd68 2022-08-04 mark
220 fe621944 2020-11-10 stsp if (chunk_type == CHUNK_MINUS || chunk_type == CHUNK_SAME) {
221 fe621944 2020-11-10 stsp start_atom = c->left_start;
222 fe621944 2020-11-10 stsp atom_count = c->left_count;
223 fe621944 2020-11-10 stsp } else if (chunk_type == CHUNK_PLUS) {
224 fe621944 2020-11-10 stsp start_atom = c->right_start;
225 fe621944 2020-11-10 stsp atom_count = c->right_count;
226 fe621944 2020-11-10 stsp } else
227 fe621944 2020-11-10 stsp return EINVAL;
228 fe621944 2020-11-10 stsp
229 fe621944 2020-11-10 stsp /* Locate the last atom. */
230 fe621944 2020-11-10 stsp if (atom_count == 0)
231 fe621944 2020-11-10 stsp return EINVAL;
232 fe621944 2020-11-10 stsp atom = &start_atom[atom_count - 1];
233 fe621944 2020-11-10 stsp
234 fe621944 2020-11-10 stsp rc = get_atom_byte(&ch, atom, atom->len - 1);
235 fe621944 2020-11-10 stsp if (rc != DIFF_RC_OK)
236 fe621944 2020-11-10 stsp return rc;
237 fe621944 2020-11-10 stsp
238 fe621944 2020-11-10 stsp if (ch != '\n') {
239 fe621944 2020-11-10 stsp if (outinfo && outinfo->line_offsets.len > 0) {
240 fe621944 2020-11-10 stsp unsigned int idx = outinfo->line_offsets.len - 1;
241 fe621944 2020-11-10 stsp outoff = outinfo->line_offsets.head[idx];
242 fe621944 2020-11-10 stsp }
243 fe621944 2020-11-10 stsp rc = fprintf(dest, "\\ No newline at end of file\n");
244 fe621944 2020-11-10 stsp if (rc < 0)
245 fe621944 2020-11-10 stsp return errno;
246 fe621944 2020-11-10 stsp if (outinfo) {
247 fe621944 2020-11-10 stsp ARRAYLIST_ADD(offp, outinfo->line_offsets);
248 fe621944 2020-11-10 stsp if (offp == NULL)
249 fe621944 2020-11-10 stsp return ENOMEM;
250 fe621944 2020-11-10 stsp outoff += rc;
251 fe621944 2020-11-10 stsp *offp = outoff;
252 b77ebd68 2022-08-04 mark ARRAYLIST_ADD(typep, outinfo->line_types);
253 b77ebd68 2022-08-04 mark if (typep == NULL)
254 b77ebd68 2022-08-04 mark return ENOMEM;
255 b77ebd68 2022-08-04 mark *typep = DIFF_LINE_NONE;
256 fe621944 2020-11-10 stsp }
257 fe621944 2020-11-10 stsp }
258 fe621944 2020-11-10 stsp
259 fe621944 2020-11-10 stsp return DIFF_RC_OK;
260 fe621944 2020-11-10 stsp }
261 fe621944 2020-11-10 stsp
262 fe621944 2020-11-10 stsp static bool
263 f3b2b552 2020-12-10 stsp is_function_prototype(unsigned char ch)
264 fe621944 2020-11-10 stsp {
265 cee4532d 2022-11-17 op return (isalpha((unsigned char)ch) || ch == '_' || ch == '$');
266 fe621944 2020-11-10 stsp }
267 fe621944 2020-11-10 stsp
268 fe621944 2020-11-10 stsp #define begins_with(s, pre) (strncmp(s, pre, sizeof(pre)-1) == 0)
269 fe621944 2020-11-10 stsp
270 fe621944 2020-11-10 stsp int
271 f3b2b552 2020-12-10 stsp diff_output_match_function_prototype(char *prototype, size_t prototype_size,
272 f3b2b552 2020-12-10 stsp int *last_prototype_idx, const struct diff_result *result,
273 579042a9 2022-09-23 stsp const struct diff_chunk_context *cc, unsigned int ncontext)
274 fe621944 2020-11-10 stsp {
275 fe621944 2020-11-10 stsp struct diff_atom *start_atom, *atom;
276 fe621944 2020-11-10 stsp const struct diff_data *data;
277 f3b2b552 2020-12-10 stsp unsigned char buf[DIFF_FUNCTION_CONTEXT_SIZE];
278 58e31a80 2022-06-27 op const char *state = NULL;
279 579042a9 2022-09-23 stsp int rc, i, ch, idx;
280 579042a9 2022-09-23 stsp
281 579042a9 2022-09-23 stsp idx = MIN(cc->left.start + (ncontext ? ncontext : 0), cc->left.end - 1);
282 fe621944 2020-11-10 stsp
283 fe621944 2020-11-10 stsp if (result->left->atoms.len > 0 && cc->left.start > 0) {
284 fe621944 2020-11-10 stsp data = result->left;
285 579042a9 2022-09-23 stsp start_atom = &data->atoms.head[idx];
286 fe621944 2020-11-10 stsp } else
287 fe621944 2020-11-10 stsp return DIFF_RC_OK;
288 fe621944 2020-11-10 stsp
289 fe621944 2020-11-10 stsp diff_data_foreach_atom_backwards_from(start_atom, atom, data) {
290 f3b2b552 2020-12-10 stsp int atom_idx = diff_atom_root_idx(data, atom);
291 f3b2b552 2020-12-10 stsp if (atom_idx < *last_prototype_idx)
292 f3b2b552 2020-12-10 stsp break;
293 f3b2b552 2020-12-10 stsp rc = get_atom_byte(&ch, atom, 0);
294 f3b2b552 2020-12-10 stsp if (rc)
295 f3b2b552 2020-12-10 stsp return rc;
296 f3b2b552 2020-12-10 stsp buf[0] = (unsigned char)ch;
297 f3b2b552 2020-12-10 stsp if (!is_function_prototype(buf[0]))
298 f3b2b552 2020-12-10 stsp continue;
299 f3b2b552 2020-12-10 stsp for (i = 1; i < atom->len && i < sizeof(buf) - 1; i++) {
300 fe621944 2020-11-10 stsp rc = get_atom_byte(&ch, atom, i);
301 fe621944 2020-11-10 stsp if (rc)
302 fe621944 2020-11-10 stsp return rc;
303 fe621944 2020-11-10 stsp if (ch == '\n')
304 fe621944 2020-11-10 stsp break;
305 f3b2b552 2020-12-10 stsp buf[i] = (unsigned char)ch;
306 fe621944 2020-11-10 stsp }
307 fe621944 2020-11-10 stsp buf[i] = '\0';
308 f3b2b552 2020-12-10 stsp if (begins_with(buf, "private:")) {
309 f3b2b552 2020-12-10 stsp if (!state)
310 f3b2b552 2020-12-10 stsp state = " (private)";
311 f3b2b552 2020-12-10 stsp } else if (begins_with(buf, "protected:")) {
312 f3b2b552 2020-12-10 stsp if (!state)
313 f3b2b552 2020-12-10 stsp state = " (protected)";
314 f3b2b552 2020-12-10 stsp } else if (begins_with(buf, "public:")) {
315 f3b2b552 2020-12-10 stsp if (!state)
316 f3b2b552 2020-12-10 stsp state = " (public)";
317 f3b2b552 2020-12-10 stsp } else {
318 f3b2b552 2020-12-10 stsp if (state) /* don't care about truncation */
319 f3b2b552 2020-12-10 stsp strlcat(buf, state, sizeof(buf));
320 f3b2b552 2020-12-10 stsp strlcpy(prototype, buf, prototype_size);
321 f3b2b552 2020-12-10 stsp break;
322 fe621944 2020-11-10 stsp }
323 fe621944 2020-11-10 stsp }
324 fe621944 2020-11-10 stsp
325 f3b2b552 2020-12-10 stsp *last_prototype_idx = diff_atom_root_idx(data, start_atom);
326 fe621944 2020-11-10 stsp return DIFF_RC_OK;
327 fe621944 2020-11-10 stsp }
328 fe621944 2020-11-10 stsp
329 fe621944 2020-11-10 stsp struct diff_output_info *
330 fe621944 2020-11-10 stsp diff_output_info_alloc(void)
331 fe621944 2020-11-10 stsp {
332 fe621944 2020-11-10 stsp struct diff_output_info *output_info;
333 fe621944 2020-11-10 stsp off_t *offp;
334 b77ebd68 2022-08-04 mark uint8_t *typep;
335 fe621944 2020-11-10 stsp
336 fe621944 2020-11-10 stsp output_info = malloc(sizeof(*output_info));
337 fe621944 2020-11-10 stsp if (output_info != NULL) {
338 fe621944 2020-11-10 stsp ARRAYLIST_INIT(output_info->line_offsets, 128);
339 fe621944 2020-11-10 stsp ARRAYLIST_ADD(offp, output_info->line_offsets);
340 fe621944 2020-11-10 stsp if (offp == NULL) {
341 fe621944 2020-11-10 stsp diff_output_info_free(output_info);
342 fe621944 2020-11-10 stsp return NULL;
343 fe621944 2020-11-10 stsp }
344 fe621944 2020-11-10 stsp *offp = 0;
345 b77ebd68 2022-08-04 mark ARRAYLIST_INIT(output_info->line_types, 128);
346 b77ebd68 2022-08-04 mark ARRAYLIST_ADD(typep, output_info->line_types);
347 b77ebd68 2022-08-04 mark if (typep == NULL) {
348 b77ebd68 2022-08-04 mark diff_output_info_free(output_info);
349 b77ebd68 2022-08-04 mark return NULL;
350 b77ebd68 2022-08-04 mark }
351 b77ebd68 2022-08-04 mark *typep = DIFF_LINE_NONE;
352 fe621944 2020-11-10 stsp }
353 fe621944 2020-11-10 stsp return output_info;
354 fe621944 2020-11-10 stsp }
355 fe621944 2020-11-10 stsp
356 fe621944 2020-11-10 stsp void
357 fe621944 2020-11-10 stsp diff_output_info_free(struct diff_output_info *output_info)
358 fe621944 2020-11-10 stsp {
359 fe621944 2020-11-10 stsp ARRAYLIST_FREE(output_info->line_offsets);
360 b77ebd68 2022-08-04 mark ARRAYLIST_FREE(output_info->line_types);
361 fe621944 2020-11-10 stsp free(output_info);
362 c4cd9c5b 2020-11-21 stsp }
363 c4cd9c5b 2020-11-21 stsp
364 c4cd9c5b 2020-11-21 stsp const char *
365 c4cd9c5b 2020-11-21 stsp diff_output_get_label_left(const struct diff_input_info *info)
366 c4cd9c5b 2020-11-21 stsp {
367 c4cd9c5b 2020-11-21 stsp if (info->flags & DIFF_INPUT_LEFT_NONEXISTENT)
368 c4cd9c5b 2020-11-21 stsp return "/dev/null";
369 c4cd9c5b 2020-11-21 stsp
370 116d19d9 2022-09-02 mark return info->left_path ? info->left_path : "a";
371 c4cd9c5b 2020-11-21 stsp }
372 c4cd9c5b 2020-11-21 stsp
373 c4cd9c5b 2020-11-21 stsp const char *
374 c4cd9c5b 2020-11-21 stsp diff_output_get_label_right(const struct diff_input_info *info)
375 c4cd9c5b 2020-11-21 stsp {
376 c4cd9c5b 2020-11-21 stsp if (info->flags & DIFF_INPUT_RIGHT_NONEXISTENT)
377 c4cd9c5b 2020-11-21 stsp return "/dev/null";
378 c4cd9c5b 2020-11-21 stsp
379 116d19d9 2022-09-02 mark return info->right_path ? info->right_path : "b";
380 fe621944 2020-11-10 stsp }