[xk2600] I have often utilized this wiki since around 2001, and have only recently felt like I've become comfortable enough with my skillset to contribute recently. Figured I would put together a landing page for common little pieces of code I utilize or feel is novel in some form or another. All code contributed below is free to use without restriction, as long as when it is used it is understood that the individual, company, or any party associated with the use of said code takes complete responsibility, and all liability of the result of the execution of said code, including the complete destruction of all things. The contributor takes absolutely no liability from the results aforementioned. '''''Error Handling snippets''''' ---- '''pflags''' ====== # pflags -- # returns a string with a consise representation of flags stored as an integer up to system # bit width. Note output only produces response for flags set. (value=1) # proc pflags {label flags flagDefinition} { array set flagArray $flagDefinition set result {} set LF "\n" # determine appropriate indention set indent [string repeat { } [expr {[string length $label]}]] # enforces 8 bit boundry set bitwidth [string length [format {%b} $flags]] set bitwidth [expr { (($bitwidth - 1) / 8 + 1) * 8 }] set bits [format "%0${bitwidth}b" $flags] set result [format { %s: %s (%d)%s} $label $bits $flags $LF] set callouts [string map {0 { } 1 {T}} $bits] append result [format { %s %s %s} $indent $callouts $LF] set callouts [string map {{T} {|}} $callouts] set tail {+} foreach flag [lsort -increasing -integer [array names flagArray]] { set callouts [string range $callouts 0 end-1] set tail [format {%s-} $tail] if {($flags & $flag) > 0} { append result [format { %s %s%s %s %s} $indent $callouts $tail $flagArray($flag) $LF] } } return $result } % pflags errorCode 63 { 1 {error} 2 {reserved by tcl} 4 {reserved by tcl} 8 {failed to create interp} 16 {failed to cleanup interp} 32 {failed to load last state} } errorCode: 00111111 (63) TTTTTT |||||+- error ||||+-- reserved by tcl |||+--- reserved by tcl ||+---- failed to create interp |+----- failed to cleanup interp +------ failed to load last state % ====== <>Personal