procmail
[Top] [All Lists]

Re: Figuring out which rc file to read (was Re: Thanks!)

1997-08-14 16:34:00
Ah, awk, one of my favorite subjects.

At 08:52 AM 8/14/97 +0300, era eriksson wrote:

[...]

 So here's something that might work better:

RCFILE=

:0hi  # Header words to match
RCFILE=| gawk '/word1|word2/ { print "rcfile.one" ; exit }
              /word3|word4/ { print "rc.two"     ; exit }'

:0bi # Else match in body
* ! RCFILE ?? .
RCFILE=| gawk '/str1|string two/  { print "rc.three" ; exit }
             /long phrase three/ { print "rc.4four" ; exit }'

:0   # If there is an RCFILE for some reason, source it
* RCFILE ?? .
{ INCLUDERC="$RCFILE" }

You should be able to combine those two gawk runs into one to
avoid running it twice...something like (completely untested):

:0hbi
RCFILE=| gawk 'NF==0 {x=1; next}
       x==0 && /word1|word2/ { print "rcfile.one" ; exit }
       x==0 && /word3|word4/ { print "rc.two"     ; exit }
       x==1 && /str1|string two/  { print "rc.three" ; exit }
       x==1 && /long phrase three/ { print "rc.4four" ; exit }'

The awk is not very polished, but it does more sensible things than
the join thing, at least.

Mine isn't very polished either... I can't remember whether a blank
line including a non-zero amount of only white space is allowed in
the headers.  If it is, then change my 'NF==0' test to either '/^$/'
or 'length($0)==0' to detect the end of the headers.

Perhaps you should take this, too, with a grain of salt ...
 Still, hope this helps,

/* era */

Seems the :E flag doesn't look at awk's exit code here?

If you want a non-zero exit code from *awk if nothing matched, then
you must set it using another pattern/action:
        END { exit(1) }
otherwise it just returns 0.

Cheers,
Stan

<Prev in Thread] Current Thread [Next in Thread>
  • Re: Figuring out which rc file to read (was Re: Thanks!), Stan Ryckman <=