home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Updates / GhostScript / !GhostScr / 6_01 / lib / uninfo.ps < prev    next >
Text File  |  2000-03-09  |  6KB  |  223 lines

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