]> git.lizzy.rs Git - plan9front.git/blob - sys/lib/ghostscript/gs_dscp.ps
aux/cpuid: decode family and model bitfields
[plan9front.git] / sys / lib / ghostscript / gs_dscp.ps
1 %  Copyright (C) 2000 Artifex Software Inc.   All rights reserved.
2
3 % This software is provided AS-IS with no warranty, either express or
4 % implied.
5
6 % This software is distributed under license and may not be copied,
7 % modified or distributed except as expressly authorized under the terms
8 % of the license contained in the file LICENSE in this distribution.
9
10 % For more information about licensing, please refer to
11 % http://www.ghostscript.com/licensing/. For information on
12 % commercial licensing, go to http://www.artifex.com/licensing/ or
13 % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14 % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15
16 % $Id: gs_dscp.ps,v 1.6 2002/02/21 21:49:28 giles Exp $
17 %  Postscript interface routines to DSC parser
18
19 /send_orientation {                     % <orientation> send_orientation -
20         % .parse_dsc_comments returns -1 for an Orientation key with an
21         % unrecognized value.
22   dup 0 ge {
23     << /Orientation 2 index >> setpagedevice
24   } if pop
25 } bind def
26
27 % This dictionary contains local handlers for DSC comments.
28 % See header in zdscpars.c for more information.
29 % <dsc_dict> handler <dsc_dict>
30 /DSCparseprocs mark
31    /Orientation { dup /Orientation get send_orientation } bind
32    /PageOrientation { dup /PageOrientation .knownget { send_orientation }
33                       { dup /Orientation .knownget { send_orientation } if }
34                       ifelse } bind
35    /Page { dup /Orientation .knownget { send_orientation } if } bind
36    /NOP { } bind
37 .dicttomark readonly def
38
39 % This procedure is called whenever a DSC comment is found by the interpreter
40 /do_parse_dsc false def
41 /parse_dsc {                            % <file> <DSC string> [<prev proc>]
42                                         %   parse_dsc -
43         % Run any previously installed parser.
44   0 get dup null eq { pop } { 3 copy exec pop } ifelse
45
46   do_parse_dsc {                        % Check if this parser is enabled
47     currentglobal true setglobal        % Go to global VM, save old state
48     3 1 roll                            % Put old VM state under <file> <string>
49     dsc_dict exch                       % <VM state> <file> <dict> <string>
50     .parse_dsc_comments                 % <VM state> <file> <dict> <DSC name>
51     4 -1 roll                           % Get old VM state from under <file> <dict> <DSC name>
52     setglobal                           % restore previous VM state
53     //DSCparseprocs exch .knownget {    % Check DSC name against local handler list
54       exec                              % execute any local handler
55     } if
56   } if
57   pop pop                               % remove file, dict
58 } bind def
59
60
61 % Check whether the currently installed parser is the one defined in this file.
62 /.using_parse_dsc {                     % - .using_parse_dsc <proc> <using?>
63   currentuserparams /ProcessDSCComment get
64   dup null eq { pop {{//null} //parse_dsc exec} } if
65   dup length 3 eq {
66     dup dup length 1 sub get /parse_dsc load eq
67   } {
68     false
69   } ifelse
70 } bind def
71
72 % Establish a binding for dsc_dict.
73 userdict /dsc_dict null put
74
75 % - dsc_init -
76 /dsc_init {                             % Initialize DSC parser
77   currentglobal true setglobal
78   /dsc_dict 50 dict store               % Size must be large enough for all DSC values
79   dsc_dict .initialize_dsc_parser
80   .using_parse_dsc {
81         % Already using this parser.
82     pop
83   } {
84         % Encapsulate the previous parser.  We know it is in global VM:
85         % allocate the new one in global VM as well.
86     1 array astore
87     /parse_dsc load /exec load 3 array astore cvx readonly
88     << /ProcessDSCComment 3 -1 roll >>
89     setuserparams
90   } ifelse
91   setglobal
92   /do_parse_dsc true def
93 } bind def
94
95
96 % Enable the DSC parser defined in this file.
97 % - enable_dsc -
98 /enable_dsc {
99   dsc_init
100 } bind def
101
102 % Disable the DSC parser defined in this file.
103 % - disable_dsc -
104 /disable_dsc {
105         % There might be another parser installed: if so, restore it.
106         % (If it has encapsulated our parser, we can't.)
107   .using_parse_dsc {
108         % Restore the parser we encapsulated.
109     0 get 0 get
110     currentglobal true setglobal exch
111     << /ProcessDSCComment 3 -1 roll >>
112     exch setglobal setuserparams
113   } {
114     pop
115   } ifelse
116         % If we couldn't restore the old parser, at least disable ours.
117   /do_parse_dsc false def
118 } bind def