Another little script, coded back in October 2001 -[jcw] # a little server to inspect local variable state over httpd # # usage: # - source this script in some app # - do "hpeek start 8056" to activate it # - do "vwait forever" if the app would exit otherwise # - point your browser to URL http://localhost:8056/ # # inspired by Harold Kaplan's "DustMote" set auto_index(hpeek) { proc hpeek {cmd args} { module hpeek $cmd $args } } namespace eval hpeek { set about {a little server to inspect local variable state over httpd} set cvs {$Id: 9154,v 1.1 2003-06-22 08:00:40 jcw Exp $} namespace export start # start must be called to set up a server socket proc start {port} { if {$port} { variable fd [socket -server hpeek::accept $port] } } # accept a new incoming tcp/ip connection proc accept {sock h p} { fconfigure $sock -blocking 0 fileevent $sock readable [list hpeek::request $sock] } # process a single request proc request {sock} { catch { set line [gets $sock] if {[fblocked $sock]} return fileevent $sock readable "" fconfigure $sock -translation binary -buffering full set p / regexp {/[^ ]*} $line p regsub -all / $p :: p set r "HTTP/1.0 200 OK\n\n" if {[catch {display $p r} err]} { set r "HTTP/1.0 404 Not found\n\n

No such URL

\
$::errorInfo
" } puts $sock $r } catch {close $sock} } # make a string suitable for viewing as HTML proc htmlize {s} { regsub -all {&} $s {\&} s regsub -all {<} $s {\<} s regsub -all {>} $s {\>} s return $s } # htmlize, show in fixed font if text contains newlines proc showtext {s} { set s [htmlize $s] if {[string first "\n" $s] >= 0} { set s "
$s
" } return $s } # generate a page with the requested information proc display {x result} { upvar $result r append r "" set a "" } foreach k [lsort -dictionary [info vars $x*]] { append r $a [htmlize [namespace tail $k]] $b if {[array exists $k]} { set n [array size $k] append r "$n entries" } elseif {[info exists $k]} { set v [set $k] append r [showtext $v] } else { append r "?" } append r "" } } else { foreach k [lsort -dictionary [array names $x]] { append r $a [htmlize [namespace tail $k]] $b set v [set ${x}($k)] append r [showtext $v] "" } } append r "
" set b "  " if {[namespace tail $x] == ""} { set c [namespace children $x] if {[llength $c] > 0} { append r $a "Namespaces:" $b foreach y [lsort -dictionary $c] { set z [namespace tail $y] append r "$z " } append r "
" } }