Fossil SCM

Restore "const" before "DLine*" where possible in the diff generator. And even add some new instances of "const".

drh 2022-01-22 18:02 diff-improvement
Commit cf69ac4e394c668bedc1c868af684cf21b452e4eae2063332f4443b3ce12aed5
1 file changed +53 -53
+53 -53
--- src/diff.c
+++ src/diff.c
@@ -164,11 +164,11 @@
164164
int nEditAlloc; /* Space allocated for aEdit[] */
165165
DLine *aFrom; /* File on left side of the diff */
166166
int nFrom; /* Number of lines in aFrom[] */
167167
DLine *aTo; /* File on right side of the diff */
168168
int nTo; /* Number of lines in aTo[] */
169
- int (*xDiffer)(DLine*,DLine*); /* comparison function */
169
+ int (*xDiffer)(const DLine *,const DLine *); /* comparison function */
170170
};
171171
172172
/* Fast isspace for use by diff */
173173
static const char diffIsSpace[] = {
174174
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0,
@@ -313,11 +313,11 @@
313313
}
314314
315315
/*
316316
** Return zero if two DLine elements are identical.
317317
*/
318
-static int compare_dline(DLine *pA, DLine *pB){
318
+static int compare_dline(const DLine *pA, const DLine *pB){
319319
if( pA->h!=pB->h ) return 1;
320320
return memcmp(pA->z,pB->z, pA->h&LENGTH_MASK);
321321
}
322322
323323
/*
@@ -324,11 +324,11 @@
324324
** Return zero if two DLine elements are identical, ignoring
325325
** all whitespace. The indent field of pA/pB already points
326326
** to the first non-space character in the string.
327327
*/
328328
329
-static int compare_dline_ignore_allws(DLine *pA, DLine *pB){
329
+static int compare_dline_ignore_allws(const DLine *pA, const DLine *pB){
330330
int a = pA->indent, b = pB->indent;
331331
if( pA->h==pB->h ){
332332
while( a<pA->n || b<pB->n ){
333333
if( a<pA->n && b<pB->n && pA->z[a++] != pB->z[b++] ) return 1;
334334
while( a<pA->n && diff_isspace(pA->z[a])) ++a;
@@ -343,11 +343,11 @@
343343
** Return true if the regular expression *pRe matches any of the
344344
** N dlines
345345
*/
346346
static int re_dline_match(
347347
ReCompiled *pRe, /* The regular expression to be matched */
348
- DLine *aDLine, /* First of N DLines to compare against */
348
+ const DLine *aDLine, /* First of N DLines to compare against */
349349
int N /* Number of DLines to check */
350350
){
351351
while( N-- ){
352352
if( re_match(pRe, (const unsigned char *)aDLine->z, LENGTH(aDLine)) ){
353353
return 1;
@@ -361,11 +361,11 @@
361361
** Append a single line of context-diff output to pOut.
362362
*/
363363
static void appendDiffLine(
364364
Blob *pOut, /* Where to write the line of output */
365365
char cPrefix, /* One of " ", "+", or "-" */
366
- DLine *pLine /* The line to be output */
366
+ const DLine *pLine /* The line to be output */
367367
){
368368
blob_append_char(pOut, cPrefix);
369369
blob_append(pOut, pLine->z, pLine->n);
370370
blob_append_char(pOut, '\n');
371371
}
@@ -394,14 +394,14 @@
394394
static void contextDiff(
395395
DContext *p, /* The difference */
396396
Blob *pOut, /* Output a context diff to here */
397397
DiffConfig *pCfg /* Configuration options */
398398
){
399
- DLine *A; /* Left side of the diff */
400
- DLine *B; /* Right side of the diff */
401
- int a = 0; /* Index of next line in A[] */
402
- int b = 0; /* Index of next line in B[] */
399
+ const DLine *A; /* Left side of the diff */
400
+ const DLine *B; /* Right side of the diff */
401
+ int a = 0; /* Index of next line in A[] */
402
+ int b = 0; /* Index of next line in B[] */
403403
int *R; /* Array of COPY/DELETE/INSERT triples */
404404
int r; /* Index into R[] */
405405
int nr; /* Number of COPY/DELETE/INSERT triples to process */
406406
int mxr; /* Maximum value for r */
407407
int na, nb; /* Number of lines shown from A and B */
@@ -713,12 +713,12 @@
713713
**
714714
** The result is written into the LineChange object given by the
715715
** third parameter.
716716
*/
717717
static void oneLineChange(
718
- DLine *pLeft, /* Left line of the change */
719
- DLine *pRight, /* Right line of the change */
718
+ const DLine *pLeft, /* Left line of the change */
719
+ const DLine *pRight, /* Right line of the change */
720720
LineChange *p /* OUTPUT: Write the results here */
721721
){
722722
int nLeft; /* Length of left line in bytes */
723723
int nRight; /* Length of right line in bytes */
724724
int nShort; /* Shortest of left and right */
@@ -909,15 +909,15 @@
909909
** in appropriate method implementations.
910910
*/
911911
typedef struct DiffBuilder DiffBuilder;
912912
struct DiffBuilder {
913913
void (*xSkip)(DiffBuilder*, unsigned int, int);
914
- void (*xCommon)(DiffBuilder*,DLine*);
915
- void (*xInsert)(DiffBuilder*,DLine*);
916
- void (*xDelete)(DiffBuilder*,DLine*);
917
- void (*xReplace)(DiffBuilder*,DLine*, DLine*);
918
- void (*xEdit)(DiffBuilder*,DLine*,DLine*);
914
+ void (*xCommon)(DiffBuilder*,const DLine*);
915
+ void (*xInsert)(DiffBuilder*,const DLine*);
916
+ void (*xDelete)(DiffBuilder*,const DLine*);
917
+ void (*xReplace)(DiffBuilder*,const DLine*,const DLine*);
918
+ void (*xEdit)(DiffBuilder*,const DLine*,const DLine*);
919919
void (*xEnd)(DiffBuilder*);
920920
unsigned int lnLeft; /* Lines seen on the left (delete) side */
921921
unsigned int lnRight; /* Lines seen on the right (insert) side */
922922
unsigned int nPending; /* Number of pending lines */
923923
int eState; /* State of the output */
@@ -939,35 +939,35 @@
939939
n, p->lnLeft+1, p->lnLeft+n, p->lnRight+1, p->lnRight+n,
940940
isFinal ? " FINAL" : "");
941941
p->lnLeft += n;
942942
p->lnRight += n;
943943
}
944
-static void dfdebugCommon(DiffBuilder *p, DLine *pLine){
944
+static void dfdebugCommon(DiffBuilder *p, const DLine *pLine){
945945
p->lnLeft++;
946946
p->lnRight++;
947947
blob_appendf(p->pOut, "COMMON %8u %8u %.*s\n",
948948
p->lnLeft, p->lnRight, (int)pLine->n, pLine->z);
949949
}
950
-static void dfdebugInsert(DiffBuilder *p, DLine *pLine){
950
+static void dfdebugInsert(DiffBuilder *p, const DLine *pLine){
951951
p->lnRight++;
952952
blob_appendf(p->pOut, "INSERT %8d %.*s\n",
953953
p->lnRight, (int)pLine->n, pLine->z);
954954
}
955
-static void dfdebugDelete(DiffBuilder *p, DLine *pLine){
955
+static void dfdebugDelete(DiffBuilder *p, const DLine *pLine){
956956
p->lnLeft++;
957957
blob_appendf(p->pOut, "DELETE %8u %.*s\n",
958958
p->lnLeft, (int)pLine->n, pLine->z);
959959
}
960
-static void dfdebugReplace(DiffBuilder *p, DLine *pX, DLine *pY){
960
+static void dfdebugReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){
961961
p->lnLeft++;
962962
p->lnRight++;
963963
blob_appendf(p->pOut, "REPLACE %8u %.*s\n",
964964
p->lnLeft, (int)pX->n, pX->z);
965965
blob_appendf(p->pOut, " %8u %.*s\n",
966966
p->lnRight, (int)pY->n, pY->z);
967967
}
968
-static void dfdebugEdit(DiffBuilder *p, DLine *pX, DLine *pY){
968
+static void dfdebugEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
969969
int i, j;
970970
int x;
971971
LineChange chng;
972972
p->lnLeft++;
973973
p->lnRight++;
@@ -1055,33 +1055,33 @@
10551055
** additional string which is a common suffix.
10561056
*/
10571057
static void dftclSkip(DiffBuilder *p, unsigned int n, int isFinal){
10581058
blob_appendf(p->pOut, "SKIP %u\n", n);
10591059
}
1060
-static void dftclCommon(DiffBuilder *p, DLine *pLine){
1060
+static void dftclCommon(DiffBuilder *p, const DLine *pLine){
10611061
blob_appendf(p->pOut, "COM ");
10621062
blob_append_tcl_literal(p->pOut, pLine->z, pLine->n);
10631063
blob_append_char(p->pOut, '\n');
10641064
}
1065
-static void dftclInsert(DiffBuilder *p, DLine *pLine){
1065
+static void dftclInsert(DiffBuilder *p, const DLine *pLine){
10661066
blob_append(p->pOut, "INS ", -1);
10671067
blob_append_tcl_literal(p->pOut, pLine->z, pLine->n);
10681068
blob_append_char(p->pOut, '\n');
10691069
}
1070
-static void dftclDelete(DiffBuilder *p, DLine *pLine){
1070
+static void dftclDelete(DiffBuilder *p, const DLine *pLine){
10711071
blob_append(p->pOut, "DEL ", -1);
10721072
blob_append_tcl_literal(p->pOut, pLine->z, pLine->n);
10731073
blob_append_char(p->pOut, '\n');
10741074
}
1075
-static void dftclReplace(DiffBuilder *p, DLine *pX, DLine *pY){
1075
+static void dftclReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){
10761076
blob_append(p->pOut, "EDIT \"\" ", -1);
10771077
blob_append_tcl_literal(p->pOut, pX->z, pX->n);
10781078
blob_append_char(p->pOut, ' ');
10791079
blob_append_tcl_literal(p->pOut, pY->z, pY->n);
10801080
blob_append_char(p->pOut, '\n');
10811081
}
1082
-static void dftclEdit(DiffBuilder *p, DLine *pX, DLine *pY){
1082
+static void dftclEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
10831083
int i, x;
10841084
LineChange chng;
10851085
blob_append(p->pOut, "EDIT", 4);
10861086
oneLineChange(pX, pY, &chng);
10871087
for(i=x=0; i<chng.n; i++){
@@ -1139,33 +1139,33 @@
11391139
** not apply.
11401140
*/
11411141
static void dfjsonSkip(DiffBuilder *p, unsigned int n, int isFinal){
11421142
blob_appendf(p->pOut, "1,%u,\n", n);
11431143
}
1144
-static void dfjsonCommon(DiffBuilder *p, DLine *pLine){
1144
+static void dfjsonCommon(DiffBuilder *p, const DLine *pLine){
11451145
blob_append(p->pOut, "2,",2);
11461146
blob_append_json_literal(p->pOut, pLine->z, (int)pLine->n);
11471147
blob_append(p->pOut, ",\n",2);
11481148
}
1149
-static void dfjsonInsert(DiffBuilder *p, DLine *pLine){
1149
+static void dfjsonInsert(DiffBuilder *p, const DLine *pLine){
11501150
blob_append(p->pOut, "3,",2);
11511151
blob_append_json_literal(p->pOut, pLine->z, (int)pLine->n);
11521152
blob_append(p->pOut, ",\n",2);
11531153
}
1154
-static void dfjsonDelete(DiffBuilder *p, DLine *pLine){
1154
+static void dfjsonDelete(DiffBuilder *p, const DLine *pLine){
11551155
blob_append(p->pOut, "4,",2);
11561156
blob_append_json_literal(p->pOut, pLine->z, (int)pLine->n);
11571157
blob_append(p->pOut, ",\n",2);
11581158
}
1159
-static void dfjsonReplace(DiffBuilder *p, DLine *pX, DLine *pY){
1159
+static void dfjsonReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){
11601160
blob_append(p->pOut, "5,[\"\",",-1);
11611161
blob_append_json_literal(p->pOut, pX->z, (int)pX->n);
11621162
blob_append(p->pOut, ",",1);
11631163
blob_append_json_literal(p->pOut, pY->z, (int)pY->n);
11641164
blob_append(p->pOut, ",\"\"],\n",-1);
11651165
}
1166
-static void dfjsonEdit(DiffBuilder *p, DLine *pX, DLine *pY){
1166
+static void dfjsonEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
11671167
int i, x;
11681168
LineChange chng;
11691169
blob_append(p->pOut, "5,[", 3);
11701170
oneLineChange(pX, pY, &chng);
11711171
for(i=x=0; i<chng.n; i++){
@@ -1294,11 +1294,11 @@
12941294
blob_append(p->pOut, "<td class=\"diffln difflne\">"
12951295
"&#xfe19;</td><td></td><td></td></tr>\n", -1);
12961296
p->lnLeft += n;
12971297
p->lnRight += n;
12981298
}
1299
-static void dfunifiedCommon(DiffBuilder *p, DLine *pLine){
1299
+static void dfunifiedCommon(DiffBuilder *p, const DLine *pLine){
13001300
dfunifiedStartRow(p);
13011301
dfunifiedFinishDelete(p);
13021302
dfunifiedFinishInsert(p);
13031303
p->lnLeft++;
13041304
p->lnRight++;
@@ -1306,20 +1306,20 @@
13061306
blob_appendf(&p->aCol[0],"%d\n",p->lnRight);
13071307
blob_append_char(&p->aCol[1], '\n');
13081308
htmlize_to_blob(&p->aCol[2], pLine->z, (int)pLine->n);
13091309
blob_append_char(&p->aCol[2], '\n');
13101310
}
1311
-static void dfunifiedInsert(DiffBuilder *p, DLine *pLine){
1311
+static void dfunifiedInsert(DiffBuilder *p, const DLine *pLine){
13121312
dfunifiedStartRow(p);
13131313
p->lnRight++;
13141314
blob_appendf(&p->aCol[3],"%d\n", p->lnRight);
13151315
blob_append(&p->aCol[4], "<ins>", 5);
13161316
htmlize_to_blob(&p->aCol[4], pLine->z, (int)pLine->n);
13171317
blob_append(&p->aCol[4], "</ins>\n", 7);
13181318
p->nPending++;
13191319
}
1320
-static void dfunifiedDelete(DiffBuilder *p, DLine *pLine){
1320
+static void dfunifiedDelete(DiffBuilder *p, const DLine *pLine){
13211321
dfunifiedStartRow(p);
13221322
dfunifiedFinishInsert(p);
13231323
if( p->eState==0 ){
13241324
dfunifiedFinishInsert(p);
13251325
blob_append(p->pOut, "<del>", 5);
@@ -1332,11 +1332,11 @@
13321332
blob_append(&p->aCol[1],"-\n",2);
13331333
blob_append(&p->aCol[2], "<del>", 5);
13341334
htmlize_to_blob(&p->aCol[2], pLine->z, (int)pLine->n);
13351335
blob_append(&p->aCol[2], "</del>\n", 7);
13361336
}
1337
-static void dfunifiedReplace(DiffBuilder *p, DLine *pX, DLine *pY){
1337
+static void dfunifiedReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){
13381338
dfunifiedStartRow(p);
13391339
if( p->eState==0 ){
13401340
dfunifiedFinishInsert(p);
13411341
blob_append(p->pOut, "<del>", 5);
13421342
blob_append(&p->aCol[2], "<del>", 5);
@@ -1355,11 +1355,11 @@
13551355
13561356
htmlize_to_blob(&p->aCol[4], pY->z, pY->n);
13571357
blob_append_char(&p->aCol[4], '\n');
13581358
p->nPending++;
13591359
}
1360
-static void dfunifiedEdit(DiffBuilder *p, DLine *pX, DLine *pY){
1360
+static void dfunifiedEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
13611361
int i;
13621362
int x;
13631363
LineChange chng;
13641364
oneLineChange(pX, pY, &chng);
13651365
dfunifiedStartRow(p);
@@ -1524,11 +1524,11 @@
15241524
"<td class=\"diffln difflnr difflne\">&#xfe19;</td>"
15251525
"<td/td></tr>\n", -1);
15261526
p->lnLeft += n;
15271527
p->lnRight += n;
15281528
}
1529
-static void dfsplitCommon(DiffBuilder *p, DLine *pLine){
1529
+static void dfsplitCommon(DiffBuilder *p, const DLine *pLine){
15301530
dfsplitStartRow(p);
15311531
dfsplitChangeState(p, 0);
15321532
p->lnLeft++;
15331533
p->lnRight++;
15341534
blob_appendf(p->pOut,"%d\n", p->lnLeft);
@@ -1537,11 +1537,11 @@
15371537
blob_append_char(&p->aCol[1], '\n');
15381538
blob_appendf(&p->aCol[2],"%d\n",p->lnRight);
15391539
htmlize_to_blob(&p->aCol[3], pLine->z, (int)pLine->n);
15401540
blob_append_char(&p->aCol[3], '\n');
15411541
}
1542
-static void dfsplitInsert(DiffBuilder *p, DLine *pLine){
1542
+static void dfsplitInsert(DiffBuilder *p, const DLine *pLine){
15431543
dfsplitStartRow(p);
15441544
dfsplitChangeState(p, 2);
15451545
p->lnRight++;
15461546
blob_append_char(p->pOut, '\n');
15471547
blob_append_char(&p->aCol[0], '\n');
@@ -1549,11 +1549,11 @@
15491549
blob_appendf(&p->aCol[2],"%d\n", p->lnRight);
15501550
blob_append(&p->aCol[3], "<ins>", 5);
15511551
htmlize_to_blob(&p->aCol[3], pLine->z, (int)pLine->n);
15521552
blob_append(&p->aCol[3], "</ins>\n", 7);
15531553
}
1554
-static void dfsplitDelete(DiffBuilder *p, DLine *pLine){
1554
+static void dfsplitDelete(DiffBuilder *p, const DLine *pLine){
15551555
dfsplitStartRow(p);
15561556
dfsplitChangeState(p, 1);
15571557
p->lnLeft++;
15581558
blob_appendf(p->pOut,"%d\n", p->lnLeft);
15591559
blob_append(&p->aCol[0], "<del>", 5);
@@ -1561,11 +1561,11 @@
15611561
blob_append(&p->aCol[0], "</del>\n", 7);
15621562
blob_append(&p->aCol[1], "&lt;\n", -1);
15631563
blob_append_char(&p->aCol[2],'\n');
15641564
blob_append_char(&p->aCol[3],'\n');
15651565
}
1566
-static void dfsplitReplace(DiffBuilder *p, DLine *pX, DLine *pY){
1566
+static void dfsplitReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){
15671567
dfsplitStartRow(p);
15681568
dfsplitChangeState(p, 3);
15691569
p->lnLeft++;
15701570
p->lnRight++;
15711571
blob_appendf(p->pOut,"%d\n", p->lnLeft);
@@ -1577,11 +1577,11 @@
15771577
blob_appendf(&p->aCol[2],"%d\n", p->lnRight);
15781578
15791579
htmlize_to_blob(&p->aCol[3], pY->z, pY->n);
15801580
blob_append_char(&p->aCol[3], '\n');
15811581
}
1582
-static void dfsplitEdit(DiffBuilder *p, DLine *pX, DLine *pY){
1582
+static void dfsplitEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
15831583
int i;
15841584
int x;
15851585
LineChange chng;
15861586
oneLineChange(pX, pY, &chng);
15871587
dfsplitStartRow(p);
@@ -1679,11 +1679,11 @@
16791679
** from pX onto the into of p.
16801680
**
16811681
** This comment contains multibyte unicode characters (ü, Æ, ð) in order
16821682
** to test the ability of the diff code to handle such characters.
16831683
*/
1684
-static void sbs_append_chars(Blob *p, int iMin, int iMax, DLine *pX){
1684
+static void sbs_append_chars(Blob *p, int iMin, int iMax, const DLine *pX){
16851685
int i;
16861686
const char *z = pX->z;
16871687
for(i=0; i<iMax && i<pX->n; i++){
16881688
char c = z[i];
16891689
blob_append_char(p, c);
@@ -1693,33 +1693,33 @@
16931693
blob_append_char(p, ' ');
16941694
i++;
16951695
}
16961696
}
16971697
1698
-static void dfsbsCommon(DiffBuilder *p, DLine *pLine){
1698
+static void dfsbsCommon(DiffBuilder *p, const DLine *pLine){
16991699
p->lnLeft++;
17001700
p->lnRight++;
17011701
blob_appendf(p->pOut,"%6u ", p->lnLeft);
17021702
sbs_append_chars(p->pOut, p->width, p->width, pLine);
17031703
blob_appendf(p->pOut," %6u ", p->lnRight);
17041704
sbs_append_chars(p->pOut, 0, p->width, pLine);
17051705
blob_append_char(p->pOut, '\n');
17061706
}
1707
-static void dfsbsInsert(DiffBuilder *p, DLine *pLine){
1707
+static void dfsbsInsert(DiffBuilder *p, const DLine *pLine){
17081708
p->lnRight++;
17091709
blob_appendf(p->pOut,"%6s %*s > %6u ",
17101710
"", p->width, "", p->lnRight);
17111711
sbs_append_chars(p->pOut, 0, p->width, pLine);
17121712
blob_append_char(p->pOut, '\n');
17131713
}
1714
-static void dfsbsDelete(DiffBuilder *p, DLine *pLine){
1714
+static void dfsbsDelete(DiffBuilder *p, const DLine *pLine){
17151715
p->lnLeft++;
17161716
blob_appendf(p->pOut,"%6u ", p->lnLeft);
17171717
sbs_append_chars(p->pOut, p->width, p->width, pLine);
17181718
blob_append(p->pOut," <\n", 3);
17191719
}
1720
-static void dfsbsEdit(DiffBuilder *p, DLine *pX, DLine *pY){
1720
+static void dfsbsEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
17211721
p->lnLeft++;
17221722
p->lnRight++;
17231723
blob_appendf(p->pOut,"%6u ", p->lnLeft);
17241724
sbs_append_chars(p->pOut, p->width, p->width, pX);
17251725
blob_appendf(p->pOut, " | %6u ", p->lnRight);
@@ -1887,12 +1887,12 @@
18871887
** mismatch.
18881888
*/
18891889
static unsigned char *diffBlockAlignment(
18901890
DLine *aLeft, int nLeft, /* Text on the left */
18911891
DLine *aRight, int nRight, /* Text on the right */
1892
- DiffConfig *pCfg, /* Configuration options */
1893
- int *pNResult /* OUTPUT: Bytes of result */
1892
+ DiffConfig *pCfg, /* Configuration options */
1893
+ int *pNResult /* OUTPUT: Bytes of result */
18941894
){
18951895
int i, j, k; /* Loop counters */
18961896
int *a; /* One row of the Wagner matrix */
18971897
int *pToFree; /* Space that needs to be freed */
18981898
unsigned char *aM; /* Wagner result matrix */
@@ -1916,13 +1916,13 @@
19161916
** O(NlogN). The result is not as precise, but this whole thing is an
19171917
** approximation anyhow, and the faster response time is an acceptable
19181918
** trade-off for reduced precision.
19191919
*/
19201920
if( nLeft*nRight>DIFF_ALIGN_MX && (pCfg->diffFlags & DIFF_SLOW_SBS)==0 ){
1921
- DLine *aSmall; /* The smaller of aLeft and aRight */
1922
- DLine *aBig; /* The larger of aLeft and aRight */
1923
- int nSmall, nBig; /* Size of aSmall and aBig. nSmall<=nBig */
1921
+ DLine *aSmall; /* The smaller of aLeft and aRight */
1922
+ DLine *aBig; /* The larger of aLeft and aRight */
1923
+ int nSmall, nBig; /* Size of aSmall and aBig. nSmall<=nBig */
19241924
int iDivSmall, iDivBig; /* Divider point for aSmall and aBig */
19251925
int iDivLeft, iDivRight; /* Divider point for aLeft and aRight */
19261926
unsigned char *a1, *a2; /* Results of the alignments on two halves */
19271927
int n1, n2; /* Number of entries in a1 and a2 */
19281928
int score, bestScore; /* Score and best score seen so far */
@@ -2061,12 +2061,12 @@
20612061
static void formatDiff(
20622062
DContext *p, /* The computed diff */
20632063
DiffConfig *pCfg, /* Configuration options */
20642064
DiffBuilder *pBuilder /* The formatter object */
20652065
){
2066
- DLine *A; /* Left side of the diff */
2067
- DLine *B; /* Right side of the diff */
2066
+ DLine *A; /* Left side of the diff */
2067
+ DLine *B; /* Right side of the diff */
20682068
unsigned int a = 0; /* Index of next line in A[] */
20692069
unsigned int b = 0; /* Index of next line in B[] */
20702070
const int *R; /* Array of COPY/DELETE/INSERT triples */
20712071
unsigned int r; /* Index into R[] */
20722072
unsigned int nr; /* Number of COPY/DELETE/INSERT triples to process */
20732073
--- src/diff.c
+++ src/diff.c
@@ -164,11 +164,11 @@
164 int nEditAlloc; /* Space allocated for aEdit[] */
165 DLine *aFrom; /* File on left side of the diff */
166 int nFrom; /* Number of lines in aFrom[] */
167 DLine *aTo; /* File on right side of the diff */
168 int nTo; /* Number of lines in aTo[] */
169 int (*xDiffer)(DLine*,DLine*); /* comparison function */
170 };
171
172 /* Fast isspace for use by diff */
173 static const char diffIsSpace[] = {
174 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0,
@@ -313,11 +313,11 @@
313 }
314
315 /*
316 ** Return zero if two DLine elements are identical.
317 */
318 static int compare_dline(DLine *pA, DLine *pB){
319 if( pA->h!=pB->h ) return 1;
320 return memcmp(pA->z,pB->z, pA->h&LENGTH_MASK);
321 }
322
323 /*
@@ -324,11 +324,11 @@
324 ** Return zero if two DLine elements are identical, ignoring
325 ** all whitespace. The indent field of pA/pB already points
326 ** to the first non-space character in the string.
327 */
328
329 static int compare_dline_ignore_allws(DLine *pA, DLine *pB){
330 int a = pA->indent, b = pB->indent;
331 if( pA->h==pB->h ){
332 while( a<pA->n || b<pB->n ){
333 if( a<pA->n && b<pB->n && pA->z[a++] != pB->z[b++] ) return 1;
334 while( a<pA->n && diff_isspace(pA->z[a])) ++a;
@@ -343,11 +343,11 @@
343 ** Return true if the regular expression *pRe matches any of the
344 ** N dlines
345 */
346 static int re_dline_match(
347 ReCompiled *pRe, /* The regular expression to be matched */
348 DLine *aDLine, /* First of N DLines to compare against */
349 int N /* Number of DLines to check */
350 ){
351 while( N-- ){
352 if( re_match(pRe, (const unsigned char *)aDLine->z, LENGTH(aDLine)) ){
353 return 1;
@@ -361,11 +361,11 @@
361 ** Append a single line of context-diff output to pOut.
362 */
363 static void appendDiffLine(
364 Blob *pOut, /* Where to write the line of output */
365 char cPrefix, /* One of " ", "+", or "-" */
366 DLine *pLine /* The line to be output */
367 ){
368 blob_append_char(pOut, cPrefix);
369 blob_append(pOut, pLine->z, pLine->n);
370 blob_append_char(pOut, '\n');
371 }
@@ -394,14 +394,14 @@
394 static void contextDiff(
395 DContext *p, /* The difference */
396 Blob *pOut, /* Output a context diff to here */
397 DiffConfig *pCfg /* Configuration options */
398 ){
399 DLine *A; /* Left side of the diff */
400 DLine *B; /* Right side of the diff */
401 int a = 0; /* Index of next line in A[] */
402 int b = 0; /* Index of next line in B[] */
403 int *R; /* Array of COPY/DELETE/INSERT triples */
404 int r; /* Index into R[] */
405 int nr; /* Number of COPY/DELETE/INSERT triples to process */
406 int mxr; /* Maximum value for r */
407 int na, nb; /* Number of lines shown from A and B */
@@ -713,12 +713,12 @@
713 **
714 ** The result is written into the LineChange object given by the
715 ** third parameter.
716 */
717 static void oneLineChange(
718 DLine *pLeft, /* Left line of the change */
719 DLine *pRight, /* Right line of the change */
720 LineChange *p /* OUTPUT: Write the results here */
721 ){
722 int nLeft; /* Length of left line in bytes */
723 int nRight; /* Length of right line in bytes */
724 int nShort; /* Shortest of left and right */
@@ -909,15 +909,15 @@
909 ** in appropriate method implementations.
910 */
911 typedef struct DiffBuilder DiffBuilder;
912 struct DiffBuilder {
913 void (*xSkip)(DiffBuilder*, unsigned int, int);
914 void (*xCommon)(DiffBuilder*,DLine*);
915 void (*xInsert)(DiffBuilder*,DLine*);
916 void (*xDelete)(DiffBuilder*,DLine*);
917 void (*xReplace)(DiffBuilder*,DLine*, DLine*);
918 void (*xEdit)(DiffBuilder*,DLine*,DLine*);
919 void (*xEnd)(DiffBuilder*);
920 unsigned int lnLeft; /* Lines seen on the left (delete) side */
921 unsigned int lnRight; /* Lines seen on the right (insert) side */
922 unsigned int nPending; /* Number of pending lines */
923 int eState; /* State of the output */
@@ -939,35 +939,35 @@
939 n, p->lnLeft+1, p->lnLeft+n, p->lnRight+1, p->lnRight+n,
940 isFinal ? " FINAL" : "");
941 p->lnLeft += n;
942 p->lnRight += n;
943 }
944 static void dfdebugCommon(DiffBuilder *p, DLine *pLine){
945 p->lnLeft++;
946 p->lnRight++;
947 blob_appendf(p->pOut, "COMMON %8u %8u %.*s\n",
948 p->lnLeft, p->lnRight, (int)pLine->n, pLine->z);
949 }
950 static void dfdebugInsert(DiffBuilder *p, DLine *pLine){
951 p->lnRight++;
952 blob_appendf(p->pOut, "INSERT %8d %.*s\n",
953 p->lnRight, (int)pLine->n, pLine->z);
954 }
955 static void dfdebugDelete(DiffBuilder *p, DLine *pLine){
956 p->lnLeft++;
957 blob_appendf(p->pOut, "DELETE %8u %.*s\n",
958 p->lnLeft, (int)pLine->n, pLine->z);
959 }
960 static void dfdebugReplace(DiffBuilder *p, DLine *pX, DLine *pY){
961 p->lnLeft++;
962 p->lnRight++;
963 blob_appendf(p->pOut, "REPLACE %8u %.*s\n",
964 p->lnLeft, (int)pX->n, pX->z);
965 blob_appendf(p->pOut, " %8u %.*s\n",
966 p->lnRight, (int)pY->n, pY->z);
967 }
968 static void dfdebugEdit(DiffBuilder *p, DLine *pX, DLine *pY){
969 int i, j;
970 int x;
971 LineChange chng;
972 p->lnLeft++;
973 p->lnRight++;
@@ -1055,33 +1055,33 @@
1055 ** additional string which is a common suffix.
1056 */
1057 static void dftclSkip(DiffBuilder *p, unsigned int n, int isFinal){
1058 blob_appendf(p->pOut, "SKIP %u\n", n);
1059 }
1060 static void dftclCommon(DiffBuilder *p, DLine *pLine){
1061 blob_appendf(p->pOut, "COM ");
1062 blob_append_tcl_literal(p->pOut, pLine->z, pLine->n);
1063 blob_append_char(p->pOut, '\n');
1064 }
1065 static void dftclInsert(DiffBuilder *p, DLine *pLine){
1066 blob_append(p->pOut, "INS ", -1);
1067 blob_append_tcl_literal(p->pOut, pLine->z, pLine->n);
1068 blob_append_char(p->pOut, '\n');
1069 }
1070 static void dftclDelete(DiffBuilder *p, DLine *pLine){
1071 blob_append(p->pOut, "DEL ", -1);
1072 blob_append_tcl_literal(p->pOut, pLine->z, pLine->n);
1073 blob_append_char(p->pOut, '\n');
1074 }
1075 static void dftclReplace(DiffBuilder *p, DLine *pX, DLine *pY){
1076 blob_append(p->pOut, "EDIT \"\" ", -1);
1077 blob_append_tcl_literal(p->pOut, pX->z, pX->n);
1078 blob_append_char(p->pOut, ' ');
1079 blob_append_tcl_literal(p->pOut, pY->z, pY->n);
1080 blob_append_char(p->pOut, '\n');
1081 }
1082 static void dftclEdit(DiffBuilder *p, DLine *pX, DLine *pY){
1083 int i, x;
1084 LineChange chng;
1085 blob_append(p->pOut, "EDIT", 4);
1086 oneLineChange(pX, pY, &chng);
1087 for(i=x=0; i<chng.n; i++){
@@ -1139,33 +1139,33 @@
1139 ** not apply.
1140 */
1141 static void dfjsonSkip(DiffBuilder *p, unsigned int n, int isFinal){
1142 blob_appendf(p->pOut, "1,%u,\n", n);
1143 }
1144 static void dfjsonCommon(DiffBuilder *p, DLine *pLine){
1145 blob_append(p->pOut, "2,",2);
1146 blob_append_json_literal(p->pOut, pLine->z, (int)pLine->n);
1147 blob_append(p->pOut, ",\n",2);
1148 }
1149 static void dfjsonInsert(DiffBuilder *p, DLine *pLine){
1150 blob_append(p->pOut, "3,",2);
1151 blob_append_json_literal(p->pOut, pLine->z, (int)pLine->n);
1152 blob_append(p->pOut, ",\n",2);
1153 }
1154 static void dfjsonDelete(DiffBuilder *p, DLine *pLine){
1155 blob_append(p->pOut, "4,",2);
1156 blob_append_json_literal(p->pOut, pLine->z, (int)pLine->n);
1157 blob_append(p->pOut, ",\n",2);
1158 }
1159 static void dfjsonReplace(DiffBuilder *p, DLine *pX, DLine *pY){
1160 blob_append(p->pOut, "5,[\"\",",-1);
1161 blob_append_json_literal(p->pOut, pX->z, (int)pX->n);
1162 blob_append(p->pOut, ",",1);
1163 blob_append_json_literal(p->pOut, pY->z, (int)pY->n);
1164 blob_append(p->pOut, ",\"\"],\n",-1);
1165 }
1166 static void dfjsonEdit(DiffBuilder *p, DLine *pX, DLine *pY){
1167 int i, x;
1168 LineChange chng;
1169 blob_append(p->pOut, "5,[", 3);
1170 oneLineChange(pX, pY, &chng);
1171 for(i=x=0; i<chng.n; i++){
@@ -1294,11 +1294,11 @@
1294 blob_append(p->pOut, "<td class=\"diffln difflne\">"
1295 "&#xfe19;</td><td></td><td></td></tr>\n", -1);
1296 p->lnLeft += n;
1297 p->lnRight += n;
1298 }
1299 static void dfunifiedCommon(DiffBuilder *p, DLine *pLine){
1300 dfunifiedStartRow(p);
1301 dfunifiedFinishDelete(p);
1302 dfunifiedFinishInsert(p);
1303 p->lnLeft++;
1304 p->lnRight++;
@@ -1306,20 +1306,20 @@
1306 blob_appendf(&p->aCol[0],"%d\n",p->lnRight);
1307 blob_append_char(&p->aCol[1], '\n');
1308 htmlize_to_blob(&p->aCol[2], pLine->z, (int)pLine->n);
1309 blob_append_char(&p->aCol[2], '\n');
1310 }
1311 static void dfunifiedInsert(DiffBuilder *p, DLine *pLine){
1312 dfunifiedStartRow(p);
1313 p->lnRight++;
1314 blob_appendf(&p->aCol[3],"%d\n", p->lnRight);
1315 blob_append(&p->aCol[4], "<ins>", 5);
1316 htmlize_to_blob(&p->aCol[4], pLine->z, (int)pLine->n);
1317 blob_append(&p->aCol[4], "</ins>\n", 7);
1318 p->nPending++;
1319 }
1320 static void dfunifiedDelete(DiffBuilder *p, DLine *pLine){
1321 dfunifiedStartRow(p);
1322 dfunifiedFinishInsert(p);
1323 if( p->eState==0 ){
1324 dfunifiedFinishInsert(p);
1325 blob_append(p->pOut, "<del>", 5);
@@ -1332,11 +1332,11 @@
1332 blob_append(&p->aCol[1],"-\n",2);
1333 blob_append(&p->aCol[2], "<del>", 5);
1334 htmlize_to_blob(&p->aCol[2], pLine->z, (int)pLine->n);
1335 blob_append(&p->aCol[2], "</del>\n", 7);
1336 }
1337 static void dfunifiedReplace(DiffBuilder *p, DLine *pX, DLine *pY){
1338 dfunifiedStartRow(p);
1339 if( p->eState==0 ){
1340 dfunifiedFinishInsert(p);
1341 blob_append(p->pOut, "<del>", 5);
1342 blob_append(&p->aCol[2], "<del>", 5);
@@ -1355,11 +1355,11 @@
1355
1356 htmlize_to_blob(&p->aCol[4], pY->z, pY->n);
1357 blob_append_char(&p->aCol[4], '\n');
1358 p->nPending++;
1359 }
1360 static void dfunifiedEdit(DiffBuilder *p, DLine *pX, DLine *pY){
1361 int i;
1362 int x;
1363 LineChange chng;
1364 oneLineChange(pX, pY, &chng);
1365 dfunifiedStartRow(p);
@@ -1524,11 +1524,11 @@
1524 "<td class=\"diffln difflnr difflne\">&#xfe19;</td>"
1525 "<td/td></tr>\n", -1);
1526 p->lnLeft += n;
1527 p->lnRight += n;
1528 }
1529 static void dfsplitCommon(DiffBuilder *p, DLine *pLine){
1530 dfsplitStartRow(p);
1531 dfsplitChangeState(p, 0);
1532 p->lnLeft++;
1533 p->lnRight++;
1534 blob_appendf(p->pOut,"%d\n", p->lnLeft);
@@ -1537,11 +1537,11 @@
1537 blob_append_char(&p->aCol[1], '\n');
1538 blob_appendf(&p->aCol[2],"%d\n",p->lnRight);
1539 htmlize_to_blob(&p->aCol[3], pLine->z, (int)pLine->n);
1540 blob_append_char(&p->aCol[3], '\n');
1541 }
1542 static void dfsplitInsert(DiffBuilder *p, DLine *pLine){
1543 dfsplitStartRow(p);
1544 dfsplitChangeState(p, 2);
1545 p->lnRight++;
1546 blob_append_char(p->pOut, '\n');
1547 blob_append_char(&p->aCol[0], '\n');
@@ -1549,11 +1549,11 @@
1549 blob_appendf(&p->aCol[2],"%d\n", p->lnRight);
1550 blob_append(&p->aCol[3], "<ins>", 5);
1551 htmlize_to_blob(&p->aCol[3], pLine->z, (int)pLine->n);
1552 blob_append(&p->aCol[3], "</ins>\n", 7);
1553 }
1554 static void dfsplitDelete(DiffBuilder *p, DLine *pLine){
1555 dfsplitStartRow(p);
1556 dfsplitChangeState(p, 1);
1557 p->lnLeft++;
1558 blob_appendf(p->pOut,"%d\n", p->lnLeft);
1559 blob_append(&p->aCol[0], "<del>", 5);
@@ -1561,11 +1561,11 @@
1561 blob_append(&p->aCol[0], "</del>\n", 7);
1562 blob_append(&p->aCol[1], "&lt;\n", -1);
1563 blob_append_char(&p->aCol[2],'\n');
1564 blob_append_char(&p->aCol[3],'\n');
1565 }
1566 static void dfsplitReplace(DiffBuilder *p, DLine *pX, DLine *pY){
1567 dfsplitStartRow(p);
1568 dfsplitChangeState(p, 3);
1569 p->lnLeft++;
1570 p->lnRight++;
1571 blob_appendf(p->pOut,"%d\n", p->lnLeft);
@@ -1577,11 +1577,11 @@
1577 blob_appendf(&p->aCol[2],"%d\n", p->lnRight);
1578
1579 htmlize_to_blob(&p->aCol[3], pY->z, pY->n);
1580 blob_append_char(&p->aCol[3], '\n');
1581 }
1582 static void dfsplitEdit(DiffBuilder *p, DLine *pX, DLine *pY){
1583 int i;
1584 int x;
1585 LineChange chng;
1586 oneLineChange(pX, pY, &chng);
1587 dfsplitStartRow(p);
@@ -1679,11 +1679,11 @@
1679 ** from pX onto the into of p.
1680 **
1681 ** This comment contains multibyte unicode characters (ü, Æ, ð) in order
1682 ** to test the ability of the diff code to handle such characters.
1683 */
1684 static void sbs_append_chars(Blob *p, int iMin, int iMax, DLine *pX){
1685 int i;
1686 const char *z = pX->z;
1687 for(i=0; i<iMax && i<pX->n; i++){
1688 char c = z[i];
1689 blob_append_char(p, c);
@@ -1693,33 +1693,33 @@
1693 blob_append_char(p, ' ');
1694 i++;
1695 }
1696 }
1697
1698 static void dfsbsCommon(DiffBuilder *p, DLine *pLine){
1699 p->lnLeft++;
1700 p->lnRight++;
1701 blob_appendf(p->pOut,"%6u ", p->lnLeft);
1702 sbs_append_chars(p->pOut, p->width, p->width, pLine);
1703 blob_appendf(p->pOut," %6u ", p->lnRight);
1704 sbs_append_chars(p->pOut, 0, p->width, pLine);
1705 blob_append_char(p->pOut, '\n');
1706 }
1707 static void dfsbsInsert(DiffBuilder *p, DLine *pLine){
1708 p->lnRight++;
1709 blob_appendf(p->pOut,"%6s %*s > %6u ",
1710 "", p->width, "", p->lnRight);
1711 sbs_append_chars(p->pOut, 0, p->width, pLine);
1712 blob_append_char(p->pOut, '\n');
1713 }
1714 static void dfsbsDelete(DiffBuilder *p, DLine *pLine){
1715 p->lnLeft++;
1716 blob_appendf(p->pOut,"%6u ", p->lnLeft);
1717 sbs_append_chars(p->pOut, p->width, p->width, pLine);
1718 blob_append(p->pOut," <\n", 3);
1719 }
1720 static void dfsbsEdit(DiffBuilder *p, DLine *pX, DLine *pY){
1721 p->lnLeft++;
1722 p->lnRight++;
1723 blob_appendf(p->pOut,"%6u ", p->lnLeft);
1724 sbs_append_chars(p->pOut, p->width, p->width, pX);
1725 blob_appendf(p->pOut, " | %6u ", p->lnRight);
@@ -1887,12 +1887,12 @@
1887 ** mismatch.
1888 */
1889 static unsigned char *diffBlockAlignment(
1890 DLine *aLeft, int nLeft, /* Text on the left */
1891 DLine *aRight, int nRight, /* Text on the right */
1892 DiffConfig *pCfg, /* Configuration options */
1893 int *pNResult /* OUTPUT: Bytes of result */
1894 ){
1895 int i, j, k; /* Loop counters */
1896 int *a; /* One row of the Wagner matrix */
1897 int *pToFree; /* Space that needs to be freed */
1898 unsigned char *aM; /* Wagner result matrix */
@@ -1916,13 +1916,13 @@
1916 ** O(NlogN). The result is not as precise, but this whole thing is an
1917 ** approximation anyhow, and the faster response time is an acceptable
1918 ** trade-off for reduced precision.
1919 */
1920 if( nLeft*nRight>DIFF_ALIGN_MX && (pCfg->diffFlags & DIFF_SLOW_SBS)==0 ){
1921 DLine *aSmall; /* The smaller of aLeft and aRight */
1922 DLine *aBig; /* The larger of aLeft and aRight */
1923 int nSmall, nBig; /* Size of aSmall and aBig. nSmall<=nBig */
1924 int iDivSmall, iDivBig; /* Divider point for aSmall and aBig */
1925 int iDivLeft, iDivRight; /* Divider point for aLeft and aRight */
1926 unsigned char *a1, *a2; /* Results of the alignments on two halves */
1927 int n1, n2; /* Number of entries in a1 and a2 */
1928 int score, bestScore; /* Score and best score seen so far */
@@ -2061,12 +2061,12 @@
2061 static void formatDiff(
2062 DContext *p, /* The computed diff */
2063 DiffConfig *pCfg, /* Configuration options */
2064 DiffBuilder *pBuilder /* The formatter object */
2065 ){
2066 DLine *A; /* Left side of the diff */
2067 DLine *B; /* Right side of the diff */
2068 unsigned int a = 0; /* Index of next line in A[] */
2069 unsigned int b = 0; /* Index of next line in B[] */
2070 const int *R; /* Array of COPY/DELETE/INSERT triples */
2071 unsigned int r; /* Index into R[] */
2072 unsigned int nr; /* Number of COPY/DELETE/INSERT triples to process */
2073
--- src/diff.c
+++ src/diff.c
@@ -164,11 +164,11 @@
164 int nEditAlloc; /* Space allocated for aEdit[] */
165 DLine *aFrom; /* File on left side of the diff */
166 int nFrom; /* Number of lines in aFrom[] */
167 DLine *aTo; /* File on right side of the diff */
168 int nTo; /* Number of lines in aTo[] */
169 int (*xDiffer)(const DLine *,const DLine *); /* comparison function */
170 };
171
172 /* Fast isspace for use by diff */
173 static const char diffIsSpace[] = {
174 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0,
@@ -313,11 +313,11 @@
313 }
314
315 /*
316 ** Return zero if two DLine elements are identical.
317 */
318 static int compare_dline(const DLine *pA, const DLine *pB){
319 if( pA->h!=pB->h ) return 1;
320 return memcmp(pA->z,pB->z, pA->h&LENGTH_MASK);
321 }
322
323 /*
@@ -324,11 +324,11 @@
324 ** Return zero if two DLine elements are identical, ignoring
325 ** all whitespace. The indent field of pA/pB already points
326 ** to the first non-space character in the string.
327 */
328
329 static int compare_dline_ignore_allws(const DLine *pA, const DLine *pB){
330 int a = pA->indent, b = pB->indent;
331 if( pA->h==pB->h ){
332 while( a<pA->n || b<pB->n ){
333 if( a<pA->n && b<pB->n && pA->z[a++] != pB->z[b++] ) return 1;
334 while( a<pA->n && diff_isspace(pA->z[a])) ++a;
@@ -343,11 +343,11 @@
343 ** Return true if the regular expression *pRe matches any of the
344 ** N dlines
345 */
346 static int re_dline_match(
347 ReCompiled *pRe, /* The regular expression to be matched */
348 const DLine *aDLine, /* First of N DLines to compare against */
349 int N /* Number of DLines to check */
350 ){
351 while( N-- ){
352 if( re_match(pRe, (const unsigned char *)aDLine->z, LENGTH(aDLine)) ){
353 return 1;
@@ -361,11 +361,11 @@
361 ** Append a single line of context-diff output to pOut.
362 */
363 static void appendDiffLine(
364 Blob *pOut, /* Where to write the line of output */
365 char cPrefix, /* One of " ", "+", or "-" */
366 const DLine *pLine /* The line to be output */
367 ){
368 blob_append_char(pOut, cPrefix);
369 blob_append(pOut, pLine->z, pLine->n);
370 blob_append_char(pOut, '\n');
371 }
@@ -394,14 +394,14 @@
394 static void contextDiff(
395 DContext *p, /* The difference */
396 Blob *pOut, /* Output a context diff to here */
397 DiffConfig *pCfg /* Configuration options */
398 ){
399 const DLine *A; /* Left side of the diff */
400 const DLine *B; /* Right side of the diff */
401 int a = 0; /* Index of next line in A[] */
402 int b = 0; /* Index of next line in B[] */
403 int *R; /* Array of COPY/DELETE/INSERT triples */
404 int r; /* Index into R[] */
405 int nr; /* Number of COPY/DELETE/INSERT triples to process */
406 int mxr; /* Maximum value for r */
407 int na, nb; /* Number of lines shown from A and B */
@@ -713,12 +713,12 @@
713 **
714 ** The result is written into the LineChange object given by the
715 ** third parameter.
716 */
717 static void oneLineChange(
718 const DLine *pLeft, /* Left line of the change */
719 const DLine *pRight, /* Right line of the change */
720 LineChange *p /* OUTPUT: Write the results here */
721 ){
722 int nLeft; /* Length of left line in bytes */
723 int nRight; /* Length of right line in bytes */
724 int nShort; /* Shortest of left and right */
@@ -909,15 +909,15 @@
909 ** in appropriate method implementations.
910 */
911 typedef struct DiffBuilder DiffBuilder;
912 struct DiffBuilder {
913 void (*xSkip)(DiffBuilder*, unsigned int, int);
914 void (*xCommon)(DiffBuilder*,const DLine*);
915 void (*xInsert)(DiffBuilder*,const DLine*);
916 void (*xDelete)(DiffBuilder*,const DLine*);
917 void (*xReplace)(DiffBuilder*,const DLine*,const DLine*);
918 void (*xEdit)(DiffBuilder*,const DLine*,const DLine*);
919 void (*xEnd)(DiffBuilder*);
920 unsigned int lnLeft; /* Lines seen on the left (delete) side */
921 unsigned int lnRight; /* Lines seen on the right (insert) side */
922 unsigned int nPending; /* Number of pending lines */
923 int eState; /* State of the output */
@@ -939,35 +939,35 @@
939 n, p->lnLeft+1, p->lnLeft+n, p->lnRight+1, p->lnRight+n,
940 isFinal ? " FINAL" : "");
941 p->lnLeft += n;
942 p->lnRight += n;
943 }
944 static void dfdebugCommon(DiffBuilder *p, const DLine *pLine){
945 p->lnLeft++;
946 p->lnRight++;
947 blob_appendf(p->pOut, "COMMON %8u %8u %.*s\n",
948 p->lnLeft, p->lnRight, (int)pLine->n, pLine->z);
949 }
950 static void dfdebugInsert(DiffBuilder *p, const DLine *pLine){
951 p->lnRight++;
952 blob_appendf(p->pOut, "INSERT %8d %.*s\n",
953 p->lnRight, (int)pLine->n, pLine->z);
954 }
955 static void dfdebugDelete(DiffBuilder *p, const DLine *pLine){
956 p->lnLeft++;
957 blob_appendf(p->pOut, "DELETE %8u %.*s\n",
958 p->lnLeft, (int)pLine->n, pLine->z);
959 }
960 static void dfdebugReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){
961 p->lnLeft++;
962 p->lnRight++;
963 blob_appendf(p->pOut, "REPLACE %8u %.*s\n",
964 p->lnLeft, (int)pX->n, pX->z);
965 blob_appendf(p->pOut, " %8u %.*s\n",
966 p->lnRight, (int)pY->n, pY->z);
967 }
968 static void dfdebugEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
969 int i, j;
970 int x;
971 LineChange chng;
972 p->lnLeft++;
973 p->lnRight++;
@@ -1055,33 +1055,33 @@
1055 ** additional string which is a common suffix.
1056 */
1057 static void dftclSkip(DiffBuilder *p, unsigned int n, int isFinal){
1058 blob_appendf(p->pOut, "SKIP %u\n", n);
1059 }
1060 static void dftclCommon(DiffBuilder *p, const DLine *pLine){
1061 blob_appendf(p->pOut, "COM ");
1062 blob_append_tcl_literal(p->pOut, pLine->z, pLine->n);
1063 blob_append_char(p->pOut, '\n');
1064 }
1065 static void dftclInsert(DiffBuilder *p, const DLine *pLine){
1066 blob_append(p->pOut, "INS ", -1);
1067 blob_append_tcl_literal(p->pOut, pLine->z, pLine->n);
1068 blob_append_char(p->pOut, '\n');
1069 }
1070 static void dftclDelete(DiffBuilder *p, const DLine *pLine){
1071 blob_append(p->pOut, "DEL ", -1);
1072 blob_append_tcl_literal(p->pOut, pLine->z, pLine->n);
1073 blob_append_char(p->pOut, '\n');
1074 }
1075 static void dftclReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){
1076 blob_append(p->pOut, "EDIT \"\" ", -1);
1077 blob_append_tcl_literal(p->pOut, pX->z, pX->n);
1078 blob_append_char(p->pOut, ' ');
1079 blob_append_tcl_literal(p->pOut, pY->z, pY->n);
1080 blob_append_char(p->pOut, '\n');
1081 }
1082 static void dftclEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
1083 int i, x;
1084 LineChange chng;
1085 blob_append(p->pOut, "EDIT", 4);
1086 oneLineChange(pX, pY, &chng);
1087 for(i=x=0; i<chng.n; i++){
@@ -1139,33 +1139,33 @@
1139 ** not apply.
1140 */
1141 static void dfjsonSkip(DiffBuilder *p, unsigned int n, int isFinal){
1142 blob_appendf(p->pOut, "1,%u,\n", n);
1143 }
1144 static void dfjsonCommon(DiffBuilder *p, const DLine *pLine){
1145 blob_append(p->pOut, "2,",2);
1146 blob_append_json_literal(p->pOut, pLine->z, (int)pLine->n);
1147 blob_append(p->pOut, ",\n",2);
1148 }
1149 static void dfjsonInsert(DiffBuilder *p, const DLine *pLine){
1150 blob_append(p->pOut, "3,",2);
1151 blob_append_json_literal(p->pOut, pLine->z, (int)pLine->n);
1152 blob_append(p->pOut, ",\n",2);
1153 }
1154 static void dfjsonDelete(DiffBuilder *p, const DLine *pLine){
1155 blob_append(p->pOut, "4,",2);
1156 blob_append_json_literal(p->pOut, pLine->z, (int)pLine->n);
1157 blob_append(p->pOut, ",\n",2);
1158 }
1159 static void dfjsonReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){
1160 blob_append(p->pOut, "5,[\"\",",-1);
1161 blob_append_json_literal(p->pOut, pX->z, (int)pX->n);
1162 blob_append(p->pOut, ",",1);
1163 blob_append_json_literal(p->pOut, pY->z, (int)pY->n);
1164 blob_append(p->pOut, ",\"\"],\n",-1);
1165 }
1166 static void dfjsonEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
1167 int i, x;
1168 LineChange chng;
1169 blob_append(p->pOut, "5,[", 3);
1170 oneLineChange(pX, pY, &chng);
1171 for(i=x=0; i<chng.n; i++){
@@ -1294,11 +1294,11 @@
1294 blob_append(p->pOut, "<td class=\"diffln difflne\">"
1295 "&#xfe19;</td><td></td><td></td></tr>\n", -1);
1296 p->lnLeft += n;
1297 p->lnRight += n;
1298 }
1299 static void dfunifiedCommon(DiffBuilder *p, const DLine *pLine){
1300 dfunifiedStartRow(p);
1301 dfunifiedFinishDelete(p);
1302 dfunifiedFinishInsert(p);
1303 p->lnLeft++;
1304 p->lnRight++;
@@ -1306,20 +1306,20 @@
1306 blob_appendf(&p->aCol[0],"%d\n",p->lnRight);
1307 blob_append_char(&p->aCol[1], '\n');
1308 htmlize_to_blob(&p->aCol[2], pLine->z, (int)pLine->n);
1309 blob_append_char(&p->aCol[2], '\n');
1310 }
1311 static void dfunifiedInsert(DiffBuilder *p, const DLine *pLine){
1312 dfunifiedStartRow(p);
1313 p->lnRight++;
1314 blob_appendf(&p->aCol[3],"%d\n", p->lnRight);
1315 blob_append(&p->aCol[4], "<ins>", 5);
1316 htmlize_to_blob(&p->aCol[4], pLine->z, (int)pLine->n);
1317 blob_append(&p->aCol[4], "</ins>\n", 7);
1318 p->nPending++;
1319 }
1320 static void dfunifiedDelete(DiffBuilder *p, const DLine *pLine){
1321 dfunifiedStartRow(p);
1322 dfunifiedFinishInsert(p);
1323 if( p->eState==0 ){
1324 dfunifiedFinishInsert(p);
1325 blob_append(p->pOut, "<del>", 5);
@@ -1332,11 +1332,11 @@
1332 blob_append(&p->aCol[1],"-\n",2);
1333 blob_append(&p->aCol[2], "<del>", 5);
1334 htmlize_to_blob(&p->aCol[2], pLine->z, (int)pLine->n);
1335 blob_append(&p->aCol[2], "</del>\n", 7);
1336 }
1337 static void dfunifiedReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){
1338 dfunifiedStartRow(p);
1339 if( p->eState==0 ){
1340 dfunifiedFinishInsert(p);
1341 blob_append(p->pOut, "<del>", 5);
1342 blob_append(&p->aCol[2], "<del>", 5);
@@ -1355,11 +1355,11 @@
1355
1356 htmlize_to_blob(&p->aCol[4], pY->z, pY->n);
1357 blob_append_char(&p->aCol[4], '\n');
1358 p->nPending++;
1359 }
1360 static void dfunifiedEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
1361 int i;
1362 int x;
1363 LineChange chng;
1364 oneLineChange(pX, pY, &chng);
1365 dfunifiedStartRow(p);
@@ -1524,11 +1524,11 @@
1524 "<td class=\"diffln difflnr difflne\">&#xfe19;</td>"
1525 "<td/td></tr>\n", -1);
1526 p->lnLeft += n;
1527 p->lnRight += n;
1528 }
1529 static void dfsplitCommon(DiffBuilder *p, const DLine *pLine){
1530 dfsplitStartRow(p);
1531 dfsplitChangeState(p, 0);
1532 p->lnLeft++;
1533 p->lnRight++;
1534 blob_appendf(p->pOut,"%d\n", p->lnLeft);
@@ -1537,11 +1537,11 @@
1537 blob_append_char(&p->aCol[1], '\n');
1538 blob_appendf(&p->aCol[2],"%d\n",p->lnRight);
1539 htmlize_to_blob(&p->aCol[3], pLine->z, (int)pLine->n);
1540 blob_append_char(&p->aCol[3], '\n');
1541 }
1542 static void dfsplitInsert(DiffBuilder *p, const DLine *pLine){
1543 dfsplitStartRow(p);
1544 dfsplitChangeState(p, 2);
1545 p->lnRight++;
1546 blob_append_char(p->pOut, '\n');
1547 blob_append_char(&p->aCol[0], '\n');
@@ -1549,11 +1549,11 @@
1549 blob_appendf(&p->aCol[2],"%d\n", p->lnRight);
1550 blob_append(&p->aCol[3], "<ins>", 5);
1551 htmlize_to_blob(&p->aCol[3], pLine->z, (int)pLine->n);
1552 blob_append(&p->aCol[3], "</ins>\n", 7);
1553 }
1554 static void dfsplitDelete(DiffBuilder *p, const DLine *pLine){
1555 dfsplitStartRow(p);
1556 dfsplitChangeState(p, 1);
1557 p->lnLeft++;
1558 blob_appendf(p->pOut,"%d\n", p->lnLeft);
1559 blob_append(&p->aCol[0], "<del>", 5);
@@ -1561,11 +1561,11 @@
1561 blob_append(&p->aCol[0], "</del>\n", 7);
1562 blob_append(&p->aCol[1], "&lt;\n", -1);
1563 blob_append_char(&p->aCol[2],'\n');
1564 blob_append_char(&p->aCol[3],'\n');
1565 }
1566 static void dfsplitReplace(DiffBuilder *p, const DLine *pX, const DLine *pY){
1567 dfsplitStartRow(p);
1568 dfsplitChangeState(p, 3);
1569 p->lnLeft++;
1570 p->lnRight++;
1571 blob_appendf(p->pOut,"%d\n", p->lnLeft);
@@ -1577,11 +1577,11 @@
1577 blob_appendf(&p->aCol[2],"%d\n", p->lnRight);
1578
1579 htmlize_to_blob(&p->aCol[3], pY->z, pY->n);
1580 blob_append_char(&p->aCol[3], '\n');
1581 }
1582 static void dfsplitEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
1583 int i;
1584 int x;
1585 LineChange chng;
1586 oneLineChange(pX, pY, &chng);
1587 dfsplitStartRow(p);
@@ -1679,11 +1679,11 @@
1679 ** from pX onto the into of p.
1680 **
1681 ** This comment contains multibyte unicode characters (ü, Æ, ð) in order
1682 ** to test the ability of the diff code to handle such characters.
1683 */
1684 static void sbs_append_chars(Blob *p, int iMin, int iMax, const DLine *pX){
1685 int i;
1686 const char *z = pX->z;
1687 for(i=0; i<iMax && i<pX->n; i++){
1688 char c = z[i];
1689 blob_append_char(p, c);
@@ -1693,33 +1693,33 @@
1693 blob_append_char(p, ' ');
1694 i++;
1695 }
1696 }
1697
1698 static void dfsbsCommon(DiffBuilder *p, const DLine *pLine){
1699 p->lnLeft++;
1700 p->lnRight++;
1701 blob_appendf(p->pOut,"%6u ", p->lnLeft);
1702 sbs_append_chars(p->pOut, p->width, p->width, pLine);
1703 blob_appendf(p->pOut," %6u ", p->lnRight);
1704 sbs_append_chars(p->pOut, 0, p->width, pLine);
1705 blob_append_char(p->pOut, '\n');
1706 }
1707 static void dfsbsInsert(DiffBuilder *p, const DLine *pLine){
1708 p->lnRight++;
1709 blob_appendf(p->pOut,"%6s %*s > %6u ",
1710 "", p->width, "", p->lnRight);
1711 sbs_append_chars(p->pOut, 0, p->width, pLine);
1712 blob_append_char(p->pOut, '\n');
1713 }
1714 static void dfsbsDelete(DiffBuilder *p, const DLine *pLine){
1715 p->lnLeft++;
1716 blob_appendf(p->pOut,"%6u ", p->lnLeft);
1717 sbs_append_chars(p->pOut, p->width, p->width, pLine);
1718 blob_append(p->pOut," <\n", 3);
1719 }
1720 static void dfsbsEdit(DiffBuilder *p, const DLine *pX, const DLine *pY){
1721 p->lnLeft++;
1722 p->lnRight++;
1723 blob_appendf(p->pOut,"%6u ", p->lnLeft);
1724 sbs_append_chars(p->pOut, p->width, p->width, pX);
1725 blob_appendf(p->pOut, " | %6u ", p->lnRight);
@@ -1887,12 +1887,12 @@
1887 ** mismatch.
1888 */
1889 static unsigned char *diffBlockAlignment(
1890 DLine *aLeft, int nLeft, /* Text on the left */
1891 DLine *aRight, int nRight, /* Text on the right */
1892 DiffConfig *pCfg, /* Configuration options */
1893 int *pNResult /* OUTPUT: Bytes of result */
1894 ){
1895 int i, j, k; /* Loop counters */
1896 int *a; /* One row of the Wagner matrix */
1897 int *pToFree; /* Space that needs to be freed */
1898 unsigned char *aM; /* Wagner result matrix */
@@ -1916,13 +1916,13 @@
1916 ** O(NlogN). The result is not as precise, but this whole thing is an
1917 ** approximation anyhow, and the faster response time is an acceptable
1918 ** trade-off for reduced precision.
1919 */
1920 if( nLeft*nRight>DIFF_ALIGN_MX && (pCfg->diffFlags & DIFF_SLOW_SBS)==0 ){
1921 DLine *aSmall; /* The smaller of aLeft and aRight */
1922 DLine *aBig; /* The larger of aLeft and aRight */
1923 int nSmall, nBig; /* Size of aSmall and aBig. nSmall<=nBig */
1924 int iDivSmall, iDivBig; /* Divider point for aSmall and aBig */
1925 int iDivLeft, iDivRight; /* Divider point for aLeft and aRight */
1926 unsigned char *a1, *a2; /* Results of the alignments on two halves */
1927 int n1, n2; /* Number of entries in a1 and a2 */
1928 int score, bestScore; /* Score and best score seen so far */
@@ -2061,12 +2061,12 @@
2061 static void formatDiff(
2062 DContext *p, /* The computed diff */
2063 DiffConfig *pCfg, /* Configuration options */
2064 DiffBuilder *pBuilder /* The formatter object */
2065 ){
2066 DLine *A; /* Left side of the diff */
2067 DLine *B; /* Right side of the diff */
2068 unsigned int a = 0; /* Index of next line in A[] */
2069 unsigned int b = 0; /* Index of next line in B[] */
2070 const int *R; /* Array of COPY/DELETE/INSERT triples */
2071 unsigned int r; /* Index into R[] */
2072 unsigned int nr; /* Number of COPY/DELETE/INSERT triples to process */
2073

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button