2 % Copyright (C) 1997 Aladdin Enterprises. All rights reserved
4 % This software is provided AS-IS with no warranty, either express or
7 % This software is distributed under license and may not be copied,
8 % modified or distributed except as expressly authorized under the terms
9 % of the license contained in the file LICENSE in this distribution.
11 % For more information about licensing, please refer to
12 % http://www.ghostscript.com/licensing/. For information on
13 % commercial licensing, go to http://www.artifex.com/licensing/ or
14 % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
15 % San Rafael, CA 94903, U.S.A., +1(415)492-9861.
17 % $Id: uninfo.ps,v 1.4 2002/02/21 21:49:28 giles Exp $
18 % uninfo.ps: Utilities for "printing" PostScript items, especially dictionaries
20 % (prefix-string) dict unprint
28 dup type % stack: any /anytype
29 dup /integertype eq 1 index /realtype eq or { pop
33 dup /booleantype eq { pop
37 dup /nametype eq { pop
38 dup length 1 add string
40 exch 1 index 1 1 index length 1 sub getinterval cvs pop
43 dup /stringtype eq { pop
44 % ------- Compute Length
45 2 1 index { % stack: str len item
46 dup 32 lt 1 index 126 gt or { % need 4
49 dup 40 eq 1 index 41 eq or 1 index 92 eq or {
56 % ------- Allocate & Fill String
57 string dup 0 (\() putinterval 1
58 3 -1 roll { % outstr pos item
59 dup 32 lt 1 index 126 gt or {
61 2 index 2 index (\\00) putinterval
62 8 3 index 3 index 3 add 1 getinterval cvrs
65 2 index 2 index (\\0) putinterval
66 8 3 index 3 index 2 add 2 getinterval cvrs
68 2 index 2 index (\\) putinterval
69 8 3 index 3 index 1 add 3 getinterval cvrs
74 dup 40 eq 1 index 41 eq or 1 index 92 eq or {
75 2 index 2 index (\\) putinterval
78 2 index exch 2 index exch put
82 1 index exch (\)) putinterval
84 dup length 1 add string
86 exch 1 index 1 1 index length 1 sub getinterval cvs pop
87 dup dup length 4 sub (-) putinterval
88 0 1 index length 3 sub getinterval
95 % int HSpindent - indent-spaces
98 1 1 3 -1 roll { pop ( ) print } for
104 % indent array HSaprint -> Print an Array
106 dup type /arraytype eq {
109 3 -1 roll { % rind pos item
110 HScvs dup length % rind pos str len
111 dup 3 index add HSpwidth ge {
134 % dict HSdnames dict names (creates sorted name-strings)
136 % Build namelist, stack: dic
141 pop dup type /nametype eq {
142 dup length string cvs
148 % Sort the namelist, stack: dic nam
149 0 1 2 index length 2 sub { % stack: dic nam I
150 2 copy get % stack: pre dic nam I nam[I]
151 1 index 1 add 1 4 index length 1 sub { % stack: dic nam I nam[I] J
152 3 index 1 index get % dic nam I S[I] J S[J]
153 2 index 1 index gt { % swap them
154 4 index 2 index 4 index put
155 4 index 4 index 2 index put
165 % string:prefix dict:which unprint
167 HSdnames % pre dic nam
168 % compute the maximum length
169 0 1 index { % pre dic nam maxlen nam[I]
170 length 2 copy lt { exch } if pop
172 % Print out all the items, stack: pre dic nam maxlen
174 exch { % pre dic maxlen nam[I]
175 % no prefix yet, -> flush right
176 3 index length 0 eq {
177 dup length 2 index exch sub HSpindent
179 3 index print (/) print
183 % prefix: fill up with blanks
184 3 index length 0 ne {
185 dup length 2 index exch sub HSpindent
187 % now print the item itself, stack: pre dic maxlen nam[I]
188 2 index 1 index cvn get dup type % stack: pre dic maxlen nam[i] item typ
190 dup /dicttype eq { pop % stack: pre dic maxlen nam[i] item
191 ( ) print dup HScvs print
192 4 index length 0 eq { % brand new prefix
193 2 index string 0 1 5 index 1 sub { 1 index exch 32 put } for
194 dup 4 index 4 index length sub 5 -1 roll putinterval
196 4 index length 1 add 2 index length add string
197 dup 0 7 index putinterval
198 dup 6 index length (/) putinterval
199 dup 6 index length 1 add 5 -1 roll putinterval
203 3 -1 roll pop % tack: pre dic maxlen item typ
205 dup /arraytype eq { pop % stack: pre dic maxlen item
206 3 index length dup 0 ne { 1 add } if 2 index add
215 pop pop length -1 eq { (\n) print } if
218 /currentpagedevice where { % check for currentpagedevice
219 /currentpagedevice get exec () exch unprint