Skip to content

Instantly share code, notes, and snippets.

@SpaceManiac
Created July 16, 2010 01:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SpaceManiac/477779 to your computer and use it in GitHub Desktop.
Save SpaceManiac/477779 to your computer and use it in GitHub Desktop.
cd [file dirname [info script]]
set file1 aaa.dlw
set file2 aaa2.dlw
set f1 [open $file1]
fconfigure $f1 -translation binary
set f2 [open $file2]
fconfigure $f2 -translation binary
set i 0
while 1 {
set b1 [read $f1 1]
set b2 [read $f2 1]
scan $b1 %c n1
scan $b2 %c n2
if {![eof $f1] && ![eof $f2]} {
if {$b1 != $b2} {
puts "byte $i: $b1,$b2 ($n1,$n2)"
}
}
if {[eof $f1] && [eof $f2]} {
puts "both files ended at $i"
break
} elseif {[eof $f1]} {
set i2 $i
set str2 ""
set nums2 [list]
while {![eof $f2]} {
set ch [read $f2 1]
append str2 $ch
lappend nums2 [scan $ch %c]
incr i2
}
puts "$file1 ended at $i; $file2 ended at $i2"
puts "$file2 added [llength $nums2]: $str2 ([join $nums2 ,])"
break
} elseif {[eof $f2]} {
set i2 $i
set str2 ""
set nums2 [list]
while {![eof $f1]} {
set ch [read $f1 1]
append str2 $ch
lappend nums2 [scan $ch %c]
incr i2
}
puts "$file2 ended at $i; $file1 ended at $i2"
puts "$file1 added [llength $nums2]: $str2 ([join $nums2 ,])"
break
}
incr i
}
puts "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment