%! %ds.ps %Dict Stack tools % wherevalue - find dictionary and key for value % dicttrace - print dictstack using names % dict== - recursively (optional) print dictionary contents % value wherevalue dict key true % false % find dictionary and key for value /wherevalue { MYDICT countdictstack array dictstack % val my-dict [ds] exch begin /found false def dup length 1 sub -1 0 { % val [ds] i 1 index exch get % val [ds] dict dup { % val [ds] dict key val dup type /stringtype eq { dup rcheck { 4 index eq { /found true def exit } if }{ pop } ifelse }{ 4 index eq { % val [ds] dict key /found true def exit %forall } if % val [ds] dict key } ifelse pop % val [ds] dict } forall % val [ds] (found: dict key) (not: dict) found { exit %for } if % val [ds] dict pop % val [ds] } for % (found: val [ds] dict key) (not: val [ds]) found { 4 2 roll pop pop true }{ pop pop false } ifelse end } dup 0 1 dict put def % print names of dictionaries on the stack /dicttrace { (Dict Stack:\n) print countdictstack array dictstack dup length 1 sub -1 0 { 1 index exch get wherevalue { exch pop ( ) cvs print (\n) print }{ (-anonymous-\n) print } ifelse } for pop } def % -dict- /dict== { dup { % d k v exch dup /.originalresourceforall eq { == pop (unprintable\n) print }{ == % d v dup type /stringtype eq { dup rcheck { == }{ pop (read access denied\n) print } ifelse }{ dup type /dicttype eq { 2 copy eq { pop (-self-\n) print }{ (% ) print flush (%lineedit) (r) { file } stopped { % >EOF % d v pop pop pop pop pop exit }{ read { (y) 0 get eq { % >y (\n<<\n) print dict== (>>\n) print }{ % >n pop (\n-dict-\n) print } ifelse }{ % > (\n<<\n) print dict== (>>\n) print } ifelse } ifelse } ifelse }{ == } ifelse } ifelse } ifelse } forall pop } def % index /dictdump { countdictstack array dictstack exch get dict== } def %eof