1 #ifndef R2_DIFF_H
2 #define R2_DIFF_H
3 
4 #include <r_types.h>
5 #include <r_util.h>
6 #include <r_cons.h>
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 R_LIB_VERSION_HEADER(r_diff);
13 
14 #define Color_INSERT Color_BGREEN
15 #define Color_DELETE Color_BRED
16 #define Color_BGINSERT "\x1b[48;5;22m"
17 #define Color_BGDELETE "\x1b[48;5;52m"
18 #define Color_HLINSERT Color_BGINSERT Color_INSERT
19 #define Color_HLDELETE Color_BGDELETE Color_DELETE
20 
21 typedef struct r_diff_op_t {
22 	/* file A */
23 	ut64 a_off;
24 	const ut8 *a_buf;
25 	ut32 a_len;
26 
27 	/* file B */
28 	ut64 b_off;
29 	const ut8 *b_buf;
30 	ut32 b_len;
31 } RDiffOp;
32 
33 //typedef struct r_diff_t RDiff;
34 
35 typedef struct r_diff_t {
36 	ut64 off_a;
37 	ut64 off_b;
38 	int delta;
39 	void *user;
40 	bool verbose;
41 	int type;
42 	const char *diff_cmd;
43 	int (*callback)(struct r_diff_t *diff, void *user, RDiffOp *op);
44 } RDiff;
45 
46 typedef int (*RDiffCallback)(RDiff *diff, void *user, RDiffOp *op);
47 
48 typedef struct r_diffchar_t {
49 	const ut8 *align_a;
50 	const ut8 *align_b;
51 	size_t len_buf;
52 	size_t start_align;
53 } RDiffChar;
54 
55 /* XXX: this api needs to be reviewed , constructor with offa+offb?? */
56 #ifdef R_API
57 R_API RDiff *r_diff_new(void);
58 R_API RDiff *r_diff_new_from(ut64 off_a, ut64 off_b);
59 R_API RDiff *r_diff_free(RDiff *d);
60 
61 R_API int r_diff_buffers(RDiff *d, const ut8 *a, ut32 la, const ut8 *b, ut32 lb);
62 R_API int r_diff_buffers_static(RDiff *d, const ut8 *a, int la, const ut8 *b, int lb);
63 R_API int r_diff_buffers_radiff(RDiff *d, const ut8 *a, int la, const ut8 *b, int lb);
64 R_API int r_diff_buffers_delta(RDiff *diff, const ut8 *sa, int la, const ut8 *sb, int lb);
65 R_API int r_diff_buffers(RDiff *d, const ut8 *a, ut32 la, const ut8 *b, ut32 lb);
66 R_API char *r_diff_buffers_to_string(RDiff *d, const ut8 *a, int la, const ut8 *b, int lb);
67 R_API int r_diff_set_callback(RDiff *d, RDiffCallback callback, void *user);
68 R_API bool r_diff_buffers_distance(RDiff *d, const ut8 *a, ut32 la, const ut8 *b, ut32 lb, ut32 *distance, double *similarity);
69 R_API bool r_diff_buffers_distance_myers(RDiff *diff, const ut8 *a, ut32 la, const ut8 *b, ut32 lb, ut32 *distance, double *similarity);
70 R_API bool r_diff_buffers_distance_levenshtein(RDiff *d, const ut8 *a, ut32 la, const ut8 *b, ut32 lb, ut32 *distance, double *similarity);
71 R_API char *r_diff_buffers_unified(RDiff *d, const ut8 *a, int la, const ut8 *b, int lb);
72 /* static method !??! */
73 R_API int r_diff_lines(const char *file1, const char *sa, int la, const char *file2, const char *sb, int lb);
74 R_API int r_diff_set_delta(RDiff *d, int delta);
75 R_API int r_diff_gdiff(const char *file1, const char *file2, int rad, int va);
76 
77 R_API RDiffChar *r_diffchar_new(const ut8 *a, const ut8 *b);
78 R_API void r_diffchar_print(RDiffChar *diffchar);
79 R_API void r_diffchar_free(RDiffChar *diffchar);
80 #endif
81 
82 #ifdef __cplusplus
83 }
84 #endif
85 
86 #endif
87