🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.free.newsservers
Article #146045

--

#146045
From: Jeff-Relf.Me
Date: Thu, 22 Nov 2012 00:39
66 lines
4210 bytes
<body style='background: black;'><pre style='background: black; font-family: DejaVu Sans Mono, Lucida Console, monospace, MS Mincho; padding: 1em; color: rgb( 128, 64, 0 ); font-size: 25px;'>
I recently rewrote my diff (text file comparison) routines.
I didn't know, much less use, standard algorithms/formats.

<A hRef="http://en.wikipedia.org/wiki/Diff#Usage">Here</A> WikiPedia provides example
inputs/outputs and explains the formats of the various outputs.
Curious, I ran them though my diff routines.

My output, <A hRef="http://Jeff-Relf.Me/Diff.PNG">shown here</A>, is much easier to read !
Green highlights the new stuff, purple the old.
Every block of "old" lines, « - », is paired with a block of "new", « + ».

Before comparing lines, leading/trailing whitespace is removed.
When reporting, the whitespace is shown as it was, unaltered.

Although unaltered/whole lines are reported,
( with intra⋅line changes/words highlighted ),
runs of whitespace ( newlines, tabs, spaces )
are treated as if they were just one space ( ASCII 32 ).

When reporting on a block of changed lines ( and/or intra⋅line changes )
runs of up to 3 unchanged lines ( and/or words ) are allowed, for context.
Besides adding context, it reduces the chance of "false" (poor) reporting.

Standard diff routines don't do that.  Instead of simply allowing a run of
3 ( or fewer ) unchanged lines, they look for the longest runs first.

Of course, the last line in a file ( and/or last token in a line )
can match without the need for "the next 3 lines" to also match.

When highlighting changes within a line, the following determines
which two lines ( old vs. new ) should be compared.

  //  From <A hRef="http://Jeff-Relf.Me/X.CPP">X.CPP</A>, Visual C++.

  if ( Cnt ) {  //  "Cnt" is the number of lines ( in "BB⋅Alts[]" )
    //  that might be comparible to the current line,
    //  "b" ( "Vx" is "b" broken into a list of tokens/words ).

    LnP Word ; int WrdCnt, Len, SzVx, LenDiff, ⦿WrdCnt, ⦿Len, ⦿LenDiff, iBest ;
    iBest = ⦿WrdCnt = ⦿Len = 0, ⦿LenDiff = 999, SzVx = szStr( b );
    Loop( Cnt ) {
    
      WrdCnt = Len = 0, rv = szStr( BB⋅Alts[ J ] ), LenDiff = abs( SzVx - rv );
      LoopXx( Ln, Vx ) { if ( !( Word = P ) ) continue ;

        LoopXx( Ln, Aa[ J ] ) {  //  How well does this line macth ?
        
          if ( !P || P[-1] == 999 || !Eq( P, Word ) )
            //  The "int" before "P" ( a "word|Token" in a line of code )
            //  holds the "already matched" flag, 999.
            continue ;

          P[-1] = 999, WrdCnt++, Len += szStr( Word );
          break;  } }
      
      if ( WrdCnt > ⦿WrdCnt  //  Pick the line with the most matching tokens.
      || WrdCnt == ⦿WrdCnt
      && ( 
            Len > ⦿Len  //  A tie, choose the bigger matched⋅tokens.
            || Len == ⦿Len
            && LenDiff < ⦿LenDiff ) ) //  A tie, go with similar line length.

        ⦿WrdCnt = WrdCnt, ⦿Len = Len, ⦿LenDiff = LenDiff, iBest = J ;  }
      
    Alt = BB⋅Alts[ iBest ], Vx₂ = Aa[ iBest ];  } 
Technical Details
Message-ID: <Jeff-Relf.Me@Nov.21{4.39.PM.Seattle.2012}>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.free.newsservers.20150605.mbox.gz!border1.nntp.dca3.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!novia!news.glorb.com!news-spur1.glorb.com!newsread.glorb.com!.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <Jeff-Relf.Me@Nov.21{4.39.PM.Seattle.2012}>
Subject: --
Date: Thu, 22 Nov 2012 00:39:35 +0000
From: Jeff-Relf.Me <@.>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.free.newsservers.20150605.mbox.gz!border1.nntp.dca3.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!novia!news.glorb.com!news-spur1.glorb.com!newsread.glorb.com!.POSTED!not-for-mail
Newsgroups: comp.os.linux.advocacy,alt.free.newsservers,sci.physics
Organization: Glorb Internet Services, http://www.glorb.com
Lines: 66
NNTP-Posting-Host: XJGH+5GM8EvggnDfgIBqtQ.155.posting.glorb.com
Content-Type: Text/HTML; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Complaints-To: abuse@glorb.com
NNTP-Posting-Date: Thu, 22 Nov 2012 00:39:35 +0000 (UTC)
User-Agent: Jeff-Relf.Me/X.TXT
X-Notice: Scanned by Mr. Bill
X-Original-Bytes: 3899