2 * Copyright (c) 2020 Neels Hofmeyr <neels@hofmeyr.de>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 #define print(args...) fprintf(stderr, ##args)
25 #define debug_dump dump
26 #define debug_dump_atom dump_atom
27 #define debug_dump_atoms dump_atoms
29 static inline void dump_atom(const struct diff_data *left, const struct diff_data *right, const struct diff_atom *atom)
36 print(" %3ld", diff_atom_root_idx(left, atom));
37 if (right && atom->patience.pos_in_other)
38 print(" %3ld", diff_atom_root_idx(right, atom->patience.pos_in_other));
40 print(" %s%s '", atom->patience.unique_here ? "u" : " ", atom->patience.unique_in_both ? "c" : " ");
42 for (s = atom->at; s < (const char*)(atom->at + atom->len); s++) {
47 else if ((*s < 32 || *s >= 127) && (*s != '\t'))
55 static inline void dump_atoms(const struct diff_data *d, struct diff_atom *atom, unsigned int count)
58 dump_atoms(d, atom, 20);
59 print("[%u lines skipped]\n", count - 20 - 20);
60 dump_atoms(d, atom + count - 20, 20);
64 foreach_diff_atom(i, atom, count) {
65 dump_atom(d, NULL, i);
70 static inline void dump(struct diff_data *d)
72 dump_atoms(d, d->atoms.head, d->atoms.len);
75 static inline void dump_myers_graph(const struct diff_data *l, const struct diff_data *r,
81 for (x = 0; x <= l->atoms.len; x++)
85 for (y = 0; y <= r->atoms.len; y++) {
87 for (x = 0; x <= l->atoms.len; x++) {
89 /* print d advancements from kd, if any. */
92 int max = l->atoms.len + r->atoms.len;
93 size_t kd_len = max + 1 + max;
96 #define xk_to_y(X, K) ((X) - (K))
97 for (di = 0; di < max; di++) {
99 for (ki = di; ki >= -di; ki -= 2) {
101 && y == xk_to_y(x, ki)) {
115 if (x < l->atoms.len && d < 10)
119 if (y == r->atoms.len)
123 for (x = 0; x < l->atoms.len; x++) {
124 if (diff_atom_same(&l->atoms.head[x], &r->atoms.head[y]))
133 static inline void debug_dump_myers_graph(const struct diff_data *l, const struct diff_data *r,
136 if (l->atoms.len > 99 || r->atoms.len > 99)
138 dump_myers_graph(l, r, kd);
142 #define debug(args...)
143 #define debug_dump(args...)
144 #define debug_dump_atom(args...)
145 #define debug_dump_atoms(args...)
146 #define debug_dump_myers_graph(args...)