3 # helper program for OCR in PCTB upload client
5 # This is part of ypp-sc-tools, a set of third-party tools for assisting
6 # players of Yohoho Puzzle Pirates.
8 # Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 # Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
24 # are used without permission. This program is not endorsed or
25 # sponsored by Three Rings.
30 # run this without args
32 # one line which is a Tcl list for unk_{l,r} unk_contexts glyphsdone etc.
33 # the xpm in the format expected
34 # then expect child to exit 0, or write a single 0 byte to fd 4
35 # if it wrote a byte to fd 4, it can take another question
38 #---------- library routines ----------
40 proc manyset {list args} {
41 foreach val $list var $args {
47 proc must_gets {f lvar} {
49 if {[gets $f l] < 0} { error "huh?" }
52 proc must_gets_exactly {f expected} {
54 if {[string compare $expected $got]} { error "$expected $got ?" }
57 proc read_counted {f var} {
60 set val [read $f $count]
62 if {[string length $eol]} { error "$eol ?" }
63 debug "READ_COUNTED $count $var"
66 proc puts_counted {f dvar} {
68 set count [string length $d]
71 debug "PUTS_COUNTED $count $dvar"
74 #---------- display core ----------
83 proc init_widgets {} {
85 global csrh gotsh ctxh
87 if {[winfo exists .d]} return
89 frame .privacy -bd 2 -relief groove
90 pack .privacy -side top -padx 2 -pady 2 -fill x
94 frame .d -bd 2 -relief groove -pady 2 -padx 2
96 image create bitmap image/main
97 label .d.mi -image image/main -borderwidth 0
99 frame .d.csr -bg black -height $csrh
100 frame .d.got -bg black -height $gotsh
101 frame .d.ctx -bg black
103 image create bitmap image/cursor -data \
104 {#define csr_width 11
105 #define csr_height 11
106 static unsigned char csr_bits[] = {
107 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x21, 0x04, 0x22, 0x02, 0x25, 0x05,
108 0xaa, 0x02, 0x74, 0x01, 0xa8, 0x00, 0x70, 0x00, 0x20, 0x00};
112 label .d.csr.csr.l -image image/cursor -compound left
113 entry .d.csr.csr.e -bd 0
114 pack .d.csr.csr.l -side left
116 frame .d.mi.csr_0 -bg white -width 1
117 frame .d.mi.csr_1 -bg white -width 1
121 button .d.pe.ok -text OK
122 pack .d.pe.grid .d.pe.ok -side left
124 pack .d.mi .d.ctx -side top
125 pack .d -fill x -padx 2 -pady 2
127 frame .help -bd 2 -relief groove
128 pack .help -pady 2 -padx 2
131 proc resize_widgets_core {} {
132 global mulcols mulrows csrh gotsh ctxh glyphsdone
133 global unk_l unk_contexts
135 foreach w {.d.csr .d.got .d.ctx} {
136 $w configure -width $mulcols
139 eval destroy [winfo children .d.ctx]
146 if {![string compare $t $last_ht]} return
147 eval destroy [grid slaves .help]
148 set y 0; foreach l $t {
149 set x 0; foreach c $l {
150 set w .help.at${x}x${y}
152 grid $w -row $y -column $x -padx 5 -sticky w
160 proc bind_key {k proc} {
162 bind . <Key-$k> $proc
163 set keybindings($k) [expr {!![string length $proc]}]
165 proc unbind_all_keys {} {
167 foreach k [array names keybindings] { bind_key $k {} }
170 #---------- database read and write common wrapper ----------
173 if {[gets $f l] < 0} { error "unexpected db eof" }
177 proc read_database {fn} {
178 global reqkind database database_fn
179 upvar #0 database_magic/$reqkind magic
180 catch { unset database }
183 if {![file exists $database_fn]} return
184 set f [open $database_fn r]
185 if {[string compare [db_getsl $f] $magic]} { error "$l $reqkind ?" }
187 read_database_header/$reqkind $f
191 if {![string length $l1]} continue
192 if {[regexp {^\#} $l1]} continue
193 if {![string compare . $l1]} break
195 read_database_entry/$reqkind $f $l1
200 proc write_database {} {
201 global reqkind database_fn database
202 upvar #0 database_magic/$reqkind magic
204 set f [open $database_fn.new w]
207 write_database_header/$reqkind $f
210 foreach bm [array names database] {
211 lappend ol [format_database_entry/$reqkind $bm $database($bm)]
213 foreach o [lsort $ol] {
218 file rename -force $database_fn.new $database_fn
221 proc required/char {} {
222 global mulrows glyphsdone unk_l unk_r unk_contexts rows
226 manyset [lrange $l 0 3] unk_l unk_r unk_contexts
227 set glyphsdone [lrange $l 3 end]
234 .d.mi.csr_$w configure -height $mulrows
237 foreach {min max contexts got} $glyphsdone {
238 show_context maxh $min $contexts
240 show_context maxh $unk_l $unk_contexts
241 .d.ctx configure -height $maxh
243 pack .d.csr -side top -before .d.mi
244 pack .d.got .d.ctx -side top -after .d.mi
246 read_database "./#local-char$rows#.txt"
251 #========== PIXMAPS ==========
253 #---------- pixmap database read and write ----------
255 set database_magic/pixmap {# ypp-sc-tools pctb pixmaps v1}
257 proc read_database_header/pixmap {f} { }
258 proc read_database_entry/pixmap {f def} {
263 set p3 [db_getsl $f]; append im $p3 "\n"
264 if {[string compare $p3 P3]} { error "$p3 ?" }
266 set wh [db_getsl $f]; append im $wh "\n"; manyset $wh w h
267 set depth [db_getsl $f]; append im $depth "\n"
269 for {set y 0} {$y < $h} {incr y} {
270 set line [db_getsl $f]; append im $line "\n"
272 set database($im) $def
274 proc write_database_header/pixmap {f} { puts $f "" }
275 proc format_database_entry/pixmap {im def} {
279 #---------- pixmap display and input handling ----------
281 proc foreach_pixmap_col {var body} {
284 for {set col 0} {$col < [llength $alloptions]/3} {incr col} {
289 proc pixmap_select {ncol} {
291 debug "PIX SELECT $ncol [llength $alloptions]"
292 foreach_pixmap_col col {
293 if {$col==$ncol} continue
294 .d.pe.grid.l$col selection clear 0 end
298 proc pixmap_maybe_ok {} {
299 global alloptions pixmap_selcol pixmap_selrow
301 foreach_pixmap_col col {
302 set cs [.d.pe.grid.l$col curselection]
303 set lcs [llength $cs]
306 set pixmap_selcol $col
307 set pixmap_selrow [lindex $cs 0]
310 debug "MAYBE_OK YES col=$pixmap_selcol row=$pixmap_selrow."
311 .d.pe.ok configure -state normal -command pixmap_ok
313 .d.pe.ok configure -state disabled -command {}
317 global database ppm pixmap_selcol pixmap_selrow mainkind alloptions
318 foreach_pixmap_col col {
319 .d.pe.grid.l$col configure -state disabled
321 .d.pe.ok configure -state disabled
322 helptext {{{ Processing }}}
323 manyset [lrange $alloptions [expr {$pixmap_selcol*3}] end] \
325 manyset [lrange $rows [expr {$pixmap_selrow*2}] end] \
327 set result "$colname - $rowname"
328 debug "UPDATE PIXMAP AS >$result<"
329 set database($ppm) $result
334 proc required/pixmap {} {
335 global unk_what ppm mulcols alloptions
336 must_gets stdin unk_what
337 debug "GOT pixmap $unk_what"
341 if {![string length $ppml]} break
342 append ppm $ppml "\n"
344 set data [exec pnmscale 2 << $ppm]
345 image create photo image/main -data $data
347 set alloptions [exec ./dictionary-pixmap-options $unk_what]
349 read_database "./#local-pixmap#.txt"
351 set mulcols [image width image/main]
352 set mulrows [image height image/main]
354 place forget .d.mi.csr_0
355 place forget .d.mi.csr_1
357 pack forget .d.csr .d.got
358 pack .d.pe -side top -before .d.mi -pady 2
361 eval destroy [winfo children .d.pe.grid]
362 set col 0; foreach {colname coldesc rows} $alloptions {
363 debug "INIT $col $colname \"$coldesc\""
364 label .d.pe.grid.t$col -text $colname
365 listbox .d.pe.grid.l$col
366 foreach {rowname rowdesc} $rows {
367 debug "INIT $col $colname \"$coldesc\" $rowname \"$rowdesc\""
368 .d.pe.grid.l$col insert end $rowdesc
370 bind .d.pe.grid.l$col <<ListboxSelect>> [list pixmap_select $col]
371 grid .d.pe.grid.t$col -column $col -row 0
372 grid .d.pe.grid.l$col -column $col -row 1
378 {{Indicate the meaning of this image, and click OK.}}
382 #========== UPLOADS TO DICTIONARY SERVER ==========
384 proc upload_init_widgets {} {
385 global privacy_setting
387 set privacy_setting [upload_status]
389 label .privacy.warn -text " Privacy "
390 if {$privacy_setting} {
391 .privacy.warn configure -background yellow -foreground black
393 label .privacy.overall -text " Upload new dictionary entry:"
394 label .privacy.reference -text " See README.privacy."
396 pack .privacy.warn .privacy.overall -side left
398 foreach {setting string} {
401 2 {Yes, quoting my pirate name.}
403 radiobutton .privacy.o$setting -text $string \
404 -value $setting -variable privacy_setting
405 pack .privacy.o$setting -side left
406 if {$setting > $privacy_setting} {
407 .privacy.o$setting configure -state disabled
410 pack .privacy.reference -side left
412 if {!$privacy_setting} {
413 foreach w [winfo children .privacy] {
414 $w configure -state disabled
419 proc upload_status {} {
420 # returns 0, 1, 2 for none, anon, with pirate name
423 if {![info exists env(YPPSC_PCTB_DICT_SUBMIT)]} { debug a; return 0 }
424 if {![string compare 0 $env(YPPSC_PCTB_DICT_SUBMIT)]} { debug b; return 0 }
426 if {![info exists env(YPPSC_PIRATE)]} { return 1 }
427 if {![string length $env(YPPSC_PIRATE)]} { return 1 }
432 #========== CHARACTER SET ==========
434 #---------- xpm input processor ----------
436 proc char_read_xpm {f} {
437 global glyphsdone mul inter rhsmost_max unk_l unk_r mulcols mulrows
438 global cols rows wordmap
444 if {![regexp {^"(.*)",$} $l dummy l]} {
446 if {[regexp {^\}\;$} $l]} break
450 manyset $l cols rows colours cpp
451 if {$colours!=2 || $cpp!=1} { error "$l ?" }
453 set chop_l [expr {$unk_l - 80}]
454 set chop_r [expr {$cols - $unk_l - 100}]
455 if {$chop_l<0} { set chop_l 0 }
457 set unk_l [expr {$unk_l - $chop_l}]
458 set unk_r [expr {$unk_r - $chop_l}]
460 foreach {min max contexts got} $glyphsdone {
462 [expr {$min-$chop_l}] \
463 [expr {$max-$chop_l}] \
469 set cols [expr {$cols - $chop_l - $chop_r}]
470 debug "NOW cols=$cols chop_l,r=$chop_l,$chop_r rows=$rows\
473 set mulcols [expr {$cols*$mul+$inter}]
474 set mulrows [expr {$rows*$mul+$inter}]
475 append o "\"$mulcols $mulrows 9 1\",\n"
476 for {set x 0} {$x<$cols} {incr x} { set wordmap($x) 0 }
477 } elseif {$y==-2} { # first pixel
488 } elseif {$y==-1} { # 2nd pixel but we've already printed ours
490 set ybit [expr {1<<$y}]
495 set l [string range $l $chop_l end-$chop_r]
497 set l [string range $l $chop_l end]
498 append l [string repeat " " [expr -$chop_r]]
500 foreach c [split $l ""] {
502 if {$x >= $unk_l && $x <= $unk_r} {
506 foreach {min max contexts got} $glyphsdone {
508 if {$x >= $min && $x <= $max} {
509 set how [lindex {a b} $ab]
518 set p [string toupper $how]
519 incr wordmap($x) $ybit
521 default { error "$c ?" }
523 append ol "[string repeat $p [expr {$mul-$inter}]][
524 string repeat + $inter]"
525 append olh [string repeat + $mul]
531 set olhn [string repeat $olh $inter]
532 if {!$y} { append o $olhn }
533 append o [string repeat $ol [expr {$mul-1}]]
538 set data [exec xpmtoppm << $o]
539 image create photo image/main -data $data
542 #---------- character set editor display ----------
544 proc show_context {maxhv x ctxs} {
548 if {[llength $ctxs]==1} { set fg blue } { set fg yellow }
549 label $w -bg black -fg $fg -text [join $ctxs "/\n"] -justify left
550 place $w -x [expr {($x-1)*$mul}] -y 0
551 set wh [winfo reqheight $w]
552 if {$wh > $maxh} { set maxh $wh }
555 proc draw_glyphsdone {} {
556 global glyphsdone mul inter
557 eval destroy [winfo children .d.got]
558 foreach {min max contexts got} $glyphsdone {
559 frame .d.got.m$min -bd 0 -background \#888
560 label .d.got.m$min.l -text "$got" -fg white -bg black -bd 0
561 pack .d.got.m$min.l -padx 1 -pady 1
562 place .d.got.m$min -x [expr {$min*$mul+$inter}] -y 0
566 proc startup_cursor {} {
567 global cur_already cur_mode cur_0 cur_1 last_ht
568 global glyphsdone unk_l unk_r
570 set cur_already [expr {[llength $glyphsdone]/4-1}]
571 set cur_mode 1 ;# one of: 0 1 already text
574 set cur_1 [expr {$unk_r+1}]
579 #---------- character set runtime display and keystroke handling ----------
581 proc recursor/0 {} { recursor//01 0 }
582 proc recursor/1 {} { recursor//01 1 }
583 proc recursor//01 {z1} {
584 global mul rhsmost_max cols glyphsdone
586 .d.csr.csr.l configure -text {adjust}
587 place .d.csr.csr -x [expr {$cur*$mul - 7}]
588 bind_key space { othercursor }
589 bind_leftright_q cur_$z1 0 [expr {$cols-1}]
590 if {[llength $glyphsdone]} {
591 bind_key BackSpace { set cur_mode already; recursor }
593 bind_key BackSpace {}
596 if {$cur_0 != $cur_1} {
597 .d.csr.csr.e delete 0 end
603 {{<- ->} {move cursor, adjusting area to define}}
604 {Space {switch to moving other cursor}}
605 {Return {confirm location, enter letter(s)}}
606 {Backspace {switch to correcting earlier ocr}}
607 {Q {quit and abandon OCR run}}
610 proc othercursor {} {
612 set cur_mode [expr {!$cur_mode}]
616 proc recursor/text {} {
618 {Return {confirm entry of new glyph}}
619 {Escape {abandon entry}}
622 .d.csr.csr.l configure -text {define:}
623 pack .d.csr.csr.e -side left
626 set strq [.d.csr.csr.e get]
627 if {[regexp -line {^(?:[!-[]|[]-~]|\\\\|\\x[0-9a-f]{2})+} $strq]} {
628 RETURN_RESULT DEFINE "$cur_0 $cur_1 $strq"
633 pack forget .d.csr.csr.e
639 proc recursor/already {} {
642 global cur_already mul
643 global glyphsdone cur_already mul
644 .d.csr.csr.l configure -text {correct}
645 set rmax [lindex $glyphsdone [expr {$cur_already*4}]]
646 place .d.csr.csr -x [expr {$rmax*$mul-3}]
648 bind_leftright_q cur_already 0 [expr {[llength $glyphsdone]/4-1}]
649 bind_key space { bind_key Delete {}; set cur_mode 1; recursor }
651 RETURN_RESULT DELETE [lrange $glyphsdone \
652 [expr $cur_already*4] \
653 [expr $cur_already*4+2]]
656 {{<- ->} {move cursor, selecting glyph to correct}}
657 {Del {clear this glyph from the recognition database}}
658 {Space {switch to selecting area to define as new glyph}}
659 {Q {quit and abandon OCR run}}
663 proc bind_leftright_q {var min max} {
664 bind_key Left [list leftright $var $min $max -1]
665 bind_key Right [list leftright $var $min $max +1]
667 puts stderr "\nCharacter resolver quitting as you requested."
671 proc leftright {var min max inc} {
675 if {$vnew < $min || $vnew > $max} return
681 global csrh cur_mode cur_0 cur_1 mul
683 place .d.mi.csr_$z1 -y 0 -x [expr {[set cur_$z1] * $mul}]
688 #---------- character database read and write ----------
693 # <context> <ncharacters> <hex>...
697 # $database($context 0x<bits> 0x<bits>...) = $hex
699 set database_magic/char {# ypp-sc-tools pctb font v1}
701 proc read_database_header/char {f} {
703 if {([db_getsl $f])+0 != $rows} { error "wrong h ?" }
705 proc read_database_entry/char {f context} {
708 set strq [db_getsl $f]
711 if {![string length $l]} break
712 lappend bm [format %x 0x$l]
714 set database($bm) $strq
717 proc write_database_header/char {f} {
721 proc format_database_entry/char {bm strq} {
723 set o "[lindex $bm 0]\n$strq\n"
724 foreach x [lrange $bm 1 end] { append o "$x\n" }
728 proc dbkey {ctx l r} {
731 for {set x $l} {$x <= $r} {incr x} {
732 lappend bm [format %x $wordmap($x)]
737 proc update_database/DEFINE {c0 c1 strq} {
738 global glyphsdone unk_l unk_contexts wordmap database
739 if {$c0 > $c1} { manyset [list $c0 $c1] c1 c0 }
741 set ncontexts $unk_contexts
743 foreach {l r contexts got} $glyphsdone {
744 if {$l==$c0} { set ncontexts $contexts; break }
746 if {![info exists ncontexts]} {
747 puts stderr "must start at letter LHS!"
752 foreach c $ncontexts {
753 set bm [dbkey $c $c0 $c1]
754 set database($bm) $strq
759 proc update_database/DELETE {l r ctxs} {
762 set bm [dbkey $ctx $l $r]
763 catch { unset database($bm) }
768 proc RETURN_RESULT {how what} {
770 place forget .d.csr.csr
771 pack forget .d.csr.csr.e
772 helptext {{{ Processing }}}
776 eval update_database/$how $what
780 #========== server for approving updates ==========
782 proc remote-serv-log {dict pirate file event} {
783 global remoteserv_logf
784 set t [clock format [clock seconds] -format {%Y-%m-%d %H:%M:%S %Z}]
785 set s [format "%s %-6s %-31s %s %s\n" \
786 $t $dict $pirate [file tail $file] $event]
787 puts -nonewline $remoteserv_logf $s
790 proc remote-serv/list {} {
792 foreach file [glob -nocomplain -type f -directory $dropdir _update.*.rdy] {
798 puts_counted stdout d
803 proc remote-serv/take {yesno file dict} {
804 global dropdir dictdir rows reqkind database
806 debug "TAKE [list $yesno $file $dict]"
807 read_counted stdin pirate
808 read_counted stdin key
809 read_counted stdin val
811 must_gets_exactly stdin confirmed
813 if {![string compare pixmap $dict]} {
816 } elseif {[regexp {^(char)([1-9]\d*)$} $dict dummy reqkind rows]} {
817 debug "DICT CHAR rqk=$reqkind r=$rows."
823 read_database $dictdir/master-$dict.txt
824 set database($key) $val
830 remote-serv-log $dict $pirate $file "$desc $reqkind $rows"
831 file delete -force $file
836 proc remote-serv/noop {} {
840 set remoteserv_banner {ypp-sc-tools pctb remote-server v1}
842 proc main/remoteserv {} {
843 global argv dropdir remoteserv_banner remoteserv_logf dictdir
844 manyset $argv dropdir dictdir
845 puts $remoteserv_banner
846 set remoteserv_logf [open $dropdir/_dict.log a]
847 fconfigure $remoteserv_logf -buffering line
850 if {[gets stdin l] < 0} break
855 #========== updates approver ==========
857 proc puts_server {s} {
862 proc must_gets_server {lv} {
869 proc must_gets_exactly_server {expected} {
871 if {[string compare $expected $got]} { error "$expected $got ?" }
874 proc regsub-data {exp subspec args} {
876 if {![eval regsub $args -- [list $exp $data $subspec data]]} {
877 error "$exp >$data< ?"
881 proc chop_counted {var} {
884 if {![regexp {^(0|[1-9]\d*)\n} $data dummy l]} { error "$data ?" }
885 regsub-data {^.*\n} {} -line
886 set val [string range $data 0 [expr {$l-1}]]
887 set data [string range $data $l end]
888 debug "CHOP_COUNTED $l $var"
892 proc approve_decompose_data {specdata} {
896 regsub-data {^ypp-sc-tools dictionary update v1\n} {}
897 uplevel 1 chop_counted pirate
898 uplevel 1 chop_counted dict
899 uplevel 1 chop_counted ctx
900 uplevel 1 chop_counted def
901 uplevel 1 chop_counted image
902 uplevel 1 chop_counted key
903 uplevel 1 chop_counted val
905 return [uplevel 1 {list $dict $def $image}]
908 proc approve_compare {fd1 fd2} {
909 manyset $fd1 file data; set sv1 [approve_decompose_data $data]
910 manyset $fd2 file data; set sv2 [approve_decompose_data $data]
911 return [string compare $sv1 $sv2]
914 proc approve_showentry {ix file specdata} {
917 approve_decompose_data $specdata
922 label $wb-inf.who -text $pirate
924 entry $wb-inf.file -font fixed -relief flat
925 $wb-inf.file insert end [file tail $file]
926 $wb-inf.file configure -state readonly -width -1
928 pack $wb-inf.who $wb-inf.file -side top
931 label $wb-def.scope -text "$dict $ctx"
932 label $wb-def.def -text $def
933 pack $wb-def.scope $wb-def.def -side bottom
935 set ppm [exec pnmscale 2 << $image]
936 image create photo approve/$ix -data $ppm
937 label $wb-image -image approve/$ix -bd 2 -relief sunken
940 button $wb-act.rej -text Reject -command [list approve_reject $ix]
943 grid $wb-def $wb-image $wb-act $wb-inf -padx 3
944 grid configure $wb-image -ipadx 3 -ipady 3 -sticky w
946 lappend approve_ixes $ix
949 proc approve_approve_reject_one {ix yesno} {
950 global approve_list server
951 manyset [lindex $approve_list $ix] file tdata
952 approve_decompose_data $tdata
953 puts_server "take $yesno $file $dict"
954 puts_counted $server pirate
955 puts_counted $server key
956 puts_counted $server val
957 puts_server confirmed
959 must_gets_exactly_server done
962 proc approve_check_server {} {
966 must_gets_exactly_server ok
969 proc approve_reject {ix} {
971 approve_approve_reject_one $ix 0
975 proc approve_these {} {
978 foreach ix $approve_ixes { approve_approve_reject_one $ix 1 }
982 proc approve_fetch_list {} {
983 global server approve_list
988 must_gets_server more
989 switch -exact $more {
992 default { error "$more ?" }
994 must_gets_server file
995 read_counted $server data
996 lappend approve_list [list $file $data]
999 if {![llength $approve_list]} { puts "Nothing (more) to approve."; exit 0 }
1001 set approve_list [lsort -command approve_compare $approve_list]
1005 proc main/approve {} {
1006 global argv server remoteserv_banner data approve_list approve_page
1007 global userhost directory dictdir debug
1009 if {[llength $argv] != 3} { error "wrong # args" }
1010 manyset $argv userhost directory dictdir
1011 set cmd [list tclsh $directory/dictionary-manager]
1012 if {$debug} { lappend cmd --debug-server }
1013 lappend cmd --remote-server-1 $directory $dictdir
1014 switch -glob $userhost {
1016 {* *} { set cmd $userhost }
1017 * { set cmd [append [list ssh $userhost] $cmd] }
1019 lappend cmd 2>@ stderr
1020 set server [open |$cmd r+]
1021 must_gets_exactly_server $remoteserv_banner
1023 button .left -text {<<} -command {approve_show_page -1}
1024 button .right -text {>>} -command {approve_show_page +1}
1026 label .title -text {}
1027 frame .app -bd 2 -relief groove
1028 button .ok -text "Approve These" -command approve_these
1029 pack .title .app -side top
1030 pack .left -side left
1031 pack .right -side right
1032 pack .ok -side bottom
1038 proc approve_show_page {delta} {
1039 global approve_page approve_ixes approve_list userhost directory dictdir
1041 eval destroy [winfo children .app]
1045 incr approve_page $delta
1047 set ll [llength $approve_list]
1048 set npages [expr {($ll+$per_page-1)/$per_page}]
1049 if {$approve_page >= $npages} { incr approve_page -1 }
1051 set page_start [expr {$approve_page*$per_page}]
1052 set page_end [expr {$page_start+$per_page-1}]
1054 for {set ix $page_start} {$ix < $ll && $ix <= $page_end} {incr ix} {
1055 set fd [lindex $approve_list $ix]
1056 eval approve_showentry $ix $fd
1059 .title configure -text \
1060 "$userhost\n$directory => $dictdir\nPage [expr {$approve_page+1}]/$npages"
1062 .left configure -state disabled
1063 .right configure -state disabled
1064 if {$approve_page>0} { .left configure -state normal }
1065 if {$approve_page<$npages-1} { .right configure -state normal }
1068 #========== main program ==========
1070 proc main/default {} {
1071 puts stderr "Do not run this program directly."
1074 proc done/default {} {
1080 fileevent stdin readable {}
1081 fconfigure stdin -blocking yes
1083 if {[gets stdin reqkind]<0} {
1084 if {[eof stdin]} { fconfigure stdin -blocking yes; exit 0 }
1092 proc main/automatic {} {
1093 fconfigure stdin -blocking no
1094 fileevent stdin readable required
1096 proc done/automatic {} {
1097 exec sh -c {printf \\0 >&4}
1103 set mainkind default
1108 switch -exact -- $arg {
1109 {--debug} { set debug 1 }
1110 {--debug-server} { proc debug {m} { puts stderr "DICT-MGR-SVR $m" }}
1112 {--approve-updates} { set mainkind approve; break }
1113 {--automatic-1} { set mainkind automatic; break }
1114 {--remote-server-1} { set mainkind remoteserv; break }
1115 {--automatic*} - {--remote-server}
1116 { error "incompatible versions - install problem" }
1117 default { error "huh $argv ?" }
1121 proc debug {m} { puts stderr "DICT-MGR $m" }
1123 set argv [lrange $argv $ai end]