From: rothman@tegra.com (Steve Rothman)
Subject: Re: PostScript disassembler?
Organization: Tegra, Inc.
Date: Mon, 9 Nov 1992 15:14:46 GMT

In article <1992Nov8.061155@eklektix.com> rcd@raven.eklektix.com (Dick Dunn)
writes:
>rothman@tegra.com writes:
>>Sometimes self-contained, perfectly functional PS programs get pretty hard
>>to decipher, because a lot of procedure definitions are made, operators are
>>redefined, etc. Does anyone know of a program that could eat a legal, but 
>>cryptic PS program and spew out Red Book standard PS?...
>
>It's not clear what you mean by "Red Book standard"--if it's a legal
>program, it's "red book" by some plausible definition.  Green book...now,
>that would be a help.

I guess what I mean is using the core Red Book operators, not invented or
redefined ones. Sure it's legal to redefine and create new operators, (and
often a great idea for efficiency) but if
I'm trying to understand a bit of PS code that has the operator "xybabble" in
it, I can't look that up in the Red Book. Of course, I _can_ look in the
begining of the PS to see how "xybabble" is defined, but I'm always running
into the situation while "xybabble" turns out to be a procedure using "xfoo"
and "ybar", and then I need to look those up, and they of course use other
redefined operators/procedures, and so on. If prologs were completely commented
& structured, this wouldn't be a big problem, but typically they're not!

>
>Unwinding procedures is a hard one, because you've got recursion and
>dynamic binding.  Even if you don't try to unwind any recursive procedures,
>it seems that expanding them out might well make a program harder to read
>rather than easier.

I'm sure you're right, but there's no harm in "expanding" them, because if they
do get more confusing I can always look at the original <g>!

>
>Why don't you sketch out some examples for us--original program and what
>you'd like as the result of the processing?  That might make it easier to
>get a handle on the problem.
>

Well, here's an extremely simple-minded example:

:
:
%buried somewhere in the prolog
/d {dup} def
:
%buried somewhere else in the prolog
/m {mul} def
:
%buried in yet another place in the prolog
/s {d m} def    
:
:
%somewhere deep in the page description
4 s
:
:

Ok, so I'm trying to understand why something happened on a page. The line, "4
s" happens right before something is drawn. In order to find out what it does,
as I'm looking in the page description, I can search for "/s". When I find it,
I then have to do a search for "/d" and "/m".  Since this is a simple example,
I'm now set. In real-life, I've found my self backtracking through a dozen
layers, in many directions, just to find out what one lousy operator in the
middle of an otherwise understandable page description does.

What I would like my mythical "ps dissasembler" program to do is to replace the
line 

4 s

with a line reading

4 dup mul

Then I know exactly what's happening, without prolonged searching around in the
prolog!

>
>>PS: Icing on the cake would be a pretty-print formatter, if this isn't
>>too ridiculous for PostScript. (Is there such a thing as pretty PS?)
>
>Well, there's definitely such a thing as ugly PS!  But yes, it's not hard
>to derive rules for formatting PS according to a style like the one the
>green book uses.
>-- 
>Dick Dunn    rcd@raven.eklektix.com   -or-   raven!rcd    Boulder, Colorado

So, is there a Pretty Printer anywhere?

Thanks for any ideas.

==================================================================
Steve Rothman
email: rothman@tegra.com *** CIS: 72120,2747 *** FAX: 508-663-7082