1/* 2 * LibXDiff by Davide Libenzi ( File Differential Library ) 3 * Copyright (C) 2003 Davide Libenzi 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * 19 * Davide Libenzi <davidel@xmailserver.org> 20 * 21 */ 22 23#include"xinclude.h" 24 25 26 27#define XDL_MAX_COST_MIN 256 28#define XDL_HEUR_MIN_COST 256 29#define XDL_LINE_MAX (long)((1UL << (CHAR_BIT * sizeof(long) - 1)) - 1) 30#define XDL_SNAKE_CNT 20 31#define XDL_K_HEUR 4 32 33 34 35typedefstruct s_xdpsplit { 36long i1, i2; 37int min_lo, min_hi; 38} xdpsplit_t; 39 40 41 42 43static longxdl_split(unsigned long const*ha1,long off1,long lim1, 44unsigned long const*ha2,long off2,long lim2, 45long*kvdf,long*kvdb,int need_min, xdpsplit_t *spl, 46 xdalgoenv_t *xenv); 47static xdchange_t *xdl_add_change(xdchange_t *xscr,long i1,long i2,long chg1,long chg2); 48 49 50 51 52 53/* 54 * See "An O(ND) Difference Algorithm and its Variations", by Eugene Myers. 55 * Basically considers a "box" (off1, off2, lim1, lim2) and scan from both 56 * the forward diagonal starting from (off1, off2) and the backward diagonal 57 * starting from (lim1, lim2). If the K values on the same diagonal crosses 58 * returns the furthest point of reach. We might end up having to expensive 59 * cases using this algorithm is full, so a little bit of heuristic is needed 60 * to cut the search and to return a suboptimal point. 61 */ 62static longxdl_split(unsigned long const*ha1,long off1,long lim1, 63unsigned long const*ha2,long off2,long lim2, 64long*kvdf,long*kvdb,int need_min, xdpsplit_t *spl, 65 xdalgoenv_t *xenv) { 66long dmin = off1 - lim2, dmax = lim1 - off2; 67long fmid = off1 - off2, bmid = lim1 - lim2; 68long odd = (fmid - bmid) &1; 69long fmin = fmid, fmax = fmid; 70long bmin = bmid, bmax = bmid; 71long ec, d, i1, i2, prev1, best, dd, v, k; 72 73/* 74 * Set initial diagonal values for both forward and backward path. 75 */ 76 kvdf[fmid] = off1; 77 kvdb[bmid] = lim1; 78 79for(ec =1;; ec++) { 80int got_snake =0; 81 82/* 83 * We need to extent the diagonal "domain" by one. If the next 84 * values exits the box boundaries we need to change it in the 85 * opposite direction because (max - min) must be a power of two. 86 * Also we initialize the external K value to -1 so that we can 87 * avoid extra conditions check inside the core loop. 88 */ 89if(fmin > dmin) 90 kvdf[--fmin -1] = -1; 91else 92++fmin; 93if(fmax < dmax) 94 kvdf[++fmax +1] = -1; 95else 96--fmax; 97 98for(d = fmax; d >= fmin; d -=2) { 99if(kvdf[d -1] >= kvdf[d +1]) 100 i1 = kvdf[d -1] +1; 101else 102 i1 = kvdf[d +1]; 103 prev1 = i1; 104 i2 = i1 - d; 105for(; i1 < lim1 && i2 < lim2 && ha1[i1] == ha2[i2]; i1++, i2++); 106if(i1 - prev1 > xenv->snake_cnt) 107 got_snake =1; 108 kvdf[d] = i1; 109if(odd && bmin <= d && d <= bmax && kvdb[d] <= i1) { 110 spl->i1 = i1; 111 spl->i2 = i2; 112 spl->min_lo = spl->min_hi =1; 113return ec; 114} 115} 116 117/* 118 * We need to extent the diagonal "domain" by one. If the next 119 * values exits the box boundaries we need to change it in the 120 * opposite direction because (max - min) must be a power of two. 121 * Also we initialize the external K value to -1 so that we can 122 * avoid extra conditions check inside the core loop. 123 */ 124if(bmin > dmin) 125 kvdb[--bmin -1] = XDL_LINE_MAX; 126else 127++bmin; 128if(bmax < dmax) 129 kvdb[++bmax +1] = XDL_LINE_MAX; 130else 131--bmax; 132 133for(d = bmax; d >= bmin; d -=2) { 134if(kvdb[d -1] < kvdb[d +1]) 135 i1 = kvdb[d -1]; 136else 137 i1 = kvdb[d +1] -1; 138 prev1 = i1; 139 i2 = i1 - d; 140for(; i1 > off1 && i2 > off2 && ha1[i1 -1] == ha2[i2 -1]; i1--, i2--); 141if(prev1 - i1 > xenv->snake_cnt) 142 got_snake =1; 143 kvdb[d] = i1; 144if(!odd && fmin <= d && d <= fmax && i1 <= kvdf[d]) { 145 spl->i1 = i1; 146 spl->i2 = i2; 147 spl->min_lo = spl->min_hi =1; 148return ec; 149} 150} 151 152if(need_min) 153continue; 154 155/* 156 * If the edit cost is above the heuristic trigger and if 157 * we got a good snake, we sample current diagonals to see 158 * if some of the, have reached an "interesting" path. Our 159 * measure is a function of the distance from the diagonal 160 * corner (i1 + i2) penalized with the distance from the 161 * mid diagonal itself. If this value is above the current 162 * edit cost times a magic factor (XDL_K_HEUR) we consider 163 * it interesting. 164 */ 165if(got_snake && ec > xenv->heur_min) { 166for(best =0, d = fmax; d >= fmin; d -=2) { 167 dd = d > fmid ? d - fmid: fmid - d; 168 i1 = kvdf[d]; 169 i2 = i1 - d; 170 v = (i1 - off1) + (i2 - off2) - dd; 171 172if(v > XDL_K_HEUR * ec && v > best && 173 off1 + xenv->snake_cnt <= i1 && i1 < lim1 && 174 off2 + xenv->snake_cnt <= i2 && i2 < lim2) { 175for(k =1; ha1[i1 - k] == ha2[i2 - k]; k++) 176if(k == xenv->snake_cnt) { 177 best = v; 178 spl->i1 = i1; 179 spl->i2 = i2; 180break; 181} 182} 183} 184if(best >0) { 185 spl->min_lo =1; 186 spl->min_hi =0; 187return ec; 188} 189 190for(best =0, d = bmax; d >= bmin; d -=2) { 191 dd = d > bmid ? d - bmid: bmid - d; 192 i1 = kvdb[d]; 193 i2 = i1 - d; 194 v = (lim1 - i1) + (lim2 - i2) - dd; 195 196if(v > XDL_K_HEUR * ec && v > best && 197 off1 < i1 && i1 <= lim1 - xenv->snake_cnt && 198 off2 < i2 && i2 <= lim2 - xenv->snake_cnt) { 199for(k =0; ha1[i1 + k] == ha2[i2 + k]; k++) 200if(k == xenv->snake_cnt -1) { 201 best = v; 202 spl->i1 = i1; 203 spl->i2 = i2; 204break; 205} 206} 207} 208if(best >0) { 209 spl->min_lo =0; 210 spl->min_hi =1; 211return ec; 212} 213} 214 215/* 216 * Enough is enough. We spent too much time here and now we collect 217 * the furthest reaching path using the (i1 + i2) measure. 218 */ 219if(ec >= xenv->mxcost) { 220long fbest, fbest1, bbest, bbest1; 221 222 fbest = fbest1 = -1; 223for(d = fmax; d >= fmin; d -=2) { 224 i1 =XDL_MIN(kvdf[d], lim1); 225 i2 = i1 - d; 226if(lim2 < i2) 227 i1 = lim2 + d, i2 = lim2; 228if(fbest < i1 + i2) { 229 fbest = i1 + i2; 230 fbest1 = i1; 231} 232} 233 234 bbest = bbest1 = XDL_LINE_MAX; 235for(d = bmax; d >= bmin; d -=2) { 236 i1 =XDL_MAX(off1, kvdb[d]); 237 i2 = i1 - d; 238if(i2 < off2) 239 i1 = off2 + d, i2 = off2; 240if(i1 + i2 < bbest) { 241 bbest = i1 + i2; 242 bbest1 = i1; 243} 244} 245 246if((lim1 + lim2) - bbest < fbest - (off1 + off2)) { 247 spl->i1 = fbest1; 248 spl->i2 = fbest - fbest1; 249 spl->min_lo =1; 250 spl->min_hi =0; 251}else{ 252 spl->i1 = bbest1; 253 spl->i2 = bbest - bbest1; 254 spl->min_lo =0; 255 spl->min_hi =1; 256} 257return ec; 258} 259} 260} 261 262 263/* 264 * Rule: "Divide et Impera". Recursively split the box in sub-boxes by calling 265 * the box splitting function. Note that the real job (marking changed lines) 266 * is done in the two boundary reaching checks. 267 */ 268intxdl_recs_cmp(diffdata_t *dd1,long off1,long lim1, 269 diffdata_t *dd2,long off2,long lim2, 270long*kvdf,long*kvdb,int need_min, xdalgoenv_t *xenv) { 271unsigned long const*ha1 = dd1->ha, *ha2 = dd2->ha; 272 273/* 274 * Shrink the box by walking through each diagonal snake (SW and NE). 275 */ 276for(; off1 < lim1 && off2 < lim2 && ha1[off1] == ha2[off2]; off1++, off2++); 277for(; off1 < lim1 && off2 < lim2 && ha1[lim1 -1] == ha2[lim2 -1]; lim1--, lim2--); 278 279/* 280 * If one dimension is empty, then all records on the other one must 281 * be obviously changed. 282 */ 283if(off1 == lim1) { 284char*rchg2 = dd2->rchg; 285long*rindex2 = dd2->rindex; 286 287for(; off2 < lim2; off2++) 288 rchg2[rindex2[off2]] =1; 289}else if(off2 == lim2) { 290char*rchg1 = dd1->rchg; 291long*rindex1 = dd1->rindex; 292 293for(; off1 < lim1; off1++) 294 rchg1[rindex1[off1]] =1; 295}else{ 296 xdpsplit_t spl; 297 spl.i1 = spl.i2 =0; 298 299/* 300 * Divide ... 301 */ 302if(xdl_split(ha1, off1, lim1, ha2, off2, lim2, kvdf, kvdb, 303 need_min, &spl, xenv) <0) { 304 305return-1; 306} 307 308/* 309 * ... et Impera. 310 */ 311if(xdl_recs_cmp(dd1, off1, spl.i1, dd2, off2, spl.i2, 312 kvdf, kvdb, spl.min_lo, xenv) <0|| 313xdl_recs_cmp(dd1, spl.i1, lim1, dd2, spl.i2, lim2, 314 kvdf, kvdb, spl.min_hi, xenv) <0) { 315 316return-1; 317} 318} 319 320return0; 321} 322 323 324intxdl_do_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const*xpp, 325 xdfenv_t *xe) { 326long ndiags; 327long*kvd, *kvdf, *kvdb; 328 xdalgoenv_t xenv; 329 diffdata_t dd1, dd2; 330 331if(XDF_DIFF_ALG(xpp->flags) == XDF_PATIENCE_DIFF) 332returnxdl_do_patience_diff(mf1, mf2, xpp, xe); 333 334if(XDF_DIFF_ALG(xpp->flags) == XDF_HISTOGRAM_DIFF) 335returnxdl_do_histogram_diff(mf1, mf2, xpp, xe); 336 337if(xdl_prepare_env(mf1, mf2, xpp, xe) <0) { 338 339return-1; 340} 341 342/* 343 * Allocate and setup K vectors to be used by the differential algorithm. 344 * One is to store the forward path and one to store the backward path. 345 */ 346 ndiags = xe->xdf1.nreff + xe->xdf2.nreff +3; 347if(!(kvd = (long*)xdl_malloc((2* ndiags +2) *sizeof(long)))) { 348 349xdl_free_env(xe); 350return-1; 351} 352 kvdf = kvd; 353 kvdb = kvdf + ndiags; 354 kvdf += xe->xdf2.nreff +1; 355 kvdb += xe->xdf2.nreff +1; 356 357 xenv.mxcost =xdl_bogosqrt(ndiags); 358if(xenv.mxcost < XDL_MAX_COST_MIN) 359 xenv.mxcost = XDL_MAX_COST_MIN; 360 xenv.snake_cnt = XDL_SNAKE_CNT; 361 xenv.heur_min = XDL_HEUR_MIN_COST; 362 363 dd1.nrec = xe->xdf1.nreff; 364 dd1.ha = xe->xdf1.ha; 365 dd1.rchg = xe->xdf1.rchg; 366 dd1.rindex = xe->xdf1.rindex; 367 dd2.nrec = xe->xdf2.nreff; 368 dd2.ha = xe->xdf2.ha; 369 dd2.rchg = xe->xdf2.rchg; 370 dd2.rindex = xe->xdf2.rindex; 371 372if(xdl_recs_cmp(&dd1,0, dd1.nrec, &dd2,0, dd2.nrec, 373 kvdf, kvdb, (xpp->flags & XDF_NEED_MINIMAL) !=0, &xenv) <0) { 374 375xdl_free(kvd); 376xdl_free_env(xe); 377return-1; 378} 379 380xdl_free(kvd); 381 382return0; 383} 384 385 386static xdchange_t *xdl_add_change(xdchange_t *xscr,long i1,long i2,long chg1,long chg2) { 387 xdchange_t *xch; 388 389if(!(xch = (xdchange_t *)xdl_malloc(sizeof(xdchange_t)))) 390return NULL; 391 392 xch->next = xscr; 393 xch->i1 = i1; 394 xch->i2 = i2; 395 xch->chg1 = chg1; 396 xch->chg2 = chg2; 397 xch->ignore =0; 398 399return xch; 400} 401 402 403static intis_blank_line(xrecord_t *rec,long flags) 404{ 405returnxdl_blankline(rec->ptr, rec->size, flags); 406} 407 408static intrecs_match(xrecord_t *rec1, xrecord_t *rec2,long flags) 409{ 410return(rec1->ha == rec2->ha && 411xdl_recmatch(rec1->ptr, rec1->size, 412 rec2->ptr, rec2->size, 413 flags)); 414} 415 416/* 417 * Represent a group of changed lines in an xdfile_t (i.e., a contiguous group 418 * of lines that was inserted or deleted from the corresponding version of the 419 * file). We consider there to be such a group at the beginning of the file, at 420 * the end of the file, and between any two unchanged lines, though most such 421 * groups will usually be empty. 422 * 423 * If the first line in a group is equal to the line following the group, then 424 * the group can be slid down. Similarly, if the last line in a group is equal 425 * to the line preceding the group, then the group can be slid up. See 426 * group_slide_down() and group_slide_up(). 427 * 428 * Note that loops that are testing for changed lines in xdf->rchg do not need 429 * index bounding since the array is prepared with a zero at position -1 and N. 430 */ 431struct group { 432/* 433 * The index of the first changed line in the group, or the index of 434 * the unchanged line above which the (empty) group is located. 435 */ 436long start; 437 438/* 439 * The index of the first unchanged line after the group. For an empty 440 * group, end is equal to start. 441 */ 442long end; 443}; 444 445/* 446 * Initialize g to point at the first group in xdf. 447 */ 448static voidgroup_init(xdfile_t *xdf,struct group *g) 449{ 450 g->start = g->end =0; 451while(xdf->rchg[g->end]) 452 g->end++; 453} 454 455/* 456 * Move g to describe the next (possibly empty) group in xdf and return 0. If g 457 * is already at the end of the file, do nothing and return -1. 458 */ 459staticinlineintgroup_next(xdfile_t *xdf,struct group *g) 460{ 461if(g->end == xdf->nrec) 462return-1; 463 464 g->start = g->end +1; 465for(g->end = g->start; xdf->rchg[g->end]; g->end++) 466; 467 468return0; 469} 470 471/* 472 * Move g to describe the previous (possibly empty) group in xdf and return 0. 473 * If g is already at the beginning of the file, do nothing and return -1. 474 */ 475staticinlineintgroup_previous(xdfile_t *xdf,struct group *g) 476{ 477if(g->start ==0) 478return-1; 479 480 g->end = g->start -1; 481for(g->start = g->end; xdf->rchg[g->start -1]; g->start--) 482; 483 484return0; 485} 486 487/* 488 * If g can be slid toward the end of the file, do so, and if it bumps into a 489 * following group, expand this group to include it. Return 0 on success or -1 490 * if g cannot be slid down. 491 */ 492static intgroup_slide_down(xdfile_t *xdf,struct group *g,long flags) 493{ 494if(g->end < xdf->nrec && 495recs_match(xdf->recs[g->start], xdf->recs[g->end], flags)) { 496 xdf->rchg[g->start++] =0; 497 xdf->rchg[g->end++] =1; 498 499while(xdf->rchg[g->end]) 500 g->end++; 501 502return0; 503}else{ 504return-1; 505} 506} 507 508/* 509 * If g can be slid toward the beginning of the file, do so, and if it bumps 510 * into a previous group, expand this group to include it. Return 0 on success 511 * or -1 if g cannot be slid up. 512 */ 513static intgroup_slide_up(xdfile_t *xdf,struct group *g,long flags) 514{ 515if(g->start >0&& 516recs_match(xdf->recs[g->start -1], xdf->recs[g->end -1], flags)) { 517 xdf->rchg[--g->start] =1; 518 xdf->rchg[--g->end] =0; 519 520while(xdf->rchg[g->start -1]) 521 g->start--; 522 523return0; 524}else{ 525return-1; 526} 527} 528 529static voidxdl_bug(const char*msg) 530{ 531fprintf(stderr,"BUG:%s\n", msg); 532exit(1); 533} 534 535/* 536 * Move back and forward change groups for a consistent and pretty diff output. 537 * This also helps in finding joinable change groups and reducing the diff 538 * size. 539 */ 540intxdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo,long flags) { 541struct group g, go; 542long earliest_end, end_matching_other; 543long groupsize; 544unsigned int blank_lines; 545 546group_init(xdf, &g); 547group_init(xdfo, &go); 548 549while(1) { 550/* If the group is empty in the to-be-compacted file, skip it: */ 551if(g.end == g.start) 552goto next; 553 554/* 555 * Now shift the change up and then down as far as possible in 556 * each direction. If it bumps into any other changes, merge them. 557 */ 558do{ 559 groupsize = g.end - g.start; 560 561/* 562 * Keep track of the last "end" index that causes this 563 * group to align with a group of changed lines in the 564 * other file. -1 indicates that we haven't found such 565 * a match yet: 566 */ 567 end_matching_other = -1; 568 569/* 570 * Boolean value that records whether there are any blank 571 * lines that could be made to be the last line of this 572 * group. 573 */ 574 blank_lines =0; 575 576/* Shift the group backward as much as possible: */ 577while(!group_slide_up(xdf, &g, flags)) 578if(group_previous(xdfo, &go)) 579xdl_bug("group sync broken sliding up"); 580 581/* 582 * This is this highest that this group can be shifted. 583 * Record its end index: 584 */ 585 earliest_end = g.end; 586 587if(go.end > go.start) 588 end_matching_other = g.end; 589 590/* Now shift the group forward as far as possible: */ 591while(1) { 592if(!blank_lines) 593 blank_lines =is_blank_line( 594 xdf->recs[g.end -1], 595 flags); 596 597if(group_slide_down(xdf, &g, flags)) 598break; 599if(group_next(xdfo, &go)) 600xdl_bug("group sync broken sliding down"); 601 602if(go.end > go.start) 603 end_matching_other = g.end; 604} 605}while(groupsize != g.end - g.start); 606 607if(g.end == earliest_end) { 608/* no shifting was possible */ 609}else if(end_matching_other != -1) { 610/* 611 * Move the possibly merged group of changes back to line 612 * up with the last group of changes from the other file 613 * that it can align with. 614 */ 615while(go.end == go.start) { 616if(group_slide_up(xdf, &g, flags)) 617xdl_bug("match disappeared"); 618if(group_previous(xdfo, &go)) 619xdl_bug("group sync broken sliding to match"); 620} 621}else if((flags & XDF_COMPACTION_HEURISTIC) && blank_lines) { 622/* 623 * Compaction heuristic: if it is possible to shift the 624 * group to make its bottom line a blank line, do so. 625 * 626 * As we already shifted the group forward as far as 627 * possible in the earlier loop, we only need to handle 628 * backward shifts, not forward ones. 629 */ 630while(!is_blank_line(xdf->recs[g.end -1], flags)) { 631if(group_slide_up(xdf, &g, flags)) 632xdl_bug("blank line disappeared"); 633if(group_previous(xdfo, &go)) 634xdl_bug("group sync broken sliding to blank line"); 635} 636} 637 638 next: 639/* Move past the just-processed group: */ 640if(group_next(xdf, &g)) 641break; 642if(group_next(xdfo, &go)) 643xdl_bug("group sync broken moving to next group"); 644} 645 646if(!group_next(xdfo, &go)) 647xdl_bug("group sync broken at end of file"); 648 649return0; 650} 651 652 653intxdl_build_script(xdfenv_t *xe, xdchange_t **xscr) { 654 xdchange_t *cscr = NULL, *xch; 655char*rchg1 = xe->xdf1.rchg, *rchg2 = xe->xdf2.rchg; 656long i1, i2, l1, l2; 657 658/* 659 * Trivial. Collects "groups" of changes and creates an edit script. 660 */ 661for(i1 = xe->xdf1.nrec, i2 = xe->xdf2.nrec; i1 >=0|| i2 >=0; i1--, i2--) 662if(rchg1[i1 -1] || rchg2[i2 -1]) { 663for(l1 = i1; rchg1[i1 -1]; i1--); 664for(l2 = i2; rchg2[i2 -1]; i2--); 665 666if(!(xch =xdl_add_change(cscr, i1, i2, l1 - i1, l2 - i2))) { 667xdl_free_script(cscr); 668return-1; 669} 670 cscr = xch; 671} 672 673*xscr = cscr; 674 675return0; 676} 677 678 679voidxdl_free_script(xdchange_t *xscr) { 680 xdchange_t *xch; 681 682while((xch = xscr) != NULL) { 683 xscr = xscr->next; 684xdl_free(xch); 685} 686} 687 688static intxdl_call_hunk_func(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb, 689 xdemitconf_t const*xecfg) 690{ 691 xdchange_t *xch, *xche; 692 693for(xch = xscr; xch; xch = xche->next) { 694 xche =xdl_get_hunk(&xch, xecfg); 695if(!xch) 696break; 697if(xecfg->hunk_func(xch->i1, xche->i1 + xche->chg1 - xch->i1, 698 xch->i2, xche->i2 + xche->chg2 - xch->i2, 699 ecb->priv) <0) 700return-1; 701} 702return0; 703} 704 705static voidxdl_mark_ignorable(xdchange_t *xscr, xdfenv_t *xe,long flags) 706{ 707 xdchange_t *xch; 708 709for(xch = xscr; xch; xch = xch->next) { 710int ignore =1; 711 xrecord_t **rec; 712long i; 713 714 rec = &xe->xdf1.recs[xch->i1]; 715for(i =0; i < xch->chg1 && ignore; i++) 716 ignore =xdl_blankline(rec[i]->ptr, rec[i]->size, flags); 717 718 rec = &xe->xdf2.recs[xch->i2]; 719for(i =0; i < xch->chg2 && ignore; i++) 720 ignore =xdl_blankline(rec[i]->ptr, rec[i]->size, flags); 721 722 xch->ignore = ignore; 723} 724} 725 726intxdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const*xpp, 727 xdemitconf_t const*xecfg, xdemitcb_t *ecb) { 728 xdchange_t *xscr; 729 xdfenv_t xe; 730 emit_func_t ef = xecfg->hunk_func ? xdl_call_hunk_func : xdl_emit_diff; 731 732if(xdl_do_diff(mf1, mf2, xpp, &xe) <0) { 733 734return-1; 735} 736if(xdl_change_compact(&xe.xdf1, &xe.xdf2, xpp->flags) <0|| 737xdl_change_compact(&xe.xdf2, &xe.xdf1, xpp->flags) <0|| 738xdl_build_script(&xe, &xscr) <0) { 739 740xdl_free_env(&xe); 741return-1; 742} 743if(xscr) { 744if(xpp->flags & XDF_IGNORE_BLANK_LINES) 745xdl_mark_ignorable(xscr, &xe, xpp->flags); 746 747if(ef(&xe, xscr, ecb, xecfg) <0) { 748 749xdl_free_script(xscr); 750xdl_free_env(&xe); 751return-1; 752} 753xdl_free_script(xscr); 754} 755xdl_free_env(&xe); 756 757return0; 758}