chiark / gitweb /
WIP update receiver script
[ypp-sc-tools.db-test.git] / pctb / yppsc-parsedb-updatereceiver
diff --git a/pctb/yppsc-parsedb-updatereceiver b/pctb/yppsc-parsedb-updatereceiver
new file mode 100755 (executable)
index 0000000..17ba868
--- /dev/null
@@ -0,0 +1,96 @@
+#!/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/;
+
+
+#---------- pixmaps ----------
+
+sub parseentryin_pixmap ($) {
+    my ($entry_in) = @_;
+    $entry_in =~
+       m/^(\w+ \- \w[-+'"#! 0-9a-z]*\w)\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";
+    }
+
+    ppmtopgm | pnmscale -width 79 | pnmnorm -bpercent 40 -wpercent 10 | pgmtopbm -threshold
+
+ <ship-ahoy.ppm ppmtopgm | pnmscale -width 79 | pnmnorm -bpercent 40 -wpercent 10 | pgmtopbm -threshold | pbmtoascii | cut -c1-79
+       
+    my $entry= "$def\n$ppm";
+    return ('',$def,$entry);
+}
+
+#---------- characters ----------
+
+#---------- 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= <<END
+To: $owner
+Subject: yppsc dictionary update
+
+Context:    $kind $ctx
+Definition: $def
+
+END
+    ;
+
+
+    
+    print $entry or die $!;
+} else {
+    die "$path ?";
+}
+