Shingo@4: #!/usr/bin/env perl Shingo@4: Shingo@4: use strict; Shingo@4: use Digest::MD5 qw(md5_hex); Shingo@4: my $f_remove_unused_eps = 0; Shingo@4: Shingo@4: if (@ARGV != 1) { Shingo@4: die 'wrong number of argument'; Shingo@4: } Shingo@4: my $prnfile = $ARGV[0]; Shingo@4: Shingo@4: my $basename = $prnfile; $basename =~ s/\.prn$//; Shingo@4: my $dirname = $prnfile; $dirname =~ s![^/]*$!!; Shingo@4: my $notedumpfile = $basename . '.note.txt'; Shingo@4: my $md5file = $basename . '.md5'; Shingo@4: Shingo@4: my %prev_md5 = (); Shingo@4: my %curr_md5 = (); Shingo@4: Shingo@4: if (-e $md5file) { Shingo@4: open(MD5, $md5file) or die; Shingo@4: while () { Shingo@4: if (/^([01-9a-f]+)\s+([-_01-9a-zA-Z]+)/) { Shingo@4: $prev_md5{$1} = $2; Shingo@4: } Shingo@4: } Shingo@4: close(MD5); Shingo@4: } Shingo@4: Shingo@4: my $counter = 1; Shingo@4: open(NOTES, $notedumpfile) or die; Shingo@4: while () { Shingo@4: if (/\014/) { Shingo@4: $counter++; Shingo@4: } Shingo@4: if (/\@file=([-_01-9a-zA-Z]+)/) { Shingo@4: my $epsbase = $1; Shingo@4: my $page = $counter; Shingo@4: my $pngfile = $basename . '.ppt.tmp_slide' . $page . '.png'; Shingo@4: my $md5; Shingo@4: if (-e $pngfile) { Shingo@4: $md5 = md5_hex(`cat $pngfile`); Shingo@4: $curr_md5{$md5} = $epsbase; Shingo@4: } else { # can't happen Shingo@4: die "no png file: $pngfile"; Shingo@4: } Shingo@4: Shingo@4: if (exists $prev_md5{$md5}) { Shingo@4: if ($prev_md5{$md5} eq $epsbase) { Shingo@4: # not changed Shingo@4: delete $prev_md5{$md5}; Shingo@4: } else { Shingo@4: system("mv $dirname$prev_md5{$md5}.eps $dirname$epsbase.eps"); Shingo@4: delete $prev_md5{$md5}; Shingo@4: } Shingo@4: } else { Shingo@4: system("psselect $page $prnfile > $dirname$epsbase.ps"); Shingo@4: system("ps2eps -R + -B -f $dirname$epsbase.ps"); Shingo@4: system("ps2eps -C $dirname$epsbase.eps"); Shingo@4: system("mv $dirname$epsbase.eps.eps $dirname$epsbase.eps"); Shingo@4: system("rm $dirname$epsbase.ps"); Shingo@4: } Shingo@4: } Shingo@4: } Shingo@4: close(NOTES); Shingo@4: Shingo@4: if ($f_remove_unused_eps) { Shingo@4: # to be implemented Shingo@4: } Shingo@4: Shingo@4: open(MD5, '>', $md5file) or die; Shingo@4: foreach my $m (keys %curr_md5) { Shingo@4: print MD5 $m . "\t" . $curr_md5{$m} . "\r\n"; Shingo@4: } Shingo@4: close(MD5); Shingo@4: system("rm " . $basename . '.ppt.tmp_slide*.png');