--- a/DiffTextView.st Mon Oct 10 04:15:21 1994 +0100
+++ b/DiffTextView.st Mon Oct 10 04:16:24 1994 +0100
@@ -2,7 +2,7 @@
"
COPYRIGHT (c) 1994 by Claus Gittinger
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -13,17 +13,17 @@
"
TwoColumnTextView subclass:#DiffTextView
- instanceVariableNames:''
- classVariableNames:''
- poolDictionaries:''
- category:'Views-Text'
+ instanceVariableNames:''
+ classVariableNames:''
+ poolDictionaries:''
+ category:'Views-Text'
!
DiffTextView comment:'
COPYRIGHT (c) 1994 by Claus Gittinger
- All Rights Reserved
+ All Rights Reserved
-$Header: /cvs/stx/stx/libtool/DiffTextView.st,v 1.2 1994-08-13 18:40:49 claus Exp $
+$Header: /cvs/stx/stx/libtool/DiffTextView.st,v 1.3 1994-10-10 03:15:33 claus Exp $
'!
!DiffTextView class methodsFor:'documentation'!
@@ -31,7 +31,7 @@
copyright
"
COPYRIGHT (c) 1994 by Claus Gittinger
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -44,21 +44,30 @@
version
"
-$Header: /cvs/stx/stx/libtool/DiffTextView.st,v 1.2 1994-08-13 18:40:49 claus Exp $
+$Header: /cvs/stx/stx/libtool/DiffTextView.st,v 1.3 1994-10-10 03:15:33 claus Exp $
"
!
documentation
"
- a view showing diff output in a user-friendly form.
+ a view showing diff (see unix manual pages) output in a
+ user-friendly form.
The view is created and opened with:
d := DiffTextView openOn:text1 and:text2.
and it will show the differences side-by-side
+ For a real world application, see the ChangesBrowsers
+ compare function.
"
! !
+!DiffTextView class methodsFor:'defaults'!
+
+diffCommand
+ ^ 'diff -b'
+! !
+
!DiffTextView methodsFor:'private'!
updateListsFrom:text1 and:text2 diffs:diffList
@@ -74,150 +83,150 @@
dEnd := diffList size + 1.
state := #initial.
[dIdx <= dEnd] whileTrue:[
- dIdx == dEnd ifTrue:[
- "dummy cleanup entry"
- entry := nil.
- state := #initial.
- ] ifFalse:[
- entry := diffList at:dIdx.
- ].
+ dIdx == dEnd ifTrue:[
+ "dummy cleanup entry"
+ entry := nil.
+ state := #initial.
+ ] ifFalse:[
+ entry := diffList at:dIdx.
+ ].
- state == #initial ifTrue:[
- "entry is of the form <nr> <op> <offs> [<offs2>]"
+ state == #initial ifTrue:[
+ "entry is of the form <nr> <op> <offs> [<offs2>]"
- "
- fill up to size difference from previous change
- "
- delta := l1 size - l2 size.
- delta > 0 ifTrue:[
- delta timesRepeat:[l2 add:nil]
- ] ifFalse:[
- delta < 0 ifTrue:[
- delta negated timesRepeat:[l1 add:nil]
- ]
- ].
+ "
+ fill up to size difference from previous change
+ "
+ delta := l1 size - l2 size.
+ delta > 0 ifTrue:[
+ delta timesRepeat:[l2 add:nil]
+ ] ifFalse:[
+ delta < 0 ifTrue:[
+ delta negated timesRepeat:[l1 add:nil]
+ ]
+ ].
- "
- except for the first chunk, add a separating line
- "
- l1 size ~~ 0 ifTrue:[
- l1 add:'--------'.
- l2 add:'--------'.
- ].
+ "
+ except for the first chunk, add a separating line
+ "
+ l1 size ~~ 0 ifTrue:[
+ l1 add:'--------'.
+ l2 add:'--------'.
+ ].
- "
- in cleanup ?
- "
- entry isNil ifTrue:[
- nr1 := text1 size + 1.
- nr2 := text2 size + 1.
- state := #finish.
- ] ifFalse:[
- s := ReadStream on:entry.
- nr1 := Integer readFrom:s.
- s peek == $, ifTrue:[
- s next.
- Integer readFrom:s
- ].
- op := s next.
- nr2 := Integer readFrom:s.
- s peek == $, ifTrue:[
- s next.
- nr3 := Integer readFrom:s
- ] ifFalse:[
- nr3 := nil
- ].
+ "
+ in cleanup ?
+ "
+ entry isNil ifTrue:[
+ nr1 := text1 size + 1.
+ nr2 := text2 size + 1.
+ state := #finish.
+ ] ifFalse:[
+ s := ReadStream on:entry.
+ nr1 := Integer readFrom:s.
+ s peek == $, ifTrue:[
+ s next.
+ Integer readFrom:s
+ ].
+ op := s next.
+ nr2 := Integer readFrom:s.
+ s peek == $, ifTrue:[
+ s next.
+ nr3 := Integer readFrom:s
+ ] ifFalse:[
+ nr3 := nil
+ ].
- op == $c ifTrue:[
- state := #changed.
- ] ifFalse:[
- op == $a ifTrue:[
- state := #added.
- l1 add:(text1 at:idx1).
- idx1 := idx1 + 1.
- ] ifFalse:[
- op == $d ifTrue:[
- state := #deleted
- ]
- ]
- ].
+ op == $c ifTrue:[
+ state := #changed.
+ ] ifFalse:[
+ op == $a ifTrue:[
+ state := #added.
+ l1 add:(text1 at:idx1).
+ idx1 := idx1 + 1.
+ ] ifFalse:[
+ op == $d ifTrue:[
+ state := #deleted
+ ]
+ ]
+ ].
- ].
+ ].
- "
- copy over unchanged lines
- "
- any := false.
- [idx1 < nr1] whileTrue:[
- l1 add:(text1 at:idx1).
- idx1 := idx1 + 1.
- any := true.
- ].
- [idx2 < nr2] whileTrue:[
- l2 add:(text2 at:idx2).
- idx2 := idx2 + 1.
- any := true.
- ].
+ "
+ copy over unchanged lines
+ "
+ any := false.
+ [idx1 < nr1] whileTrue:[
+ l1 add:(text1 at:idx1).
+ idx1 := idx1 + 1.
+ any := true.
+ ].
+ [idx2 < nr2] whileTrue:[
+ l2 add:(text2 at:idx2).
+ idx2 := idx2 + 1.
+ any := true.
+ ].
- "
- add a separating line, except at end
- "
- any ifTrue:[
- state ~~ #finish ifTrue:[
- l1 add:'--------'.
- l2 add:'--------'.
- ]
- ].
+ "
+ add a separating line, except at end
+ "
+ any ifTrue:[
+ state ~~ #finish ifTrue:[
+ l1 add:'--------'.
+ l2 add:'--------'.
+ ]
+ ].
- ] ifFalse:[
- state == #changed ifTrue:[
- (entry at:1) == $< ifTrue:[
- l1 add:(text1 at:idx1).
- idx1 := idx1 + 1
- ] ifFalse:[
- (entry at:1) == $> ifTrue:[
- l2 add:(text2 at:idx2).
- idx2 := idx2 + 1
- ] ifFalse:[
- (entry at:1) == $- ifTrue:[
- ] ifFalse:[
- state := #initial.
- dIdx := dIdx - 1
- ]
- ]
- ]
- ] ifFalse:[
- state == #added ifTrue:[
- (entry at:1) == $> ifTrue:[
- l2 add:(text2 at:idx2).
- idx2 := idx2 + 1.
- l1 add:nil
- ] ifFalse:[
- state := #initial.
- dIdx := dIdx - 1
- ]
- ] ifFalse:[
- state == #deleted ifTrue:[
- (entry at:1) == $< ifTrue:[
- l1 add:(text1 at:idx1).
- idx1 := idx1 + 1.
- l2 add:nil
- ] ifFalse:[
- state := #initial.
- dIdx := dIdx - 1
- ]
- ]
- "must be in finish otherwise"
- ]
- ]
- ].
- dIdx := dIdx + 1
+ ] ifFalse:[
+ state == #changed ifTrue:[
+ (entry at:1) == $< ifTrue:[
+ l1 add:(text1 at:idx1).
+ idx1 := idx1 + 1
+ ] ifFalse:[
+ (entry at:1) == $> ifTrue:[
+ l2 add:(text2 at:idx2).
+ idx2 := idx2 + 1
+ ] ifFalse:[
+ (entry at:1) == $- ifTrue:[
+ ] ifFalse:[
+ state := #initial.
+ dIdx := dIdx - 1
+ ]
+ ]
+ ]
+ ] ifFalse:[
+ state == #added ifTrue:[
+ (entry at:1) == $> ifTrue:[
+ l2 add:(text2 at:idx2).
+ idx2 := idx2 + 1.
+ l1 add:nil
+ ] ifFalse:[
+ state := #initial.
+ dIdx := dIdx - 1
+ ]
+ ] ifFalse:[
+ state == #deleted ifTrue:[
+ (entry at:1) == $< ifTrue:[
+ l1 add:(text1 at:idx1).
+ idx1 := idx1 + 1.
+ l2 add:nil
+ ] ifFalse:[
+ state := #initial.
+ dIdx := dIdx - 1
+ ]
+ ]
+ "must be in finish otherwise"
+ ]
+ ]
+ ].
+ dIdx := dIdx + 1
].
[l1 size < l2 size] whileTrue:[
- l1 add:''.
+ l1 add:''.
].
[l2 size < l1 size] whileTrue:[
- l2 add:''.
+ l2 add:''.
].
textView1 list:l1.
textView2 list:l2
@@ -239,31 +248,36 @@
stream := tmpName1 asFilename writeStream.
text1 do:[:line |
- stream nextPutAll:line; cr
+ stream nextPutAll:line; cr
].
stream close.
stream := tmpName2 asFilename writeStream.
text2 do:[:line |
- stream nextPutAll:line; cr
+ stream nextPutAll:line; cr
].
stream close.
"
start diff on it ...
"
- stream := PipeStream readingFrom:'diff ' , tmpName1 , ' ' , tmpName2.
+ stream := PipeStream
+ readingFrom:self class diffCommand , ' ' ,
+ tmpName1 , ' ' , tmpName2.
stream isNil ifTrue:[
- self error:'cannot execute diff'.
- text1 := text2 := nil.
- ^ nil
+ self error:'cannot execute diff'.
+ text1 := text2 := nil.
+ ] ifFalse:[
+ diffList := OrderedCollection new.
+ [stream atEnd] whileFalse:[
+ line := stream nextLine.
+ line notNil ifTrue:[diffList add:line]
+ ].
+ stream close.
].
- diffList := OrderedCollection new.
- [stream atEnd] whileFalse:[
- line := stream nextLine.
- line notNil ifTrue:[diffList add:line]
- ].
- stream close.
+
+ tmpName1 asFilename delete.
+ tmpName2 asFilename delete.
self updateListsFrom:text1 and:text2 diffs:diffList
@@ -272,7 +286,7 @@
v := HVScrollableView for:DiffTextView.
v scrolledView text1:('../libview/Color.st' asFilename readStream contents)
- text2:('../libview/Color.st.old' asFilename readStream contents).
+ text2:('../libview/Color.st.old' asFilename readStream contents).
v open
"