Folks,
I've put together a little function-box INCLUDERC tool in procmail
and decided to publish it. It can take an integer as input (stated
in a var) and return that number of dots, up to 99 inclusive.
This is not hard to do with recursion. However, I didn't want to
have an rcfile that calls itself, e.g., 77 times to create 78 dots!
So I have it call itself, at most, only once. It processes any
10's column it finds in the number (i.e., the first number of a
two-digit number), and then it processes the 1's column.
"What's the point?" you might be thinking. Well, for example,
suppose we want to look for NN number of chars on a line in the
body. Suppose we want the user to be able to state his wish for
NN as a number. Voila!
Me, I use it already to format text strings in the manner of the
Unix program "par" right in procmail. E.g., I have a log-string
parser that sets a right margin via these dots.
One could do what this file does by storing env vars in a lib file.
E.g., _16 = ................
and so on. But that takes up env space even when it's not used.
This only takes the env space on an as-needed basis.
The file is called func.nndots, and is currently viewable at
<http://vsnag.spamless.us/download/toolkit/>. But I'll also publish it
below.
The "function" tool will work on decimal numbers as well, ignoring
all but the integer portion. It can do a small bit of other sanity
testing, also: bad input normally is ignored. Longer numbers are
truncated to the first two digits.
Here is the current version:
====================== start includerc ======================
_SELF = $_ # func.nndots, ver. 1.0.061215.0
##############################################################################
# _inout should be a counting number < 100; output will express number as dots
# Copyright 12/2006 by Dallman Ross; vsnag.spamless.us; free use; no liability
##############################################################################
_func = ${_inout}
:0
* $ _func ?? ()${_10s+.}\/.
{ _func = $MATCH......... }
:0
* ! _func ?? 9\/.........
* ! _func ?? 8\/........
* ! _func ?? 7\/.......
* ! _func ?? 6\/......
* ! _func ?? 5\/.....
* ! _func ?? 4\/....
* ! _func ?? 3\/...
* ! _func ?? 2\/..
* ! _func ?? 1\/.
{ MATCH } # "success" = either zero or bad input
:0 E
* $! SWITCHRC ?? ^^$_^^
* $ ${_inout} ^0
* -9 ^0
{
_10s = $MATCH$MATCH$MATCH$MATCH$MATCH$MATCH$MATCH$MATCH$MATCH$MATCH
SWITCHRC = $_ # loop just once
} _inout = ${_10s}$MATCH _10s
======================= end includerc =======================
Okay, I've appended some sample output:
======================= start testing =======================
$ 2>&1 < /dev/null procmail -m DEFAULT=/dev/null VERBOSE=y _inout=3
func.nndots|
grep _inout
procmail: Assigning "_inout=3"
procmail: Assigning "_inout=..."
$ 2>&1 < /dev/null procmail -m DEFAULT=/dev/null VERBOSE=y _inout=33
func.nndots|
grep _inout
procmail: Assigning "_inout=33"
procmail: Assigning "_inout=................................."
$ 2>&1 < /dev/null procmail -m DEFAULT=/dev/null VERBOSE=y _inout=41
func.nndots|
grep _inout
procmail: Assigning "_inout=41"
procmail: Assigning "_inout=........................................."
$ 2>&1 < /dev/null procmail -m DEFAULT=/dev/null VERBOSE=y _inout=''
func.nndots|
echo _inout
_inout
$ 2>&1 < /dev/null procmail -m DEFAULT=/dev/null VERBOSE=y \
_inout='bogus stuff' func.nndots|
grep _inout
procmail: Assigning "_inout=bogus stuff"
procmail: Assigning "_inout="
======================== end testing ========================
Dallman
____________________________________________________________
procmail mailing list Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail