Script '''bracelevel.tcl''': # prefix the current brace level on each line -[jcw] # I guess the reason for this script is to help in finding missing braces [AK]. proc bracelevel {str} { set lev 0 set out "" foreach l [split $str \n] { append out $lev \t foreach c [split $l ""] { append out $c switch -- $c \{ { incr lev } \} { incr lev -1 } } append out \n } return $out } puts [bracelevel [read stdin]] ---- Output of '''running bracelevel.tcl with itself as input''': 0 # prefix the current brace level on each line -[jcw] 0 0 proc bracelevel {str} { 1 set lev 0 1 set out "" 1 foreach l [split $str \n] { 2 append out $lev \t 2 foreach c [split $l ""] { 3 append out $c 3 switch -- $c \{ { incr lev } \} { incr lev -1 } 3 } 2 append out \n 2 } 1 return $out 1 } 0 0 puts [bracelevel [read stdin]] 0