🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #84675

--

#84675
From: Anon
Date: Tue, 03 Apr 2012 17:30
155 lines
7718 bytes
ďťż
How do you ( Michael⋅Moroney ) manage to keep missing the point ? !

Google Groups is the best way to link to a post.
Variable⋅width glyphs are the default there and elsewhere;
so, to insure a monospaced font, use the PRE tag.

There are many ways to display HTML,
emacs and slrn ⋅should⋅ be one way, but they can't manage it;
so Ray Banana's noob⋅fest, Eternal⋅September, drops HTML posts.

My HTML⋅to⋅Plain⋅Text code has changed again ( and again ).
>From Jeff-Relf.Me/X.CPP:

#define  While( ↻ )  Ch = 1, P-- ; while( ( Ch−1 = Ch ) && ( Ch = *++P, Ch2 = !Ch ? 0 : P[1], ↻ ) )
//  "While(0)" ( for example ) would loop zero times and not alter P,
//  but sets Ch and Ch2 to P[0] and P[1], respectively.
//
//  Essentially, the macro is "while( A && B )" where
//  B sets Ch and increments P.
//
//  B won't happen unless A is true.  First time through the loop,
//  A is true.  Second pass, A is false when, initially, "*P == 0".
#define  WhileBac( ↻ )  \
  Ch = Ch2 = 0, E ? 0 : E = B + szStr( B ), P = E ;  \
  while ( P >= B && ( Ch2 = *P, ( Ch = --P < B ? 0 : *P ) && ( ↻ ) ) )

//  Don't indent "footers" ( i.e. links, tag IDs and Alt text ).
//  Make plain⋅text stand out, indent it 4 spaces and
//  put a newline before and after each block of plain⋅text.

//  Wrap to "mxCols" ( 121 columns, monospaced ).
const int mxCols = ColsWin - 6 ;
int ↡, iPP, PRE, inTag, Open⋅A ;  LnT _id, _Alt, _Src, _hRef ;

Cat( LnP B², int Sz² ) { if ( Sz² <= 0 ) return;
  LnP &Bš = *Ln.PP, Bš⁺² ; int Szš = szStr( Bš ), Szš⁺² = Szš + Sz² ;
  if ( !Szš || Szš⁺² > mxCols ) {
    //  Start a new line, don't append.
    //
    //  When the current console line is blank (!Szš)
    //  and it's not Top⋅Most ( Top⋅Most must be a blank line )
    //  and the line above isn't a "Footer", remove it.
    Ln.PP -= !Szš && Ln.PP > Ln.BB + iPP && *Ln.PP[-1] <= 32 ;

    if ( Sz² < 4 || B²[2] != L'⌗' )
      //  Print the plain⋅text, indented.
      Sh( L"    %.*s", Sz², B² );
    else
      //  Print the tag ID, not indented, omit the leading " ,".
      Sh( L"%.*s", Sz²-=2, B²+=2 );
     
    return;  }

  //  Append, tag ID or plain⋅text.
  Bš⁺² = MallocTmp( ++Szš⁺² * szChr ), Str( Bš⁺², L"%s%.*s", Bš, Sz², B² ), Bš = Bš⁺² ;  }

Cat( wchar_t Ch ) { Cat( &Ch, 1 );  }

//  Print a new line or "↡", print footers.
Trim() { if ( ↡ = 0, Open⋅A ) return ; int Footers = _Alt.BB || _Src.BB || _hRef.BB || _id.BB ;
  //  Remove trailing whitespace and leading blank lines.                                               
  LOOP { B = *Ln.PP, E = 0 ;  WhileBac( Ch == L'↡' || Ch <= 32 || Ch == L'\xA0' );
    if ( ++P < E ) *P = 0 ;  if ( !*B && Ln.PP > Ln.BB + iPP && !PRE ) Ln.PP-- ; else break ;  }
    
  if ( !PRE && *B == 32 && !( ↡ = !Footers ) )
    //  "Footers" follow plain text, print a blank line.
    Sh(0);
  if ( _hRef.BB ) { LoopXx( Ln, _hRef ) Sh( L"%s%s", ⁺Folder( B ), Human( B ) );  Zero( _hRef );  }
  if ( _Alt.BB ) { LoopXx( Ln, _Alt ) Sh( L"%s", Human( B ) );  Zero( _Alt );  }
  if ( _Src.BB ) { LoopXx( Ln, _Src ) Sh( L"%s%s", ⁺Folder( B ), Human( B ) );  Zero( _Src );  }
  if ( _id.BB ) {
    LoopXx( Ln, _id )
      if ( Human(B), **Ln.PP != L'⌗' )
        //  Start a line of tag IDs.
        Sh( L"⌗%s", B );
      else
        //  Add to the line of tag IDs.
        rv = Str( _T, L", ⌗%s", B ), Cat( _T, rv );
    Zero( _id );  } }

//  Print a new line or "↡", print footers.
#define Br  ( Trim(), Open⋅A ? Cat( 32 ) : !**Ln.PP && !*Ln.PP[-1] ? 0 : ↡ ? Cat( L'↡' ) : Sh(0) )
#define feedMe  { if ( !feedMe₍₎( B, P, PP, EE ) ) return ;  }

int feedMe₍₎( LnP &B, LnP &P, LnA &PP, LnA EE ) { While(0); if ( Ch ) return 1 ;
  //  Read in a new line.  
  if ( PRE && !inTag ) Br;
  else { LnP &T = *Ln.PP ; if ( rv = szStr( T ), rv && T[ rv - 1 ] > 32 ) Cat( 32 );  }

  if ( ++PP >= EE || ( P = B = *PP, B && MimeSep && EqN( B, *MimeSep, Sz_MimeSep ) ) ) {
    //  All done !
    Trim(); return 0 ;  }

  //  Keep parsing.
  While(0);  return 1 ;  }

//  Parse out plain⋅text from tags/entities.
#define Ch⋅BoTag& ( \
     Ch == '&' && ( Ch2 == '#' || isAlpha( Ch2 ) )  \
  || Ch == '<' && ( Ch2 == '!' || Ch2 == '?' || isAlpha( Ch2 ) || Ch2 == '/' && isAlpha( P[2] ) ) )

HTML⋅to⋅Text( LnA  BB, LnA  EE ) { static rv ;  LnA PP = BB - 1 ;
  if ( **Ln.PP ) Sh(0);  iPP = Ln.PP - Ln.BB ;
  LnP  euText, B = L"", P = B, Alt, Src, id, hRef = 0 ; int PlainText ;
  Zero( _Alt ), Zero( _Src ), Zero( _hRef ), Zero( _id );
  PlainText = PRE = Ch = Open⋅A = 0 ;
  ➤BoTag&:
  inTag = 0 ;  feedMe
  if ( PlainText ) {  //  Print unparsed.
    euText = P, P += szStr( P ), Ch = 0 ;  } 
  else { //  Parse out plain⋅text from tags/entities.
    euText = 0 ; While( !Ch⋅BoTag& ) if ( !euText && Ch ) euText = P ;  }

  LnP  BoTag& = P ; LnA  BoTagPP = PP ;  if ( !euText ) goto Parse⋅Tag ;
  { LnP  Bš, B², P², Eš, E² ;  int Szš, Sz², Sz⁝², Szš⁺², SP, SP², Ch, Ch2 ;
    Bš = Eš = *Ln.PP, Szš = szStr( Bš ), Eš += Szš ;
    if ( B² = euText, E² = BoTag&, !PRE ) {
      //  Pemove redundent whitespace. What's left will be printed.
      Ch = !Szš ? 0 : Eš[-1], SP = Ch <= 32, P² = B², D = B² - 1 ;
      While²( P² < E² )
        if ( SP² = Ch <= 32 || Ch == L'\xFeFF', !SP && SP² ) *++D = 32, SP = 1 ; else if ( !SP² ) *++D = Ch, SP = 0 ;

      E² = ++D ;  }

    if ( Sz² = E² - B², Sz² <= 0 || Sz² == 1 && *B² <= 32 ) goto Parse⋅Tag ;
    if ( PRE ) {
      //  Print the "PRE⋅formatted" text, no wrapping.
      Cat( B², Sz² ); goto Parse⋅Tag ;  }

    LOOP {
      if ( Szš⁺² = Szš + Sz², Szš⁺² <= mxCols ) {
        //  Print as is, don't wrap.
        Cat( B², Sz² ); goto Parse⋅Tag ;  }

      E² = B² + ER( 0, mxCols - Szš ); WhileBac²( Iden( Ch ) );
      if ( Sz⁝² = P² - B² + 1, Sz⁝² >= 22 )
        //  Append part of the text to the current line.
        Cat( B², Sz⁝² ), Szš = Sh(0); 
      else
        //  Start a line, instead of appending.
        if ( !Sz⁝² )
          //  Start a blank line.
          Szš = Sh(0);
        else
          //  Start a new line with the text. 
          Szš = Sh( L"    %.*s", Sz⁝², B² );
      
      //  Print the rest of it, might be blank.
      Sz² -= Sz⁝², B² = ++P² ;  } }
    
  Parse⋅Tag:
    //  Parse the tag or entity.
    inTag = 1 ;  While(0);  if ( !Ch ) goto ➤BoTag& ;
Technical Details
Message-ID: <Jeff-Relf.Me@2012_Apr.3^10.30^AM>
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!postnews.google.com!news3.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
References: <52419e8532dca12c0d42ed3dc6692d9f@tioat.net> <5h4oah.n9v.19.1@news.alt.net> <Jeff-Relf.Me@2012_Apr.1^0.57^AM> <jl9ubp$d5d$1@pcls6.std.com> <X.Invalid@2012_Apr.1^11.37^AM> <jlf475$i2v$1@pcls6.std.com>

Show Full Headers
Complete Article Headers
Message-ID: <Jeff-Relf.Me@2012_Apr.3^10.30^AM>
Subject: --
Date: Tue, 03 Apr 2012 17:30:10 +0000
From: @Jeff-Relf.Me
References: <52419e8532dca12c0d42ed3dc6692d9f@tioat.net> <5h4oah.n9v.19.1@news.alt.net> <Jeff-Relf.Me@2012_Apr.1^0.57^AM> <jl9ubp$d5d$1@pcls6.std.com> <X.Invalid@2012_Apr.1^11.37^AM> <jlf475$i2v$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!postnews.google.com!news3.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
Newsgroups: alt.free.newsservers,news.software.readers,news.software.nntp
Lines: 155
Content-Type: Text/plain; charset=UTF-8
X-Trace: individual.net 73dOSAOfjiDGE61Z6v1nlA+KygLBvHFVn+wygqNl3KfEq5e8Da
Cancel-Lock: sha1:3c72wXJf7NUQXBxoBlnbB9gunkg=
User-Agent: Jeff-Relf.Me/X.TXT
X-Original-Bytes: 7701