File: psmerge.pl

package info (click to toggle)
texlive-bin 2009-8
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 231,976 kB
  • ctags: 165,663
  • sloc: ansic: 1,113,212; cpp: 454,597; sh: 49,189; perl: 43,889; makefile: 15,564; python: 11,825; xml: 7,446; lisp: 6,494; asm: 4,361; lex: 3,571; java: 3,569; pascal: 2,487; yacc: 2,451; exp: 2,031; ruby: 2,012; ada: 1,681; objc: 1,362; cs: 879; sed: 519; csh: 47; tcl: 45; awk: 35
file content (85 lines) | stat: -rw-r--r-- 1,943 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
@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.

$prog = ($0 =~ s=.*/==);

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;
@END@