arith

Perform arithmetic computations V8.10 and later

Beginning with V8.10, sendmail supports arithmetic computations in rule sets via a database-map type called arith. This form of database map is always present for your use, without the need for special compile-time macros. To illustrate one use for arith, consider this mini configuration file:

V10
Kmath arith
SCalculate
R $+ $+ $+      $@ $(math $2 $@ $1 $@ $3 $: EXCEPTION $)

The K configuration command declares that a database map named math will be of the database-map type arith. To use this database map we declare a rule set. We call that rule set Calculate so that rule-set testing will be mnemonically clear.

The rule is the crux of how this math database map is used:

R $+ $+ $+      $@ $(math $2 $@ $1 $@ $3 $: EXCEPTION $)
                          ↑     ↑     ↑
                      operator  lvalue   rvalue

The arith database-type database maps (such as math here) take three arguments. The first, in the position of the key that would otherwise be used for lookups, is the arithmetic operator. The legal operators, as of V8.12, are shown in Table 23-5.

Table 23-5. Operators for the arith database-map type

Operator

Description

[a]

+

Addition: add lvalue to rvalue

Subtraction: subtract rvalue from lvalue

*

Multiplication: multiply lvalue by rvalue

/

Division: divide lvalue by rvalue

l

Less-Than: if lvalue is less than rvalue return literal TRUE, otherwise literal FALSE

=

Equality: if lvalue is equal to rvalue return literal TRUE, otherwise literal FALSE

|

The bitwise OR operation (V8.12 ...

Get sendmail, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.