--- a/DiffTextView.st Sat Oct 10 12:08:51 2009 +0200
+++ b/DiffTextView.st Sat Oct 10 12:09:23 2009 +0200
@@ -165,32 +165,15 @@
diffCommand
"return the diff-command (with argument placeHolders)"
- DiffCommandTemplate isNil ifTrue:[
- OperatingSystem isMSDOSlike ifTrue:[
- (OperatingSystem canExecuteCommand:'diff') ifFalse:[
- 'DiffTextView [warning]: no diff command found (please download and unzip "UnxUtils.zip" from "unxutils.sourceforge.net")' infoPrintCR.
- ^ nil
- ].
- ^ 'diff %1 %2'
- ].
- ^ 'diff -b %1 %2'
- ].
- ^ DiffCommandTemplate
-
- "Modified: / 30.1.1998 / 12:12:49 / cg"
+ "/ forwarded, for backward compatibility...
+ ^ DiffListUtility diffCommand
!
diffCommandTemplate:aCommandTemplateString
"set the diff-command template"
- OperatingSystem isMSDOSlike ifTrue:[
- ^ DiffCommandTemplate ? 'diff %1 %2'
- ].
-
- ^ DiffCommandTemplate ? 'diff -b %1 %2'
-
- "Modified: / 30.1.1998 / 12:10:34 / cg"
- "Created: / 30.1.1998 / 12:12:37 / cg"
+ "/ forwarded for backward compatibility
+ DiffListUtility diffCommandTemplate:aCommandTemplateString
! !
!DiffTextView methodsFor:'accessing'!
@@ -289,128 +272,26 @@
!DiffTextView methodsFor:'private'!
diffListFor:text1 and:text2
- "set the two texts which are to be diffed;
- execute DiffCommand and update the two textViews."
-
- |tmpFile1 tmpFile2 stream line
- diffList diffTemplate diffCmd|
-
- diffTemplate := self class diffCommand.
- diffTemplate isNil ifTrue:[
- "/ self warn:'no diff command available'.
- ^ nil
- ].
-
- text1 = text2 ifTrue:[
- "no diff"
- ^ ''
- ].
+ "return a raw difflist for the two texts which are to be diffed"
- "
- save them texts in two temporary files ...
- "
- self save:text1 as:(tmpFile1 := Filename newTemporary).
- self save:text2 as:(tmpFile2 := Filename newTemporary).
- [
- "
- start diff on it ...
- "
- diffCmd := diffTemplate
- bindWith:tmpFile1 asString
- with:tmpFile2 asString.
-
- stream := PipeStream readingFrom:diffCmd.
- stream isNil ifTrue:[
- stream := PipeStream readingFrom:('support' , Filename separator , diffCmd).
- ].
- stream isNil ifTrue:[
- self error:'cannot execute diff' mayProceed:true.
- ^ nil.
- ].
-
- diffList := OrderedCollection new.
- (stream readWaitWithTimeout:5) ifTrue:[
- "/ timeout
- self error:'cannot execute diff (timeout)' mayProceed:true.
- ^ nil.
- ].
-
- [stream atEnd] whileFalse:[
- line := stream nextLine.
- line notNil ifTrue:[diffList add:line]
- ].
- stream close.
- ^ diffList
- ] ensure:[
- tmpFile1 delete.
- tmpFile2 delete.
- ].
+ ^ DiffListUtility diffListFor:text1 and:text2
!
-save:text as:filename
- |stream|
-
- stream := filename writeStream.
- text do:[:line |
- |lOut i|
+processDiffList:diffList from:text1 and:text2
+ "given the two texts in text1 and text2, and the diff-output in diffList,
+ return new left and right lists."
- line notEmptyOrNil ifTrue:[
- lOut := line.
- (line includes:Character return) ifTrue: [
- (line endsWith:Character return) ifTrue:[
- lOut := line copyWithoutLast:1.
- ] ifFalse:[
- i := line indexOf:Character return.
- (line at:i+1) == Character nl ifTrue:[
- "/ crnl endings
- lOut := line copyReplaceString:(String crlf) withString:(String lf).
- ] ifFalse:[
- "/ cr endings
- lOut := line copyReplaceAll:Character return with:Character nl.
- ].
- ]
- ].
- lOut bitsPerCharacter > 8 ifTrue:[
- (lOut first = (Character value:16rFEFF)) ifTrue:[
- lOut := (lOut copyFrom:2) asSingleByteStringIfPossible.
- ].
- lOut bitsPerCharacter > 8 ifTrue:[
- lOut := lOut collect:[:ch | ch bitsPerCharacter > 8
- ifTrue:[ Character value:16rFF ]
- ifFalse:[ ch ]].
- lOut := lOut asSingleByteStringIfPossible.
- ].
- ].
- stream nextPutAll:lOut.
- ].
- stream cr
+ |idx1 idx2 dIdx dEnd state s nr1 nr2 nr3 op entry l1 l2 any delta s1 s2 line1 line2|
+
+ diffList size == 1 ifTrue:[
+ ^ { diffList. diffList }
].
- stream close.
-
- "Modified: / 22-10-2008 / 17:52:52 / cg"
-!
-
-updateListsFrom:text1 and:text2 diffs:diffList
- "given the two texts in text1 and text2, and the diff-output in diffList,
- update my views contents"
-
- |idx1 idx2 dIdx dEnd state s nr1 nr2 nr3 op entry c l1 l2 any delta
- textView1 textView2 s1 s2 line1 line2|
diffLineNumbers := OrderedCollection new.
- textView1 := textViews at:1.
- textView2 := textViews at:2.
-
l1 := OrderedCollection new.
l2 := OrderedCollection new.
- diffList size == 1 ifTrue:[
- textView1 list:diffList.
- textView2 list:diffList.
- ^ self.
- ].
-
idx1 := 1.
idx2 := 1.
@@ -539,7 +420,7 @@
useColors ifTrue:[
(l2 size >= idx1
and:[(s2 := line2 := l2 at:idx1) notNil
- and:[(s2 asString withoutSeparators = (text1 at:idx1) withoutSeparators)
+ and:[(s2 asString string withoutSeparators = (text1 at:idx1) string withoutSeparators)
"/ or:[(s2 asString withoutSeparators withTabsExpanded = (text1 at:idx1) withoutSeparators withTabsExpanded)]
]]) ifTrue:[
line1 := Text string:(text1 at:idx1)
@@ -576,7 +457,7 @@
useColors ifTrue:[
(l1 size >= idx2
and:[(s1 := line1 := l1 at:idx2) notNil
- and:[(s1 asString withoutSeparators = (text2 at:idx2) withoutSeparators)
+ and:[(s1 asString string withoutSeparators = (text2 at:idx2) string withoutSeparators)
"/ or:[(s1 asString withoutSeparators withTabsExpanded = (text2 at:idx2) withoutSeparators withTabsExpanded)]
]]) ifTrue:[
line2 := Text string:(text2 at:idx2)
@@ -679,14 +560,32 @@
]
].
- textView1 list:l1.
- textView2 list:l2
+ ^ { l1. l2 }
"Modified: / 13.7.1999 / 14:12:11 / cg"
+!
+
+updateListsFrom:text1 and:text2 diffs:diffList
+ "given the two texts in text1 and text2, and the diff-output in diffList,
+ update my views contents"
+
+ |lists textView1 textView2|
+
+ textView1 := textViews at:1.
+ textView2 := textViews at:2.
+
+ lists := self processDiffList:diffList from:text1 and:text2.
+
+ textView1 list:lists first.
+ textView2 list:lists second.
! !
!DiffTextView class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libtool/DiffTextView.st,v 1.55 2009-08-14 20:35:22 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libtool/DiffTextView.st,v 1.56 2009-10-10 10:09:23 cg Exp $'
+!
+
+version_CVS
+ ^ '$Header: /cvs/stx/stx/libtool/DiffTextView.st,v 1.56 2009-10-10 10:09:23 cg Exp $'
! !