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 {
26 if {[gets $f l] < 0} { error "huh? "}
27 if {![regexp {^"(.*)",$} $l dummy l]} {
29 if {[regexp {^\}\;$} $l]} break
33 manyset $l cols rows colours cpp
36 set mulcols [expr {$cols*$mul+$inter}]
37 set mulrows [expr {$rows*$mul+$inter}]
38 append o "\"$mulcols $mulrows 9 1\",\n"
39 for {set x 0} {$x<$cols} {incr x} { set wordmap($x) 0 }
40 } elseif {$y==-2} { # first pixel
51 } elseif {$y==-1} { # 2nd pixel but we've already printed ours
53 set ybit [expr {1<<$y}]
57 foreach c [split $l ""] {
59 if {$x >= $unk_l && $x <= $unk_r} {
63 foreach {min max context got} $foolist {
65 if {$x >= $min && $x <= $max} {
66 set how [lindex {a b} $ab]
75 set p [string toupper $how]
76 incr wordmap($x) $ybit
78 default { error "$c ?" }
80 append ol "[string repeat $p [expr {$mul-$inter}]][
81 string repeat + $inter]"
82 append olh [string repeat + $mul]
88 set olhn [string repeat $olh $inter]
89 if {!$y} { append o $olhn }
90 append o [string repeat $ol [expr {$mul-1}]]
95 set data [exec xpmtoppm << $o]
96 image create photo main_image -data $xpm
104 frame .d -width $mulcols -height [expr {$csrh+$mulrows+$gotsh}]
107 image create bitmap main_image
108 label .d.mi -image $mi -borderwidth 0
110 frame .d.csr -bg black -width $mulcols -height $csrh
111 frame .d.got -bg black -width $mulcols -height $gotsh
113 foreach {min max context got} $foolist {
114 frame .d.got.m$min -bd 0 -background \#888
115 label .d.got.m$min.l -text "$got" -fg white -bg black -bd 0
116 pack .d.got.m$min.l -padx 1 -pady 1
117 place .d.got.m$min -x [expr {$min*$mul+$inter}] -y 0
120 set imcsr [image create bitmap -data \
121 {#define csr_width 11
122 #define csr_height 11
123 static unsigned char csr_bits[] = {
124 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x21, 0x04, 0x22, 0x02, 0x25, 0x05,
125 0xaa, 0x02, 0x74, 0x01, 0xa8, 0x00, 0x70, 0x00, 0x20, 0x00};
129 label .d.csr.csr.l -image $imcsr -compound left
130 entry .d.csr.csr.e -bd 0
131 pack .d.csr.csr.l -side left
133 frame .d.csr_0 -bg white -height $mulrows -width 1
134 frame .d.csr_1 -bg white -height $mulrows -width 1
136 place .d.csr -x 0 -y 0
137 place .d.mi -x 0 -y $csrh
138 place .d.got -x 0 -y [expr {$csrh+$mulrows}]
144 set cur_already [expr {[llength $foolist]/4-1}]
145 set cur_mode 1 ;# one of: 0 1 already text
148 set cur_1 [expr {$unk_r+1}]
153 if {![string compare $t $last_ht]} return
154 eval destroy [grid slaves .help]
155 set y 0; foreach l $t {
156 set x 0; foreach c $l {
157 set w .help.at${x}x${y}
159 grid $w -row $y -column $x -padx 5
167 proc recursor/0 {} { recursor//01 0 }
168 proc recursor/1 {} { recursor//01 1 }
169 proc recursor//01 {z1} {
170 global mul rhsmost_max cols foolist
172 .d.csr.csr.l configure -text {adjust}
173 place .d.csr.csr -x [expr {$cur*$mul - 7}]
174 bind_key space { othercursor }
175 bind_leftright cur_$z1 0 [expr {$cols-1}]
176 if {[llength $foolist]} {
177 bind_key Tab { set cur_mode already; recursor }
182 if {$cur_0 != $cur_1} {
188 {{<- ->} {move cursor, adjusting area to define}}
189 {Space {switch to moving other cursor}}
190 {Return {confirm location, enter letter(s)}}
191 {Tab {switch to correcting earlier ocr}}
194 proc othercursor {} {
196 set cur_mode [expr {!$cur_mode}]
200 proc recursor/text {} {
202 {Return {confirm entry of new glyph}}
203 {Escape {abandon entry}}
206 .d.csr.csr.l configure -text {define:}
207 pack .d.csr.csr.e -side left
210 binary scan [.d.csr.csr.e get] h* hex
211 if {[string length $hex]} {
212 RETURN_RESULT DEFINE "$cur_0 $cur_1 $hex"
217 pack forget .d.csr.csr.e
223 proc recursor/already {} {
226 global cur_already mul
227 global foolist cur_already mul
228 .d.csr.csr.l configure -text {correct}
229 set rmax [lindex $foolist [expr {$cur_already*4}]]
230 place .d.csr.csr -x [expr {$rmax*$mul-3}]
233 bind_leftright cur_already 0 [expr {[llength $foolist]/4-1}]
234 bind_key Tab { bind_key Delete {}; set cur_mode 1; recursor }
236 RETURN_RESULT DELETE [lrange $foolist \
237 [expr $cur_already*4] \
238 [expr $cur_already*4+1]]
241 {{<- ->} {move cursor, selecting glyph to correct}}
242 {Del {clear this glyph from the recognition database}}
243 {Tab {switch to selecting area to define as new glyph}}
247 proc bind_key {k proc} {
249 bind . <Key-$k> $proc
250 set keybindings($k) [expr {!![string length $proc]}]
252 proc unbind_all_keys {} {
254 foreach k [array names keybindings] { bind_key $k {} }
257 proc bind_leftright {var min max} {
258 bind_key Left [list leftright $var $min $max -1]
259 bind_key Right [list leftright $var $min $max +1]
261 proc leftright {var min max inc} {
265 if {$vnew < $min || $vnew > $max} return
271 global csrh cur_mode cur_0 cur_1 mul
273 place .d.csr_$z1 -y $csrh -x [expr {[set cur_$z1] * $mul}]
281 # <context> <ncharacters> <hex>...
285 # $database($context 0x<bits> 0x<bits>...) = $hex
287 proc read_database {} {
289 set f [open database r]
290 while {[gets $f l] >= 0} {
291 if {![regexp {^(\w+) (\d+) ((?:[0-9a-f]{2})+)$} $l \
292 dummy context strl strh]} {
295 if {[string length $strh] != $strl*2} { error "$strh $strl" }
296 gets $f l; set width [format %d $l]
298 for {set x 0} {$x < $width} {incr x} {
299 gets $f l; lappend bm [format %x 0x$l]
301 set database($bm) $strh
306 proc write_database {} {
309 foreach bm [array names database] {
310 set strh $database($bm)
311 set strs [binary format h* $strh]
312 set strdo [format "%d %s" [expr {[string length $strh]/2}] $strh]
313 set o "[lindex $bm 0] $strdo\n"
314 append o [format "%d\n" [expr {[llength $bm]-1}]]
315 foreach x [lrange $bm 1 end] { append o "$x\n" }
318 set f [open database.new w]
319 foreach o [lsort $ol] {
320 puts -nonewline $f $o
323 file rename -force database.new database
326 proc update_database/DEFINE {c0 c1 strh} {
327 global foolist unk_l unk_context wordmap database
328 if {$c0 > $c1} { manyset [list $c0 $c1] c1 c0 }
330 set ncontext $unk_context
332 foreach {l r context got} $foolist {
333 if {$l==$c0} { set ncontext $context; break }
335 if {![exists ncontext]} {
336 puts stderr "must start at letter LHS!"
341 for {set x $c0} {$x < $c1} {incr x} {
342 lappend bm [format %x $wordmap($x)]
344 set database($bm) $strh
349 proc RETURN_RESULT {how what} {
350 place forget .d.csr.csr
351 pack forget .d.csr.csr.e
352 helptext {{{ Processing }}}
356 eval update_database/$how $what
359 # bind . <Key-space> {}
373 set f [open text.xpm]