# The SC PCTB client does this so that
use strict (qw(vars));
+use POSIX;
$CGI::POST_MAX= 65536;
$CGI::DISABLE_UPLOADS= 1;
$ppm .= "\n";
}
- my $icon= pipeval($ppm,
- 'ppmtopgm',
- 'pnmscale -xysize 156 80',
- 'pnmnorm -bpercent 40 -wpercent 20',
- 'pgmtopbm -threshold',
- 'pnminvert',
- 'pbmtoascii -2x4');
-
- my $whole= pipeval($ppm,
- 'ppmtopgm',
- 'pnmnorm -bpercent 40 -wpercent 20',
- 'pgmtopbm -threshold',
- 'pnminvert',
- 'pbmtoascii');
-
- my $entry= "$def\n$ppm";
- return ('',$def,$entry,$icon,$w,$whole);
+ return ('',$def,$ppm,$ppm,$def);
}
#---------- 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";
my $ppm= "P2\n$w $h\n1\n";
for (my $y=0; $y<$h; $y++) {
for (my $x=0; $x<$w; $x++) {
- $ppm .= sprintf " %d", !!($d[$x] & (1<<$y));
+ $ppm .= sprintf " %d", !($d[$x] & (1<<$y));
}
$ppm .= "\n";
}
- my $entry= sprintf "%d\n%s\n%s\n", $h,$ctx,$str;
- map { $entry .= sprintf "%x\n", $_; } @d;
+ my $key= join ' ', $ctx, map { sprintf "%x", $_; } @d;
-#print STDERR "[[[[\n$ppm\n]]]]";
-
- my $icon= pipeval($ppm,
-# "pnmscale -xysize 78 $h",
- 'pgmtopbm -threshold',
- 'pnminvert',
- 'pbmtoascii');
-
- return ("$ctx",$str,$entry, '',$w,$icon);
-}
-
-#---------- useful stuff ----------
-
-sub pipeval ($@) {
- my ($val, @cmds) = @_;
- my (@pids);
-
- my $lastpipe;
-
- foreach my $cmd ('',@cmds) {
- my $pipe= new IO::Pipe or die $!;
- my $pid= fork(); defined $pid or die $!;
-
- if (!$pid) {
- $pipe->writer();
- if (!$lastpipe) {
- print $pipe $val or die $!;
- exit 0;
- } else {
- open STDIN, '<&', $lastpipe or die $!;
- open STDOUT, '>&', $pipe or die $!;
- close $lastpipe or die $!;
- close $pipe or die $!;
- exec $cmd; die $!;
- }
- }
- $pipe->reader();
- if ($lastpipe) { close $lastpipe or die $!; }
- $lastpipe= $pipe;
- push @pids, $pid;
- }
-
- $!=0; { local ($/)=undef; $val= <$lastpipe>; }
- defined $val or die $!;
- $lastpipe->error and die $!; close $lastpipe or die $!;
-
- foreach my $cmd ('(paste)', @cmds) {
- my $pid= shift @pids;
- waitpid($pid,0) == $pid or die "$pid $? $!";
- $?==0 or $?==13 or die "$cmd $?";
- }
- return $val;
+ return ($ctx,$str,$ppm,$key,$str);
}
#---------- main program ----------
-my $path= path_info();
+my $dict= param('dict');
my $entry_in= param('entry');
defined $entry_in or die;
+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 $du=$ENV{'YPPSC_DICTUPDATES'};
chdir $du or die "$du $!"
if defined $du;
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)= &{"parseentryin__$kind"}($entry_in, @xa);
my $fn_t= "_update.$$-xxxxxxxxxxxxxxxx.tmp";
open F, "> $fn_t" or die "$fn_t $!";
(stat F) or die $!;
my $fn_i= sprintf "_update.$$-%016x.rdy", (stat _)[1];
-print F $whole or die $!;
-close F or die $!;
-rename $fn_t, $fn_i or die "$fn_t $fn_i $!";
-
-__END__
-
-$icon =~ s/^/ /mg;
-
-my $email= <<END
-To: $owner
-Subject: yppsc dictionary update
-
-Context: $kind $ctx
-Definition: $def
+print F "ypp-sc-tools dictionary update v1\n";
-$icon
-
-END
- ;
-
-$whole =~ s/(.*)\n/ sprintf "%-${width}s\n", $1 /mge;
-$whole =~ s/^/|/mg;
-$whole =~ s/\n/|\n/mg;
-$whole =~ s/^(.*)/ ",".('_' x $width).".\n".$1 /e;
-$whole =~ s/(.*)$/ $1."\n\`".('~' x $width)."'\n" /e;
-
-my $lw= 79;
-
-while ($whole =~ m/../) {
- my $lhs= $whole;
- $lhs =~ s/^(.{0,$lw}).*$/$1/mg;
- $whole =~ s/^.{1,$lw}//mg;
-#print STDERR "[[[[[$lhs########$whole]]]]]\n";
- $email .= $lhs;
+foreach my $v ($pirate,$dict,$ctx,$def,$image,$key,$val) {
+ printf F "%d\n", length($v) or die $!;
+ print F $v,"\n" or die $!;
}
-END
- ;
+close F or die $!;
+
+my @tm= localtime;
+my $tm= strftime "%Y-%m-%d %H:%M:%S %Z", @tm;
-my $cutline= "-8<-\n";
-$email .= $cutline.$entry.$cutline;
+open L, ">> _dict.log" or die $!;
+my $ll= sprintf "%s %-6s %-31s %s %s\n", $tm, $dict, $pirate, $fn_i, "submit";
+print L $ll or die $!;
+close L or die $!;
-print $email or die $!;
+rename $fn_t, $fn_i or die "$fn_t $fn_i $!";