1 /*
2  *  LibXDiff by Davide Libenzi ( File Differential Library )
3  *  Copyright (C) 2003  Davide Libenzi
4  *
5  *  This library is free software; you can redistribute it and/or
6  *  modify it under the terms of the GNU Lesser General Public
7  *  License as published by the Free Software Foundation; either
8  *  version 2.1 of the License, or (at your option) any later version.
9  *
10  *  This library is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *  Lesser General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Lesser General Public
16  *  License along with this library; if not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  *  Davide Libenzi <davidel@xmailserver.org>
20  *
21  */
22 
23 #if !defined(XDIFF_H)
24 #define XDIFF_H
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif /* #ifdef __cplusplus */
29 
30 /* xpparm_t.flags */
31 #define XDF_NEED_MINIMAL (1 << 0)
32 
33 #define XDF_IGNORE_WHITESPACE (1 << 1)
34 #define XDF_IGNORE_WHITESPACE_CHANGE (1 << 2)
35 #define XDF_IGNORE_WHITESPACE_AT_EOL (1 << 3)
36 #define XDF_IGNORE_CR_AT_EOL (1 << 4)
37 #define XDF_WHITESPACE_FLAGS (XDF_IGNORE_WHITESPACE | \
38 			      XDF_IGNORE_WHITESPACE_CHANGE | \
39 			      XDF_IGNORE_WHITESPACE_AT_EOL | \
40 			      XDF_IGNORE_CR_AT_EOL)
41 
42 #define XDF_IGNORE_BLANK_LINES (1 << 7)
43 
44 #define XDF_PATIENCE_DIFF (1 << 14)
45 #define XDF_HISTOGRAM_DIFF (1 << 15)
46 #define XDF_DIFF_ALGORITHM_MASK (XDF_PATIENCE_DIFF | XDF_HISTOGRAM_DIFF)
47 #define XDF_DIFF_ALG(x) ((x) & XDF_DIFF_ALGORITHM_MASK)
48 
49 #define XDF_INDENT_HEURISTIC (1 << 23)
50 
51 /* xdemitconf_t.flags */
52 #define XDL_EMIT_FUNCNAMES (1 << 0)
53 #define XDL_EMIT_FUNCCONTEXT (1 << 2)
54 
55 #define XDL_MMB_READONLY (1 << 0)
56 
57 #define XDL_MMF_ATOMIC (1 << 0)
58 
59 #define XDL_BDOP_INS 1
60 #define XDL_BDOP_CPY 2
61 #define XDL_BDOP_INSB 3
62 
63 /* merge simplification levels */
64 #define XDL_MERGE_MINIMAL 0
65 #define XDL_MERGE_EAGER 1
66 #define XDL_MERGE_ZEALOUS 2
67 #define XDL_MERGE_ZEALOUS_ALNUM 3
68 
69 /* merge favor modes */
70 #define XDL_MERGE_FAVOR_OURS 1
71 #define XDL_MERGE_FAVOR_THEIRS 2
72 #define XDL_MERGE_FAVOR_UNION 3
73 
74 /* merge output styles */
75 #define XDL_MERGE_DIFF3 1
76 
77 typedef struct s_mmfile {
78 	char *ptr;
79 	size_t size;
80 } mmfile_t;
81 
82 typedef struct s_mmbuffer {
83 	char *ptr;
84 	size_t size;
85 } mmbuffer_t;
86 
87 typedef struct s_xpparam {
88 	unsigned long flags;
89 
90 	/* See Documentation/diff-options.txt. */
91 	char **anchors;
92 	size_t anchors_nr;
93 } xpparam_t;
94 
95 typedef struct s_xdemitcb {
96 	void *priv;
97 	int (*outf)(void *, mmbuffer_t *, int);
98 } xdemitcb_t;
99 
100 typedef long (*find_func_t)(const char *line, long line_len, char *buffer, long buffer_size, void *priv);
101 
102 typedef int (*xdl_emit_hunk_consume_func_t)(long start_a, long count_a,
103 					    long start_b, long count_b,
104 					    void *cb_data);
105 
106 typedef struct s_xdemitconf {
107 	long ctxlen;
108 	long interhunkctxlen;
109 	unsigned long flags;
110 	find_func_t find_func;
111 	void *find_func_priv;
112 	xdl_emit_hunk_consume_func_t hunk_func;
113 } xdemitconf_t;
114 
115 typedef struct s_bdiffparam {
116 	long bsize;
117 } bdiffparam_t;
118 
119 
120 #define xdl_malloc(x) git__malloc(x)
121 #define xdl_free(ptr) git__free(ptr)
122 #define xdl_realloc(ptr,x) git__realloc(ptr,x)
123 
124 void *xdl_mmfile_first(mmfile_t *mmf, long *size);
125 long xdl_mmfile_size(mmfile_t *mmf);
126 
127 int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
128 	     xdemitconf_t const *xecfg, xdemitcb_t *ecb);
129 
130 typedef struct s_xmparam {
131 	xpparam_t xpp;
132 	int marker_size;
133 	int level;
134 	int favor;
135 	int style;
136 	const char *ancestor;	/* label for orig */
137 	const char *file1;	/* label for mf1 */
138 	const char *file2;	/* label for mf2 */
139 } xmparam_t;
140 
141 #define DEFAULT_CONFLICT_MARKER_SIZE 7
142 
143 int xdl_merge(mmfile_t *orig, mmfile_t *mf1, mmfile_t *mf2,
144 		xmparam_t const *xmp, mmbuffer_t *result);
145 
146 #ifdef __cplusplus
147 }
148 #endif /* #ifdef __cplusplus */
149 
150 #endif /* #if !defined(XDIFF_H) */
151