#!/usr/bin/perl -w # # This script is invoked when the YPP SC PCTB client phones home to # provide updated character set OCR data or updated screenshot pixmap # interpretation (island name) data. # # The client will also phone home anyway to fetch the latest parsedb # before # # This allows me (the operator of the SC server) to: # - review the choices made by the user # - if they are correct, incorporate them in the next client version # - if they are wrong, incorporate fixes of them, or contradictions of them, # in # The information reported # The SC PCTB client does this so that use strict (qw(vars)); $CGI::POST_MAX= 65536; $CGI::DISABLE_UPLOADS= 1; use CGI qw/:standard -private_tempfiles/; use IPC::Open2; use IO::Handle; use File::Temp; #---------- pixmaps ---------- sub parseentryin__pixmap ($) { my ($entry_in) = @_; $entry_in =~ m/^(\w+ \- \w[-+'"#! 0-9a-z]*)\nP3\n([1-9]\d{1,3}) ([1-9]\d{1,3})\n255\n/s or die; # ']); my ($def,$w,$h)= ($1, $2+0, $3+0); my @d= grep { m/./ } split /\s+/, $'; @d == $w*$h*3 or die "$d[0]|$d[1]|...|$d[$#d-1]|$d[$#d] ?"; map { m/\D/ and die "$& ?"; $_ += 0; $_ >= 0 or die "$_ ?"; $_ <= 255 or die "$_ ?"; } @d; my $ppm= "P3\n$w $h\n255\n"; my $di=0; for (my $y=0; $y<$h; $y++) { for (my $x=0; $x<$w; $x++, $di+=3) { #print STDERR ">$x,$y,$di,",scalar(@d),"<\n"; $ppm .= sprintf " %3d %3d %3d", @d[$di..$di+2]; } $ppm .= "\n"; } my $summary= pipeval($ppm, 'set -x; cat >&2', 'ppmtopgm', 'pnmscale -width 79', 'pnmnorm -bpercent 40 -wpercent 10', 'pgmtopbm -threshold'); print STDERR ">$summary<\n"; # ; print STDERR ">$_<\n"; foreach my $cmd (@cmds) { my $newf; print STDERR "$cmd | $f\n"; push @pids, open2($newf, "<& $f", $cmd); # if (@pids>1) { close $f or die $!; } print STDERR "$cmd | $f $newf @pids\n"; $f= $newf; } $!=0; { local ($/)=undef; $val= <$f>; } defined $val or die $!; $f->error and die $!; close $f or die $!; waitpid($paste_child,0) == $paste_child or die "paste $? $!"; $?==0 or $?==13 or die "paste $?"; close PIPEVAL_PASTE or die $!; foreach my $cmd (@cmds) { my $pid= shift @pids; waitpid($pid,0) == $pid or die "$pid $? $!"; $?==0 or $?==13 or die "$cmd $?"; } return $val; } #---------- main program ---------- my $path= path_info(); my $entry_in= param('entry'); defined $entry_in or die; my $owner= `whoami`; $? and die $?; my $kind; if ($path =~ /(pixmap|char)/) { $kind=$1; } else { die "$path ?"; } my ($ctx,$def,$entry)= &{"parseentryin__$kind"}($entry_in); my $summary= <