3 # This script is invoked when the YPP SC PCTB client phones home to
4 # provide updated character set OCR data or updated screenshot pixmap
5 # interpretation (island name) data.
7 # The client will also phone home anyway to fetch the latest parsedb
10 # This allows me (the operator of the SC server) to:
11 # - review the choices made by the user
12 # - if they are correct, incorporate them in the next client version
13 # - if they are wrong, incorporate fixes of them, or contradictions of them,
16 # The information reported
17 # The SC PCTB client does this so that
19 use strict (qw(vars));
21 $CGI::POST_MAX= 65536;
22 $CGI::DISABLE_UPLOADS= 1;
24 use CGI qw/:standard -private_tempfiles/;
28 #---------- pixmaps ----------
30 sub parseentryin__pixmap ($) {
33 m/^(\w+ \- \w[-+'"#! 0-9a-z]*)\nP3\n([1-9]\d{1,3}) ([1-9]\d{1,3})\n255\n/s or die; # ']);
34 my ($def,$w,$h)= ($1, $2+0, $3+0);
35 my @d= grep { m/./ } split /\s+/, $';
36 @d == $w*$h*3 or die "$d[0]|$d[1]|...|$d[$#d-1]|$d[$#d] ?";
40 $_ >= 0 or die "$_ ?";
41 $_ <= 255 or die "$_ ?";
43 my $ppm= "P3\n$w $h\n255\n";
45 for (my $y=0; $y<$h; $y++) {
46 for (my $x=0; $x<$w; $x++, $di+=3) {
47 #print STDERR ">$x,$y,$di,",scalar(@d),"<\n";
48 $ppm .= sprintf " %3d %3d %3d", @d[$di..$di+2];
53 my $summary= pipeval($ppm,
56 'pnmnorm -bpercent 40 -wpercent 10',
57 'pgmtopbm -threshold',
60 print STDERR ">$summary<\n";
63 # <ship-ahoy.ppm ppmtopgm | pnmscale -width 79 | pnmnorm -bpercent 40 -wpercent 10 | pgmtopbm -threshold | pbmtoascii | cut -c1-79
65 my $entry= "$def\n$ppm";
66 return ('',$def,$entry);
69 #---------- characters ----------
71 #---------- useful stuff ----------
74 my ($val, @cmds) = @_;
79 foreach my $cmd ('',@cmds) {
80 my $pipe= new IO::Pipe or die $!;
81 my $pid= fork(); defined $pid or die $!;
86 print $pipe $val or die $!;
89 open STDIN, '<&', $lastpipe or die $!;
90 open STDOUT, '>&', $pipe or die $!;
91 close $lastpipe or die $!;
92 close $pipe or die $!;
97 if ($lastpipe) { close $lastpipe or die $!; }
102 $!=0; { local ($/)=undef; $val= <$lastpipe>; }
103 defined $val or die $!;
104 $lastpipe->error and die $!; close $lastpipe or die $!;
106 foreach my $cmd ('(paste)', @cmds) {
107 my $pid= shift @pids;
108 waitpid($pid,0) == $pid or die "$pid $? $!";
109 $?==0 or $?==13 or die "$cmd $?";
110 print STDERR "OK $cmd\n";
115 #---------- main program ----------
117 my $path= path_info();
118 my $entry_in= param('entry');
119 defined $entry_in or die;
121 my $owner= `whoami`; $? and die $?;
125 if ($path =~ /(pixmap|char)/) {
131 my ($ctx,$def,$entry)= &{"parseentryin__$kind"}($entry_in);
135 Subject: yppsc dictionary update