everypolitician-daff 1.3.26

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +252 -0
  3. data/bin/daff.rb +3 -0
  4. data/lib/daff.rb +150 -0
  5. data/lib/lib/coopy/alignment.rb +307 -0
  6. data/lib/lib/coopy/cell_builder.rb +17 -0
  7. data/lib/lib/coopy/cell_info.rb +33 -0
  8. data/lib/lib/coopy/column_change.rb +16 -0
  9. data/lib/lib/coopy/combined_table.rb +127 -0
  10. data/lib/lib/coopy/combined_table_body.rb +151 -0
  11. data/lib/lib/coopy/combined_table_head.rb +103 -0
  12. data/lib/lib/coopy/compare_flags.rb +127 -0
  13. data/lib/lib/coopy/compare_table.rb +688 -0
  14. data/lib/lib/coopy/conflict_info.rb +23 -0
  15. data/lib/lib/coopy/coopy.rb +1065 -0
  16. data/lib/lib/coopy/cross_match.rb +17 -0
  17. data/lib/lib/coopy/csv.rb +290 -0
  18. data/lib/lib/coopy/diff_render.rb +339 -0
  19. data/lib/lib/coopy/diff_summary.rb +28 -0
  20. data/lib/lib/coopy/flat_cell_builder.rb +75 -0
  21. data/lib/lib/coopy/highlight_patch.rb +977 -0
  22. data/lib/lib/coopy/highlight_patch_unit.rb +38 -0
  23. data/lib/lib/coopy/index.rb +131 -0
  24. data/lib/lib/coopy/index_item.rb +37 -0
  25. data/lib/lib/coopy/index_pair.rb +96 -0
  26. data/lib/lib/coopy/json_table.rb +165 -0
  27. data/lib/lib/coopy/json_tables.rb +129 -0
  28. data/lib/lib/coopy/merger.rb +197 -0
  29. data/lib/lib/coopy/meta.rb +20 -0
  30. data/lib/lib/coopy/mover.rb +197 -0
  31. data/lib/lib/coopy/ndjson.rb +134 -0
  32. data/lib/lib/coopy/nested_cell_builder.rb +74 -0
  33. data/lib/lib/coopy/ordering.rb +54 -0
  34. data/lib/lib/coopy/property_change.rb +16 -0
  35. data/lib/lib/coopy/row.rb +11 -0
  36. data/lib/lib/coopy/row_change.rb +42 -0
  37. data/lib/lib/coopy/row_stream.rb +11 -0
  38. data/lib/lib/coopy/simple_meta.rb +314 -0
  39. data/lib/lib/coopy/simple_table.rb +345 -0
  40. data/lib/lib/coopy/simple_view.rb +70 -0
  41. data/lib/lib/coopy/sparse_sheet.rb +51 -0
  42. data/lib/lib/coopy/sql_column.rb +47 -0
  43. data/lib/lib/coopy/sql_compare.rb +605 -0
  44. data/lib/lib/coopy/sql_database.rb +21 -0
  45. data/lib/lib/coopy/sql_helper.rb +17 -0
  46. data/lib/lib/coopy/sql_table.rb +335 -0
  47. data/lib/lib/coopy/sql_table_name.rb +23 -0
  48. data/lib/lib/coopy/sql_tables.rb +128 -0
  49. data/lib/lib/coopy/sqlite_helper.rb +316 -0
  50. data/lib/lib/coopy/table.rb +24 -0
  51. data/lib/lib/coopy/table_comparison_state.rb +50 -0
  52. data/lib/lib/coopy/table_diff.rb +1185 -0
  53. data/lib/lib/coopy/table_io.rb +72 -0
  54. data/lib/lib/coopy/table_modifier.rb +40 -0
  55. data/lib/lib/coopy/table_stream.rb +102 -0
  56. data/lib/lib/coopy/table_view.rb +148 -0
  57. data/lib/lib/coopy/tables.rb +52 -0
  58. data/lib/lib/coopy/terminal_diff_render.rb +213 -0
  59. data/lib/lib/coopy/unit.rb +93 -0
  60. data/lib/lib/coopy/view.rb +20 -0
  61. data/lib/lib/coopy/viterbi.rb +177 -0
  62. data/lib/lib/haxe/ds/int_map.rb +19 -0
  63. data/lib/lib/haxe/ds/string_map.rb +19 -0
  64. data/lib/lib/haxe/format/json_parser.rb +265 -0
  65. data/lib/lib/haxe/format/json_printer.rb +240 -0
  66. data/lib/lib/haxe/imap.rb +10 -0
  67. data/lib/lib/haxe/io/bytes.rb +34 -0
  68. data/lib/lib/haxe/io/eof.rb +18 -0
  69. data/lib/lib/haxe/io/error.rb +22 -0
  70. data/lib/lib/haxe/io/output.rb +41 -0
  71. data/lib/lib/hx_overrides.rb +19 -0
  72. data/lib/lib/hx_sys.rb +74 -0
  73. data/lib/lib/lambda.rb +37 -0
  74. data/lib/lib/list.rb +36 -0
  75. data/lib/lib/math.rb +5 -0
  76. data/lib/lib/rb/boot.rb +39 -0
  77. data/lib/lib/rb/ruby_iterator.rb +50 -0
  78. data/lib/lib/reflect.rb +41 -0
  79. data/lib/lib/std.rb +12 -0
  80. data/lib/lib/string_buf.rb +19 -0
  81. data/lib/lib/sys/io/file_handle.rb +18 -0
  82. data/lib/lib/sys/io/file_output.rb +36 -0
  83. data/lib/lib/sys/io/hx_file.rb +20 -0
  84. data/lib/lib/type.rb +37 -0
  85. data/lib/lib/value_type.rb +23 -0
  86. data/lib/lib/x_list/list_iterator.rb +32 -0
  87. metadata +235 -0
@@ -0,0 +1,316 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ module Coopy
5
+ class SqliteHelper
6
+
7
+ def initialize
8
+ end
9
+
10
+ def get_table_names(db)
11
+ q = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name"
12
+ return nil if !db._begin(q,nil,["name"])
13
+ names = Array.new
14
+ while(db.read)
15
+ names.push(db.get(0))
16
+ end
17
+ db._end
18
+ names
19
+ end
20
+
21
+ def count_rows(db,name)
22
+ q = "SELECT COUNT(*) AS ct FROM " + _hx_str(db.get_quoted_table_name(name))
23
+ return -1 if !db._begin(q,nil,["ct"])
24
+ ct = -1
25
+ while(db.read)
26
+ ct = db.get(0)
27
+ end
28
+ db._end
29
+ ct
30
+ end
31
+
32
+ def get_row_ids(db,name)
33
+ result = Array.new
34
+ q = "SELECT ROWID AS r FROM " + _hx_str(db.get_quoted_table_name(name)) + " ORDER BY ROWID"
35
+ return nil if !db._begin(q,nil,["r"])
36
+ while(db.read)
37
+ c = db.get(0)
38
+ result.push(c)
39
+ end
40
+ db._end
41
+ result
42
+ end
43
+
44
+ def update(db,name,conds,vals)
45
+ q = "UPDATE " + _hx_str(db.get_quoted_table_name(name)) + " SET "
46
+ lst = Array.new
47
+ _it = ::Rb::RubyIterator.new(vals.keys)
48
+ while(_it.has_next) do
49
+ k = _it._next
50
+ q += ", " if lst.length > 0
51
+ q += db.get_quoted_column_name(k)
52
+ q += " = ?"
53
+ lst.push(vals[k])
54
+ end
55
+ val_len = lst.length
56
+ q += " WHERE "
57
+ _it2 = ::Rb::RubyIterator.new(conds.keys)
58
+ while(_it2.has_next) do
59
+ k1 = _it2._next
60
+ q += " and " if lst.length > val_len
61
+ q += db.get_quoted_column_name(k1)
62
+ q += " IS ?"
63
+ lst.push(conds[k1])
64
+ end
65
+ if !db._begin(q,lst,[])
66
+ puts "Problem with database update"
67
+ return false
68
+ end
69
+ db._end
70
+ true
71
+ end
72
+
73
+ def _delete(db,name,conds)
74
+ q = "DELETE FROM " + _hx_str(db.get_quoted_table_name(name)) + " WHERE "
75
+ lst = Array.new
76
+ _it = ::Rb::RubyIterator.new(conds.keys)
77
+ while(_it.has_next) do
78
+ k = _it._next
79
+ q += " and " if lst.length > 0
80
+ q += db.get_quoted_column_name(k)
81
+ q += " = ?"
82
+ lst.push(conds[k])
83
+ end
84
+ if !db._begin(q,lst,[])
85
+ puts "Problem with database delete"
86
+ return false
87
+ end
88
+ db._end
89
+ true
90
+ end
91
+
92
+ def insert(db,name,vals)
93
+ q = "INSERT INTO " + _hx_str(db.get_quoted_table_name(name)) + " ("
94
+ lst = Array.new
95
+ _it = ::Rb::RubyIterator.new(vals.keys)
96
+ while(_it.has_next) do
97
+ k = _it._next
98
+ q += "," if lst.length > 0
99
+ q += db.get_quoted_column_name(k)
100
+ lst.push(vals[k])
101
+ end
102
+ q += ") VALUES("
103
+ need_comma = false
104
+ _it2 = ::Rb::RubyIterator.new(vals.keys)
105
+ while(_it2.has_next) do
106
+ k1 = _it2._next
107
+ q += "," if need_comma
108
+ q += "?"
109
+ need_comma = true
110
+ end
111
+ q += ")"
112
+ if !db._begin(q,lst,[])
113
+ puts "Problem with database insert"
114
+ return false
115
+ end
116
+ db._end
117
+ true
118
+ end
119
+
120
+ def attach(db,tag,resource_name)
121
+ tag_present = false
122
+ tag_correct = false
123
+ result = Array.new
124
+ q = "PRAGMA database_list"
125
+ return false if !db._begin(q,nil,["seq","name","file"])
126
+ while(db.read)
127
+ name = db.get(1)
128
+ if name == tag
129
+ tag_present = true
130
+ file = db.get(2)
131
+ tag_correct = true if file == resource_name
132
+ end
133
+ end
134
+ db._end
135
+ if tag_present
136
+ return true if tag_correct
137
+ if !db._begin("DETACH `" + _hx_str(tag) + "`",nil,[])
138
+ puts "Failed to detach " + _hx_str(tag)
139
+ return false
140
+ end
141
+ db._end
142
+ end
143
+ if !db._begin("ATTACH ? AS `" + _hx_str(tag) + "`",[resource_name],[])
144
+ puts "Failed to attach " + _hx_str(resource_name) + " as " + _hx_str(tag)
145
+ return false
146
+ end
147
+ db._end
148
+ true
149
+ end
150
+
151
+ protected
152
+
153
+ def column_list_sql(x)
154
+ x.join(",")
155
+ end
156
+
157
+ def fetch_schema(db,name)
158
+ tname = db.get_quoted_table_name(name)
159
+ query = "select sql from sqlite_master where name = '" + _hx_str(tname) + "'"
160
+ if !db._begin(query,nil,["sql"])
161
+ puts "Cannot find schema for table " + _hx_str(tname)
162
+ return nil
163
+ end
164
+ sql = ""
165
+ sql = db.get(0) if db.read
166
+ db._end
167
+ sql
168
+ end
169
+
170
+ def split_schema(db,name,sql)
171
+ preamble = ""
172
+ parts = Array.new
173
+ double_quote = false
174
+ single_quote = false
175
+ token = ""
176
+ nesting = 0
177
+ begin
178
+ _g1 = 0
179
+ _g = sql.length
180
+ while(_g1 < _g)
181
+ i = _g1
182
+ _g1+=1
183
+ ch = sql[i]
184
+ if double_quote || single_quote
185
+ if double_quote
186
+ double_quote = false if ch == "\""
187
+ end
188
+ if single_quote
189
+ single_quote = false if ch == "'"
190
+ end
191
+ token += ch
192
+ next
193
+ end
194
+ brk = false
195
+ if ch == "("
196
+ nesting+=1
197
+ brk = true if nesting == 1
198
+ elsif ch == ")"
199
+ nesting-=1
200
+ brk = true if nesting == 0
201
+ end
202
+ if ch == ","
203
+ brk = true
204
+ if nesting == 1
205
+ end
206
+ end
207
+ if brk
208
+ token = token[1,token.length] if token[0] == " "
209
+ if preamble == ""
210
+ preamble = token
211
+ else
212
+ parts.push(token)
213
+ end
214
+ token = ""
215
+ else
216
+ token += ch
217
+ end
218
+ end
219
+ end
220
+ cols = db.get_columns(name)
221
+ name2part = {}
222
+ name2col = {}
223
+ begin
224
+ _g11 = 0
225
+ _g2 = cols.length
226
+ while(_g11 < _g2)
227
+ i1 = _g11
228
+ _g11+=1
229
+ col = cols[i1]
230
+ name2part[col.name] = parts[i1]
231
+ name2col[col.name] = cols[i1]
232
+ end
233
+ end
234
+ { preamble: preamble, parts: parts, name2part: name2part, columns: cols, name2column: name2col}
235
+ end
236
+
237
+ def exec(db,query)
238
+ if !db._begin(query)
239
+ puts "database problem"
240
+ return false
241
+ end
242
+ db._end
243
+ true
244
+ end
245
+
246
+ public
247
+
248
+ def alter_columns(db,name,columns)
249
+ not_blank = lambda {|x|
250
+ return false if x == nil || x == "" || x == "null"
251
+ true
252
+ }
253
+ sql = self.fetch_schema(db,name)
254
+ schema = self.split_schema(db,name,sql)
255
+ parts = schema[:parts]
256
+ nparts = Array.new
257
+ new_column_list = Array.new
258
+ ins_column_list = Array.new
259
+ sel_column_list = Array.new
260
+ meta = schema[:columns]
261
+ begin
262
+ _g1 = 0
263
+ _g = columns.length
264
+ while(_g1 < _g)
265
+ i = _g1
266
+ _g1+=1
267
+ c = columns[i]
268
+ if c.name != nil
269
+ if c.prev_name != nil
270
+ sel_column_list.push(c.prev_name)
271
+ ins_column_list.push(c.name)
272
+ end
273
+ orig_type = ""
274
+ orig_primary = false
275
+ if schema[:name2column].include?(c.name)
276
+ m = schema[:name2column][c.name]
277
+ orig_type = m.type_value
278
+ orig_primary = m.primary
279
+ end
280
+ next_type = orig_type
281
+ next_primary = orig_primary
282
+ if c.props != nil
283
+ _g2 = 0
284
+ _g3 = c.props
285
+ while(_g2 < _g3.length)
286
+ p = _g3[_g2]
287
+ _g2+=1
288
+ next_type = p.val if p.name == "type"
289
+ next_primary = "" + _hx_str(p.val.to_s) == "primary" if p.name == "key"
290
+ end
291
+ end
292
+ part = "" + _hx_str(c.name)
293
+ part += " " + _hx_str(next_type) if not_blank.call(next_type)
294
+ part += " PRIMARY KEY" if next_primary
295
+ nparts.push(part)
296
+ new_column_list.push(c.name)
297
+ end
298
+ end
299
+ end
300
+ return false if !self.exec(db,"BEGIN TRANSACTION")
301
+ c1 = self.column_list_sql(ins_column_list)
302
+ tname = db.get_quoted_table_name(name)
303
+ return false if !self.exec(db,"CREATE TEMPORARY TABLE __coopy_backup(" + _hx_str(c1) + ")")
304
+ return false if !self.exec(db,"INSERT INTO __coopy_backup (" + _hx_str(c1) + ") SELECT " + _hx_str(c1) + " FROM " + _hx_str(tname))
305
+ return false if !self.exec(db,"DROP TABLE " + _hx_str(tname))
306
+ return false if !self.exec(db,_hx_str(schema[:preamble]) + "(" + _hx_str(nparts.join(", ")) + ")")
307
+ return false if !self.exec(db,"INSERT INTO " + _hx_str(tname) + " (" + _hx_str(c1) + ") SELECT " + _hx_str(c1) + " FROM __coopy_backup")
308
+ return false if !self.exec(db,"DROP TABLE __coopy_backup")
309
+ return false if !self.exec(db,"COMMIT")
310
+ true
311
+ end
312
+
313
+ haxe_me ["coopy", "SqliteHelper"]
314
+ end
315
+
316
+ end
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ module Coopy
5
+ class Table
6
+ def getCell(x,y) puts "Abstract Table.getCell called" end
7
+ def setCell(x,y,c) puts "Abstract Table.setCell called" end
8
+ def getCellView() puts "Abstract Table.getCellView called" end
9
+ def isResizable() puts "Abstract Table.isResizable called" end
10
+ def resize(w,h) puts "Abstract Table.resize called" end
11
+ def clear() puts "Abstract Table.clear called" end
12
+ def insertOrDeleteRows(fate,hfate) puts "Abstract Table.insertOrDeleteRows called" end
13
+ def insertOrDeleteColumns(fate,wfate) puts "Abstract Table.insertOrDeleteColumns called" end
14
+ def trimBlank() puts "Abstract Table.trimBlank called" end
15
+ def get_width() puts "Abstract Table.get_width called" end
16
+ def get_height() puts "Abstract Table.get_height called" end
17
+ def getData() puts "Abstract Table.getData called" end
18
+ def clone() puts "Abstract Table.clone called" end
19
+ def create() puts "Abstract Table.create called" end
20
+ def getMeta() puts "Abstract Table.getMeta called" end
21
+ haxe_me ["coopy", "Table"]
22
+ end
23
+
24
+ end
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ module Coopy
5
+ class TableComparisonState
6
+
7
+ def initialize
8
+ self.reset
9
+ end
10
+
11
+ attr_accessor :p
12
+ attr_accessor :a
13
+ attr_accessor :b
14
+ attr_accessor :completed
15
+ attr_accessor :run_to_completion
16
+ attr_accessor :is_equal
17
+ attr_accessor :is_equal_known
18
+ attr_accessor :has_same_columns
19
+ attr_accessor :has_same_columns_known
20
+ attr_accessor :compare_flags
21
+ attr_accessor :p_meta
22
+ attr_accessor :a_meta
23
+ attr_accessor :b_meta
24
+ attr_accessor :alignment
25
+ attr_accessor :children
26
+ attr_accessor :child_order
27
+
28
+ def reset
29
+ @completed = false
30
+ @run_to_completion = true
31
+ @is_equal_known = false
32
+ @is_equal = false
33
+ @has_same_columns = false
34
+ @has_same_columns_known = false
35
+ @compare_flags = nil
36
+ @alignment = nil
37
+ @children = nil
38
+ @child_order = nil
39
+ end
40
+
41
+ def get_meta
42
+ @p_meta = @p.get_meta if @p != nil && @p_meta == nil
43
+ @a_meta = @a.get_meta if @a != nil && @a_meta == nil
44
+ @b_meta = @b.get_meta if @b != nil && @b_meta == nil
45
+ end
46
+
47
+ haxe_me ["coopy", "TableComparisonState"]
48
+ end
49
+
50
+ end
@@ -0,0 +1,1185 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ module Coopy
5
+ class TableDiff
6
+
7
+ def initialize(align,flags)
8
+ @align = align
9
+ @flags = flags
10
+ @builder = nil
11
+ @preserve_columns = false
12
+ end
13
+
14
+ protected
15
+
16
+ attr_accessor :align
17
+ attr_accessor :flags
18
+ attr_accessor :builder
19
+ attr_accessor :row_map
20
+ attr_accessor :col_map
21
+ attr_accessor :has_parent
22
+ attr_accessor :a
23
+ attr_accessor :b
24
+ attr_accessor :p
25
+ attr_accessor :rp_header
26
+ attr_accessor :ra_header
27
+ attr_accessor :rb_header
28
+ attr_accessor :is_index_p
29
+ attr_accessor :is_index_a
30
+ attr_accessor :is_index_b
31
+ attr_accessor :order
32
+ attr_accessor :row_units
33
+ attr_accessor :column_units
34
+ attr_accessor :show_rc_numbers
35
+ attr_accessor :row_moves
36
+ attr_accessor :col_moves
37
+ attr_accessor :active_row
38
+ attr_accessor :active_column
39
+ attr_accessor :allow_insert
40
+ attr_accessor :allow_delete
41
+ attr_accessor :allow_update
42
+ attr_accessor :v
43
+ attr_accessor :sep
44
+ attr_accessor :conflict_sep
45
+ attr_accessor :schema
46
+ attr_accessor :have_schema
47
+ attr_accessor :top_line_done
48
+ attr_accessor :have_addition
49
+ attr_accessor :act
50
+ attr_accessor :publish
51
+ attr_accessor :diff_found
52
+ attr_accessor :schema_diff_found
53
+ attr_accessor :preserve_columns
54
+ attr_accessor :row_deletes
55
+ attr_accessor :row_inserts
56
+ attr_accessor :row_updates
57
+ attr_accessor :row_reorders
58
+ attr_accessor :col_deletes
59
+ attr_accessor :col_inserts
60
+ attr_accessor :col_updates
61
+ attr_accessor :col_renames
62
+ attr_accessor :col_reorders
63
+ attr_accessor :column_units_updated
64
+ attr_accessor :nested
65
+ attr_accessor :nesting_present
66
+
67
+ public
68
+
69
+ def set_cell_builder(builder)
70
+ @builder = builder
71
+ end
72
+
73
+ protected
74
+
75
+ def get_separator(t,t2,root)
76
+ sep = root
77
+ w = t.get_width
78
+ h = t.get_height
79
+ view = t.get_cell_view
80
+ begin
81
+ _g = 0
82
+ while(_g < h)
83
+ y = _g
84
+ _g+=1
85
+ begin
86
+ _g1 = 0
87
+ while(_g1 < w)
88
+ x = _g1
89
+ _g1+=1
90
+ txt = view.to_s(t.get_cell(x,y))
91
+ next if txt == nil
92
+ while((txt.index(sep,nil || 0) || -1) >= 0)
93
+ sep = "-" + _hx_str(sep)
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
99
+ if t2 != nil
100
+ w = t2.get_width
101
+ h = t2.get_height
102
+ begin
103
+ _g2 = 0
104
+ while(_g2 < h)
105
+ y1 = _g2
106
+ _g2+=1
107
+ begin
108
+ _g11 = 0
109
+ while(_g11 < w)
110
+ x1 = _g11
111
+ _g11+=1
112
+ txt1 = view.to_s(t2.get_cell(x1,y1))
113
+ next if txt1 == nil
114
+ while((txt1.index(sep,nil || 0) || -1) >= 0)
115
+ sep = "-" + _hx_str(sep)
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
122
+ sep
123
+ end
124
+
125
+ def quote_for_diff(v,d)
126
+ _nil = "NULL"
127
+ return _nil if v.equals(d,nil)
128
+ str = v.to_s(d)
129
+ score = 0
130
+ begin
131
+ _g1 = 0
132
+ _g = str.length
133
+ while(_g1 < _g)
134
+ i = _g1
135
+ _g1+=1
136
+ break if (str[score].ord rescue nil) != 95
137
+ score+=1
138
+ end
139
+ end
140
+ str = "_" + _hx_str(str) if str[score..-1] == _nil
141
+ str
142
+ end
143
+
144
+ def is_reordered(m,ct)
145
+ reordered = false
146
+ l = -1
147
+ r = -1
148
+ begin
149
+ _g = 0
150
+ while(_g < ct)
151
+ i = _g
152
+ _g+=1
153
+ unit = m[i]
154
+ next if unit == nil
155
+ if unit.l >= 0
156
+ if unit.l < l
157
+ reordered = true
158
+ break
159
+ end
160
+ l = unit.l
161
+ end
162
+ if unit.r >= 0
163
+ if unit.r < r
164
+ reordered = true
165
+ break
166
+ end
167
+ r = unit.r
168
+ end
169
+ end
170
+ end
171
+ reordered
172
+ end
173
+
174
+ def spread_context(units,del,active)
175
+ if del > 0 && active != nil
176
+ mark = -del - 1
177
+ skips = 0
178
+ begin
179
+ _g1 = 0
180
+ _g = units.length
181
+ while(_g1 < _g)
182
+ i = _g1
183
+ _g1+=1
184
+ if active[i] == -3
185
+ skips+=1
186
+ next
187
+ end
188
+ if active[i] == 0 || active[i] == 3
189
+ if i - mark <= del + skips
190
+ active[i] = 2
191
+ elsif i - mark == del + 1 + skips
192
+ active[i] = 3
193
+ end
194
+ elsif active[i] == 1
195
+ mark = i
196
+ skips = 0
197
+ end
198
+ end
199
+ end
200
+ mark = units.length + del + 1
201
+ skips = 0
202
+ begin
203
+ _g11 = 0
204
+ _g2 = units.length
205
+ while(_g11 < _g2)
206
+ j = _g11
207
+ _g11+=1
208
+ i1 = units.length - 1 - j
209
+ if active[i1] == -3
210
+ skips+=1
211
+ next
212
+ end
213
+ if active[i1] == 0 || active[i1] == 3
214
+ if mark - i1 <= del + skips
215
+ active[i1] = 2
216
+ elsif mark - i1 == del + 1 + skips
217
+ active[i1] = 3
218
+ end
219
+ elsif active[i1] == 1
220
+ mark = i1
221
+ skips = 0
222
+ end
223
+ end
224
+ end
225
+ end
226
+ end
227
+
228
+ def set_ignore(ignore,idx_ignore,tab,r_header)
229
+ v = tab.get_cell_view
230
+ if tab.get_height >= r_header
231
+ _g1 = 0
232
+ _g = tab.get_width
233
+ while(_g1 < _g)
234
+ i = _g1
235
+ _g1+=1
236
+ name = v.to_s(tab.get_cell(i,r_header))
237
+ next if !ignore.include?(name)
238
+ idx_ignore[i] = true
239
+ end
240
+ end
241
+ end
242
+
243
+ def count_active(active)
244
+ ct = 0
245
+ showed_dummy = false
246
+ begin
247
+ _g1 = 0
248
+ _g = active.length
249
+ while(_g1 < _g)
250
+ i = _g1
251
+ _g1+=1
252
+ publish = active[i] > 0
253
+ dummy = active[i] == 3
254
+ next if dummy && showed_dummy
255
+ next if !publish
256
+ showed_dummy = dummy
257
+ ct+=1
258
+ end
259
+ end
260
+ ct
261
+ end
262
+
263
+ def reset
264
+ @has_parent = false
265
+ @rp_header = @ra_header = @rb_header = 0
266
+ @is_index_p = {}
267
+ @is_index_a = {}
268
+ @is_index_b = {}
269
+ @row_map = {}
270
+ @col_map = {}
271
+ @show_rc_numbers = false
272
+ @row_moves = nil
273
+ @col_moves = nil
274
+ @allow_insert = @allow_delete = @allow_update = true
275
+ @sep = ""
276
+ @conflict_sep = ""
277
+ @top_line_done = false
278
+ @diff_found = false
279
+ @schema_diff_found = false
280
+ @row_deletes = 0
281
+ @row_inserts = 0
282
+ @row_updates = 0
283
+ @row_reorders = 0
284
+ @col_deletes = 0
285
+ @col_inserts = 0
286
+ @col_updates = 0
287
+ @col_renames = 0
288
+ @col_reorders = 0
289
+ @column_units_updated = {}
290
+ end
291
+
292
+ def setup_tables
293
+ @order = @align.to_order
294
+ @row_units = @order.get_list
295
+ @has_parent = @align.reference != nil
296
+ if @has_parent
297
+ @p = @align.get_source
298
+ @a = @align.reference.get_target
299
+ @b = @align.get_target
300
+ @rp_header = @align.reference.meta.get_source_header
301
+ @ra_header = @align.reference.meta.get_target_header
302
+ @rb_header = @align.meta.get_target_header
303
+ if @align.get_index_columns != nil
304
+ _g = 0
305
+ _g1 = @align.get_index_columns
306
+ while(_g < _g1.length)
307
+ p2b = _g1[_g]
308
+ _g+=1
309
+ @is_index_p[p2b.l] = true if p2b.l >= 0
310
+ @is_index_b[p2b.r] = true if p2b.r >= 0
311
+ end
312
+ end
313
+ if @align.reference.get_index_columns != nil
314
+ _g2 = 0
315
+ _g11 = @align.reference.get_index_columns
316
+ while(_g2 < _g11.length)
317
+ p2a = _g11[_g2]
318
+ _g2+=1
319
+ @is_index_p[p2a.l] = true if p2a.l >= 0
320
+ @is_index_a[p2a.r] = true if p2a.r >= 0
321
+ end
322
+ end
323
+ else
324
+ @a = @align.get_source
325
+ @b = @align.get_target
326
+ @p = @a
327
+ @ra_header = @align.meta.get_source_header
328
+ @rp_header = @ra_header
329
+ @rb_header = @align.meta.get_target_header
330
+ if @align.get_index_columns != nil
331
+ _g3 = 0
332
+ _g12 = @align.get_index_columns
333
+ while(_g3 < _g12.length)
334
+ a2b = _g12[_g3]
335
+ _g3+=1
336
+ @is_index_a[a2b.l] = true if a2b.l >= 0
337
+ @is_index_b[a2b.r] = true if a2b.r >= 0
338
+ end
339
+ end
340
+ end
341
+ @allow_insert = @flags.allow_insert
342
+ @allow_delete = @flags.allow_delete
343
+ @allow_update = @flags.allow_update
344
+ common = @a
345
+ common = @b if common == nil
346
+ common = @p if common == nil
347
+ @v = common.get_cell_view
348
+ @builder.set_view(@v)
349
+ @nested = false
350
+ meta = common.get_meta
351
+ @nested = meta.is_nested if meta != nil
352
+ @nesting_present = false
353
+ end
354
+
355
+ def scan_activity
356
+ @active_row = Array.new
357
+ @active_column = nil
358
+ if !@flags.show_unchanged
359
+ _g1 = 0
360
+ _g = @row_units.length
361
+ while(_g1 < _g)
362
+ i = _g1
363
+ _g1+=1
364
+ @active_row[@row_units.length - 1 - i] = 0
365
+ end
366
+ end
367
+ if !@flags.show_unchanged_columns
368
+ @active_column = Array.new
369
+ begin
370
+ _g11 = 0
371
+ _g2 = @column_units.length
372
+ while(_g11 < _g2)
373
+ i1 = _g11
374
+ _g11+=1
375
+ v = 0
376
+ unit = @column_units[i1]
377
+ v = 1 if unit.l >= 0 && @is_index_a[unit.l]
378
+ v = 1 if unit.r >= 0 && @is_index_b[unit.r]
379
+ v = 1 if unit.p >= 0 && @is_index_p[unit.p]
380
+ @active_column[i1] = v
381
+ end
382
+ end
383
+ end
384
+ end
385
+
386
+ def setup_columns
387
+ column_order = @align.meta.to_order
388
+ @column_units = column_order.get_list
389
+ ignore = @flags.get_ignored_columns
390
+ if ignore != nil
391
+ p_ignore = {}
392
+ a_ignore = {}
393
+ b_ignore = {}
394
+ self.set_ignore(ignore,p_ignore,@p,@rp_header)
395
+ self.set_ignore(ignore,a_ignore,@a,@ra_header)
396
+ self.set_ignore(ignore,b_ignore,@b,@rb_header)
397
+ ncolumn_units = Array.new
398
+ begin
399
+ _g1 = 0
400
+ _g = @column_units.length
401
+ while(_g1 < _g)
402
+ j = _g1
403
+ _g1+=1
404
+ cunit = @column_units[j]
405
+ next if p_ignore.include?(cunit.p) || a_ignore.include?(cunit.l) || b_ignore.include?(cunit.r)
406
+ ncolumn_units.push(cunit)
407
+ end
408
+ end
409
+ @column_units = ncolumn_units
410
+ end
411
+ end
412
+
413
+ def setup_moves
414
+ if @flags.ordered
415
+ @row_moves = {}
416
+ moves = ::Coopy::Mover.move_units(@row_units)
417
+ begin
418
+ _g1 = 0
419
+ _g = moves.length
420
+ while(_g1 < _g)
421
+ i = _g1
422
+ _g1+=1
423
+ begin
424
+ @row_moves[moves[i]] = i
425
+ i
426
+ end
427
+ end
428
+ end
429
+ @col_moves = {}
430
+ moves = ::Coopy::Mover.move_units(@column_units)
431
+ begin
432
+ _g11 = 0
433
+ _g2 = moves.length
434
+ while(_g11 < _g2)
435
+ i1 = _g11
436
+ _g11+=1
437
+ begin
438
+ @col_moves[moves[i1]] = i1
439
+ i1
440
+ end
441
+ end
442
+ end
443
+ end
444
+ end
445
+
446
+ def scan_schema
447
+ @schema = Array.new
448
+ @have_schema = false
449
+ begin
450
+ _g1 = 0
451
+ _g = @column_units.length
452
+ while(_g1 < _g)
453
+ j = _g1
454
+ _g1+=1
455
+ cunit = @column_units[j]
456
+ reordered = false
457
+ if @flags.ordered
458
+ reordered = true if @col_moves.include?(j)
459
+ @show_rc_numbers = true if reordered
460
+ end
461
+ act = ""
462
+ if cunit.r >= 0 && cunit.lp == -1
463
+ @have_schema = true
464
+ act = "+++"
465
+ if @active_column != nil
466
+ @active_column[j] = 1 if @allow_update
467
+ end
468
+ @col_inserts+=1 if @allow_update
469
+ end
470
+ if cunit.r < 0 && cunit.lp >= 0
471
+ @have_schema = true
472
+ act = "---"
473
+ if @active_column != nil
474
+ @active_column[j] = 1 if @allow_update
475
+ end
476
+ @col_deletes+=1 if @allow_update
477
+ end
478
+ if cunit.r >= 0 && cunit.lp >= 0
479
+ if @p.get_height >= @rp_header && @b.get_height >= @rb_header
480
+ pp = @p.get_cell(cunit.lp,@rp_header)
481
+ bb = @b.get_cell(cunit.r,@rb_header)
482
+ if !self.is_equal(@v,pp,bb)
483
+ @have_schema = true
484
+ act = "("
485
+ act += @v.to_s(pp)
486
+ act += ")"
487
+ if @active_column != nil
488
+ @active_column[j] = 1
489
+ @col_renames+=1
490
+ end
491
+ end
492
+ end
493
+ end
494
+ if reordered
495
+ act = ":" + _hx_str(act)
496
+ @have_schema = true
497
+ @active_column = nil if @active_column != nil
498
+ @col_reorders+=1
499
+ end
500
+ @schema.push(act)
501
+ end
502
+ end
503
+ end
504
+
505
+ def check_rc_numbers(w,h)
506
+ if !@show_rc_numbers
507
+ if @flags.always_show_order
508
+ @show_rc_numbers = true
509
+ elsif @flags.ordered
510
+ @show_rc_numbers = self.is_reordered(@row_map,h)
511
+ @show_rc_numbers = self.is_reordered(@col_map,w) if !@show_rc_numbers
512
+ end
513
+ end
514
+ end
515
+
516
+ def add_rc_numbers(output)
517
+ admin_w = 1
518
+ if @show_rc_numbers && !@flags.never_show_order
519
+ admin_w+=1
520
+ target = Array.new
521
+ begin
522
+ _g1 = 0
523
+ _g = output.get_width
524
+ while(_g1 < _g)
525
+ i = _g1
526
+ _g1+=1
527
+ target.push(i + 1)
528
+ end
529
+ end
530
+ output.insert_or_delete_columns(target,output.get_width + 1)
531
+ begin
532
+ _g11 = 0
533
+ _g2 = output.get_height
534
+ while(_g11 < _g2)
535
+ i1 = _g11
536
+ _g11+=1
537
+ unit = @row_map[i1]
538
+ if unit == nil
539
+ output.set_cell(0,i1,"")
540
+ next
541
+ end
542
+ output.set_cell(0,i1,@builder.links(unit,true))
543
+ end
544
+ end
545
+ target = Array.new
546
+ begin
547
+ _g12 = 0
548
+ _g3 = output.get_height
549
+ while(_g12 < _g3)
550
+ i2 = _g12
551
+ _g12+=1
552
+ target.push(i2 + 1)
553
+ end
554
+ end
555
+ output.insert_or_delete_rows(target,output.get_height + 1)
556
+ begin
557
+ _g13 = 1
558
+ _g4 = output.get_width
559
+ while(_g13 < _g4)
560
+ i3 = _g13
561
+ _g13+=1
562
+ unit1 = @col_map[i3 - 1]
563
+ if unit1 == nil
564
+ output.set_cell(i3,0,"")
565
+ next
566
+ end
567
+ output.set_cell(i3,0,@builder.links(unit1,false))
568
+ end
569
+ end
570
+ output.set_cell(0,0,@builder.marker("@:@"))
571
+ end
572
+ admin_w
573
+ end
574
+
575
+ def elide_columns(output,admin_w)
576
+ if @active_column != nil
577
+ all_active = true
578
+ begin
579
+ _g1 = 0
580
+ _g = @active_column.length
581
+ while(_g1 < _g)
582
+ i = _g1
583
+ _g1+=1
584
+ if @active_column[i] == 0
585
+ all_active = false
586
+ break
587
+ end
588
+ end
589
+ end
590
+ if !all_active
591
+ fate = Array.new
592
+ begin
593
+ _g2 = 0
594
+ while(_g2 < admin_w)
595
+ i1 = _g2
596
+ _g2+=1
597
+ fate.push(i1)
598
+ end
599
+ end
600
+ at = admin_w
601
+ ct = 0
602
+ dots = Array.new
603
+ begin
604
+ _g11 = 0
605
+ _g3 = @active_column.length
606
+ while(_g11 < _g3)
607
+ i2 = _g11
608
+ _g11+=1
609
+ off = @active_column[i2] == 0
610
+ if off
611
+ ct = ct + 1
612
+ else
613
+ ct = 0
614
+ end
615
+ if off && ct > 1
616
+ fate.push(-1)
617
+ else
618
+ dots.push(at) if off
619
+ fate.push(at)
620
+ at+=1
621
+ end
622
+ end
623
+ end
624
+ output.insert_or_delete_columns(fate,at)
625
+ begin
626
+ _g4 = 0
627
+ while(_g4 < dots.length)
628
+ d = dots[_g4]
629
+ _g4+=1
630
+ begin
631
+ _g21 = 0
632
+ _g12 = output.get_height
633
+ while(_g21 < _g12)
634
+ j = _g21
635
+ _g21+=1
636
+ output.set_cell(d,j,@builder.marker("..."))
637
+ end
638
+ end
639
+ end
640
+ end
641
+ end
642
+ end
643
+ end
644
+
645
+ def add_schema(output)
646
+ if @have_schema
647
+ at = output.get_height
648
+ output.resize(@column_units.length + 1,at + 1)
649
+ output.set_cell(0,at,@builder.marker("!"))
650
+ begin
651
+ _g1 = 0
652
+ _g = @column_units.length
653
+ while(_g1 < _g)
654
+ j = _g1
655
+ _g1+=1
656
+ output.set_cell(j + 1,at,@v.to_datum(@schema[j]))
657
+ end
658
+ end
659
+ @schema_diff_found = true
660
+ end
661
+ end
662
+
663
+ def add_header(output)
664
+ if @flags.always_show_header
665
+ at = output.get_height
666
+ output.resize(@column_units.length + 1,at + 1)
667
+ output.set_cell(0,at,@builder.marker("@@"))
668
+ begin
669
+ _g1 = 0
670
+ _g = @column_units.length
671
+ while(_g1 < _g)
672
+ j = _g1
673
+ _g1+=1
674
+ cunit = @column_units[j]
675
+ if cunit.r >= 0
676
+ output.set_cell(j + 1,at,@b.get_cell(cunit.r,@rb_header)) if @b.get_height != 0
677
+ elsif cunit.l >= 0
678
+ output.set_cell(j + 1,at,@a.get_cell(cunit.l,@ra_header)) if @a.get_height != 0
679
+ elsif cunit.lp >= 0
680
+ output.set_cell(j + 1,at,@p.get_cell(cunit.lp,@rp_header)) if @p.get_height != 0
681
+ end
682
+ @col_map[j + 1] = cunit
683
+ end
684
+ end
685
+ @top_line_done = true
686
+ end
687
+ end
688
+
689
+ def check_meta(t,meta)
690
+ return false if meta.get_width != t.get_width + 1
691
+ return false if meta.get_width == 0 || meta.get_height == 0
692
+ true
693
+ end
694
+
695
+ def get_meta_table(t)
696
+ return nil if t == nil
697
+ meta = t.get_meta
698
+ return nil if meta == nil
699
+ meta.as_table
700
+ end
701
+
702
+ def add_meta(output)
703
+ a_meta = nil
704
+ b_meta = nil
705
+ p_meta = nil
706
+ a_meta = self.get_meta_table(@a)
707
+ b_meta = self.get_meta_table(@b)
708
+ p_meta = self.get_meta_table(@p)
709
+ return false if a_meta == nil || b_meta == nil || p_meta == nil
710
+ return false if !self.check_meta(@a,a_meta)
711
+ return false if !self.check_meta(@b,b_meta)
712
+ return false if !self.check_meta(@p,p_meta)
713
+ return false if !@flags.show_meta
714
+ meta_diff = ::Coopy::SimpleTable.new(0,0)
715
+ meta_flags = ::Coopy::CompareFlags.new
716
+ meta_flags.add_primary_key("@@")
717
+ meta_flags.add_primary_key("@")
718
+ meta_flags.unchanged_column_context = 65536
719
+ meta_flags.unchanged_context = 0
720
+ meta_align = ::Coopy::Coopy.compare_tables3(((a_meta == p_meta) ? nil : p_meta),a_meta,b_meta,meta_flags).align
721
+ td = ::Coopy::TableDiff.new(meta_align,meta_flags)
722
+ td.preserve_columns = true
723
+ td.hilite(meta_diff)
724
+ if td.has_difference
725
+ h = output.get_height
726
+ dh = meta_diff.get_height
727
+ offset = nil
728
+ if td.has_schema_difference
729
+ offset = 2
730
+ else
731
+ offset = 1
732
+ end
733
+ output.resize(output.get_width,h + dh - offset)
734
+ v = meta_diff.get_cell_view
735
+ begin
736
+ _g = offset
737
+ while(_g < dh)
738
+ y = _g
739
+ _g+=1
740
+ begin
741
+ _g2 = 1
742
+ _g1 = meta_diff.get_width
743
+ while(_g2 < _g1)
744
+ x = _g2
745
+ _g2+=1
746
+ c = meta_diff.get_cell(x,y)
747
+ c = "@" + _hx_str(v.to_s(c)) + "@" + _hx_str(v.to_s(meta_diff.get_cell(0,y))) if x == 1
748
+ output.set_cell(x - 1,h + y - offset,c)
749
+ end
750
+ end
751
+ end
752
+ end
753
+ if @active_column != nil
754
+ if td.active_column.length == meta_diff.get_width
755
+ _g11 = 1
756
+ _g3 = meta_diff.get_width
757
+ while(_g11 < _g3)
758
+ i = _g11
759
+ _g11+=1
760
+ @active_column[i - 1] = 1 if td.active_column[i] >= 0
761
+ end
762
+ end
763
+ end
764
+ end
765
+ false
766
+ end
767
+
768
+ def refine_activity
769
+ self.spread_context(@row_units,@flags.unchanged_context,@active_row)
770
+ self.spread_context(@column_units,@flags.unchanged_column_context,@active_column)
771
+ if @active_column != nil
772
+ _g1 = 0
773
+ _g = @column_units.length
774
+ while(_g1 < _g)
775
+ i = _g1
776
+ _g1+=1
777
+ @active_column[i] = 0 if @active_column[i] == 3
778
+ end
779
+ end
780
+ end
781
+
782
+ def normalize_string(v,str)
783
+ return str if str == nil
784
+ return str if !(@flags.ignore_whitespace || @flags.ignore_case)
785
+ txt = v.to_s(str)
786
+ txt = txt.strip if @flags.ignore_whitespace
787
+ txt = txt.downcase if @flags.ignore_case
788
+ txt
789
+ end
790
+
791
+ def is_equal(v,aa,bb)
792
+ return self.normalize_string(v,aa) == self.normalize_string(v,bb) if @flags.ignore_whitespace || @flags.ignore_case
793
+ v.equals(aa,bb)
794
+ end
795
+
796
+ def check_nesting(v,have_ll,ll,have_rr,rr,have_pp,pp,x,y)
797
+ all_tables = true
798
+ all_tables = all_tables && v.is_table(ll) if have_ll
799
+ all_tables = all_tables && v.is_table(rr) if have_rr
800
+ all_tables = all_tables && v.is_table(pp) if have_pp
801
+ return [ll,rr,pp] if !all_tables
802
+ ll_table = nil
803
+ rr_table = nil
804
+ pp_table = nil
805
+ ll_table = v.get_table(ll) if have_ll
806
+ rr_table = v.get_table(rr) if have_rr
807
+ pp_table = v.get_table(pp) if have_pp
808
+ compare = false
809
+ comp = ::Coopy::TableComparisonState.new
810
+ comp.a = ll_table
811
+ comp.b = rr_table
812
+ comp.p = pp_table
813
+ comp.compare_flags = @flags
814
+ comp.get_meta
815
+ key = nil
816
+ key = comp.a_meta.get_name if comp.a_meta != nil
817
+ key = comp.b_meta.get_name if key == nil && comp.b_meta != nil
818
+ key = _hx_str(x) + "_" + _hx_str(y) if key == nil
819
+ if @align.comp != nil
820
+ if @align.comp.children == nil
821
+ @align.comp.children = {}
822
+ @align.comp.child_order = Array.new
823
+ compare = true
824
+ else
825
+ compare = !@align.comp.children.include?(key)
826
+ end
827
+ end
828
+ if compare
829
+ @nesting_present = true
830
+ @align.comp.children[key] = comp
831
+ @align.comp.child_order.push(key)
832
+ ct = ::Coopy::CompareTable.new(comp)
833
+ ct.align
834
+ else
835
+ comp = @align.comp.children[key]
836
+ end
837
+ ll_out = nil
838
+ rr_out = nil
839
+ pp_out = nil
840
+ if comp.alignment.is_marked_as_identical || have_ll && !have_rr || have_rr && !have_ll
841
+ ll_out = "[" + _hx_str(key) + "]"
842
+ rr_out = ll_out
843
+ pp_out = ll_out
844
+ else
845
+ ll_out = "[a." + _hx_str(key) + "]" if ll != nil
846
+ rr_out = "[b." + _hx_str(key) + "]" if rr != nil
847
+ pp_out = "[p." + _hx_str(key) + "]" if pp != nil
848
+ end
849
+ [ll_out,rr_out,pp_out]
850
+ end
851
+
852
+ def scan_row(unit,output,at,i,out)
853
+ row_update = false
854
+ begin
855
+ _g1 = 0
856
+ _g = @column_units.length
857
+ while(_g1 < _g)
858
+ j = _g1
859
+ _g1+=1
860
+ cunit = @column_units[j]
861
+ pp = nil
862
+ ll = nil
863
+ rr = nil
864
+ dd = nil
865
+ dd_to = nil
866
+ have_dd_to = false
867
+ dd_to_alt = nil
868
+ have_dd_to_alt = false
869
+ have_pp = false
870
+ have_ll = false
871
+ have_rr = false
872
+ if cunit.p >= 0 && unit.p >= 0
873
+ pp = @p.get_cell(cunit.p,unit.p)
874
+ have_pp = true
875
+ end
876
+ if cunit.l >= 0 && unit.l >= 0
877
+ ll = @a.get_cell(cunit.l,unit.l)
878
+ have_ll = true
879
+ end
880
+ if cunit.r >= 0 && unit.r >= 0
881
+ rr = @b.get_cell(cunit.r,unit.r)
882
+ have_rr = true
883
+ if (((have_pp) ? cunit.p : cunit.l)) < 0
884
+ if rr != nil
885
+ if @v.to_s(rr) != ""
886
+ @have_addition = true if @flags.allow_update
887
+ end
888
+ end
889
+ end
890
+ end
891
+ if @nested
892
+ ndiff = self.check_nesting(@v,have_ll,ll,have_rr,rr,have_pp,pp,i,j)
893
+ ll = ndiff[0]
894
+ rr = ndiff[1]
895
+ pp = ndiff[2]
896
+ end
897
+ if have_pp
898
+ if !have_rr
899
+ dd = pp
900
+ elsif self.is_equal(@v,pp,rr)
901
+ dd = ll
902
+ else
903
+ dd = pp
904
+ dd_to = rr
905
+ have_dd_to = true
906
+ if !self.is_equal(@v,pp,ll)
907
+ if !self.is_equal(@v,pp,rr)
908
+ dd_to_alt = ll
909
+ have_dd_to_alt = true
910
+ end
911
+ end
912
+ end
913
+ elsif have_ll
914
+ if !have_rr
915
+ dd = ll
916
+ elsif self.is_equal(@v,ll,rr)
917
+ dd = ll
918
+ else
919
+ dd = ll
920
+ dd_to = rr
921
+ have_dd_to = true
922
+ end
923
+ else
924
+ dd = rr
925
+ end
926
+ cell = dd
927
+ if have_dd_to && @allow_update
928
+ if !row_update
929
+ @row_updates+=1 if out == 0
930
+ row_update = true
931
+ end
932
+ @active_column[j] = 1 if @active_column != nil
933
+ if @sep == ""
934
+ if @builder.need_separator
935
+ @sep = self.get_separator(@a,@b,"->")
936
+ @builder.set_separator(@sep)
937
+ else
938
+ @sep = "->"
939
+ end
940
+ end
941
+ is_conflict = false
942
+ if have_dd_to_alt
943
+ is_conflict = true if !self.is_equal(@v,dd_to,dd_to_alt)
944
+ end
945
+ if !is_conflict
946
+ cell = @builder.update(dd,dd_to)
947
+ @act = @sep if @sep.length > @act.length
948
+ else
949
+ if @conflict_sep == ""
950
+ if @builder.need_separator
951
+ @conflict_sep = _hx_str(self.get_separator(@p,@a,"!")) + _hx_str(@sep)
952
+ @builder.set_conflict_separator(@conflict_sep)
953
+ else
954
+ @conflict_sep = "!->"
955
+ end
956
+ end
957
+ cell = @builder.conflict(dd,dd_to_alt,dd_to)
958
+ @act = @conflict_sep
959
+ end
960
+ if !@column_units_updated.include?(j)
961
+ @column_units_updated[j] = true
962
+ @col_updates+=1
963
+ end
964
+ end
965
+ @act = "+" if @act == "" && @have_addition
966
+ if @act == "+++"
967
+ if have_rr
968
+ @active_column[j] = 1 if @active_column != nil
969
+ end
970
+ end
971
+ if @publish
972
+ output.set_cell(j + 1,at,cell) if @active_column == nil || @active_column[j] > 0
973
+ end
974
+ end
975
+ end
976
+ if @publish
977
+ output.set_cell(0,at,@builder.marker(@act))
978
+ @row_map[at] = unit
979
+ end
980
+ if @act != ""
981
+ @diff_found = true
982
+ if !@publish
983
+ @active_row[i] = 1 if @active_row != nil
984
+ end
985
+ end
986
+ end
987
+
988
+ public
989
+
990
+ def hilite(output)
991
+ output = ::Coopy::Coopy.tablify(output)
992
+ self.hilite_single(output)
993
+ end
994
+
995
+ protected
996
+
997
+ def hilite_single(output)
998
+ return false if !output.is_resizable
999
+ if @builder == nil
1000
+ if @flags.allow_nested_cells
1001
+ @builder = ::Coopy::NestedCellBuilder.new
1002
+ else
1003
+ @builder = ::Coopy::FlatCellBuilder.new(@flags)
1004
+ end
1005
+ end
1006
+ output.resize(0,0)
1007
+ output.clear
1008
+ self.reset
1009
+ self.setup_tables
1010
+ self.setup_columns
1011
+ self.setup_moves
1012
+ self.scan_activity
1013
+ self.scan_schema
1014
+ self.add_schema(output)
1015
+ self.add_header(output)
1016
+ self.add_meta(output)
1017
+ outer_reps_needed = nil
1018
+ if @flags.show_unchanged && @flags.show_unchanged_columns
1019
+ outer_reps_needed = 1
1020
+ else
1021
+ outer_reps_needed = 2
1022
+ end
1023
+ output_height = output.get_height
1024
+ output_height_init = output.get_height
1025
+ begin
1026
+ _g = 0
1027
+ while(_g < outer_reps_needed)
1028
+ out = _g
1029
+ _g+=1
1030
+ if out == 1
1031
+ self.refine_activity
1032
+ rows = self.count_active(@active_row) + output_height_init
1033
+ rows-=1 if @top_line_done
1034
+ output_height = output_height_init
1035
+ output.resize(@column_units.length + 1,rows) if rows > output.get_height
1036
+ end
1037
+ showed_dummy = false
1038
+ l = -1
1039
+ r = -1
1040
+ begin
1041
+ _g2 = 0
1042
+ _g1 = @row_units.length
1043
+ while(_g2 < _g1)
1044
+ i = _g2
1045
+ _g2+=1
1046
+ unit = @row_units[i]
1047
+ reordered = false
1048
+ if @flags.ordered
1049
+ reordered = true if @row_moves.include?(i)
1050
+ @show_rc_numbers = true if reordered
1051
+ end
1052
+ next if unit.r < 0 && unit.l < 0
1053
+ next if unit.r == 0 && unit.lp <= 0 && @top_line_done
1054
+ @publish = @flags.show_unchanged
1055
+ dummy = false
1056
+ if out == 1
1057
+ value = @active_row[i]
1058
+ @publish = value != nil && value > 0
1059
+ dummy = value != nil && value == 3
1060
+ next if dummy && showed_dummy
1061
+ next if !@publish
1062
+ end
1063
+ showed_dummy = false if !dummy
1064
+ at = output_height
1065
+ if @publish
1066
+ output_height+=1
1067
+ output.resize(@column_units.length + 1,output_height) if output.get_height < output_height
1068
+ end
1069
+ if dummy
1070
+ begin
1071
+ _g4 = 0
1072
+ _g3 = @column_units.length + 1
1073
+ while(_g4 < _g3)
1074
+ j = _g4
1075
+ _g4+=1
1076
+ output.set_cell(j,at,@v.to_datum("..."))
1077
+ end
1078
+ end
1079
+ showed_dummy = true
1080
+ next
1081
+ end
1082
+ @have_addition = false
1083
+ skip = false
1084
+ @act = ""
1085
+ if reordered
1086
+ @act = ":"
1087
+ @row_reorders+=1 if out == 0
1088
+ end
1089
+ if unit.p < 0 && unit.l < 0 && unit.r >= 0
1090
+ skip = true if !@allow_insert
1091
+ @act = "+++"
1092
+ @row_inserts+=1 if out == 0 && !skip
1093
+ end
1094
+ if (unit.p >= 0 || !@has_parent) && unit.l >= 0 && unit.r < 0
1095
+ skip = true if !@allow_delete
1096
+ @act = "---"
1097
+ @row_deletes+=1 if out == 0 && !skip
1098
+ end
1099
+ if skip
1100
+ if !@publish
1101
+ @active_row[i] = -3 if @active_row != nil
1102
+ end
1103
+ next
1104
+ end
1105
+ self.scan_row(unit,output,at,i,out)
1106
+ end
1107
+ end
1108
+ end
1109
+ end
1110
+ self.check_rc_numbers(output.get_width,output.get_height)
1111
+ admin_w = self.add_rc_numbers(output)
1112
+ self.elide_columns(output,admin_w) if !@preserve_columns
1113
+ true
1114
+ end
1115
+
1116
+ public
1117
+
1118
+ def hilite_with_nesting(output)
1119
+ base = output.add("base")
1120
+ result = self.hilite_single(base)
1121
+ return false if !result
1122
+ return true if @align.comp == nil
1123
+ order = @align.comp.child_order
1124
+ return true if order == nil
1125
+ output.alignment = @align
1126
+ begin
1127
+ _g = 0
1128
+ while(_g < order.length)
1129
+ name = order[_g]
1130
+ _g+=1
1131
+ child = @align.comp.children[name]
1132
+ alignment = child.alignment
1133
+ if alignment.is_marked_as_identical
1134
+ @align.comp.children[name] = nil
1135
+ next
1136
+ end
1137
+ td = ::Coopy::TableDiff.new(alignment,@flags)
1138
+ child_output = output.add(name)
1139
+ result = result && td.hilite_single(child_output)
1140
+ end
1141
+ end
1142
+ result
1143
+ end
1144
+
1145
+ def has_difference
1146
+ @diff_found
1147
+ end
1148
+
1149
+ def has_schema_difference
1150
+ @schema_diff_found
1151
+ end
1152
+
1153
+ def is_nested
1154
+ @nesting_present
1155
+ end
1156
+
1157
+ def get_comparison_state
1158
+ return nil if @align == nil
1159
+ @align.comp
1160
+ end
1161
+
1162
+ def get_summary
1163
+ ds = ::Coopy::DiffSummary.new
1164
+ ds.row_deletes = @row_deletes
1165
+ ds.row_inserts = @row_inserts
1166
+ ds.row_updates = @row_updates
1167
+ ds.row_reorders = @row_reorders
1168
+ ds.col_deletes = @col_deletes
1169
+ ds.col_inserts = @col_inserts
1170
+ ds.col_updates = @col_updates
1171
+ ds.col_renames = @col_renames
1172
+ ds.col_reorders = @col_reorders
1173
+ ds.row_count_initial_with_header = @align.get_source.get_height
1174
+ ds.row_count_final_with_header = @align.get_target.get_height
1175
+ ds.row_count_initial = @align.get_source.get_height - @align.get_source_header - 1
1176
+ ds.row_count_final = @align.get_target.get_height - @align.get_target_header - 1
1177
+ ds.col_count_initial = @align.get_source.get_width
1178
+ ds.col_count_final = @align.get_target.get_width
1179
+ ds
1180
+ end
1181
+
1182
+ haxe_me ["coopy", "TableDiff"]
1183
+ end
1184
+
1185
+ end