tex/prn2eps.pl
author Shingo W. Kagami
Mon, 13 Sep 2010 03:54:21 +0900
changeset 4 8b90d57759c9
permissions -rw-r--r--
Add ppt2eps tool set.
     1 #!/usr/bin/env perl
     2 
     3 use strict;
     4 use Digest::MD5 qw(md5_hex);
     5 my $f_remove_unused_eps = 0;
     6 
     7 if (@ARGV != 1) {
     8     die 'wrong number of argument';
     9 }
    10 my $prnfile = $ARGV[0];    
    11 
    12 my $basename = $prnfile; $basename =~ s/\.prn$//;
    13 my $dirname = $prnfile; $dirname =~ s![^/]*$!!;
    14 my $notedumpfile  = $basename . '.note.txt';
    15 my $md5file  = $basename . '.md5';
    16 
    17 my %prev_md5 = ();
    18 my %curr_md5 = ();
    19 
    20 if (-e $md5file) {
    21     open(MD5, $md5file) or die;
    22     while (<MD5>) {
    23         if (/^([01-9a-f]+)\s+([-_01-9a-zA-Z]+)/) {
    24             $prev_md5{$1} = $2;
    25         }
    26     }
    27     close(MD5);
    28 }
    29 
    30 my $counter = 1;
    31 open(NOTES, $notedumpfile) or die;
    32 while (<NOTES>) {
    33     if (/\014/) {
    34         $counter++;
    35     }
    36     if (/\@file=([-_01-9a-zA-Z]+)/) {
    37         my $epsbase = $1;
    38         my $page = $counter;
    39         my $pngfile = $basename . '.ppt.tmp_slide' . $page . '.png';
    40         my $md5;
    41         if (-e $pngfile) {
    42             $md5 = md5_hex(`cat $pngfile`);
    43             $curr_md5{$md5} = $epsbase;
    44         } else { # can't happen
    45             die "no png file: $pngfile";
    46         }
    47 
    48         if (exists $prev_md5{$md5}) {
    49             if ($prev_md5{$md5} eq $epsbase) {
    50                 # not changed
    51                 delete $prev_md5{$md5};
    52             } else {
    53                 system("mv $dirname$prev_md5{$md5}.eps $dirname$epsbase.eps");
    54                 delete $prev_md5{$md5};                
    55             }
    56         } else {
    57             system("psselect $page $prnfile > $dirname$epsbase.ps");
    58             system("ps2eps -R + -B -f $dirname$epsbase.ps");
    59             system("ps2eps -C $dirname$epsbase.eps");
    60             system("mv $dirname$epsbase.eps.eps $dirname$epsbase.eps");
    61             system("rm $dirname$epsbase.ps");
    62         }
    63     }
    64 }
    65 close(NOTES);
    66 
    67 if ($f_remove_unused_eps) {
    68     # to be implemented
    69 }
    70 
    71 open(MD5, '>', $md5file) or die;
    72 foreach my $m (keys %curr_md5) {
    73     print MD5 $m . "\t" . $curr_md5{$m} . "\r\n";
    74 }
    75 close(MD5);
    76 system("rm " . $basename . '.ppt.tmp_slide*.png');