Article View: news.software.readers
Article #139798Re: [slrn] fixing tofu for display
From: Paul Boekholt
Date: Wed, 24 Dec 2003 23:09
Date: Wed, 24 Dec 2003 23:09
82 lines
4455 bytes
4455 bytes
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 24 Dec 2003 10:58:47 GMT, Sven Guckes <usenet@guckes.net> said:
> so - can you do it for slrn, too?
Write an un_tofu function you mean? I'd prefer to do it in JED, and later
port it to slrn, since JED provides a nice S-Lang IDE and slrn does not.
> well, describing such things is not easy within sed as you
> don't have a language with if/then/else "branches". ok,
> there *is* such a thing, but it's not really readable. ;-)
Doing it with S-Lang is not easy either, it has a nice C-like syntax but
the regexp functions are not as powerful as in, say, Emacs lisp (or sed).
That's actually the weakest point of S-Lang. Maybe it should be solved in
Awk or something. Writing this without using JED's intrinsics is awkward
enough for me, but I hope it can be useful in slrn as well. To fix tofu
in reply to other tofu, ntuf in reply to tofu etc. it should be made
recursive - the quoted part should be compared against a quoted tofu
pattern. Maybe next year. Merry Christmas.
define string_nth_match()
{
variable pos, len;
(pos, len) = string_match_nth(n);
return substr(str, pos+1, len);
}
define un_tofu()
{
mark_buffer;
variable article = bufsubstr_delete;
EXIT_BLOCK
{
insert (article);
}
% from here it should not be JED-specific
% S-Lang's regexps are weak - we can group a part with parentheses,
% but we can't make the make the group optional, so to match the
% attribution we have to make a substring match and then do a
% string_match on that. That will not match a quote at the beginning,
% so we just string_match twice.
!if (string_match
(article,
"\\n>", 1)) return;
% Now split the article in an unquoted part, and a part with quotes
variable pos1, pos2;
(pos2, ) = string_match_nth(0);
pos1 = pos2;
variable part2 = substr(article, pos2+1, -1);
% If second part is all quoted, it's tofu
if (string_match(part2, "\\n[^>]", 1)) return;
% To find the attribution, check the article again, including the last
% non-empty line of the non-quoted part.
variable attribution = "";
if (string_match(article, "\\(\n+[^\n]+\n*\\)\\n>", 1))
{
attribution = string_nth_match(article, 1);
if (orelse
{ is_substr(attribution, "@")}
{ attribution[-1] == ':'})
(pos1, ) = string_match_nth(1);
else attribution = "";
}
variable part1 = substr(article, 1, pos1);
article = strcat(attribution, part2, part1);
}
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: processed by gpg.sl <http://jedmodes.sf.net>
iEYEARECAAYFAj/qGwMACgkQ1RTqFUe7bzOAJQCfWkvHxuJWR0AnO8sKAB0Zw9p+
3CUAmgMm64Y13vS8ZUj8j60nJU0QEEmB
=LUXc
-----END PGP SIGNATURE-----
Technical Details
Message-ID:
<bsd6ak$42s$1@reader08.wxs.nl>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!internal1.nntp.ash.giganews.com!border2.nntp.ash.giganews.com!border1.nntp.ash.giganews.com!firehose2!nntp4!intern1.nntp.aus1.giganews.com!border3.nntp.aus1.giganews.com!nntp.giganews.com!newshosting.com!news-xfer2.atl.newshosting.com!217.73.144.44.MISMATCH!ecngs!feeder.ecngs.de!news.cambrium.nl!news.cambrium.nl!news.cambrium.nl!newsfeed.wxs.nl!textnews.wxs.nl!not-for-mailReferences:
<slrnbtv8su.e4o.usenet@pima.hostsharing.net> <slrnbu1mou.2j1.tststs@moonlight.tststs.ddns.org> <2003-12-18T19-33-21@guckes.net> <slrnbu6kmt.1cg.tststs@moonlight.tststs.ddns.org> <bs1is8$5ga$1@reader10.wxs.nl> <slrnbu9n9s.2hu.jbn@forestfield.org> <bs410m$qqt$1@reader11.wxs.nl> <slrnbucuqm.a6d.jbn@forestfield.org> <bs6ck7$l3e$1@reader10.wxs.nl> <slrnbuet82.bg4.jbn@forestfield.org> <bs9cni$oi3$1@reader10.wxs.nl> <2003-12-24T07-30-39@guckes.net> <bsbogt$hag$1@reader10.wxs.nl> <2003-12-24T10-54-38@guckes.net>Show Full Headers
Complete Article Headers
Message-ID: <bsd6ak$42s$1@reader08.wxs.nl> Subject: Re: [slrn] fixing tofu for display Date: Wed, 24 Dec 2003 23:09:08 +0000 From: Paul Boekholt <p.boekholt@hetnet.nl> References: <slrnbtv8su.e4o.usenet@pima.hostsharing.net> <slrnbu1mou.2j1.tststs@moonlight.tststs.ddns.org> <2003-12-18T19-33-21@guckes.net> <slrnbu6kmt.1cg.tststs@moonlight.tststs.ddns.org> <bs1is8$5ga$1@reader10.wxs.nl> <slrnbu9n9s.2hu.jbn@forestfield.org> <bs410m$qqt$1@reader11.wxs.nl> <slrnbucuqm.a6d.jbn@forestfield.org> <bs6ck7$l3e$1@reader10.wxs.nl> <slrnbuet82.bg4.jbn@forestfield.org> <bs9cni$oi3$1@reader10.wxs.nl> <2003-12-24T07-30-39@guckes.net> <bsbogt$hag$1@reader10.wxs.nl> <2003-12-24T10-54-38@guckes.net> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!internal1.nntp.ash.giganews.com!border2.nntp.ash.giganews.com!border1.nntp.ash.giganews.com!firehose2!nntp4!intern1.nntp.aus1.giganews.com!border3.nntp.aus1.giganews.com!nntp.giganews.com!newshosting.com!news-xfer2.atl.newshosting.com!217.73.144.44.MISMATCH!ecngs!feeder.ecngs.de!news.cambrium.nl!news.cambrium.nl!news.cambrium.nl!newsfeed.wxs.nl!textnews.wxs.nl!not-for-mail Newsgroups: news.software.readers Organization: Planet Internet Lines: 82 NNTP-Posting-Host: ipc3798d49.dial.hetnet.nl X-Trace: reader08.wxs.nl 1072307348 4188 195.121.141.73 (24 Dec 2003 23:09:08 GMT) X-Complaints-To: abuse@planet.nl NNTP-Posting-Date: 24 Dec 2003 23:09:08 GMT User-Agent: JED 0.99.16