🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.free.newsservers
Article #145840

--

#145840
From: Jeff-Relf.Me
Date: Mon, 12 Nov 2012 07:51
122 lines
5796 bytes
ï»ż<PRE><H2>
Since you replied to me, Michael⋅Moroney,
I'll explain some of my code to you, as if you cared.

Basically, "Eq30()" (below) returns "1" when the "left" block of lines
matches the "right" one.  When there's enough text for it,
no less than 30 characters must match.

Leading/Trailing White Space is ignored and
each run of White Space, including newlines,
is treated as if it were a single space.

⊿ <A hRef="http://Jeff-Relf.Me/X.CPP">The Visual C++ 2010 source code, X.CPP</A>.

Basically, "»Black∫()" (below) sets "P" ( which points to a character ) to:

  The first non⋅whitespace.
  ⋅OR⋅ to the end of a line, when:
    "End⋅of⋅File" is true.  EoF is "!PP[1]", "PP" points to a line.
    ⋅OR⋅ 30 or more characters have been compared.
  
  #define »Black∫( P, PP, P⋅W )  \
    \
    if ( P⋅W = *P &lt;= 32 )  \
      while(1) {  \
        /* Scan the block of lines for a non⋅white character. */ \
        while( *P && *P &lt;= 32 ) \
          /*  Scan current line for a non⋅white */ \
          P++ ;  \
         \
        if ( *P || Sz >= 30 )  \
          /*  Break at non⋅white ⋅OR⋅ the end of the line/block. */ \
          break ;  \
        \
        if ( !PP[1] ) { \
          /* "*P == 0", end of line, and "P⋅W = -1", end of file.  \
             Block matches if "!*P && !*Q && P⋅W == -1 && Q⋅W == -1" */ \
          EoF⋅Diff = P⋅W = -1 ; break ;  } \
        \
        /*  Get the next line in the block. */ \
        P = *++PP ;  }

  LnA LL₀, RR₀, ll, rr ; int Match ;
  //  LL and RR, left and right, point to blocks of lines.
  //  The blocks are compared.
  //
  //  "LL₀", a global, is the first line.
  //  "ll", also a global, is the last line of a match or mis⋅match.
  int Eq30( LnA LL, LnA RR ) {

    int Leading = 1, P⋅W, Q⋅W, Sz = 0 ;
    //  LL₀ (a global) points to first line in the block,
    //  LL (returned) points the last one.
    ll = LL₀ = LL, rr = RR₀ = RR ;  LnP P = *LL₀, Q = *RR₀ ;
    if ( EoF⋅Diff = !P || !Q )
      //  EoF⋅Diff right away ! can't do anything.
      return Match = 0 ;

    while(1) {
      //  "ll", a global, advances through a block of lines.
      »Black∫( P, ll, P⋅W ) »Black∫( Q, rr, Q⋅W )
      if ( *P != *Q || !Leading && P⋅W != Q⋅W )
        //  No match.  Either non⋅whitespace didn't match
        //  or one block had whitespace and the other didn't.
        return Match = 0 ;

      if ( !Leading && P⋅W )
        //  Count the virtual "ASCII 32" token.
        Sz++ ;
        
      Leading = 0 ;
      if ( !*P )
        //  A match.  Hit End⋅of⋅Line ( after one or more lines,
        //  >= 30 characters, ⋅OR⋅ "End⋅of⋅File" ( !PP[1] ) ).
        return Match = 1 ;
      
      while( *P && *P == *Q && *P > 32 )
        //  Advance "P" and "Q" ( the left and right lines )
        //  to the next "ASCII 32" token ⋅OR⋅ to the first mismatch.
        Sz++, P++, Q++ ;
    }
  }

"Eq30()" is used like this:

  if ( Eq30( L.PP, R.PP ), L.PP = ll, R.PP = rr, Match )
    //  The block of lines ( containing 30 or more characters ) match,
    //  Ignore them, go to the next pair of blocks.
    goto Next⋅Pair ;

  cnt⋅L = cnt⋅R = Identical = 0 ;   
  { Loop( 30 ) {
      LL = L.PP,  RR = R.PP + J ;
      //  Starting from the mismatched line, right⋅side,
      //  check the next 30 lines, "Loop( 30 )".
      //
      //  See if any of them are in the left⋅side file,
      //  starting with the left⋅side's mismatched line.
      while( Eq30( LL++, RR ), !Match && !EoF⋅Diff ) ;
      if ( Match ) { cnt⋅L = !Match ? 0 : LL₀ - L.PP ; break ;  } } }

  { Loop( 30 ) { LL = L.PP + J, RR = R.PP ;
      //  Same as above, switching sides.
      while( Eq30( LL, RR++ ), !Match && !EoF⋅Diff );
      if ( Match ) { cnt⋅R = !Match ? 0 : RR₀ - R.PP ; break ;  } } }

  if ( L.PP--, cnt⋅L ) {
    Loop( cnt⋅L )
      //  Print out the block of mismatched lines.
      P = *++L.PP, Sh( L"%s%s%s", !J ? L"«-" : L"  ", P, J + 1 == LLL ? L" »" : L"" );

    Sh(0);  }

  if ( R.PP--, cnt⋅R ) {
    Loop( cnt⋅R )
      P = *++R.PP, Sh( L"%s%s%s", !J ? L"« " : L"  ", P, J + 1 == LLL ? L" »" : L"" );

    Sh(0);  }

  if ( cnt⋅L || cnt⋅R ) goto Next⋅Pair ;

Some of this code will soon change, I expect.
Technical Details
Message-ID: <Jeff-Relf.Me@Nov.11{11.51.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!border2.nntp.dca3.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!novia!news.glorb.com!news-spur1.glorb.com!newsread.glorb.com!.POSTED!not-for-mail
References: <Jeff-Relf.Me@Nov.8{0.35.PM.Seattle.2012}> <k7i5f5$1gs$1@pcls6.std.com> <Jeff-Relf.Me@Nov.9{9.48.PM.Seattle.2012}> <k7lo68$904$1@pcls6.std.com> <Jeff-Relf.Me@Nov.10{2.16.PM.Seattle.2012}> <k7oq5j$o26$1@pcls6.std.com>

Show Full Headers
Complete Article Headers
Message-ID: <Jeff-Relf.Me@Nov.11{11.51.PM.Seattle.2012}>
Subject: --
Date: Mon, 12 Nov 2012 07:51:30 +0000
From: Jeff-Relf.Me <@.>
References: <Jeff-Relf.Me@Nov.8{0.35.PM.Seattle.2012}> <k7i5f5$1gs$1@pcls6.std.com> <Jeff-Relf.Me@Nov.9{9.48.PM.Seattle.2012}> <k7lo68$904$1@pcls6.std.com> <Jeff-Relf.Me@Nov.10{2.16.PM.Seattle.2012}> <k7oq5j$o26$1@pcls6.std.com>
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!border2.nntp.dca3.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!novia!news.glorb.com!news-spur1.glorb.com!newsread.glorb.com!.POSTED!not-for-mail
Newsgroups: alt.free.newsservers,sci.physics,comp.os.linux.advocacy
Organization: Glorb Internet Services, http://www.glorb.com
Lines: 122
NNTP-Posting-Host: XJGH+5GM8EvggnDfgIBqtQ.257.posting.glorb.com
Content-Type: Text/HTML; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Complaints-To: abuse@glorb.com
NNTP-Posting-Date: Mon, 12 Nov 2012 07:51:30 +0000 (UTC)
User-Agent: Jeff-Relf.Me/X.TXT
X-Notice: Scanned by Mr. Bill
X-Original-Bytes: 5529