summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/petri-nets/pn2pdf
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/latex/petri-nets/pn2pdf')
-rw-r--r--Master/texmf-dist/source/latex/petri-nets/pn2pdf102
1 files changed, 102 insertions, 0 deletions
diff --git a/Master/texmf-dist/source/latex/petri-nets/pn2pdf b/Master/texmf-dist/source/latex/petri-nets/pn2pdf
new file mode 100644
index 00000000000..38f2deda1eb
--- /dev/null
+++ b/Master/texmf-dist/source/latex/petri-nets/pn2pdf
@@ -0,0 +1,102 @@
+#!/usr/bin/perl
+
+## This file is part of the Petri-nets packages. See file README for
+## copyright notice.
+
+use strict;
+use Digest::MD5 qw(md5_hex);
+
+my $keep = 0;
+
+foreach my $job (@ARGV) {
+ ##
+ ## check argument
+ ##
+ if ($job =~ /^(-k|--keep)$/) {
+ $keep = 1;
+ next;
+ } elsif ($job =~ /^(-c|--clean)$/) {
+ $keep = 0;
+ next;
+ } elsif ($job =~ /^(-f|--force)$/) {
+ unlink "$job.sum" if -f "$job.sum";
+ next;
+ } elsif ($job =~ /^(-h|--help)$/) {
+ print "Usage: pn2pdf [OPTION]... DOC...\n";
+ print "Create Petri net figures from DOC.\n\n";
+ print " -k, --keep keep temporary files\n";
+ print " -c, --clean delete temporary files\n";
+ print " -f, --force force the rendering of all pictures\n";
+ print " -h, --help display this help and exit\n\n";
+ print "Report bugs to <pommereau\@univ-paris12.fr>\n";
+ exit 0;
+ }
+ ##
+ ## load MD5 sums if available
+ ##
+ my %sum = ();
+ if (-f "$job.sum") {
+ open SUM, "$job.sum"
+ or die "pn2pdf: unable to open $job.sum -- $!\n";
+ while (<SUM>) {
+ if (/(\d+)\s+(.*)/) {
+ $sum{$1} = $2;
+ } else {
+ warn "pn2pdf: invalid checksum in $job.sum\n";
+ }
+ }
+ close SUM;
+ }
+ ##
+ ## process file
+ ##
+ my $preamble = "";
+ open TEX, "$job.tex"
+ or die "pn2pdf: unable to open $job.tex -- $!\n";
+ open SUM, ">$job.sum"
+ or die "pn2pdf: unable to open $job.sum -- $!\n";
+ while (<TEX>) {
+ $preamble .= $_;
+ last if /\\begin\{document\}/;
+ $preamble =~ s/(\\begin\{document\}).*$/$1/;
+ }
+ $preamble .= "\\thispagestyle\{empty\}\n";
+ my $count = 0;
+ my $petrinet;
+ while (<TEX>) {
+ last if /^\\end\{document\}$/;
+ if (/(\\begin\{petrinet\}.*)/) {
+ $count++;
+ $petrinet = "$1\n";
+ while (<TEX>) {
+ $petrinet .= $_;
+ last if /\\end\{petrinet\}/;
+ }
+ $petrinet =~ s/(\\end\{petrinet\}).*$/$1\n/;
+ ##
+ ## create fig-file
+ ##
+ my $md5 = md5_hex ("$preamble$petrinet");
+ print SUM "$count $md5\n";
+ next if ($md5 eq $sum{$count}) && (-f "$job-fig$count.pdf");
+ open FIG, ">$job-fig$count.tex"
+ or die "pn2pdf: unable to open $job-fig$count.tex -- $!\n";
+ print FIG "$preamble$petrinet\\end\{document\}\n";
+ close FIG;
+ ##
+ ## process fig-file
+ ##
+ system "latex", "$job-fig$count";
+ system "dvips", ("-E", "-Pcmz", "-Pamz",
+ "-o", "$job-fig$count.eps",
+ "$job-fig$count");
+ system "epstopdf", "$job-fig$count.eps";
+ unlink ("$job-fig$count.tex", "$job-fig$count.log",
+ "$job-fig$count.aux", "$job-fig$count.dvi",
+ "$job-fig$count.eps") unless $keep;
+ }
+ }
+ close TEX;
+ close SUM;
+}
+