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 {
37 if {[gets $f l] < 0} { error "huh? "}
38 if {![regexp {^"(.*)",$} $l dummy l]} {
40 if {[regexp {^\}\;$} $l]} break
44 manyset $l cols rows colours cpp
47 set mulcols [expr {$cols*$mul+$inter}]
48 set mulrows [expr {$rows*$mul+$inter}]
49 append o "\"$mulcols $mulrows 9 1\",\n"
50 for {set x 0} {$x<$cols} {incr x} { set wordmap($x) 0 }
51 } elseif {$y==-2} { # first pixel
62 } elseif {$y==-1} { # 2nd pixel but we've already printed ours
64 set ybit [expr {1<<$y}]
68 foreach c [split $l ""] {
70 if {$x >= $unk_l && $x <= $unk_r} {
74 foreach {min max context got} $foolist {
76 if {$x >= $min && $x <= $max} {
77 set how [lindex {a b} $ab]
86 set p [string toupper $how]
87 incr wordmap($x) $ybit
89 default { error "$c ?" }
91 append ol "[string repeat $p [expr {$mul-$inter}]][
92 string repeat + $inter]"
93 append olh [string repeat + $mul]
99 set olhn [string repeat $olh $inter]
100 if {!$y} { append o $olhn }
101 append o [string repeat $ol [expr {$mul-1}]]
109 set xpm [exec xpmtoppm << $o]
114 frame .d -width $mulcols -height [expr {$csrh+$mulrows+$gotsh}]
116 set mi [image create photo -data $xpm]
117 label .d.mi -image $mi -borderwidth 0
119 frame .d.csr -bg black -width $mulcols -height $csrh
120 frame .d.got -bg black -width $mulcols -height $gotsh
122 foreach {min max context got} $foolist {
123 frame .d.got.m$min -bd 0 -background \#888
124 label .d.got.m$min.l -text "$got" -fg white -bg black -bd 0
125 pack .d.got.m$min.l -padx 1 -pady 1
126 place .d.got.m$min -x [expr {$min*$mul+$inter}] -y 0
129 set imcsr [image create bitmap -data \
130 {#define csr_width 11
131 #define csr_height 11
132 static unsigned char csr_bits[] = {
133 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x21, 0x04, 0x22, 0x02, 0x25, 0x05,
134 0xaa, 0x02, 0x74, 0x01, 0xa8, 0x00, 0x70, 0x00, 0x20, 0x00};
138 label .d.csr.csr.l -image $imcsr -compound left
139 entry .d.csr.csr.e -bd 0
140 pack .d.csr.csr.l -side left
142 frame .d.csr_0 -bg white -height $mulrows -width 1
143 frame .d.csr_1 -bg white -height $mulrows -width 1
145 place .d.csr -x 0 -y 0
146 place .d.mi -x 0 -y $csrh
147 place .d.got -x 0 -y [expr {$csrh+$mulrows}]
153 set cur_already [expr {[llength $foolist]/4-1}]
154 set cur_mode 1 ;# one of: 0 1 already text
157 set cur_1 [expr {$unk_r+1}]
162 if {![string compare $t $last_ht]} return
163 eval destroy [grid slaves .help]
164 set y 0; foreach l $t {
165 set x 0; foreach c $l {
166 set w .help.at${x}x${y}
168 grid $w -row $y -column $x -padx 5
176 proc recursor/0 {} { recursor//01 0 }
177 proc recursor/1 {} { recursor//01 1 }
178 proc recursor//01 {z1} {
179 global mul rhsmost_max cols foolist
181 .d.csr.csr.l configure -text {adjust}
182 place .d.csr.csr -x [expr {$cur*$mul - 7}]
183 bind_key space { othercursor }
184 bind_leftright cur_$z1 0 [expr {$cols-1}]
185 if {[llength $foolist]} {
186 bind_key Tab { set cur_mode already; recursor }
191 if {$cur_0 != $cur_1} {
197 {{<- ->} {move cursor, adjusting area to define}}
198 {Space {switch to moving other cursor}}
199 {Return {confirm location, enter letter(s)}}
200 {Tab {switch to correcting earlier ocr}}
203 proc othercursor {} {
205 set cur_mode [expr {!$cur_mode}]
209 proc recursor/text {} {
211 {Return {confirm entry of new glyph}}
212 {Escape {abandon entry}}
215 .d.csr.csr.l configure -text {define:}
216 pack .d.csr.csr.e -side left
219 binary scan [.d.csr.csr.e get] h* hex
220 if {[string length $hex]} {
221 RETURN_RESULT DEFINE "$cur_0 $cur_1 $hex"
226 pack forget .d.csr.csr.e
232 proc recursor/already {} {
235 global cur_already mul
236 global foolist cur_already mul
237 .d.csr.csr.l configure -text {correct}
238 set rmax [lindex $foolist [expr {$cur_already*4}]]
239 place .d.csr.csr -x [expr {$rmax*$mul-3}]
242 bind_leftright cur_already 0 [expr {[llength $foolist]/4-1}]
243 bind_key Tab { bind_key Delete {}; set cur_mode 1; recursor }
245 RETURN_RESULT DELETE [lrange $foolist \
246 [expr $cur_already*4] \
247 [expr $cur_already*4+1]]
250 {{<- ->} {move cursor, selecting glyph to correct}}
251 {Del {clear this glyph from the recognition database}}
252 {Tab {switch to selecting area to define as new glyph}}
256 proc bind_key {k proc} {
258 bind . <Key-$k> $proc
259 set keybindings($k) [expr {!![string length $proc]}]
261 proc unbind_all_keys {} {
263 foreach k [array names keybindings] { bind_key $k {} }
266 proc bind_leftright {var min max} {
267 bind_key Left [list leftright $var $min $max -1]
268 bind_key Right [list leftright $var $min $max +1]
270 proc leftright {var min max inc} {
274 if {$vnew < $min || $vnew > $max} return
280 global csrh cur_mode cur_0 cur_1 mul
282 place .d.csr_$z1 -y $csrh -x [expr {[set cur_$z1] * $mul}]
290 # <context> <ncharacters> <hex>...
294 # $database($context 0x<bits> 0x<bits>...) = $hex
296 proc read_database {} {
298 set f [open database r]
299 while {[gets $f l] >= 0} {
300 if {![regexp {^(\w+) (\d+) ((?:[0-9a-f]{2})+)$} $l \
301 dummy context strl strh]} {
304 if {[string length $strh] != $strl*2} { error "$strh $strl" }
305 gets $f l; set width [format %d $l]
307 for {set x 0} {$x < $width} {incr x} {
308 gets $f l; lappend bm [format %x 0x$l]
310 set database($bm) $strh
315 proc write_database {} {
318 foreach bm [array names database] {
319 set strh $database($bm)
320 set strs [binary format h* $strh]
321 set strdo [format "%d %s" [expr {[string length $strh]/2}] $strh]
322 set o "[lindex $bm 0] $strdo\n"
323 append o [format "%d\n" [expr {[llength $bm]-1}]]
324 foreach x [lrange $bm 1 end] { append o "$x\n" }
327 set f [open database.new w]
328 foreach o [lsort $ol] {
329 puts -nonewline $f $o
332 file rename -force database.new database
335 proc update_database/DEFINE {c0 c1 strh} {
336 global foolist unk_l unk_context wordmap database
337 if {$c0 > $c1} { manyset [list $c0 $c1] c1 c0 }
339 set ncontext $unk_context
341 foreach {l r context got} $foolist {
342 if {$l==$c0} { set ncontext $context; break }
344 if {![exists ncontext]} {
345 puts stderr "must start at letter LHS!"
350 for {set x $c0} {$x < $c1} {incr x} {
351 lappend bm [format %x $wordmap($x)]
353 set database($bm) $strh
358 proc RETURN_RESULT {how what} {
359 place forget .d.csr.csr
360 pack forget .d.csr.csr.e
361 helptext {{{ Processing }}}
365 eval update_database/$how $what
368 # bind . <Key-space> {}