procmail
[Top] [All Lists]

Counting score program exit code and negation

1997-02-04 13:44:10
Hi,

I'd like to count the '@' signs in the header fields, and use
the results in a score. I've asked this question before, and
appreciate the help, but previous responses posted here can't do
this with internal egrep, they only count the number of LINES
with '@' in them, which is not enough.

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
{
...

and

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

(For the C challenged, I offer everyone the source to countat
at the bottom. I prefer C for little stuff like this because
of speed and size vs. PERL.)

The procmailsc manual says this:

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.
 
       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.




In reading this, I guess I could rewrite countat to return 0
and take an arg on the number desired. Still, I'd like an answer
to this question, as there are other rules and tools I'd
like to use this setup with.



Source to countat:
________________________________________________________________
/*
 * Countat
 *      Counts the number of '@' symbols in std input
 *
 *
 * KBM 2/4/97
 *
 */  



#include <stdio.h>

main(int argc, char **argv)
{
        int count=0, c;

        while((c=getchar()) != EOF)
            if ( c == '@')
                count++;

        if (count > 255) count = 255;

        exit (count);

}

________________________________________________________________


Ken.

-------------------------------------------------------------------------
Mail: kmarsh(_at_)charm(_dot_)net             | Edit a binary .INI file, then 
tell
WWW:  http://www.charm.net/~kmarsh | me that UNIX is too complicated.
-------------------------------------------------------------------------