1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
%!PS-Adobe-3.0
%%Pages: 1
%%EndComments
%
%
% Automatic translation of .dcw file to postscript
%
% Debugging....
% const debuglm: left margin of debug messages
/debuglm 0.5 72 mul def
% const debugtop: top of debug messages - 11 inches up.
/debugtop 11 72 mul def
% const debugdown: how far to go down each line
/debugdown 20 def
% debugorigin():
% move to debugging origin
/debugorigin
{
debuglm debugtop moveto
(Debugging log:) show
newline
} bind def
% debugnv( name, value );
% display name and value on a debug line.
% keep this as it's so much simpler than debug() below
% and also debug() has commented out invocations to
% this throughout it:-)
/debugnv
{
% initially: stack top: value, name
30 0 rmoveto
exch % stack top: name, value
show % show name, stack top: value
(: ) show
50 string cvs show % show convert_to_string(value)
newline
} bind def
% debugsay( string, array_of_pairs );
% display a single message, combining the initial string and then
% every pair of items (variable,string) in <array> with no separators.
% eg debugsay( (x:), [ x (, y:) y (, z:) z ()] ) produces
% "x: value_of_x, y: value_of_y, z: value_of_z"
/debugsay
{
6 dict begin % next N items defined are in a local dictionary
/array exch def % localize parameter name, removing it from stack
/initstr exch def % localize parameter name, removing it from stack
/len 0 def % local variable - length of array
/pos 0 def % local variable - position in array
/name () def % local variable - an array element
/value () def % local variable - next array element
30 0 rmoveto
/len array length def
initstr 50 string cvs show
% for pos = 0 to $#array step 2
0 2 len 1 sub
{
/pos exch def
% (pos) pos debugnv
% $name = $array[$pos];
/name array pos get def
% (name) name debugnv
% $value = $array[$pos+1];
/value array pos 1 add get def
% (value) value debugnv
name 50 string cvs show
value 50 string cvs show
} for
newline
end % local dictionary destroyed here
} def
% newline();
% go to left margin of next line for debug messages
/newline
{
currentpoint debugdown sub % decrement Y pos
exch pop % drop old X
debuglm exch % form (debuglm,Y) on stack
moveto % go there!
} def
% str = i2s(n):
% convert n to a string
/i2s
{
50 string cvs
} def
% result = append( string1, string2 )
% Concatenates two strings together. Some languages
% already know how to do stuff like this!!!
/append
{
% Initial stack: s1 s2 <-- top of stack
2 copy % s1 s2 s1 s2
length % s1 s2 s1 len(s2)
exch % s1 s2 len(s2) s1
length add % s1 s2 len(s1)+len(s2)
string dup % s1 s2 r r
4 2 roll % r r s1 s2
2 index % r r s1 s2 r
0 % r r s1 s2 r 0
3 index % r r s1 s2 r 0 s1
putinterval % strcpy( r+0, s1 )
% r r s1 s2
exch % r r s2 s1
length % r r s2 len(s1)
exch % r r len(s1) s2
putinterval % strcpy( r+len(s1), s2 )
% return r
} bind def
%%Page: 1 1
%%PageOrientation: Portrait
/Helvetica-Bold findfont 13 scalefont setfont
debugorigin
/n 20 def
/found 0 def
/i 100 def
{
/lower i cvi 10 mod def
/upper i def
{
upper 9 le
{
exit
} if
/upper upper 10 div int def
} loop
/div 10 upper mul lower add def
i cvi div mod 0 eq
{
%say "$i"
() [i ()] debugsay
/found found 1 add def
} if
found n ge
{
exit
} if
/i i 1 add def
} loop
showpage
|