daff 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/bin/daff.rb +3 -0
  2. data/lib/daff.rb +95 -0
  3. data/lib/lib/coopy/alignment.rb +409 -0
  4. data/lib/lib/coopy/bag.rb +10 -0
  5. data/lib/lib/coopy/cell_info.rb +29 -0
  6. data/lib/lib/coopy/change.rb +48 -0
  7. data/lib/lib/coopy/change_type.rb +21 -0
  8. data/lib/lib/coopy/compare.rb +98 -0
  9. data/lib/lib/coopy/compare_flags.rb +46 -0
  10. data/lib/lib/coopy/compare_table.rb +402 -0
  11. data/lib/lib/coopy/coopy.rb +414 -0
  12. data/lib/lib/coopy/cross_match.rb +16 -0
  13. data/lib/lib/coopy/csv.rb +181 -0
  14. data/lib/lib/coopy/diff_render.rb +254 -0
  15. data/lib/lib/coopy/highlight_patch.rb +651 -0
  16. data/lib/lib/coopy/highlight_patch_unit.rb +37 -0
  17. data/lib/lib/coopy/index.rb +101 -0
  18. data/lib/lib/coopy/index_item.rb +20 -0
  19. data/lib/lib/coopy/index_pair.rb +87 -0
  20. data/lib/lib/coopy/mover.rb +195 -0
  21. data/lib/lib/coopy/ordering.rb +49 -0
  22. data/lib/lib/coopy/report.rb +23 -0
  23. data/lib/lib/coopy/row.rb +9 -0
  24. data/lib/lib/coopy/simple_cell.rb +23 -0
  25. data/lib/lib/coopy/simple_table.rb +242 -0
  26. data/lib/lib/coopy/simple_view.rb +41 -0
  27. data/lib/lib/coopy/sparse_sheet.rb +50 -0
  28. data/lib/lib/coopy/table.rb +17 -0
  29. data/lib/lib/coopy/table_comparison_state.rb +32 -0
  30. data/lib/lib/coopy/table_diff.rb +738 -0
  31. data/lib/lib/coopy/table_io.rb +33 -0
  32. data/lib/lib/coopy/table_modifier.rb +39 -0
  33. data/lib/lib/coopy/table_text.rb +25 -0
  34. data/lib/lib/coopy/unit.rb +70 -0
  35. data/lib/lib/coopy/view.rb +14 -0
  36. data/lib/lib/coopy/viewed_datum.rb +37 -0
  37. data/lib/lib/coopy/viterbi.rb +172 -0
  38. data/lib/lib/coopy/workspace.rb +22 -0
  39. data/lib/lib/haxe/ds/int_map.rb +14 -0
  40. data/lib/lib/haxe/ds/string_map.rb +14 -0
  41. data/lib/lib/haxe/format/json_parser.rb +264 -0
  42. data/lib/lib/haxe/format/json_printer.rb +239 -0
  43. data/lib/lib/haxe/io/bytes.rb +33 -0
  44. data/lib/lib/haxe/io/eof.rb +17 -0
  45. data/lib/lib/haxe/io/error.rb +21 -0
  46. data/lib/lib/haxe/io/output.rb +40 -0
  47. data/lib/lib/haxe/log.rb +16 -0
  48. data/lib/lib/hx_overrides.rb +18 -0
  49. data/lib/lib/imap.rb +6 -0
  50. data/lib/lib/lambda.rb +36 -0
  51. data/lib/lib/list.rb +42 -0
  52. data/lib/lib/rb/boot.rb +19 -0
  53. data/lib/lib/rb/ruby_iterator.rb +49 -0
  54. data/lib/lib/reflect.rb +29 -0
  55. data/lib/lib/string_buf.rb +14 -0
  56. data/lib/lib/sys.rb +19 -0
  57. data/lib/lib/sys/io/file.rb +19 -0
  58. data/lib/lib/sys/io/file_handle.rb +17 -0
  59. data/lib/lib/sys/io/file_output.rb +35 -0
  60. data/lib/lib/type.rb +32 -0
  61. data/lib/lib/value_type.rb +22 -0
  62. metadata +181 -0
data/bin/daff.rb ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'daff'
3
+ Daff::Coopy.main
data/lib/daff.rb ADDED
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ # Translation requires Ruby >= 1.9.3
5
+ ruby_major, ruby_minor, ruby_patch = RUBY_VERSION.split('.').map{|x| x.to_i}
6
+ if ruby_major<1 || (ruby_major==1 && (ruby_minor<9 || (ruby_minor==9 && ruby_patch<3)))
7
+ $stderr.puts "Your current Ruby version is: #{RUBY_VERSION}. Haxe/Ruby generates code for version 1.9.3 or later."
8
+ Kernel.exit 1
9
+ end
10
+
11
+ require 'date'
12
+ require_relative 'lib/hx_overrides'
13
+ require_relative 'lib/lambda'
14
+ require_relative 'lib/list'
15
+ require_relative 'lib/imap'
16
+ require_relative 'lib/reflect'
17
+ require_relative 'lib/string_buf'
18
+ require_relative 'lib/sys'
19
+ require_relative 'lib/value_type'
20
+ require_relative 'lib/type'
21
+ require_relative 'lib/coopy/alignment'
22
+ require_relative 'lib/coopy/bag'
23
+ require_relative 'lib/coopy/cell_info'
24
+ require_relative 'lib/coopy/change'
25
+ require_relative 'lib/coopy/change_type'
26
+ require_relative 'lib/coopy/compare'
27
+ require_relative 'lib/coopy/compare_flags'
28
+ require_relative 'lib/coopy/compare_table'
29
+ require_relative 'lib/coopy/coopy'
30
+ require_relative 'lib/coopy/cross_match'
31
+ require_relative 'lib/coopy/csv'
32
+ require_relative 'lib/coopy/diff_render'
33
+ require_relative 'lib/coopy/row'
34
+ require_relative 'lib/coopy/highlight_patch'
35
+ require_relative 'lib/coopy/highlight_patch_unit'
36
+ require_relative 'lib/coopy/index'
37
+ require_relative 'lib/coopy/index_item'
38
+ require_relative 'lib/coopy/index_pair'
39
+ require_relative 'lib/coopy/mover'
40
+ require_relative 'lib/coopy/ordering'
41
+ require_relative 'lib/coopy/report'
42
+ require_relative 'lib/coopy/simple_cell'
43
+ require_relative 'lib/coopy/table'
44
+ require_relative 'lib/coopy/simple_table'
45
+ require_relative 'lib/coopy/view'
46
+ require_relative 'lib/coopy/simple_view'
47
+ require_relative 'lib/coopy/sparse_sheet'
48
+ require_relative 'lib/coopy/table_comparison_state'
49
+ require_relative 'lib/coopy/table_diff'
50
+ require_relative 'lib/coopy/table_io'
51
+ require_relative 'lib/coopy/table_modifier'
52
+ require_relative 'lib/coopy/table_text'
53
+ require_relative 'lib/coopy/unit'
54
+ require_relative 'lib/coopy/viewed_datum'
55
+ require_relative 'lib/coopy/viterbi'
56
+ require_relative 'lib/coopy/workspace'
57
+ require_relative 'lib/haxe/log'
58
+ require_relative 'lib/haxe/ds/int_map'
59
+ require_relative 'lib/haxe/ds/string_map'
60
+ require_relative 'lib/haxe/format/json_parser'
61
+ require_relative 'lib/haxe/format/json_printer'
62
+ require_relative 'lib/haxe/io/bytes'
63
+ require_relative 'lib/haxe/io/output'
64
+ require_relative 'lib/haxe/io/eof'
65
+ require_relative 'lib/haxe/io/error'
66
+ require_relative 'lib/rb/boot'
67
+ require_relative 'lib/rb/ruby_iterator'
68
+ require_relative 'lib/sys/io/file_handle'
69
+ require_relative 'lib/sys/io/file'
70
+ require_relative 'lib/sys/io/file_output'
71
+
72
+
73
+ def _hx_ushr(x,ct) (((x<0) ? (x + 0x100000000) : x) >> ct) end
74
+ def _hx_str(x) (x.nil? ? 'null' : x.to_s) end
75
+ def _hx_add(x,y) (((x.is_a? String)||(y.is_a? String)) ? (_hx_str(x)+_hx_str(y)) : (x+y)) end
76
+ def _hx_ord(s) return 0 if s.nil?; s.ord end
77
+ $hx_exception_classes = {}
78
+ def hx_exception_class(c)
79
+ $hx_exception_classes[c.name] ||= Class.new(RuntimeError) do
80
+ Object.const_set((c.name.split(/::/).old_access(-1)||'') + 'HaxeException',self)
81
+ def initialize(target) @target = target; end
82
+ def method_missing(name, *args, &block)
83
+ @target.send(name, *args, &block)
84
+ end
85
+ end
86
+ end
87
+ def hx_exception(x)
88
+ hx_exception_class(x.class).new(x)
89
+ end
90
+
91
+
92
+ Daff = Coopy
93
+ if __FILE__ == $0
94
+ Coopy::Coopy.main
95
+ end
@@ -0,0 +1,409 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ module Coopy
5
+ class Alignment
6
+
7
+ def initialize
8
+ @map_a2b = {}
9
+ @map_b2a = {}
10
+ @ha = @hb = 0
11
+ @map_count = 0
12
+ @reference = nil
13
+ @meta = nil
14
+ @order_cache_has_reference = false
15
+ @ia = 0
16
+ @ib = 0
17
+ end
18
+
19
+ protected
20
+
21
+ attr_accessor :map_a2b
22
+ attr_accessor :map_b2a
23
+ attr_accessor :ha
24
+ attr_accessor :hb
25
+ attr_accessor :ta
26
+ attr_accessor :tb
27
+ attr_accessor :ia
28
+ attr_accessor :ib
29
+ attr_accessor :map_count
30
+ attr_accessor :order_cache
31
+ attr_accessor :order_cache_has_reference
32
+ attr_accessor :index_columns
33
+
34
+ public
35
+
36
+ attr_accessor :reference
37
+ attr_accessor :meta
38
+
39
+ def range(ha,hb)
40
+ @ha = ha
41
+ @hb = hb
42
+ end
43
+
44
+ def tables(ta,tb)
45
+ @ta = ta
46
+ @tb = tb
47
+ end
48
+
49
+ def headers(ia,ib)
50
+ @ia = ia
51
+ @ib = ib
52
+ end
53
+
54
+ def set_rowlike(flag)
55
+ end
56
+
57
+ def link(a,b)
58
+ @map_a2b[a] = b
59
+ @map_b2a[b] = a
60
+ @map_count+=1
61
+ end
62
+
63
+ def add_index_columns(unit)
64
+ @index_columns = Array.new if @index_columns == nil
65
+ @index_columns.push(unit)
66
+ end
67
+
68
+ def get_index_columns
69
+ return @index_columns
70
+ end
71
+
72
+ def a2b(a)
73
+ return @map_a2b[a]
74
+ end
75
+
76
+ def b2a(b)
77
+ return @map_b2a[b]
78
+ end
79
+
80
+ def count
81
+ return @map_count
82
+ end
83
+
84
+ def to_s
85
+ return "" + "not implemented yet"
86
+ end
87
+
88
+ def to_order_pruned(rowlike)
89
+ return self.to_order_cached(true,rowlike)
90
+ end
91
+
92
+ def to_order
93
+ return self.to_order_cached(false,false)
94
+ end
95
+
96
+ def get_source
97
+ return @ta
98
+ end
99
+
100
+ def get_target
101
+ return @tb
102
+ end
103
+
104
+ def get_source_header
105
+ return @ia
106
+ end
107
+
108
+ def get_target_header
109
+ return @ib
110
+ end
111
+
112
+ protected
113
+
114
+ def to_order_cached(prune,rowlike)
115
+ if @order_cache != nil
116
+ if @reference != nil
117
+ @order_cache = nil if !@order_cache_has_reference
118
+ end
119
+ end
120
+ @order_cache = self.to_order3(prune,rowlike) if @order_cache == nil
121
+ @order_cache_has_reference = true if @reference != nil
122
+ return @order_cache
123
+ end
124
+
125
+ def prune_order(o,ref,rowlike)
126
+ tl = ref.tb
127
+ tr = @tb
128
+ if rowlike
129
+ return if tl.get_width != tr.get_width
130
+ elsif tl.get_height != tr.get_height
131
+ return
132
+ end
133
+ units = o.get_list
134
+ left_units = Array.new
135
+ left_locs = Array.new
136
+ right_units = Array.new
137
+ right_locs = Array.new
138
+ eliminate = Array.new
139
+ ct = 0
140
+ begin
141
+ _g1 = 0
142
+ _g = units.length
143
+ while(_g1 < _g)
144
+ i = _g1
145
+ _g1+=1
146
+ unit = units[i]
147
+ if unit.l < 0 && unit.r >= 0
148
+ right_units.push(unit)
149
+ right_locs.push(i)
150
+ ct+=1
151
+ elsif unit.r < 0 && unit.l >= 0
152
+ left_units.push(unit)
153
+ left_locs.push(i)
154
+ ct+=1
155
+ elsif ct > 0
156
+ left_units.slice!(0,left_units.length)
157
+ right_units.slice!(0,right_units.length)
158
+ left_locs.slice!(0,left_locs.length)
159
+ right_locs.slice!(0,right_locs.length)
160
+ ct = 0
161
+ end
162
+ while(left_locs.length > 0 && right_locs.length > 0)
163
+ l = left_units[0].l
164
+ r = right_units[0].r
165
+ view = tl.get_cell_view
166
+ match = true
167
+ if rowlike
168
+ w = tl.get_width
169
+ begin
170
+ _g2 = 0
171
+ while(_g2 < w)
172
+ j = _g2
173
+ _g2+=1
174
+ if !view.equals(tl.get_cell(j,l),tr.get_cell(j,r))
175
+ match = false
176
+ break
177
+ end
178
+ end
179
+ end
180
+ else
181
+ h = tl.get_height
182
+ begin
183
+ _g21 = 0
184
+ while(_g21 < h)
185
+ j1 = _g21
186
+ _g21+=1
187
+ if !view.equals(tl.get_cell(l,j1),tr.get_cell(r,j1))
188
+ match = false
189
+ break
190
+ end
191
+ end
192
+ end
193
+ end
194
+ if match
195
+ eliminate.push(left_locs[0])
196
+ eliminate.push(right_locs[0])
197
+ end
198
+ left_units.shift
199
+ right_units.shift
200
+ left_locs.shift
201
+ right_locs.shift
202
+ ct -= 2
203
+ end
204
+ end
205
+ end
206
+ if eliminate.length > 0
207
+ eliminate.sort {|a,b|
208
+ return a - b
209
+ }
210
+ del = 0
211
+ begin
212
+ _g3 = 0
213
+ while(_g3 < eliminate.length)
214
+ e = eliminate[_g3]
215
+ _g3+=1
216
+ begin
217
+ _this = o.get_list
218
+ _this.slice!(e - del,1)
219
+ end
220
+ del+=1
221
+ end
222
+ end
223
+ end
224
+ end
225
+
226
+ def to_order3(prune,rowlike)
227
+ ref = @reference
228
+ if ref == nil
229
+ ref = ::Coopy::Alignment.new
230
+ ref.range(@ha,@ha)
231
+ ref.tables(@ta,@ta)
232
+ begin
233
+ _g1 = 0
234
+ _g = @ha
235
+ while(_g1 < _g)
236
+ i = _g1
237
+ _g1+=1
238
+ ref.link(i,i)
239
+ end
240
+ end
241
+ end
242
+ order = ::Coopy::Ordering.new
243
+ order.ignore_parent if @reference == nil
244
+ xp = 0
245
+ xl = 0
246
+ xr = 0
247
+ hp = @ha
248
+ hl = ref.hb
249
+ hr = @hb
250
+ vp = {}
251
+ vl = {}
252
+ vr = {}
253
+ begin
254
+ _g2 = 0
255
+ while(_g2 < hp)
256
+ i1 = _g2
257
+ _g2+=1
258
+ vp[i1] = i1
259
+ end
260
+ end
261
+ begin
262
+ _g3 = 0
263
+ while(_g3 < hl)
264
+ i2 = _g3
265
+ _g3+=1
266
+ vl[i2] = i2
267
+ end
268
+ end
269
+ begin
270
+ _g4 = 0
271
+ while(_g4 < hr)
272
+ i3 = _g4
273
+ _g4+=1
274
+ vr[i3] = i3
275
+ end
276
+ end
277
+ ct_vp = hp
278
+ ct_vl = hl
279
+ ct_vr = hr
280
+ prev = -1
281
+ ct = 0
282
+ max_ct = (hp + hl + hr) * 10
283
+ while(ct_vp > 0 || ct_vl > 0 || ct_vr > 0)
284
+ ct+=1
285
+ if ct > max_ct
286
+ ::Haxe::Log._trace.call("Ordering took too long, something went wrong",{ file_name: "Alignment.hx", line_number: 241, class_name: "coopy.Alignment", method_name: "toOrder3"})
287
+ break
288
+ end
289
+ xp = 0 if xp >= hp
290
+ xl = 0 if xl >= hl
291
+ xr = 0 if xr >= hr
292
+ if xp < hp && ct_vp > 0
293
+ if self.a2b(xp) == nil && ref.a2b(xp) == nil
294
+ if vp.include?(xp)
295
+ order.add(-1,-1,xp)
296
+ prev = xp
297
+ vp.delete(xp)
298
+ ct_vp-=1
299
+ end
300
+ xp+=1
301
+ next
302
+ end
303
+ end
304
+ zl = nil
305
+ zr = nil
306
+ if xl < hl && ct_vl > 0
307
+ zl = ref.b2a(xl)
308
+ if zl == nil
309
+ if vl.include?(xl)
310
+ order.add(xl,-1,-1)
311
+ vl.delete(xl)
312
+ ct_vl-=1
313
+ end
314
+ xl+=1
315
+ next
316
+ end
317
+ end
318
+ if xr < hr && ct_vr > 0
319
+ zr = self.b2a(xr)
320
+ if zr == nil
321
+ if vr.include?(xr)
322
+ order.add(-1,xr,-1)
323
+ vr.delete(xr)
324
+ ct_vr-=1
325
+ end
326
+ xr+=1
327
+ next
328
+ end
329
+ end
330
+ if zl != nil
331
+ if self.a2b(zl) == nil
332
+ if vl.include?(xl)
333
+ order.add(xl,-1,zl)
334
+ prev = zl
335
+ vp.delete(zl)
336
+ ct_vp-=1
337
+ vl.delete(xl)
338
+ ct_vl-=1
339
+ xp = zl + 1
340
+ end
341
+ xl+=1
342
+ next
343
+ end
344
+ end
345
+ if zr != nil
346
+ if ref.a2b(zr) == nil
347
+ if vr.include?(xr)
348
+ order.add(-1,xr,zr)
349
+ prev = zr
350
+ vp.delete(zr)
351
+ ct_vp-=1
352
+ vr.delete(xr)
353
+ ct_vr-=1
354
+ xp = zr + 1
355
+ end
356
+ xr+=1
357
+ next
358
+ end
359
+ end
360
+ if zl != nil && zr != nil && self.a2b(zl) != nil && ref.a2b(zr) != nil
361
+ if zl == prev + 1 || zr != prev + 1
362
+ if vr.include?(xr)
363
+ order.add(ref.a2b(zr),xr,zr)
364
+ prev = zr
365
+ vp.delete(zr)
366
+ ct_vp-=1
367
+ begin
368
+ key = ref.a2b(zr)
369
+ vl.delete(key)
370
+ end
371
+ ct_vl-=1
372
+ vr.delete(xr)
373
+ ct_vr-=1
374
+ xp = zr + 1
375
+ xl = ref.a2b(zr) + 1
376
+ end
377
+ xr+=1
378
+ next
379
+ else
380
+ if vl.include?(xl)
381
+ order.add(xl,self.a2b(zl),zl)
382
+ prev = zl
383
+ vp.delete(zl)
384
+ ct_vp-=1
385
+ vl.delete(xl)
386
+ ct_vl-=1
387
+ begin
388
+ key1 = self.a2b(zl)
389
+ vr.delete(key1)
390
+ end
391
+ ct_vr-=1
392
+ xp = zl + 1
393
+ xr = self.a2b(zl) + 1
394
+ end
395
+ xl+=1
396
+ next
397
+ end
398
+ end
399
+ xp+=1
400
+ xl+=1
401
+ xr+=1
402
+ end
403
+ self.prune_order(order,ref,rowlike) if prune
404
+ return order
405
+ end
406
+
407
+ end
408
+
409
+ end