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