procmail
[Top] [All Lists]

dec2hex.rc

2006-07-01 16:32:47
Save as dec2hex.rc, chmod 700,
and run as

  dec2hex.rc  234  < /dev/null


===8<===8<===8<===8<===8<===8<===
#!/usr/local/bin/procmail -m

  DEFAULT = /dev/null
  VERBOSE = OFF

  MAXSC = 2147483647
  NL    = '
'
  :0  #  arg = 0 + $1
  *$ $1 ^ 0
  { } arg = $=

  _DOT    = '.'

  _BAS    = 16
  _STR    = 0123456789ABCDEF

  :0  #  fac = _BAS ^ 2
  *$ _DOT ?? 1 ^ 2 < ${_BAS}
  { } fac = $=

  :0  #  max = fac - 1
  *$ $fac ^ 0
  *    -1 ^ 0
  { } max = $=

  :0  #  die if arg > max
  *$ -$max ^ 0
  *$ +$arg ^ 0
  {
    LOG = "Error: '$arg' not allowed, maximum is $max.$NL"
    SWITCHRC
  }

  MATCH = '0'

  :0
  *$ _STR ?? ^\/[^$MATCH]*
  { tmp = $MATCH }
  :0
  *$ _DOT ?? $fac ^ 1 > ${_BAS}
  { } fac = $=
  :0
  *$ tmp ?? ${_BAS} ^ 1 > 1
  *$          -$arg ^ 0
  *              -1 ^ 0
  *$         $MAXSC ^ 0
  *$           $fac ^ 1 _STR ?? ()\/.
  { } ret = "$ret$MATCH"

  :0
  *$ _STR ?? ^\/[^$MATCH]*
  { tmp = $MATCH }
  :0
  *$ _DOT ?? $fac ^ 1 > ${_BAS}
  { } fac = $=
  :0
  *$ tmp ?? ${_BAS} ^ 1 > 1
  *$          -$arg ^ 0
  *              -1 ^ 0
  *$         $MAXSC ^ 0
  *$           $fac ^ 1 _STR ?? ()\/.
  { } ret = "$ret$MATCH"

  LOG = "0d$arg = 0x$ret$NL"




This uses again repeated code that could be isolated for a recursive
INCLUDERC.

-- 
Groet, Ruud


____________________________________________________________
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

<Prev in Thread] Current Thread [Next in Thread>
  • dec2hex.rc, Ruud H.G. van Tol <=