X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.web-live.git;a=blobdiff_plain;f=pctb%2Fdictionary-update-receiver;h=25a6dfc3639a840edbb7b045341b1cdac241d3c6;hp=cd1638e22a476e905d2ebecd7975169181fb1358;hb=df05f8de89a10e07fc8677ab9594e1a485990d5e;hpb=0ae7e17eb009e215cfd61b7193816caa0108f43c diff --git a/pctb/dictionary-update-receiver b/pctb/dictionary-update-receiver index cd1638e..25a6dfc 100755 --- a/pctb/dictionary-update-receiver +++ b/pctb/dictionary-update-receiver @@ -19,6 +19,8 @@ use CGI qw/:standard -private_tempfiles/; use IO::Pipe; use IO::Handle; +my $aadepth=2; + #---------- pixmaps ---------- sub parseentryin__pixmap ($) { @@ -54,7 +56,7 @@ sub parseentryin__pixmap ($) { my $whole= pipeval($ppm, 'ppmtopgm', - 'pnmnorm -bpercent 40 -wpercent 20', + 'pnmnorm -bpercent 10 -wpercent 5', 'pgmtopbm -threshold', 'pnminvert', 'pbmtoascii'); @@ -68,42 +70,48 @@ sub parseentryin__pixmap ($) { sub parseentryin__char ($$) { my ($ei,$h) = @_; - $ei =~ m/^(Digit|Upper|Lower)\n([^\n]+)\n/s or die; + $ei =~ m/^(Digit|Upper|Lower|Word)\n([^\n]+)\n/s or die; my ($ctx,$str)= ($1,$2); -#print STDERR ">$'<\n"; +print STDERR ">ctx=$ctx|str=$str|$'<\n"; my @d= grep { m/./ } split /\n/, $'; -#print STDERR ">@d<\n"; - die if $h>31; +print STDERR ">@d<\n"; + die if $h>100; die if @d>400; - my $maxval= (1<<$h)-1; - map { - m/^[0-9a-f]{1,8}$/ or die; - $_= hex $_; - die "$_ ?" if $_ > $maxval; - } @d; + my $w= @d; - my $ppm= "P2\n$w $h\n1\n"; - my $whole=''; - for (my $y=0; $y<$h; $y++) { - for (my $x=0; $x<$w; $x++) { - my $pix= !($d[$x] & (1<<$y)); - $ppm .= sprintf " %d", $pix; - $whole .= $pix ? ' ' : '<>'; - } - $ppm .= "\n"; - $whole .= "\n"; - } - map { $_= sprintf "%x", $_; } @d; + + my $maxval= (1<<$aadepth)-1; + die 'cannot do [^0...$maxval]!' if $maxval>9; + + my $pgm= "P2\n$h $w\n$maxval\n"; + map { # x, left to right + m/[^0-$maxval]/ and die "$_ ?"; + my $l= $_; + $l =~ s/./ $&/g; + $pgm .= "$l\n"; + } @d; + my $key= join ' ', $ctx, @d; -# my $whole= pipeval($ppm, -# "pnmscale 2", -# 'pgmtopbm -threshold', -# 'pbmtoascii'); + $pgm= pipeval($pgm, + "pnmflip -xy", + "pnmnoraw"); + + my $icon= pipeval($pgm, + "pnmscale -xysize 156 ".($h*4), + 'pgmtopbm -threshold', + 'pnminvert', + 'pbmtoascii -2x4'); + + my $whole= pipeval($pgm, + "pnmscale 4", + 'pgmtopbm -fs', + 'pnminvert', + 'pbmtoascii'); - my $entry= "$ctx\n$str\n". join("\n", @d). "\n"; + my $entry= "$ctx\n$str\n$key\n"; - return ($ctx,$str,$ppm,$key,$str, $w*2,'',$whole,$entry); + return ($ctx,$str,$pgm,$key,$str, $w*4,$icon,$whole,$entry); } #---------- useful stuff ---------- @@ -153,6 +161,14 @@ sub pipeval ($@) { #---------- determine properties of the submission ---------- +my $version= param('version'); +my $spec_aadepth= param('depth'); +if ($version ne '3' || $spec_aadepth ne $aadepth) { + print header('text/plain','403 Client out of date'); + print "\nYour YPP SC client is out of date.\n"; + exit 0; +} + my $dict= param('dict'); my $entry_in= param('entry'); defined $entry_in or die Dump()." ?"; @@ -190,6 +206,18 @@ $dict= $&; my ($ctx,$def,$image,$key,$val, $width,$icon,$whole,$entry)= &{"parseentryin__$kind"}($entry_in, @xa); +my $du=$ENV{'YPPSC_DICTUPDATES'}; +chdir $du or die "$du $!" + if defined $du; + +my $instance= $du; +$instance =~ s,ypp-sc-tools,,ig; +$instance =~ s,ypp,,ig; +$instance =~ s,pctb,,ig; +$instance =~ s,/\W+/,/,g; +$instance =~ s,/+$,,; +$instance =~ s,^.*/,,; + #---------- compute the email to send ---------- my $whoami= `whoami`; $? and die $?; @@ -197,7 +225,7 @@ chomp $whoami; my $email= < $fn_t" or die "$fn_t $!"; (stat F) or die $!; my $fn_i= sprintf "_update.$$-%016x.rdy", (stat _)[1]; -print F "ypp-sc-tools dictionary update v1\n"; +print F "ypp-sc-tools dictionary update v3 depth=$aadepth\n"; foreach my $v ($pirate,$caller,$dict,$ctx,$def,$image,$key,$val) { printf F "%d\n", length($v) or die $!;