procmail
[Top] [All Lists]

(A&B)|(C&D)

1997-09-01 23:19:05
Philip Guenther came up with a way to code (A & B) | (C & D) within procmail
without listing the action twice [it needed the tiniest tweak from me, but he
gets at least 98% of the credit].  I'm doing this from memory, though:

  :0
  * 1400000000^0
  *  400000000^0 A
  *  400000000^0 B
# If A & B, then the score is 2.2e9, which is greater than procmailsc's
# allowed maximum, so all remaining weighted conditions are skipped and
# deemed satisfied, and we head straight for the action.
# If A & ~B or if ~A & B, the score is 1.8e9; if ~A & ~B, the score is 1.4e9.
# Either way, we continue.  We next have to subtract more than procmailsc's
# maximum number, so we do it in two steps:
  * -1400000000^0
  * -1400000000^0
# Now, unless both A and B were satisfied and this part is getting skipped,
# the score is -1e9 or -1.4e9.
  *  800000000^0 C
  *  800000000^0 D
# If ~(A&B) & C & ~D or if ~(A&B) & ~C & D, we're still below zero, but
# if ~(A&B) & C & D, we're in positive territory (6e8 or 2e8).
  action

Yup, pretty tangled, but an interesting curiosity.  Other combinations of
weights will also work with the same logic:

 :0
 * 2147483645^0
 * 1^0 A
 * 1^0 B
# If A&B, we've hit the maximum and procmail skips down to the action.
# Otherwise, continue with the conditions:
 * -2147483646^0
 * -2^0
# The score is now -2 or -3.
 * 2^0 C
 * 2^0 D
 action

<Prev in Thread] Current Thread [Next in Thread>
  • (A&B)|(C&D), David W. Tamkin <=