[comp.lang.postscript] Question about Concatenating PS Files

grantw@zooid.Eng.Sun.COM (Grant Williamson) (06/29/90)

I want to take an arbitary number of PostScript files and concatenate 
them together for subsequent processing by various PostScript programs.

Based on a few tests and my *very* limited knowledge of PostScript, 
I've reached the conclusion that merely concatenating the two (or more)
files together without some sort of re-structuring is *not* acceptable.  

The (multi-part) question is:

   1. Is this even a feasible concept (concatenation of PostScript files)?

   2. If so, I would imagine that a filter should be written which 
      would restructure the concatenated contents into something that 
      looks like a single cohesive document.  Do you think this filter 
      would be difficult to write in a robust fashion (so that it 
      won't fail for non-trivial PostScript files)?

   3. If a generalized filter isn't an option, is there perhaps
      some way to reset all PostScript parameters at the beginning
      of each new document appearing in the concatenated file?

If you can give me any pointers, hints, references, code ;^), please
do so by sending e-mail to grantw@sun.com.

Your help is greatly appreciated!
--

-Grant

zben@umd5.umd.edu (Ben Cranston) (06/30/90)

In article <138052@sun.Eng.Sun.COM> grantw@zooid.Eng.Sun.COM 
(Grant Williamson) writes:

> I want to take an arbitary number of PostScript files and concatenate 
> them together for subsequent processing by various PostScript programs.

Yes, I know the guy explicitly asked for email, and in fact I typed this
entire message in as an email message, but as I was about to commit it I
thought that the concept of PostScript save is something that everybody
could profit from.  So, I killed the mailer and am posting it instead.
Mea culpa.

Here's something I wrote that handles a real worst case scenario, multiple
Macintosh command-f files!  I did multiple technical notes with it.

#! /bin/sh

# output file both sides
# m option for macintosh files

{ case "$1" in
-m|-M) cat $HOME/etc/ratpro70 ; shift ;;
*) echo %!PS-Adobe ;;
esac

echo statusdict begin true setduplexmode end
for file in $*
do
        echo save mark
        cat $file
        echo cleartomark restore statusdict begin newsheet end
done
} | qpr -q lps20

You can ignore the setduplexmode stuff, that was to print on both sides
of the paper.  The important stuff is the stuff in the do loop.  It saves
the state before each file and puts a mark on the stack.  After the file
it clears the stack back to that mark and does a restore of the save object.
The statusdict begin newsheet end gets each new file on a new physical
piece of paper, again, this is the bothsides stuff.

A malevolent file can still kill this by clearing away the mark and the
stacked save object, but Mac files don't do this.  They do leave detrius
on the stack, though, hence the mark/cleartomark stuff.

If you are really paranoid you could save the save object under some name
and get it back, with something like this:

/bandersnitch save def
   <.include file 1 here.>
bandersnitch restore
/bandersnitch save def
   <.include file 2 here.>
bandersnitch restore

and so on.  Then only if the included files blow away the bandersnitch
variable would it break.

You could probably protect against even that by creating a directory and
putting it on the directory stack before including the file.  Then any use
of the name would occur in that directory, and you could pop it off when
you get back from the include file...
-- 

Ben Cranston <zben@umd2.umd.edu>
Warm and Fuzzy Networking Group, Egregious State University
My cat is named "Perpetually Hungry Autonomous Carbon Unit"; I call him "Sam".