|
|
67b279 |
--- psutils/psmerge.pl.new 2006-06-12 09:53:37.000000000 +0200
|
|
|
67b279 |
+++ psutils/psmerge.pl 2006-06-12 09:53:47.000000000 +0200
|
|
|
67b279 |
@@ -1,11 +1,19 @@
|
|
|
67b279 |
-@PERL@
|
|
|
67b279 |
+#!/usr/bin/perl
|
|
|
67b279 |
+eval 'exec perl -S $0 "$@"'
|
|
|
67b279 |
+ if (1 == 0);
|
|
|
67b279 |
+
|
|
|
67b279 |
# psmerge: merge PostScript files produced by same application and setup
|
|
|
67b279 |
-# usage: psmerge [-oout.ps] [-thorough] file1.ps file2.ps ...
|
|
|
67b279 |
+# usage: psmerge [-oout.ps] file1.ps file2.ps ...
|
|
|
67b279 |
#
|
|
|
67b279 |
# Copyright (C) Angus J. C. Duggan 1991-1995
|
|
|
67b279 |
# See file LICENSE for details.
|
|
|
67b279 |
+#
|
|
|
67b279 |
+# Unbroken (or, broken in a different way that at least sometimes
|
|
|
67b279 |
+# works) by Peter Williams 2003 <peter@newton.cx>
|
|
|
67b279 |
+
|
|
|
67b279 |
|
|
|
67b279 |
-$prog = ($0 =~ s=.*/==);
|
|
|
67b279 |
+$prog = $0;
|
|
|
67b279 |
+$prog =~ s=.*/==;
|
|
|
67b279 |
|
|
|
67b279 |
while ($ARGV[0] =~ /^-/) {
|
|
|
67b279 |
$_ = shift;
|
|
|
67b279 |
@@ -14,72 +22,75 @@
|
|
|
67b279 |
print STDERR "$prog: can't open $1 for output\n";
|
|
|
67b279 |
exit 1;
|
|
|
67b279 |
}
|
|
|
67b279 |
- } elsif (/^-t(horough)?$/) {
|
|
|
67b279 |
- $thorough = 1;
|
|
|
67b279 |
} else {
|
|
|
67b279 |
- print STDERR "Usage: $prog [-oout] [-thorough] file...\n";
|
|
|
67b279 |
+ print STDERR "Usage: $prog [-oout] file1 file2...\n";
|
|
|
67b279 |
exit 1;
|
|
|
67b279 |
}
|
|
|
67b279 |
}
|
|
|
67b279 |
|
|
|
67b279 |
$page = 0;
|
|
|
67b279 |
$first = 1;
|
|
|
67b279 |
+$seenpages = 0;
|
|
|
67b279 |
$nesting = 0;
|
|
|
67b279 |
|
|
|
67b279 |
-@header = ();
|
|
|
67b279 |
-$header = 1;
|
|
|
67b279 |
-
|
|
|
67b279 |
@trailer = ();
|
|
|
67b279 |
-$trailer = 0;
|
|
|
67b279 |
-
|
|
|
67b279 |
-@pages = ();
|
|
|
67b279 |
-@body = ();
|
|
|
67b279 |
-
|
|
|
67b279 |
-@resources = ();
|
|
|
67b279 |
-$inresource = 0;
|
|
|
67b279 |
+$trailermode = 0;
|
|
|
67b279 |
|
|
|
67b279 |
while (<>) {
|
|
|
67b279 |
- if (/^%%BeginFont:/ || /^%%BeginResource:/ || /^%%BeginProcSet:/) {
|
|
|
67b279 |
- $inresource = 1;
|
|
|
67b279 |
- push(@resources, $_);
|
|
|
67b279 |
- } elsif ($inresource) {
|
|
|
67b279 |
- push(@resources, $_);
|
|
|
67b279 |
- $inresource = 0 if /^%%EndFont/ || /^%%EndResource/ || /^%%EndProcSet/;
|
|
|
67b279 |
- } elsif (/^%%Page:/ && $nesting == 0) {
|
|
|
67b279 |
- $header = $trailer = 0;
|
|
|
67b279 |
- push(@pages, join("", @body)) if @body;
|
|
|
67b279 |
- $page++;
|
|
|
67b279 |
- @body = ("%%Page: ($page) $page\n");
|
|
|
67b279 |
- } elsif (/^%%Trailer/ && $nesting == 0) {
|
|
|
67b279 |
- push(@trailer, $_);
|
|
|
67b279 |
- push(@pages, join("", @body)) if @body;
|
|
|
67b279 |
- @body = ();
|
|
|
67b279 |
- $trailer = 1;
|
|
|
67b279 |
- $header = 0;
|
|
|
67b279 |
- } elsif ($header) {
|
|
|
67b279 |
- push(@trailer, $_);
|
|
|
67b279 |
- push(@pages, join("", @body)) if @body;
|
|
|
67b279 |
- @body = ();
|
|
|
67b279 |
- $trailer = 1;
|
|
|
67b279 |
- $header = 0;
|
|
|
67b279 |
- } elsif ($trailer) {
|
|
|
67b279 |
- if (/^%!/ || /%%EOF/) {
|
|
|
67b279 |
- $trailer = $first = 0;
|
|
|
67b279 |
- } elsif ($first) {
|
|
|
67b279 |
- push(@trailer, $_);
|
|
|
67b279 |
- }
|
|
|
67b279 |
- } elsif (/^%%BeginDocument/ || /^%%BeginBinary/ || /^%%BeginFile/) {
|
|
|
67b279 |
- push(@body, $_);
|
|
|
67b279 |
- $nesting++;
|
|
|
67b279 |
- } elsif (/^%%EndDocument/ || /^%%EndBinary/ || /^%%EndFile/) {
|
|
|
67b279 |
- push(@body, $_);
|
|
|
67b279 |
- $nesting--;
|
|
|
67b279 |
- } else {
|
|
|
67b279 |
- print $_ if $print;
|
|
|
67b279 |
- }
|
|
|
67b279 |
+ if ($seenpages == 0) {
|
|
|
67b279 |
+ if (/^%%Page:/) {
|
|
|
67b279 |
+ if ($nesting == 0) {
|
|
|
67b279 |
+ $seenpages = 1;
|
|
|
67b279 |
+ $page++;
|
|
|
67b279 |
+ print "%%Page: ($page) $page\n";
|
|
|
67b279 |
+ } else {
|
|
|
67b279 |
+ print $_;
|
|
|
67b279 |
+ }
|
|
|
67b279 |
+ } elsif ($first) {
|
|
|
67b279 |
+ if (/^%%Pages: /) {
|
|
|
67b279 |
+ print "%%Pages: (atend)\n";
|
|
|
67b279 |
+ } else {
|
|
|
67b279 |
+ print $_;
|
|
|
67b279 |
+ }
|
|
|
67b279 |
+ }
|
|
|
67b279 |
+ } elsif ($trailermode) {
|
|
|
67b279 |
+ if (/^%!/ || /%%EOF/) {
|
|
|
67b279 |
+ $seenpages = 0;
|
|
|
67b279 |
+ $first = 0;
|
|
|
67b279 |
+ $trailermode = 0;
|
|
|
67b279 |
+ } elsif ($first) {
|
|
|
67b279 |
+ push (@trailer, $_)
|
|
|
67b279 |
+ unless (/^%%Pages/);
|
|
|
67b279 |
+ }
|
|
|
67b279 |
+ } else {
|
|
|
67b279 |
+ if (/^%%Page:/) {
|
|
|
67b279 |
+ if ($nesting == 0) {
|
|
|
67b279 |
+ $seenpages = 1;
|
|
|
67b279 |
+ $page++;
|
|
|
67b279 |
+ print "%%Page: ($page) $page\n";
|
|
|
67b279 |
+ } else {
|
|
|
67b279 |
+ print $_;
|
|
|
67b279 |
+ }
|
|
|
67b279 |
+ } elsif (/^%%Trailer/ && $nesting == 0) {
|
|
|
67b279 |
+ $trailermode = 1;
|
|
|
67b279 |
+ } elsif (/^%%BeginDocument/ || /^%%BeginBinary/ || /^%%BeginFile/) {
|
|
|
67b279 |
+ push(@body, $_);
|
|
|
67b279 |
+ $nesting++;
|
|
|
67b279 |
+ print $_;
|
|
|
67b279 |
+ } elsif (/^%%EndDocument/ || /^%%EndBinary/ || /^%%EndFile/) {
|
|
|
67b279 |
+ push(@body, $_);
|
|
|
67b279 |
+ $nesting--;
|
|
|
67b279 |
+ print $_;
|
|
|
67b279 |
+ } else {
|
|
|
67b279 |
+ print $_;
|
|
|
67b279 |
+ }
|
|
|
67b279 |
+ }
|
|
|
67b279 |
}
|
|
|
67b279 |
|
|
|
67b279 |
+print "%%Trailer\n";
|
|
|
67b279 |
print @trailer;
|
|
|
67b279 |
+print "%%Pages: $page\n";
|
|
|
67b279 |
+print "%%EOF\n";
|
|
|
67b279 |
|
|
|
67b279 |
exit 0;
|
|
|
67b279 |
-@END@
|
|
|
67b279 |
+
|