#!/usr/bin/perl -i ########################################################################### # This file is part of the MPATTERN package # # mpp: Postprocessing MetaPost output files in which patterns were used # # Author: Piotr Bolek # version: 0.2 (Sep 25, 1998) # # $Id: mpp,v 1.3 1998/09/25 10:49:30 piotrek Exp $ ########################################################################### $file=shift; ($logfile = $file . ".log") =~ s/\.mp\.log/.log/; $file =~ s/\.mp$//; system("mpost $file"); open LOG, $logfile; while() { if (/Pattern:(\d+)/) { push @pictures, $1; } } print STDERR "Postprocessing patterns"; for $i (@pictures) { $newfile="$file.$i"; print STDERR "."; $oldfile="$file.p!!"; rename($newfile,$oldfile); open IN, $oldfile; open OUT, ">$newfile"; $output = $fonts = ""; LINE: while(){ if((/^%%EndProlog\s*$/../^%%EOF\s*$/) && /%*Font:/) { $fonts .= $_; next LINE; } if(/^% Pattern:(0\.[0-9]+):(.*)/) { $pattern{$1}=$2; # print STDERR "\$pattern{$1}=$2\n"; } if(/^ (0\.[0-9]+) setgray/ && (defined $pattern{$1})) { s"^ (0\.[0-9]+).*"%$&\n$pattern{$1} setpattern"; } $output .= $_; } $output =~ s/%%EndProlog/$fonts$&/; print OUT $output; unlink $oldfile; } print STDERR "\n";