├── .gitignore ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── css └── daff.css ├── csvhub.js ├── icons ├── 128.png └── 48.png ├── js ├── daff-1.1.8.js ├── jquery-1.11.1.js └── jquery.csv-0.71.js └── manifest.json /.gitignore: -------------------------------------------------------------------------------- 1 | /.DS_Store 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 1.0.3 4 | 5 | Updated for changes to github diff CSS selectors again. It's almost like they 6 | don't expect us to be relying on them :) 7 | 8 | ## 1.0.2 9 | 10 | Updated for changes to github diff CSS selectors 11 | 12 | ## 1.0.1 13 | 14 | Fixed bug where CSV diffs would not display at all 15 | Updated daff version 16 | 17 | ## 1.0.0 18 | 19 | First proper release - basically working, probably has bugs. 20 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | --------------------- 3 | 4 | Copyright (c) 2014 The Open Data Institute 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CSVHub 2 | 3 | A Chrome extension that shows CSV file diffs nicely on GitHub. 4 | 5 | ## Installation 6 | 7 | Install the extension from the [Chrome Web Store](https://chrome.google.com/webstore/detail/csvhub/dbemglgpbebafkibfncdpdmdikacingf). 8 | 9 | ## Usage 10 | 11 | Then just view a 12 | [diff of a CSV file on GitHub](https://github.com/theodi/test-data/commit/9f391e6e35963b96aa0eed56c20ccd70f326e1f7) 13 | and enjoy the results. 14 | 15 | ## Bug Reports 16 | 17 | If you notice any problems, please [file an issue](https://github.com/theodi/csvhub/issues) 18 | including the version you're using, and the URL that you're having trouble with. 19 | 20 | Also, this code is open source, and pull requests are gratefully accepted! 21 | 22 | ## Colophon 23 | 24 | All the clever stuff in this extension is done by Paul Fitzpatrick's amazing 25 | cross-platform CSV diffing library, [daff](https://github.com/paulfitz/daff). 26 | 27 | We also gladly use [jQuery](https://jquery.com/) 28 | and [jQuery-csv](https://code.google.com/p/jquery-csv/). 29 | 30 | ## License 31 | 32 | This code is open source under the MIT license. See the LICENSE.md file for 33 | full details. 34 | -------------------------------------------------------------------------------- /css/daff.css: -------------------------------------------------------------------------------- 1 | .csvhub-diff { 2 | } 3 | 4 | .csvhub-diff table { 5 | width: 100%; 6 | } 7 | 8 | .csvhub-diff th { 9 | text-align: left; 10 | } 11 | 12 | .csvhub-diff td, .csvhub-diff th { 13 | border: 1px solid #DDD; 14 | padding: 5px; 15 | } 16 | 17 | .csvhub-diff tr:nth-child(even) { 18 | background-color: #f8f8f8; 19 | } 20 | 21 | .csvhub-diff tr:nth-child(even) td.modify, 22 | .csvhub-diff tr:nth-child(even) th.modify { 23 | background-color: #BFCFD6 !important; 24 | } 25 | 26 | .csvhub-diff tr:nth-child(odd) td.modify, 27 | .csvhub-diff tr:nth-child(odd) th.modify { 28 | background-color: #C5D5DD !important; 29 | } 30 | 31 | .csvhub-diff tr:nth-child(even) td.add, 32 | .csvhub-diff tr:nth-child(even) th.add, 33 | .csvhub-diff tr.add:nth-child(even) { 34 | background-color: #D6F8D6 !important; 35 | } 36 | 37 | 38 | .csvhub-diff tr:nth-child(odd) td.add, 39 | .csvhub-diff tr:nth-child(odd) th.add, 40 | .csvhub-diff tr.add:nth-child(odd) { 41 | background-color: #DFD !important; 42 | } 43 | 44 | .csvhub-diff tr:nth-child(even) td.remove, 45 | .csvhub-diff tr:nth-child(even) th.remove, 46 | .csvhub-diff tr.remove:nth-child(even) { 47 | background-color: #F8D6D6 !important; 48 | } 49 | 50 | .csvhub-diff tr:nth-child(odd) td.remove, 51 | .csvhub-diff tr:nth-child(odd) th.remove, 52 | .csvhub-diff tr.remove:nth-child(odd) { 53 | background-color: #FDD !important; 54 | } 55 | -------------------------------------------------------------------------------- /csvhub.js: -------------------------------------------------------------------------------- 1 | function render_csv_files() { 2 | // Check diff view mode 3 | var diff_view = $("meta[name=diff-view]").attr("content"); // 'unified' or 'split' 4 | if (diff_view != "unified") return; // Work only in 'unified' mode 5 | 6 | // Find all files in the page 7 | files = $("div#files.diff-view .file"); 8 | for (var f = 0; f < files.length; f++) { 9 | // Large diffs are not rendered by default, skip this file 10 | if (files[f].querySelector("div.data") == null) continue; 11 | 12 | // Check if this is a CSV file 13 | filename = files[f] 14 | .querySelector("div[data-path]") 15 | .getAttribute("data-path"); 16 | if (filename.match(".*.csv$")) { 17 | // Get all diff lines 18 | lines = files[f].querySelectorAll(".blob-code-marker"); 19 | 20 | // Get data 21 | var old_data = []; 22 | var new_data = []; 23 | 24 | for (var l = 0; l < lines.length; l++) { 25 | // Parse data from line 26 | code_marker = lines[l].getAttribute("data-code-marker"); 27 | line = lines[l].textContent.trim(); 28 | if (line.length == 0) continue; // Skip empty line 29 | data = $.csv.toArray(line); 30 | 31 | // Line has been added 32 | if (code_marker == "+") { 33 | new_data.push(data); 34 | } 35 | 36 | // Line has been removed 37 | if (code_marker == "-") { 38 | old_data.push(data); 39 | } 40 | 41 | // Line has not changed 42 | if (code_marker == " ") { 43 | new_data.push(data); 44 | old_data.push(data); 45 | } 46 | } 47 | 48 | // Parse CSV 49 | var old_table = new daff.TableView(old_data); 50 | var new_table = new daff.TableView(new_data); 51 | 52 | var alignment = daff.compareTables(old_table, new_table).align(); 53 | 54 | var data_diff = []; 55 | var table_diff = new daff.TableView(data_diff); 56 | 57 | var flags = new daff.CompareFlags(); 58 | flags.show_unchanged = true; 59 | flags.show_unchanged_columns = true; 60 | flags.always_show_header = false; 61 | var highlighter = new daff.TableDiff(alignment, flags); 62 | highlighter.hilite(table_diff); 63 | 64 | var diff2html = new daff.DiffRender(); 65 | diff2html.render(table_diff); 66 | diff_html = diff2html.html(); 67 | 68 | files[f].querySelector("div.data").innerHTML = 69 | "
" + diff_html + "
"; 70 | } 71 | } 72 | } 73 | 74 | $(function() { 75 | render_csv_files(); 76 | }); 77 | -------------------------------------------------------------------------------- /icons/128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Data-Liberation-Front/csvhub/6afdea9b38b18b12267c28a10e32e3ad9ea63907/icons/128.png -------------------------------------------------------------------------------- /icons/48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Data-Liberation-Front/csvhub/6afdea9b38b18b12267c28a10e32e3ad9ea63907/icons/48.png -------------------------------------------------------------------------------- /js/daff-1.1.8.js: -------------------------------------------------------------------------------- 1 | (function ($hx_exports) { "use strict"; 2 | $hx_exports.coopy = $hx_exports.coopy || {}; 3 | var $estr = function() { return js.Boot.__string_rec(this,''); }; 4 | var HxOverrides = function() { }; 5 | HxOverrides.__name__ = true; 6 | HxOverrides.cca = function(s,index) { 7 | var x = s.charCodeAt(index); 8 | if(x != x) return undefined; 9 | return x; 10 | }; 11 | HxOverrides.substr = function(s,pos,len) { 12 | if(pos != null && pos != 0 && len != null && len < 0) return ""; 13 | if(len == null) len = s.length; 14 | if(pos < 0) { 15 | pos = s.length + pos; 16 | if(pos < 0) pos = 0; 17 | } else if(len < 0) len = s.length + len - pos; 18 | return s.substr(pos,len); 19 | }; 20 | HxOverrides.iter = function(a) { 21 | return { cur : 0, arr : a, hasNext : function() { 22 | return this.cur < this.arr.length; 23 | }, next : function() { 24 | return this.arr[this.cur++]; 25 | }}; 26 | }; 27 | var Lambda = function() { }; 28 | Lambda.__name__ = true; 29 | Lambda.array = function(it) { 30 | var a = new Array(); 31 | var $it0 = $iterator(it)(); 32 | while( $it0.hasNext() ) { 33 | var i = $it0.next(); 34 | a.push(i); 35 | } 36 | return a; 37 | }; 38 | Lambda.map = function(it,f) { 39 | var l = new List(); 40 | var $it0 = $iterator(it)(); 41 | while( $it0.hasNext() ) { 42 | var x = $it0.next(); 43 | l.add(f(x)); 44 | } 45 | return l; 46 | }; 47 | Lambda.has = function(it,elt) { 48 | var $it0 = $iterator(it)(); 49 | while( $it0.hasNext() ) { 50 | var x = $it0.next(); 51 | if(x == elt) return true; 52 | } 53 | return false; 54 | }; 55 | var List = function() { 56 | this.length = 0; 57 | }; 58 | List.__name__ = true; 59 | List.prototype = { 60 | add: function(item) { 61 | var x = [item]; 62 | if(this.h == null) this.h = x; else this.q[1] = x; 63 | this.q = x; 64 | this.length++; 65 | } 66 | ,iterator: function() { 67 | return { h : this.h, hasNext : function() { 68 | return this.h != null; 69 | }, next : function() { 70 | if(this.h == null) return null; 71 | var x = this.h[0]; 72 | this.h = this.h[1]; 73 | return x; 74 | }}; 75 | } 76 | }; 77 | var IMap = function() { }; 78 | IMap.__name__ = true; 79 | Math.__name__ = true; 80 | var Reflect = function() { }; 81 | Reflect.__name__ = true; 82 | Reflect.field = function(o,field) { 83 | try { 84 | return o[field]; 85 | } catch( e ) { 86 | return null; 87 | } 88 | }; 89 | Reflect.fields = function(o) { 90 | var a = []; 91 | if(o != null) { 92 | var hasOwnProperty = Object.prototype.hasOwnProperty; 93 | for( var f in o ) { 94 | if(f != "__id__" && f != "hx__closures__" && hasOwnProperty.call(o,f)) a.push(f); 95 | } 96 | } 97 | return a; 98 | }; 99 | var Std = function() { }; 100 | Std.__name__ = true; 101 | Std.string = function(s) { 102 | return js.Boot.__string_rec(s,""); 103 | }; 104 | Std.parseInt = function(x) { 105 | var v = parseInt(x,10); 106 | if(v == 0 && (HxOverrides.cca(x,1) == 120 || HxOverrides.cca(x,1) == 88)) v = parseInt(x); 107 | if(isNaN(v)) return null; 108 | return v; 109 | }; 110 | var StringBuf = function() { 111 | this.b = ""; 112 | }; 113 | StringBuf.__name__ = true; 114 | StringBuf.prototype = { 115 | add: function(x) { 116 | this.b += Std.string(x); 117 | } 118 | }; 119 | var StringTools = function() { }; 120 | StringTools.__name__ = true; 121 | StringTools.replace = function(s,sub,by) { 122 | return s.split(sub).join(by); 123 | }; 124 | var coopy = {}; 125 | coopy.Alignment = function() { 126 | this.map_a2b = new haxe.ds.IntMap(); 127 | this.map_b2a = new haxe.ds.IntMap(); 128 | this.ha = this.hb = 0; 129 | this.map_count = 0; 130 | this.reference = null; 131 | this.meta = null; 132 | this.order_cache_has_reference = false; 133 | this.ia = 0; 134 | this.ib = 0; 135 | }; 136 | coopy.Alignment.__name__ = true; 137 | coopy.Alignment.prototype = { 138 | range: function(ha,hb) { 139 | this.ha = ha; 140 | this.hb = hb; 141 | } 142 | ,tables: function(ta,tb) { 143 | this.ta = ta; 144 | this.tb = tb; 145 | } 146 | ,headers: function(ia,ib) { 147 | this.ia = ia; 148 | this.ib = ib; 149 | } 150 | ,setRowlike: function(flag) { 151 | } 152 | ,link: function(a,b) { 153 | this.map_a2b.set(a,b); 154 | this.map_b2a.set(b,a); 155 | this.map_count++; 156 | } 157 | ,addIndexColumns: function(unit) { 158 | if(this.index_columns == null) this.index_columns = new Array(); 159 | this.index_columns.push(unit); 160 | } 161 | ,getIndexColumns: function() { 162 | return this.index_columns; 163 | } 164 | ,a2b: function(a) { 165 | return this.map_a2b.get(a); 166 | } 167 | ,b2a: function(b) { 168 | return this.map_b2a.get(b); 169 | } 170 | ,count: function() { 171 | return this.map_count; 172 | } 173 | ,toString: function() { 174 | return "" + this.map_a2b.toString(); 175 | } 176 | ,toOrderPruned: function(rowlike) { 177 | return this.toOrderCached(true,rowlike); 178 | } 179 | ,toOrder: function() { 180 | return this.toOrderCached(false,false); 181 | } 182 | ,getSource: function() { 183 | return this.ta; 184 | } 185 | ,getTarget: function() { 186 | return this.tb; 187 | } 188 | ,getSourceHeader: function() { 189 | return this.ia; 190 | } 191 | ,getTargetHeader: function() { 192 | return this.ib; 193 | } 194 | ,toOrderCached: function(prune,rowlike) { 195 | if(this.order_cache != null) { 196 | if(this.reference != null) { 197 | if(!this.order_cache_has_reference) this.order_cache = null; 198 | } 199 | } 200 | if(this.order_cache == null) this.order_cache = this.toOrder3(prune,rowlike); 201 | if(this.reference != null) this.order_cache_has_reference = true; 202 | return this.order_cache; 203 | } 204 | ,pruneOrder: function(o,ref,rowlike) { 205 | var tl = ref.tb; 206 | var tr = this.tb; 207 | if(rowlike) { 208 | if(tl.get_width() != tr.get_width()) return; 209 | } else if(tl.get_height() != tr.get_height()) return; 210 | var units = o.getList(); 211 | var left_units = new Array(); 212 | var left_locs = new Array(); 213 | var right_units = new Array(); 214 | var right_locs = new Array(); 215 | var eliminate = new Array(); 216 | var ct = 0; 217 | var _g1 = 0; 218 | var _g = units.length; 219 | while(_g1 < _g) { 220 | var i = _g1++; 221 | var unit = units[i]; 222 | if(unit.l < 0 && unit.r >= 0) { 223 | right_units.push(unit); 224 | right_locs.push(i); 225 | ct++; 226 | } else if(unit.r < 0 && unit.l >= 0) { 227 | left_units.push(unit); 228 | left_locs.push(i); 229 | ct++; 230 | } else if(ct > 0) { 231 | left_units.splice(0,left_units.length); 232 | right_units.splice(0,right_units.length); 233 | left_locs.splice(0,left_locs.length); 234 | right_locs.splice(0,right_locs.length); 235 | ct = 0; 236 | } 237 | while(left_locs.length > 0 && right_locs.length > 0) { 238 | var l = left_units[0].l; 239 | var r = right_units[0].r; 240 | var view = tl.getCellView(); 241 | var match = true; 242 | if(rowlike) { 243 | var w = tl.get_width(); 244 | var _g2 = 0; 245 | while(_g2 < w) { 246 | var j = _g2++; 247 | if(!view.equals(tl.getCell(j,l),tr.getCell(j,r))) { 248 | match = false; 249 | break; 250 | } 251 | } 252 | } else { 253 | var h = tl.get_height(); 254 | var _g21 = 0; 255 | while(_g21 < h) { 256 | var j1 = _g21++; 257 | if(!view.equals(tl.getCell(l,j1),tr.getCell(r,j1))) { 258 | match = false; 259 | break; 260 | } 261 | } 262 | } 263 | if(match) { 264 | eliminate.push(left_locs[0]); 265 | eliminate.push(right_locs[0]); 266 | } 267 | left_units.shift(); 268 | right_units.shift(); 269 | left_locs.shift(); 270 | right_locs.shift(); 271 | ct -= 2; 272 | } 273 | } 274 | if(eliminate.length > 0) { 275 | eliminate.sort(function(a,b) { 276 | return a - b; 277 | }); 278 | var del = 0; 279 | var _g3 = 0; 280 | while(_g3 < eliminate.length) { 281 | var e = eliminate[_g3]; 282 | ++_g3; 283 | o.getList().splice(e - del,1); 284 | del++; 285 | } 286 | } 287 | } 288 | ,toOrder3: function(prune,rowlike) { 289 | var ref = this.reference; 290 | if(ref == null) { 291 | ref = new coopy.Alignment(); 292 | ref.range(this.ha,this.ha); 293 | ref.tables(this.ta,this.ta); 294 | var _g1 = 0; 295 | var _g = this.ha; 296 | while(_g1 < _g) { 297 | var i = _g1++; 298 | ref.link(i,i); 299 | } 300 | } 301 | var order = new coopy.Ordering(); 302 | if(this.reference == null) order.ignoreParent(); 303 | var xp = 0; 304 | var xl = 0; 305 | var xr = 0; 306 | var hp = this.ha; 307 | var hl = ref.hb; 308 | var hr = this.hb; 309 | var vp = new haxe.ds.IntMap(); 310 | var vl = new haxe.ds.IntMap(); 311 | var vr = new haxe.ds.IntMap(); 312 | var _g2 = 0; 313 | while(_g2 < hp) { 314 | var i1 = _g2++; 315 | vp.set(i1,i1); 316 | } 317 | var _g3 = 0; 318 | while(_g3 < hl) { 319 | var i2 = _g3++; 320 | vl.set(i2,i2); 321 | } 322 | var _g4 = 0; 323 | while(_g4 < hr) { 324 | var i3 = _g4++; 325 | vr.set(i3,i3); 326 | } 327 | var ct_vp = hp; 328 | var ct_vl = hl; 329 | var ct_vr = hr; 330 | var prev = -1; 331 | var ct = 0; 332 | var max_ct = (hp + hl + hr) * 10; 333 | while(ct_vp > 0 || ct_vl > 0 || ct_vr > 0) { 334 | ct++; 335 | if(ct > max_ct) { 336 | console.log("Ordering took too long, something went wrong"); 337 | break; 338 | } 339 | if(xp >= hp) xp = 0; 340 | if(xl >= hl) xl = 0; 341 | if(xr >= hr) xr = 0; 342 | if(xp < hp && ct_vp > 0) { 343 | if(this.a2b(xp) == null && ref.a2b(xp) == null) { 344 | if(vp.exists(xp)) { 345 | order.add(-1,-1,xp); 346 | prev = xp; 347 | vp.remove(xp); 348 | ct_vp--; 349 | } 350 | xp++; 351 | continue; 352 | } 353 | } 354 | var zl = null; 355 | var zr = null; 356 | if(xl < hl && ct_vl > 0) { 357 | zl = ref.b2a(xl); 358 | if(zl == null) { 359 | if(vl.exists(xl)) { 360 | order.add(xl,-1,-1); 361 | vl.remove(xl); 362 | ct_vl--; 363 | } 364 | xl++; 365 | continue; 366 | } 367 | } 368 | if(xr < hr && ct_vr > 0) { 369 | zr = this.b2a(xr); 370 | if(zr == null) { 371 | if(vr.exists(xr)) { 372 | order.add(-1,xr,-1); 373 | vr.remove(xr); 374 | ct_vr--; 375 | } 376 | xr++; 377 | continue; 378 | } 379 | } 380 | if(zl != null) { 381 | if(this.a2b(zl) == null) { 382 | if(vl.exists(xl)) { 383 | order.add(xl,-1,zl); 384 | prev = zl; 385 | vp.remove(zl); 386 | ct_vp--; 387 | vl.remove(xl); 388 | ct_vl--; 389 | xp = zl + 1; 390 | } 391 | xl++; 392 | continue; 393 | } 394 | } 395 | if(zr != null) { 396 | if(ref.a2b(zr) == null) { 397 | if(vr.exists(xr)) { 398 | order.add(-1,xr,zr); 399 | prev = zr; 400 | vp.remove(zr); 401 | ct_vp--; 402 | vr.remove(xr); 403 | ct_vr--; 404 | xp = zr + 1; 405 | } 406 | xr++; 407 | continue; 408 | } 409 | } 410 | if(zl != null && zr != null && this.a2b(zl) != null && ref.a2b(zr) != null) { 411 | if(zl == prev + 1 || zr != prev + 1) { 412 | if(vr.exists(xr)) { 413 | order.add(ref.a2b(zr),xr,zr); 414 | prev = zr; 415 | vp.remove(zr); 416 | ct_vp--; 417 | var key = ref.a2b(zr); 418 | vl.remove(key); 419 | ct_vl--; 420 | vr.remove(xr); 421 | ct_vr--; 422 | xp = zr + 1; 423 | xl = ref.a2b(zr) + 1; 424 | } 425 | xr++; 426 | continue; 427 | } else { 428 | if(vl.exists(xl)) { 429 | order.add(xl,this.a2b(zl),zl); 430 | prev = zl; 431 | vp.remove(zl); 432 | ct_vp--; 433 | vl.remove(xl); 434 | ct_vl--; 435 | var key1 = this.a2b(zl); 436 | vr.remove(key1); 437 | ct_vr--; 438 | xp = zl + 1; 439 | xr = this.a2b(zl) + 1; 440 | } 441 | xl++; 442 | continue; 443 | } 444 | } 445 | xp++; 446 | xl++; 447 | xr++; 448 | } 449 | if(prune) this.pruneOrder(order,ref,rowlike); 450 | return order; 451 | } 452 | }; 453 | coopy.Bag = function() { }; 454 | coopy.Bag.__name__ = true; 455 | coopy.CellInfo = $hx_exports.coopy.CellInfo = function() { 456 | }; 457 | coopy.CellInfo.__name__ = true; 458 | coopy.CellInfo.prototype = { 459 | toString: function() { 460 | if(!this.updated) return this.value; 461 | if(!this.conflicted) return this.lvalue + "::" + this.rvalue; 462 | return this.pvalue + "||" + this.lvalue + "::" + this.rvalue; 463 | } 464 | }; 465 | coopy.Change = $hx_exports.coopy.Change = function(txt) { 466 | if(txt != null) { 467 | this.mode = coopy.ChangeType.NOTE_CHANGE; 468 | this.change = txt; 469 | } else this.mode = coopy.ChangeType.NO_CHANGE; 470 | }; 471 | coopy.Change.__name__ = true; 472 | coopy.Change.prototype = { 473 | getMode: function() { 474 | return "" + Std.string(this.mode); 475 | } 476 | ,toString: function() { 477 | var _g = this.mode; 478 | switch(_g[1]) { 479 | case 0: 480 | return "no change"; 481 | case 2: 482 | return "local change: " + Std.string(this.remote) + " -> " + Std.string(this.local); 483 | case 1: 484 | return "remote change: " + Std.string(this.local) + " -> " + Std.string(this.remote); 485 | case 3: 486 | return "conflicting change: " + Std.string(this.parent) + " -> " + Std.string(this.local) + " / " + Std.string(this.remote); 487 | case 4: 488 | return "same change: " + Std.string(this.parent) + " -> " + Std.string(this.local) + " / " + Std.string(this.remote); 489 | case 5: 490 | return this.change; 491 | } 492 | } 493 | }; 494 | coopy.ChangeType = { __ename__ : true, __constructs__ : ["NO_CHANGE","REMOTE_CHANGE","LOCAL_CHANGE","BOTH_CHANGE","SAME_CHANGE","NOTE_CHANGE"] }; 495 | coopy.ChangeType.NO_CHANGE = ["NO_CHANGE",0]; 496 | coopy.ChangeType.NO_CHANGE.toString = $estr; 497 | coopy.ChangeType.NO_CHANGE.__enum__ = coopy.ChangeType; 498 | coopy.ChangeType.REMOTE_CHANGE = ["REMOTE_CHANGE",1]; 499 | coopy.ChangeType.REMOTE_CHANGE.toString = $estr; 500 | coopy.ChangeType.REMOTE_CHANGE.__enum__ = coopy.ChangeType; 501 | coopy.ChangeType.LOCAL_CHANGE = ["LOCAL_CHANGE",2]; 502 | coopy.ChangeType.LOCAL_CHANGE.toString = $estr; 503 | coopy.ChangeType.LOCAL_CHANGE.__enum__ = coopy.ChangeType; 504 | coopy.ChangeType.BOTH_CHANGE = ["BOTH_CHANGE",3]; 505 | coopy.ChangeType.BOTH_CHANGE.toString = $estr; 506 | coopy.ChangeType.BOTH_CHANGE.__enum__ = coopy.ChangeType; 507 | coopy.ChangeType.SAME_CHANGE = ["SAME_CHANGE",4]; 508 | coopy.ChangeType.SAME_CHANGE.toString = $estr; 509 | coopy.ChangeType.SAME_CHANGE.__enum__ = coopy.ChangeType; 510 | coopy.ChangeType.NOTE_CHANGE = ["NOTE_CHANGE",5]; 511 | coopy.ChangeType.NOTE_CHANGE.toString = $estr; 512 | coopy.ChangeType.NOTE_CHANGE.__enum__ = coopy.ChangeType; 513 | coopy.Compare = $hx_exports.coopy.Compare = function() { 514 | }; 515 | coopy.Compare.__name__ = true; 516 | coopy.Compare.prototype = { 517 | compare: function(parent,local,remote,report) { 518 | var ws = new coopy.Workspace(); 519 | ws.parent = parent; 520 | ws.local = local; 521 | ws.remote = remote; 522 | ws.report = report; 523 | report.clear(); 524 | if(parent == null || local == null || remote == null) { 525 | report.changes.push(new coopy.Change("only 3-way comparison allowed right now")); 526 | return false; 527 | } 528 | if(parent.hasStructure() || local.hasStructure() || remote.hasStructure()) return this.compareStructured(ws); 529 | return this.comparePrimitive(ws); 530 | } 531 | ,compareStructured: function(ws) { 532 | ws.tparent = ws.parent.getTable(); 533 | ws.tlocal = ws.local.getTable(); 534 | ws.tremote = ws.remote.getTable(); 535 | if(ws.tparent == null || ws.tlocal == null || ws.tremote == null) { 536 | ws.report.changes.push(new coopy.Change("structured comparisons that include non-tables are not available yet")); 537 | return false; 538 | } 539 | return this.compareTable(ws); 540 | } 541 | ,compareTable: function(ws) { 542 | ws.p2l = new coopy.TableComparisonState(); 543 | ws.p2r = new coopy.TableComparisonState(); 544 | ws.p2l.a = ws.tparent; 545 | ws.p2l.b = ws.tlocal; 546 | ws.p2r.a = ws.tparent; 547 | ws.p2r.b = ws.tremote; 548 | var cmp = new coopy.CompareTable(); 549 | cmp.attach(ws.p2l); 550 | cmp.attach(ws.p2r); 551 | var c = new coopy.Change(); 552 | c.parent = ws.parent; 553 | c.local = ws.local; 554 | c.remote = ws.remote; 555 | if(ws.p2l.is_equal && !ws.p2r.is_equal) c.mode = coopy.ChangeType.REMOTE_CHANGE; else if(!ws.p2l.is_equal && ws.p2r.is_equal) c.mode = coopy.ChangeType.LOCAL_CHANGE; else if(!ws.p2l.is_equal && !ws.p2r.is_equal) { 556 | ws.l2r = new coopy.TableComparisonState(); 557 | ws.l2r.a = ws.tlocal; 558 | ws.l2r.b = ws.tremote; 559 | cmp.attach(ws.l2r); 560 | if(ws.l2r.is_equal) c.mode = coopy.ChangeType.SAME_CHANGE; else c.mode = coopy.ChangeType.BOTH_CHANGE; 561 | } else c.mode = coopy.ChangeType.NO_CHANGE; 562 | if(c.mode != coopy.ChangeType.NO_CHANGE) ws.report.changes.push(c); 563 | return true; 564 | } 565 | ,comparePrimitive: function(ws) { 566 | var sparent = ws.parent.toString(); 567 | var slocal = ws.local.toString(); 568 | var sremote = ws.remote.toString(); 569 | var c = new coopy.Change(); 570 | c.parent = ws.parent; 571 | c.local = ws.local; 572 | c.remote = ws.remote; 573 | if(sparent == slocal && sparent != sremote) c.mode = coopy.ChangeType.REMOTE_CHANGE; else if(sparent == sremote && sparent != slocal) c.mode = coopy.ChangeType.LOCAL_CHANGE; else if(slocal == sremote && sparent != slocal) c.mode = coopy.ChangeType.SAME_CHANGE; else if(sparent != slocal && sparent != sremote) c.mode = coopy.ChangeType.BOTH_CHANGE; else c.mode = coopy.ChangeType.NO_CHANGE; 574 | if(c.mode != coopy.ChangeType.NO_CHANGE) ws.report.changes.push(c); 575 | return true; 576 | } 577 | }; 578 | coopy.CompareFlags = $hx_exports.coopy.CompareFlags = function() { 579 | this.ordered = true; 580 | this.show_unchanged = false; 581 | this.unchanged_context = 1; 582 | this.always_show_order = false; 583 | this.never_show_order = true; 584 | this.show_unchanged_columns = false; 585 | this.unchanged_column_context = 1; 586 | this.always_show_header = true; 587 | this.acts = null; 588 | }; 589 | coopy.CompareFlags.__name__ = true; 590 | coopy.CompareFlags.prototype = { 591 | allowUpdate: function() { 592 | if(this.acts == null) return true; 593 | return this.acts.exists("update"); 594 | } 595 | ,allowInsert: function() { 596 | if(this.acts == null) return true; 597 | return this.acts.exists("insert"); 598 | } 599 | ,allowDelete: function() { 600 | if(this.acts == null) return true; 601 | return this.acts.exists("delete"); 602 | } 603 | }; 604 | coopy.CompareTable = $hx_exports.coopy.CompareTable = function() { 605 | }; 606 | coopy.CompareTable.__name__ = true; 607 | coopy.CompareTable.prototype = { 608 | attach: function(comp) { 609 | this.comp = comp; 610 | var more = this.compareCore(); 611 | while(more && comp.run_to_completion) more = this.compareCore(); 612 | return !more; 613 | } 614 | ,align: function() { 615 | var alignment = new coopy.Alignment(); 616 | this.alignCore(alignment); 617 | return alignment; 618 | } 619 | ,getComparisonState: function() { 620 | return this.comp; 621 | } 622 | ,alignCore: function(align) { 623 | if(this.comp.p == null) { 624 | this.alignCore2(align,this.comp.a,this.comp.b); 625 | return; 626 | } 627 | align.reference = new coopy.Alignment(); 628 | this.alignCore2(align,this.comp.p,this.comp.b); 629 | this.alignCore2(align.reference,this.comp.p,this.comp.a); 630 | align.meta.reference = align.reference.meta; 631 | } 632 | ,alignCore2: function(align,a,b) { 633 | if(align.meta == null) align.meta = new coopy.Alignment(); 634 | this.alignColumns(align.meta,a,b); 635 | var column_order = align.meta.toOrderPruned(false); 636 | var common_units = new Array(); 637 | var _g = 0; 638 | var _g1 = column_order.getList(); 639 | while(_g < _g1.length) { 640 | var unit = _g1[_g]; 641 | ++_g; 642 | if(unit.l >= 0 && unit.r >= 0 && unit.p != -1) common_units.push(unit); 643 | } 644 | align.range(a.get_height(),b.get_height()); 645 | align.tables(a,b); 646 | align.setRowlike(true); 647 | var w = a.get_width(); 648 | var ha = a.get_height(); 649 | var hb = b.get_height(); 650 | var av = a.getCellView(); 651 | var N = 5; 652 | var columns = new Array(); 653 | if(common_units.length > N) { 654 | var columns_eval = new Array(); 655 | var _g11 = 0; 656 | var _g2 = common_units.length; 657 | while(_g11 < _g2) { 658 | var i = _g11++; 659 | var ct = 0; 660 | var mem = new haxe.ds.StringMap(); 661 | var mem2 = new haxe.ds.StringMap(); 662 | var ca = common_units[i].l; 663 | var cb = common_units[i].r; 664 | var _g21 = 0; 665 | while(_g21 < ha) { 666 | var j = _g21++; 667 | var key = av.toString(a.getCell(ca,j)); 668 | if(!mem.exists(key)) { 669 | mem.set(key,1); 670 | ct++; 671 | } 672 | } 673 | var _g22 = 0; 674 | while(_g22 < hb) { 675 | var j1 = _g22++; 676 | var key1 = av.toString(b.getCell(cb,j1)); 677 | if(!mem2.exists(key1)) { 678 | mem2.set(key1,1); 679 | ct++; 680 | } 681 | } 682 | columns_eval.push([i,ct]); 683 | } 684 | var sorter = function(a1,b1) { 685 | if(a1[1] < b1[1]) return 1; 686 | if(a1[1] > b1[1]) return -1; 687 | return 0; 688 | }; 689 | columns_eval.sort(sorter); 690 | columns = Lambda.array(Lambda.map(columns_eval,function(v) { 691 | return v[0]; 692 | })); 693 | columns = columns.slice(0,N); 694 | } else { 695 | var _g12 = 0; 696 | var _g3 = common_units.length; 697 | while(_g12 < _g3) { 698 | var i1 = _g12++; 699 | columns.push(i1); 700 | } 701 | } 702 | var top = Math.round(Math.pow(2,columns.length)); 703 | var pending = new haxe.ds.IntMap(); 704 | var _g4 = 0; 705 | while(_g4 < ha) { 706 | var j2 = _g4++; 707 | pending.set(j2,j2); 708 | } 709 | var pending_ct = ha; 710 | var _g5 = 0; 711 | while(_g5 < top) { 712 | var k = _g5++; 713 | if(k == 0) continue; 714 | if(pending_ct == 0) break; 715 | var active_columns = new Array(); 716 | var kk = k; 717 | var at = 0; 718 | while(kk > 0) { 719 | if(kk % 2 == 1) active_columns.push(columns[at]); 720 | kk >>= 1; 721 | at++; 722 | } 723 | var index = new coopy.IndexPair(); 724 | var _g23 = 0; 725 | var _g13 = active_columns.length; 726 | while(_g23 < _g13) { 727 | var k1 = _g23++; 728 | var unit1 = common_units[active_columns[k1]]; 729 | index.addColumns(unit1.l,unit1.r); 730 | align.addIndexColumns(unit1); 731 | } 732 | index.indexTables(a,b); 733 | var h = a.get_height(); 734 | if(b.get_height() > h) h = b.get_height(); 735 | if(h < 1) h = 1; 736 | var wide_top_freq = index.getTopFreq(); 737 | var ratio = wide_top_freq; 738 | ratio /= h + 20; 739 | if(ratio >= 0.1) continue; 740 | if(this.indexes != null) this.indexes.push(index); 741 | var fixed = new Array(); 742 | var $it0 = pending.keys(); 743 | while( $it0.hasNext() ) { 744 | var j3 = $it0.next(); 745 | var cross = index.queryLocal(j3); 746 | var spot_a = cross.spot_a; 747 | var spot_b = cross.spot_b; 748 | if(spot_a != 1 || spot_b != 1) continue; 749 | fixed.push(j3); 750 | align.link(j3,cross.item_b.lst[0]); 751 | } 752 | var _g24 = 0; 753 | var _g14 = fixed.length; 754 | while(_g24 < _g14) { 755 | var j4 = _g24++; 756 | pending.remove(fixed[j4]); 757 | pending_ct--; 758 | } 759 | } 760 | align.link(0,0); 761 | } 762 | ,alignColumns: function(align,a,b) { 763 | align.range(a.get_width(),b.get_width()); 764 | align.tables(a,b); 765 | align.setRowlike(false); 766 | var slop = 5; 767 | var va = a.getCellView(); 768 | var vb = b.getCellView(); 769 | var ra_best = 0; 770 | var rb_best = 0; 771 | var ct_best = -1; 772 | var ma_best = null; 773 | var mb_best = null; 774 | var ra_header = 0; 775 | var rb_header = 0; 776 | var ra_uniques = 0; 777 | var rb_uniques = 0; 778 | var _g = 0; 779 | while(_g < slop) { 780 | var ra = _g++; 781 | if(ra >= a.get_height()) break; 782 | var _g1 = 0; 783 | while(_g1 < slop) { 784 | var rb = _g1++; 785 | if(rb >= b.get_height()) break; 786 | var ma = new haxe.ds.StringMap(); 787 | var mb = new haxe.ds.StringMap(); 788 | var ct = 0; 789 | var uniques = 0; 790 | var _g3 = 0; 791 | var _g2 = a.get_width(); 792 | while(_g3 < _g2) { 793 | var ca = _g3++; 794 | var key = va.toString(a.getCell(ca,ra)); 795 | if(ma.exists(key)) { 796 | ma.set(key,-1); 797 | uniques--; 798 | } else { 799 | ma.set(key,ca); 800 | uniques++; 801 | } 802 | } 803 | if(uniques > ra_uniques) { 804 | ra_header = ra; 805 | ra_uniques = uniques; 806 | } 807 | uniques = 0; 808 | var _g31 = 0; 809 | var _g21 = b.get_width(); 810 | while(_g31 < _g21) { 811 | var cb = _g31++; 812 | var key1 = vb.toString(b.getCell(cb,rb)); 813 | if(mb.exists(key1)) { 814 | mb.set(key1,-1); 815 | uniques--; 816 | } else { 817 | mb.set(key1,cb); 818 | uniques++; 819 | } 820 | } 821 | if(uniques > rb_uniques) { 822 | rb_header = rb; 823 | rb_uniques = uniques; 824 | } 825 | var $it0 = ma.keys(); 826 | while( $it0.hasNext() ) { 827 | var key2 = $it0.next(); 828 | var i0 = ma.get(key2); 829 | var i1 = mb.get(key2); 830 | if(i1 != null) { 831 | if(i1 >= 0 && i0 >= 0) ct++; 832 | } 833 | } 834 | if(ct > ct_best) { 835 | ct_best = ct; 836 | ma_best = ma; 837 | mb_best = mb; 838 | ra_best = ra; 839 | rb_best = rb; 840 | } 841 | } 842 | } 843 | if(ma_best == null) return; 844 | var $it1 = ma_best.keys(); 845 | while( $it1.hasNext() ) { 846 | var key3 = $it1.next(); 847 | var i01 = ma_best.get(key3); 848 | var i11 = mb_best.get(key3); 849 | if(i11 != null && i01 != null) align.link(i01,i11); 850 | } 851 | align.headers(ra_header,rb_header); 852 | } 853 | ,testHasSameColumns: function() { 854 | var p = this.comp.p; 855 | var a = this.comp.a; 856 | var b = this.comp.b; 857 | var eq = this.hasSameColumns2(a,b); 858 | if(eq && p != null) eq = this.hasSameColumns2(p,a); 859 | this.comp.has_same_columns = eq; 860 | this.comp.has_same_columns_known = true; 861 | return true; 862 | } 863 | ,hasSameColumns2: function(a,b) { 864 | if(a.get_width() != b.get_width()) return false; 865 | if(a.get_height() == 0 || b.get_height() == 0) return true; 866 | var av = a.getCellView(); 867 | var _g1 = 0; 868 | var _g = a.get_width(); 869 | while(_g1 < _g) { 870 | var i = _g1++; 871 | var _g3 = i + 1; 872 | var _g2 = a.get_width(); 873 | while(_g3 < _g2) { 874 | var j = _g3++; 875 | if(av.equals(a.getCell(i,0),a.getCell(j,0))) return false; 876 | } 877 | if(!av.equals(a.getCell(i,0),b.getCell(i,0))) return false; 878 | } 879 | return true; 880 | } 881 | ,testIsEqual: function() { 882 | var p = this.comp.p; 883 | var a = this.comp.a; 884 | var b = this.comp.b; 885 | var eq = this.isEqual2(a,b); 886 | if(eq && p != null) eq = this.isEqual2(p,a); 887 | this.comp.is_equal = eq; 888 | this.comp.is_equal_known = true; 889 | return true; 890 | } 891 | ,isEqual2: function(a,b) { 892 | if(a.get_width() != b.get_width() || a.get_height() != b.get_height()) return false; 893 | var av = a.getCellView(); 894 | var _g1 = 0; 895 | var _g = a.get_height(); 896 | while(_g1 < _g) { 897 | var i = _g1++; 898 | var _g3 = 0; 899 | var _g2 = a.get_width(); 900 | while(_g3 < _g2) { 901 | var j = _g3++; 902 | if(!av.equals(a.getCell(j,i),b.getCell(j,i))) return false; 903 | } 904 | } 905 | return true; 906 | } 907 | ,compareCore: function() { 908 | if(this.comp.completed) return false; 909 | if(!this.comp.is_equal_known) return this.testIsEqual(); 910 | if(!this.comp.has_same_columns_known) return this.testHasSameColumns(); 911 | this.comp.completed = true; 912 | return false; 913 | } 914 | ,storeIndexes: function() { 915 | this.indexes = new Array(); 916 | } 917 | ,getIndexes: function() { 918 | return this.indexes; 919 | } 920 | }; 921 | coopy.Coopy = $hx_exports.coopy.Coopy = function() { 922 | }; 923 | coopy.Coopy.__name__ = true; 924 | coopy.Coopy.compareTables = function(local,remote) { 925 | var ct = new coopy.CompareTable(); 926 | var comp = new coopy.TableComparisonState(); 927 | comp.a = local; 928 | comp.b = remote; 929 | ct.attach(comp); 930 | return ct; 931 | }; 932 | coopy.Coopy.compareTables3 = function(parent,local,remote) { 933 | var ct = new coopy.CompareTable(); 934 | var comp = new coopy.TableComparisonState(); 935 | comp.p = parent; 936 | comp.a = local; 937 | comp.b = remote; 938 | ct.attach(comp); 939 | return ct; 940 | }; 941 | coopy.Coopy.randomTests = function() { 942 | var st = new coopy.SimpleTable(15,6); 943 | var tab = st; 944 | console.log("table size is " + tab.get_width() + "x" + tab.get_height()); 945 | tab.setCell(3,4,new coopy.SimpleCell(33)); 946 | console.log("element is " + Std.string(tab.getCell(3,4))); 947 | var compare = new coopy.Compare(); 948 | var d1 = coopy.ViewedDatum.getSimpleView(new coopy.SimpleCell(10)); 949 | var d2 = coopy.ViewedDatum.getSimpleView(new coopy.SimpleCell(10)); 950 | var d3 = coopy.ViewedDatum.getSimpleView(new coopy.SimpleCell(20)); 951 | var report = new coopy.Report(); 952 | compare.compare(d1,d2,d3,report); 953 | console.log("report is " + Std.string(report)); 954 | d2 = coopy.ViewedDatum.getSimpleView(new coopy.SimpleCell(50)); 955 | report.clear(); 956 | compare.compare(d1,d2,d3,report); 957 | console.log("report is " + Std.string(report)); 958 | d2 = coopy.ViewedDatum.getSimpleView(new coopy.SimpleCell(20)); 959 | report.clear(); 960 | compare.compare(d1,d2,d3,report); 961 | console.log("report is " + Std.string(report)); 962 | d1 = coopy.ViewedDatum.getSimpleView(new coopy.SimpleCell(20)); 963 | report.clear(); 964 | compare.compare(d1,d2,d3,report); 965 | console.log("report is " + Std.string(report)); 966 | var comp = new coopy.TableComparisonState(); 967 | var ct = new coopy.CompareTable(); 968 | comp.a = st; 969 | comp.b = st; 970 | ct.attach(comp); 971 | console.log("comparing tables"); 972 | var t1 = new coopy.SimpleTable(3,2); 973 | var t2 = new coopy.SimpleTable(3,2); 974 | var t3 = new coopy.SimpleTable(3,2); 975 | var dt1 = new coopy.ViewedDatum(t1,new coopy.SimpleView()); 976 | var dt2 = new coopy.ViewedDatum(t2,new coopy.SimpleView()); 977 | var dt3 = new coopy.ViewedDatum(t3,new coopy.SimpleView()); 978 | compare.compare(dt1,dt2,dt3,report); 979 | console.log("report is " + Std.string(report)); 980 | t3.setCell(1,1,new coopy.SimpleCell("hello")); 981 | compare.compare(dt1,dt2,dt3,report); 982 | console.log("report is " + Std.string(report)); 983 | t1.setCell(1,1,new coopy.SimpleCell("hello")); 984 | compare.compare(dt1,dt2,dt3,report); 985 | console.log("report is " + Std.string(report)); 986 | var v = new coopy.Viterbi(); 987 | var td = new coopy.TableDiff(null,null); 988 | var idx = new coopy.Index(); 989 | var dr = new coopy.DiffRender(); 990 | var cf = new coopy.CompareFlags(); 991 | var hp = new coopy.HighlightPatch(null,null); 992 | var csv = new coopy.Csv(); 993 | var tm = new coopy.TableModifier(null); 994 | return 0; 995 | }; 996 | coopy.Coopy.cellFor = function(x) { 997 | if(x == null) return null; 998 | return new coopy.SimpleCell(x); 999 | }; 1000 | coopy.Coopy.jsonToTable = function(json) { 1001 | var output = null; 1002 | var _g = 0; 1003 | var _g1 = Reflect.fields(json); 1004 | while(_g < _g1.length) { 1005 | var name = _g1[_g]; 1006 | ++_g; 1007 | var t = Reflect.field(json,name); 1008 | var columns = Reflect.field(t,"columns"); 1009 | if(columns == null) continue; 1010 | var rows = Reflect.field(t,"rows"); 1011 | if(rows == null) continue; 1012 | output = new coopy.SimpleTable(columns.length,rows.length); 1013 | var has_hash = false; 1014 | var has_hash_known = false; 1015 | var _g3 = 0; 1016 | var _g2 = rows.length; 1017 | while(_g3 < _g2) { 1018 | var i = _g3++; 1019 | var row = rows[i]; 1020 | if(!has_hash_known) { 1021 | if(Reflect.fields(row).length == columns.length) has_hash = true; 1022 | has_hash_known = true; 1023 | } 1024 | if(!has_hash) { 1025 | var lst = row; 1026 | var _g5 = 0; 1027 | var _g4 = columns.length; 1028 | while(_g5 < _g4) { 1029 | var j = _g5++; 1030 | var val = lst[j]; 1031 | output.setCell(j,i,coopy.Coopy.cellFor(val)); 1032 | } 1033 | } else { 1034 | var _g51 = 0; 1035 | var _g41 = columns.length; 1036 | while(_g51 < _g41) { 1037 | var j1 = _g51++; 1038 | var val1 = Reflect.field(row,columns[j1]); 1039 | output.setCell(j1,i,coopy.Coopy.cellFor(val1)); 1040 | } 1041 | } 1042 | } 1043 | } 1044 | if(output != null) output.trimBlank(); 1045 | return output; 1046 | }; 1047 | coopy.Coopy.main = function() { 1048 | return 0; 1049 | }; 1050 | coopy.Coopy.show = function(t) { 1051 | var w = t.get_width(); 1052 | var h = t.get_height(); 1053 | var txt = ""; 1054 | var _g = 0; 1055 | while(_g < h) { 1056 | var y = _g++; 1057 | var _g1 = 0; 1058 | while(_g1 < w) { 1059 | var x = _g1++; 1060 | txt += Std.string(t.getCell(x,y)); 1061 | txt += " "; 1062 | } 1063 | txt += "\n"; 1064 | } 1065 | console.log(txt); 1066 | }; 1067 | coopy.Coopy.jsonify = function(t) { 1068 | var workbook = new haxe.ds.StringMap(); 1069 | var sheet = new Array(); 1070 | var w = t.get_width(); 1071 | var h = t.get_height(); 1072 | var txt = ""; 1073 | var _g = 0; 1074 | while(_g < h) { 1075 | var y = _g++; 1076 | var row = new Array(); 1077 | var _g1 = 0; 1078 | while(_g1 < w) { 1079 | var x = _g1++; 1080 | var v = t.getCell(x,y); 1081 | if(v != null) row.push(v.toString()); else row.push(null); 1082 | } 1083 | sheet.push(row); 1084 | } 1085 | workbook.set("sheet",sheet); 1086 | return workbook; 1087 | }; 1088 | coopy.Coopy.prototype = { 1089 | saveTable: function(name,t) { 1090 | var txt = ""; 1091 | if(this.format_preference != "json") { 1092 | var csv = new coopy.Csv(); 1093 | txt = csv.renderTable(t); 1094 | } else txt = JSON.stringify(coopy.Coopy.jsonify(t)); 1095 | return this.saveText(name,txt); 1096 | } 1097 | ,saveText: function(name,txt) { 1098 | if(name != "-") this.io.saveContent(name,txt); else this.io.writeStdout(txt); 1099 | return true; 1100 | } 1101 | ,loadTable: function(name) { 1102 | var txt = this.io.getContent(name); 1103 | try { 1104 | var json = JSON.parse(txt); 1105 | this.format_preference = "json"; 1106 | var t = coopy.Coopy.jsonToTable(json); 1107 | if(t == null) throw "JSON failed"; 1108 | return t; 1109 | } catch( e ) { 1110 | var csv = new coopy.Csv(); 1111 | this.format_preference = "csv"; 1112 | var data = csv.parseTable(txt); 1113 | var h = data.length; 1114 | var w = 0; 1115 | if(h > 0) w = data[0].length; 1116 | var output = new coopy.SimpleTable(w,h); 1117 | var _g = 0; 1118 | while(_g < h) { 1119 | var i = _g++; 1120 | var _g1 = 0; 1121 | while(_g1 < w) { 1122 | var j = _g1++; 1123 | var val = data[i][j]; 1124 | output.setCell(j,i,coopy.Coopy.cellFor(val)); 1125 | } 1126 | } 1127 | if(output != null) output.trimBlank(); 1128 | return output; 1129 | } 1130 | } 1131 | ,command: function(io,cmd,args) { 1132 | var r = 0; 1133 | if(io.async()) r = io.command(cmd,args); 1134 | if(r != 999) { 1135 | io.writeStdout("$ " + cmd); 1136 | var _g = 0; 1137 | while(_g < args.length) { 1138 | var arg = args[_g]; 1139 | ++_g; 1140 | io.writeStdout(" "); 1141 | var spaced = arg.indexOf(" ") >= 0; 1142 | if(spaced) io.writeStdout("\""); 1143 | io.writeStdout(arg); 1144 | if(spaced) io.writeStdout("\""); 1145 | } 1146 | io.writeStdout("\n"); 1147 | } 1148 | if(!io.async()) r = io.command(cmd,args); 1149 | return r; 1150 | } 1151 | ,installGitDriver: function(io,formats) { 1152 | var r = 0; 1153 | if(this.status == null) { 1154 | this.status = new haxe.ds.StringMap(); 1155 | this.daff_cmd = ""; 1156 | } 1157 | var key = "hello"; 1158 | if(!this.status.exists(key)) { 1159 | io.writeStdout("Setting up git to use daff on"); 1160 | var _g = 0; 1161 | while(_g < formats.length) { 1162 | var format = formats[_g]; 1163 | ++_g; 1164 | io.writeStdout(" *." + format); 1165 | } 1166 | io.writeStdout(" files\n"); 1167 | this.status.set(key,r); 1168 | } 1169 | key = "can_run_git"; 1170 | if(!this.status.exists(key)) { 1171 | r = this.command(io,"git",["--version"]); 1172 | if(r == 999) return r; 1173 | this.status.set(key,r); 1174 | if(r != 0) { 1175 | io.writeStderr("! Cannot run git, aborting\n"); 1176 | return 1; 1177 | } 1178 | io.writeStdout("- Can run git\n"); 1179 | } 1180 | var daffs = ["daff","daff.rb","daff.py"]; 1181 | if(this.daff_cmd == "") { 1182 | var _g1 = 0; 1183 | while(_g1 < daffs.length) { 1184 | var daff = daffs[_g1]; 1185 | ++_g1; 1186 | var key1 = "can_run_" + daff; 1187 | if(!this.status.exists(key1)) { 1188 | r = this.command(io,daff,["version"]); 1189 | if(r == 999) return r; 1190 | this.status.set(key1,r); 1191 | if(r == 0) { 1192 | this.daff_cmd = daff; 1193 | io.writeStdout("- Can run " + daff + " as \"" + daff + "\"\n"); 1194 | break; 1195 | } 1196 | } 1197 | } 1198 | if(this.daff_cmd == "") { 1199 | io.writeStderr("! Cannot find daff, is it in your path?\n"); 1200 | return 1; 1201 | } 1202 | } 1203 | var _g2 = 0; 1204 | while(_g2 < formats.length) { 1205 | var format1 = formats[_g2]; 1206 | ++_g2; 1207 | key = "have_diff_driver_" + format1; 1208 | if(!this.status.exists(key)) { 1209 | r = this.command(io,"git",["config","--global","--get","diff.daff-" + format1 + ".command"]); 1210 | if(r == 999) return r; 1211 | this.status.set(key,r); 1212 | } 1213 | var have_diff_driver = this.status.get(key) == 0; 1214 | key = "add_diff_driver_" + format1; 1215 | if(!this.status.exists(key)) { 1216 | if(!have_diff_driver) { 1217 | r = this.command(io,"git",["config","--global","diff.daff-" + format1 + ".command",this.daff_cmd + " diff --color --git"]); 1218 | if(r == 999) return r; 1219 | io.writeStdout("- Added diff driver for " + format1 + "\n"); 1220 | } else { 1221 | r = 0; 1222 | io.writeStdout("- Already have diff driver for " + format1 + ", not touching it\n"); 1223 | } 1224 | this.status.set(key,r); 1225 | } 1226 | key = "have_merge_driver_" + format1; 1227 | if(!this.status.exists(key)) { 1228 | r = this.command(io,"git",["config","--global","--get","merge.daff-" + format1 + ".driver"]); 1229 | if(r == 999) return r; 1230 | this.status.set(key,r); 1231 | } 1232 | var have_merge_driver = this.status.get(key) == 0; 1233 | key = "name_merge_driver_" + format1; 1234 | if(!this.status.exists(key)) { 1235 | if(!have_merge_driver) { 1236 | r = this.command(io,"git",["config","--global","merge.daff-" + format1 + ".name","daff tabular " + format1 + " merge"]); 1237 | if(r == 999) return r; 1238 | } else r = 0; 1239 | this.status.set(key,r); 1240 | } 1241 | key = "add_merge_driver_" + format1; 1242 | if(!this.status.exists(key)) { 1243 | if(!have_merge_driver) { 1244 | r = this.command(io,"git",["config","--global","merge.daff-" + format1 + ".driver",this.daff_cmd + " merge --output %A %O %A %B"]); 1245 | if(r == 999) return r; 1246 | io.writeStdout("- Added merge driver for " + format1 + "\n"); 1247 | } else { 1248 | r = 0; 1249 | io.writeStdout("- Already have merge driver for " + format1 + ", not touching it\n"); 1250 | } 1251 | this.status.set(key,r); 1252 | } 1253 | } 1254 | if(!io.exists(".git/config")) { 1255 | io.writeStderr("! This next part needs to happen in a git repository.\n"); 1256 | io.writeStderr("! Please run again from the root of a git repository.\n"); 1257 | return 1; 1258 | } 1259 | var attr = ".gitattributes"; 1260 | var txt = ""; 1261 | var post = ""; 1262 | if(!io.exists(attr)) io.writeStdout("- No .gitattributes file\n"); else { 1263 | io.writeStdout("- You have a .gitattributes file\n"); 1264 | txt = io.getContent(attr); 1265 | } 1266 | var need_update = false; 1267 | var _g3 = 0; 1268 | while(_g3 < formats.length) { 1269 | var format2 = formats[_g3]; 1270 | ++_g3; 1271 | if(txt.indexOf("*." + format2) >= 0) io.writeStderr("- Your .gitattributes file already mentions *." + format2 + "\n"); else { 1272 | post += "*." + format2 + " diff=daff-" + format2 + "\n"; 1273 | post += "*." + format2 + " merge=daff-" + format2 + "\n"; 1274 | io.writeStdout("- Placing the following lines in .gitattributes:\n"); 1275 | io.writeStdout(post); 1276 | if(txt != "" && !need_update) txt += "\n"; 1277 | txt += post; 1278 | need_update = true; 1279 | } 1280 | } 1281 | if(need_update) io.saveContent(attr,txt); 1282 | io.writeStdout("- Done!\n"); 1283 | return 0; 1284 | } 1285 | ,coopyhx: function(io) { 1286 | var args = io.args(); 1287 | if(args[0] == "--test") return coopy.Coopy.randomTests(); 1288 | var more = true; 1289 | var output = null; 1290 | var css_output = null; 1291 | var fragment = false; 1292 | var pretty = true; 1293 | var inplace = false; 1294 | var git = false; 1295 | var color = false; 1296 | var flags = new coopy.CompareFlags(); 1297 | flags.always_show_header = true; 1298 | while(more) { 1299 | more = false; 1300 | var _g1 = 0; 1301 | var _g = args.length; 1302 | while(_g1 < _g) { 1303 | var i = _g1++; 1304 | var tag = args[i]; 1305 | if(tag == "--output") { 1306 | more = true; 1307 | output = args[i + 1]; 1308 | args.splice(i,2); 1309 | break; 1310 | } else if(tag == "--css") { 1311 | more = true; 1312 | fragment = true; 1313 | css_output = args[i + 1]; 1314 | args.splice(i,2); 1315 | break; 1316 | } else if(tag == "--fragment") { 1317 | more = true; 1318 | fragment = true; 1319 | args.splice(i,1); 1320 | break; 1321 | } else if(tag == "--plain") { 1322 | more = true; 1323 | pretty = false; 1324 | args.splice(i,1); 1325 | break; 1326 | } else if(tag == "--all") { 1327 | more = true; 1328 | flags.show_unchanged = true; 1329 | args.splice(i,1); 1330 | break; 1331 | } else if(tag == "--act") { 1332 | more = true; 1333 | if(flags.acts == null) flags.acts = new haxe.ds.StringMap(); 1334 | flags.acts.set(args[i + 1],true); 1335 | true; 1336 | args.splice(i,2); 1337 | break; 1338 | } else if(tag == "--context") { 1339 | more = true; 1340 | var context = Std.parseInt(args[i + 1]); 1341 | if(context >= 0) flags.unchanged_context = context; 1342 | args.splice(i,2); 1343 | break; 1344 | } else if(tag == "--inplace") { 1345 | more = true; 1346 | inplace = true; 1347 | args.splice(i,1); 1348 | break; 1349 | } else if(tag == "--git") { 1350 | more = true; 1351 | git = true; 1352 | args.splice(i,1); 1353 | break; 1354 | } else if(tag == "--color") { 1355 | more = true; 1356 | color = true; 1357 | args.splice(i,1); 1358 | break; 1359 | } 1360 | } 1361 | } 1362 | var cmd = args[0]; 1363 | if(args.length < 2) { 1364 | if(cmd == "version") { 1365 | io.writeStdout(coopy.Coopy.VERSION + "\n"); 1366 | return 0; 1367 | } 1368 | if(cmd == "git") { 1369 | io.writeStdout("You can use daff to improve git's handling of csv files, by using it as a\ndiff driver (for showing what has changed) and as a merge driver (for merging\nchanges between multiple versions).\n"); 1370 | io.writeStdout("\n"); 1371 | io.writeStdout("Automatic setup\n"); 1372 | io.writeStdout("---------------\n\n"); 1373 | io.writeStdout("Run:\n"); 1374 | io.writeStdout(" daff git csv\n"); 1375 | io.writeStdout("\n"); 1376 | io.writeStdout("Manual setup\n"); 1377 | io.writeStdout("------------\n\n"); 1378 | io.writeStdout("Create and add a file called .gitattributes in the root directory of your\nrepository, containing:\n\n"); 1379 | io.writeStdout(" *.csv diff=daff-csv\n"); 1380 | io.writeStdout(" *.csv merge=daff-csv\n"); 1381 | io.writeStdout("\nCreate a file called .gitconfig in your home directory (or alternatively\nopen .git/config for a particular repository) and add:\n\n"); 1382 | io.writeStdout(" [diff \"daff-csv\"]\n"); 1383 | io.writeStdout(" command = daff diff --color --git\n"); 1384 | io.writeStderr("\n"); 1385 | io.writeStdout(" [merge \"daff-csv\"]\n"); 1386 | io.writeStdout(" name = daff tabular merge\n"); 1387 | io.writeStdout(" driver = daff merge --output %A %O %A %B\n\n"); 1388 | io.writeStderr("Make sure you can run daff from the command-line as just \"daff\" - if not,\nreplace \"daff\" in the driver and command lines above with the correct way\nto call it. Omit --color if your terminal does not support ANSI colors."); 1389 | io.writeStderr("\n"); 1390 | return 0; 1391 | } 1392 | io.writeStderr("daff can produce and apply tabular diffs.\n"); 1393 | io.writeStderr("Call as:\n"); 1394 | io.writeStderr(" daff [--color] [--output OUTPUT.csv] a.csv b.csv\n"); 1395 | io.writeStderr(" daff [--output OUTPUT.csv] parent.csv a.csv b.csv\n"); 1396 | io.writeStderr(" daff [--output OUTPUT.jsonbook] a.jsonbook b.jsonbook\n"); 1397 | io.writeStderr(" daff patch [--inplace] [--output OUTPUT.csv] a.csv patch.csv\n"); 1398 | io.writeStderr(" daff merge [--inplace] [--output OUTPUT.csv] parent.csv a.csv b.csv\n"); 1399 | io.writeStderr(" daff trim [--output OUTPUT.csv] source.csv\n"); 1400 | io.writeStderr(" daff render [--output OUTPUT.html] diff.csv\n"); 1401 | io.writeStderr(" daff git\n"); 1402 | io.writeStderr(" daff version\n"); 1403 | io.writeStderr("\n"); 1404 | io.writeStderr("The --inplace option to patch and merge will result in modification of a.csv.\n"); 1405 | io.writeStderr("\n"); 1406 | io.writeStderr("If you need more control, here is the full list of flags:\n"); 1407 | io.writeStderr(" daff diff [--output OUTPUT.csv] [--context NUM] [--all] [--act ACT] a.csv b.csv\n"); 1408 | io.writeStderr(" --color: highlight changes with terminal colors\n"); 1409 | io.writeStderr(" --context NUM: show NUM rows of context\n"); 1410 | io.writeStderr(" --all: do not prune unchanged rows\n"); 1411 | io.writeStderr(" --act ACT: show only a certain kind of change (update, insert, delete)\n"); 1412 | io.writeStderr("\n"); 1413 | io.writeStderr(" daff diff --git path old-file old-hex old-mode new-file new-hex new-mode\n"); 1414 | io.writeStderr(" --git: process arguments provided by git to diff drivers\n"); 1415 | io.writeStderr("\n"); 1416 | io.writeStderr(" daff render [--output OUTPUT.html] [--css CSS.css] [--fragment] [--plain] diff.csv\n"); 1417 | io.writeStderr(" --css CSS.css: generate a suitable css file to go with the html\n"); 1418 | io.writeStderr(" --fragment: generate just a html fragment rather than a page\n"); 1419 | io.writeStderr(" --plain: do not use fancy utf8 characters to make arrows prettier\n"); 1420 | return 1; 1421 | } 1422 | var cmd1 = args[0]; 1423 | var offset = 1; 1424 | if(!Lambda.has(["diff","patch","merge","trim","render","git","version"],cmd1)) { 1425 | if(cmd1.indexOf(".") != -1 || cmd1.indexOf("--") == 0) { 1426 | cmd1 = "diff"; 1427 | offset = 0; 1428 | } 1429 | } 1430 | if(cmd1 == "git") { 1431 | var types = args.splice(offset,args.length - offset); 1432 | return this.installGitDriver(io,types); 1433 | } 1434 | if(git) { 1435 | var ct = args.length - offset; 1436 | if(ct != 7) { 1437 | io.writeStderr("Expected 7 parameters from git, but got " + ct + "\n"); 1438 | return 1; 1439 | } 1440 | var git_args = args.splice(offset,ct); 1441 | args.splice(0,args.length); 1442 | offset = 0; 1443 | var path = git_args[0]; 1444 | var old_file = git_args[1]; 1445 | var new_file = git_args[4]; 1446 | io.writeStdout("--- a/" + path + "\n"); 1447 | io.writeStdout("+++ b/" + path + "\n"); 1448 | args.push(old_file); 1449 | args.push(new_file); 1450 | } 1451 | var tool = new coopy.Coopy(); 1452 | tool.io = io; 1453 | var parent = null; 1454 | if(args.length - offset >= 3) { 1455 | parent = tool.loadTable(args[offset]); 1456 | offset++; 1457 | } 1458 | var aname = args[offset]; 1459 | var a = tool.loadTable(aname); 1460 | var b = null; 1461 | if(args.length - offset >= 2) b = tool.loadTable(args[1 + offset]); 1462 | if(inplace) { 1463 | if(output != null) io.writeStderr("Please do not use --inplace when specifying an output.\n"); 1464 | output = aname; 1465 | return 1; 1466 | } 1467 | if(output == null) output = "-"; 1468 | var ok = true; 1469 | if(cmd1 == "diff") { 1470 | var ct1 = coopy.Coopy.compareTables3(parent,a,b); 1471 | var align = ct1.align(); 1472 | var td = new coopy.TableDiff(align,flags); 1473 | var o = new coopy.SimpleTable(0,0); 1474 | td.hilite(o); 1475 | if(color) { 1476 | var render = new coopy.TerminalDiffRender(); 1477 | tool.saveText(output,render.render(o)); 1478 | } else tool.saveTable(output,o); 1479 | } else if(cmd1 == "patch") { 1480 | var patcher = new coopy.HighlightPatch(a,b); 1481 | patcher.apply(); 1482 | tool.saveTable(output,a); 1483 | } else if(cmd1 == "merge") { 1484 | var merger = new coopy.Merger(parent,a,b,flags); 1485 | var conflicts = merger.apply(); 1486 | ok = conflicts == 0; 1487 | if(conflicts > 0) io.writeStderr(conflicts + " conflict" + (conflicts > 1?"s":"") + "\n"); 1488 | tool.saveTable(output,a); 1489 | } else if(cmd1 == "trim") tool.saveTable(output,a); else if(cmd1 == "render") { 1490 | var renderer = new coopy.DiffRender(); 1491 | renderer.usePrettyArrows(pretty); 1492 | renderer.render(a); 1493 | if(!fragment) renderer.completeHtml(); 1494 | tool.saveText(output,renderer.html()); 1495 | if(css_output != null) tool.saveText(css_output,renderer.sampleCss()); 1496 | } 1497 | if(ok) return 0; else return 1; 1498 | } 1499 | }; 1500 | coopy.CrossMatch = function() { 1501 | }; 1502 | coopy.CrossMatch.__name__ = true; 1503 | coopy.Csv = $hx_exports.coopy.Csv = function() { 1504 | this.cursor = 0; 1505 | this.row_ended = false; 1506 | }; 1507 | coopy.Csv.__name__ = true; 1508 | coopy.Csv.prototype = { 1509 | renderTable: function(t) { 1510 | var result = ""; 1511 | var w = t.get_width(); 1512 | var h = t.get_height(); 1513 | var txt = ""; 1514 | var v = t.getCellView(); 1515 | var _g = 0; 1516 | while(_g < h) { 1517 | var y = _g++; 1518 | var _g1 = 0; 1519 | while(_g1 < w) { 1520 | var x = _g1++; 1521 | if(x > 0) txt += ","; 1522 | txt += this.renderCell(v,t.getCell(x,y)); 1523 | } 1524 | txt += "\r\n"; 1525 | } 1526 | return txt; 1527 | } 1528 | ,renderCell: function(v,d) { 1529 | if(d == null) return "NULL"; 1530 | var str = v.toString(d); 1531 | var delim = ","; 1532 | var need_quote = false; 1533 | var _g1 = 0; 1534 | var _g = str.length; 1535 | while(_g1 < _g) { 1536 | var i = _g1++; 1537 | var ch = str.charAt(i); 1538 | if(ch == "\"" || ch == "'" || ch == delim || ch == "\r" || ch == "\n" || ch == "\t" || ch == " ") { 1539 | need_quote = true; 1540 | break; 1541 | } 1542 | } 1543 | var result = ""; 1544 | if(need_quote) result += "\""; 1545 | var line_buf = ""; 1546 | var _g11 = 0; 1547 | var _g2 = str.length; 1548 | while(_g11 < _g2) { 1549 | var i1 = _g11++; 1550 | var ch1 = str.charAt(i1); 1551 | if(ch1 == "\"") result += "\""; 1552 | if(ch1 != "\r" && ch1 != "\n") { 1553 | if(line_buf.length > 0) { 1554 | result += line_buf; 1555 | line_buf = ""; 1556 | } 1557 | result += ch1; 1558 | } else line_buf += ch1; 1559 | } 1560 | if(need_quote) result += "\""; 1561 | return result; 1562 | } 1563 | ,parseTable: function(txt) { 1564 | this.cursor = 0; 1565 | this.row_ended = false; 1566 | this.has_structure = true; 1567 | var result = new Array(); 1568 | var row = new Array(); 1569 | while(this.cursor < txt.length) { 1570 | var cell = this.parseCell(txt); 1571 | row.push(cell); 1572 | if(this.row_ended) { 1573 | result.push(row); 1574 | row = new Array(); 1575 | } 1576 | this.cursor++; 1577 | } 1578 | return result; 1579 | } 1580 | ,parseCell: function(txt) { 1581 | if(txt == null) return null; 1582 | this.row_ended = false; 1583 | var first_non_underscore = txt.length; 1584 | var last_processed = 0; 1585 | var quoting = false; 1586 | var quote = 0; 1587 | var result = ""; 1588 | var start = this.cursor; 1589 | var _g1 = this.cursor; 1590 | var _g = txt.length; 1591 | while(_g1 < _g) { 1592 | var i = _g1++; 1593 | var ch = HxOverrides.cca(txt,i); 1594 | last_processed = i; 1595 | if(ch != 95 && i < first_non_underscore) first_non_underscore = i; 1596 | if(this.has_structure) { 1597 | if(!quoting) { 1598 | if(ch == 44) break; 1599 | if(ch == 13 || ch == 10) { 1600 | var ch2 = HxOverrides.cca(txt,i + 1); 1601 | if(ch2 != null) { 1602 | if(ch2 != ch) { 1603 | if(ch2 == 13 || ch2 == 10) last_processed++; 1604 | } 1605 | } 1606 | this.row_ended = true; 1607 | break; 1608 | } 1609 | if(ch == 34 || ch == 39) { 1610 | if(i == this.cursor) { 1611 | quoting = true; 1612 | quote = ch; 1613 | if(i != start) result += String.fromCharCode(ch); 1614 | continue; 1615 | } else if(ch == quote) quoting = true; 1616 | } 1617 | result += String.fromCharCode(ch); 1618 | continue; 1619 | } 1620 | if(ch == quote) { 1621 | quoting = false; 1622 | continue; 1623 | } 1624 | } 1625 | result += String.fromCharCode(ch); 1626 | } 1627 | this.cursor = last_processed; 1628 | if(quote == 0) { 1629 | if(result == "NULL") return null; 1630 | if(first_non_underscore > start) { 1631 | var del = first_non_underscore - start; 1632 | if(HxOverrides.substr(result,del,null) == "NULL") return HxOverrides.substr(result,1,null); 1633 | } 1634 | } 1635 | return result; 1636 | } 1637 | ,parseSingleCell: function(txt) { 1638 | this.cursor = 0; 1639 | this.row_ended = false; 1640 | this.has_structure = false; 1641 | return this.parseCell(txt); 1642 | } 1643 | }; 1644 | coopy.DiffRender = $hx_exports.coopy.DiffRender = function() { 1645 | this.text_to_insert = new Array(); 1646 | this.open = false; 1647 | this.pretty_arrows = true; 1648 | }; 1649 | coopy.DiffRender.__name__ = true; 1650 | coopy.DiffRender.examineCell = function(x,y,value,vcol,vrow,vcorner,cell) { 1651 | cell.category = ""; 1652 | cell.category_given_tr = ""; 1653 | cell.separator = ""; 1654 | cell.pretty_separator = ""; 1655 | cell.conflicted = false; 1656 | cell.updated = false; 1657 | cell.pvalue = cell.lvalue = cell.rvalue = null; 1658 | cell.value = value; 1659 | if(cell.value == null) cell.value = ""; 1660 | cell.pretty_value = cell.value; 1661 | if(vrow == null) vrow = ""; 1662 | if(vcol == null) vcol = ""; 1663 | var removed_column = false; 1664 | if(vrow == ":") cell.category = "move"; 1665 | if(vcol.indexOf("+++") >= 0) cell.category_given_tr = cell.category = "add"; else if(vcol.indexOf("---") >= 0) { 1666 | cell.category_given_tr = cell.category = "remove"; 1667 | removed_column = true; 1668 | } 1669 | if(vrow == "!") cell.category = "spec"; else if(vrow == "@@") cell.category = "header"; else if(vrow == "+++") { 1670 | if(!removed_column) cell.category = "add"; 1671 | } else if(vrow == "---") cell.category = "remove"; else if(vrow.indexOf("->") >= 0) { 1672 | if(!removed_column) { 1673 | var tokens = vrow.split("!"); 1674 | var full = vrow; 1675 | var part = tokens[1]; 1676 | if(part == null) part = full; 1677 | if(cell.value.indexOf(part) >= 0) { 1678 | var cat = "modify"; 1679 | var div = part; 1680 | if(part != full) { 1681 | if(cell.value.indexOf(full) >= 0) { 1682 | div = full; 1683 | cat = "conflict"; 1684 | cell.conflicted = true; 1685 | } 1686 | } 1687 | cell.updated = true; 1688 | cell.separator = div; 1689 | cell.pretty_separator = div; 1690 | if(cell.pretty_value == div) tokens = ["",""]; else tokens = cell.pretty_value.split(div); 1691 | var pretty_tokens = tokens; 1692 | if(tokens.length >= 2) { 1693 | pretty_tokens[0] = coopy.DiffRender.markSpaces(tokens[0],tokens[1]); 1694 | pretty_tokens[1] = coopy.DiffRender.markSpaces(tokens[1],tokens[0]); 1695 | } 1696 | if(tokens.length >= 3) { 1697 | var ref = pretty_tokens[0]; 1698 | pretty_tokens[0] = coopy.DiffRender.markSpaces(ref,tokens[2]); 1699 | pretty_tokens[2] = coopy.DiffRender.markSpaces(tokens[2],ref); 1700 | } 1701 | cell.pretty_separator = String.fromCharCode(8594); 1702 | cell.pretty_value = pretty_tokens.join(cell.pretty_separator); 1703 | cell.category_given_tr = cell.category = cat; 1704 | var offset; 1705 | if(cell.conflicted) offset = 1; else offset = 0; 1706 | cell.lvalue = tokens[offset]; 1707 | cell.rvalue = tokens[offset + 1]; 1708 | if(cell.conflicted) cell.pvalue = tokens[0]; 1709 | } 1710 | } 1711 | } 1712 | }; 1713 | coopy.DiffRender.markSpaces = function(sl,sr) { 1714 | if(sl == sr) return sl; 1715 | if(sl == null || sr == null) return sl; 1716 | var slc = StringTools.replace(sl," ",""); 1717 | var src = StringTools.replace(sr," ",""); 1718 | if(slc != src) return sl; 1719 | var slo = new String(""); 1720 | var il = 0; 1721 | var ir = 0; 1722 | while(il < sl.length) { 1723 | var cl = sl.charAt(il); 1724 | var cr = ""; 1725 | if(ir < sr.length) cr = sr.charAt(ir); 1726 | if(cl == cr) { 1727 | slo += cl; 1728 | il++; 1729 | ir++; 1730 | } else if(cr == " ") ir++; else { 1731 | slo += String.fromCharCode(9251); 1732 | il++; 1733 | } 1734 | } 1735 | return slo; 1736 | }; 1737 | coopy.DiffRender.renderCell = function(tt,x,y) { 1738 | var cell = new coopy.CellInfo(); 1739 | var corner = tt.getCellText(0,0); 1740 | var off; 1741 | if(corner == "@:@") off = 1; else off = 0; 1742 | coopy.DiffRender.examineCell(x,y,tt.getCellText(x,y),tt.getCellText(x,off),tt.getCellText(off,y),corner,cell); 1743 | return cell; 1744 | }; 1745 | coopy.DiffRender.prototype = { 1746 | usePrettyArrows: function(flag) { 1747 | this.pretty_arrows = flag; 1748 | } 1749 | ,insert: function(str) { 1750 | this.text_to_insert.push(str); 1751 | } 1752 | ,beginTable: function() { 1753 | this.insert("\n"); 1754 | } 1755 | ,beginRow: function(mode) { 1756 | this.td_open = ""; 1765 | this.insert(tr); 1766 | } 1767 | ,insertCell: function(txt,mode) { 1768 | var cell_decorate = ""; 1769 | if(mode != "") cell_decorate = " class=\"" + mode + "\""; 1770 | this.insert(this.td_open + cell_decorate + ">"); 1771 | this.insert(txt); 1772 | this.insert(this.td_close); 1773 | } 1774 | ,endRow: function() { 1775 | this.insert("\n"); 1776 | } 1777 | ,endTable: function() { 1778 | this.insert("
\n"); 1779 | } 1780 | ,html: function() { 1781 | return this.text_to_insert.join(""); 1782 | } 1783 | ,toString: function() { 1784 | return this.html(); 1785 | } 1786 | ,render: function(rows) { 1787 | if(rows.get_width() == 0 || rows.get_height() == 0) return; 1788 | var render = this; 1789 | render.beginTable(); 1790 | var change_row = -1; 1791 | var tt = new coopy.TableText(rows); 1792 | var cell = new coopy.CellInfo(); 1793 | var corner = tt.getCellText(0,0); 1794 | var off; 1795 | if(corner == "@:@") off = 1; else off = 0; 1796 | if(off > 0) { 1797 | if(rows.get_width() <= 1 || rows.get_height() <= 1) return; 1798 | } 1799 | var _g1 = 0; 1800 | var _g = rows.get_height(); 1801 | while(_g1 < _g) { 1802 | var row = _g1++; 1803 | var open = false; 1804 | var txt = tt.getCellText(off,row); 1805 | if(txt == null) txt = ""; 1806 | coopy.DiffRender.examineCell(0,row,txt,"",txt,corner,cell); 1807 | var row_mode = cell.category; 1808 | if(row_mode == "spec") change_row = row; 1809 | render.beginRow(row_mode); 1810 | var _g3 = 0; 1811 | var _g2 = rows.get_width(); 1812 | while(_g3 < _g2) { 1813 | var c = _g3++; 1814 | coopy.DiffRender.examineCell(c,row,tt.getCellText(c,row),change_row >= 0?tt.getCellText(c,change_row):"",txt,corner,cell); 1815 | render.insertCell(this.pretty_arrows?cell.pretty_value:cell.value,cell.category_given_tr); 1816 | } 1817 | render.endRow(); 1818 | } 1819 | render.endTable(); 1820 | } 1821 | ,sampleCss: function() { 1822 | return ".highlighter .add { \n background-color: #7fff7f;\n}\n\n.highlighter .remove { \n background-color: #ff7f7f;\n}\n\n.highlighter td.modify { \n background-color: #7f7fff;\n}\n\n.highlighter td.conflict { \n background-color: #f00;\n}\n\n.highlighter .spec { \n background-color: #aaa;\n}\n\n.highlighter .move { \n background-color: #ffa;\n}\n\n.highlighter .null { \n color: #888;\n}\n\n.highlighter table { \n border-collapse:collapse;\n}\n\n.highlighter td, .highlighter th {\n border: 1px solid #2D4068;\n padding: 3px 7px 2px;\n}\n\n.highlighter th, .highlighter .header { \n background-color: #aaf;\n font-weight: bold;\n padding-bottom: 4px;\n padding-top: 5px;\n text-align:left;\n}\n\n.highlighter tr:first-child td {\n border-top: 1px solid #2D4068;\n}\n\n.highlighter td:first-child { \n border-left: 1px solid #2D4068;\n}\n\n.highlighter td {\n empty-cells: show;\n}\n"; 1823 | } 1824 | ,completeHtml: function() { 1825 | this.text_to_insert.splice(0,0,"\n\n\n\n\n\n
\n"); 1829 | this.text_to_insert.push("
\n\n\n"); 1830 | } 1831 | }; 1832 | coopy.Row = function() { }; 1833 | coopy.Row.__name__ = true; 1834 | coopy.HighlightPatch = $hx_exports.coopy.HighlightPatch = function(source,patch) { 1835 | this.source = source; 1836 | this.patch = patch; 1837 | this.view = patch.getCellView(); 1838 | }; 1839 | coopy.HighlightPatch.__name__ = true; 1840 | coopy.HighlightPatch.__interfaces__ = [coopy.Row]; 1841 | coopy.HighlightPatch.prototype = { 1842 | reset: function() { 1843 | this.header = new haxe.ds.IntMap(); 1844 | this.headerPre = new haxe.ds.StringMap(); 1845 | this.headerPost = new haxe.ds.StringMap(); 1846 | this.headerRename = new haxe.ds.StringMap(); 1847 | this.headerMove = null; 1848 | this.modifier = new haxe.ds.IntMap(); 1849 | this.mods = new Array(); 1850 | this.cmods = new Array(); 1851 | this.csv = new coopy.Csv(); 1852 | this.rcOffset = 0; 1853 | this.currentRow = -1; 1854 | this.rowInfo = new coopy.CellInfo(); 1855 | this.cellInfo = new coopy.CellInfo(); 1856 | this.sourceInPatchCol = this.patchInSourceCol = null; 1857 | this.patchInSourceRow = new haxe.ds.IntMap(); 1858 | this.indexes = null; 1859 | this.lastSourceRow = -1; 1860 | this.actions = new Array(); 1861 | this.rowPermutation = null; 1862 | this.rowPermutationRev = null; 1863 | this.colPermutation = null; 1864 | this.colPermutationRev = null; 1865 | this.haveDroppedColumns = false; 1866 | } 1867 | ,apply: function() { 1868 | this.reset(); 1869 | if(this.patch.get_width() < 2) return true; 1870 | if(this.patch.get_height() < 1) return true; 1871 | this.payloadCol = 1 + this.rcOffset; 1872 | this.payloadTop = this.patch.get_width(); 1873 | var corner = this.patch.getCellView().toString(this.patch.getCell(0,0)); 1874 | if(corner == "@:@") this.rcOffset = 1; else this.rcOffset = 0; 1875 | var _g1 = 0; 1876 | var _g = this.patch.get_height(); 1877 | while(_g1 < _g) { 1878 | var r = _g1++; 1879 | var str = this.view.toString(this.patch.getCell(this.rcOffset,r)); 1880 | this.actions.push(str != null?str:""); 1881 | } 1882 | var _g11 = 0; 1883 | var _g2 = this.patch.get_height(); 1884 | while(_g11 < _g2) { 1885 | var r1 = _g11++; 1886 | this.applyRow(r1); 1887 | } 1888 | this.finishRows(); 1889 | this.finishColumns(); 1890 | return true; 1891 | } 1892 | ,needSourceColumns: function() { 1893 | if(this.sourceInPatchCol != null) return; 1894 | this.sourceInPatchCol = new haxe.ds.IntMap(); 1895 | this.patchInSourceCol = new haxe.ds.IntMap(); 1896 | var av = this.source.getCellView(); 1897 | var _g1 = 0; 1898 | var _g = this.source.get_width(); 1899 | while(_g1 < _g) { 1900 | var i = _g1++; 1901 | var name = av.toString(this.source.getCell(i,0)); 1902 | var at = this.headerPre.get(name); 1903 | if(at == null) continue; 1904 | this.sourceInPatchCol.set(i,at); 1905 | this.patchInSourceCol.set(at,i); 1906 | } 1907 | } 1908 | ,needSourceIndex: function() { 1909 | if(this.indexes != null) return; 1910 | var state = new coopy.TableComparisonState(); 1911 | state.a = this.source; 1912 | state.b = this.source; 1913 | var comp = new coopy.CompareTable(); 1914 | comp.storeIndexes(); 1915 | comp.attach(state); 1916 | comp.align(); 1917 | this.indexes = comp.getIndexes(); 1918 | this.needSourceColumns(); 1919 | } 1920 | ,applyRow: function(r) { 1921 | this.currentRow = r; 1922 | var code = this.actions[r]; 1923 | if(r == 0 && this.rcOffset > 0) { 1924 | } else if(code == "@@") { 1925 | this.applyHeader(); 1926 | this.applyAction("@@"); 1927 | } else if(code == "!") this.applyMeta(); else if(code == "+++") this.applyAction(code); else if(code == "---") this.applyAction(code); else if(code == "+" || code == ":") this.applyAction(code); else if(code.indexOf("->") >= 0) this.applyAction("->"); else this.lastSourceRow = -1; 1928 | } 1929 | ,getDatum: function(c) { 1930 | return this.patch.getCell(c,this.currentRow); 1931 | } 1932 | ,getString: function(c) { 1933 | return this.view.toString(this.getDatum(c)); 1934 | } 1935 | ,applyMeta: function() { 1936 | var _g1 = this.payloadCol; 1937 | var _g = this.payloadTop; 1938 | while(_g1 < _g) { 1939 | var i = _g1++; 1940 | var name = this.getString(i); 1941 | if(name == "") continue; 1942 | this.modifier.set(i,name); 1943 | } 1944 | } 1945 | ,applyHeader: function() { 1946 | var _g1 = this.payloadCol; 1947 | var _g = this.payloadTop; 1948 | while(_g1 < _g) { 1949 | var i = _g1++; 1950 | var name = this.getString(i); 1951 | if(name == "...") { 1952 | this.modifier.set(i,"..."); 1953 | this.haveDroppedColumns = true; 1954 | continue; 1955 | } 1956 | var mod = this.modifier.get(i); 1957 | var move = false; 1958 | if(mod != null) { 1959 | if(HxOverrides.cca(mod,0) == 58) { 1960 | move = true; 1961 | mod = HxOverrides.substr(mod,1,mod.length); 1962 | } 1963 | } 1964 | this.header.set(i,name); 1965 | if(mod != null) { 1966 | if(HxOverrides.cca(mod,0) == 40) { 1967 | var prev_name = HxOverrides.substr(mod,1,mod.length - 2); 1968 | this.headerPre.set(prev_name,i); 1969 | this.headerPost.set(name,i); 1970 | this.headerRename.set(prev_name,name); 1971 | continue; 1972 | } 1973 | } 1974 | if(mod != "+++") this.headerPre.set(name,i); 1975 | if(mod != "---") this.headerPost.set(name,i); 1976 | if(move) { 1977 | if(this.headerMove == null) this.headerMove = new haxe.ds.StringMap(); 1978 | this.headerMove.set(name,1); 1979 | } 1980 | } 1981 | if(this.source.get_height() == 0) this.applyAction("+++"); 1982 | } 1983 | ,lookUp: function(del) { 1984 | if(del == null) del = 0; 1985 | var at = this.patchInSourceRow.get(this.currentRow + del); 1986 | if(at != null) return at; 1987 | var result = -1; 1988 | this.currentRow += del; 1989 | if(this.currentRow >= 0 && this.currentRow < this.patch.get_height()) { 1990 | var _g = 0; 1991 | var _g1 = this.indexes; 1992 | while(_g < _g1.length) { 1993 | var idx = _g1[_g]; 1994 | ++_g; 1995 | var match = idx.queryByContent(this); 1996 | if(match.spot_a != 1) continue; 1997 | result = match.item_a.lst[0]; 1998 | break; 1999 | } 2000 | } 2001 | this.patchInSourceRow.set(this.currentRow,result); 2002 | result; 2003 | this.currentRow -= del; 2004 | return result; 2005 | } 2006 | ,applyAction: function(code) { 2007 | var mod = new coopy.HighlightPatchUnit(); 2008 | mod.code = code; 2009 | mod.add = code == "+++"; 2010 | mod.rem = code == "---"; 2011 | mod.update = code == "->"; 2012 | this.needSourceIndex(); 2013 | if(this.lastSourceRow == -1) this.lastSourceRow = this.lookUp(-1); 2014 | mod.sourcePrevRow = this.lastSourceRow; 2015 | var nextAct = this.actions[this.currentRow + 1]; 2016 | if(nextAct != "+++" && nextAct != "...") mod.sourceNextRow = this.lookUp(1); 2017 | if(mod.add) { 2018 | if(this.actions[this.currentRow - 1] != "+++") mod.sourcePrevRow = this.lookUp(-1); 2019 | mod.sourceRow = mod.sourcePrevRow; 2020 | if(mod.sourceRow != -1) mod.sourceRowOffset = 1; 2021 | } else mod.sourceRow = this.lastSourceRow = this.lookUp(); 2022 | if(this.actions[this.currentRow + 1] == "") this.lastSourceRow = mod.sourceNextRow; 2023 | mod.patchRow = this.currentRow; 2024 | if(code == "@@") mod.sourceRow = 0; 2025 | this.mods.push(mod); 2026 | } 2027 | ,checkAct: function() { 2028 | var act = this.getString(this.rcOffset); 2029 | if(this.rowInfo.value != act) coopy.DiffRender.examineCell(0,0,act,"",act,"",this.rowInfo); 2030 | } 2031 | ,getPreString: function(txt) { 2032 | this.checkAct(); 2033 | if(!this.rowInfo.updated) return txt; 2034 | coopy.DiffRender.examineCell(0,0,txt,"",this.rowInfo.value,"",this.cellInfo); 2035 | if(!this.cellInfo.updated) return txt; 2036 | return this.cellInfo.lvalue; 2037 | } 2038 | ,getRowString: function(c) { 2039 | var at = this.sourceInPatchCol.get(c); 2040 | if(at == null) return "NOT_FOUND"; 2041 | return this.getPreString(this.getString(at)); 2042 | } 2043 | ,sortMods: function(a,b) { 2044 | if(b.code == "@@" && a.code != "@@") return 1; 2045 | if(a.code == "@@" && b.code != "@@") return -1; 2046 | if(a.sourceRow == -1 && !a.add && b.sourceRow != -1) return 1; 2047 | if(a.sourceRow != -1 && !b.add && b.sourceRow == -1) return -1; 2048 | if(a.sourceRow + a.sourceRowOffset > b.sourceRow + b.sourceRowOffset) return 1; 2049 | if(a.sourceRow + a.sourceRowOffset < b.sourceRow + b.sourceRowOffset) return -1; 2050 | if(a.patchRow > b.patchRow) return 1; 2051 | if(a.patchRow < b.patchRow) return -1; 2052 | return 0; 2053 | } 2054 | ,processMods: function(rmods,fate,len) { 2055 | rmods.sort($bind(this,this.sortMods)); 2056 | var offset = 0; 2057 | var last = -1; 2058 | var target = 0; 2059 | var _g = 0; 2060 | while(_g < rmods.length) { 2061 | var mod = rmods[_g]; 2062 | ++_g; 2063 | if(last != -1) { 2064 | var _g2 = last; 2065 | var _g1 = mod.sourceRow + mod.sourceRowOffset; 2066 | while(_g2 < _g1) { 2067 | var i = _g2++; 2068 | fate.push(i + offset); 2069 | target++; 2070 | last++; 2071 | } 2072 | } 2073 | if(mod.rem) { 2074 | fate.push(-1); 2075 | offset--; 2076 | } else if(mod.add) { 2077 | mod.destRow = target; 2078 | target++; 2079 | offset++; 2080 | } else mod.destRow = target; 2081 | if(mod.sourceRow >= 0) { 2082 | last = mod.sourceRow + mod.sourceRowOffset; 2083 | if(mod.rem) last++; 2084 | } else last = -1; 2085 | } 2086 | if(last != -1) { 2087 | var _g3 = last; 2088 | while(_g3 < len) { 2089 | var i1 = _g3++; 2090 | fate.push(i1 + offset); 2091 | target++; 2092 | last++; 2093 | } 2094 | } 2095 | return len + offset; 2096 | } 2097 | ,computeOrdering: function(mods,permutation,permutationRev,dim) { 2098 | var to_unit = new haxe.ds.IntMap(); 2099 | var from_unit = new haxe.ds.IntMap(); 2100 | var meta_from_unit = new haxe.ds.IntMap(); 2101 | var ct = 0; 2102 | var _g = 0; 2103 | while(_g < mods.length) { 2104 | var mod = mods[_g]; 2105 | ++_g; 2106 | if(mod.add || mod.rem) continue; 2107 | if(mod.sourceRow < 0) continue; 2108 | if(mod.sourcePrevRow >= 0) { 2109 | var v = mod.sourceRow; 2110 | to_unit.set(mod.sourcePrevRow,v); 2111 | v; 2112 | var v1 = mod.sourcePrevRow; 2113 | from_unit.set(mod.sourceRow,v1); 2114 | v1; 2115 | if(mod.sourcePrevRow + 1 != mod.sourceRow) ct++; 2116 | } 2117 | if(mod.sourceNextRow >= 0) { 2118 | var v2 = mod.sourceNextRow; 2119 | to_unit.set(mod.sourceRow,v2); 2120 | v2; 2121 | var v3 = mod.sourceRow; 2122 | from_unit.set(mod.sourceNextRow,v3); 2123 | v3; 2124 | if(mod.sourceRow + 1 != mod.sourceNextRow) ct++; 2125 | } 2126 | } 2127 | if(ct > 0) { 2128 | var cursor = null; 2129 | var logical = null; 2130 | var starts = []; 2131 | var _g1 = 0; 2132 | while(_g1 < dim) { 2133 | var i = _g1++; 2134 | var u = from_unit.get(i); 2135 | if(u != null) { 2136 | meta_from_unit.set(u,i); 2137 | i; 2138 | } else starts.push(i); 2139 | } 2140 | var used = new haxe.ds.IntMap(); 2141 | var len = 0; 2142 | var _g2 = 0; 2143 | while(_g2 < dim) { 2144 | var i1 = _g2++; 2145 | if(meta_from_unit.exists(logical)) cursor = meta_from_unit.get(logical); else cursor = null; 2146 | if(cursor == null) { 2147 | var v4 = starts.shift(); 2148 | cursor = v4; 2149 | logical = v4; 2150 | } 2151 | if(cursor == null) cursor = 0; 2152 | while(used.exists(cursor)) cursor = (cursor + 1) % dim; 2153 | logical = cursor; 2154 | permutationRev.push(cursor); 2155 | used.set(cursor,1); 2156 | 1; 2157 | } 2158 | var _g11 = 0; 2159 | var _g3 = permutationRev.length; 2160 | while(_g11 < _g3) { 2161 | var i2 = _g11++; 2162 | permutation[i2] = -1; 2163 | } 2164 | var _g12 = 0; 2165 | var _g4 = permutation.length; 2166 | while(_g12 < _g4) { 2167 | var i3 = _g12++; 2168 | permutation[permutationRev[i3]] = i3; 2169 | } 2170 | } 2171 | } 2172 | ,permuteRows: function() { 2173 | this.rowPermutation = new Array(); 2174 | this.rowPermutationRev = new Array(); 2175 | this.computeOrdering(this.mods,this.rowPermutation,this.rowPermutationRev,this.source.get_height()); 2176 | } 2177 | ,finishRows: function() { 2178 | var fate = new Array(); 2179 | this.permuteRows(); 2180 | if(this.rowPermutation.length > 0) { 2181 | var _g = 0; 2182 | var _g1 = this.mods; 2183 | while(_g < _g1.length) { 2184 | var mod = _g1[_g]; 2185 | ++_g; 2186 | if(mod.sourceRow >= 0) mod.sourceRow = this.rowPermutation[mod.sourceRow]; 2187 | } 2188 | } 2189 | if(this.rowPermutation.length > 0) this.source.insertOrDeleteRows(this.rowPermutation,this.rowPermutation.length); 2190 | var len = this.processMods(this.mods,fate,this.source.get_height()); 2191 | this.source.insertOrDeleteRows(fate,len); 2192 | var _g2 = 0; 2193 | var _g11 = this.mods; 2194 | while(_g2 < _g11.length) { 2195 | var mod1 = _g11[_g2]; 2196 | ++_g2; 2197 | if(!mod1.rem) { 2198 | if(mod1.add) { 2199 | var $it0 = this.headerPost.iterator(); 2200 | while( $it0.hasNext() ) { 2201 | var c = $it0.next(); 2202 | var offset = this.patchInSourceCol.get(c); 2203 | if(offset != null && offset >= 0) this.source.setCell(offset,mod1.destRow,this.patch.getCell(c,mod1.patchRow)); 2204 | } 2205 | } else if(mod1.update) { 2206 | this.currentRow = mod1.patchRow; 2207 | this.checkAct(); 2208 | if(!this.rowInfo.updated) continue; 2209 | var $it1 = this.headerPre.iterator(); 2210 | while( $it1.hasNext() ) { 2211 | var c1 = $it1.next(); 2212 | var txt = this.view.toString(this.patch.getCell(c1,mod1.patchRow)); 2213 | coopy.DiffRender.examineCell(0,0,txt,"",this.rowInfo.value,"",this.cellInfo); 2214 | if(!this.cellInfo.updated) continue; 2215 | if(this.cellInfo.conflicted) continue; 2216 | var d = this.view.toDatum(this.csv.parseSingleCell(this.cellInfo.rvalue)); 2217 | this.source.setCell(this.patchInSourceCol.get(c1),mod1.destRow,d); 2218 | } 2219 | } 2220 | } 2221 | } 2222 | } 2223 | ,permuteColumns: function() { 2224 | if(this.headerMove == null) return; 2225 | this.colPermutation = new Array(); 2226 | this.colPermutationRev = new Array(); 2227 | this.computeOrdering(this.cmods,this.colPermutation,this.colPermutationRev,this.source.get_width()); 2228 | if(this.colPermutation.length == 0) return; 2229 | } 2230 | ,finishColumns: function() { 2231 | this.needSourceColumns(); 2232 | var _g1 = this.payloadCol; 2233 | var _g = this.payloadTop; 2234 | while(_g1 < _g) { 2235 | var i = _g1++; 2236 | var act = this.modifier.get(i); 2237 | var hdr = this.header.get(i); 2238 | if(act == null) act = ""; 2239 | if(act == "---") { 2240 | var at = this.patchInSourceCol.get(i); 2241 | var mod = new coopy.HighlightPatchUnit(); 2242 | mod.code = act; 2243 | mod.rem = true; 2244 | mod.sourceRow = at; 2245 | mod.patchRow = i; 2246 | this.cmods.push(mod); 2247 | } else if(act == "+++") { 2248 | var mod1 = new coopy.HighlightPatchUnit(); 2249 | mod1.code = act; 2250 | mod1.add = true; 2251 | var prev = -1; 2252 | var cont = false; 2253 | mod1.sourceRow = -1; 2254 | if(this.cmods.length > 0) mod1.sourceRow = this.cmods[this.cmods.length - 1].sourceRow; 2255 | if(mod1.sourceRow != -1) mod1.sourceRowOffset = 1; 2256 | mod1.patchRow = i; 2257 | this.cmods.push(mod1); 2258 | } else if(act != "...") { 2259 | var mod2 = new coopy.HighlightPatchUnit(); 2260 | mod2.code = act; 2261 | mod2.patchRow = i; 2262 | mod2.sourceRow = this.patchInSourceCol.get(i); 2263 | this.cmods.push(mod2); 2264 | } 2265 | } 2266 | var at1 = -1; 2267 | var rat = -1; 2268 | var _g11 = 0; 2269 | var _g2 = this.cmods.length - 1; 2270 | while(_g11 < _g2) { 2271 | var i1 = _g11++; 2272 | var icode = this.cmods[i1].code; 2273 | if(icode != "+++" && icode != "---") at1 = this.cmods[i1].sourceRow; 2274 | this.cmods[i1 + 1].sourcePrevRow = at1; 2275 | var j = this.cmods.length - 1 - i1; 2276 | var jcode = this.cmods[j].code; 2277 | if(jcode != "+++" && jcode != "---") rat = this.cmods[j].sourceRow; 2278 | this.cmods[j - 1].sourceNextRow = rat; 2279 | } 2280 | var fate = new Array(); 2281 | this.permuteColumns(); 2282 | if(this.headerMove != null) { 2283 | if(this.colPermutation.length > 0) { 2284 | var _g3 = 0; 2285 | var _g12 = this.cmods; 2286 | while(_g3 < _g12.length) { 2287 | var mod3 = _g12[_g3]; 2288 | ++_g3; 2289 | if(mod3.sourceRow >= 0) mod3.sourceRow = this.colPermutation[mod3.sourceRow]; 2290 | } 2291 | this.source.insertOrDeleteColumns(this.colPermutation,this.colPermutation.length); 2292 | } 2293 | } 2294 | var len = this.processMods(this.cmods,fate,this.source.get_width()); 2295 | this.source.insertOrDeleteColumns(fate,len); 2296 | var _g4 = 0; 2297 | var _g13 = this.cmods; 2298 | while(_g4 < _g13.length) { 2299 | var cmod = _g13[_g4]; 2300 | ++_g4; 2301 | if(!cmod.rem) { 2302 | if(cmod.add) { 2303 | var _g21 = 0; 2304 | var _g31 = this.mods; 2305 | while(_g21 < _g31.length) { 2306 | var mod4 = _g31[_g21]; 2307 | ++_g21; 2308 | if(mod4.patchRow != -1 && mod4.destRow != -1) { 2309 | var d = this.patch.getCell(cmod.patchRow,mod4.patchRow); 2310 | this.source.setCell(cmod.destRow,mod4.destRow,d); 2311 | } 2312 | } 2313 | var hdr1 = this.header.get(cmod.patchRow); 2314 | this.source.setCell(cmod.destRow,0,this.view.toDatum(hdr1)); 2315 | } 2316 | } 2317 | } 2318 | var _g14 = 0; 2319 | var _g5 = this.source.get_width(); 2320 | while(_g14 < _g5) { 2321 | var i2 = _g14++; 2322 | var name = this.view.toString(this.source.getCell(i2,0)); 2323 | var next_name = this.headerRename.get(name); 2324 | if(next_name == null) continue; 2325 | this.source.setCell(i2,0,this.view.toDatum(next_name)); 2326 | } 2327 | } 2328 | }; 2329 | coopy.HighlightPatchUnit = $hx_exports.coopy.HighlightPatchUnit = function() { 2330 | this.add = false; 2331 | this.rem = false; 2332 | this.update = false; 2333 | this.sourceRow = -1; 2334 | this.sourceRowOffset = 0; 2335 | this.sourcePrevRow = -1; 2336 | this.sourceNextRow = -1; 2337 | this.destRow = -1; 2338 | this.patchRow = -1; 2339 | this.code = ""; 2340 | }; 2341 | coopy.HighlightPatchUnit.__name__ = true; 2342 | coopy.HighlightPatchUnit.prototype = { 2343 | toString: function() { 2344 | return this.code + " patchRow " + this.patchRow + " sourceRows " + this.sourcePrevRow + "," + this.sourceRow + "," + this.sourceNextRow + " destRow " + this.destRow; 2345 | } 2346 | }; 2347 | coopy.Index = function() { 2348 | this.items = new haxe.ds.StringMap(); 2349 | this.cols = new Array(); 2350 | this.keys = new Array(); 2351 | this.top_freq = 0; 2352 | this.height = 0; 2353 | }; 2354 | coopy.Index.__name__ = true; 2355 | coopy.Index.prototype = { 2356 | addColumn: function(i) { 2357 | this.cols.push(i); 2358 | } 2359 | ,indexTable: function(t) { 2360 | this.indexed_table = t; 2361 | var _g1 = 0; 2362 | var _g = t.get_height(); 2363 | while(_g1 < _g) { 2364 | var i = _g1++; 2365 | var key; 2366 | if(this.keys.length > i) key = this.keys[i]; else { 2367 | key = this.toKey(t,i); 2368 | this.keys.push(key); 2369 | } 2370 | var item = this.items.get(key); 2371 | if(item == null) { 2372 | item = new coopy.IndexItem(); 2373 | this.items.set(key,item); 2374 | } 2375 | var ct = item.add(i); 2376 | if(ct > this.top_freq) this.top_freq = ct; 2377 | } 2378 | this.height = t.get_height(); 2379 | } 2380 | ,toKey: function(t,i) { 2381 | var wide = ""; 2382 | if(this.v == null) this.v = t.getCellView(); 2383 | var _g1 = 0; 2384 | var _g = this.cols.length; 2385 | while(_g1 < _g) { 2386 | var k = _g1++; 2387 | var d = t.getCell(this.cols[k],i); 2388 | var txt = this.v.toString(d); 2389 | if(txt == null || txt == "" || txt == "null" || txt == "undefined") continue; 2390 | if(k > 0) wide += " // "; 2391 | wide += txt; 2392 | } 2393 | return wide; 2394 | } 2395 | ,toKeyByContent: function(row) { 2396 | var wide = ""; 2397 | var _g1 = 0; 2398 | var _g = this.cols.length; 2399 | while(_g1 < _g) { 2400 | var k = _g1++; 2401 | var txt = row.getRowString(this.cols[k]); 2402 | if(txt == null || txt == "" || txt == "null" || txt == "undefined") continue; 2403 | if(k > 0) wide += " // "; 2404 | wide += txt; 2405 | } 2406 | return wide; 2407 | } 2408 | ,getTable: function() { 2409 | return this.indexed_table; 2410 | } 2411 | }; 2412 | coopy.IndexItem = function() { 2413 | }; 2414 | coopy.IndexItem.__name__ = true; 2415 | coopy.IndexItem.prototype = { 2416 | add: function(i) { 2417 | if(this.lst == null) this.lst = new Array(); 2418 | this.lst.push(i); 2419 | return this.lst.length; 2420 | } 2421 | }; 2422 | coopy.IndexPair = function() { 2423 | this.ia = new coopy.Index(); 2424 | this.ib = new coopy.Index(); 2425 | this.quality = 0; 2426 | }; 2427 | coopy.IndexPair.__name__ = true; 2428 | coopy.IndexPair.prototype = { 2429 | addColumn: function(i) { 2430 | this.ia.addColumn(i); 2431 | this.ib.addColumn(i); 2432 | } 2433 | ,addColumns: function(ca,cb) { 2434 | this.ia.addColumn(ca); 2435 | this.ib.addColumn(cb); 2436 | } 2437 | ,indexTables: function(a,b) { 2438 | this.ia.indexTable(a); 2439 | this.ib.indexTable(b); 2440 | var good = 0; 2441 | var $it0 = this.ia.items.keys(); 2442 | while( $it0.hasNext() ) { 2443 | var key = $it0.next(); 2444 | var item_a = this.ia.items.get(key); 2445 | var spot_a = item_a.lst.length; 2446 | var item_b = this.ib.items.get(key); 2447 | var spot_b = 0; 2448 | if(item_b != null) spot_b = item_b.lst.length; 2449 | if(spot_a == 1 && spot_b == 1) good++; 2450 | } 2451 | this.quality = good / Math.max(1.0,a.get_height()); 2452 | } 2453 | ,queryByKey: function(ka) { 2454 | var result = new coopy.CrossMatch(); 2455 | result.item_a = this.ia.items.get(ka); 2456 | result.item_b = this.ib.items.get(ka); 2457 | result.spot_a = result.spot_b = 0; 2458 | if(ka != "") { 2459 | if(result.item_a != null) result.spot_a = result.item_a.lst.length; 2460 | if(result.item_b != null) result.spot_b = result.item_b.lst.length; 2461 | } 2462 | return result; 2463 | } 2464 | ,queryByContent: function(row) { 2465 | var result = new coopy.CrossMatch(); 2466 | var ka = this.ia.toKeyByContent(row); 2467 | return this.queryByKey(ka); 2468 | } 2469 | ,queryLocal: function(row) { 2470 | var ka = this.ia.toKey(this.ia.getTable(),row); 2471 | return this.queryByKey(ka); 2472 | } 2473 | ,getTopFreq: function() { 2474 | if(this.ib.top_freq > this.ia.top_freq) return this.ib.top_freq; 2475 | return this.ia.top_freq; 2476 | } 2477 | ,getQuality: function() { 2478 | return this.quality; 2479 | } 2480 | }; 2481 | coopy.Merger = $hx_exports.coopy.Merger = function(parent,local,remote,flags) { 2482 | this.parent = parent; 2483 | this.local = local; 2484 | this.remote = remote; 2485 | this.flags = flags; 2486 | }; 2487 | coopy.Merger.__name__ = true; 2488 | coopy.Merger.makeConflictedCell = function(view,pcell,lcell,rcell) { 2489 | return view.toDatum("((( " + view.toString(pcell) + " ))) " + view.toString(lcell) + " /// " + view.toString(rcell)); 2490 | }; 2491 | coopy.Merger.prototype = { 2492 | shuffleDimension: function(dim_units,len,fate,cl,cr) { 2493 | var at = 0; 2494 | var _g = 0; 2495 | while(_g < dim_units.length) { 2496 | var cunit = dim_units[_g]; 2497 | ++_g; 2498 | if(cunit.p < 0) { 2499 | if(cunit.l < 0) { 2500 | if(cunit.r >= 0) { 2501 | cr.set(cunit.r,at); 2502 | at; 2503 | at++; 2504 | } 2505 | } else { 2506 | cl.set(cunit.l,at); 2507 | at; 2508 | at++; 2509 | } 2510 | } else if(cunit.l >= 0) { 2511 | if(cunit.r < 0) { 2512 | } else { 2513 | cl.set(cunit.l,at); 2514 | at; 2515 | at++; 2516 | } 2517 | } 2518 | } 2519 | var _g1 = 0; 2520 | while(_g1 < len) { 2521 | var x = _g1++; 2522 | var idx = cl.get(x); 2523 | if(idx == null) fate.push(-1); else fate.push(idx); 2524 | } 2525 | return at; 2526 | } 2527 | ,shuffleColumns: function() { 2528 | this.column_mix_local = new haxe.ds.IntMap(); 2529 | this.column_mix_remote = new haxe.ds.IntMap(); 2530 | var fate = new Array(); 2531 | var wfate = this.shuffleDimension(this.column_units,this.local.get_width(),fate,this.column_mix_local,this.column_mix_remote); 2532 | this.local.insertOrDeleteColumns(fate,wfate); 2533 | } 2534 | ,shuffleRows: function() { 2535 | this.row_mix_local = new haxe.ds.IntMap(); 2536 | this.row_mix_remote = new haxe.ds.IntMap(); 2537 | var fate = new Array(); 2538 | var hfate = this.shuffleDimension(this.units,this.local.get_height(),fate,this.row_mix_local,this.row_mix_remote); 2539 | this.local.insertOrDeleteRows(fate,hfate); 2540 | } 2541 | ,apply: function() { 2542 | this.conflicts = 0; 2543 | var ct = coopy.Coopy.compareTables3(this.parent,this.local,this.remote); 2544 | var align = ct.align(); 2545 | this.order = align.toOrderPruned(true); 2546 | this.units = this.order.getList(); 2547 | this.column_order = align.meta.toOrderPruned(false); 2548 | this.column_units = this.column_order.getList(); 2549 | var allow_insert = this.flags.allowInsert(); 2550 | var allow_delete = this.flags.allowDelete(); 2551 | var allow_update = this.flags.allowUpdate(); 2552 | var view = this.parent.getCellView(); 2553 | var _g = 0; 2554 | var _g1 = this.units; 2555 | while(_g < _g1.length) { 2556 | var row = _g1[_g]; 2557 | ++_g; 2558 | if(row.l >= 0 && row.r >= 0 && row.p >= 0) { 2559 | var _g2 = 0; 2560 | var _g3 = this.column_units; 2561 | while(_g2 < _g3.length) { 2562 | var col = _g3[_g2]; 2563 | ++_g2; 2564 | if(col.l >= 0 && col.r >= 0 && col.p >= 0) { 2565 | var pcell = this.parent.getCell(col.p,row.p); 2566 | var rcell = this.remote.getCell(col.r,row.r); 2567 | if(!view.equals(pcell,rcell)) { 2568 | var lcell = this.local.getCell(col.l,row.l); 2569 | if(view.equals(pcell,lcell)) this.local.setCell(col.l,row.l,rcell); else { 2570 | this.local.setCell(col.l,row.l,coopy.Merger.makeConflictedCell(view,pcell,lcell,rcell)); 2571 | this.conflicts++; 2572 | } 2573 | } 2574 | } 2575 | } 2576 | } 2577 | } 2578 | this.shuffleColumns(); 2579 | this.shuffleRows(); 2580 | var $it0 = this.column_mix_remote.keys(); 2581 | while( $it0.hasNext() ) { 2582 | var x = $it0.next(); 2583 | var x2 = this.column_mix_remote.get(x); 2584 | var _g4 = 0; 2585 | var _g11 = this.units; 2586 | while(_g4 < _g11.length) { 2587 | var unit = _g11[_g4]; 2588 | ++_g4; 2589 | if(unit.l >= 0 && unit.r >= 0) this.local.setCell(x2,this.row_mix_local.get(unit.l),this.remote.getCell(x,unit.r)); else if(unit.p < 0 && unit.r >= 0) this.local.setCell(x2,this.row_mix_remote.get(unit.r),this.remote.getCell(x,unit.r)); 2590 | } 2591 | } 2592 | var $it1 = this.row_mix_remote.keys(); 2593 | while( $it1.hasNext() ) { 2594 | var y = $it1.next(); 2595 | var y2 = this.row_mix_remote.get(y); 2596 | var _g5 = 0; 2597 | var _g12 = this.column_units; 2598 | while(_g5 < _g12.length) { 2599 | var unit1 = _g12[_g5]; 2600 | ++_g5; 2601 | if(unit1.l >= 0 && unit1.r >= 0) this.local.setCell(this.column_mix_local.get(unit1.l),y2,this.remote.getCell(unit1.r,y)); 2602 | } 2603 | } 2604 | return this.conflicts; 2605 | } 2606 | }; 2607 | coopy.Mover = $hx_exports.coopy.Mover = function() { 2608 | }; 2609 | coopy.Mover.__name__ = true; 2610 | coopy.Mover.moveUnits = function(units) { 2611 | var isrc = new Array(); 2612 | var idest = new Array(); 2613 | var len = units.length; 2614 | var ltop = -1; 2615 | var rtop = -1; 2616 | var in_src = new haxe.ds.IntMap(); 2617 | var in_dest = new haxe.ds.IntMap(); 2618 | var _g = 0; 2619 | while(_g < len) { 2620 | var i = _g++; 2621 | var unit = units[i]; 2622 | if(unit.l >= 0 && unit.r >= 0) { 2623 | if(ltop < unit.l) ltop = unit.l; 2624 | if(rtop < unit.r) rtop = unit.r; 2625 | in_src.set(unit.l,i); 2626 | i; 2627 | in_dest.set(unit.r,i); 2628 | i; 2629 | } 2630 | } 2631 | var v; 2632 | var _g1 = 0; 2633 | var _g2 = ltop + 1; 2634 | while(_g1 < _g2) { 2635 | var i1 = _g1++; 2636 | v = in_src.get(i1); 2637 | if(v != null) isrc.push(v); 2638 | } 2639 | var _g11 = 0; 2640 | var _g3 = rtop + 1; 2641 | while(_g11 < _g3) { 2642 | var i2 = _g11++; 2643 | v = in_dest.get(i2); 2644 | if(v != null) idest.push(v); 2645 | } 2646 | return coopy.Mover.moveWithoutExtras(isrc,idest); 2647 | }; 2648 | coopy.Mover.moveWithExtras = function(isrc,idest) { 2649 | var len = isrc.length; 2650 | var len2 = idest.length; 2651 | var in_src = new haxe.ds.IntMap(); 2652 | var in_dest = new haxe.ds.IntMap(); 2653 | var _g = 0; 2654 | while(_g < len) { 2655 | var i = _g++; 2656 | in_src.set(isrc[i],i); 2657 | i; 2658 | } 2659 | var _g1 = 0; 2660 | while(_g1 < len2) { 2661 | var i1 = _g1++; 2662 | in_dest.set(idest[i1],i1); 2663 | i1; 2664 | } 2665 | var src = new Array(); 2666 | var dest = new Array(); 2667 | var v; 2668 | var _g2 = 0; 2669 | while(_g2 < len) { 2670 | var i2 = _g2++; 2671 | v = isrc[i2]; 2672 | if(in_dest.exists(v)) src.push(v); 2673 | } 2674 | var _g3 = 0; 2675 | while(_g3 < len2) { 2676 | var i3 = _g3++; 2677 | v = idest[i3]; 2678 | if(in_src.exists(v)) dest.push(v); 2679 | } 2680 | return coopy.Mover.moveWithoutExtras(src,dest); 2681 | }; 2682 | coopy.Mover.moveWithoutExtras = function(src,dest) { 2683 | if(src.length != dest.length) return null; 2684 | if(src.length <= 1) return []; 2685 | var len = src.length; 2686 | var in_src = new haxe.ds.IntMap(); 2687 | var blk_len = new haxe.ds.IntMap(); 2688 | var blk_src_loc = new haxe.ds.IntMap(); 2689 | var blk_dest_loc = new haxe.ds.IntMap(); 2690 | var _g = 0; 2691 | while(_g < len) { 2692 | var i = _g++; 2693 | in_src.set(src[i],i); 2694 | i; 2695 | } 2696 | var ct = 0; 2697 | var in_cursor = -2; 2698 | var out_cursor = 0; 2699 | var next; 2700 | var blk = -1; 2701 | var v; 2702 | while(out_cursor < len) { 2703 | v = dest[out_cursor]; 2704 | next = in_src.get(v); 2705 | if(next != in_cursor + 1) { 2706 | blk = v; 2707 | ct = 1; 2708 | blk_src_loc.set(blk,next); 2709 | blk_dest_loc.set(blk,out_cursor); 2710 | } else ct++; 2711 | blk_len.set(blk,ct); 2712 | in_cursor = next; 2713 | out_cursor++; 2714 | } 2715 | var blks = new Array(); 2716 | var $it0 = blk_len.keys(); 2717 | while( $it0.hasNext() ) { 2718 | var k = $it0.next(); 2719 | blks.push(k); 2720 | } 2721 | blks.sort(function(a,b) { 2722 | return blk_len.get(b) - blk_len.get(a); 2723 | }); 2724 | var moved = new Array(); 2725 | while(blks.length > 0) { 2726 | var blk1 = blks.shift(); 2727 | var blen = blks.length; 2728 | var ref_src_loc = blk_src_loc.get(blk1); 2729 | var ref_dest_loc = blk_dest_loc.get(blk1); 2730 | var i1 = blen - 1; 2731 | while(i1 >= 0) { 2732 | var blki = blks[i1]; 2733 | var blki_src_loc = blk_src_loc.get(blki); 2734 | var to_left_src = blki_src_loc < ref_src_loc; 2735 | var to_left_dest = blk_dest_loc.get(blki) < ref_dest_loc; 2736 | if(to_left_src != to_left_dest) { 2737 | var ct1 = blk_len.get(blki); 2738 | var _g1 = 0; 2739 | while(_g1 < ct1) { 2740 | var j = _g1++; 2741 | moved.push(src[blki_src_loc]); 2742 | blki_src_loc++; 2743 | } 2744 | blks.splice(i1,1); 2745 | } 2746 | i1--; 2747 | } 2748 | } 2749 | return moved; 2750 | }; 2751 | coopy.Ordering = function() { 2752 | this.order = new Array(); 2753 | this.ignore_parent = false; 2754 | }; 2755 | coopy.Ordering.__name__ = true; 2756 | coopy.Ordering.prototype = { 2757 | add: function(l,r,p) { 2758 | if(p == null) p = -2; 2759 | if(this.ignore_parent) p = -2; 2760 | this.order.push(new coopy.Unit(l,r,p)); 2761 | } 2762 | ,getList: function() { 2763 | return this.order; 2764 | } 2765 | ,toString: function() { 2766 | var txt = ""; 2767 | var _g1 = 0; 2768 | var _g = this.order.length; 2769 | while(_g1 < _g) { 2770 | var i = _g1++; 2771 | if(i > 0) txt += ", "; 2772 | txt += Std.string(this.order[i]); 2773 | } 2774 | return txt; 2775 | } 2776 | ,ignoreParent: function() { 2777 | this.ignore_parent = true; 2778 | } 2779 | }; 2780 | coopy.Report = $hx_exports.coopy.Report = function() { 2781 | this.changes = new Array(); 2782 | }; 2783 | coopy.Report.__name__ = true; 2784 | coopy.Report.prototype = { 2785 | toString: function() { 2786 | return this.changes.toString(); 2787 | } 2788 | ,clear: function() { 2789 | this.changes = new Array(); 2790 | } 2791 | }; 2792 | coopy.SimpleCell = function(x) { 2793 | this.datum = x; 2794 | }; 2795 | coopy.SimpleCell.__name__ = true; 2796 | coopy.SimpleCell.prototype = { 2797 | toString: function() { 2798 | return this.datum; 2799 | } 2800 | }; 2801 | coopy.Table = function() { }; 2802 | coopy.Table.__name__ = true; 2803 | coopy.SimpleTable = $hx_exports.coopy.SimpleTable = function(w,h) { 2804 | this.data = new haxe.ds.IntMap(); 2805 | this.w = w; 2806 | this.h = h; 2807 | }; 2808 | coopy.SimpleTable.__name__ = true; 2809 | coopy.SimpleTable.__interfaces__ = [coopy.Table]; 2810 | coopy.SimpleTable.tableToString = function(tab) { 2811 | var x = ""; 2812 | var _g1 = 0; 2813 | var _g = tab.get_height(); 2814 | while(_g1 < _g) { 2815 | var i = _g1++; 2816 | var _g3 = 0; 2817 | var _g2 = tab.get_width(); 2818 | while(_g3 < _g2) { 2819 | var j = _g3++; 2820 | if(j > 0) x += " "; 2821 | x += Std.string(tab.getCell(j,i)); 2822 | } 2823 | x += "\n"; 2824 | } 2825 | return x; 2826 | }; 2827 | coopy.SimpleTable.prototype = { 2828 | getTable: function() { 2829 | return this; 2830 | } 2831 | ,get_width: function() { 2832 | return this.w; 2833 | } 2834 | ,get_height: function() { 2835 | return this.h; 2836 | } 2837 | ,get_size: function() { 2838 | return this.h; 2839 | } 2840 | ,getCell: function(x,y) { 2841 | return this.data.get(x + y * this.w); 2842 | } 2843 | ,setCell: function(x,y,c) { 2844 | var value = c; 2845 | this.data.set(x + y * this.w,value); 2846 | } 2847 | ,toString: function() { 2848 | return coopy.SimpleTable.tableToString(this); 2849 | } 2850 | ,getCellView: function() { 2851 | return new coopy.SimpleView(); 2852 | } 2853 | ,isResizable: function() { 2854 | return true; 2855 | } 2856 | ,resize: function(w,h) { 2857 | this.w = w; 2858 | this.h = h; 2859 | return true; 2860 | } 2861 | ,clear: function() { 2862 | this.data = new haxe.ds.IntMap(); 2863 | } 2864 | ,insertOrDeleteRows: function(fate,hfate) { 2865 | var data2 = new haxe.ds.IntMap(); 2866 | var _g1 = 0; 2867 | var _g = fate.length; 2868 | while(_g1 < _g) { 2869 | var i = _g1++; 2870 | var j = fate[i]; 2871 | if(j != -1) { 2872 | var _g3 = 0; 2873 | var _g2 = this.w; 2874 | while(_g3 < _g2) { 2875 | var c = _g3++; 2876 | var idx = i * this.w + c; 2877 | if(this.data.exists(idx)) { 2878 | var value = this.data.get(idx); 2879 | data2.set(j * this.w + c,value); 2880 | } 2881 | } 2882 | } 2883 | } 2884 | this.h = hfate; 2885 | this.data = data2; 2886 | return true; 2887 | } 2888 | ,insertOrDeleteColumns: function(fate,wfate) { 2889 | var data2 = new haxe.ds.IntMap(); 2890 | var _g1 = 0; 2891 | var _g = fate.length; 2892 | while(_g1 < _g) { 2893 | var i = _g1++; 2894 | var j = fate[i]; 2895 | if(j != -1) { 2896 | var _g3 = 0; 2897 | var _g2 = this.h; 2898 | while(_g3 < _g2) { 2899 | var r = _g3++; 2900 | var idx = r * this.w + i; 2901 | if(this.data.exists(idx)) { 2902 | var value = this.data.get(idx); 2903 | data2.set(r * wfate + j,value); 2904 | } 2905 | } 2906 | } 2907 | } 2908 | this.w = wfate; 2909 | this.data = data2; 2910 | return true; 2911 | } 2912 | ,trimBlank: function() { 2913 | if(this.h == 0) return true; 2914 | var h_test = this.h; 2915 | if(h_test >= 3) h_test = 3; 2916 | var view = this.getCellView(); 2917 | var space = view.toDatum(""); 2918 | var more = true; 2919 | while(more) { 2920 | var _g1 = 0; 2921 | var _g = this.get_width(); 2922 | while(_g1 < _g) { 2923 | var i = _g1++; 2924 | var c = this.getCell(i,this.h - 1); 2925 | if(!(view.equals(c,space) || c == null)) { 2926 | more = false; 2927 | break; 2928 | } 2929 | } 2930 | if(more) this.h--; 2931 | } 2932 | more = true; 2933 | var nw = this.w; 2934 | while(more) { 2935 | if(this.w == 0) break; 2936 | var _g2 = 0; 2937 | while(_g2 < h_test) { 2938 | var i1 = _g2++; 2939 | var c1 = this.getCell(nw - 1,i1); 2940 | if(!(view.equals(c1,space) || c1 == null)) { 2941 | more = false; 2942 | break; 2943 | } 2944 | } 2945 | if(more) nw--; 2946 | } 2947 | if(nw == this.w) return true; 2948 | var data2 = new haxe.ds.IntMap(); 2949 | var _g3 = 0; 2950 | while(_g3 < nw) { 2951 | var i2 = _g3++; 2952 | var _g21 = 0; 2953 | var _g11 = this.h; 2954 | while(_g21 < _g11) { 2955 | var r = _g21++; 2956 | var idx = r * this.w + i2; 2957 | if(this.data.exists(idx)) { 2958 | var value = this.data.get(idx); 2959 | data2.set(r * nw + i2,value); 2960 | } 2961 | } 2962 | } 2963 | this.w = nw; 2964 | this.data = data2; 2965 | return true; 2966 | } 2967 | }; 2968 | coopy.View = function() { }; 2969 | coopy.View.__name__ = true; 2970 | coopy.SimpleView = $hx_exports.coopy.SimpleView = function() { 2971 | }; 2972 | coopy.SimpleView.__name__ = true; 2973 | coopy.SimpleView.__interfaces__ = [coopy.View]; 2974 | coopy.SimpleView.prototype = { 2975 | toString: function(d) { 2976 | if(d == null) return null; 2977 | return "" + Std.string(d); 2978 | } 2979 | ,getBag: function(d) { 2980 | return null; 2981 | } 2982 | ,getTable: function(d) { 2983 | return null; 2984 | } 2985 | ,hasStructure: function(d) { 2986 | return false; 2987 | } 2988 | ,equals: function(d1,d2) { 2989 | if(d1 == null && d2 == null) return true; 2990 | if(d1 == null && "" + Std.string(d2) == "") return true; 2991 | if("" + Std.string(d1) == "" && d2 == null) return true; 2992 | return "" + Std.string(d1) == "" + Std.string(d2); 2993 | } 2994 | ,toDatum: function(str) { 2995 | if(str == null) return null; 2996 | return str; 2997 | } 2998 | }; 2999 | coopy.SparseSheet = function() { 3000 | this.h = this.w = 0; 3001 | }; 3002 | coopy.SparseSheet.__name__ = true; 3003 | coopy.SparseSheet.prototype = { 3004 | resize: function(w,h,zero) { 3005 | this.row = new haxe.ds.IntMap(); 3006 | this.nonDestructiveResize(w,h,zero); 3007 | } 3008 | ,nonDestructiveResize: function(w,h,zero) { 3009 | this.w = w; 3010 | this.h = h; 3011 | this.zero = zero; 3012 | } 3013 | ,get: function(x,y) { 3014 | var cursor = this.row.get(y); 3015 | if(cursor == null) return this.zero; 3016 | var val = cursor.get(x); 3017 | if(val == null) return this.zero; 3018 | return val; 3019 | } 3020 | ,set: function(x,y,val) { 3021 | var cursor = this.row.get(y); 3022 | if(cursor == null) { 3023 | cursor = new haxe.ds.IntMap(); 3024 | this.row.set(y,cursor); 3025 | } 3026 | cursor.set(x,val); 3027 | } 3028 | }; 3029 | coopy.TableComparisonState = $hx_exports.coopy.TableComparisonState = function() { 3030 | this.reset(); 3031 | }; 3032 | coopy.TableComparisonState.__name__ = true; 3033 | coopy.TableComparisonState.prototype = { 3034 | reset: function() { 3035 | this.completed = false; 3036 | this.run_to_completion = true; 3037 | this.is_equal_known = false; 3038 | this.is_equal = false; 3039 | this.has_same_columns = false; 3040 | this.has_same_columns_known = false; 3041 | } 3042 | }; 3043 | coopy.TableDiff = $hx_exports.coopy.TableDiff = function(align,flags) { 3044 | this.align = align; 3045 | this.flags = flags; 3046 | }; 3047 | coopy.TableDiff.__name__ = true; 3048 | coopy.TableDiff.prototype = { 3049 | getSeparator: function(t,t2,root) { 3050 | var sep = root; 3051 | var w = t.get_width(); 3052 | var h = t.get_height(); 3053 | var view = t.getCellView(); 3054 | var _g = 0; 3055 | while(_g < h) { 3056 | var y = _g++; 3057 | var _g1 = 0; 3058 | while(_g1 < w) { 3059 | var x = _g1++; 3060 | var txt = view.toString(t.getCell(x,y)); 3061 | if(txt == null) continue; 3062 | while(txt.indexOf(sep) >= 0) sep = "-" + sep; 3063 | } 3064 | } 3065 | if(t2 != null) { 3066 | w = t2.get_width(); 3067 | h = t2.get_height(); 3068 | var _g2 = 0; 3069 | while(_g2 < h) { 3070 | var y1 = _g2++; 3071 | var _g11 = 0; 3072 | while(_g11 < w) { 3073 | var x1 = _g11++; 3074 | var txt1 = view.toString(t2.getCell(x1,y1)); 3075 | if(txt1 == null) continue; 3076 | while(txt1.indexOf(sep) >= 0) sep = "-" + sep; 3077 | } 3078 | } 3079 | } 3080 | return sep; 3081 | } 3082 | ,quoteForDiff: function(v,d) { 3083 | var nil = "NULL"; 3084 | if(v.equals(d,null)) return nil; 3085 | var str = v.toString(d); 3086 | var score = 0; 3087 | var _g1 = 0; 3088 | var _g = str.length; 3089 | while(_g1 < _g) { 3090 | var i = _g1++; 3091 | if(HxOverrides.cca(str,score) != 95) break; 3092 | score++; 3093 | } 3094 | if(HxOverrides.substr(str,score,null) == nil) str = "_" + str; 3095 | return str; 3096 | } 3097 | ,isReordered: function(m,ct) { 3098 | var reordered = false; 3099 | var l = -1; 3100 | var r = -1; 3101 | var _g = 0; 3102 | while(_g < ct) { 3103 | var i = _g++; 3104 | var unit = m.get(i); 3105 | if(unit == null) continue; 3106 | if(unit.l >= 0) { 3107 | if(unit.l < l) { 3108 | reordered = true; 3109 | break; 3110 | } 3111 | l = unit.l; 3112 | } 3113 | if(unit.r >= 0) { 3114 | if(unit.r < r) { 3115 | reordered = true; 3116 | break; 3117 | } 3118 | r = unit.r; 3119 | } 3120 | } 3121 | return reordered; 3122 | } 3123 | ,spreadContext: function(units,del,active) { 3124 | if(del > 0 && active != null) { 3125 | var mark = -del - 1; 3126 | var skips = 0; 3127 | var _g1 = 0; 3128 | var _g = units.length; 3129 | while(_g1 < _g) { 3130 | var i = _g1++; 3131 | if(active[i] == -3) { 3132 | skips++; 3133 | continue; 3134 | } 3135 | if(active[i] == 0 || active[i] == 3) { 3136 | if(i - mark <= del + skips) active[i] = 2; else if(i - mark == del + 1 + skips) active[i] = 3; 3137 | } else if(active[i] == 1) { 3138 | mark = i; 3139 | skips = 0; 3140 | } 3141 | } 3142 | mark = units.length + del + 1; 3143 | skips = 0; 3144 | var _g11 = 0; 3145 | var _g2 = units.length; 3146 | while(_g11 < _g2) { 3147 | var j = _g11++; 3148 | var i1 = units.length - 1 - j; 3149 | if(active[i1] == -3) { 3150 | skips++; 3151 | continue; 3152 | } 3153 | if(active[i1] == 0 || active[i1] == 3) { 3154 | if(mark - i1 <= del + skips) active[i1] = 2; else if(mark - i1 == del + 1 + skips) active[i1] = 3; 3155 | } else if(active[i1] == 1) { 3156 | mark = i1; 3157 | skips = 0; 3158 | } 3159 | } 3160 | } 3161 | } 3162 | ,reportUnit: function(unit) { 3163 | var txt = unit.toString(); 3164 | var reordered = false; 3165 | if(unit.l >= 0) { 3166 | if(unit.l < this.l_prev) reordered = true; 3167 | this.l_prev = unit.l; 3168 | } 3169 | if(unit.r >= 0) { 3170 | if(unit.r < this.r_prev) reordered = true; 3171 | this.r_prev = unit.r; 3172 | } 3173 | if(reordered) txt = "[" + txt + "]"; 3174 | return txt; 3175 | } 3176 | ,hilite: function(output) { 3177 | if(!output.isResizable()) return false; 3178 | output.resize(0,0); 3179 | output.clear(); 3180 | var row_map = new haxe.ds.IntMap(); 3181 | var col_map = new haxe.ds.IntMap(); 3182 | var order = this.align.toOrderPruned(true); 3183 | var units = order.getList(); 3184 | var has_parent = this.align.reference != null; 3185 | var a; 3186 | var b; 3187 | var p; 3188 | var ra_header = 0; 3189 | var rb_header = 0; 3190 | var is_index_p = new haxe.ds.IntMap(); 3191 | var is_index_a = new haxe.ds.IntMap(); 3192 | var is_index_b = new haxe.ds.IntMap(); 3193 | if(has_parent) { 3194 | p = this.align.getSource(); 3195 | a = this.align.reference.getTarget(); 3196 | b = this.align.getTarget(); 3197 | ra_header = this.align.reference.meta.getTargetHeader(); 3198 | rb_header = this.align.meta.getTargetHeader(); 3199 | if(this.align.getIndexColumns() != null) { 3200 | var _g = 0; 3201 | var _g1 = this.align.getIndexColumns(); 3202 | while(_g < _g1.length) { 3203 | var p2b = _g1[_g]; 3204 | ++_g; 3205 | if(p2b.l >= 0) is_index_p.set(p2b.l,true); 3206 | if(p2b.r >= 0) is_index_b.set(p2b.r,true); 3207 | } 3208 | } 3209 | if(this.align.reference.getIndexColumns() != null) { 3210 | var _g2 = 0; 3211 | var _g11 = this.align.reference.getIndexColumns(); 3212 | while(_g2 < _g11.length) { 3213 | var p2a = _g11[_g2]; 3214 | ++_g2; 3215 | if(p2a.l >= 0) is_index_p.set(p2a.l,true); 3216 | if(p2a.r >= 0) is_index_a.set(p2a.r,true); 3217 | } 3218 | } 3219 | } else { 3220 | a = this.align.getSource(); 3221 | b = this.align.getTarget(); 3222 | p = a; 3223 | ra_header = this.align.meta.getSourceHeader(); 3224 | rb_header = this.align.meta.getTargetHeader(); 3225 | if(this.align.getIndexColumns() != null) { 3226 | var _g3 = 0; 3227 | var _g12 = this.align.getIndexColumns(); 3228 | while(_g3 < _g12.length) { 3229 | var a2b = _g12[_g3]; 3230 | ++_g3; 3231 | if(a2b.l >= 0) is_index_a.set(a2b.l,true); 3232 | if(a2b.r >= 0) is_index_b.set(a2b.r,true); 3233 | } 3234 | } 3235 | } 3236 | var column_order = this.align.meta.toOrderPruned(false); 3237 | var column_units = column_order.getList(); 3238 | var show_rc_numbers = false; 3239 | var row_moves = null; 3240 | var col_moves = null; 3241 | if(this.flags.ordered) { 3242 | row_moves = new haxe.ds.IntMap(); 3243 | var moves = coopy.Mover.moveUnits(units); 3244 | var _g13 = 0; 3245 | var _g4 = moves.length; 3246 | while(_g13 < _g4) { 3247 | var i = _g13++; 3248 | row_moves.set(moves[i],i); 3249 | i; 3250 | } 3251 | col_moves = new haxe.ds.IntMap(); 3252 | moves = coopy.Mover.moveUnits(column_units); 3253 | var _g14 = 0; 3254 | var _g5 = moves.length; 3255 | while(_g14 < _g5) { 3256 | var i1 = _g14++; 3257 | col_moves.set(moves[i1],i1); 3258 | i1; 3259 | } 3260 | } 3261 | var active = new Array(); 3262 | var active_column = null; 3263 | if(!this.flags.show_unchanged) { 3264 | var _g15 = 0; 3265 | var _g6 = units.length; 3266 | while(_g15 < _g6) { 3267 | var i2 = _g15++; 3268 | active[i2] = 0; 3269 | } 3270 | } 3271 | var allow_insert = this.flags.allowInsert(); 3272 | var allow_delete = this.flags.allowDelete(); 3273 | var allow_update = this.flags.allowUpdate(); 3274 | if(!this.flags.show_unchanged_columns) { 3275 | active_column = new Array(); 3276 | var _g16 = 0; 3277 | var _g7 = column_units.length; 3278 | while(_g16 < _g7) { 3279 | var i3 = _g16++; 3280 | var v = 0; 3281 | var unit = column_units[i3]; 3282 | if(unit.l >= 0 && is_index_a.get(unit.l)) v = 1; 3283 | if(unit.r >= 0 && is_index_b.get(unit.r)) v = 1; 3284 | if(unit.p >= 0 && is_index_p.get(unit.p)) v = 1; 3285 | active_column[i3] = v; 3286 | } 3287 | } 3288 | var outer_reps_needed; 3289 | if(this.flags.show_unchanged && this.flags.show_unchanged_columns) outer_reps_needed = 1; else outer_reps_needed = 2; 3290 | var v1 = a.getCellView(); 3291 | var sep = ""; 3292 | var conflict_sep = ""; 3293 | var schema = new Array(); 3294 | var have_schema = false; 3295 | var _g17 = 0; 3296 | var _g8 = column_units.length; 3297 | while(_g17 < _g8) { 3298 | var j = _g17++; 3299 | var cunit = column_units[j]; 3300 | var reordered = false; 3301 | if(this.flags.ordered) { 3302 | if(col_moves.exists(j)) reordered = true; 3303 | if(reordered) show_rc_numbers = true; 3304 | } 3305 | var act = ""; 3306 | if(cunit.r >= 0 && cunit.lp() == -1) { 3307 | have_schema = true; 3308 | act = "+++"; 3309 | if(active_column != null) { 3310 | if(allow_update) active_column[j] = 1; 3311 | } 3312 | } 3313 | if(cunit.r < 0 && cunit.lp() >= 0) { 3314 | have_schema = true; 3315 | act = "---"; 3316 | if(active_column != null) { 3317 | if(allow_update) active_column[j] = 1; 3318 | } 3319 | } 3320 | if(cunit.r >= 0 && cunit.lp() >= 0) { 3321 | if(a.get_height() >= ra_header && b.get_height() >= rb_header) { 3322 | var aa = a.getCell(cunit.lp(),ra_header); 3323 | var bb = b.getCell(cunit.r,rb_header); 3324 | if(!v1.equals(aa,bb)) { 3325 | have_schema = true; 3326 | act = "("; 3327 | act += v1.toString(aa); 3328 | act += ")"; 3329 | if(active_column != null) active_column[j] = 1; 3330 | } 3331 | } 3332 | } 3333 | if(reordered) { 3334 | act = ":" + act; 3335 | have_schema = true; 3336 | if(active_column != null) active_column = null; 3337 | } 3338 | schema.push(act); 3339 | } 3340 | if(have_schema) { 3341 | var at = output.get_height(); 3342 | output.resize(column_units.length + 1,at + 1); 3343 | output.setCell(0,at,v1.toDatum("!")); 3344 | var _g18 = 0; 3345 | var _g9 = column_units.length; 3346 | while(_g18 < _g9) { 3347 | var j1 = _g18++; 3348 | output.setCell(j1 + 1,at,v1.toDatum(schema[j1])); 3349 | } 3350 | } 3351 | var top_line_done = false; 3352 | if(this.flags.always_show_header) { 3353 | var at1 = output.get_height(); 3354 | output.resize(column_units.length + 1,at1 + 1); 3355 | output.setCell(0,at1,v1.toDatum("@@")); 3356 | var _g19 = 0; 3357 | var _g10 = column_units.length; 3358 | while(_g19 < _g10) { 3359 | var j2 = _g19++; 3360 | var cunit1 = column_units[j2]; 3361 | if(cunit1.r >= 0) { 3362 | if(b.get_height() > 0) output.setCell(j2 + 1,at1,b.getCell(cunit1.r,rb_header)); 3363 | } else if(cunit1.lp() >= 0) { 3364 | if(a.get_height() > 0) output.setCell(j2 + 1,at1,a.getCell(cunit1.lp(),ra_header)); 3365 | } 3366 | col_map.set(j2 + 1,cunit1); 3367 | } 3368 | top_line_done = true; 3369 | } 3370 | var _g20 = 0; 3371 | while(_g20 < outer_reps_needed) { 3372 | var out = _g20++; 3373 | if(out == 1) { 3374 | this.spreadContext(units,this.flags.unchanged_context,active); 3375 | this.spreadContext(column_units,this.flags.unchanged_column_context,active_column); 3376 | if(active_column != null) { 3377 | var _g21 = 0; 3378 | var _g110 = column_units.length; 3379 | while(_g21 < _g110) { 3380 | var i4 = _g21++; 3381 | if(active_column[i4] == 3) active_column[i4] = 0; 3382 | } 3383 | } 3384 | } 3385 | var showed_dummy = false; 3386 | var l = -1; 3387 | var r = -1; 3388 | var _g22 = 0; 3389 | var _g111 = units.length; 3390 | while(_g22 < _g111) { 3391 | var i5 = _g22++; 3392 | var unit1 = units[i5]; 3393 | var reordered1 = false; 3394 | if(this.flags.ordered) { 3395 | if(row_moves.exists(i5)) reordered1 = true; 3396 | if(reordered1) show_rc_numbers = true; 3397 | } 3398 | if(unit1.r < 0 && unit1.l < 0) continue; 3399 | if(unit1.r == 0 && unit1.lp() == 0 && top_line_done) continue; 3400 | var act1 = ""; 3401 | if(reordered1) act1 = ":"; 3402 | var publish = this.flags.show_unchanged; 3403 | var dummy = false; 3404 | if(out == 1) { 3405 | publish = active[i5] > 0; 3406 | dummy = active[i5] == 3; 3407 | if(dummy && showed_dummy) continue; 3408 | if(!publish) continue; 3409 | } 3410 | if(!dummy) showed_dummy = false; 3411 | var at2 = output.get_height(); 3412 | if(publish) output.resize(column_units.length + 1,at2 + 1); 3413 | if(dummy) { 3414 | var _g41 = 0; 3415 | var _g31 = column_units.length + 1; 3416 | while(_g41 < _g31) { 3417 | var j3 = _g41++; 3418 | output.setCell(j3,at2,v1.toDatum("...")); 3419 | showed_dummy = true; 3420 | } 3421 | continue; 3422 | } 3423 | var have_addition = false; 3424 | var skip = false; 3425 | if(unit1.p < 0 && unit1.l < 0 && unit1.r >= 0) { 3426 | if(!allow_insert) skip = true; 3427 | act1 = "+++"; 3428 | } 3429 | if((unit1.p >= 0 || !has_parent) && unit1.l >= 0 && unit1.r < 0) { 3430 | if(!allow_delete) skip = true; 3431 | act1 = "---"; 3432 | } 3433 | if(skip) { 3434 | if(!publish) { 3435 | if(active != null) active[i5] = -3; 3436 | } 3437 | continue; 3438 | } 3439 | var _g42 = 0; 3440 | var _g32 = column_units.length; 3441 | while(_g42 < _g32) { 3442 | var j4 = _g42++; 3443 | var cunit2 = column_units[j4]; 3444 | var pp = null; 3445 | var ll = null; 3446 | var rr = null; 3447 | var dd = null; 3448 | var dd_to = null; 3449 | var have_dd_to = false; 3450 | var dd_to_alt = null; 3451 | var have_dd_to_alt = false; 3452 | var have_pp = false; 3453 | var have_ll = false; 3454 | var have_rr = false; 3455 | if(cunit2.p >= 0 && unit1.p >= 0) { 3456 | pp = p.getCell(cunit2.p,unit1.p); 3457 | have_pp = true; 3458 | } 3459 | if(cunit2.l >= 0 && unit1.l >= 0) { 3460 | ll = a.getCell(cunit2.l,unit1.l); 3461 | have_ll = true; 3462 | } 3463 | if(cunit2.r >= 0 && unit1.r >= 0) { 3464 | rr = b.getCell(cunit2.r,unit1.r); 3465 | have_rr = true; 3466 | if((have_pp?cunit2.p:cunit2.l) < 0) { 3467 | if(rr != null) { 3468 | if(v1.toString(rr) != "") { 3469 | if(this.flags.allowUpdate()) have_addition = true; 3470 | } 3471 | } 3472 | } 3473 | } 3474 | if(have_pp) { 3475 | if(!have_rr) dd = pp; else if(v1.equals(pp,rr)) dd = pp; else { 3476 | dd = pp; 3477 | dd_to = rr; 3478 | have_dd_to = true; 3479 | if(!v1.equals(pp,ll)) { 3480 | if(!v1.equals(pp,rr)) { 3481 | dd_to_alt = ll; 3482 | have_dd_to_alt = true; 3483 | } 3484 | } 3485 | } 3486 | } else if(have_ll) { 3487 | if(!have_rr) dd = ll; else if(v1.equals(ll,rr)) dd = ll; else { 3488 | dd = ll; 3489 | dd_to = rr; 3490 | have_dd_to = true; 3491 | } 3492 | } else dd = rr; 3493 | var txt = null; 3494 | if(have_dd_to && allow_update) { 3495 | if(active_column != null) active_column[j4] = 1; 3496 | txt = this.quoteForDiff(v1,dd); 3497 | if(sep == "") sep = this.getSeparator(a,b,"->"); 3498 | var is_conflict = false; 3499 | if(have_dd_to_alt) { 3500 | if(!v1.equals(dd_to,dd_to_alt)) is_conflict = true; 3501 | } 3502 | if(!is_conflict) { 3503 | txt = txt + sep + this.quoteForDiff(v1,dd_to); 3504 | if(sep.length > act1.length) act1 = sep; 3505 | } else { 3506 | if(conflict_sep == "") conflict_sep = this.getSeparator(p,a,"!") + sep; 3507 | txt = txt + conflict_sep + this.quoteForDiff(v1,dd_to_alt) + conflict_sep + this.quoteForDiff(v1,dd_to); 3508 | act1 = conflict_sep; 3509 | } 3510 | } 3511 | if(act1 == "" && have_addition) act1 = "+"; 3512 | if(act1 == "+++") { 3513 | if(have_rr) { 3514 | if(active_column != null) active_column[j4] = 1; 3515 | } 3516 | } 3517 | if(publish) { 3518 | if(active_column == null || active_column[j4] > 0) { 3519 | if(txt != null) output.setCell(j4 + 1,at2,v1.toDatum(txt)); else output.setCell(j4 + 1,at2,dd); 3520 | } 3521 | } 3522 | } 3523 | if(publish) { 3524 | output.setCell(0,at2,v1.toDatum(act1)); 3525 | row_map.set(at2,unit1); 3526 | } 3527 | if(act1 != "") { 3528 | if(!publish) { 3529 | if(active != null) active[i5] = 1; 3530 | } 3531 | } 3532 | } 3533 | } 3534 | if(!show_rc_numbers) { 3535 | if(this.flags.always_show_order) show_rc_numbers = true; else if(this.flags.ordered) { 3536 | show_rc_numbers = this.isReordered(row_map,output.get_height()); 3537 | if(!show_rc_numbers) show_rc_numbers = this.isReordered(col_map,output.get_width()); 3538 | } 3539 | } 3540 | var admin_w = 1; 3541 | if(show_rc_numbers && !this.flags.never_show_order) { 3542 | admin_w++; 3543 | var target = new Array(); 3544 | var _g112 = 0; 3545 | var _g23 = output.get_width(); 3546 | while(_g112 < _g23) { 3547 | var i6 = _g112++; 3548 | target.push(i6 + 1); 3549 | } 3550 | output.insertOrDeleteColumns(target,output.get_width() + 1); 3551 | this.l_prev = -1; 3552 | this.r_prev = -1; 3553 | var _g113 = 0; 3554 | var _g24 = output.get_height(); 3555 | while(_g113 < _g24) { 3556 | var i7 = _g113++; 3557 | var unit2 = row_map.get(i7); 3558 | if(unit2 == null) continue; 3559 | output.setCell(0,i7,this.reportUnit(unit2)); 3560 | } 3561 | target = new Array(); 3562 | var _g114 = 0; 3563 | var _g25 = output.get_height(); 3564 | while(_g114 < _g25) { 3565 | var i8 = _g114++; 3566 | target.push(i8 + 1); 3567 | } 3568 | output.insertOrDeleteRows(target,output.get_height() + 1); 3569 | this.l_prev = -1; 3570 | this.r_prev = -1; 3571 | var _g115 = 1; 3572 | var _g26 = output.get_width(); 3573 | while(_g115 < _g26) { 3574 | var i9 = _g115++; 3575 | var unit3 = col_map.get(i9 - 1); 3576 | if(unit3 == null) continue; 3577 | output.setCell(i9,0,this.reportUnit(unit3)); 3578 | } 3579 | output.setCell(0,0,"@:@"); 3580 | } 3581 | if(active_column != null) { 3582 | var all_active = true; 3583 | var _g116 = 0; 3584 | var _g27 = active_column.length; 3585 | while(_g116 < _g27) { 3586 | var i10 = _g116++; 3587 | if(active_column[i10] == 0) { 3588 | all_active = false; 3589 | break; 3590 | } 3591 | } 3592 | if(!all_active) { 3593 | var fate = new Array(); 3594 | var _g28 = 0; 3595 | while(_g28 < admin_w) { 3596 | var i11 = _g28++; 3597 | fate.push(i11); 3598 | } 3599 | var at3 = admin_w; 3600 | var ct = 0; 3601 | var dots = new Array(); 3602 | var _g117 = 0; 3603 | var _g29 = active_column.length; 3604 | while(_g117 < _g29) { 3605 | var i12 = _g117++; 3606 | var off = active_column[i12] == 0; 3607 | if(off) ct = ct + 1; else ct = 0; 3608 | if(off && ct > 1) fate.push(-1); else { 3609 | if(off) dots.push(at3); 3610 | fate.push(at3); 3611 | at3++; 3612 | } 3613 | } 3614 | output.insertOrDeleteColumns(fate,at3); 3615 | var _g30 = 0; 3616 | while(_g30 < dots.length) { 3617 | var d = dots[_g30]; 3618 | ++_g30; 3619 | var _g210 = 0; 3620 | var _g118 = output.get_height(); 3621 | while(_g210 < _g118) { 3622 | var j5 = _g210++; 3623 | output.setCell(d,j5,"..."); 3624 | } 3625 | } 3626 | } 3627 | } 3628 | return true; 3629 | } 3630 | }; 3631 | coopy.TableIO = $hx_exports.coopy.TableIO = function() { 3632 | }; 3633 | coopy.TableIO.__name__ = true; 3634 | coopy.TableIO.prototype = { 3635 | getContent: function(name) { 3636 | return ""; 3637 | } 3638 | ,saveContent: function(name,txt) { 3639 | return false; 3640 | } 3641 | ,args: function() { 3642 | return []; 3643 | } 3644 | ,writeStdout: function(txt) { 3645 | } 3646 | ,writeStderr: function(txt) { 3647 | } 3648 | ,command: function(cmd,args) { 3649 | return 1; 3650 | } 3651 | ,async: function() { 3652 | return false; 3653 | } 3654 | ,exists: function(path) { 3655 | return false; 3656 | } 3657 | }; 3658 | coopy.TableModifier = $hx_exports.coopy.TableModifier = function(t) { 3659 | this.t = t; 3660 | }; 3661 | coopy.TableModifier.__name__ = true; 3662 | coopy.TableModifier.prototype = { 3663 | removeColumn: function(at) { 3664 | var fate = []; 3665 | var _g1 = 0; 3666 | var _g = this.t.get_width(); 3667 | while(_g1 < _g) { 3668 | var i = _g1++; 3669 | if(i < at) fate.push(i); else if(i > at) fate.push(i - 1); else fate.push(-1); 3670 | } 3671 | return this.t.insertOrDeleteColumns(fate,this.t.get_width() - 1); 3672 | } 3673 | }; 3674 | coopy.TableText = $hx_exports.coopy.TableText = function(rows) { 3675 | this.rows = rows; 3676 | this.view = rows.getCellView(); 3677 | }; 3678 | coopy.TableText.__name__ = true; 3679 | coopy.TableText.prototype = { 3680 | getCellText: function(x,y) { 3681 | return this.view.toString(this.rows.getCell(x,y)); 3682 | } 3683 | }; 3684 | coopy.TerminalDiffRender = $hx_exports.coopy.TerminalDiffRender = function() { 3685 | }; 3686 | coopy.TerminalDiffRender.__name__ = true; 3687 | coopy.TerminalDiffRender.prototype = { 3688 | render: function(t) { 3689 | var csv = new coopy.Csv(); 3690 | var result = ""; 3691 | var w = t.get_width(); 3692 | var h = t.get_height(); 3693 | var txt = ""; 3694 | var v = t.getCellView(); 3695 | var tt = new coopy.TableText(t); 3696 | var codes = new haxe.ds.StringMap(); 3697 | codes.set("header","\x1B[0;1m"); 3698 | codes.set("spec","\x1B[35;1m"); 3699 | codes.set("add","\x1B[32;1m"); 3700 | codes.set("conflict","\x1B[33;1m"); 3701 | codes.set("modify","\x1B[34;1m"); 3702 | codes.set("remove","\x1B[31;1m"); 3703 | codes.set("minor","\x1B[2m"); 3704 | codes.set("done","\x1B[0m"); 3705 | var _g = 0; 3706 | while(_g < h) { 3707 | var y = _g++; 3708 | var _g1 = 0; 3709 | while(_g1 < w) { 3710 | var x = _g1++; 3711 | if(x > 0) txt += codes.get("minor") + "," + codes.get("done"); 3712 | var val = tt.getCellText(x,y); 3713 | if(val == null) val = ""; 3714 | var cell = coopy.DiffRender.renderCell(tt,x,y); 3715 | var code = null; 3716 | if(cell.category != null) code = codes.get(cell.category); 3717 | if(cell.category_given_tr != null) { 3718 | var code_tr = codes.get(cell.category_given_tr); 3719 | if(code_tr != null) code = code_tr; 3720 | } 3721 | if(code != null) { 3722 | if(cell.rvalue != null) { 3723 | val = codes.get("remove") + cell.lvalue + codes.get("modify") + cell.pretty_separator + codes.get("add") + cell.rvalue + codes.get("done"); 3724 | if(cell.pvalue != null) val = codes.get("conflict") + cell.pvalue + codes.get("modify") + cell.pretty_separator + val; 3725 | } else { 3726 | val = cell.pretty_value; 3727 | val = code + val + codes.get("done"); 3728 | } 3729 | } 3730 | txt += csv.renderCell(v,val); 3731 | } 3732 | txt += "\r\n"; 3733 | } 3734 | return txt; 3735 | } 3736 | }; 3737 | coopy.Unit = function(l,r,p) { 3738 | if(p == null) p = -2; 3739 | if(r == null) r = -2; 3740 | if(l == null) l = -2; 3741 | this.l = l; 3742 | this.r = r; 3743 | this.p = p; 3744 | }; 3745 | coopy.Unit.__name__ = true; 3746 | coopy.Unit.describe = function(i) { 3747 | if(i >= 0) return "" + i; else return "-"; 3748 | }; 3749 | coopy.Unit.prototype = { 3750 | lp: function() { 3751 | if(this.p == -2) return this.l; else return this.p; 3752 | } 3753 | ,toString: function() { 3754 | if(this.p >= -1) return coopy.Unit.describe(this.p) + "|" + coopy.Unit.describe(this.l) + ":" + coopy.Unit.describe(this.r); 3755 | return coopy.Unit.describe(this.l) + ":" + coopy.Unit.describe(this.r); 3756 | } 3757 | ,fromString: function(txt) { 3758 | txt += "]"; 3759 | var at = 0; 3760 | var _g1 = 0; 3761 | var _g = txt.length; 3762 | while(_g1 < _g) { 3763 | var i = _g1++; 3764 | var ch = HxOverrides.cca(txt,i); 3765 | if(ch >= 48 && ch <= 57) { 3766 | at *= 10; 3767 | at += ch - 48; 3768 | } else if(ch == 45) at = -1; else if(ch == 124) { 3769 | this.p = at; 3770 | at = 0; 3771 | } else if(ch == 58) { 3772 | this.l = at; 3773 | at = 0; 3774 | } else if(ch == 93) { 3775 | this.r = at; 3776 | return true; 3777 | } 3778 | } 3779 | return false; 3780 | } 3781 | }; 3782 | coopy.ViewedDatum = $hx_exports.coopy.ViewedDatum = function(datum,view) { 3783 | this.datum = datum; 3784 | this.view = view; 3785 | }; 3786 | coopy.ViewedDatum.__name__ = true; 3787 | coopy.ViewedDatum.getSimpleView = function(datum) { 3788 | return new coopy.ViewedDatum(datum,new coopy.SimpleView()); 3789 | }; 3790 | coopy.ViewedDatum.prototype = { 3791 | toString: function() { 3792 | return this.view.toString(this.datum); 3793 | } 3794 | ,getBag: function() { 3795 | return this.view.getBag(this.datum); 3796 | } 3797 | ,getTable: function() { 3798 | return this.view.getTable(this.datum); 3799 | } 3800 | ,hasStructure: function() { 3801 | return this.view.hasStructure(this.datum); 3802 | } 3803 | }; 3804 | coopy.Viterbi = $hx_exports.coopy.Viterbi = function() { 3805 | this.K = this.T = 0; 3806 | this.reset(); 3807 | this.cost = new coopy.SparseSheet(); 3808 | this.src = new coopy.SparseSheet(); 3809 | this.path = new coopy.SparseSheet(); 3810 | }; 3811 | coopy.Viterbi.__name__ = true; 3812 | coopy.Viterbi.prototype = { 3813 | reset: function() { 3814 | this.index = 0; 3815 | this.mode = 0; 3816 | this.path_valid = false; 3817 | this.best_cost = 0; 3818 | } 3819 | ,setSize: function(states,sequence_length) { 3820 | this.K = states; 3821 | this.T = sequence_length; 3822 | this.cost.resize(this.K,this.T,0); 3823 | this.src.resize(this.K,this.T,-1); 3824 | this.path.resize(1,this.T,-1); 3825 | } 3826 | ,assertMode: function(next) { 3827 | if(next == 0 && this.mode == 1) this.index++; 3828 | this.mode = next; 3829 | } 3830 | ,addTransition: function(s0,s1,c) { 3831 | var resize = false; 3832 | if(s0 >= this.K) { 3833 | this.K = s0 + 1; 3834 | resize = true; 3835 | } 3836 | if(s1 >= this.K) { 3837 | this.K = s1 + 1; 3838 | resize = true; 3839 | } 3840 | if(resize) { 3841 | this.cost.nonDestructiveResize(this.K,this.T,0); 3842 | this.src.nonDestructiveResize(this.K,this.T,-1); 3843 | this.path.nonDestructiveResize(1,this.T,-1); 3844 | } 3845 | this.path_valid = false; 3846 | this.assertMode(1); 3847 | if(this.index >= this.T) { 3848 | this.T = this.index + 1; 3849 | this.cost.nonDestructiveResize(this.K,this.T,0); 3850 | this.src.nonDestructiveResize(this.K,this.T,-1); 3851 | this.path.nonDestructiveResize(1,this.T,-1); 3852 | } 3853 | var sourced = false; 3854 | if(this.index > 0) { 3855 | c += this.cost.get(s0,this.index - 1); 3856 | sourced = this.src.get(s0,this.index - 1) != -1; 3857 | } else sourced = true; 3858 | if(sourced) { 3859 | if(c < this.cost.get(s1,this.index) || this.src.get(s1,this.index) == -1) { 3860 | this.cost.set(s1,this.index,c); 3861 | this.src.set(s1,this.index,s0); 3862 | } 3863 | } 3864 | } 3865 | ,endTransitions: function() { 3866 | this.path_valid = false; 3867 | this.assertMode(0); 3868 | } 3869 | ,beginTransitions: function() { 3870 | this.path_valid = false; 3871 | this.assertMode(1); 3872 | } 3873 | ,calculatePath: function() { 3874 | if(this.path_valid) return; 3875 | this.endTransitions(); 3876 | var best = 0; 3877 | var bestj = -1; 3878 | if(this.index <= 0) { 3879 | this.path_valid = true; 3880 | return; 3881 | } 3882 | var _g1 = 0; 3883 | var _g = this.K; 3884 | while(_g1 < _g) { 3885 | var j = _g1++; 3886 | if((this.cost.get(j,this.index - 1) < best || bestj == -1) && this.src.get(j,this.index - 1) != -1) { 3887 | best = this.cost.get(j,this.index - 1); 3888 | bestj = j; 3889 | } 3890 | } 3891 | this.best_cost = best; 3892 | var _g11 = 0; 3893 | var _g2 = this.index; 3894 | while(_g11 < _g2) { 3895 | var j1 = _g11++; 3896 | var i = this.index - 1 - j1; 3897 | this.path.set(0,i,bestj); 3898 | if(!(bestj != -1 && (bestj >= 0 && bestj < this.K))) console.log("Problem in Viterbi"); 3899 | bestj = this.src.get(bestj,i); 3900 | } 3901 | this.path_valid = true; 3902 | } 3903 | ,toString: function() { 3904 | this.calculatePath(); 3905 | var txt = ""; 3906 | var _g1 = 0; 3907 | var _g = this.index; 3908 | while(_g1 < _g) { 3909 | var i = _g1++; 3910 | if(this.path.get(0,i) == -1) txt += "*"; else txt += this.path.get(0,i); 3911 | if(this.K >= 10) txt += " "; 3912 | } 3913 | txt += " costs " + this.getCost(); 3914 | return txt; 3915 | } 3916 | ,length: function() { 3917 | if(this.index > 0) this.calculatePath(); 3918 | return this.index; 3919 | } 3920 | ,get: function(i) { 3921 | this.calculatePath(); 3922 | return this.path.get(0,i); 3923 | } 3924 | ,getCost: function() { 3925 | this.calculatePath(); 3926 | return this.best_cost; 3927 | } 3928 | }; 3929 | coopy.Workspace = function() { 3930 | }; 3931 | coopy.Workspace.__name__ = true; 3932 | var haxe = {}; 3933 | haxe.ds = {}; 3934 | haxe.ds.IntMap = function() { 3935 | this.h = { }; 3936 | }; 3937 | haxe.ds.IntMap.__name__ = true; 3938 | haxe.ds.IntMap.__interfaces__ = [IMap]; 3939 | haxe.ds.IntMap.prototype = { 3940 | set: function(key,value) { 3941 | this.h[key] = value; 3942 | } 3943 | ,get: function(key) { 3944 | return this.h[key]; 3945 | } 3946 | ,exists: function(key) { 3947 | return this.h.hasOwnProperty(key); 3948 | } 3949 | ,remove: function(key) { 3950 | if(!this.h.hasOwnProperty(key)) return false; 3951 | delete(this.h[key]); 3952 | return true; 3953 | } 3954 | ,keys: function() { 3955 | var a = []; 3956 | for( var key in this.h ) { 3957 | if(this.h.hasOwnProperty(key)) a.push(key | 0); 3958 | } 3959 | return HxOverrides.iter(a); 3960 | } 3961 | ,toString: function() { 3962 | var s = new StringBuf(); 3963 | s.b += "{"; 3964 | var it = this.keys(); 3965 | while( it.hasNext() ) { 3966 | var i = it.next(); 3967 | if(i == null) s.b += "null"; else s.b += "" + i; 3968 | s.b += " => "; 3969 | s.add(Std.string(this.get(i))); 3970 | if(it.hasNext()) s.b += ", "; 3971 | } 3972 | s.b += "}"; 3973 | return s.b; 3974 | } 3975 | }; 3976 | haxe.ds.StringMap = function() { 3977 | this.h = { }; 3978 | }; 3979 | haxe.ds.StringMap.__name__ = true; 3980 | haxe.ds.StringMap.__interfaces__ = [IMap]; 3981 | haxe.ds.StringMap.prototype = { 3982 | set: function(key,value) { 3983 | this.h["$" + key] = value; 3984 | } 3985 | ,get: function(key) { 3986 | return this.h["$" + key]; 3987 | } 3988 | ,exists: function(key) { 3989 | return this.h.hasOwnProperty("$" + key); 3990 | } 3991 | ,keys: function() { 3992 | var a = []; 3993 | for( var key in this.h ) { 3994 | if(this.h.hasOwnProperty(key)) a.push(key.substr(1)); 3995 | } 3996 | return HxOverrides.iter(a); 3997 | } 3998 | ,iterator: function() { 3999 | return { ref : this.h, it : this.keys(), hasNext : function() { 4000 | return this.it.hasNext(); 4001 | }, next : function() { 4002 | var i = this.it.next(); 4003 | return this.ref["$" + i]; 4004 | }}; 4005 | } 4006 | }; 4007 | var js = {}; 4008 | js.Boot = function() { }; 4009 | js.Boot.__name__ = true; 4010 | js.Boot.__string_rec = function(o,s) { 4011 | if(o == null) return "null"; 4012 | if(s.length >= 5) return "<...>"; 4013 | var t = typeof(o); 4014 | if(t == "function" && (o.__name__ || o.__ename__)) t = "object"; 4015 | switch(t) { 4016 | case "object": 4017 | if(o instanceof Array) { 4018 | if(o.__enum__) { 4019 | if(o.length == 2) return o[0]; 4020 | var str = o[0] + "("; 4021 | s += "\t"; 4022 | var _g1 = 2; 4023 | var _g = o.length; 4024 | while(_g1 < _g) { 4025 | var i = _g1++; 4026 | if(i != 2) str += "," + js.Boot.__string_rec(o[i],s); else str += js.Boot.__string_rec(o[i],s); 4027 | } 4028 | return str + ")"; 4029 | } 4030 | var l = o.length; 4031 | var i1; 4032 | var str1 = "["; 4033 | s += "\t"; 4034 | var _g2 = 0; 4035 | while(_g2 < l) { 4036 | var i2 = _g2++; 4037 | str1 += (i2 > 0?",":"") + js.Boot.__string_rec(o[i2],s); 4038 | } 4039 | str1 += "]"; 4040 | return str1; 4041 | } 4042 | var tostr; 4043 | try { 4044 | tostr = o.toString; 4045 | } catch( e ) { 4046 | return "???"; 4047 | } 4048 | if(tostr != null && tostr != Object.toString) { 4049 | var s2 = o.toString(); 4050 | if(s2 != "[object Object]") return s2; 4051 | } 4052 | var k = null; 4053 | var str2 = "{\n"; 4054 | s += "\t"; 4055 | var hasp = o.hasOwnProperty != null; 4056 | for( var k in o ) { 4057 | if(hasp && !o.hasOwnProperty(k)) { 4058 | continue; 4059 | } 4060 | if(k == "prototype" || k == "__class__" || k == "__super__" || k == "__interfaces__" || k == "__properties__") { 4061 | continue; 4062 | } 4063 | if(str2.length != 2) str2 += ", \n"; 4064 | str2 += s + k + " : " + js.Boot.__string_rec(o[k],s); 4065 | } 4066 | s = s.substring(1); 4067 | str2 += "\n" + s + "}"; 4068 | return str2; 4069 | case "function": 4070 | return ""; 4071 | case "string": 4072 | return o; 4073 | default: 4074 | return String(o); 4075 | } 4076 | }; 4077 | function $iterator(o) { if( o instanceof Array ) return function() { return HxOverrides.iter(o); }; return typeof(o.iterator) == 'function' ? $bind(o,o.iterator) : o.iterator; } 4078 | var $_, $fid = 0; 4079 | function $bind(o,m) { if( m == null ) return null; if( m.__id__ == null ) m.__id__ = $fid++; var f; if( o.hx__closures__ == null ) o.hx__closures__ = {}; else f = o.hx__closures__[m.__id__]; if( f == null ) { f = function(){ return f.method.apply(f.scope, arguments); }; f.scope = o; f.method = m; o.hx__closures__[m.__id__] = f; } return f; } 4080 | Math.NaN = Number.NaN; 4081 | Math.NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY; 4082 | Math.POSITIVE_INFINITY = Number.POSITIVE_INFINITY; 4083 | Math.isFinite = function(i) { 4084 | return isFinite(i); 4085 | }; 4086 | Math.isNaN = function(i1) { 4087 | return isNaN(i1); 4088 | }; 4089 | String.__name__ = true; 4090 | Array.__name__ = true; 4091 | coopy.Coopy.VERSION = "1.1.8"; 4092 | coopy.Coopy.main(); 4093 | })(typeof window != "undefined" ? window : exports); 4094 | 4095 | 4096 | if (typeof exports != "undefined") { 4097 | // avoid having excess nesting (coopy.coopy) when using node 4098 | for (f in exports.coopy) { 4099 | if (exports.coopy.hasOwnProperty(f)) { 4100 | exports[f] = exports.coopy[f]; 4101 | } 4102 | } 4103 | // promote methods of coopy.Coopy 4104 | for (f in exports.Coopy) { 4105 | if (exports.Coopy.hasOwnProperty(f)) { 4106 | exports[f] = exports.Coopy[f]; 4107 | } 4108 | } 4109 | } else { 4110 | // promote methods of coopy.Coopy 4111 | for (f in coopy.Coopy) { 4112 | if (coopy.Coopy.hasOwnProperty(f)) { 4113 | coopy[f] = coopy.Coopy[f]; 4114 | } 4115 | } 4116 | daff = coopy; 4117 | } 4118 | (function() { 4119 | 4120 | var coopy = null; 4121 | if (typeof exports != "undefined") { 4122 | if (typeof exports.Coopy != "undefined") { 4123 | coopy = exports; 4124 | } 4125 | } 4126 | if (coopy == null) { 4127 | coopy = window.daff; 4128 | } 4129 | 4130 | var TableView = function(data) { 4131 | // variant constructor (cols, rows) 4132 | if (arguments.length==2) { 4133 | var lst = []; 4134 | for (var i=0; i0) { 4147 | this.width = data[0].length; 4148 | } 4149 | } 4150 | 4151 | TableView.prototype.get_width = function() { 4152 | return this.width; 4153 | } 4154 | 4155 | TableView.prototype.get_height = function() { 4156 | return this.height; 4157 | } 4158 | 4159 | TableView.prototype.getCell = function(x,y) { 4160 | return this.data[y][x]; 4161 | } 4162 | 4163 | TableView.prototype.setCell = function(x,y,c) { 4164 | this.data[y][x] = c; 4165 | } 4166 | 4167 | TableView.prototype.toString = function() { 4168 | return coopy.SimpleTable.tableToString(this); 4169 | } 4170 | 4171 | TableView.prototype.getCellView = function() { 4172 | return new coopy.SimpleView(); 4173 | } 4174 | 4175 | TableView.prototype.isResizable = function() { 4176 | return true; 4177 | } 4178 | 4179 | TableView.prototype.resize = function(w,h) { 4180 | this.width = w; 4181 | this.height = h; 4182 | for (var i=0; i=this.width) break; 4235 | var row = this.data[i]; 4236 | for (var j=0; jtop_content) { 4240 | top_content = j; 4241 | } 4242 | } 4243 | } 4244 | } 4245 | if (this.height==0 || top_content+1==this.width) return false; 4246 | this.width = top_content+1; 4247 | return true; 4248 | } 4249 | 4250 | TableView.prototype.getData = function() { 4251 | return this.data; 4252 | } 4253 | 4254 | TableView.prototype.clone = function() { 4255 | var ndata = []; 4256 | for (var i=0; i=0) { 4381 | argi = "\"" + argi + "\""; 4382 | } 4383 | cmd += " " + argi; 4384 | } 4385 | var cmd = cmd; + " " + args.join(" "); 4386 | if (cmd == cmd_pending) { 4387 | cmd_pending = null; 4388 | return cmd_result; 4389 | } else if (cmd_pending!=null) { 4390 | return 998; // "hack not working correctly" 4391 | } 4392 | cmd_pending = cmd; 4393 | return 999; // "cannot be executed synchronously" 4394 | } 4395 | 4396 | var main = new coopy.Coopy(); 4397 | 4398 | function run_daff() { 4399 | var code = main.coopyhx(tio); 4400 | if (code==999) { 4401 | if (cmd_pending!=null) { 4402 | exec(cmd_pending,function(error,stdout,stderr) { 4403 | cmd_result = 0; 4404 | if (error!=null) { 4405 | cmd_result = error.code; 4406 | } 4407 | run_daff(); 4408 | }); 4409 | } 4410 | } else { 4411 | process.exit(code); 4412 | } 4413 | } 4414 | run_daff(); 4415 | } 4416 | } 4417 | -------------------------------------------------------------------------------- /js/jquery.csv-0.71.js: -------------------------------------------------------------------------------- 1 | /** 2 | * jQuery-csv (jQuery Plugin) 3 | * version: 0.71 (2012-11-19) 4 | * 5 | * This document is licensed as free software under the terms of the 6 | * MIT License: http://www.opensource.org/licenses/mit-license.php 7 | * 8 | * Acknowledgements: 9 | * The original design and influence to implement this library as a jquery 10 | * plugin is influenced by jquery-json (http://code.google.com/p/jquery-json/). 11 | * If you're looking to use native JSON.Stringify but want additional backwards 12 | * compatibility for browsers that don't support it, I highly recommend you 13 | * check it out. 14 | * 15 | * A special thanks goes out to rwk@acm.org for providing a lot of valuable 16 | * feedback to the project including the core for the new FSM 17 | * (Finite State Machine) parsers. If you're looking for a stable TSV parser 18 | * be sure to take a look at jquery-tsv (http://code.google.com/p/jquery-tsv/). 19 | 20 | * For legal purposes I'll include the "NO WARRANTY EXPRESSED OR IMPLIED. 21 | * USE AT YOUR OWN RISK.". Which, in 'layman's terms' means, by using this 22 | * library you are accepting responsibility if it breaks your code. 23 | * 24 | * Legal jargon aside, I will do my best to provide a useful and stable core 25 | * that can effectively be built on. 26 | * 27 | * Copyrighted 2012 by Evan Plaice. 28 | */ 29 | 30 | RegExp.escape= function(s) { 31 | return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); 32 | }; 33 | 34 | (function( $ ) { 35 | 'use strict' 36 | /** 37 | * jQuery.csv.defaults 38 | * Encapsulates the method paramater defaults for the CSV plugin module. 39 | */ 40 | 41 | $.csv = { 42 | defaults: { 43 | separator:',', 44 | delimiter:'"', 45 | headers:true 46 | }, 47 | 48 | hooks: { 49 | castToScalar: function(value, state) { 50 | var hasDot = /\./; 51 | if (isNaN(value)) { 52 | return value; 53 | } else { 54 | if (hasDot.test(value)) { 55 | return parseFloat(value); 56 | } else { 57 | var integer = parseInt(value); 58 | if(isNaN(integer)) { 59 | return null; 60 | } else { 61 | return integer; 62 | } 63 | } 64 | } 65 | } 66 | }, 67 | 68 | parsers: { 69 | parse: function(csv, options) { 70 | // cache settings 71 | var separator = options.separator; 72 | var delimiter = options.delimiter; 73 | 74 | // set initial state if it's missing 75 | if(!options.state.rowNum) { 76 | options.state.rowNum = 1; 77 | } 78 | if(!options.state.colNum) { 79 | options.state.colNum = 1; 80 | } 81 | 82 | // clear initial state 83 | var data = []; 84 | var entry = []; 85 | var state = 0; 86 | var value = '' 87 | var exit = false; 88 | 89 | function endOfEntry() { 90 | // reset the state 91 | state = 0; 92 | value = ''; 93 | 94 | // if 'start' hasn't been met, don't output 95 | if(options.start && options.state.rowNum < options.start) { 96 | // update global state 97 | entry = []; 98 | options.state.rowNum++; 99 | options.state.colNum = 1; 100 | return; 101 | } 102 | 103 | if(options.onParseEntry === undefined) { 104 | // onParseEntry hook not set 105 | data.push(entry); 106 | } else { 107 | var hookVal = options.onParseEntry(entry, options.state); // onParseEntry Hook 108 | // false skips the row, configurable through a hook 109 | if(hookVal !== false) { 110 | data.push(hookVal); 111 | } 112 | } 113 | //console.log('entry:' + entry); 114 | 115 | // cleanup 116 | entry = []; 117 | 118 | // if 'end' is met, stop parsing 119 | if(options.end && options.state.rowNum >= options.end) { 120 | exit = true; 121 | } 122 | 123 | // update global state 124 | options.state.rowNum++; 125 | options.state.colNum = 1; 126 | } 127 | 128 | function endOfValue() { 129 | if(options.onParseValue === undefined) { 130 | // onParseValue hook not set 131 | entry.push(value); 132 | } else { 133 | var hook = options.onParseValue(value, options.state); // onParseValue Hook 134 | // false skips the row, configurable through a hook 135 | if(hook !== false) { 136 | entry.push(hook); 137 | } 138 | } 139 | //console.log('value:' + value); 140 | // reset the state 141 | value = ''; 142 | state = 0; 143 | // update global state 144 | options.state.colNum++; 145 | } 146 | 147 | // escape regex-specific control chars 148 | var escSeparator = RegExp.escape(separator); 149 | var escDelimiter = RegExp.escape(delimiter); 150 | 151 | // compile the regEx str using the custom delimiter/separator 152 | var match = /(D|S|\n|\r|[^DS\r\n]+)/; 153 | var matchSrc = match.source; 154 | matchSrc = matchSrc.replace(/S/g, escSeparator); 155 | matchSrc = matchSrc.replace(/D/g, escDelimiter); 156 | match = RegExp(matchSrc, 'gm'); 157 | 158 | // put on your fancy pants... 159 | // process control chars individually, use look-ahead on non-control chars 160 | csv.replace(match, function (m0) { 161 | if(exit) { 162 | return; 163 | } 164 | switch (state) { 165 | // the start of a value 166 | case 0: 167 | // null last value 168 | if (m0 === separator) { 169 | value += ''; 170 | endOfValue(); 171 | break; 172 | } 173 | // opening delimiter 174 | if (m0 === delimiter) { 175 | state = 1; 176 | break; 177 | } 178 | // null last value 179 | if (m0 === '\n') { 180 | endOfValue(); 181 | endOfEntry(); 182 | break; 183 | } 184 | // phantom carriage return 185 | if (/^\r$/.test(m0)) { 186 | break; 187 | } 188 | // un-delimited value 189 | value += m0; 190 | state = 3; 191 | break; 192 | 193 | // delimited input 194 | case 1: 195 | // second delimiter? check further 196 | if (m0 === delimiter) { 197 | state = 2; 198 | break; 199 | } 200 | // delimited data 201 | value += m0; 202 | state = 1; 203 | break; 204 | 205 | // delimiter found in delimited input 206 | case 2: 207 | // escaped delimiter? 208 | if (m0 === delimiter) { 209 | value += m0; 210 | state = 1; 211 | break; 212 | } 213 | // null value 214 | if (m0 === separator) { 215 | endOfValue(); 216 | break; 217 | } 218 | // end of entry 219 | if (m0 === '\n') { 220 | endOfValue(); 221 | endOfEntry(); 222 | break; 223 | } 224 | // phantom carriage return 225 | if (/^\r$/.test(m0)) { 226 | break; 227 | } 228 | // broken paser? 229 | throw new Error('CSVDataError: Illegal State [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']'); 230 | 231 | // un-delimited input 232 | case 3: 233 | // null last value 234 | if (m0 === separator) { 235 | endOfValue(); 236 | break; 237 | } 238 | // end of entry 239 | if (m0 === '\n') { 240 | endOfValue(); 241 | endOfEntry(); 242 | break; 243 | } 244 | // phantom carriage return 245 | if (/^\r$/.test(m0)) { 246 | break; 247 | } 248 | if (m0 === delimiter) { 249 | // non-compliant data 250 | throw new Error('CSVDataError: Illegal Quote [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']'); 251 | } 252 | // broken parser? 253 | throw new Error('CSVDataError: Illegal Data [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']'); 254 | default: 255 | // shenanigans 256 | throw new Error('CSVDataError: Unknown State [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']'); 257 | } 258 | //console.log('val:' + m0 + ' state:' + state); 259 | }); 260 | 261 | // submit the last entry 262 | // ignore null last line 263 | if(entry.length !== 0) { 264 | endOfValue(); 265 | endOfEntry(); 266 | } 267 | 268 | return data; 269 | }, 270 | 271 | // a csv-specific line splitter 272 | splitLines: function(csv, options) { 273 | // cache settings 274 | var separator = options.separator; 275 | var delimiter = options.delimiter; 276 | 277 | // set initial state if it's missing 278 | if(!options.state.rowNum) { 279 | options.state.rowNum = 1; 280 | } 281 | 282 | // clear initial state 283 | var entries = []; 284 | var state = 0; 285 | var entry = ''; 286 | var exit = false; 287 | 288 | function endOfLine() { 289 | // reset the state 290 | state = 0; 291 | 292 | // if 'start' hasn't been met, don't output 293 | if(options.start && options.state.rowNum < options.start) { 294 | // update global state 295 | entry = ''; 296 | options.state.rowNum++; 297 | return; 298 | } 299 | 300 | if(options.onParseEntry === undefined) { 301 | // onParseEntry hook not set 302 | entries.push(entry); 303 | } else { 304 | var hookVal = options.onParseEntry(entry, options.state); // onParseEntry Hook 305 | // false skips the row, configurable through a hook 306 | if(hookVal !== false) { 307 | entries.push(hookVal); 308 | } 309 | } 310 | 311 | // cleanup 312 | entry = ''; 313 | 314 | // if 'end' is met, stop parsing 315 | if(options.end && options.state.rowNum >= options.end) { 316 | exit = true; 317 | } 318 | 319 | // update global state 320 | options.state.rowNum++; 321 | } 322 | 323 | // escape regex-specific control chars 324 | var escSeparator = RegExp.escape(separator); 325 | var escDelimiter = RegExp.escape(delimiter); 326 | 327 | // compile the regEx str using the custom delimiter/separator 328 | var match = /(D|S|\n|\r|[^DS\r\n]+)/; 329 | var matchSrc = match.source; 330 | matchSrc = matchSrc.replace(/S/g, escSeparator); 331 | matchSrc = matchSrc.replace(/D/g, escDelimiter); 332 | match = RegExp(matchSrc, 'gm'); 333 | 334 | // put on your fancy pants... 335 | // process control chars individually, use look-ahead on non-control chars 336 | csv.replace(match, function (m0) { 337 | if(exit) { 338 | return; 339 | } 340 | switch (state) { 341 | // the start of a value/entry 342 | case 0: 343 | // null value 344 | if (m0 === separator) { 345 | entry += m0; 346 | state = 0; 347 | break; 348 | } 349 | // opening delimiter 350 | if (m0 === delimiter) { 351 | entry += m0; 352 | state = 1; 353 | break; 354 | } 355 | // end of line 356 | if (m0 === '\n') { 357 | endOfLine(); 358 | break; 359 | } 360 | // phantom carriage return 361 | if (/^\r$/.test(m0)) { 362 | break; 363 | } 364 | // un-delimit value 365 | entry += m0; 366 | state = 3; 367 | break; 368 | 369 | // delimited input 370 | case 1: 371 | // second delimiter? check further 372 | if (m0 === delimiter) { 373 | entry += m0; 374 | state = 2; 375 | break; 376 | } 377 | // delimited data 378 | entry += m0; 379 | state = 1; 380 | break; 381 | 382 | // delimiter found in delimited input 383 | case 2: 384 | // escaped delimiter? 385 | var prevChar = entry.substr(entry.length - 1); 386 | if (m0 === delimiter && prevChar === delimiter) { 387 | entry += m0; 388 | state = 1; 389 | break; 390 | } 391 | // end of value 392 | if (m0 === separator) { 393 | entry += m0; 394 | state = 0; 395 | break; 396 | } 397 | // end of line 398 | if (m0 === '\n') { 399 | endOfLine(); 400 | break; 401 | } 402 | // phantom carriage return 403 | if (m0 === '\r') { 404 | break; 405 | } 406 | // broken paser? 407 | throw new Error('CSVDataError: Illegal state [Row:' + options.state.rowNum + ']'); 408 | 409 | // un-delimited input 410 | case 3: 411 | // null value 412 | if (m0 === separator) { 413 | entry += m0; 414 | state = 0; 415 | break; 416 | } 417 | // end of line 418 | if (m0 === '\n') { 419 | endOfLine(); 420 | break; 421 | } 422 | // phantom carriage return 423 | if (m0 === '\r') { 424 | break; 425 | } 426 | // non-compliant data 427 | if (m0 === delimiter) { 428 | throw new Error('CSVDataError: Illegal quote [Row:' + options.state.rowNum + ']'); 429 | } 430 | // broken parser? 431 | throw new Error('CSVDataError: Illegal state [Row:' + options.state.rowNum + ']'); 432 | default: 433 | // shenanigans 434 | throw new Error('CSVDataError: Unknown state [Row:' + options.state.rowNum + ']'); 435 | } 436 | //console.log('val:' + m0 + ' state:' + state); 437 | }); 438 | 439 | // submit the last entry 440 | // ignore null last line 441 | if(entry !== '') { 442 | endOfLine(); 443 | } 444 | 445 | return entries; 446 | }, 447 | 448 | // a csv entry parser 449 | parseEntry: function(csv, options) { 450 | // cache settings 451 | var separator = options.separator; 452 | var delimiter = options.delimiter; 453 | 454 | // set initial state if it's missing 455 | if(!options.state.rowNum) { 456 | options.state.rowNum = 1; 457 | } 458 | if(!options.state.colNum) { 459 | options.state.colNum = 1; 460 | } 461 | 462 | // clear initial state 463 | var entry = []; 464 | var state = 0; 465 | var value = ''; 466 | 467 | function endOfValue() { 468 | if(options.onParseValue === undefined) { 469 | // onParseValue hook not set 470 | entry.push(value); 471 | } else { 472 | var hook = options.onParseValue(value, options.state); // onParseValue Hook 473 | // false skips the value, configurable through a hook 474 | if(hook !== false) { 475 | entry.push(hook); 476 | } 477 | } 478 | // reset the state 479 | value = ''; 480 | state = 0; 481 | // update global state 482 | options.state.colNum++; 483 | } 484 | 485 | // checked for a cached regEx first 486 | if(!options.match) { 487 | // escape regex-specific control chars 488 | var escSeparator = RegExp.escape(separator); 489 | var escDelimiter = RegExp.escape(delimiter); 490 | 491 | // compile the regEx str using the custom delimiter/separator 492 | var match = /(D|S|\n|\r|[^DS\r\n]+)/; 493 | var matchSrc = match.source; 494 | matchSrc = matchSrc.replace(/S/g, escSeparator); 495 | matchSrc = matchSrc.replace(/D/g, escDelimiter); 496 | options.match = RegExp(matchSrc, 'gm'); 497 | } 498 | 499 | // put on your fancy pants... 500 | // process control chars individually, use look-ahead on non-control chars 501 | csv.replace(options.match, function (m0) { 502 | switch (state) { 503 | // the start of a value 504 | case 0: 505 | // null last value 506 | if (m0 === separator) { 507 | value += ''; 508 | endOfValue(); 509 | break; 510 | } 511 | // opening delimiter 512 | if (m0 === delimiter) { 513 | state = 1; 514 | break; 515 | } 516 | // skip un-delimited new-lines 517 | if (m0 === '\n' || m0 === '\r') { 518 | break; 519 | } 520 | // un-delimited value 521 | value += m0; 522 | state = 3; 523 | break; 524 | 525 | // delimited input 526 | case 1: 527 | // second delimiter? check further 528 | if (m0 === delimiter) { 529 | state = 2; 530 | break; 531 | } 532 | // delimited data 533 | value += m0; 534 | state = 1; 535 | break; 536 | 537 | // delimiter found in delimited input 538 | case 2: 539 | // escaped delimiter? 540 | if (m0 === delimiter) { 541 | value += m0; 542 | state = 1; 543 | break; 544 | } 545 | // null value 546 | if (m0 === separator) { 547 | endOfValue(); 548 | break; 549 | } 550 | // skip un-delimited new-lines 551 | if (m0 === '\n' || m0 === '\r') { 552 | break; 553 | } 554 | // broken paser? 555 | throw new Error('CSVDataError: Illegal State [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']'); 556 | 557 | // un-delimited input 558 | case 3: 559 | // null last value 560 | if (m0 === separator) { 561 | endOfValue(); 562 | break; 563 | } 564 | // skip un-delimited new-lines 565 | if (m0 === '\n' || m0 === '\r') { 566 | break; 567 | } 568 | // non-compliant data 569 | if (m0 === delimiter) { 570 | throw new Error('CSVDataError: Illegal Quote [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']'); 571 | } 572 | // broken parser? 573 | throw new Error('CSVDataError: Illegal Data [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']'); 574 | default: 575 | // shenanigans 576 | throw new Error('CSVDataError: Unknown State [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']'); 577 | } 578 | //console.log('val:' + m0 + ' state:' + state); 579 | }); 580 | 581 | // submit the last value 582 | endOfValue(); 583 | 584 | return entry; 585 | } 586 | }, 587 | 588 | /** 589 | * $.csv.toArray(csv) 590 | * Converts a CSV entry string to a javascript array. 591 | * 592 | * @param {Array} csv The string containing the CSV data. 593 | * @param {Object} [options] An object containing user-defined options. 594 | * @param {Character} [separator] An override for the separator character. Defaults to a comma(,). 595 | * @param {Character} [delimiter] An override for the delimiter character. Defaults to a double-quote("). 596 | * 597 | * This method deals with simple CSV strings only. It's useful if you only 598 | * need to parse a single entry. If you need to parse more than one line, 599 | * use $.csv2Array instead. 600 | */ 601 | toArray: function(csv, options, callback) { 602 | var options = (options !== undefined ? options : {}); 603 | var config = {}; 604 | config.callback = ((callback !== undefined && typeof(callback) === 'function') ? callback : false); 605 | config.separator = 'separator' in options ? options.separator : $.csv.defaults.separator; 606 | config.delimiter = 'delimiter' in options ? options.delimiter : $.csv.defaults.delimiter; 607 | var state = (options.state !== undefined ? options.state : {}); 608 | 609 | // setup 610 | var options = { 611 | delimiter: config.delimiter, 612 | separator: config.separator, 613 | onParseEntry: options.onParseEntry, 614 | onParseValue: options.onParseValue, 615 | state: state 616 | } 617 | 618 | var entry = $.csv.parsers.parseEntry(csv, options); 619 | 620 | // push the value to a callback if one is defined 621 | if(!config.callback) { 622 | return entry; 623 | } else { 624 | config.callback('', entry); 625 | } 626 | }, 627 | 628 | /** 629 | * $.csv.toArrays(csv) 630 | * Converts a CSV string to a javascript array. 631 | * 632 | * @param {String} csv The string containing the raw CSV data. 633 | * @param {Object} [options] An object containing user-defined options. 634 | * @param {Character} [separator] An override for the separator character. Defaults to a comma(,). 635 | * @param {Character} [delimiter] An override for the delimiter character. Defaults to a double-quote("). 636 | * 637 | * This method deals with multi-line CSV. The breakdown is simple. The first 638 | * dimension of the array represents the line (or entry/row) while the second 639 | * dimension contains the values (or values/columns). 640 | */ 641 | toArrays: function(csv, options, callback) { 642 | var options = (options !== undefined ? options : {}); 643 | var config = {}; 644 | config.callback = ((callback !== undefined && typeof(callback) === 'function') ? callback : false); 645 | config.separator = 'separator' in options ? options.separator : $.csv.defaults.separator; 646 | config.delimiter = 'delimiter' in options ? options.delimiter : $.csv.defaults.delimiter; 647 | 648 | // setup 649 | var data = []; 650 | var options = { 651 | delimiter: config.delimiter, 652 | separator: config.separator, 653 | onParseEntry: options.onParseEntry, 654 | onParseValue: options.onParseValue, 655 | start: options.start, 656 | end: options.end, 657 | state: { 658 | rowNum: 1, 659 | colNum: 1 660 | } 661 | }; 662 | 663 | // break the data down to lines 664 | data = $.csv.parsers.parse(csv, options); 665 | 666 | // push the value to a callback if one is defined 667 | if(!config.callback) { 668 | return data; 669 | } else { 670 | config.callback('', data); 671 | } 672 | }, 673 | 674 | /** 675 | * $.csv.toObjects(csv) 676 | * Converts a CSV string to a javascript object. 677 | * @param {String} csv The string containing the raw CSV data. 678 | * @param {Object} [options] An object containing user-defined options. 679 | * @param {Character} [separator] An override for the separator character. Defaults to a comma(,). 680 | * @param {Character} [delimiter] An override for the delimiter character. Defaults to a double-quote("). 681 | * @param {Boolean} [headers] Indicates whether the data contains a header line. Defaults to true. 682 | * 683 | * This method deals with multi-line CSV strings. Where the headers line is 684 | * used as the key for each value per entry. 685 | */ 686 | toObjects: function(csv, options, callback) { 687 | var options = (options !== undefined ? options : {}); 688 | var config = {}; 689 | config.callback = ((callback !== undefined && typeof(callback) === 'function') ? callback : false); 690 | config.separator = 'separator' in options ? options.separator : $.csv.defaults.separator; 691 | config.delimiter = 'delimiter' in options ? options.delimiter : $.csv.defaults.delimiter; 692 | config.headers = 'headers' in options ? options.headers : $.csv.defaults.headers; 693 | options.start = 'start' in options ? options.start : 1; 694 | 695 | // account for headers 696 | if(config.headers) { 697 | options.start++; 698 | } 699 | if(options.end && config.headers) { 700 | options.end++; 701 | } 702 | 703 | // setup 704 | var lines = []; 705 | var data = []; 706 | 707 | var options = { 708 | delimiter: config.delimiter, 709 | separator: config.separator, 710 | onParseEntry: options.onParseEntry, 711 | onParseValue: options.onParseValue, 712 | start: options.start, 713 | end: options.end, 714 | state: { 715 | rowNum: 1, 716 | colNum: 1 717 | }, 718 | match: false 719 | }; 720 | 721 | // fetch the headers 722 | var headerOptions = { 723 | delimiter: config.delimiter, 724 | separator: config.separator, 725 | start: 1, 726 | end: 1, 727 | state: { 728 | rowNum:1, 729 | colNum:1 730 | } 731 | } 732 | var headerLine = $.csv.parsers.splitLines(csv, headerOptions); 733 | var headers = $.csv.toArray(headerLine[0], options); 734 | 735 | // fetch the data 736 | var lines = $.csv.parsers.splitLines(csv, options); 737 | 738 | // reset the state for re-use 739 | options.state.colNum = 1; 740 | if(headers){ 741 | options.state.rowNum = 2; 742 | } else { 743 | options.state.rowNum = 1; 744 | } 745 | 746 | // convert data to objects 747 | for(var i=0, len=lines.length; i