1
2 REBOL []
3
4
5 do-by-type: func [
6 value
7 actions [block!]
8 /default
9 def-action [block!]
10 /local action
11 ][
12 either action: select actions type?/word value [
13 ;print mold action
14 do bind/copy action 'value
15 ][
16 if default [do bind/copy def-action 'value]
17 ]
18 ]
19
20 to-binary-ex: func [value] [
21 do-by-type value [
22 binary! [value]
23 string! [to-binary value]
24 file! [read/binary value]
25 ]
26 ]
27
28 xor-diff: func [
29 a [binary! string! file!]
30 b [binary! string! file!]
31 /local bin-a bin-b
32 ][
33 bin-a: to-binary-ex a
34 bin-b: to-binary-ex b
35 bin-a xor bin-b
36 ]
37
38 make-patch: func [
39 a [binary! string! file!]
40 b [binary! string! file!]
41 ][
42 compress xor-diff a b
43 ]
44
45 apply-patch: func [
46 data [binary! string! file!]
47 patch [binary! string!]
48 /local result
49 ][
50 result: xor-diff data decompress patch
51 ; If they gave us a string as the source, return a string.
52 ;?? If they give us a file, should we write back out to it?
53 either string? data [to-string result][result]
54 ]
55
56
57 a: "Now is the time for all good men to come to the aid of their country..."
58 b: {Now is the time for all good men to come to the aid of their country...
59 whether 'tis nolber to suffer the slings and arrows...}
60 ;d1: xor-diff a b
61 p1: make-patch a b
62 bp: apply-patch a p1
63
64
65
66 change-dir %./test-files
67
68 files: sort read %.
69 print mold files
70 print [files/1 files/2]
71 fp-1-2: make-patch files/1 files/2
72 fp-2-3: make-patch files/2 files/3
73 fp-3-4: make-patch files/3 files/4
74 fp-a-b: make-patch files/5 files/6
75
76 pp-a-b: apply-patch files/5 fp-a-b
77
78 change-dir %..
79
80
81 halt
82
83