Article View: alt.free.newsservers
Article #146803--
From: Jeff-Relf.Me
Date: Mon, 31 Dec 2012 02:20
Date: Mon, 31 Dec 2012 02:20
47 lines
4260 bytes
4260 bytes
<style> :not(:link):not(:visited){color:rgb(255,111,111)} :link{color:rgb(155,155,155)} :visited{color:rgb(155,155,0)} </style> <body bgcolor=black style='margin: 0'><pre style='color: rgb(255,111,111); padding:0 1em 1em 1em; font-size: 15px; font-family: DejaVu Sans Mono, Lucida Console, monospace, MS Mincho; background: black;'>Â
Most often, the best code ( for me, and only me ) is the code I wrote.
As a programmer, text comparison is like water; an essential, daily thing.
So I wrote my own diff routine ( as part of X.EXE, my console/newsreader ).
At it's heart, and right off the bat, my "diff" sort of "skips past"
the unchanged part at the beginning and the ends of both lines and files.
A run of whitespace, including "new lines" ( ASCII 13 and 10 ),
is treated as if it were a single space ( ASCII 32 ).
I could've stopped right there, if I wanted to,
as that is (almost) good enough; but I didn't.
The heart of the line/token comparison routine looks like this:
#define white( P ) ( *P <= 32 || *P == 0xA0 )
#define Data ( ToData( P, EEx, EE, SyncCnt ), ToData( _P, _EEx, _EE, _SyncCnt ), EEx < EE && _EEx < _EE )
ToData( LnP &P, LnA &EEx, LnA EE, int &SyncCnt ) { if ( P ) while( *P && white( P ) ) P++ ;
while( ( !P || !*P ) && EEx < EE ) ( ++EEx >= EE ? ( P = 0, 0 ) : ( P = *EEx, SyncCnt += !!*P ) ); }
LnA BBx, EEx, _BBx, _EEx ; int SyncCnt, _SyncCnt ;
int inSync( int minSyncCnt, LnA BB, LnA EE, LnA _BB, LnA _EE ) { int rv ; LnP P, _P ; LnA PP, _PP ;
BBx = PP = EEx = BB, _BBx = _PP = _EEx = _BB, SyncCnt = _SyncCnt = 0, P = _P = 0, EEx--, _EEx-- ;
while ( Data ) { while( *P && *P == *_P && !white( _P ) ) P++, _P++ ; if ( !white( P ) || !white( _P ) ) return 0 ;
if ( !*P && !*_P && ( SyncCnt + _SyncCnt ) / 2 >= minSyncCnt ) return Data, 1 ; } return 0 ; }
#define EoFS ( S = PPâ‹…Slow < EE, _S = _PPâ‹…Slow < _EE, F = PPâ‹…Fast < EE, _F = _PPâ‹…Fast < _EE )
ReSync( int minSyncCnt, LnA BB, LnA EE, LnA _BB, LnA _EE ) {
int S, _S, F, _F ; LnA PPâ‹…Slow, PPâ‹…Fast, _PPâ‹…Slow, _PPâ‹…Fast ;
PPâ‹…Slow = BB, _PPâ‹…Slow = _BB ; Top_: PPâ‹…Fast = BB, _PPâ‹…Fast = _BB ; Down:
if ( EoFS, !S && !_S ) { BBx = EEx = EE, _BBx = _EEx = _EE ; return ; }
if ( F && _S ) if ( inSync( minSyncCnt, PPâ‹…Fast, EE, _PPâ‹…Slow, _EE ) ) return; else PPâ‹…Fast++ ;
if ( S && _F ) if ( inSync( minSyncCnt, PPâ‹…Slow, EE, _PPâ‹…Fast, _EE ) ) return; else _PPâ‹…Fast++ ;
if ( EoFS, F && _S || S && _F ) goto Down ; PPâ‹…Slow += S, _PPâ‹…Slow += _S ; goto Top_ ; }
â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…â‹…
WhileSynced:
if ( Vx.PP >= Vx.ee || _Vx.PP >= _Vx.ee ) { VxPPă‚ ( Diffâ‹…Ch, Vx.ee, _Vx.ee ), Str( D, L"%s", D2 ); return Bâ‹…D ; }
if ( rv = inSync( 99, Vx.PP, Vx.ee, _Vx.PP, _Vx.ee ), VxPPă‚ ( textâ‹…Ch, EEx, _EEx ), rv ) goto WhileSynced ;
ReSync( 2, Vx.PP, Vx.ee, _Vx.PP, _Vx.ee ), VxPPă‚ ( Diffâ‹…Ch, BBx, _BBx ); goto WhileSynced ; }
<img Src="http://Jeff-Relf.Me/Diff.PNG" Alt="Text Comparison">
Technical Details
Message-ID:
<Jeff-Relf.Me@Dec.30{6.20.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.ams2.giganews.com!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news2.euro.net!news.glorb.com!news-spur1.glorb.com!newsread.glorb.com!.POSTED!not-for-mailShow Full Headers
Complete Article Headers
Message-ID: <Jeff-Relf.Me@Dec.30{6.20.PM.Seattle.2012}>
Subject: --
Date: Mon, 31 Dec 2012 02:20:47 +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.ams2.giganews.com!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news2.euro.net!news.glorb.com!news-spur1.glorb.com!newsread.glorb.com!.POSTED!not-for-mail
Newsgroups: comp.os.linux.advocacy, alt.free.newsservers, sci.physics, alt.astronomy
alt.astronomy
Organization: Glorb Internet Services, http://www.glorb.com
Lines: 47
NNTP-Posting-Host: XJGH+5GM8EvggnDfgIBqtQ.479.posting.glorb.com
Content-Type: Text/HTML; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Complaints-To: abuse@glorb.com
NNTP-Posting-Date: Mon, 31 Dec 2012 02:20:47 +0000 (UTC)
User-Agent: Jeff-Relf.Me/X.HTM
X-Notice: Scanned by Mr. Bill