Index: src/diff.c ================================================================== --- src/diff.c +++ src/diff.c @@ -351,10 +351,12 @@ appendDiffLine(pOut, ' ', &B[b+j], html); } } } +static int maxwidth; + /* ** Status of a single output line */ typedef struct SbsLine SbsLine; struct SbsLine { @@ -388,10 +390,14 @@ int k; /* Cursor position */ int needEndSpan = 0; const char *zIn = pLine->z; char *z = &p->zLine[p->n]; int w = p->width; + + if (n > maxwidth) + maxwidth = n; + for(i=j=k=0; kescHtml ){ if( i==p->iStart ){ int x = strlen(p->zStart); @@ -863,11 +869,11 @@ static void sbsDiff( DContext *p, /* The computed diff */ Blob *pOut, /* Write the results here */ int nContext, /* Number of lines of context around each change */ int width, /* Width of each column of output */ - int escHtml /* True to generate HTML output */ + int escHtml /* True to generate HTML output */ ){ DLine *A; /* Left side of the diff */ DLine *B; /* Right side of the diff */ int a = 0; /* Index of next line in A[] */ int b = 0; /* Index of next line in B[] */ @@ -1432,11 +1438,10 @@ ** Extract the width of columns for side-by-side diff. Supply an ** appropriate default if no width is given. */ int diff_width(int diffFlags){ int w = (diffFlags & DIFF_WIDTH_MASK)/(DIFF_CONTEXT_MASK+1); - if( w==0 ) w = 80; return w; } /* ** Generate a report of the differences between files pA and pB. @@ -1492,10 +1497,18 @@ if( pOut ){ /* Compute a context or side-by-side diff into pOut */ int escHtml = (diffFlags & DIFF_HTML)!=0; if( diffFlags & DIFF_SIDEBYSIDE ){ int width = diff_width(diffFlags); + if (width == 0){ /* Autocalculate */ + Blob dump; + /* Webserver */ + maxwidth = 0; + blob_zero(&dump); + sbsDiff(&c, &dump, nContext, width, escHtml); + width = maxwidth; + } sbsDiff(&c, pOut, nContext, width, escHtml); }else{ int showLn = (diffFlags & DIFF_LINENO)!=0; contextDiff(&c, pOut, nContext, showLn, escHtml); } Index: src/diffcmd.c ================================================================== --- src/diffcmd.c +++ src/diffcmd.c @@ -41,12 +41,19 @@ /* no-op */ }else if( diffFlags & DIFF_SIDEBYSIDE ){ int w = diff_width(diffFlags); int n1 = strlen(zLeft); int x; - if( n1>w*2 ) n1 = w*2; - x = w*2+17 - (n1+2); + if (w > 0) { + if( n1>w*2 ) n1 = w*2; + x = w*2+17 - (n1+2); + }else{ + /* Autocalculate width + * We can't know the width in advance, so we'll make it + * output three = around the name */ + x = 6; + } z = mprintf("%.*c %.*s %.*c\n", x/2, '=', n1, zLeft, (x+1)/2, '='); }else{ z = mprintf("--- %s\n+++ %s\n", zLeft, zRight); } Index: src/info.c ================================================================== --- src/info.c +++ src/info.c @@ -363,12 +363,13 @@ }else{ int x; if( sideBySide ){ diffFlags = DIFF_SIDEBYSIDE | DIFF_IGNORE_EOLWS; - /* "dw" query parameter determines width of each column */ - x = atoi(PD("dw","80"))*(DIFF_CONTEXT_MASK+1); + /* "dw" query parameter determines width of each column + * 0 means autocalculate. */ + x = atoi(PD("dw","0"))*(DIFF_CONTEXT_MASK+1); if( x<0 || x>DIFF_WIDTH_MASK ) x = DIFF_WIDTH_MASK; diffFlags += x; }else{ diffFlags = DIFF_INLINE | DIFF_IGNORE_EOLWS; }