For a number of weeks, the following comment from my "spamcheck" has
been bothering me
# needs to be set for INCLUDERC. Is there a way to get it from $_ ?
SPAMCHECK_RCDIR=${SPAMCHECK_RCDIR:-$RCDIR/spamcheck}
that is I want to do
this_rcfile=$_
SPAMCHECK_RCDIR=`dirname $this_rcfile`
but without having to leave procmail. Well, today I figured out how
to do this by using a recursive INCLUDERC file. Here's dirname.rc
lastdirname=${lastdirname:-"/"}
dir_re="[^/]+"
regexp=${regexp:-"(^/)?$dir_re"}
:0
* $ PATHNAME ?? ()\/$regexp
{
lastdirname=$dirname
dirname=$MATCH
regexp=$regexp/$dir_re
INCLUDERC=$_
}
:E
{
DIRNAME=$lastdirname
lastdirname=
dirname=
regexp=
}
And a few simple test cases...
RCDIR=$HOME/.procmail
PATHNAME=/foo/bar/baz/foobar.baz
INCLUDERC=$RCDIR/dirname.rc
TMP=`dirname $PATHNAME`
LOG="$PATHNAME: $DIRNAME <-> $TMP
"
PATHNAME=/foo
INCLUDERC=$RCDIR/dirname.rc
TMP=`dirname $PATHNAME`
LOG="$PATHNAME: $DIRNAME <-> $TMP
"
PATHNAME=foo/bar/baz/foobar.baz
INCLUDERC=$RCDIR/dirname.rc
TMP=`dirname $PATHNAME`
LOG="$PATHNAME: $DIRNAME <-> $TMP
"
It seems like things such as this would be a lot easier of procmail
had a LIGHTER variable which would be set to the matching text before
the \/ token.
Dan
------------------- message is author's opinion only ------------------
J. Daniel Smith <DanS(_at_)bristol(_dot_)com>
http://www.bristol.com/~DanS
Bristol Technology B.V. +31 33 450 50 50, ...51 (FAX)
Amersfoort, The Netherlands {info,jobs}(_at_)bristol(_dot_)com