$CGI::DISABLE_UPLOADS= 1;
use CGI qw/:standard -private_tempfiles/;
-
+use IO::Pipe;
+use IO::Handle;
#---------- pixmaps ----------
-sub parseentryin_pixmap ($) {
+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; # ']);
+ 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] ?";
$ppm .= "\n";
}
- ppmtopgm | pnmscale -width 79 | pnmnorm -bpercent 40 -wpercent 10 | pgmtopbm -threshold
+ my $summary= pipeval($ppm,
+ 'ppmtopgm',
+ 'pnmscale -width 79',
+ 'pnmnorm -bpercent 40 -wpercent 10',
+ 'pgmtopbm -threshold',
+ 'pbmtoascii'
+ );
+ print STDERR ">$summary<\n";
+
- <ship-ahoy.ppm ppmtopgm | pnmscale -width 79 | pnmnorm -bpercent 40 -wpercent 10 | pgmtopbm -threshold | pbmtoascii | cut -c1-79
+# <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 ----------
+#---------- 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 $?";
+print STDERR "OK $cmd\n";
+ }
+ return $val;
+}
+
#---------- main program ----------
my $path= path_info();
die "$path ?";
}
-my ($ctx,$def,$entry)= ${"parseentryin__$kind"}($entry_in);
+my ($ctx,$def,$entry)= &{"parseentryin__$kind"}($entry_in);
my $summary= <<END
To: $owner
END
;
-
-
-
- print $entry or die $!;
-} else {
- die "$path ?";
-}
-