1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
|
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
|
-
-
+
+
-
-
+
+
-
-
-
+
+
-
-
-
+
-
-
-
-
+
-
-
+
-
+
-
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
-
-
+
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+
+
+
+
+
-
+
-
-
+
+
-
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
-
+
-
-
-
+
+
+
-
+
+
-
-
+
-
+
-
+
-
-
-
-
-
+
-
-
+
+
+
-
-
-
+
+
+
+
-
-
+
+
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
+
+
-
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
+
-
-
+
+
+
+
-
+
-
+
-
+
-
+
-
+
-
-
-
-
-
+
+
+
+
+
-
-
+
-
+
-
+
-
+
-
+
-
+
-
-
+
+
+
-
-
+
-
+
-
-
-
-
-
|
/************************* DiffBuilderUnified********************************/
/* This formatter generates a unified diff for HTML.
**
** The result is a <table> with four columns. The four columns hold:
**
** 1. The line numbers for the first file.
** 2. The line numbers for the second file.
** 3. The "diff mark": "+" or "-" or just a space
** 4. Text of the line
** 3. The "diff mark": "+", "-" or blank.
** 4. Text of the line.
**
** Inserted lines are marked with <ins> and deleted lines are marked
** with <del>. The whole line is marked this way, not just the part that
** The table cells holding the inserted and deleted lines are assigned to CSS
** classes .nul, .ins or .del to color them accordingly. The changed parts of
** changed. The part that change has an additional nested <ins> or <del>.
** The CSS needs to be set up such that a single <ins> or <del> gives a
** light background and a nested <ins> or <del> gives a darker background.
** each line have additional <ins> or <del> elements. The CSS needs to be set
** up such that the <ins> or <del> intensify the background color of the .ins
** Additional attributes (like bold font) might also be added to nested
** <ins> and <del> since those are the characters that have actually
** changed.
** and .del CSS classes.
**
** Accumulator strategy:
**
** * Delete line numbers are output directly to p->pOut
** * Insert line numbers accumulate in p->aCol[0].
** * Separator marks accumulate in p->aCol[1].
** * Change text accumulates in p->aCol[2].
** * Retained insert text goes to p->bBuf2
** * Pending insert line numbers go into p->aCol[3].
** * Pending insert text goes into p->aCol[4].
** * Anything else goes directly to p->pOut
**
** eState is 1 if text has an open <del>
** eState is 1 if the last line was a deletion.
*/
static void dfunifiedFinishDelete(DiffBuilder *p){
if( p->eState==0 ) return;
blob_append(p->pOut, "</del>", 6);
blob_append(&p->aCol[2], "</del>", 6);
p->eState = 0;
}
static void dfunifiedFinishInsert(DiffBuilder *p){
unsigned int i;
if( p->nPending==0 ) return;
if( blob_size(&p->bBuf2)==0 ) return;
dfunifiedFinishDelete(p);
/* Blank lines for delete line numbers for each inserted line */
for(i=0; i<p->nPending; i++) blob_append_char(p->pOut, '\n');
/* Insert line numbers */
blob_append(&p->aCol[0], "<ins>", 5);
blob_append_xfer(&p->aCol[0], &p->aCol[3]);
blob_append_xfer(p->pOut,&p->bBuf2);
blob_append(&p->aCol[0], "</ins>", 6);
/* "+" marks for the separator on inserted lines */
for(i=0; i<p->nPending; i++) blob_append(&p->aCol[1], "+\n", 2);
/* Text of the inserted lines */
blob_append(&p->aCol[2], "<ins>", 5);
blob_append_xfer(&p->aCol[2], &p->aCol[4]);
blob_append(&p->aCol[2], "</ins>", 6);
p->nPending = 0;
}
static void dfunifiedFinishRow(DiffBuilder *p){
dfunifiedFinishDelete(p);
dfunifiedFinishInsert(p);
if( blob_size(&p->aCol[0])==0 ) return;
blob_append(p->pOut, "</pre></td><td class=\"diffln difflnr\"><pre>\n", -1);
blob_append_xfer(p->pOut, &p->aCol[0]);
blob_append(p->pOut, "</pre></td><td class=\"diffsep\"><pre>\n", -1);
blob_append_xfer(p->pOut, &p->aCol[1]);
blob_append(p->pOut, "</pre></td><td class=\"difftxt difftxtu\"><pre>\n",-1);
blob_append_xfer(p->pOut, &p->aCol[2]);
blob_append(p->pOut, "</pre></td></tr>\n", -1);
}
static void dfunifiedStartRow(DiffBuilder *p){
if( blob_size(&p->aCol[0])>0 ) return;
blob_appendf(p->pOut,"<tr id=\"chunk%d\" class=\"diffchunk\">"
"<td class=\"diffln difflnl\"><pre>\n", ++nChunk);
}
static void dfunifiedSkip(DiffBuilder *p, unsigned int n, int isFinal){
dfunifiedFinishRow(p);
if( p->pCfg && p->pCfg->zLeftHash ){
blob_appendf(p->pOut,
"<tr class=\"diffskip\" data-startln=\"%d\" data-endln=\"%d\""
" id=\"skip%xh%xi%x\">\n",
p->lnLeft+1, p->lnLeft+n,
p->lnLeft+1, p->lnLeft+n, nChunk, p->lnLeft, n);
nChunk, p->lnLeft, n);
}else{
blob_append(p->pOut, "<tr>", 4);
}
blob_append(p->pOut, "<td class=\"diffln difflne\">"
"︙</td><td></td><td></td></tr>\n", -1);
blob_append(p->pOut, "<td class=\"diffln difflne\" colspan=\"4\">"
"︙</td></tr>\n", -1);
p->lnLeft += n;
p->lnRight += n;
}
static void dfunifiedCommon(DiffBuilder *p, const DLine *pLine){
dfunifiedStartRow(p);
dfunifiedFinishDelete(p);
dfunifiedFinishInsert(p);
p->lnLeft++;
p->lnRight++;
blob_append (p->pOut, "<tr class=\"diffline\">", 21);
blob_appendf(p->pOut,"%d\n", p->lnLeft);
blob_appendf(&p->aCol[0],"%d\n",p->lnRight);
blob_append_char(&p->aCol[1], '\n');
htmlize_to_blob(&p->aCol[2], pLine->z, (int)pLine->n);
blob_append_char(&p->aCol[2], '\n');
blob_appendf(p->pOut, "<td class=\"diffln difflnl\">%d</td>", p->lnLeft);
blob_appendf(p->pOut, "<td class=\"diffln difflnr\">%d</td>", p->lnRight);
blob_append (p->pOut, "<td class=\"diffsep\"></td>", 25);
blob_append (p->pOut, "<td class=\"difftxt difftxtu\">", 29);
htmlize_to_blob(p->pOut, pLine->z, (int)pLine->n);
blob_append (p->pOut, "</td>", 5);
blob_append (p->pOut, "</tr>\n", 6);
}
static void dfunifiedInsert(DiffBuilder *p, const DLine *pLine){
dfunifiedStartRow(p);
p->lnRight++;
blob_append (&p->bBuf2, "<tr class=\"diffline\">", 21);
blob_append (&p->bBuf2, "<td class=\"diffln difflnl ins\"></td>", 36);
blob_appendf(&p->bBuf2, "<td class=\"diffln difflnr ins\">%d</td>",
blob_appendf(&p->aCol[3],"%d\n", p->lnRight);
blob_append(&p->aCol[4], "<ins>", 5);
htmlize_to_blob(&p->aCol[4], pLine->z, (int)pLine->n);
blob_append(&p->aCol[4], "</ins>\n", 7);
p->nPending++;
p->lnRight);
blob_append (&p->bBuf2, "<td class=\"diffsep ins\">+</td>", 30);
blob_append (&p->bBuf2, "<td class=\"difftxt difftxtu ins\"><ins>", 38);
htmlize_to_blob(&p->bBuf2, pLine->z, (int)pLine->n);
blob_append (&p->bBuf2, "</ins></td>", 11);
blob_append (&p->bBuf2, "</tr>\n", 6);
}
static void dfunifiedDelete(DiffBuilder *p, const DLine *pLine){
dfunifiedStartRow(p);
dfunifiedFinishInsert(p);
if( p->eState==0 ){
dfunifiedFinishInsert(p);
blob_append(p->pOut, "<del>", 5);
blob_append(&p->aCol[2], "<del>", 5);
p->eState = 1;
}
p->lnLeft++;
blob_append (p->pOut, "<tr class=\"diffline\">", 21);
blob_appendf(p->pOut,"%d\n", p->lnLeft);
blob_append_char(&p->aCol[0],'\n');
blob_append(&p->aCol[1],"-\n",2);
blob_append(&p->aCol[2], "<del>", 5);
htmlize_to_blob(&p->aCol[2], pLine->z, (int)pLine->n);
blob_append(&p->aCol[2], "</del>\n", 7);
blob_appendf(p->pOut, "<td class=\"diffln difflnl del\">%d</td>", p->lnLeft);
blob_append (p->pOut, "<td class=\"diffln difflnr del\"></td>", 36);
blob_append (p->pOut, "<td class=\"diffsep del\">-</td>", 30);
blob_append (p->pOut, "<td class=\"difftxt difftxtu del\"><del>", 38);
htmlize_to_blob(p->pOut, pLine->z, (int)pLine->n);
blob_append (p->pOut, "</del></td>", 11);
blob_append (p->pOut, "</tr>\n", 6);
}
static void dfunifiedReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){
dfunifiedStartRow(p);
if( p->eState==0 ){
dfunifiedFinishInsert(p);
blob_append(p->pOut, "<del>", 5);
blob_append(&p->aCol[2], "<del>", 5);
p->eState = 1;
}
p->lnLeft++;
p->lnRight++;
blob_appendf(p->pOut,"%d\n", p->lnLeft);
blob_append_char(&p->aCol[0], '\n');
blob_append(&p->aCol[1], "-\n", 2);
fossil_fatal("The seemingly unused function dfunifiedReplace() was called!");
htmlize_to_blob(&p->aCol[2], pX->z, pX->n);
blob_append_char(&p->aCol[2], '\n');
blob_appendf(&p->aCol[3],"%d\n", p->lnRight);
htmlize_to_blob(&p->aCol[4], pY->z, pY->n);
blob_append_char(&p->aCol[4], '\n');
p->nPending++;
}
static void dfunifiedEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
int i;
int x;
LineChange chng;
oneLineChange(pX, pY, &chng);
dfunifiedStartRow(p);
if( p->eState==0 ){
dfunifiedFinishInsert(p);
blob_append(p->pOut, "<del>", 5);
blob_append(&p->aCol[2], "<del>", 5);
p->eState = 1;
}
p->lnLeft++;
p->lnRight++;
blob_append (p->pOut, "<tr class=\"diffline\">", 21);
blob_appendf(p->pOut,"%d\n", p->lnLeft);
blob_append_char(&p->aCol[0], '\n');
blob_append(&p->aCol[1], "-\n", 2);
for(i=x=0; i<chng.n; i++){
blob_appendf(p->pOut, "<td class=\"diffln difflnl del\">%d</td>", p->lnLeft);
blob_append (p->pOut, "<td class=\"diffln difflnr del\"></td>", 36);
blob_append (p->pOut, "<td class=\"diffsep del\">-</td>", 30);
blob_append (p->pOut, "<td class=\"difftxt difftxtu del\">", 33);
for( i=x=0; i<chng.n; i++ ){
int ofst = chng.a[i].iStart1;
int len = chng.a[i].iLen1;
if( len ){
htmlize_to_blob(&p->aCol[2], pX->z+x, ofst - x);
htmlize_to_blob(p->pOut, pX->z+x, ofst - x);
x = ofst;
blob_append(&p->aCol[2], "<del>", 5);
htmlize_to_blob(&p->aCol[2], pX->z+x, len);
blob_append(p->pOut, "<del>", 5);
htmlize_to_blob(p->pOut, pX->z+x, len);
x += len;
blob_append(&p->aCol[2], "</del>", 6);
blob_append(p->pOut, "</del>", 6);
}
}
htmlize_to_blob(&p->aCol[2], pX->z+x, pX->n - x);
blob_append_char(&p->aCol[2], '\n');
blob_appendf(&p->aCol[3],"%d\n", p->lnRight);
for(i=x=0; i<chng.n; i++){
htmlize_to_blob(p->pOut, pX->z+x, pX->n - x);
blob_append (p->pOut, "</td>", 5);
blob_append (p->pOut, "</tr>\n", 6);
blob_append (&p->bBuf2, "<tr class=\"diffline\">", 21);
blob_append (&p->bBuf2, "<td class=\"diffln difflnl ins\"></td>", 36);
blob_appendf(&p->bBuf2, "<td class=\"diffln difflnr ins\">%d</td>",
p->lnRight);
blob_append (&p->bBuf2, "<td class=\"diffsep ins\">+</td>", 30);
blob_append (&p->bBuf2, "<td class=\"difftxt difftxtu ins\">", 33);
for( i=x=0; i<chng.n; i++ ){
int ofst = chng.a[i].iStart2;
int len = chng.a[i].iLen2;
if( len ){
htmlize_to_blob(&p->aCol[4], pY->z+x, ofst - x);
htmlize_to_blob(&p->bBuf2, pY->z+x, ofst - x);
x = ofst;
blob_append(&p->aCol[4], "<ins>", 5);
htmlize_to_blob(&p->aCol[4], pY->z+x, len);
blob_append(&p->bBuf2, "<ins>", 5);
htmlize_to_blob(&p->bBuf2, pY->z+x, len);
x += len;
blob_append(&p->aCol[4], "</ins>", 6);
blob_append(&p->bBuf2, "</ins>", 6);
}
}
htmlize_to_blob(&p->aCol[4], pY->z+x, pY->n - x);
blob_append_char(&p->aCol[4], '\n');
p->nPending++;
htmlize_to_blob(&p->bBuf2, pY->z+x, pY->n - x);
blob_append (&p->bBuf2, "</td>", 5);
blob_append (&p->bBuf2, "</tr>\n", 6);
}
static void dfunifiedEnd(DiffBuilder *p){
dfunifiedFinishRow(p);
blob_append(p->pOut, "</table>\n",-1);
blob_append(p->pOut, "</table>\n", 9);
blob_reset(&p->bBuf2);
fossil_free(p);
}
static DiffBuilder *dfunifiedNew(Blob *pOut, DiffConfig *pCfg){
DiffBuilder *p = fossil_malloc(sizeof(*p));
p->xSkip = dfunifiedSkip;
p->xCommon = dfunifiedCommon;
p->xInsert = dfunifiedInsert;
p->xDelete = dfunifiedDelete;
p->xReplace = dfunifiedReplace;
p->xEdit = dfunifiedEdit;
p->xEnd = dfunifiedEnd;
p->lnLeft = p->lnRight = 0;
p->eState = 0;
p->nPending = 0;
p->pOut = pOut;
if( pCfg->zLeftHash ){
blob_appendf(pOut, "<table class=\"diff udiff\" data-lefthash=\"%s\">\n",
pCfg->zLeftHash);
pCfg->zLeftHash);
}else{
blob_append(pOut, "<table class=\"diff udiff\">\n", -1);
blob_append(pOut, "<table class=\"diff udiff\">\n", 27);
}
blob_init(&p->aCol[0], 0, 0);
blob_init(&p->bBuf2, 0, 0);
blob_init(&p->aCol[1], 0, 0);
blob_init(&p->aCol[2], 0, 0);
blob_init(&p->aCol[3], 0, 0);
blob_init(&p->aCol[4], 0, 0);
p->pCfg = pCfg;
return p;
}
/************************* DiffBuilderSplit ******************************/
/* This formatter creates a side-by-side diff in HTML. The output is a
** <table> with 5 columns:
** <table> with 6 columns:
**
** 1. Line numbers for the first file.
** 2. Text for the first file.
** 1. Line numbers for the first file.
** 2. First difference mark: "+", "-" or blank.
** 3. Text for the first file.
** 3. The difference mark. "<", ">", "|" or blank
** 4. Line numbers for the second file.
** 5. Text for the second file.
** 4. Line numbers for the second file.
** 5. Second difference mark: "+", "-" or blank.
** 6. Text for the second file.
**
** The styling approach with .nul, .ins and .del CSS classes and <ins> and
** The <ins> and <del> strategy is the same as for unified diff above.
** In fact, the same CSS can be used for both.
** <del> elements is the same as for the unified diffs above. In fact, the
** same CSS can be used for both.
**
** Accumulator strategy:
**
** * Left line numbers are output directly to p->pOut
** * All output goes directly to p->pOut
** * Left text accumulates in p->aCol[0].
** * Edit marks accumulates in p->aCol[1].
** * Right line numbers accumulate in p->aCol[2].
** * Right text accumulates in p->aCol[3].
**
** eState:
** eState is not unused.
** 0 In common block
** 1 Have <del> on the left
** 2 Have <ins> on the right
** 3 Have <del> on left and <ins> on the right
*/
static void dfsplitChangeState(DiffBuilder *p, int newState){
if( p->eState == newState ) return;
if( (p->eState&1)==0 && (newState & 1)!=0 ){
blob_append(p->pOut, "<del>", 5);
blob_append(&p->aCol[0], "<del>", 5);
p->eState |= 1;
}else if( (p->eState&1)!=0 && (newState & 1)==0 ){
blob_append(p->pOut, "</del>", 6);
blob_append(&p->aCol[0], "</del>", 6);
p->eState &= ~1;
}
if( (p->eState&2)==0 && (newState & 2)!=0 ){
blob_append(&p->aCol[2], "<ins>", 5);
blob_append(&p->aCol[3], "<ins>", 5);
p->eState |= 2;
}else if( (p->eState&2)!=0 && (newState & 2)==0 ){
blob_append(&p->aCol[2], "</ins>", 6);
blob_append(&p->aCol[3], "</ins>", 6);
p->eState &= ~2;
}
}
static void dfsplitFinishRow(DiffBuilder *p){
if( blob_size(&p->aCol[0])==0 ) return;
dfsplitChangeState(p, 0);
blob_append(p->pOut, "</pre></td><td class=\"difftxt difftxtl\"><pre>\n",-1);
blob_append_xfer(p->pOut, &p->aCol[0]);
blob_append(p->pOut, "</pre></td><td class=\"diffsep\"><pre>\n", -1);
blob_append_xfer(p->pOut, &p->aCol[1]);
blob_append(p->pOut, "</pre></td><td class=\"diffln difflnr\"><pre>\n",-1);
blob_append_xfer(p->pOut, &p->aCol[2]);
blob_append(p->pOut, "</pre></td><td class=\"difftxt difftxtr\"><pre>\n",-1);
blob_append_xfer(p->pOut, &p->aCol[3]);
blob_append(p->pOut, "</pre></td></tr>\n", -1);
}
static void dfsplitStartRow(DiffBuilder *p){
if( blob_size(&p->aCol[0])>0 ) return;
blob_appendf(p->pOut,"<tr id=\"chunk%d\" class=\"diffchunk\">"
"<td class=\"diffln difflnl\"><pre>\n", ++nChunk);
p->eState = 0;
}
static void dfsplitSkip(DiffBuilder *p, unsigned int n, int isFinal){
dfsplitFinishRow(p);
if( p->pCfg && p->pCfg->zLeftHash ){
blob_appendf(p->pOut,
"<tr class=\"diffskip\" data-startln=\"%d\" data-endln=\"%d\""
" id=\"skip%xh%xi%x\">\n",
p->lnLeft+1, p->lnLeft+n,
p->lnLeft+1, p->lnLeft+n, nChunk, p->lnLeft, n);
nChunk,p->lnLeft,n);
}else{
blob_append(p->pOut, "<tr>", 4);
}
blob_append(p->pOut,
"<td class=\"diffln difflnl difflne\">︙</td>"
"<td class=\"diffln difflnl difflne\" colspan=\"3\">︙</td>"
"<td></td><td></td>"
"<td class=\"diffln difflnr difflne\">︙</td>"
"<td/td></tr>\n", -1);
"<td class=\"diffln difflnr difflne\" colspan=\"3\">︙</td>"
"</tr>\n", -1);
p->lnLeft += n;
p->lnRight += n;
}
static void dfsplitCommon(DiffBuilder *p, const DLine *pLine){
dfsplitStartRow(p);
dfsplitChangeState(p, 0);
p->lnLeft++;
p->lnRight++;
blob_append (p->pOut, "<tr class=\"diffline\">", 21);
blob_appendf(p->pOut,"%d\n", p->lnLeft);
htmlize_to_blob(&p->aCol[0], pLine->z, (int)pLine->n);
blob_append_char(&p->aCol[0], '\n');
blob_append_char(&p->aCol[1], '\n');
blob_appendf(&p->aCol[2],"%d\n",p->lnRight);
htmlize_to_blob(&p->aCol[3], pLine->z, (int)pLine->n);
blob_append_char(&p->aCol[3], '\n');
blob_appendf(p->pOut, "<td class=\"diffln difflnl\">%d</td>", p->lnLeft);
blob_append (p->pOut, "<td class=\"diffsep\"></td>", 25);
blob_append (p->pOut, "<td class=\"difftxt difftxtl\">", 29);
htmlize_to_blob(p->pOut, pLine->z, (int)pLine->n);
blob_append (p->pOut, "</td>", 5);
blob_appendf(p->pOut, "<td class=\"diffln difflnr\">%d</td>", p->lnRight);
blob_append (p->pOut, "<td class=\"diffsep\"></td>", 25);
blob_append (p->pOut, "<td class=\"difftxt difftxtr\">", 29);
htmlize_to_blob(p->pOut, pLine->z, (int)pLine->n);
blob_append (p->pOut, "</td>", 5);
blob_append (p->pOut, "</tr>\n", 6);
}
static void dfsplitInsert(DiffBuilder *p, const DLine *pLine){
dfsplitStartRow(p);
dfsplitChangeState(p, 2);
p->lnRight++;
blob_append_char(p->pOut, '\n');
blob_append_char(&p->aCol[0], '\n');
blob_append(&p->aCol[1], ">\n", -1);
blob_appendf(&p->aCol[2],"%d\n", p->lnRight);
blob_append(&p->aCol[3], "<ins>", 5);
htmlize_to_blob(&p->aCol[3], pLine->z, (int)pLine->n);
blob_append(&p->aCol[3], "</ins>\n", 7);
blob_append (p->pOut, "<tr class=\"diffline\">", 21);
blob_append (p->pOut, "<td class=\"diffln difflnl nul\"></td>", 36);
blob_append (p->pOut, "<td class=\"diffsep nul\"></td>", 29);
blob_append (p->pOut, "<td class=\"difftxt difftxtl nul\"></td>", 38);
blob_appendf(p->pOut, "<td class=\"diffln difflnr ins\">%d</td>", p->lnRight);
blob_append (p->pOut, "<td class=\"diffsep ins\">+</td>", 30);
blob_append (p->pOut, "<td class=\"difftxt difftxtr ins\"><ins>", 38);
htmlize_to_blob(p->pOut, pLine->z, (int)pLine->n);
blob_append (p->pOut, "</ins></td>", 11);
blob_append (p->pOut, "</tr>\n", 6);
}
static void dfsplitDelete(DiffBuilder *p, const DLine *pLine){
dfsplitStartRow(p);
dfsplitChangeState(p, 1);
p->lnLeft++;
blob_append (p->pOut, "<tr class=\"diffline\">", 21);
blob_appendf(p->pOut,"%d\n", p->lnLeft);
blob_append(&p->aCol[0], "<del>", 5);
htmlize_to_blob(&p->aCol[0], pLine->z, (int)pLine->n);
blob_append(&p->aCol[0], "</del>\n", 7);
blob_append(&p->aCol[1], "<\n", -1);
blob_append_char(&p->aCol[2],'\n');
blob_append_char(&p->aCol[3],'\n');
blob_appendf(p->pOut, "<td class=\"diffln difflnl del\">%d</td>", p->lnLeft);
blob_append (p->pOut, "<td class=\"diffsep del\">-</td>", 30);
blob_append (p->pOut, "<td class=\"difftxt difftxtl del\"><del>", 38);
htmlize_to_blob(p->pOut, pLine->z, (int)pLine->n);
blob_append (p->pOut, "</del></td>", 11);
blob_append (p->pOut, "<td class=\"diffln difflnr nul\"></td>", 36);
blob_append (p->pOut, "<td class=\"diffsep nul\"></td>", 29);
blob_append (p->pOut, "<td class=\"difftxt difftxtr nul\"></td>", 38);
blob_append (p->pOut, "</tr>\n", 6);
}
static void dfsplitReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){
dfsplitStartRow(p);
dfsplitChangeState(p, 3);
p->lnLeft++;
p->lnRight++;
blob_appendf(p->pOut,"%d\n", p->lnLeft);
htmlize_to_blob(&p->aCol[0], pX->z, pX->n);
blob_append_char(&p->aCol[0], '\n');
fossil_fatal("The seemingly unused function dfsplitReplace() was called!");
blob_append(&p->aCol[1], "|\n", 2);
blob_appendf(&p->aCol[2],"%d\n", p->lnRight);
htmlize_to_blob(&p->aCol[3], pY->z, pY->n);
blob_append_char(&p->aCol[3], '\n');
}
static void dfsplitEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
int i;
int x;
LineChange chng;
oneLineChange(pX, pY, &chng);
dfsplitStartRow(p);
dfsplitChangeState(p, 3);
p->lnLeft++;
p->lnRight++;
blob_append (p->pOut, "<tr class=\"diffline\">", 21);
blob_appendf(p->pOut,"%d\n", p->lnLeft);
for(i=x=0; i<chng.n; i++){
blob_appendf(p->pOut, "<td class=\"diffln difflnl del\">%d</td>", p->lnLeft);
blob_append (p->pOut, "<td class=\"diffsep del\">-</td>", 30);
blob_append (p->pOut, "<td class=\"difftxt difftxtl del\">", 33);
for( i=x=0; i<chng.n; i++ ){
int ofst = chng.a[i].iStart1;
int len = chng.a[i].iLen1;
if( len ){
htmlize_to_blob(&p->aCol[0], pX->z+x, ofst - x);
htmlize_to_blob(p->pOut, pX->z+x, ofst - x);
x = ofst;
if( chng.a[i].iLen2 ){
blob_append(&p->aCol[0], "<del class='edit'>", -1);
blob_append(p->pOut, "<del class=\"edit\">", 18);
}else{
blob_append(&p->aCol[0], "<del>", 5);
blob_append(p->pOut, "<del>", 5);
}
htmlize_to_blob(&p->aCol[0], pX->z+x, len);
htmlize_to_blob(p->pOut, pX->z+x, len);
x += len;
blob_append(&p->aCol[0], "</del>", 6);
blob_append(p->pOut, "</del>", 6);
}
}
htmlize_to_blob(&p->aCol[0], pX->z+x, pX->n - x);
blob_append_char(&p->aCol[0], '\n');
blob_append(&p->aCol[1], "|\n", 2);
htmlize_to_blob(p->pOut, pX->z+x, pX->n - x);
blob_append (p->pOut, "</td>", 5);
blob_appendf(p->pOut, "<td class=\"diffln difflnr ins\">%d</td>", p->lnRight);
blob_append (p->pOut, "<td class=\"diffsep ins\">+</td>", 30);
blob_append (p->pOut, "<td class=\"difftxt difftxtr ins\">", 33);
blob_appendf(&p->aCol[2],"%d\n", p->lnRight);
for(i=x=0; i<chng.n; i++){
for( i=x=0; i<chng.n; i++ ){
int ofst = chng.a[i].iStart2;
int len = chng.a[i].iLen2;
if( len ){
htmlize_to_blob(&p->aCol[3], pY->z+x, ofst - x);
htmlize_to_blob(p->pOut, pY->z+x, ofst - x);
x = ofst;
if( chng.a[i].iLen1 ){
blob_append(&p->aCol[3], "<ins class='edit'>", -1);
blob_append(p->pOut, "<ins class=\"edit\">", 18);
}else{
blob_append(&p->aCol[3], "<ins>", 5);
blob_append(p->pOut, "<ins>", 5);
}
htmlize_to_blob(&p->aCol[3], pY->z+x, len);
htmlize_to_blob(p->pOut, pY->z+x, len);
x += len;
blob_append(&p->aCol[3], "</ins>", 6);
blob_append(p->pOut, "</ins>", 6);
}
}
htmlize_to_blob(&p->aCol[3], pY->z+x, pY->n - x);
blob_append_char(&p->aCol[3], '\n');
htmlize_to_blob(p->pOut, pY->z+x, pY->n - x);
blob_append (p->pOut, "</td>", 5);
blob_append (p->pOut, "</tr>\n", 6);
}
static void dfsplitEnd(DiffBuilder *p){
dfsplitFinishRow(p);
blob_append(p->pOut, "</table>\n",-1);
blob_append(p->pOut, "</table>\n", 9);
fossil_free(p);
}
static DiffBuilder *dfsplitNew(Blob *pOut, DiffConfig *pCfg){
DiffBuilder *p = fossil_malloc(sizeof(*p));
p->xSkip = dfsplitSkip;
p->xCommon = dfsplitCommon;
p->xInsert = dfsplitInsert;
p->xDelete = dfsplitDelete;
p->xReplace = dfsplitReplace;
p->xEdit = dfsplitEdit;
p->xEnd = dfsplitEnd;
p->lnLeft = p->lnRight = 0;
p->eState = 0;
p->pOut = pOut;
if( pCfg->zLeftHash ){
blob_appendf(pOut,
"<table class=\"diff splitdiff\" data-lefthash=\"%s\">\n",
pCfg->zLeftHash);
}else{
blob_append(pOut, "<table class=\"diff splitdiff\">\n", -1);
blob_append(pOut, "<table class=\"diff splitdiff\">\n", 31);
}
blob_init(&p->aCol[0], 0, 0);
blob_init(&p->aCol[1], 0, 0);
blob_init(&p->aCol[2], 0, 0);
blob_init(&p->aCol[3], 0, 0);
blob_init(&p->aCol[4], 0, 0);
p->pCfg = pCfg;
return p;
}
/************************* DiffBuilderSbs ******************************/
/* This formatter creates a side-by-side diff in text.
*/
|