From: Ian Jackson Date: Sun, 14 Jun 2009 23:53:47 +0000 (+0100) Subject: WIP island determination; ocr resolver can make query to user X-Git-Tag: 1.9.2~124^2~2 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.web-live.git;a=commitdiff_plain;h=b92f51387b77f876112c62d1a1afd816583e987d WIP island determination; ocr resolver can make query to user --- diff --git a/pctb/resolve.c b/pctb/resolve.c new file mode 100644 index 0000000..052ec32 --- /dev/null +++ b/pctb/resolve.c @@ -0,0 +1,89 @@ +/* + * IPC to external resolver program + */ +/* + * This is part of ypp-sc-tools, a set of third-party tools for assisting + * players of Yohoho Puzzle Pirates. + * + * Copyright (C) 2009 Ian Jackson + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Yohoho and Puzzle Pirates are probably trademarks of Three Rings and + * are used without permission. This program is not endorsed or + * sponsored by Three Rings. + */ + +#include "ocr.h" + +static FILE *resolver; +static pid_t resolver_pid; +static int resolver_done; + +FILE *resolve_start(void) { + int jobpipe[2],donepipe[2]; + + if (!o_resolver) return 0; + + if (!resolver) { + sysassert(! pipe(jobpipe) ); + sysassert(! pipe(donepipe) ); + resolver_pid= fork(); + sysassert(resolver_pid!=-1); + if (!resolver_pid) { + sysassert( dup2(jobpipe[0],0) ==0 ); + sysassert(! close(jobpipe[1]) ); + sysassert(! close(donepipe[0]) ); + /* we know donepipe[1] is >= 4 and we have dealt with all the others + * so we aren't in any danger of overwriting some other fd 4: */ + sysassert( dup2(donepipe[1],4) ==4 ); + execlp(o_resolver, o_resolver, + DEBUGP(callout) ? "--debug" : "--noop-arg", + "--automatic-1", + (char*)0); + sysassert(!"execlp ocr-resolver failed"); + } + sysassert(! close(jobpipe[0]) ); + sysassert(! close(donepipe[1]) ); + resolver= fdopen(jobpipe[1],"w"); sysassert(resolver); + resolver_done= donepipe[0]; + } + return resolver; +} + +void resolve_finish(void) { + char cb; + + sysassert(!ferror(resolver)); + sysassert(!fflush(resolver)); + + sysassert(resolver); + + int r; + for (;;) { + r= read(resolver_done,&cb,1); + if (r==-1) { sysassert(errno==EINTR); continue; } + break; + } + + if (r==0) { + waitpid_check_exitstatus(resolver_pid, "character resolver"); + fclose(resolver); + close(resolver_done); + resolver= 0; + } else { + assert(r==1); + sysassert(cb==0); + } +} diff --git a/pctb/yppsc-ocr-resolver b/pctb/yppsc-ocr-resolver index ec4473d..6ff436b 100755 --- a/pctb/yppsc-ocr-resolver +++ b/pctb/yppsc-ocr-resolver @@ -82,8 +82,12 @@ static unsigned char csr_bits[] = { frame .d.mi.csr_0 -bg white -width 1 frame .d.mi.csr_1 -bg white -width 1 + frame .d.pe + frame .d.pe.grid + button .d.pe.ok -text OK + pack .d.pe.grid .d.pe.ok -side left - pack .d.csr .d.mi .d.got .d.ctx -side top + pack .d.mi .d.got .d.ctx -side top pack .d frame .help @@ -101,26 +105,15 @@ proc show_context {maxhv x ctxs} { if {$wh > $maxh} { set maxh $wh } } -proc resize_widgets {} { +proc resize_widgets_core {} { global mulcols mulrows csrh gotsh ctxh glyphsdone global unk_l unk_contexts foreach w {.d.csr .d.got .d.ctx} { $w configure -width $mulcols } - #.d configure -height [expr {$csrh+$mulrows+$gotsh+$ctxh}] - foreach w {0 1} { - .d.mi.csr_$w configure -height $mulrows - } eval destroy [winfo children .d.ctx] - - set maxh 0 - foreach {min max contexts got} $glyphsdone { - show_context maxh $min $contexts - } - show_context maxh $unk_l $unk_contexts - .d.ctx configure -height $maxh } @@ -260,7 +253,6 @@ proc startup_cursor {} { set cur_0 $unk_l set cur_1 [expr {$unk_r+1}] - set last_ht {} recursor } @@ -268,6 +260,8 @@ proc startup_cursor {} { #---------- runtime display and keystroke handling ---------- +set last_ht {} + proc helptext {t} { global last_ht if {![string compare $t $last_ht]} return @@ -525,26 +519,6 @@ proc RETURN_RESULT {how what} { proc main/default {} { puts stderr "Do not run this program directly." exit 12 - - global glyphsdone unk_l unk_r unk_contexts - - set glyphsdone { - 7 11 1 M - 13 17 0 a - 19 23 0 n - } - set unk_l 25 - set unk_r 29 - set unk_contexts Test - - set f [open text.xpm] - read_xpm $f - close $f - - read_database - resize_widgets - draw_glyphsdone - startup_cursor } proc done/default {} { } @@ -561,13 +535,97 @@ proc required {} { required/$l } + +proc foreach_pixmap_col {var body} { + global alloptions + upvar 1 $var col + for {set col 0} {$col < [llength $alloptions]/3} {incr col} { + uplevel 1 $body + } +} + +proc pixmap_select {ncol} { + global alloptions + debug "PIX SELECT $ncol [llength $alloptions]" + foreach_pixmap_col col { + if {$col==$ncol} continue + .d.pe.grid.l$col selection clear 0 end + } + pixmap_maybe_ok +} +proc pixmap_maybe_ok {} { + global alloptions pixmap_selcol pixmap_selrow + set nsel 0 + foreach_pixmap_col col { + set cs [.d.pe.grid.l$col curselection] + incr nsel [llength $cs] + set pixmap_selcol $col + set pixmap_selrow [lindex $cs 0] + } + if {$nsel==1} { + .d.pe.ok configure -state normal -command pixmap_ok + } else { + .d.pe.ok configure -state disabled -command {} + } +} +proc pixmap_ok {} { + foreach_pixmap_col col { + .d.pe.grid.l$col configure -state disabled + } + .d.pe.ok configure -state disabled + helptext {{{ Processing }}} +} + proc required/pixmap {} { - global unk_what + global unk_what ppm mulcols alloptions must_gets stdin unk_what - error nyi + debug "GOT pixmap $unk_what" + set ppm {} + while 1 { + must_gets stdin ppml + if {![string length $ppml]} break + append ppm $ppml "\n" + } + set data [exec pnmscale 2 << $ppm] + image create photo image/main -data $data + + set alloptions [exec ./yppsc-resolver-pixoptions $unk_what] + + #read_database_pixmaps + + set mulcols [image width image/main] + set mulrows [image height image/main] + resize_widgets_core + place forget .d.mi.csr_0 + place forget .d.mi.csr_1 + .d.ctx configure -height 0 + pack forget .d.csr + pack .d.pe -side top -before .d.mi -pady 10 + + eval destroy [winfo children .d.pe.grid] + set col 0; foreach {colname coldesc rows} $alloptions { + debug "INIT $col $colname \"$coldesc\"" + label .d.pe.grid.t$col -text $colname + listbox .d.pe.grid.l$col + foreach {rowname rowdesc} $rows { + debug "INIT $col $colname \"$coldesc\" $rowname \"$rowdesc\"" + .d.pe.grid.l$col insert end $rowdesc + } + bind .d.pe.grid.l$col <> [list pixmap_select $col] + grid .d.pe.grid.t$col -column $col -row 0 + grid .d.pe.grid.l$col -column $col -row 1 + incr col + } + pixmap_maybe_ok + + helptext { + {{Indicate the correct parse of this image, and click OK.}} + } } proc required/char {} { + global mulrows + must_gets stdin l manyset [lrange $l 0 3] unk_l unk_r unk_contexts @@ -578,7 +636,20 @@ proc required/char {} { fconfigure stdin -blocking yes read_xpm stdin - resize_widgets + + resize_widgets_core + foreach w {0 1} { + .d.mi.csr_$w configure -height $mulrows + } + set maxh 0 + foreach {min max contexts got} $glyphsdone { + show_context maxh $min $contexts + } + show_context maxh $unk_l $unk_contexts + .d.ctx configure -height $maxh + pack forget .d.pe + pack .d.csr -side top -before .d.mi + read_database draw_glyphsdone startup_cursor diff --git a/pctb/yppsc-resolver-pixoptions b/pctb/yppsc-resolver-pixoptions new file mode 100755 index 0000000..260c5a2 --- /dev/null +++ b/pctb/yppsc-resolver-pixoptions @@ -0,0 +1,52 @@ +#!/usr/bin/perl -w + +# helper program for determining pixmap resolution options + +# This is part of ypp-sc-tools, a set of third-party tools for assisting +# players of Yohoho Puzzle Pirates. +# +# Copyright (C) 2009 Ian Jackson +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Yohoho and Puzzle Pirates are probably trademarks of Three Rings and +# are used without permission. This program is not endorsed or +# sponsored by Three Rings. + +@ARGV==1 or die "You probably don't want to run this program directly.\n"; +our ($which) = shift @ARGV; + +$which =~ s/\W//g; + +&{"main__$which"}(); + +sub main__sunshinewidget () { + print <