| 3 | | char *diff( char *old_file, char *new_file, usize_t *diff_size) |
|---|
| 4 | | { |
|---|
| 5 | | int size=strlen(old_file); |
|---|
| 6 | | usize_t avail_output = (size > XD3_ALLOCSIZE ) ? size : XD3_ALLOCSIZE; |
|---|
| 7 | | uint8_t *output_buffer = malloc(avail_output); |
|---|
| 8 | | usize_t output_size; |
|---|
| | 6 | int main(int argc, char **argv){ |
|---|
| | 7 | char *string1=strdup("Most folks are about as happy as they make up their minds to be."); |
|---|
| | 8 | char *string2=strdup("The secret of happiness is to make others believe they are the cause of it."); |
|---|
| | 9 | |
|---|
| | 10 | int string1_len=strlen(string1); |
|---|
| | 11 | int string2_len=strlen(string2); |
|---|
| 21 | | return output_buffer; |
|---|
| | 19 | xd3_encode_memory(string1, string1_len, |
|---|
| | 20 | string2, string2_len, |
|---|
| | 21 | diff, &diff_len, XD3_ALLOCSIZE, |
|---|
| | 22 | 0); |
|---|
| | 23 | |
|---|
| | 24 | char *output=malloc(XD3_ALLOCSIZE); |
|---|
| | 25 | int output_len; |
|---|
| | 26 | |
|---|
| | 27 | printf("Diff( String1 -> String2 ): %s(%i)\n",diff,diff_len); |
|---|
| | 28 | |
|---|
| | 29 | xd3_decode_memory(diff, diff_len, |
|---|
| | 30 | string2, string2_len, |
|---|
| | 31 | output, &output_len, XD3_ALLOCSIZE, |
|---|
| | 32 | 0); |
|---|
| | 33 | |
|---|
| | 34 | printf("Output( Diff -> String2): %s(%i)\n",output,output_len); |
|---|
| | 35 | |
|---|
| | 36 | |
|---|
| | 37 | free(string1); |
|---|
| | 38 | free(string2); |
|---|
| | 39 | free(diff); |
|---|
| | 40 | free(output); |
|---|
| | 41 | return 0; |
|---|
| 23 | | |
|---|
| 24 | | char *patch( char *old_file, char *diff, usize_t *new_size) |
|---|
| 25 | | { |
|---|
| 26 | | int size=strlen(old_file); |
|---|
| 27 | | usize_t avail_output = (size > XD3_ALLOCSIZE ) ? size : XD3_ALLOCSIZE; |
|---|
| 28 | | uint8_t *output_buffer = malloc(avail_output); |
|---|
| 29 | | usize_t output_size; |
|---|
| 30 | | |
|---|
| 31 | | xd3_decode_memory(old_file, |
|---|
| 32 | | strlen(old_file), |
|---|
| 33 | | diff, |
|---|
| 34 | | strlen(diff), |
|---|
| 35 | | output_buffer, |
|---|
| 36 | | &output_size, |
|---|
| 37 | | avail_output, |
|---|
| 38 | | 0); |
|---|
| 39 | | |
|---|
| 40 | | new_size = output_size; |
|---|
| 41 | | |
|---|
| 42 | | return output_buffer; |
|---|
| 43 | | } |
|---|
| 44 | | |
|---|
| 45 | | int main(int argc, char *argv[]) |
|---|
| 46 | | { |
|---|
| 47 | | if (argc < 3) |
|---|
| 48 | | { |
|---|
| 49 | | printf("error\n"); |
|---|
| 50 | | return -1; |
|---|
| 51 | | } |
|---|
| 52 | | else |
|---|
| 53 | | { |
|---|
| 54 | | usize_t *diff_size; |
|---|
| 55 | | uint8_t *diff_out = malloc(1000); |
|---|
| 56 | | diff_out = diff(argv[1] , argv[2], &diff_size); |
|---|
| 57 | | printf("%s\n",diff_out); |
|---|
| 58 | | printf("%s\n",patch(argv[2], diff_out, diff_size)); |
|---|
| 59 | | } |
|---|
| 60 | | } |
|---|