X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.web-live.git;a=blobdiff_plain;f=pctb%2Fshow-thing.tcl;h=c04d4ddf21b897e56d323e0c1ac17d40a14f8ea3;hp=440f9c6a13a0cc88b994e7bbfd7f76defb9d9dff;hb=6a62bf40d383872f274943b2fd062593b51e08a6;hpb=8787ee59f6840de63bac432b516a30d0dfe22c84 diff --git a/pctb/show-thing.tcl b/pctb/show-thing.tcl index 440f9c6..c04d4dd 100755 --- a/pctb/show-thing.tcl +++ b/pctb/show-thing.tcl @@ -26,6 +26,10 @@ set gotsh 20 set csrh 20 set ctxh 20 +proc debug {m} { + puts stderr "SHOW-THING $m" +} + proc init_widgets {} { # idempotent global csrh gotsh ctxh @@ -69,8 +73,8 @@ proc show_context {maxhv x ctxs} { upvar 1 $maxhv maxh set w .d.ctx.at$x if {[llength $ctxs]==1} { set fg blue } { set fg yellow } - label $w -bg black -fg $fg -text [join $ctxs "/\n "] - place $w -x [expr {$x*$mul}] -y 0 + label $w -bg black -fg $fg -text [join $ctxs "/\n"] -justify left + place $w -x [expr {($x-1)*$mul}] -y 0 set wh [winfo reqheight $w] if {$wh > $maxh} { set maxh $wh } } @@ -90,8 +94,8 @@ proc resize_widgets {} { eval destroy [winfo children .d.ctx] set maxh 0 - foreach {min max context got} $glyphsdone { - show_context maxh $min [list $context] + foreach {min max contexts got} $glyphsdone { + show_context maxh $min $contexts } show_context maxh $unk_l $unk_contexts .d.ctx configure -height $maxh @@ -115,8 +119,28 @@ proc read_xpm {f} { } if {$y==-3} { manyset $l cols rows colours cpp - #assert {$colours==2} - #assert {$cpp==1} + if {$colours!=2 || $cpp!=1} { error "$l ?" } + + set chop_l [expr {$unk_l - 80}] + set chop_r [expr {$cols - $unk_l - 100}] + if {$chop_l<0} { set chop_l 0 } + + set unk_l [expr {$unk_l - $chop_l}] + set unk_r [expr {$unk_r - $chop_l}] + set ngd {} + foreach {min max contexts got} $glyphsdone { + lappend ngd \ + [expr {$min-$chop_l}] \ + [expr {$max-$chop_l}] \ + $contexts $got + } + set glyphsdone $ngd + + set realcols $cols + set cols [expr {$cols - $chop_l - $chop_r}] + debug "NOW cols=$cols chop_l,r=$chop_l,$chop_r rows=$rows\ + $unk_l $unk_r $ngd" + set mulcols [expr {$cols*$mul+$inter}] set mulrows [expr {$rows*$mul+$inter}] append o "\"$mulcols $mulrows 9 1\",\n" @@ -138,13 +162,19 @@ proc read_xpm {f} { set x 0 set ol "\"+" set olh $ol + if {$chop_r>=0} { + set l [string range $l $chop_l end-$chop_r] + } else { + set l [string range $l $chop_l end] + append l [string repeat " " [expr -$chop_r]] + } foreach c [split $l ""] { set how "u" if {$x >= $unk_l && $x <= $unk_r} { set how q } else { set ab 0 - foreach {min max context got} $glyphsdone { + foreach {min max contexts got} $glyphsdone { set rhsmost_max $max if {$x >= $min && $x <= $max} { set how [lindex {a b} $ab] @@ -186,7 +216,7 @@ proc read_xpm {f} { proc draw_glyphsdone {} { global glyphsdone mul inter eval destroy [winfo children .d.got] - foreach {min max context got} $glyphsdone { + foreach {min max contexts got} $glyphsdone { frame .d.got.m$min -bd 0 -background \#888 label .d.got.m$min.l -text "$got" -fg white -bg black -bd 0 pack .d.got.m$min.l -padx 1 -pady 1 @@ -243,6 +273,7 @@ proc recursor//01 {z1} { } bind_key Return { if {$cur_0 != $cur_1} { + .d.csr.csr.e delete 0 end set cur_mode text recursor } @@ -272,7 +303,6 @@ proc recursor/text {} { bind_key Return { set strq [.d.csr.csr.e get] if {[regexp {^(?:[!-[]|[]-~]|\\\\|\\x[0-9a-f]{2})+} $strq]} { - .d.csr.csr.e delete 0 end RETURN_RESULT DEFINE "$cur_0 $cur_1 $strq" } } @@ -361,6 +391,7 @@ proc read_database {} { global database database_header rows database_fn catch { unset database } set database_fn ./charset-$rows.txt + if {![file exists $database_fn]} return set f [open $database_fn r] if {[string compare [db_getsl $f] $database_header]} { error "$l ?" } if {([db_getsl $f])+0 != $rows} { error "wrong h ?" } @@ -397,6 +428,7 @@ proc write_database {} { foreach o [lsort $ol] { puts $f $o } + puts $f "." close $f file rename -force $database_fn.new $database_fn } @@ -416,8 +448,8 @@ proc update_database/DEFINE {c0 c1 strq} { if {$c0 == $unk_l} { set ncontexts $unk_contexts } else { - foreach {l r context got} $glyphsdone { - if {$l==$c0} { set ncontexts [list $context]; break } + foreach {l r contexts got} $glyphsdone { + if {$l==$c0} { set ncontexts $contexts; break } } if {![info exists ncontexts]} { puts stderr "must start at letter LHS!" @@ -432,10 +464,12 @@ proc update_database/DEFINE {c0 c1 strq} { write_database } -proc update_database/DELETE {l r ctx} { +proc update_database/DELETE {l r ctxs} { global database - set bm [dbkey $ctx $l $r] - unset database($bm) + foreach ctx $ctxs { + set bm [dbkey $ctx $l $r] + catch { unset database($bm) } + } write_database } @@ -447,7 +481,7 @@ proc RETURN_RESULT {how what} { helptext {{{ Processing }}} unbind_all_keys update idletasks - puts stderr "$how $what" + debug "$how $what" eval update_database/$how $what done/$mainkind } @@ -488,7 +522,7 @@ proc required {} { init_widgets manyset [lrange $l 0 3] unk_l unk_r unk_contexts set glyphsdone [lrange $l 3 end] - puts stderr "SHOW-THING GOT $l" + debug "GOT $l" fileevent stdin readable {}