chiark / gitweb /
WIP update receiver script
[ypp-sc-tools.main.git] / pctb / yppsc-parsedb-updatereceiver
1 #!/usr/bin/perl -w
2 #
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.
6 #
7 # The client will also phone home anyway to fetch the latest parsedb
8 # before 
9 #
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,
14 #      in
15
16 # The information reported 
17 # The SC PCTB client does this so that 
18
19 use strict (qw(vars));
20
21 $CGI::POST_MAX= 65536;
22 $CGI::DISABLE_UPLOADS= 1;
23
24 use CGI qw/:standard -private_tempfiles/;
25
26
27 #---------- pixmaps ----------
28
29 sub parseentryin_pixmap ($) {
30     my ($entry_in) = @_;
31     $entry_in =~
32         m/^(\w+ \- \w[-+'"#! 0-9a-z]*\w)\nP3\n([1-9]\d{1,3}) ([1-9]\d{1,3})\n255\n/s or die; # ']);
33     my ($def,$w,$h)= ($1, $2+0, $3+0);
34     my @d= grep { m/./ } split /\s+/, $';
35     @d == $w*$h*3 or die "$d[0]|$d[1]|...|$d[$#d-1]|$d[$#d] ?";
36     map {
37         m/\D/ and die "$& ?";
38         $_ += 0;
39         $_ >= 0 or die "$_ ?";
40         $_ <= 255 or die "$_ ?";
41     } @d;
42     my $ppm= "P3\n$w $h\n255\n";
43     my $di=0;
44     for (my $y=0; $y<$h; $y++) {
45         for (my $x=0; $x<$w; $x++, $di+=3) {
46 #print STDERR ">$x,$y,$di,",scalar(@d),"<\n";
47             $ppm .= sprintf "  %3d %3d %3d", @d[$di..$di+2];
48         }
49         $ppm .= "\n";
50     }
51
52     ppmtopgm | pnmscale -width 79 | pnmnorm -bpercent 40 -wpercent 10 | pgmtopbm -threshold
53
54  <ship-ahoy.ppm ppmtopgm | pnmscale -width 79 | pnmnorm -bpercent 40 -wpercent 10 | pgmtopbm -threshold | pbmtoascii | cut -c1-79
55         
56     my $entry= "$def\n$ppm";
57     return ('',$def,$entry);
58 }
59
60 #---------- characters ----------
61
62 #---------- main program ----------
63
64 my $path= path_info();
65 my $entry_in= param('entry');
66 defined $entry_in or die;
67
68 my $owner= `whoami`; $? and die $?;
69
70 my $kind;
71
72 if ($path =~ /(pixmap|char)/) {
73     $kind=$1;
74 } else {
75     die "$path ?";
76 }
77
78 my ($ctx,$def,$entry)= ${"parseentryin__$kind"}($entry_in);
79
80 my $summary= <<END
81 To: $owner
82 Subject: yppsc dictionary update
83
84 Context:    $kind $ctx
85 Definition: $def
86
87 END
88     ;
89
90
91     
92     print $entry or die $!;
93 } else {
94     die "$path ?";
95 }
96