procmail
[Top] [All Lists]

Re: Counting score program exit code and negation

1997-02-04 15:48:21
According to the procmail manual, I should be able to run
an external program and use the return code as a score
if I "negate" it. It gives no examples (that I can find).

I've tried:

:0 h c
* -15^0
* !? /usr/kmarsh/bin/countat
{

Look at the man page again (and really read it carefully), and then look
again the the above recipe.  You haven't assigned a weight value to the
program; as it stands, it's just a typical pattern statement -- a
successful return code (0) is a match, anything else is not match.  Sort
of like: 

* ^Subject: bob

It either matches, or it doesn't.  If you negate it, it's still behaving 
like a standard pattern match, excep the meaning of the exit code is 
reversed.

Looking through the man page:

Weighted program conditions
       If  the  program returns an exitcode of EXIT_SUCCESS (=0),
       then the total added score will be w.  If it  returns  any
       other exitcode (indicating failure), the total added score
       will be x.

To me, this says that given:

:0
* 1^-1 /usr/kmarsh/bin/countat

Then a successful return code will add '1' to the score, and an 
unsuccessful return code will add '-1' to the score.

       If the exitcode of the program is negated, then, the exit-
       code  will be considered as if it were a virtual number of
       matches.  Calculation of the added score then proceeds  as
       if  it  had been a normal regular expression with n=`exit-
       code' matches.

And this says that:

:0
* 1^2 ! /usr/kmarsh/bin/counat

Will evaluate like a standard weighted match, except that instead of 
n=<number of occurences of the match>, you have n=<return code of the 
program>.

     The first time the regular expression is found, it will  add
     w  to  the  score.  The second time it is found, w*x will be
     added.  The third time it is found,  w*x*x  will  be  added.
     The fourth time w*x*x*x will be added.  And so forth.

That is, if the return code of countat=1 (in the recipe above), then '1'
will be added to the score.  If countat returns 2, then 1 + (1*2) will be
added to the score.  If the return code is 3, then 1 + (1*2) + (1*2*2)
will be added to the score...and so forth. 

If you just want to add the number of @'s to the score, you use a weight of:

* 1^1 /path/countat

If counat find 5 @'s, and returns an exit code of 5, this results in:

1 + (1*1) + (1*1*1) + (1*1*1*1) + (1*1*1*1*1) = 5

So it adds 5 onto the score.

-- Lars

---
Lars Kellogg-Stedman * lars(_at_)bu(_dot_)edu * (617)353-8277
Office of Information Technology, Boston University