| 1 |
|
| /* vim: set ts=4 et sw=4: */ |
| 2 |
|
| #include <EXTERN.h> |
| 3 |
|
| #include <perl.h> |
| 4 |
|
| #include <XSUB.h> |
| 5 |
|
| |
| 6 |
|
| #include <string.h> |
| 7 |
|
| #include <strings.h> |
| 8 |
|
| #include <stdlib.h> |
| 9 |
|
| #include <ctype.h> |
| 10 |
|
| #include "xdiff.h" |
| 11 |
|
| |
| 12 |
|
| /* This value taken from libxdiff-0.23/test/xtestutils.c */ |
| 13 |
|
| #define MMF_STD_BLKSIZE (1024 * 8) |
| 14 |
|
| |
| 15 |
67 |
| static void *std_malloc(void *priv, unsigned int size) { |
| 16 |
67 |
| return malloc(size); |
| 17 |
|
| } |
| 18 |
|
| |
| 19 |
65 |
| static void std_free(void *priv, void *ptr) { |
| 20 |
65 |
| free(ptr); |
| 21 |
65 |
| } |
| 22 |
|
| |
| 23 |
0 |
| static void *std_realloc(void *priv, void *ptr, unsigned int size) { |
| 24 |
0 |
| return realloc(ptr, size); |
| 25 |
|
| } |
| 26 |
|
| |
| 27 |
0 |
| static int _file_outf(void *priv, mmbuffer_t *mb, int nbuf) { |
| 28 |
|
| int i; |
| 29 |
0 |
▶ | for (i = 0; i < nbuf; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < nbuf; i++) |
0 |
0 |
0 |
|
| 30 |
0 |
▶ | if (!fwrite(mb[i].ptr, mb[i].size, 1, (FILE *) priv)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!fwrite(mb[i].ptr, mb[i].size, 1, (FILE *) priv)) |
0 |
0 |
0 |
|
| 31 |
0 |
| return -1; |
| 32 |
0 |
| return 0; |
| 33 |
|
| } |
| 34 |
|
| |
| 35 |
17 |
| static int _mmfile_outf(void *priv, mmbuffer_t *mb, int nbuf) { |
| 36 |
17 |
| mmfile_t *mmf = priv; |
| 37 |
17 |
▶ | if (xdl_writem_mmfile(mmf, mb, nbuf) < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (xdl_writem_mmfile(mmf, mb, nbuf) < 0) { |
0 |
17 |
17 |
|
| 38 |
0 |
| return -1; |
| 39 |
|
| } |
| 40 |
17 |
| return 0; |
| 41 |
|
| } |
| 42 |
|
| |
| 43 |
|
| memallocator_t memallocator = { malloc, 0 }; /* Paranoid... */ |
| 44 |
|
| |
| 45 |
18 |
| static void initialize_allocator(void) { |
| 46 |
18 |
▶ | if (! memallocator.malloc) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (! memallocator.malloc) { |
2 |
16 |
18 |
|
| 47 |
2 |
| memallocator.priv = NULL; |
| 48 |
2 |
| memallocator.malloc = std_malloc; |
| 49 |
2 |
| memallocator.free = std_free; |
| 50 |
2 |
| memallocator.realloc = std_realloc; |
| 51 |
2 |
| xdl_set_allocator(&memallocator); |
| 52 |
|
| } |
| 53 |
18 |
| } |
| 54 |
|
| |
| 55 |
|
| #define CONTEXT_string_result(_INDEX_) (context->string_result[_INDEX_]) |
| 56 |
|
| #define CONTEXT_string_result_length(_INDEX_) (context->string_result_length[_INDEX_]) |
| 57 |
|
| #define CONTEXT_mmf(_INDEX_) (context->mmf[_INDEX_]) |
| 58 |
|
| #define CONTEXT_mmf_result(_INDEX_) (context->mmf_result[_INDEX_]) |
| 59 |
|
| #define CONTEXT_add_error(_ERROR_) context->error[++context->error_counter - 1] = _ERROR_; |
| 60 |
|
| |
| 61 |
|
| #define CONTEXT_error_size 3 |
| 62 |
|
| #define CONTEXT_string_result_size 2 |
| 63 |
|
| #define CONTEXT_mmf_size 3 |
| 64 |
|
| #define CONTEXT_mmf_result_size 2 |
| 65 |
|
| |
| 66 |
|
| typedef struct { |
| 67 |
|
| char *string_result[CONTEXT_string_result_size]; |
| 68 |
|
| int string_result_length[CONTEXT_string_result_size]; |
| 69 |
|
| mmfile_t mmf[CONTEXT_mmf_size]; |
| 70 |
|
| mmfile_t mmf_result[2]; |
| 71 |
|
| const char *error[CONTEXT_error_size]; |
| 72 |
|
| int error_counter; |
| 73 |
|
| } context_t; |
| 74 |
|
| context_t result; |
| 75 |
|
| |
| 76 |
6 |
| static int CONTEXT_mmf_result_2_string_result( context_t* context, int index ) { |
| 77 |
|
| |
| 78 |
6 |
| mmfile_t *mmf_r1 = &CONTEXT_mmf_result(index); |
| 79 |
6 |
| int size = xdl_mmfile_size( mmf_r1 ); |
| 80 |
6 |
| int wrote = 0; |
| 81 |
6 |
| char *string_result = CONTEXT_string_result(index) = malloc( sizeof(char) * (size + 1) ); |
| 82 |
|
| |
| 83 |
6 |
| xdl_seek_mmfile( mmf_r1, 0); |
| 84 |
6 |
▶ | if ( (wrote = xdl_read_mmfile( mmf_r1, string_result, size )) < size ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( (wrote = xdl_read_mmfile( mmf_r1, string_result, size )) < size ) { |
0 |
6 |
6 |
|
| 85 |
0 |
| return size - wrote; |
| 86 |
|
| } |
| 87 |
6 |
| string_result[size] = 0; |
| 88 |
6 |
| CONTEXT_string_result_length(index) = size; |
| 89 |
6 |
| return 0; |
| 90 |
|
| } |
| 91 |
|
| |
| 92 |
2 |
| static int CONTEXT_mmf_result_2_binary_result( context_t* context, int index ) { |
| 93 |
|
| |
| 94 |
2 |
| mmfile_t *mmf_r1 = &CONTEXT_mmf_result(index); |
| 95 |
2 |
| int size = xdl_mmfile_size( mmf_r1 ); |
| 96 |
2 |
| int wrote = 0; |
| 97 |
2 |
| char *string_result = CONTEXT_string_result(index) = malloc( sizeof(char) * (size + 1) ); |
| 98 |
|
| |
| 99 |
2 |
| xdl_seek_mmfile( mmf_r1, 0); |
| 100 |
2 |
▶ | if ( (wrote = xdl_read_mmfile( mmf_r1, string_result, size )) < size ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( (wrote = xdl_read_mmfile( mmf_r1, string_result, size )) < size ) { |
0 |
2 |
2 |
|
| 101 |
0 |
| return size - wrote; |
| 102 |
|
| } |
| 103 |
2 |
| CONTEXT_string_result_length( index ) = size; |
| 104 |
2 |
| return 0; |
| 105 |
|
| } |
| 106 |
|
| |
| 107 |
6 |
| static void CONTEXT_cleanup( context_t* context ) { |
| 108 |
|
| int ii; |
| 109 |
|
| |
| 110 |
18 |
▶ | for (ii = 0; ii < CONTEXT_string_result_size; ii++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (ii = 0; ii < CONTEXT_string_result_size; ii++) |
12 |
6 |
18 |
|
| 111 |
12 |
| free( context->string_result[ ii ] ); |
| 112 |
|
| |
| 113 |
24 |
▶ | for (ii = 0; ii < CONTEXT_mmf_size; ii++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (ii = 0; ii < CONTEXT_mmf_size; ii++) |
18 |
6 |
24 |
|
| 114 |
18 |
| xdl_free_mmfile( &( context->mmf[ ii ] ) ); |
| 115 |
|
| |
| 116 |
18 |
▶ | for (ii = 0; ii < CONTEXT_mmf_result_size; ii++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (ii = 0; ii < CONTEXT_mmf_result_size; ii++) |
12 |
6 |
18 |
|
| 117 |
12 |
| xdl_free_mmfile( &( context->mmf_result[ ii ] ) ); |
| 118 |
6 |
| } |
| 119 |
|
| |
| 120 |
4 |
| static const char* _binary_2_mmfile( mmfile_t* mmf, const char* string, const int length ) { |
| 121 |
|
| |
| 122 |
4 |
| initialize_allocator(); |
| 123 |
4 |
▶ | if ( xdl_init_mmfile( mmf, MMF_STD_BLKSIZE, XDL_MMF_ATOMIC ) < 0 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( xdl_init_mmfile( mmf, MMF_STD_BLKSIZE, XDL_MMF_ATOMIC ) < 0 ) { |
0 |
4 |
4 |
|
| 124 |
0 |
| return "Unable to initialize mmfile"; |
| 125 |
|
| } |
| 126 |
|
| |
| 127 |
4 |
| int wrote = 0; |
| 128 |
4 |
▶ | if ( (wrote = xdl_write_mmfile( mmf, string, length )) < length ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( (wrote = xdl_write_mmfile( mmf, string, length )) < length ) { |
0 |
4 |
4 |
|
| 129 |
0 |
| return "Couldn't write entire string to mmfile"; |
| 130 |
|
| } |
| 131 |
|
| |
| 132 |
4 |
| return 0; |
| 133 |
|
| } |
| 134 |
8 |
| static const char* _string_2_mmfile( mmfile_t* mmf, const char* string ) { |
| 135 |
|
| |
| 136 |
8 |
| initialize_allocator(); |
| 137 |
|
| |
| 138 |
8 |
▶ | if ( xdl_init_mmfile( mmf, MMF_STD_BLKSIZE, XDL_MMF_ATOMIC ) < 0 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( xdl_init_mmfile( mmf, MMF_STD_BLKSIZE, XDL_MMF_ATOMIC ) < 0 ) { |
0 |
8 |
8 |
|
| 139 |
0 |
| return "Unable to initialize mmfile"; |
| 140 |
|
| } |
| 141 |
|
| |
| 142 |
8 |
| int wrote = 0; |
| 143 |
8 |
| int length = strlen(string); |
| 144 |
8 |
▶ | if ( (wrote = xdl_write_mmfile( mmf, string, length )) < length ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( (wrote = xdl_write_mmfile( mmf, string, length )) < length ) { |
0 |
8 |
8 |
|
| 145 |
0 |
| return "Couldn't write entire string to mmfile"; |
| 146 |
|
| } |
| 147 |
|
| |
| 148 |
8 |
| return 0; |
| 149 |
|
| } |
| 150 |
|
| |
| 151 |
2 |
| void __xpatch( context_t *context, const char *string1, const char *string2 ) { |
| 152 |
|
| |
| 153 |
|
| mmfile_t *mmf1, *mmf2, *mmf_r1, *mmf_r2; |
| 154 |
|
| const char *error; |
| 155 |
|
| |
| 156 |
2 |
| mmf1 = &CONTEXT_mmf(0); |
| 157 |
2 |
| mmf2 = &CONTEXT_mmf(1); |
| 158 |
2 |
| mmf_r1 = &CONTEXT_mmf_result(0); |
| 159 |
2 |
| mmf_r2 = &CONTEXT_mmf_result(1); |
| 160 |
|
| |
| 161 |
2 |
| initialize_allocator(); |
| 162 |
|
| |
| 163 |
2 |
▶ | if ( error = _string_2_mmfile( mmf1, string1 ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( error = _string_2_mmfile( mmf1, string1 ) ) { |
0 |
2 |
2 |
|
| 164 |
0 |
| CONTEXT_add_error( error ); |
| 165 |
0 |
| CONTEXT_add_error( "Couldn't load string1 into mmfile" ); |
| 166 |
0 |
| return; |
| 167 |
|
| } |
| 168 |
|
| |
| 169 |
2 |
▶ | if ( error = _string_2_mmfile( mmf2, string2 ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( error = _string_2_mmfile( mmf2, string2 ) ) { |
0 |
2 |
2 |
|
| 170 |
0 |
| CONTEXT_add_error( error ); |
| 171 |
0 |
| CONTEXT_add_error( "Couldn't load string2 into mmfile" ); |
| 172 |
0 |
| return; |
| 173 |
|
| } |
| 174 |
|
| |
| 175 |
|
| { |
| 176 |
|
| xdemitcb_t ecb1, ecb2; |
| 177 |
|
| |
| 178 |
2 |
| ecb1.priv = mmf_r1; |
| 179 |
2 |
| ecb1.outf = _mmfile_outf; |
| 180 |
|
| |
| 181 |
2 |
| ecb2.priv = mmf_r2; |
| 182 |
2 |
| ecb2.outf = _mmfile_outf; |
| 183 |
|
| |
| 184 |
2 |
▶ | if (xdl_init_mmfile( mmf_r1, MMF_STD_BLKSIZE, XDL_MMF_ATOMIC ) < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (xdl_init_mmfile( mmf_r1, MMF_STD_BLKSIZE, XDL_MMF_ATOMIC ) < 0) { |
0 |
2 |
2 |
|
| 185 |
0 |
| CONTEXT_add_error( "Couldn't initialize accumulating mmfile mmf_r1 (xdl_init_atomic)" ); |
| 186 |
0 |
| return; |
| 187 |
|
| } |
| 188 |
|
| |
| 189 |
2 |
▶ | if (xdl_init_mmfile( mmf_r2, MMF_STD_BLKSIZE, XDL_MMF_ATOMIC ) < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (xdl_init_mmfile( mmf_r2, MMF_STD_BLKSIZE, XDL_MMF_ATOMIC ) < 0) { |
0 |
2 |
2 |
|
| 190 |
0 |
| CONTEXT_add_error( "Couldn't initialize accumulating mmfile mmf_r2 (xdl_init_atomic)" ); |
| 191 |
0 |
| return; |
| 192 |
|
| } |
| 193 |
|
| |
| 194 |
2 |
▶ | if (xdl_patch( mmf1, mmf2, XDL_PATCH_NORMAL, &ecb1, &ecb2) < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (xdl_patch( mmf1, mmf2, XDL_PATCH_NORMAL, &ecb1, &ecb2) < 0) { |
0 |
2 |
2 |
|
| 195 |
0 |
| CONTEXT_add_error( "Couldn't perform patch (xdl_patch)" ); |
| 196 |
0 |
| return; |
| 197 |
|
| } |
| 198 |
|
| |
| 199 |
2 |
▶ | if ( CONTEXT_mmf_result_2_string_result( context, 0 ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( CONTEXT_mmf_result_2_string_result( context, 0 ) ) { |
0 |
2 |
2 |
|
| 200 |
0 |
| CONTEXT_add_error( "Wasn't able to read entire mmfile result (mmf_r1) (xdl_read_mmfile)" ); |
| 201 |
0 |
| return; |
| 202 |
|
| } |
| 203 |
|
| |
| 204 |
2 |
▶ | if ( CONTEXT_mmf_result_2_string_result( context, 1 ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( CONTEXT_mmf_result_2_string_result( context, 1 ) ) { |
0 |
2 |
2 |
|
| 205 |
0 |
| CONTEXT_add_error( "Wasn't able to read entire mmfile result (mmf_r2) (xdl_read_mmfile)" ); |
| 206 |
0 |
| return; |
| 207 |
|
| } |
| 208 |
|
| } |
| 209 |
|
| } |
| 210 |
|
| |
| 211 |
1 |
| void __xbpatch( context_t *context, const char *string1, const int len1, const char *string2, const int len2 ) { |
| 212 |
|
| |
| 213 |
|
| mmfile_t *mmf1, *mmf2, *mmf_r1, *mmf_r2; |
| 214 |
|
| const char *error; |
| 215 |
|
| |
| 216 |
1 |
| mmf1 = &CONTEXT_mmf(0); |
| 217 |
1 |
| mmf2 = &CONTEXT_mmf(1); |
| 218 |
1 |
| mmf_r1 = &CONTEXT_mmf_result(0); |
| 219 |
1 |
| mmf_r2 = &CONTEXT_mmf_result(1); |
| 220 |
|
| |
| 221 |
1 |
| initialize_allocator(); |
| 222 |
|
| |
| 223 |
1 |
▶ | if ( error = _binary_2_mmfile( mmf1, string1, len1 ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( error = _binary_2_mmfile( mmf1, string1, len1 ) ) { |
0 |
1 |
1 |
|
| 224 |
0 |
| CONTEXT_add_error( error ); |
| 225 |
0 |
| CONTEXT_add_error( "Couldn't load string1 into mmfile" ); |
| 226 |
0 |
| return; |
| 227 |
|
| } |
| 228 |
|
| |
| 229 |
1 |
▶ | if ( error = _binary_2_mmfile( mmf2, string2, len2 ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( error = _binary_2_mmfile( mmf2, string2, len2 ) ) { |
0 |
1 |
1 |
|
| 230 |
0 |
| CONTEXT_add_error( error ); |
| 231 |
0 |
| CONTEXT_add_error( "Couldn't load string2 into mmfile" ); |
| 232 |
0 |
| return; |
| 233 |
|
| } |
| 234 |
|
| |
| 235 |
|
| /* Compact the files - needed for binary operations */ |
| 236 |
|
| mmfile_t mmf1c; |
| 237 |
1 |
▶ | if (xdl_mmfile_compact( mmf1, &mmf1c,MMF_STD_BLKSIZE, XDL_MMF_ATOMIC) < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (xdl_mmfile_compact( mmf1, &mmf1c,MMF_STD_BLKSIZE, XDL_MMF_ATOMIC) < 0) { |
0 |
1 |
1 |
|
| 238 |
0 |
| CONTEXT_add_error( "mmf1 is not compact - and unable to compact it!"); |
| 239 |
0 |
| return; |
| 240 |
|
| } |
| 241 |
|
| |
| 242 |
|
| mmfile_t mmf2c; |
| 243 |
1 |
▶ | if (xdl_mmfile_compact( mmf2, &mmf2c,MMF_STD_BLKSIZE, XDL_MMF_ATOMIC) < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (xdl_mmfile_compact( mmf2, &mmf2c,MMF_STD_BLKSIZE, XDL_MMF_ATOMIC) < 0) { |
0 |
1 |
1 |
|
| 244 |
0 |
| CONTEXT_add_error( "mmf2 is not compact - and unable to compact it!"); |
| 245 |
0 |
| return; |
| 246 |
|
| } |
| 247 |
|
| |
| 248 |
|
| { |
| 249 |
|
| xdemitcb_t ecb; |
| 250 |
|
| |
| 251 |
1 |
| ecb.priv = mmf_r1; |
| 252 |
1 |
| ecb.outf = _mmfile_outf; |
| 253 |
|
| |
| 254 |
1 |
▶ | if (xdl_init_mmfile( mmf_r1, MMF_STD_BLKSIZE, XDL_MMF_ATOMIC ) < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (xdl_init_mmfile( mmf_r1, MMF_STD_BLKSIZE, XDL_MMF_ATOMIC ) < 0) { |
0 |
1 |
1 |
|
| 255 |
0 |
| CONTEXT_add_error( "Couldn't initialize accumulating mmfile mmf_r1 (xdl_init_atomic)" ); |
| 256 |
0 |
| return; |
| 257 |
|
| } |
| 258 |
|
| |
| 259 |
1 |
▶ | if (xdl_bpatch( mmf1, mmf2, &ecb) < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (xdl_bpatch( mmf1, mmf2, &ecb) < 0) { |
0 |
1 |
1 |
|
| 260 |
0 |
| CONTEXT_add_error( "Couldn't perform patch (xdl_bpatch)" ); |
| 261 |
0 |
| return; |
| 262 |
|
| } |
| 263 |
|
| |
| 264 |
1 |
▶ | if ( CONTEXT_mmf_result_2_binary_result( context, 0 ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( CONTEXT_mmf_result_2_binary_result( context, 0 ) ) { |
0 |
1 |
1 |
|
| 265 |
0 |
| CONTEXT_add_error( "Wasn't able to read entire mmfile result (mmf_r1) (xdl_read_mmfile)" ); |
| 266 |
|
| } |
| 267 |
|
| } |
| 268 |
|
| } |
| 269 |
|
| |
| 270 |
2 |
| void __xdiff( context_t *context, const char *string1, const char *string2 ) { |
| 271 |
|
| |
| 272 |
|
| mmfile_t *mmf1, *mmf2, *mmf_r1; |
| 273 |
|
| const char *error; |
| 274 |
|
| |
| 275 |
2 |
| mmf1 = &CONTEXT_mmf(0); |
| 276 |
2 |
| mmf2 = &CONTEXT_mmf(1); |
| 277 |
2 |
| mmf_r1 = &CONTEXT_mmf_result(0); |
| 278 |
|
| |
| 279 |
2 |
| initialize_allocator(); |
| 280 |
|
| |
| 281 |
2 |
▶ | if ( error = _string_2_mmfile( mmf1, string1 ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( error = _string_2_mmfile( mmf1, string1 ) ) { |
0 |
2 |
2 |
|
| 282 |
0 |
| CONTEXT_add_error( error ); |
| 283 |
0 |
| CONTEXT_add_error( "Couldn't load string1 into mmfile" ); |
| 284 |
0 |
| return; |
| 285 |
|
| } |
| 286 |
|
| |
| 287 |
2 |
▶ | if ( error = _string_2_mmfile( mmf2, string2 ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( error = _string_2_mmfile( mmf2, string2 ) ) { |
0 |
2 |
2 |
|
| 288 |
0 |
| CONTEXT_add_error( error ); |
| 289 |
0 |
| CONTEXT_add_error( "Couldn't load string2 into mmfile" ); |
| 290 |
0 |
| return; |
| 291 |
|
| } |
| 292 |
|
| |
| 293 |
|
| { |
| 294 |
|
| xpparam_t xpp; |
| 295 |
2 |
| xpp.flags = 0; |
| 296 |
|
| |
| 297 |
|
| xdemitconf_t xecfg; |
| 298 |
2 |
| xecfg.ctxlen = 3; |
| 299 |
|
| |
| 300 |
|
| xdemitcb_t ecb; |
| 301 |
2 |
| ecb.priv = mmf_r1; |
| 302 |
2 |
| ecb.outf = _mmfile_outf; |
| 303 |
|
| |
| 304 |
2 |
▶ | if (xdl_init_mmfile( mmf_r1, MMF_STD_BLKSIZE, XDL_MMF_ATOMIC ) < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (xdl_init_mmfile( mmf_r1, MMF_STD_BLKSIZE, XDL_MMF_ATOMIC ) < 0) { |
0 |
2 |
2 |
|
| 305 |
0 |
| CONTEXT_add_error( "Couldn't initialize accumulating mmfile (xdl_init_atomic)" ); |
| 306 |
0 |
| return; |
| 307 |
|
| } |
| 308 |
|
| |
| 309 |
2 |
▶ | if (xdl_diff( mmf1, mmf2, &xpp, &xecfg, &ecb ) < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (xdl_diff( mmf1, mmf2, &xpp, &xecfg, &ecb ) < 0) { |
0 |
2 |
2 |
|
| 310 |
0 |
| CONTEXT_add_error( "Couldn't perform diff (xdl_diff)" ); |
| 311 |
0 |
| return; |
| 312 |
|
| } |
| 313 |
|
| |
| 314 |
2 |
▶ | if ( CONTEXT_mmf_result_2_string_result( context, 0 ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( CONTEXT_mmf_result_2_string_result( context, 0 ) ) { |
0 |
2 |
2 |
|
| 315 |
0 |
| CONTEXT_add_error( "Wasn't able to read entire mmfile result (xdl_read_mmfile)" ); |
| 316 |
|
| } |
| 317 |
|
| } |
| 318 |
|
| } |
| 319 |
|
| |
| 320 |
1 |
| void __xbdiff( context_t *context, const char *string1, const int len1,const char *string2, const int len2 ) { |
| 321 |
|
| |
| 322 |
|
| mmfile_t *mmf1, *mmf2, *mmf_r1; |
| 323 |
|
| const char *error; |
| 324 |
|
| |
| 325 |
1 |
| mmf1 = &CONTEXT_mmf(0); |
| 326 |
1 |
| mmf2 = &CONTEXT_mmf(1); |
| 327 |
1 |
| mmf_r1 = &CONTEXT_mmf_result(0); |
| 328 |
|
| |
| 329 |
1 |
| initialize_allocator(); |
| 330 |
|
| |
| 331 |
1 |
▶ | if ( error = _binary_2_mmfile( mmf1, string1,len1 ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( error = _binary_2_mmfile( mmf1, string1,len1 ) ) { |
0 |
1 |
1 |
|
| 332 |
0 |
| CONTEXT_add_error( error ); |
| 333 |
0 |
| CONTEXT_add_error( "Couldn't load binary1 into mmfile" ); |
| 334 |
0 |
| return; |
| 335 |
|
| } |
| 336 |
|
| |
| 337 |
1 |
▶ | if ( error = _binary_2_mmfile( mmf2, string2, len2 ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( error = _binary_2_mmfile( mmf2, string2, len2 ) ) { |
0 |
1 |
1 |
|
| 338 |
0 |
| CONTEXT_add_error( error ); |
| 339 |
0 |
| CONTEXT_add_error( "Couldn't load binary2 into mmfile" ); |
| 340 |
0 |
| return; |
| 341 |
|
| } |
| 342 |
|
| /* Compact the files - needed for binary operations */ |
| 343 |
|
| mmfile_t mmf1c; |
| 344 |
1 |
▶ | if (xdl_mmfile_compact( mmf1, &mmf1c,MMF_STD_BLKSIZE, XDL_MMF_ATOMIC) < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (xdl_mmfile_compact( mmf1, &mmf1c,MMF_STD_BLKSIZE, XDL_MMF_ATOMIC) < 0) { |
0 |
1 |
1 |
|
| 345 |
0 |
| CONTEXT_add_error( "mmf1 is not compact - and unable to compact it!"); |
| 346 |
0 |
| return; |
| 347 |
|
| } |
| 348 |
|
| |
| 349 |
|
| mmfile_t mmf2c; |
| 350 |
1 |
▶ | if (xdl_mmfile_compact( mmf2, &mmf2c,MMF_STD_BLKSIZE, XDL_MMF_ATOMIC) < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (xdl_mmfile_compact( mmf2, &mmf2c,MMF_STD_BLKSIZE, XDL_MMF_ATOMIC) < 0) { |
0 |
1 |
1 |
|
| 351 |
0 |
| CONTEXT_add_error( "mmf2 is not compact - and unable to compact it!"); |
| 352 |
0 |
| return; |
| 353 |
|
| } |
| 354 |
|
| |
| 355 |
|
| { |
| 356 |
|
| bdiffparam_t bdp; |
| 357 |
1 |
| bdp.bsize=16; |
| 358 |
|
| |
| 359 |
|
| xdemitcb_t ecb; |
| 360 |
1 |
| ecb.priv = mmf_r1; |
| 361 |
1 |
| ecb.outf = _mmfile_outf; |
| 362 |
|
| |
| 363 |
1 |
▶ | if (xdl_init_mmfile( mmf_r1, MMF_STD_BLKSIZE, XDL_MMF_ATOMIC ) < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (xdl_init_mmfile( mmf_r1, MMF_STD_BLKSIZE, XDL_MMF_ATOMIC ) < 0) { |
0 |
1 |
1 |
|
| 364 |
0 |
| CONTEXT_add_error( "Couldn't initialize accumulating mmfile (xdl_init_atomic)" ); |
| 365 |
0 |
| return; |
| 366 |
|
| } |
| 367 |
|
| |
| 368 |
1 |
▶ | if (xdl_bdiff( &mmf1c, &mmf2c, &bdp, &ecb ) < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (xdl_bdiff( &mmf1c, &mmf2c, &bdp, &ecb ) < 0) { |
0 |
1 |
1 |
|
| 369 |
0 |
| CONTEXT_add_error( "Couldn't perform diff (xdl_bdiff)" ); |
| 370 |
0 |
| return; |
| 371 |
|
| } |
| 372 |
1 |
| xdl_free_mmfile(&mmf1c); |
| 373 |
1 |
| xdl_free_mmfile(&mmf2c); |
| 374 |
|
| |
| 375 |
1 |
▶ | if ( CONTEXT_mmf_result_2_binary_result( context, 0 ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( CONTEXT_mmf_result_2_binary_result( context, 0 ) ) { |
0 |
1 |
1 |
|
| 376 |
0 |
| CONTEXT_add_error( "Wasn't able to read entire mmfile result (xdl_read_mmfile)" ); |
| 377 |
|
| } |
| 378 |
|
| } |
| 379 |
|
| } |
| 380 |
|
| |
| 381 |
|
| MODULE = Diff::LibXDiff PACKAGE = Diff::LibXDiff |
| 382 |
|
| |
| 383 |
|
| PROTOTYPES: disable |
| 384 |
|
| |
| 385 |
|
| SV* |
| 386 |
|
| _xdiff(string1, string2) |
| 387 |
|
| SV* string1 |
| 388 |
|
| SV* string2 |
| 389 |
|
| INIT: |
| 390 |
2 |
| context_t context = { 0 }; |
| 391 |
2 |
| RETVAL = &PL_sv_undef; |
| 392 |
|
| CODE: |
| 393 |
2 |
| __xdiff( &context, SvPVX(string1), SvPVX(string2) ); |
| 394 |
2 |
| HV* hash_result = (HV*) sv_2mortal( (SV*) newHV() ); |
| 395 |
2 |
| AV* error_result = (AV*) sv_2mortal( (SV*) newAV() ); |
| 396 |
|
| int ii; |
| 397 |
2 |
▶ | for (ii = 0; ii < context.error_counter; ii++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ii = 0; ii < context.error_counter; ii++) { |
0 |
2 |
2 |
|
| 398 |
0 |
| av_push( error_result, newSVpv( context.error[ii], 0 ) ); |
| 399 |
|
| } |
| 400 |
2 |
| hv_store( hash_result, "result", 6, newSVpv( context.string_result[0], 0 ), 0); |
| 401 |
2 |
| hv_store( hash_result, "error", 5, newRV( (SV*) error_result ), 0); |
| 402 |
2 |
| CONTEXT_cleanup( &context ); |
| 403 |
2 |
| RETVAL = newRV( (SV*) hash_result ); |
| 404 |
|
| OUTPUT: |
| 405 |
|
| RETVAL |
| 406 |
|
| |
| 407 |
|
| SV* |
| 408 |
|
| _xbdiff(string1, string2) |
| 409 |
|
| SV* string1 |
| 410 |
|
| SV* string2 |
| 411 |
|
| INIT: |
| 412 |
1 |
| context_t context = { 0 }; |
| 413 |
1 |
| RETVAL = &PL_sv_undef; |
| 414 |
|
| CODE: |
| 415 |
1 |
| int str1_len=sv_len(string1); |
| 416 |
1 |
| int str2_len=sv_len(string2); |
| 417 |
1 |
| __xbdiff( &context, SvPVX(string1), str1_len, SvPVX(string2), str2_len); |
| 418 |
1 |
| HV* hash_result = (HV*) sv_2mortal( (SV*) newHV() ); |
| 419 |
1 |
| AV* error_result = (AV*) sv_2mortal( (SV*) newAV() ); |
| 420 |
|
| int ii; |
| 421 |
1 |
▶ | for (ii = 0; ii < context.error_counter; ii++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ii = 0; ii < context.error_counter; ii++) { |
0 |
1 |
1 |
|
| 422 |
0 |
| av_push( error_result, newSVpv( context.error[ii], 0 ) ); |
| 423 |
|
| } |
| 424 |
1 |
| hv_store( hash_result, "result", 6, newSVpv( |
| 425 |
|
| context.string_result[0], |
| 426 |
|
| context.string_result_length[0]), |
| 427 |
|
| 0); |
| 428 |
1 |
| hv_store( hash_result, "error", 5, newRV( (SV*) error_result ), 0); |
| 429 |
1 |
| CONTEXT_cleanup( &context ); |
| 430 |
1 |
| RETVAL = newRV( (SV*) hash_result ); |
| 431 |
|
| OUTPUT: |
| 432 |
|
| RETVAL |
| 433 |
|
| |
| 434 |
|
| SV* |
| 435 |
|
| _xpatch(string1, string2) |
| 436 |
|
| SV* string1 |
| 437 |
|
| SV* string2 |
| 438 |
|
| INIT: |
| 439 |
2 |
| context_t context = { 0 }; |
| 440 |
2 |
| RETVAL = &PL_sv_undef; |
| 441 |
|
| CODE: |
| 442 |
2 |
| __xpatch( &context, SvPVX(string1), SvPVX(string2) ); |
| 443 |
2 |
| HV* hash_result = (HV*) sv_2mortal( (SV*) newHV() ); |
| 444 |
2 |
| AV* error_result = (AV*) sv_2mortal( (SV*) newAV() ); |
| 445 |
|
| int ii; |
| 446 |
2 |
▶ | for (ii = 0; ii < context.error_counter; ii++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ii = 0; ii < context.error_counter; ii++) { |
0 |
2 |
2 |
|
| 447 |
0 |
| av_push( error_result, newSVpv( context.error[ii], 0 ) ); |
| 448 |
|
| } |
| 449 |
2 |
| hv_store( hash_result, "result", 6, newSVpv( context.string_result[0], 0 ), 0); |
| 450 |
2 |
| hv_store( hash_result, "rejected_result", 15, newSVpv( context.string_result[1], 0 ), 0); |
| 451 |
2 |
| hv_store( hash_result, "error", 5, newRV( (SV*) error_result ), 0); |
| 452 |
2 |
| CONTEXT_cleanup( &context ); |
| 453 |
2 |
| RETVAL = newRV( (SV*) hash_result ); |
| 454 |
|
| OUTPUT: |
| 455 |
|
| RETVAL |
| 456 |
|
| |
| 457 |
|
| SV* |
| 458 |
|
| _xbpatch(string1, string2) |
| 459 |
|
| SV* string1 |
| 460 |
|
| SV* string2 |
| 461 |
|
| INIT: |
| 462 |
1 |
| context_t context = { 0 }; |
| 463 |
1 |
| RETVAL = &PL_sv_undef; |
| 464 |
|
| CODE: |
| 465 |
1 |
| int str1_len=sv_len(string1); |
| 466 |
1 |
| int str2_len=sv_len(string2); |
| 467 |
1 |
| __xbpatch( &context, SvPVX(string1), str1_len, SvPVX(string2), str2_len); |
| 468 |
1 |
| HV* hash_result = (HV*) sv_2mortal( (SV*) newHV() ); |
| 469 |
1 |
| AV* error_result = (AV*) sv_2mortal( (SV*) newAV() ); |
| 470 |
|
| int ii; |
| 471 |
1 |
▶ | for (ii = 0; ii < context.error_counter; ii++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ii = 0; ii < context.error_counter; ii++) { |
0 |
1 |
1 |
|
| 472 |
0 |
| av_push( error_result, newSVpv( context.error[ii], 0 ) ); |
| 473 |
|
| } |
| 474 |
1 |
| hv_store( hash_result, "result", 6, newSVpv( |
| 475 |
|
| context.string_result[0], |
| 476 |
|
| context.string_result_length[0] ), |
| 477 |
|
| 0); |
| 478 |
1 |
| hv_store( hash_result, "error", 5, newRV( (SV*) error_result ), 0); |
| 479 |
1 |
| CONTEXT_cleanup( &context ); |
| 480 |
1 |
| RETVAL = newRV( (SV*) hash_result ); |
| 481 |
|
| OUTPUT: |
| 482 |
|
| RETVAL |