uninfo.ps 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. %!
  2. % Copyright (C) 1997 Aladdin Enterprises. All rights reserved
  3. %
  4. % This file is part of AFPL Ghostscript.
  5. %
  6. % AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  7. % distributor accepts any responsibility for the consequences of using it, or
  8. % for whether it serves any particular purpose or works at all, unless he or
  9. % she says so in writing. Refer to the Aladdin Free Public License (the
  10. % "License") for full details.
  11. %
  12. % Every copy of AFPL Ghostscript must include a copy of the License, normally
  13. % in a plain ASCII text file named PUBLIC. The License grants you the right
  14. % to copy, modify and redistribute AFPL Ghostscript, but only under certain
  15. % conditions described in the License. Among other things, the License
  16. % requires that the copyright notice and this notice be preserved on all
  17. % copies.
  18. % $Id: uninfo.ps,v 1.2 2000/09/19 18:29:11 lpd Exp $
  19. % uninfo.ps: Utilities for "printing" PostScript items, especially dictionaries
  20. % Usage:
  21. % (prefix-string) dict unprint
  22. % Maximum Print-Width
  23. /HSpwidth 80 def
  24. % any HScvs string
  25. /HScvs {
  26. % Number-Syntax
  27. dup type % stack: any /anytype
  28. dup /integertype eq 1 index /realtype eq or { pop
  29. 16 string cvs
  30. }{
  31. % Logical-Type
  32. dup /booleantype eq { pop
  33. 5 string cvs
  34. }{
  35. % Identifiers
  36. dup /nametype eq { pop
  37. dup length 1 add string
  38. dup 0 (/) putinterval
  39. exch 1 index 1 1 index length 1 sub getinterval cvs pop
  40. }{
  41. % Strings
  42. dup /stringtype eq { pop
  43. % ------- Compute Length
  44. 2 1 index { % stack: str len item
  45. dup 32 lt 1 index 126 gt or { % need 4
  46. pop 4 add
  47. }{
  48. dup 40 eq 1 index 41 eq or 1 index 92 eq or {
  49. pop 2 add
  50. }{
  51. pop 1 add
  52. } ifelse
  53. } ifelse
  54. } forall
  55. % ------- Allocate & Fill String
  56. string dup 0 (\() putinterval 1
  57. 3 -1 roll { % outstr pos item
  58. dup 32 lt 1 index 126 gt or {
  59. dup 7 le {
  60. 2 index 2 index (\\00) putinterval
  61. 8 3 index 3 index 3 add 1 getinterval cvrs
  62. }{
  63. dup 63 le {
  64. 2 index 2 index (\\0) putinterval
  65. 8 3 index 3 index 2 add 2 getinterval cvrs
  66. }{
  67. 2 index 2 index (\\) putinterval
  68. 8 3 index 3 index 1 add 3 getinterval cvrs
  69. } ifelse
  70. } ifelse
  71. pop 4 add
  72. }{
  73. dup 40 eq 1 index 41 eq or 1 index 92 eq or {
  74. 2 index 2 index (\\) putinterval
  75. exch 1 add exch
  76. } if
  77. 2 index exch 2 index exch put
  78. 1 add
  79. } ifelse
  80. } forall
  81. 1 index exch (\)) putinterval
  82. }{ exch pop
  83. dup length 1 add string
  84. dup 0 (-) putinterval
  85. exch 1 index 1 1 index length 1 sub getinterval cvs pop
  86. dup dup length 4 sub (-) putinterval
  87. 0 1 index length 3 sub getinterval
  88. } ifelse
  89. } ifelse
  90. } ifelse
  91. } ifelse
  92. } bind def
  93. % int HSpindent - indent-spaces
  94. /HSpindent {
  95. dup 0 gt {
  96. 1 1 3 -1 roll { pop ( ) print } for
  97. }{
  98. pop
  99. } ifelse
  100. } bind def
  101. % indent array HSaprint -> Print an Array
  102. /HSaprint {
  103. dup type /arraytype eq {
  104. ( [) print
  105. exch 1 add dup 1 add
  106. 3 -1 roll { % rind pos item
  107. HScvs dup length % rind pos str len
  108. dup 3 index add HSpwidth ge {
  109. (\n) print
  110. 3 index HSpindent
  111. 3 -1 roll pop
  112. 2 index add
  113. exch
  114. }{
  115. ( ) print
  116. 2 index add 1 add
  117. 3 -1 roll pop
  118. exch
  119. } ifelse
  120. print
  121. } forall
  122. ( ]) print
  123. pop pop
  124. }{
  125. ( ) print
  126. HScvs print pop
  127. } ifelse
  128. (\n) print
  129. } bind def
  130. % dict HSdnames dict names (creates sorted name-strings)
  131. /HSdnames {
  132. % Build namelist, stack: dic
  133. dup length 0 eq {
  134. []
  135. }{
  136. [ 1 index {
  137. pop dup type /nametype eq {
  138. dup length string cvs
  139. }{
  140. pop
  141. } ifelse
  142. } forall
  143. ]
  144. % Sort the namelist, stack: dic nam
  145. 0 1 2 index length 2 sub { % stack: dic nam I
  146. 2 copy get % stack: pre dic nam I nam[I]
  147. 1 index 1 add 1 4 index length 1 sub { % stack: dic nam I nam[I] J
  148. 3 index 1 index get % dic nam I S[I] J S[J]
  149. 2 index 1 index gt { % swap them
  150. 4 index 2 index 4 index put
  151. 4 index 4 index 2 index put
  152. 3 1 roll
  153. } if
  154. pop pop
  155. } for
  156. pop pop
  157. } for
  158. } ifelse
  159. } bind def
  160. % string:prefix dict:which unprint
  161. /unprint {
  162. HSdnames % pre dic nam
  163. % compute the maximum length
  164. 0 1 index { % pre dic nam maxlen nam[I]
  165. length 2 copy lt { exch } if pop
  166. } forall
  167. % Print out all the items, stack: pre dic nam maxlen
  168. (\n) print
  169. exch { % pre dic maxlen nam[I]
  170. % no prefix yet, -> flush right
  171. 3 index length 0 eq {
  172. dup length 2 index exch sub HSpindent
  173. }{
  174. 3 index print (/) print
  175. } ifelse
  176. % print the name
  177. dup print
  178. % prefix: fill up with blanks
  179. 3 index length 0 ne {
  180. dup length 2 index exch sub HSpindent
  181. } if
  182. % now print the item itself, stack: pre dic maxlen nam[I]
  183. 2 index 1 index cvn get dup type % stack: pre dic maxlen nam[i] item typ
  184. % Dict-Syntax
  185. dup /dicttype eq { pop % stack: pre dic maxlen nam[i] item
  186. ( ) print dup HScvs print
  187. 4 index length 0 eq { % brand new prefix
  188. 2 index string 0 1 5 index 1 sub { 1 index exch 32 put } for
  189. dup 4 index 4 index length sub 5 -1 roll putinterval
  190. }{
  191. 4 index length 1 add 2 index length add string
  192. dup 0 7 index putinterval
  193. dup 6 index length (/) putinterval
  194. dup 6 index length 1 add 5 -1 roll putinterval
  195. } ifelse
  196. exch unprint
  197. }{
  198. 3 -1 roll pop % tack: pre dic maxlen item typ
  199. % Array-Syntax
  200. dup /arraytype eq { pop % stack: pre dic maxlen item
  201. 3 index length dup 0 ne { 1 add } if 2 index add
  202. exch HSaprint
  203. }{ pop
  204. ( ) print
  205. HScvs print
  206. (\n) print
  207. } ifelse
  208. } ifelse
  209. } forall
  210. pop pop length -1 eq { (\n) print } if
  211. } bind def
  212. /currentpagedevice where { % check for currentpagedevice
  213. /currentpagedevice get exec () exch unprint
  214. } if