36
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
45
|
3 |
All Rights Reserved
|
36
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
TwoColumnTextView subclass:#DiffTextView
|
45
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Text'
|
36
|
18 |
!
|
|
19 |
|
|
20 |
DiffTextView comment:'
|
|
21 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
45
|
22 |
All Rights Reserved
|
36
|
23 |
|
52
|
24 |
$Header: /cvs/stx/stx/libtool/Attic/DiffTxtV.st,v 1.4 1994-11-17 14:46:45 claus Exp $
|
36
|
25 |
'!
|
|
26 |
|
|
27 |
!DiffTextView class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
45
|
32 |
All Rights Reserved
|
36
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
52
|
45 |
$Header: /cvs/stx/stx/libtool/Attic/DiffTxtV.st,v 1.4 1994-11-17 14:46:45 claus Exp $
|
36
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
45
|
51 |
a view showing diff (see unix manual pages) output in a
|
|
52 |
user-friendly form.
|
36
|
53 |
The view is created and opened with:
|
|
54 |
|
|
55 |
d := DiffTextView openOn:text1 and:text2.
|
|
56 |
|
|
57 |
and it will show the differences side-by-side
|
45
|
58 |
For a real world application, see the ChangesBrowsers
|
|
59 |
compare function.
|
36
|
60 |
"
|
|
61 |
! !
|
|
62 |
|
45
|
63 |
!DiffTextView class methodsFor:'defaults'!
|
|
64 |
|
|
65 |
diffCommand
|
|
66 |
^ 'diff -b'
|
|
67 |
! !
|
|
68 |
|
36
|
69 |
!DiffTextView methodsFor:'private'!
|
|
70 |
|
|
71 |
updateListsFrom:text1 and:text2 diffs:diffList
|
|
72 |
|idx1 idx2 dIdx dEnd state s nr1 nr2 nr3 op entry c l1 l2 any delta|
|
|
73 |
|
|
74 |
l1 := OrderedCollection new.
|
|
75 |
l2 := OrderedCollection new.
|
|
76 |
|
|
77 |
idx1 := 1.
|
|
78 |
idx2 := 1.
|
|
79 |
|
|
80 |
dIdx := 1.
|
|
81 |
dEnd := diffList size + 1.
|
|
82 |
state := #initial.
|
|
83 |
[dIdx <= dEnd] whileTrue:[
|
45
|
84 |
dIdx == dEnd ifTrue:[
|
|
85 |
"dummy cleanup entry"
|
|
86 |
entry := nil.
|
|
87 |
state := #initial.
|
|
88 |
] ifFalse:[
|
|
89 |
entry := diffList at:dIdx.
|
|
90 |
].
|
36
|
91 |
|
45
|
92 |
state == #initial ifTrue:[
|
|
93 |
"entry is of the form <nr> <op> <offs> [<offs2>]"
|
36
|
94 |
|
45
|
95 |
"
|
|
96 |
fill up to size difference from previous change
|
|
97 |
"
|
|
98 |
delta := l1 size - l2 size.
|
|
99 |
delta > 0 ifTrue:[
|
|
100 |
delta timesRepeat:[l2 add:nil]
|
|
101 |
] ifFalse:[
|
|
102 |
delta < 0 ifTrue:[
|
|
103 |
delta negated timesRepeat:[l1 add:nil]
|
|
104 |
]
|
|
105 |
].
|
36
|
106 |
|
45
|
107 |
"
|
|
108 |
except for the first chunk, add a separating line
|
|
109 |
"
|
|
110 |
l1 size ~~ 0 ifTrue:[
|
|
111 |
l1 add:'--------'.
|
|
112 |
l2 add:'--------'.
|
|
113 |
].
|
36
|
114 |
|
45
|
115 |
"
|
|
116 |
in cleanup ?
|
|
117 |
"
|
|
118 |
entry isNil ifTrue:[
|
|
119 |
nr1 := text1 size + 1.
|
|
120 |
nr2 := text2 size + 1.
|
|
121 |
state := #finish.
|
|
122 |
] ifFalse:[
|
|
123 |
s := ReadStream on:entry.
|
|
124 |
nr1 := Integer readFrom:s.
|
|
125 |
s peek == $, ifTrue:[
|
|
126 |
s next.
|
|
127 |
Integer readFrom:s
|
|
128 |
].
|
|
129 |
op := s next.
|
|
130 |
nr2 := Integer readFrom:s.
|
|
131 |
s peek == $, ifTrue:[
|
|
132 |
s next.
|
|
133 |
nr3 := Integer readFrom:s
|
|
134 |
] ifFalse:[
|
|
135 |
nr3 := nil
|
|
136 |
].
|
36
|
137 |
|
45
|
138 |
op == $c ifTrue:[
|
|
139 |
state := #changed.
|
|
140 |
] ifFalse:[
|
|
141 |
op == $a ifTrue:[
|
|
142 |
state := #added.
|
|
143 |
l1 add:(text1 at:idx1).
|
|
144 |
idx1 := idx1 + 1.
|
|
145 |
] ifFalse:[
|
|
146 |
op == $d ifTrue:[
|
|
147 |
state := #deleted
|
|
148 |
]
|
|
149 |
]
|
|
150 |
].
|
36
|
151 |
|
45
|
152 |
].
|
36
|
153 |
|
45
|
154 |
"
|
|
155 |
copy over unchanged lines
|
|
156 |
"
|
|
157 |
any := false.
|
|
158 |
[idx1 < nr1] whileTrue:[
|
|
159 |
l1 add:(text1 at:idx1).
|
|
160 |
idx1 := idx1 + 1.
|
|
161 |
any := true.
|
|
162 |
].
|
|
163 |
[idx2 < nr2] whileTrue:[
|
|
164 |
l2 add:(text2 at:idx2).
|
|
165 |
idx2 := idx2 + 1.
|
|
166 |
any := true.
|
|
167 |
].
|
36
|
168 |
|
45
|
169 |
"
|
|
170 |
add a separating line, except at end
|
|
171 |
"
|
|
172 |
any ifTrue:[
|
|
173 |
state ~~ #finish ifTrue:[
|
|
174 |
l1 add:'--------'.
|
|
175 |
l2 add:'--------'.
|
|
176 |
]
|
|
177 |
].
|
36
|
178 |
|
45
|
179 |
] ifFalse:[
|
|
180 |
state == #changed ifTrue:[
|
|
181 |
(entry at:1) == $< ifTrue:[
|
|
182 |
l1 add:(text1 at:idx1).
|
|
183 |
idx1 := idx1 + 1
|
|
184 |
] ifFalse:[
|
|
185 |
(entry at:1) == $> ifTrue:[
|
|
186 |
l2 add:(text2 at:idx2).
|
|
187 |
idx2 := idx2 + 1
|
|
188 |
] ifFalse:[
|
|
189 |
(entry at:1) == $- ifTrue:[
|
|
190 |
] ifFalse:[
|
|
191 |
state := #initial.
|
|
192 |
dIdx := dIdx - 1
|
|
193 |
]
|
|
194 |
]
|
|
195 |
]
|
|
196 |
] ifFalse:[
|
|
197 |
state == #added ifTrue:[
|
|
198 |
(entry at:1) == $> ifTrue:[
|
|
199 |
l2 add:(text2 at:idx2).
|
|
200 |
idx2 := idx2 + 1.
|
|
201 |
l1 add:nil
|
|
202 |
] ifFalse:[
|
|
203 |
state := #initial.
|
|
204 |
dIdx := dIdx - 1
|
|
205 |
]
|
|
206 |
] ifFalse:[
|
|
207 |
state == #deleted ifTrue:[
|
|
208 |
(entry at:1) == $< ifTrue:[
|
|
209 |
l1 add:(text1 at:idx1).
|
|
210 |
idx1 := idx1 + 1.
|
|
211 |
l2 add:nil
|
|
212 |
] ifFalse:[
|
|
213 |
state := #initial.
|
|
214 |
dIdx := dIdx - 1
|
|
215 |
]
|
|
216 |
]
|
|
217 |
"must be in finish otherwise"
|
|
218 |
]
|
|
219 |
]
|
|
220 |
].
|
|
221 |
dIdx := dIdx + 1
|
36
|
222 |
].
|
|
223 |
[l1 size < l2 size] whileTrue:[
|
45
|
224 |
l1 add:''.
|
36
|
225 |
].
|
|
226 |
[l2 size < l1 size] whileTrue:[
|
45
|
227 |
l2 add:''.
|
36
|
228 |
].
|
|
229 |
textView1 list:l1.
|
|
230 |
textView2 list:l2
|
|
231 |
! !
|
|
232 |
|
|
233 |
!DiffTextView methodsFor:'accessing'!
|
|
234 |
|
|
235 |
text1:t1 text2:t2
|
|
236 |
|tmpName1 tmpName2 stream line text1 text2 diffList|
|
|
237 |
|
|
238 |
text1 := t1 asText.
|
|
239 |
text2 := t2 asText.
|
|
240 |
|
|
241 |
"
|
|
242 |
save them texts in two temporary files ...
|
|
243 |
"
|
|
244 |
tmpName1 := '/tmp/sta_' , OperatingSystem getProcessId printString , '.tmp'.
|
|
245 |
tmpName2 := '/tmp/stb_' , OperatingSystem getProcessId printString , '.tmp'.
|
|
246 |
|
|
247 |
stream := tmpName1 asFilename writeStream.
|
|
248 |
text1 do:[:line |
|
45
|
249 |
stream nextPutAll:line; cr
|
36
|
250 |
].
|
|
251 |
stream close.
|
|
252 |
|
|
253 |
stream := tmpName2 asFilename writeStream.
|
|
254 |
text2 do:[:line |
|
45
|
255 |
stream nextPutAll:line; cr
|
36
|
256 |
].
|
|
257 |
stream close.
|
|
258 |
|
|
259 |
"
|
|
260 |
start diff on it ...
|
|
261 |
"
|
45
|
262 |
stream := PipeStream
|
|
263 |
readingFrom:self class diffCommand , ' ' ,
|
|
264 |
tmpName1 , ' ' , tmpName2.
|
36
|
265 |
stream isNil ifTrue:[
|
45
|
266 |
self error:'cannot execute diff'.
|
|
267 |
text1 := text2 := nil.
|
|
268 |
] ifFalse:[
|
|
269 |
diffList := OrderedCollection new.
|
|
270 |
[stream atEnd] whileFalse:[
|
|
271 |
line := stream nextLine.
|
|
272 |
line notNil ifTrue:[diffList add:line]
|
|
273 |
].
|
|
274 |
stream close.
|
36
|
275 |
].
|
45
|
276 |
|
|
277 |
tmpName1 asFilename delete.
|
|
278 |
tmpName2 asFilename delete.
|
36
|
279 |
|
|
280 |
self updateListsFrom:text1 and:text2 diffs:diffList
|
|
281 |
|
|
282 |
"
|
|
283 |
|v|
|
|
284 |
|
|
285 |
v := HVScrollableView for:DiffTextView.
|
|
286 |
v scrolledView text1:('../libview/Color.st' asFilename readStream contents)
|
45
|
287 |
text2:('../libview/Color.st.old' asFilename readStream contents).
|
36
|
288 |
v open
|
|
289 |
"
|
|
290 |
|
|
291 |
"
|
|
292 |
|v t1 t2|
|
|
293 |
|
|
294 |
t1 := '
|
|
295 |
one
|
|
296 |
two
|
|
297 |
three
|
|
298 |
four
|
|
299 |
'.
|
|
300 |
t2 := '
|
|
301 |
one
|
|
302 |
two-a
|
|
303 |
two-b
|
|
304 |
three
|
|
305 |
three-b
|
|
306 |
four
|
|
307 |
'.
|
|
308 |
|
|
309 |
v := DiffTextView new.
|
|
310 |
v text1:t1 text2:t2.
|
|
311 |
v
|
|
312 |
"
|
|
313 |
! !
|