summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/psutils/psmerge.pl
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-04-07 18:42:53 +0000
committerKarl Berry <karl@freefriends.org>2013-04-07 18:42:53 +0000
commitedb2136c619d2c59bcb6dfd431c4c7636ff8913d (patch)
tree8aa04dd27bee1b2f2f9b3fd45dab41cf7771f82e /Master/texmf-dist/scripts/psutils/psmerge.pl
parentb3efa3bb4509e7bd53d737fb729d0d92a76f1f98 (diff)
texmf -> texmf-dist: scripts
git-svn-id: svn://tug.org/texlive/trunk@29719 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/psutils/psmerge.pl')
-rwxr-xr-xMaster/texmf-dist/scripts/psutils/psmerge.pl86
1 files changed, 86 insertions, 0 deletions
diff --git a/Master/texmf-dist/scripts/psutils/psmerge.pl b/Master/texmf-dist/scripts/psutils/psmerge.pl
new file mode 100755
index 00000000000..ff1b8039b4d
--- /dev/null
+++ b/Master/texmf-dist/scripts/psutils/psmerge.pl
@@ -0,0 +1,86 @@
+#!/usr/bin/env perl
+# psmerge: merge PostScript files produced by same application and setup
+# usage: psmerge [-oout.ps] [-thorough] file1.ps file2.ps ...
+#
+# Copyright (C) Angus J. C. Duggan 1991-1995
+# See file LICENSE for details.
+
+$0 =~ s=.*/==;
+$prog = $0;
+
+while ($ARGV[0] =~ /^-/) {
+ $_ = shift;
+ if (/^-o(.+)/) {
+ if (!close(STDOUT) || !open(STDOUT, ">$1")) {
+ print STDERR "$prog: can't open $1 for output\n";
+ exit 1;
+ }
+ } elsif (/^-t(horough)?$/) {
+ $thorough = 1;
+ } else {
+ print STDERR "Usage: $prog [-oout] [-thorough] file...\n";
+ exit 1;
+ }
+}
+
+$page = 0;
+$first = 1;
+$nesting = 0;
+
+@header = ();
+$header = 1;
+
+@trailer = ();
+$trailer = 0;
+
+@pages = ();
+@body = ();
+
+@resources = ();
+$inresource = 0;
+
+while (<>) {
+ if (/^%%BeginFont:/ || /^%%BeginResource:/ || /^%%BeginProcSet:/) {
+ $inresource = 1;
+ push(@resources, $_);
+ } elsif ($inresource) {
+ push(@resources, $_);
+ $inresource = 0 if /^%%EndFont/ || /^%%EndResource/ || /^%%EndProcSet/;
+ } elsif (/^%%Page:/ && $nesting == 0) {
+ $header = $trailer = 0;
+ push(@pages, join("", @body)) if @body;
+ $page++;
+ @body = ("%%Page: ($page) $page\n");
+ } elsif (/^%%Trailer/ && $nesting == 0) {
+ push(@trailer, $_);
+ push(@pages, join("", @body)) if @body;
+ @body = ();
+ $trailer = 1;
+ $header = 0;
+ } elsif ($header) {
+ push(@trailer, $_);
+ push(@pages, join("", @body)) if @body;
+ @body = ();
+ $trailer = 1;
+ $header = 0;
+ } elsif ($trailer) {
+ if (/^%!/ || /%%EOF/) {
+ $trailer = $first = 0;
+ } elsif ($first) {
+ push(@trailer, $_);
+ }
+ } elsif (/^%%BeginDocument/ || /^%%BeginBinary/ || /^%%BeginFile/) {
+ push(@body, $_);
+ $nesting++;
+ } elsif (/^%%EndDocument/ || /^%%EndBinary/ || /^%%EndFile/) {
+ push(@body, $_);
+ $nesting--;
+ } else {
+ print $_ if $print;
+ }
+}
+
+print @trailer;
+
+exit 0;
+