{s n} { set c [csplit $s] if {$n > [expr [llength [lindex $c 0]]-1]} {set n [expr [llength [lindex $c 0]]-1]} set b 0 set u 0 set cf -1 set cb -1 set r "" foreach f [lindex $c 1] { if {[lindex $f 0] > $n} { if {$b eq 1} {append r "\002"} if {$u eq 1} {append r "\037"} if {$cf > -1} {append r [format "\002%s" $cf]} if {$cb > -1} {append r [format ",%s" $cb]} return $r } if {[lindex $f 1] eq "\002"} {set b [expr $b ^ 1]} if {[lindex $f 1] eq "\037"} {set u [expr $u ^ 1]} if {[lindex $f 1] eq "\003"} {set cf -1;set cb -1} if {[lindex $f 1] eq "\017"} {set cf -1;set cb -1;set b 0;set u 0} if {[lindex $f 1] eq "\026"} {set t $cb;set cb $cf;set cf $t} if {[set m [regexp -inline {([\d]+)$} [lindex $f 1]]] ne ""} {set cf [lindex $m 1]} if {[set m [regexp -inline {([\d]+),([\d]+)} [lindex $f 1]]] ne ""} {set cf [lindex $m 1];set cb [lindex $m 2]} } if {$b eq 1} {append r "\002"} if {$u eq 1} {append r "\037"} if {$cf > -1} {append r [format "\002%s" $cf]} if {$cb > -1} {append r [format ",%s" $cb]} return $r }