procmail
[Top] [All Lists]

Re: Two variable assignments on one line?

1998-08-24 11:11:14
Not only can you place two (or more) variable assignments in a line,
you can treat many curly braces as you would new lines, and combine
lines as follows:

:0
*MODE??^^prod^^
{ LOGFILE=$LOGDIR/procmail.log IN=in STEST=no }:0E
{ MODE=test LOGFILE=$LOGDIR/test.procmail.log IN=test DEFAULT=$IN.inbox 
STEST=${stest:-${STEST:-no}} }:0
*!STEST??^^no^^
{ STEST=yes }MYDOM_RE="[^x]\.netcom\.com" VERBOSE=${wordy:-${WORDY:-off}} 
HERE=rik(_at_)netcom(_dot_)com FWD_MAIL=name2(_at_)xxxx(_dot_)com 
HOLDMETAS=$SHELLMETAS MAX_BANG=4 MAX_RECIP=9 REV="$Revision: 4.125 $"
:0
*REV?? \\/[0-9.]+
{ :0

My procmail rc generator (a hundred lines of perl) produces this type
of condensed code, along with a few other space optimizations, from
fully commented, more easily edited source. In this case, the nine
lines above come from the 37 lines below. I think it shows most, if not
all, of the possible space optimizations, although I'd be happy to
learn of more.

## Process command line arguments
##
  :0                          ## is
  * MODE ?? ^^prod^^          ##  the mode prod?
  { LOGFILE=$LOGDIR/procmail.log        ## if so, record actions here and
    IN=in                     ##  deliver mail to folders like in.abc
    STEST=no                  ##  not spamtest mode, either
  }                           ##
  :0 E                        ## otherwise
  { MODE=test                 ##  make it test mode
    LOGFILE=$LOGDIR/test.procmail.log   ## select a different log file
    IN=test                   ##  and deliver to
    DEFAULT=$IN.inbox         ##  different folders
    STEST=${stest:-${STEST:-no}}        ## does command line have STEST?
  }                           ##
  :0                          ## now,
  * ! STEST ?? ^^no^^         ## if this isn't not stest
  { STEST=yes }               ## it must be yes stest
##
## NOTE: \ in REs must be protected (\\) if not in hard or soft quotes
##
  MYDOM_RE="[^x]\.netcom\.com"          ## mid checking, exclude ix.netcom.com
  VERBOSE=${wordy:-${WORDY:-off}}       ## may be on command line
##
## These variables are personal! Change them to suit your addresses
##
  HERE=rik(_at_)netcom(_dot_)com         ## for loop and spam control
  FWD_MAIL=name2(_at_)xxxx(_dot_)com     ## forwarding any time to mail 
account, list ok
##
  HOLDMETAS=$SHELLMETAS       ## save for restoring value later
  MAX_BANG=4                  ## max exclamation points per message
  MAX_RECIP=9                 ## max recipients per message
  REV="$Revision: 4.125 $"    ## updated by rcs at checkin
  :0                          ## clean it up for use
  * REV ?? \\/[0-9.]+         ## by extracting 99.99...
  {                           ## and
    :0                        ## if

Why you would want to directly write condensed code like that
(including doubling assignments) is beyond me. Maintainability should
be paramount. I wrote the condenser as the first step in a now halted
attempt to create a combined tool for syntax checking and then either
obfuscating or pretty printing my procmail rc source.

-- 
Rik Kabel          Old enough to be an adult              
rik(_at_)netcom(_dot_)com

<Prev in Thread] Current Thread [Next in Thread>