tex/prn2eps.pl
changeset 4 8b90d57759c9
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tex/prn2eps.pl	Mon Sep 13 03:54:21 2010 +0900
     1.3 @@ -0,0 +1,76 @@
     1.4 +#!/usr/bin/env perl
     1.5 +
     1.6 +use strict;
     1.7 +use Digest::MD5 qw(md5_hex);
     1.8 +my $f_remove_unused_eps = 0;
     1.9 +
    1.10 +if (@ARGV != 1) {
    1.11 +    die 'wrong number of argument';
    1.12 +}
    1.13 +my $prnfile = $ARGV[0];    
    1.14 +
    1.15 +my $basename = $prnfile; $basename =~ s/\.prn$//;
    1.16 +my $dirname = $prnfile; $dirname =~ s![^/]*$!!;
    1.17 +my $notedumpfile  = $basename . '.note.txt';
    1.18 +my $md5file  = $basename . '.md5';
    1.19 +
    1.20 +my %prev_md5 = ();
    1.21 +my %curr_md5 = ();
    1.22 +
    1.23 +if (-e $md5file) {
    1.24 +    open(MD5, $md5file) or die;
    1.25 +    while (<MD5>) {
    1.26 +        if (/^([01-9a-f]+)\s+([-_01-9a-zA-Z]+)/) {
    1.27 +            $prev_md5{$1} = $2;
    1.28 +        }
    1.29 +    }
    1.30 +    close(MD5);
    1.31 +}
    1.32 +
    1.33 +my $counter = 1;
    1.34 +open(NOTES, $notedumpfile) or die;
    1.35 +while (<NOTES>) {
    1.36 +    if (/\014/) {
    1.37 +        $counter++;
    1.38 +    }
    1.39 +    if (/\@file=([-_01-9a-zA-Z]+)/) {
    1.40 +        my $epsbase = $1;
    1.41 +        my $page = $counter;
    1.42 +        my $pngfile = $basename . '.ppt.tmp_slide' . $page . '.png';
    1.43 +        my $md5;
    1.44 +        if (-e $pngfile) {
    1.45 +            $md5 = md5_hex(`cat $pngfile`);
    1.46 +            $curr_md5{$md5} = $epsbase;
    1.47 +        } else { # can't happen
    1.48 +            die "no png file: $pngfile";
    1.49 +        }
    1.50 +
    1.51 +        if (exists $prev_md5{$md5}) {
    1.52 +            if ($prev_md5{$md5} eq $epsbase) {
    1.53 +                # not changed
    1.54 +                delete $prev_md5{$md5};
    1.55 +            } else {
    1.56 +                system("mv $dirname$prev_md5{$md5}.eps $dirname$epsbase.eps");
    1.57 +                delete $prev_md5{$md5};                
    1.58 +            }
    1.59 +        } else {
    1.60 +            system("psselect $page $prnfile > $dirname$epsbase.ps");
    1.61 +            system("ps2eps -R + -B -f $dirname$epsbase.ps");
    1.62 +            system("ps2eps -C $dirname$epsbase.eps");
    1.63 +            system("mv $dirname$epsbase.eps.eps $dirname$epsbase.eps");
    1.64 +            system("rm $dirname$epsbase.ps");
    1.65 +        }
    1.66 +    }
    1.67 +}
    1.68 +close(NOTES);
    1.69 +
    1.70 +if ($f_remove_unused_eps) {
    1.71 +    # to be implemented
    1.72 +}
    1.73 +
    1.74 +open(MD5, '>', $md5file) or die;
    1.75 +foreach my $m (keys %curr_md5) {
    1.76 +    print MD5 $m . "\t" . $curr_md5{$m} . "\r\n";
    1.77 +}
    1.78 +close(MD5);
    1.79 +system("rm " . $basename . '.ppt.tmp_slide*.png');