X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;f=pctb%2Fdictionary-update-receiver;h=078b9f8c312ffd300d6bbf205b743a672b7937f8;hb=9739f45fc783a87f02d1f435cf04fde3899ad4c7;hp=9132c4e9d22036ab35a249ffbe8e54d388666662;hpb=6bc2ac751dfd2cd3633e94388b6c1f5a52abb5ae;p=ypp-sc-tools.web-live.git diff --git a/pctb/dictionary-update-receiver b/pctb/dictionary-update-receiver index 9132c4e..078b9f8 100755 --- a/pctb/dictionary-update-receiver +++ b/pctb/dictionary-update-receiver @@ -17,6 +17,7 @@ # The SC PCTB client does this so that use strict (qw(vars)); +use POSIX; $CGI::POST_MAX= 65536; $CGI::DISABLE_UPLOADS= 1; @@ -30,7 +31,7 @@ use IO::Handle; 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; # ']); + 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] ?"; @@ -64,17 +65,18 @@ sub parseentryin__pixmap ($) { 'pgmtopbm -threshold', 'pnminvert', 'pbmtoascii'); - + my $entry= "$def\n$ppm"; - return ('',$def,$entry,$icon,$w,$whole); + + return ('',$def,$ppm,$ppm,$def, $w,$icon,$whole,$entry); } #---------- characters ---------- -sub parseentryin__char ($) { - my ($ei) = @_; - $ei =~ m/^([1-9]\d{0,2})\n(Digit|Upper|Lower)\n((?:[-&\'A-F0-9a-f ]|\x20)+)\n/s or die; - my ($h,$ctx,$str)= ($1+0,$2,$3); +sub parseentryin__char ($$) { + my ($ei,$h) = @_; + $ei =~ m/^(Digit|Upper|Lower)\n((?:[-&\'A-F0-9a-f ]|\x20)+)\n/s or die; + my ($ctx,$str)= ($1,$2); #print STDERR ">$'<\n"; my @d= grep { m/./ } split /\n/, $'; #print STDERR ">@d<\n"; @@ -88,24 +90,27 @@ sub parseentryin__char ($) { } @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++) { - $ppm .= sprintf " %d", !!($d[$x] & (1<<$y)); + my $pix= !($d[$x] & (1<<$y)); + $ppm .= sprintf " %d", $pix; + $whole .= $pix ? ' ' : '<>'; } $ppm .= "\n"; + $whole .= "\n"; } - my $entry= sprintf "%d\n%s\n%s\n", $h,$ctx,$str; - map { $entry .= sprintf "%x\n", $_; } @d; - -#print STDERR "[[[[\n$ppm\n]]]]"; + map { $_= sprintf "%x", $_; } @d; + my $key= join ' ', $ctx, @d; - my $icon= pipeval($ppm, -# "pnmscale -xysize 78 $h", - 'pgmtopbm -threshold', - 'pnminvert', - 'pbmtoascii'); +# my $whole= pipeval($ppm, +# "pnmscale 2", +# 'pgmtopbm -threshold', +# 'pbmtoascii'); - return ("$ctx",$str,$entry, '',$w,$icon); + my $entry= "$ctx\n$str\n". join("\n", @d). "\n"; + + return ($ctx,$str,$ppm,$key,$str, $w*2,'',$whole,$entry); } #---------- useful stuff ---------- @@ -151,39 +156,64 @@ sub pipeval ($@) { return $val; } -#---------- main program ---------- +#========== main program ========== -my $path= path_info(); +#---------- determine properties of the submission ---------- + +my $dict= param('dict'); my $entry_in= param('entry'); defined $entry_in or die; -my $owner= `whoami`; $? and die $?; -chomp $owner; +my $ocean= param('ocean'); +my $pirate= param('pirate'); +if (defined $ocean && defined $pirate) { + $pirate= "$ocean - $pirate"; +} else { + $pirate= $ENV{'REMOTE_ADDR'}; + my $fwdf= $ENV{'HTTP_X_FORWARDED_FOR'}; + if (defined $fwdf) { + $fwdf =~ s/\s//g; + $fwdf =~ s/[^0-9.,]/?/g; + $pirate= "$fwdf,$pirate"; + } +} my $kind; +my @xa; -if ($path =~ /(pixmap|char)/) { - $kind=$1; +if ($dict =~ m/^pixmap$/) { + $kind= $&; +} elsif ($dict =~ m/^(char)([1-9]\d?)$/) { + ($kind,@xa)= ($1,$2); } else { - die "$path ?"; + die "$dict ?"; } +$dict= $&; -my ($ctx,$def,$entry,$icon,$width,$whole)= &{"parseentryin__$kind"}($entry_in); +my ($ctx,$def,$image,$key,$val, $width,$icon,$whole,$entry)= + &{"parseentryin__$kind"}($entry_in, @xa); -$icon =~ s/^/ /mg; +#---------- compute the email to send ---------- + +my $whoami= `whoami`; $? and die $?; +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"; + +foreach my $v ($pirate,$dict,$ctx,$def,$image,$key,$val) { + printf F "%d\n", length($v) or die $!; + print F $v,"\n" or die $!; +} + +close F or die $!; + +my @tm= localtime; +my $tm= strftime "%Y-%m-%d %H:%M:%S %Z", @tm; + +open L, ">> _dict.log" or die $!; +my $ll= sprintf "%s %-6s %-31s %s", $tm, $dict, $pirate, $fn_i; + +#---------- commit everything ---------- + +print L "$ll submit\n" or die $!; +L->flush or die $!; + +if (eval { + + open S, "|sendmail -odb -oee -oi -t" or die $!; + print S $email or die $!; + $!=0; $?=0; close S or die $!; $? and die $?; + + rename $fn_t, $fn_i or die "$fn_t $fn_i $!"; + + 1; +}) { + print L "$ll stored\n" or die $!; +} else { + print L "$ll ERROR! $@\n" or die $!; +} +close L or die $!; + +print header('text/plain'), "$fn_i\n" or die $!;