jim@nih-csl.UUCP (jim sullivan) (12/30/88)
I am trying to write a postscript routine that will look into the dictstack of the printer and print the names of all dictionaries. From there I will print key/value pairs which seems easy enough. I have tried using the DICTSTACK operator to get the dictionaries into an array but when I try to print them using a CVS operator, I get a --nostringval-- which I presume is correct after reading the red book. Does anyone know how to print the name of a directory from the dictionary stack? Thanks in advance jim jim@nih-csl.dcrt.nih.gov
geof@apolling (Geof Cooper) (12/31/88)
The only way to get the "name" of a dictionary (it may have
more than one, or different names in different contexts) is
to scan all dictionaries on the dict stack and do an associative
search for the name. Here is a procedure that I wrote to do
this some time ago. It uses the "dstack" variable from $error,
but can easily be modified to get the dict stack currently
in effect. As an efficiency hack, userdict and systemdict
are checked for as special cases. The outer two ifelse's
serve no other purpose.
- Geof
% print a dictionary by searching for it in the other dictionaries
% must be called with $error begun.
/pdict
{
dup systemdict eq
{ (-dictionary: systemdict\n) print pop }
{
dup userdict eq
{ (-dictionary: userdict\n) print pop }
{
print_dict begin
/toprint exch def
/found false def
dstack length 1 sub -1 0
{
dstack exch get
{
toprint eq
{ (-dictionary: ) print
=string cvs print (\n) print
/found true def
exit
}
{ pop }
ifelse
} forall
found { exit } if
} for
found not { (-dictionary-\n) print } if
end
} ifelse
} ifelse
} def