head     1.1;
branch   ;
access   ;
symbols  ;
locks    ; strict;
comment  @# @;


1.1
date     92.04.17.11.39.22;  author romig;  state Exp;
branches ;
next     ;


desc
@Merge a bunch of ps files into one big one.
@



1.1
log
@Initial revision
@
text
@#! /usr/local/bin/perl

$count = 0;			# page count, starts at 0

$usage = "usage: unite [-o outputfile]  file [file...]\n";
$options = "o:";

require 'yagrip.pl';

&getopt($options) ||
  die $usage;

if (defined($opt_o)) {
    open(STDOUT, ">$opt_o") ||
      die "cannot open $opt_o for writing ($!)\n";
}

if ($#ARGV < 0) {
    die $usage;
}

$filename = shift;
open(STDIN, "<$filename") || 
       die "cannot open $filename for reading ($!)\n";
print stderr "working on $filename\n";

&copy_prolog();
&copy_page();

close(STDIN);

while ($#ARGV >= 0) {
    $filename = shift;
    open(STDIN, "<$filename") || 
      die "cannot open $filename for reading ($!)\n";
print stderr "working on $filename\n";

    &skip_prolog();
    &copy_page();

    close(STDIN);
}

print "%%Trailer\n";
print "%%Pages: $count\n";

close(STDOUT);

exit(0);


sub copy_prolog {
    while (<STDIN>) {
	return if m/^%%Page:/;

	print $_;
    }
}

sub skip_prolog {
    while (<STDIN>) {
	return if m/^%%Page:/;
    }
}


sub copy_page {
    $count++;
    print "%%Page: $count $count\n";

    while (<STDIN>) {
	last if m/^%%Trailer/;

	print $_;
    }
}
@
