chiark / gitweb /
WIP yppsc-parsedb-updatereceiver; can convert pixmap to email
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 19 Jun 2009 17:43:54 +0000 (18:43 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Fri, 19 Jun 2009 17:43:54 +0000 (18:43 +0100)
pctb/yppsc-parsedb-updatereceiver

index 5d5585ef38bdc4324337c77d2dddb5e2efbc0573..bdc76c26c9748acfb9aa1171f6924ed869a37074 100755 (executable)
@@ -50,20 +50,23 @@ sub parseentryin__pixmap ($) {
        $ppm .= "\n";
     }
 
-    my $summary= pipeval($ppm,
+    my $icon= pipeval($ppm,
                         'ppmtopgm',
-                        'pnmscale -width 79',
-                        'pnmnorm -bpercent 40 -wpercent 10',
+                        'pnmscale -xysize 156 80',
+                        'pnmnorm -bpercent 40 -wpercent 20',
                         'pgmtopbm -threshold',
-                        'pbmtoascii'
-                        );
-    print STDERR ">$summary<\n";
+                        'pnminvert',
+                        'pbmtoascii -2x4');
+
+    my $whole= pipeval($ppm,
+                      'ppmtopgm',
+                      'pnmnorm -bpercent 40 -wpercent 20',
+                      'pgmtopbm -threshold',
+                      'pnminvert',
+                      'pbmtoascii');
     
-
-# <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);
+    return ('',$def,$entry,$icon,$w,$whole);
 }
 
 #---------- characters ----------
@@ -107,7 +110,6 @@ sub pipeval ($@) {
        my $pid= shift @pids;
        waitpid($pid,0) == $pid or die "$pid $? $!";
        $?==0 or $?==13 or die "$cmd $?";
-print STDERR "OK $cmd\n";
     }
     return $val;
 }
@@ -119,6 +121,7 @@ my $entry_in= param('entry');
 defined $entry_in or die;
 
 my $owner= `whoami`; $? and die $?;
+chomp $owner;
 
 my $kind;
 
@@ -128,14 +131,42 @@ if ($path =~ /(pixmap|char)/) {
     die "$path ?";
 }
 
-my ($ctx,$def,$entry)= &{"parseentryin__$kind"}($entry_in);
+my ($ctx,$def,$entry,$icon,$width,$whole)= &{"parseentryin__$kind"}($entry_in);
+
+$icon =~ s/^/ /mg;
 
-my $summary= <<END
+my $email= <<END
 To: $owner
 Subject: yppsc dictionary update
 
 Context:    $kind $ctx
 Definition: $def
 
+$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;
+}
+
 END
     ;
+
+my $cutline= "-8<-\n";
+$email .= $cutline.$entry.$cutline;
+
+print $email or die $!;