uninfo.ps 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. %!
  2. % Copyright (C) 1997 Aladdin Enterprises. All rights reserved
  3. %
  4. % This software is provided AS-IS with no warranty, either express or
  5. % implied.
  6. %
  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.
  10. %
  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.
  16. % $Id: uninfo.ps,v 1.4 2002/02/21 21:49:28 giles Exp $
  17. % uninfo.ps: Utilities for "printing" PostScript items, especially dictionaries
  18. % Usage:
  19. % (prefix-string) dict unprint
  20. % Maximum Print-Width
  21. /HSpwidth 80 def
  22. % any HScvs string
  23. /HScvs {
  24. % Number-Syntax
  25. dup type % stack: any /anytype
  26. dup /integertype eq 1 index /realtype eq or { pop
  27. 16 string cvs
  28. }{
  29. % Logical-Type
  30. dup /booleantype eq { pop
  31. 5 string cvs
  32. }{
  33. % Identifiers
  34. dup /nametype eq { pop
  35. dup length 1 add string
  36. dup 0 (/) putinterval
  37. exch 1 index 1 1 index length 1 sub getinterval cvs pop
  38. }{
  39. % Strings
  40. dup /stringtype eq { pop
  41. % ------- Compute Length
  42. 2 1 index { % stack: str len item
  43. dup 32 lt 1 index 126 gt or { % need 4
  44. pop 4 add
  45. }{
  46. dup 40 eq 1 index 41 eq or 1 index 92 eq or {
  47. pop 2 add
  48. }{
  49. pop 1 add
  50. } ifelse
  51. } ifelse
  52. } forall
  53. % ------- Allocate & Fill String
  54. string dup 0 (\() putinterval 1
  55. 3 -1 roll { % outstr pos item
  56. dup 32 lt 1 index 126 gt or {
  57. dup 7 le {
  58. 2 index 2 index (\\00) putinterval
  59. 8 3 index 3 index 3 add 1 getinterval cvrs
  60. }{
  61. dup 63 le {
  62. 2 index 2 index (\\0) putinterval
  63. 8 3 index 3 index 2 add 2 getinterval cvrs
  64. }{
  65. 2 index 2 index (\\) putinterval
  66. 8 3 index 3 index 1 add 3 getinterval cvrs
  67. } ifelse
  68. } ifelse
  69. pop 4 add
  70. }{
  71. dup 40 eq 1 index 41 eq or 1 index 92 eq or {
  72. 2 index 2 index (\\) putinterval
  73. exch 1 add exch
  74. } if
  75. 2 index exch 2 index exch put
  76. 1 add
  77. } ifelse
  78. } forall
  79. 1 index exch (\)) putinterval
  80. }{ exch pop
  81. dup length 1 add string
  82. dup 0 (-) putinterval
  83. exch 1 index 1 1 index length 1 sub getinterval cvs pop
  84. dup dup length 4 sub (-) putinterval
  85. 0 1 index length 3 sub getinterval
  86. } ifelse
  87. } ifelse
  88. } ifelse
  89. } ifelse
  90. } bind def
  91. % int HSpindent - indent-spaces
  92. /HSpindent {
  93. dup 0 gt {
  94. 1 1 3 -1 roll { pop ( ) print } for
  95. }{
  96. pop
  97. } ifelse
  98. } bind def
  99. % indent array HSaprint -> Print an Array
  100. /HSaprint {
  101. dup type /arraytype eq {
  102. ( [) print
  103. exch 1 add dup 1 add
  104. 3 -1 roll { % rind pos item
  105. HScvs dup length % rind pos str len
  106. dup 3 index add HSpwidth ge {
  107. (\n) print
  108. 3 index HSpindent
  109. 3 -1 roll pop
  110. 2 index add
  111. exch
  112. }{
  113. ( ) print
  114. 2 index add 1 add
  115. 3 -1 roll pop
  116. exch
  117. } ifelse
  118. print
  119. } forall
  120. ( ]) print
  121. pop pop
  122. }{
  123. ( ) print
  124. HScvs print pop
  125. } ifelse
  126. (\n) print
  127. } bind def
  128. % dict HSdnames dict names (creates sorted name-strings)
  129. /HSdnames {
  130. % Build namelist, stack: dic
  131. dup length 0 eq {
  132. []
  133. }{
  134. [ 1 index {
  135. pop dup type /nametype eq {
  136. dup length string cvs
  137. }{
  138. pop
  139. } ifelse
  140. } forall
  141. ]
  142. % Sort the namelist, stack: dic nam
  143. 0 1 2 index length 2 sub { % stack: dic nam I
  144. 2 copy get % stack: pre dic nam I nam[I]
  145. 1 index 1 add 1 4 index length 1 sub { % stack: dic nam I nam[I] J
  146. 3 index 1 index get % dic nam I S[I] J S[J]
  147. 2 index 1 index gt { % swap them
  148. 4 index 2 index 4 index put
  149. 4 index 4 index 2 index put
  150. 3 1 roll
  151. } if
  152. pop pop
  153. } for
  154. pop pop
  155. } for
  156. } ifelse
  157. } bind def
  158. % string:prefix dict:which unprint
  159. /unprint {
  160. HSdnames % pre dic nam
  161. % compute the maximum length
  162. 0 1 index { % pre dic nam maxlen nam[I]
  163. length 2 copy lt { exch } if pop
  164. } forall
  165. % Print out all the items, stack: pre dic nam maxlen
  166. (\n) print
  167. exch { % pre dic maxlen nam[I]
  168. % no prefix yet, -> flush right
  169. 3 index length 0 eq {
  170. dup length 2 index exch sub HSpindent
  171. }{
  172. 3 index print (/) print
  173. } ifelse
  174. % print the name
  175. dup print
  176. % prefix: fill up with blanks
  177. 3 index length 0 ne {
  178. dup length 2 index exch sub HSpindent
  179. } if
  180. % now print the item itself, stack: pre dic maxlen nam[I]
  181. 2 index 1 index cvn get dup type % stack: pre dic maxlen nam[i] item typ
  182. % Dict-Syntax
  183. dup /dicttype eq { pop % stack: pre dic maxlen nam[i] item
  184. ( ) print dup HScvs print
  185. 4 index length 0 eq { % brand new prefix
  186. 2 index string 0 1 5 index 1 sub { 1 index exch 32 put } for
  187. dup 4 index 4 index length sub 5 -1 roll putinterval
  188. }{
  189. 4 index length 1 add 2 index length add string
  190. dup 0 7 index putinterval
  191. dup 6 index length (/) putinterval
  192. dup 6 index length 1 add 5 -1 roll putinterval
  193. } ifelse
  194. exch unprint
  195. }{
  196. 3 -1 roll pop % tack: pre dic maxlen item typ
  197. % Array-Syntax
  198. dup /arraytype eq { pop % stack: pre dic maxlen item
  199. 3 index length dup 0 ne { 1 add } if 2 index add
  200. exch HSaprint
  201. }{ pop
  202. ( ) print
  203. HScvs print
  204. (\n) print
  205. } ifelse
  206. } ifelse
  207. } forall
  208. pop pop length -1 eq { (\n) print } if
  209. } bind def
  210. /currentpagedevice where { % check for currentpagedevice
  211. /currentpagedevice get exec () exch unprint
  212. } if