Version 1 of Super Code

Updated 2003-07-22 15:56:01

July 22, 2003 Rohan Pall (my birthday!)

Here is an example of Super Code, a dns caching proc on windows. It executes an external binary to do the lookups.

I'm going to clean this up so its useful, apart from an example of Super Code

  proc a>   {a args} {eval [list interp alias {} $a {}] $args}
  a>   a<   interp alias {}
  a>   a?   interp aliases
  a>   l    list
  a>   ^    uplevel
  a>   g>   uplevel #0
  a>   p    puts
  a>   pr   parray
  a>   s    set
  a>   s-   unset
  a>   s(   array set
  a>   kz   array names
  a>   li   lindex
  a>   la   lappend
  a>   pk   proc
  a>   >>   eval
  a>   ()   catch
  a>   ?    s errorInfo
  a>   -*-  return
  a>   r    return
  a>   i    info
  a>   iv   i vars
  a>   il   i level
  a>   i-   il 0
  a>   exe  i nameofexe
  a>   sc   i script
  a>   ,    after
  a>   f    foreach
  a>   fi   file
  a>   dn   file dirname
  a>   fj   file join
  a>   re   regexp
  a>   mp   string map
  a>   ma   string match
  a>   c:   clock
  a>   c:s  c: seconds
  a>   c:c  c: clicks
  a>   t    trace
  a>   t.   t variable
  a>   t-   t vdelete
  a>   se   string equal
  a>   =    expr
  pk   ev   {t b} {g> $b ; , $t [i-]}
  pk   g>>  args {s b >> ; f el $args {la b $el} ; g> $b}

  #----

  s dir [dn [exe]]
  s e(resolver) [fj $dir resolver.exe]
  s( h {}
  a> ph pr h ; a> pe pr e ; a> pi iv ::_qip_*

  pk qip {h t b} {
  if {![() {li $::h($h) 1} ip]} {g>> $b $ip ; -*-}
  s a ::_qip_ ; s z _[c:s]_[c:c] ; f el {vs vo} {s $el $a$el$z}
  t. $vo w [l qip.t $h $b] ; , ${t}000 [l s $vo ""]
  blt::bgexec $vs -output $vo $::e(resolver) $h & ; -*-}

  pk qip.t {h b n1 _n2 _op} {
  t- $n1 w [l qip.t $h $b] ; s ip [s $n1]
  if {[se "0.0.0.0" $ip] || [se "" $ip]} {g>> $b error ; -*-}
  s ::h($h) [l [c:s] $ip] ; g>> $b $ip}

  #pk x {a b c} {p [^ iv] ; p $a ; p $b ; p $c ; p --}
  #qip fr 1 {x 1 2}

  pk qip- {} {s life 180 ; s c [c:s] ; f el [kz ::h] {
  s x [li $::h($el) 0] ; s e [= $c-$x]
  if {$e > $life} {s- ::h($el)} }}

  ev 5000 qip-

  pk qip-- {} {s n [c:s] ; f vs [iv ::_qip_vs_*] {
  if {[re {vs_(\d+)} $vs -> c]
  && ([s e [= $n-$c]] > 60)
  && [ma EXITED* [s $vs]]} {
    s vo [mp {vs vo} $vs] ; () {s- $vs $vo} }}}

  ev 5000 qip--