7 #define Color_RANGE Color_BBLUE
8 #define Color_INSERT Color_BGREEN
9 #define Color_DELETE Color_BRED
10 #define Color_BGINSERT "\x1b[48;5;22m"
11 #define Color_BGDELETE "\x1b[48;5;52m"
13 #define FAST_MOD2(x, y) ((x) & (y - 1))
14 #define FAST_MOD64(x) FAST_MOD2(x, 64)
15 #define DIFF_COLOR(prefix) (prefix == '+' ? Color_INSERT : (prefix == '-' ? Color_DELETE : ""))
16 #define DIFF_BGCOLOR(prefix) (prefix == '+' ? Color_BGINSERT : (prefix == '-' ? Color_BGDELETE : ""))
29 elem = elem_at(array,
i);
30 stringify(elem, &
tmp);
33 if (
len > 0 &&
p[
len - 1] ==
'\n') {
95 elem = elem_at(array,
i);
96 stringify(elem, &
tmp);
100 if (
len > 0 &&
p[
len - 1] ==
'\n') {
123 const void *a_array = diff->
a;
130 const void *b_array = diff->
b;
139 ut32 num_bounds = num_nl + 1;
144 for (
ut32 i = 0;
i < num_bounds;
i++) {
145 char_bounds[
i * 2] = char_bounds[
i * 2 + 1] = -1;
150 bool newline =
false;
153 for (;
i < a_end; ++
i) {
159 elem = elem_at(a_array,
i);
160 stringify(elem, &
tmp);
163 if (
len > 0 &&
p[
len - 1] ==
'\n') {
172 for (; j < b_end; ++j) {
174 elem_b = elem_at(b_array, j);
175 stringify(elem_b, &tmp2);
178 if (len_b > 0 && p_b[len_b - 1] ==
'\n') {
182 if (
len && len_b && (
p[0] == p_b[0] ||
p[
len - 1] == p_b[len_b - 1])) {
185 for (; left <
RZ_MIN(
len, len_b) &&
p[left] == p_b[left]; left++)
187 char_bounds[bounds_idx * 2] = left;
191 for (; right <
RZ_MIN(
len, len_b) - left &&
p[
len - 1 - right] == p_b[len_b - 1 - right];
194 char_bounds[bounds_idx * 2 + 1] = right;
212 for (
st32 i = a_beg;
i < a_end; ++
i) {
219 elem = elem_at(a_array,
i);
220 stringify(elem, &
tmp);
223 if (
len > 0 &&
p[
len - 1] ==
'\n') {
227 st32 left = char_bounds[bounds_idx * 2];
228 st32 right = char_bounds[bounds_idx * 2 + 1];
229 if (left < 0 || right < 0 ||
len - right < left) {
250 for (
st32 i = b_beg;
i < b_end; ++
i) {
257 elem = elem_at(b_array,
i);
258 stringify(elem, &
tmp);
261 if (
len > 0 &&
p[
len - 1] ==
'\n') {
265 st32 left = char_bounds[bounds_idx * 2];
266 st32 right = char_bounds[bounds_idx * 2 + 1];
267 if (left < 0 || right < 0 ||
len - right < left) {
290 bool newline =
false;
312 elem = elem_at(array,
i);
313 stringify(elem, &
tmp);
317 if (
len > 0 &&
p[
len - 1] ==
'\n') {
351 goto rz_diff_unified_text_fail;
364 goto rz_diff_unified_text_fail;
397 rz_diff_unified_text_fail:
427 RZ_LOG_ERROR(
"rz_diff_unified: failed to allocate json\n");
428 goto rz_diff_unified_json_fail;
435 RZ_LOG_ERROR(
"rz_diff_unified: failed to allocate timestamp\n");
436 goto rz_diff_unified_json_fail;
447 goto rz_diff_unified_json_fail;
479 rz_diff_unified_json_fail:
#define DIFF_IS_BYTES_METHOD(x)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
RZ_API RZ_OWN RzList * rz_diff_opcodes_grouped_new(RZ_NONNULL RzDiff *diff, ut32 n_groups)
Generates groups of opcodes needed to go from A to B.
unsigned short prefix[65536]
RZ_API void Ht_() free(HtName_(Ht) *ht)
RZ_API RZ_BORROW void * rz_list_first(RZ_NONNULL const RzList *list)
Returns the first element of the list.
RZ_API RZ_BORROW void * rz_list_last(RZ_NONNULL const RzList *list)
Returns the last element of the list.
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
void * malloc(size_t size)
#define DIFF_IS_LINES_METHOD(x)
static static fork const void static count static fd const char const char static newpath char char char static envp time
#define rz_return_val_if_fail(expr, val)
const void *(* RzDiffMethodElemAt)(RZ_BORROW const void *array, ut32 index)
#define RZ_DIFF_DEFAULT_N_GROUPS
void(* RzDiffMethodStringify)(RZ_BORROW const void *elem, RZ_BORROW RzStrBuf *sb)
#define RZ_LOG_ERROR(fmtstr,...)
RZ_API PJ * pj_ka(PJ *j, const char *k)
RZ_API PJ * pj_end(PJ *j)
RZ_API void pj_free(PJ *j)
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
RZ_API PJ * pj_N(PJ *j, st64 n)
RZ_API RZ_OWN char * rz_strbuf_drain(RzStrBuf *sb)
RZ_API char * rz_strbuf_get(RzStrBuf *sb)
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
RZ_API void rz_strbuf_fini(RzStrBuf *sb)
RZ_API RzStrBuf * rz_strbuf_new(const char *s)
RZ_API void rz_strbuf_free(RzStrBuf *sb)
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API void rz_strbuf_init(RzStrBuf *sb)
RZ_API int rz_strbuf_length(RzStrBuf *sb)
RZ_API bool rz_strbuf_append_n(RzStrBuf *sb, const char *s, size_t l)
RZ_API RZ_OWN char * rz_time_date_now_to_string(void)
Returns the timestamp in string format of the current time (now)
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr socklen_t static fromlen const void const struct sockaddr to
RzDiffMethodElemAt elem_at
RzDiffMethodStringify stringify
RZ_API RZ_OWN char * rz_diff_unified_text(RZ_NONNULL RzDiff *diff, RZ_NULLABLE const char *from, RZ_NULLABLE const char *to, bool show_time, bool color)
Produces a diff output with A and B inputs presented immediately adjacent to each other.
RZ_API RZ_OWN PJ * rz_diff_unified_json(RZ_NONNULL RzDiff *diff, RZ_NULLABLE const char *from, RZ_NULLABLE const char *to, bool show_time)
Produces a diff output to convert A in B in a JSON format.
#define DIFF_COLOR(prefix)
static void diff_unified_append_data(RzDiff *diff, const void *array, st32 beg, st32 end, RzStrBuf *sb, char prefix, bool color)
static void diff_unified_json_data(RzDiff *diff, const void *array, st32 beg, st32 end, PJ *pj, const char *op)
static ut32 count_newlines(RzDiff *diff, const void *array, st32 beg, st32 end)
static void diff_unified_append_ranges(RzList *opcodes, RzStrBuf *sb, bool color)
#define DIFF_BGCOLOR(prefix)
static void diff_unified_json_ranges(RzList *opcodes, PJ *pj)
static void diff_unified_lines_hl(RzDiff *diff, RzDiffOp *op, RzStrBuf *sb, char del_prefix, char ins_prefix)