blob: 323b3d9cdaff2d61faf6b221286a150b406ecb61 (
plain)
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
%!PS
% begin included library code
% see https://github.com/Firedrake/postscript-libraries/
/apush.right { % [a b] c -> [a b c]
exch
[ exch aload length 2 add -1 roll ]
} bind def
/reduce { % array proc -> value
2 dict begin
/p exch def
/a exch def
a 0 get
1 1 a length 1 sub {
a exch get
p
} for
end
} bind def
/deepeq {
2 dict begin
/a exch def
/b exch def
a type b type eq {
a type /dicttype eq {
a length b length eq {
<<
a {
pop
true
} forall
b {
pop
true
} forall
>>
true exch
{
pop
dup a exch known {
dup b exch known {
dup a exch get exch b exch get deepeq not {
pop false
} if
} {
false
} ifelse
} {
false
} ifelse
} forall
} {
false
} ifelse
} {
a type dup /arraytype eq exch /stringtype eq or {
a length b length eq {
true
0 1 a length 1 sub {
dup a exch get exch b exch get deepeq not {
pop false
exit
} if
} for
} {
false
} ifelse
} {
a b eq
} ifelse
} ifelse
} {
false
} ifelse
end
} bind def
/listmin {
{ min } reduce
} bind def
/test {
/test.count test.count 1 add def
{
/test.pass test.pass 1 add def
} {
( ) print
test.count (....) cvs print
(-fail) print
} ifelse
} bind def
/test.end {
( ) print
test.count 0 gt {
(Passed ) print
test.pass (...) cvs print
(/) print
test.count (...) cvs print
( \() print
test.pass 100 mul test.count idiv (...) cvs print
(%\)) print
(\r\n) print
} if
} bind def
/apush { apush.right } bind def
/strconcat % (a) (b) -> (ab)
{ exch dup length
2 index length add string
dup dup 4 2 roll copy length
4 -1 roll putinterval
} bind def
/strsplit % (ajbjc) (j) -> [ (a) (b) (c) ]
{
1 dict begin
/sep exch def
[ exch
{
dup length 0 eq {
pop
exit
} {
sep search {
exch pop
dup length 0 eq {
pop
} {
exch
} ifelse
} {
()
} ifelse
} ifelse
} loop
]
end
} bind def
/test.start {
print (:) print
/test.pass 0 def
/test.count 0 def
} bind def
/strjoin % [(a) (b) (c)] (j) -> (ajbjc)
{
3 dict begin
/j exch def
dup 0 get /out exch def
/first true def
{
first {
pop
/first false def
} {
out j strconcat
exch strconcat
/out exch def
} ifelse
} forall
out
end
} bind def
% end included library code
/commonpath {
6 dict begin
/pa 0 array def
/pl 0 array def
{
(/) strsplit /q exch def
/pl pl q length apush def
/pa pa q apush def
} forall
/out [ () ] def
0 1 pl listmin 1 sub {
/cl exch def
/ex false def
/tx pa 0 get cl get def
pa {
cl get tx deepeq not {
/ex true def
exit
} if
} forall
ex {
exit
} if
/out out tx apush def
} for
out (/) strjoin
end
} bind def
(commonpath) test.start
[
(/a/b/c/1/x.pl)
(/a/b/c/d/e/2/x.pl)
(/a/b/c/d/3/x.pl)
(/a/b/c/4/x.pl)
(/a/b/c/d/5/x.pl)
] commonpath (/a/b/c) deepeq test
test.end
|