[ Usenet FAQs | Search | Web FAQs | Documents | RFC Index ]
    Search the FAQ Archives

Part1 - Part2 - Single Page

Top Document: [news.software.readers] trn newsreader FAQ, part 1: Basics
Previous Document: USPW: How can I select articles which contain a particular word in the body?
Next Document: USNA: How can I see only the new articles in trn?


USSP: How to select based on my script that processes an article?


        Wayne Davison <trn@clari.net>

> Trn has the ability within the KILL file to indicate that an article
> matching a regular expression should be piped into a program.
>
> What I would like is for the _return code_ of the program on the end
> of the pipe to determine whether an article was marked as selected,
> junked or left alone. What I want to do is be able to say things like:
>
> /nonsense/:|mycheck
>
> and then have mycheck be something like:
>
> #! /bin/sh
> grep -s 'morestuff' >> /dev/null
> return $?
>
> so that now I can do operations on the news article, and have the return
> code determine whether the item deserves to be selected or not.

Here's something that should help you out:

	/subject search/:%(%`fgrep -c trn %A`=^0?-:+)

This works quite well on a local trn since %A points to the real article
even when you are doing subject searches.  The command portion uses the
if-then-else operator -- %( = ? : ) -- to run a program via the execute
operator -- %`cmd` -- and compare the output to 0 (it's a regex compare,
so make sure to anchor it via '^').  Based on the result of this it either
deselects or selects the article (-/+).  Substitute a shell script for
the fgrep and have it echo 0 or 1 and you're all set.

If you are using an NNTP version, %A may not have the correct article
text in it (trn only fetches one article at a time).  This seems to be
a bug in the %A expansion (which should force the article to be fetched
when you reference it -- it's fixed in version 3.6), so with older
versions you'll have to force trn to fetch each article before it runs
the command by using something like this with the 'a' modifier on the
search:

	/^[^A-Z]./ca:%(%`fgrep -c trn %A`=^0?-:+)

The search portion of this is an attempt to match past the header, since
trn doesn't bother to read the whole article until it fails to match the
header portion.  In version 3.6 you don't have to jump through this hoop
to get this to work.



Top Document: [news.software.readers] trn newsreader FAQ, part 1: Basics
Previous Document: USPW: How can I select articles which contain a particular word in the body?
Next Document: USNA: How can I see only the new articles in trn?

Part1 - Part2 - Single Page


[ Usenet FAQs | Search | Web FAQs | Documents | RFC Index ]

Send corrections/additions to the FAQ Maintainer:
@tigerden.com (Peter J. Kappesser)

Last Update October 12 2008 @ 00:13 AM

© 2008 FAQS.ORG. All rights reserved.