4 # run show-thing without args
6 # one line which is a Tcl list for foolist
7 # the xpm in the format expected
8 # then expect child to raise SIGSTOP or exit 0 or exit nonzero
9 # if child raised SIGSTOP, check database was updated
11 proc manyset {list args} {
12 foreach val $list var $args {
25 global foolist mul inter rhsmost_max unk_l unk_r gotsh csrh
26 global cols rows wordmap
31 if {[gets $f l] < 0} { error "huh? "}
32 if {![regexp {^"(.*)",$} $l dummy l]} {
34 if {[regexp {^\}\;$} $l]} break
38 manyset $l cols rows colours cpp
41 set mulcols [expr {$cols*$mul+$inter}]
42 set mulrows [expr {$rows*$mul+$inter}]
43 append o "\"$mulcols $mulrows 9 1\",\n"
44 for {set x 0} {$x<$cols} {incr x} { set wordmap($x) 0 }
45 } elseif {$y==-2} { # first pixel
56 } elseif {$y==-1} { # 2nd pixel but we've already printed ours
58 set ybit [expr {1<<$y}]
62 foreach c [split $l ""] {
64 if {$x >= $unk_l && $x <= $unk_r} {
68 foreach {min max context got} $foolist {
70 if {$x >= $min && $x <= $max} {
71 set how [lindex {a b} $ab]
80 set p [string toupper $how]
81 incr wordmap($x) $ybit
83 default { error "$c ?" }
85 append ol "[string repeat $p [expr {$mul-$inter}]][
86 string repeat + $inter]"
87 append olh [string repeat + $mul]
93 set olhn [string repeat $olh $inter]
94 if {!$y} { append o $olhn }
95 append o [string repeat $ol [expr {$mul-1}]]
100 set data [exec xpmtoppm << $o]
101 image create photo main_image -data $data
103 foreach w {.d .d.csr .d.got} {
104 $w configure -width $mulcols
106 .d configure -height [expr {$csrh+$mulrows+$gotsh}]
108 .d.csr_$w configure -height $mulrows
110 place .d.got -x 0 -y [expr {$csrh+$mulrows}]
118 image create bitmap main_image
119 label .d.mi -image $mi -borderwidth 0
121 frame .d.csr -bg black -height $csrh
122 frame .d.got -bg black -height $gotsh
124 proc draw_foolist {} {
125 global foolist mul inter
126 eval destroy [winfo children .d.got]
127 foreach {min max context got} $foolist {
128 frame .d.got.m$min -bd 0 -background \#888
129 label .d.got.m$min.l -text "$got" -fg white -bg black -bd 0
130 pack .d.got.m$min.l -padx 1 -pady 1
131 place .d.got.m$min -x [expr {$min*$mul+$inter}] -y 0
135 set imcsr [image create bitmap -data \
136 {#define csr_width 11
137 #define csr_height 11
138 static unsigned char csr_bits[] = {
139 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x21, 0x04, 0x22, 0x02, 0x25, 0x05,
140 0xaa, 0x02, 0x74, 0x01, 0xa8, 0x00, 0x70, 0x00, 0x20, 0x00};
144 label .d.csr.csr.l -image $imcsr -compound left
145 entry .d.csr.csr.e -bd 0
146 pack .d.csr.csr.l -side left
148 frame .d.csr_0 -bg white -width 1
149 frame .d.csr_1 -bg white -width 1
151 place .d.csr -x 0 -y 0
152 place .d.mi -x 0 -y $csrh
158 proc startup_cursor {} {
159 global cur_already cur_mode cur_0 cur_1 last_ht
160 global foolist unk_l unk_r
162 set cur_already [expr {[llength $foolist]/4-1}]
163 set cur_mode 1 ;# one of: 0 1 already text
166 set cur_1 [expr {$unk_r+1}]
172 if {![string compare $t $last_ht]} return
173 eval destroy [grid slaves .help]
174 set y 0; foreach l $t {
175 set x 0; foreach c $l {
176 set w .help.at${x}x${y}
178 grid $w -row $y -column $x -padx 5
186 proc recursor/0 {} { recursor//01 0 }
187 proc recursor/1 {} { recursor//01 1 }
188 proc recursor//01 {z1} {
189 global mul rhsmost_max cols foolist
191 .d.csr.csr.l configure -text {adjust}
192 place .d.csr.csr -x [expr {$cur*$mul - 7}]
193 bind_key space { othercursor }
194 bind_leftright cur_$z1 0 [expr {$cols-1}]
195 if {[llength $foolist]} {
196 bind_key Tab { set cur_mode already; recursor }
201 if {$cur_0 != $cur_1} {
207 {{<- ->} {move cursor, adjusting area to define}}
208 {Space {switch to moving other cursor}}
209 {Return {confirm location, enter letter(s)}}
210 {Tab {switch to correcting earlier ocr}}
213 proc othercursor {} {
215 set cur_mode [expr {!$cur_mode}]
219 proc recursor/text {} {
221 {Return {confirm entry of new glyph}}
222 {Escape {abandon entry}}
225 .d.csr.csr.l configure -text {define:}
226 pack .d.csr.csr.e -side left
229 binary scan [.d.csr.csr.e get] h* hex
230 if {[string length $hex]} {
231 RETURN_RESULT DEFINE "$cur_0 $cur_1 $hex"
236 pack forget .d.csr.csr.e
242 proc recursor/already {} {
245 global cur_already mul
246 global foolist cur_already mul
247 .d.csr.csr.l configure -text {correct}
248 set rmax [lindex $foolist [expr {$cur_already*4}]]
249 place .d.csr.csr -x [expr {$rmax*$mul-3}]
252 bind_leftright cur_already 0 [expr {[llength $foolist]/4-1}]
253 bind_key Tab { bind_key Delete {}; set cur_mode 1; recursor }
255 RETURN_RESULT DELETE [lrange $foolist \
256 [expr $cur_already*4] \
257 [expr $cur_already*4+1]]
260 {{<- ->} {move cursor, selecting glyph to correct}}
261 {Del {clear this glyph from the recognition database}}
262 {Tab {switch to selecting area to define as new glyph}}
266 proc bind_key {k proc} {
268 bind . <Key-$k> $proc
269 set keybindings($k) [expr {!![string length $proc]}]
271 proc unbind_all_keys {} {
273 foreach k [array names keybindings] { bind_key $k {} }
276 proc bind_leftright {var min max} {
277 bind_key Left [list leftright $var $min $max -1]
278 bind_key Right [list leftright $var $min $max +1]
280 proc leftright {var min max inc} {
284 if {$vnew < $min || $vnew > $max} return
290 global csrh cur_mode cur_0 cur_1 mul
292 place .d.csr_$z1 -y $csrh -x [expr {[set cur_$z1] * $mul}]
300 # <context> <ncharacters> <hex>...
304 # $database($context 0x<bits> 0x<bits>...) = $hex
306 proc read_database {} {
308 set f [open database r]
309 while {[gets $f l] >= 0} {
310 if {![regexp {^(\w+) (\d+) ((?:[0-9a-f]{2})+)$} $l \
311 dummy context strl strh]} {
314 if {[string length $strh] != $strl*2} { error "$strh $strl" }
315 gets $f l; set width [format %d $l]
317 for {set x 0} {$x < $width} {incr x} {
318 gets $f l; lappend bm [format %x 0x$l]
320 set database($bm) $strh
325 proc write_database {} {
328 foreach bm [array names database] {
329 set strh $database($bm)
330 set strs [binary format h* $strh]
331 set strdo [format "%d %s" [expr {[string length $strh]/2}] $strh]
332 set o "[lindex $bm 0] $strdo\n"
333 append o [format "%d\n" [expr {[llength $bm]-1}]]
334 foreach x [lrange $bm 1 end] { append o "$x\n" }
337 set f [open database.new w]
338 foreach o [lsort $ol] {
339 puts -nonewline $f $o
342 file rename -force database.new database
345 proc update_database/DEFINE {c0 c1 strh} {
346 global foolist unk_l unk_context wordmap database
347 if {$c0 > $c1} { manyset [list $c0 $c1] c1 c0 }
349 set ncontext $unk_context
351 foreach {l r context got} $foolist {
352 if {$l==$c0} { set ncontext $context; break }
354 if {![exists ncontext]} {
355 puts stderr "must start at letter LHS!"
360 for {set x $c0} {$x < $c1} {incr x} {
361 lappend bm [format %x $wordmap($x)]
363 set database($bm) $strh
368 proc RETURN_RESULT {how what} {
369 place forget .d.csr.csr
370 pack forget .d.csr.csr.e
371 helptext {{{ Processing }}}
375 eval update_database/$how $what
378 # bind . <Key-space> {}
381 global foolist unk_l unk_r unk_context
392 set f [open text.xpm]